libp2p 0.46.8-a6be8f0f → 0.46.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA;AACxC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAA"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAA;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,71 @@
1
+ {
2
+ "AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATComponents.html",
3
+ "./autonat:AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATComponents.html",
4
+ "AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATServiceInit.html",
5
+ "./autonat:AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATServiceInit.html",
6
+ "autoNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.autonat.autoNATService.html",
7
+ "./autonat:autoNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.autonat.autoNATService.html",
8
+ "CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayService.html",
9
+ "./circuit-relay:CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayService.html",
10
+ "CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayServiceEvents.html",
11
+ "./circuit-relay:CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayServiceEvents.html",
12
+ "RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.RelayReservation.html",
13
+ "./circuit-relay:RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.RelayReservation.html",
14
+ "circuitRelayServer": "https://libp2p.github.io/js-libp2p/functions/libp2p.circuit_relay.circuitRelayServer.html",
15
+ "circuitRelayTransport": "https://libp2p.github.io/js-libp2p/functions/libp2p.circuit_relay.circuitRelayTransport.html",
16
+ "FetchService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchService.html",
17
+ "./fetch:FetchService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchService.html",
18
+ "FetchServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceComponents.html",
19
+ "./fetch:FetchServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceComponents.html",
20
+ "FetchServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceInit.html",
21
+ "./fetch:FetchServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceInit.html",
22
+ "HandleMessageOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.HandleMessageOptions.html",
23
+ "./fetch:HandleMessageOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.HandleMessageOptions.html",
24
+ "LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.LookupFunction.html",
25
+ "./fetch:LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.LookupFunction.html",
26
+ "fetchService": "https://libp2p.github.io/js-libp2p/functions/libp2p.fetch.fetchService-1.html",
27
+ "./fetch:fetchService": "https://libp2p.github.io/js-libp2p/functions/libp2p.fetch.fetchService-1.html",
28
+ "IdentifyService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyService.html",
29
+ "./identify:IdentifyService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyService.html",
30
+ "IdentifyServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceComponents.html",
31
+ "./identify:IdentifyServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceComponents.html",
32
+ "IdentifyServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceInit.html",
33
+ "./identify:IdentifyServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceInit.html",
34
+ "Message": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.Message.html",
35
+ "./identify:Message": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.Message.html",
36
+ "multicodecs": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.multicodecs.html",
37
+ "./identify:multicodecs": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.multicodecs.html",
38
+ "identifyService": "https://libp2p.github.io/js-libp2p/functions/libp2p.identify.identifyService-1.html",
39
+ "./identify:identifyService": "https://libp2p.github.io/js-libp2p/functions/libp2p.identify.identifyService-1.html",
40
+ "Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
41
+ ".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
42
+ "Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
43
+ ".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
44
+ "ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
45
+ ".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
46
+ "createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
47
+ ".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
48
+ "plaintext": "https://libp2p.github.io/js-libp2p/functions/libp2p.insecure.plaintext.html",
49
+ "./insecure:plaintext": "https://libp2p.github.io/js-libp2p/functions/libp2p.insecure.plaintext.html",
50
+ "PingService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingService.html",
51
+ "./ping:PingService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingService.html",
52
+ "PingServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceComponents.html",
53
+ "./ping:PingServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceComponents.html",
54
+ "PingServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceInit.html",
55
+ "./ping:PingServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceInit.html",
56
+ "pingService": "https://libp2p.github.io/js-libp2p/functions/libp2p.ping.pingService-1.html",
57
+ "./ping:pingService": "https://libp2p.github.io/js-libp2p/functions/libp2p.ping.pingService-1.html",
58
+ "ProtectorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.pnet.ProtectorInit.html",
59
+ "./pnet:ProtectorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.pnet.ProtectorInit.html",
60
+ "generateKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.generateKey.html",
61
+ "preSharedKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.preSharedKey.html",
62
+ "./pnet:preSharedKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.preSharedKey.html",
63
+ "PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.PMPOptions.html",
64
+ "./upnp-nat:PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.PMPOptions.html",
65
+ "UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATComponents.html",
66
+ "./upnp-nat:UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATComponents.html",
67
+ "UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATInit.html",
68
+ "./upnp-nat:UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATInit.html",
69
+ "uPnPNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.upnp_nat.uPnPNATService.html",
70
+ "./upnp-nat:uPnPNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.upnp_nat.uPnPNATService.html"
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.46.8-a6be8f0f",
3
+ "version": "0.46.9",
4
4
  "description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p#readme",
@@ -120,22 +120,21 @@
120
120
  },
121
121
  "dependencies": {
122
122
  "@achingbrain/nat-port-mapper": "^1.0.9",
123
- "@libp2p/crypto": "2.0.3-a6be8f0f",
124
- "@libp2p/interface": "0.1.2-a6be8f0f",
125
- "@libp2p/interface-internal": "0.1.4-a6be8f0f",
126
- "@libp2p/keychain": "3.0.3-a6be8f0f",
127
- "@libp2p/logger": "3.0.2-a6be8f0f",
128
- "@libp2p/multistream-select": "4.0.2-a6be8f0f",
129
- "@libp2p/peer-collections": "4.0.3-a6be8f0f",
130
- "@libp2p/peer-id": "3.0.2-a6be8f0f",
131
- "@libp2p/peer-id-factory": "3.0.3-a6be8f0f",
132
- "@libp2p/peer-record": "6.0.3-a6be8f0f",
133
- "@libp2p/peer-store": "9.0.3-a6be8f0f",
134
- "@libp2p/utils": "4.0.2-a6be8f0f",
123
+ "@libp2p/crypto": "^2.0.3",
124
+ "@libp2p/interface": "^0.1.2",
125
+ "@libp2p/interface-internal": "^0.1.4",
126
+ "@libp2p/keychain": "^3.0.3",
127
+ "@libp2p/logger": "^3.0.2",
128
+ "@libp2p/multistream-select": "^4.0.2",
129
+ "@libp2p/peer-collections": "^4.0.3",
130
+ "@libp2p/peer-id": "^3.0.2",
131
+ "@libp2p/peer-id-factory": "^3.0.3",
132
+ "@libp2p/peer-record": "^6.0.3",
133
+ "@libp2p/peer-store": "^9.0.3",
134
+ "@libp2p/utils": "^4.0.2",
135
135
  "@multiformats/mafmt": "^12.1.2",
136
136
  "@multiformats/multiaddr": "^12.1.5",
137
137
  "@multiformats/multiaddr-matcher": "^1.0.0",
138
- "abortable-iterator": "^5.0.1",
139
138
  "any-signal": "^4.1.1",
140
139
  "datastore-core": "^9.0.1",
141
140
  "delay": "^6.0.0",
@@ -170,17 +169,17 @@
170
169
  "@chainsafe/libp2p-gossipsub": "^10.0.0",
171
170
  "@chainsafe/libp2p-noise": "^13.0.0",
172
171
  "@chainsafe/libp2p-yamux": "^5.0.0",
173
- "@libp2p/bootstrap": "9.0.5-a6be8f0f",
172
+ "@libp2p/bootstrap": "^9.0.5",
174
173
  "@libp2p/daemon-client": "^7.0.0",
175
174
  "@libp2p/daemon-server": "^6.0.0",
176
- "@libp2p/floodsub": "8.0.6-a6be8f0f",
177
- "@libp2p/interface-compliance-tests": "4.0.5-a6be8f0f",
175
+ "@libp2p/floodsub": "^8.0.6",
176
+ "@libp2p/interface-compliance-tests": "^4.0.5",
178
177
  "@libp2p/interop": "^9.0.0",
179
- "@libp2p/kad-dht": "10.0.5-a6be8f0f",
180
- "@libp2p/mdns": "9.0.6-a6be8f0f",
181
- "@libp2p/mplex": "9.0.5-a6be8f0f",
182
- "@libp2p/tcp": "8.0.5-a6be8f0f",
183
- "@libp2p/websockets": "7.0.5-a6be8f0f",
178
+ "@libp2p/kad-dht": "^10.0.5",
179
+ "@libp2p/mdns": "^9.0.6",
180
+ "@libp2p/mplex": "^9.0.5",
181
+ "@libp2p/tcp": "^8.0.5",
182
+ "@libp2p/websockets": "^7.0.5",
184
183
  "@types/xsalsa20": "^1.1.0",
185
184
  "aegir": "^40.0.8",
186
185
  "execa": "^8.0.1",
@@ -20,17 +20,18 @@
20
20
  */
21
21
 
22
22
  import { setMaxListeners } from 'events'
23
+ import { CodeError } from '@libp2p/interface/errors'
23
24
  import { logger } from '@libp2p/logger'
24
25
  import { peerIdFromBytes } from '@libp2p/peer-id'
25
26
  import { createEd25519PeerId } from '@libp2p/peer-id-factory'
26
27
  import { multiaddr, protocols } from '@multiformats/multiaddr'
27
- import { abortableDuplex } from 'abortable-iterator'
28
28
  import first from 'it-first'
29
29
  import * as lp from 'it-length-prefixed'
30
30
  import map from 'it-map'
31
31
  import parallel from 'it-parallel'
32
32
  import { pipe } from 'it-pipe'
33
33
  import isPrivateIp from 'private-ip'
34
+ import { codes } from '../errors.js'
34
35
  import {
35
36
  MAX_INBOUND_STREAMS,
36
37
  MAX_OUTBOUND_STREAMS,
@@ -155,6 +156,12 @@ class DefaultAutoNATService implements Startable {
155
156
  async handleIncomingAutonatStream (data: IncomingStreamData): Promise<void> {
156
157
  const signal = AbortSignal.timeout(this.timeout)
157
158
 
159
+ const onAbort = (): void => {
160
+ data.stream.abort(new CodeError('handleIncomingAutonatStream timeout', codes.ERR_TIMEOUT))
161
+ }
162
+
163
+ signal.addEventListener('abort', onAbort, { once: true })
164
+
158
165
  // this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
159
166
  // appearing in the console
160
167
  try {
@@ -166,11 +173,10 @@ class DefaultAutoNATService implements Startable {
166
173
  .map(ma => ma.toOptions().host)
167
174
 
168
175
  try {
169
- const source = abortableDuplex(data.stream, signal)
170
176
  const self = this
171
177
 
172
178
  await pipe(
173
- source,
179
+ data.stream,
174
180
  (source) => lp.decode(source),
175
181
  async function * (stream) {
176
182
  const buf = await first(stream)
@@ -379,12 +385,12 @@ class DefaultAutoNATService implements Startable {
379
385
  })
380
386
  },
381
387
  (source) => lp.encode(source),
382
- // pipe to the stream, not the abortable source other wise we
383
- // can't tell the remote when a dial timed out..
384
388
  data.stream
385
389
  )
386
390
  } catch (err) {
387
391
  log.error('error handling incoming autonat stream', err)
392
+ } finally {
393
+ signal.removeEventListener('abort', onAbort)
388
394
  }
389
395
  }
390
396
 
@@ -453,6 +459,8 @@ class DefaultAutoNATService implements Startable {
453
459
  const networkSegments: string[] = []
454
460
 
455
461
  const verifyAddress = async (peer: PeerInfo): Promise<Message.DialResponse | undefined> => {
462
+ let onAbort = (): void => {}
463
+
456
464
  try {
457
465
  log('asking %p to verify multiaddr', peer.id)
458
466
 
@@ -463,12 +471,15 @@ class DefaultAutoNATService implements Startable {
463
471
  const stream = await connection.newStream(this.protocol, {
464
472
  signal
465
473
  })
466
- const source = abortableDuplex(stream, signal)
474
+
475
+ onAbort = () => { stream.abort(new CodeError('verifyAddress timeout', codes.ERR_TIMEOUT)) }
476
+
477
+ signal.addEventListener('abort', onAbort, { once: true })
467
478
 
468
479
  const buf = await pipe(
469
480
  [request],
470
481
  (source) => lp.encode(source),
471
- source,
482
+ stream,
472
483
  (source) => lp.decode(source),
473
484
  async (stream) => first(stream)
474
485
  )
@@ -510,6 +521,8 @@ class DefaultAutoNATService implements Startable {
510
521
  return response.dialResponse
511
522
  } catch (err) {
512
523
  log.error('error asking remote to verify multiaddr', err)
524
+ } finally {
525
+ signal.removeEventListener('abort', onAbort)
513
526
  }
514
527
  }
515
528
 
@@ -261,7 +261,7 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
261
261
  options.signal?.throwIfAborted()
262
262
 
263
263
  log('requesting reservation from %p', connection.remotePeer)
264
- const stream = await connection.newStream(RELAY_V2_HOP_CODEC)
264
+ const stream = await connection.newStream(RELAY_V2_HOP_CODEC, options)
265
265
  const pbstr = pbStream(stream)
266
266
  const hopstr = pbstr.pb(HopMessage)
267
267
  await hopstr.write({ type: HopMessage.Type.RESERVE }, options)
@@ -1,8 +1,9 @@
1
+ import { CodeError } from '@libp2p/interface/errors'
1
2
  import { logger } from '@libp2p/logger'
2
- import { abortableSource } from 'abortable-iterator'
3
3
  import { anySignal } from 'any-signal'
4
4
  import { CID } from 'multiformats/cid'
5
5
  import { sha256 } from 'multiformats/hashes/sha2'
6
+ import { codes } from '../errors.js'
6
7
  import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js'
7
8
  import type { Limit } from './pb/index.js'
8
9
  import type { Stream } from '@libp2p/interface/connection'
@@ -58,9 +59,13 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
58
59
  }
59
60
 
60
61
  queueMicrotask(() => {
61
- void dst.sink(countStreamBytes(abortableSource(src.source, signal, {
62
- abortMessage: 'duration limit exceeded'
63
- }), dataLimit))
62
+ const onAbort = (): void => {
63
+ dst.abort(new CodeError('duration limit exceeded', codes.ERR_TIMEOUT))
64
+ }
65
+
66
+ signal.addEventListener('abort', onAbort, { once: true })
67
+
68
+ void dst.sink(countStreamBytes(src.source, dataLimit))
64
69
  .catch(err => {
65
70
  log.error('error while relaying streams src -> dst', err)
66
71
  abortStreams(err)
@@ -69,6 +74,7 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
69
74
  srcDstFinished = true
70
75
 
71
76
  if (dstSrcFinished) {
77
+ signal.removeEventListener('abort', onAbort)
72
78
  signal.clear()
73
79
  clearTimeout(timeout)
74
80
  }
@@ -76,9 +82,13 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
76
82
  })
77
83
 
78
84
  queueMicrotask(() => {
79
- void src.sink(countStreamBytes(abortableSource(dst.source, signal, {
80
- abortMessage: 'duration limit exceeded'
81
- }), dataLimit))
85
+ const onAbort = (): void => {
86
+ src.abort(new CodeError('duration limit exceeded', codes.ERR_TIMEOUT))
87
+ }
88
+
89
+ signal.addEventListener('abort', onAbort, { once: true })
90
+
91
+ void src.sink(countStreamBytes(dst.source, dataLimit))
82
92
  .catch(err => {
83
93
  log.error('error while relaying streams dst -> src', err)
84
94
  abortStreams(err)
@@ -87,6 +97,7 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
87
97
  dstSrcFinished = true
88
98
 
89
99
  if (srcDstFinished) {
100
+ signal.removeEventListener('abort', onAbort)
90
101
  signal.clear()
91
102
  clearTimeout(timeout)
92
103
  }
@@ -1,7 +1,6 @@
1
1
  import { setMaxListeners } from 'events'
2
2
  import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
- import { abortableDuplex } from 'abortable-iterator'
5
4
  import first from 'it-first'
6
5
  import * as lp from 'it-length-prefixed'
7
6
  import { pipe } from 'it-pipe'
@@ -140,6 +139,7 @@ class DefaultFetchService implements Startable, FetchService {
140
139
  const connection = await this.components.connectionManager.openConnection(peer, options)
141
140
  let signal = options.signal
142
141
  let stream: Stream | undefined
142
+ let onAbort = (): void => {}
143
143
 
144
144
  // create a timeout if no abort signal passed
145
145
  if (signal == null) {
@@ -157,15 +157,19 @@ class DefaultFetchService implements Startable, FetchService {
157
157
  signal
158
158
  })
159
159
 
160
+ onAbort = () => {
161
+ stream?.abort(new CodeError('fetch timeout', codes.ERR_TIMEOUT))
162
+ }
163
+
160
164
  // make stream abortable
161
- const source = abortableDuplex(stream, signal)
165
+ signal.addEventListener('abort', onAbort, { once: true })
162
166
 
163
167
  log('fetch %s', key)
164
168
 
165
169
  const result = await pipe(
166
170
  [FetchRequest.encode({ identifier: key })],
167
171
  (source) => lp.encode(source),
168
- source,
172
+ stream,
169
173
  (source) => lp.decode(source),
170
174
  async function (source) {
171
175
  const buf = await first(source)
@@ -200,6 +204,7 @@ class DefaultFetchService implements Startable, FetchService {
200
204
 
201
205
  return result ?? null
202
206
  } finally {
207
+ signal.removeEventListener('abort', onAbort)
203
208
  if (stream != null) {
204
209
  await stream.close()
205
210
  }
package/src/ping/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { randomBytes } from '@libp2p/crypto'
2
2
  import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
- import { abortableDuplex } from 'abortable-iterator'
5
4
  import first from 'it-first'
6
5
  import { pipe } from 'it-pipe'
7
6
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
@@ -108,6 +107,7 @@ class DefaultPingService implements Startable, PingService {
108
107
  const data = randomBytes(PING_LENGTH)
109
108
  const connection = await this.components.connectionManager.openConnection(peer, options)
110
109
  let stream: Stream | undefined
110
+ let onAbort = (): void => {}
111
111
 
112
112
  options.signal = options.signal ?? AbortSignal.timeout(this.timeout)
113
113
 
@@ -117,12 +117,16 @@ class DefaultPingService implements Startable, PingService {
117
117
  runOnTransientConnection: this.runOnTransientConnection
118
118
  })
119
119
 
120
+ onAbort = () => {
121
+ stream?.abort(new CodeError('ping timeout', codes.ERR_TIMEOUT))
122
+ }
123
+
120
124
  // make stream abortable
121
- const source = abortableDuplex(stream, options.signal)
125
+ options.signal.addEventListener('abort', onAbort, { once: true })
122
126
 
123
127
  const result = await pipe(
124
128
  [data],
125
- source,
129
+ stream,
126
130
  async (source) => first(source)
127
131
  )
128
132
 
@@ -146,6 +150,7 @@ class DefaultPingService implements Startable, PingService {
146
150
 
147
151
  throw err
148
152
  } finally {
153
+ options.signal.removeEventListener('abort', onAbort)
149
154
  if (stream != null) {
150
155
  await stream.close()
151
156
  }
package/src/upgrader.ts CHANGED
@@ -3,7 +3,6 @@ import { CodeError } from '@libp2p/interface/errors'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import * as mss from '@libp2p/multistream-select'
5
5
  import { peerIdFromString } from '@libp2p/peer-id'
6
- import { abortableDuplex } from 'abortable-iterator'
7
6
  import { createConnection } from './connection/index.js'
8
7
  import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
9
8
  import { codes } from './errors.js'
@@ -165,16 +164,18 @@ export class DefaultUpgrader implements Upgrader {
165
164
 
166
165
  const signal = AbortSignal.timeout(this.inboundUpgradeTimeout)
167
166
 
167
+ const onAbort = (): void => {
168
+ maConn.abort(new CodeError('inbound upgrade timeout', codes.ERR_TIMEOUT))
169
+ }
170
+
171
+ signal.addEventListener('abort', onAbort, { once: true })
172
+
168
173
  try {
169
174
  // fails on node < 15.4
170
175
  setMaxListeners?.(Infinity, signal)
171
176
  } catch { }
172
177
 
173
178
  try {
174
- const abortableStream = abortableDuplex(maConn, signal)
175
- maConn.source = abortableStream.source
176
- maConn.sink = abortableStream.sink
177
-
178
179
  if ((await this.components.connectionGater.denyInboundConnection?.(maConn)) === true) {
179
180
  throw new CodeError('The multiaddr connection is blocked by gater.acceptConnection', codes.ERR_CONNECTION_INTERCEPTED)
180
181
  }
@@ -255,6 +256,8 @@ export class DefaultUpgrader implements Upgrader {
255
256
  transient: opts?.transient
256
257
  })
257
258
  } finally {
259
+ signal.removeEventListener('abort', onAbort)
260
+
258
261
  this.components.connectionManager.afterUpgradeInbound()
259
262
  }
260
263
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '0.46.8-a6be8f0f'
1
+ export const version = '0.46.9'
2
2
  export const name = 'libp2p'