libp2p 0.46.15 → 0.46.16-346ff5a2
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.
- package/README.md +20 -63
- package/dist/index.min.js +28 -28
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +3 -11
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +2 -7
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +1 -0
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +2 -6
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +2 -6
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +3 -11
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/dcutr/dcutr.d.ts.map +1 -1
- package/dist/src/dcutr/dcutr.js +1 -0
- package/dist/src/dcutr/dcutr.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +2 -6
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/consts.d.ts +1 -1
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/identify.d.ts.map +1 -1
- package/dist/src/identify/identify.js +24 -32
- package/dist/src/identify/identify.js.map +1 -1
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +3 -7
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/registrar.d.ts +7 -6
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +16 -41
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +3 -11
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +22 -23
- package/src/autonat/index.ts +3 -9
- package/src/circuit-relay/server/index.ts +2 -6
- package/src/circuit-relay/transport/discovery.ts +1 -0
- package/src/connection/index.ts +2 -5
- package/src/connection-manager/dial-queue.ts +2 -5
- package/src/connection-manager/utils.ts +3 -9
- package/src/dcutr/dcutr.ts +1 -0
- package/src/fetch/index.ts +2 -5
- package/src/identify/identify.ts +26 -33
- package/src/libp2p.ts +3 -6
- package/src/pnet/README.md +0 -4
- package/src/registrar.ts +19 -50
- package/src/upgrader.ts +3 -9
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -71
package/dist/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,kBAAkB,CAAA;AACzC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.16-346ff5a2",
|
|
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",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"scripts": {
|
|
101
101
|
"clean": "aegir clean",
|
|
102
102
|
"lint": "aegir lint",
|
|
103
|
-
"dep-check": "aegir dep-check
|
|
103
|
+
"dep-check": "aegir dep-check",
|
|
104
104
|
"prepublishOnly": "node scripts/update-version.js && npm run build",
|
|
105
105
|
"build": "aegir build",
|
|
106
106
|
"generate": "run-s generate:proto:*",
|
|
@@ -121,25 +121,24 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@achingbrain/nat-port-mapper": "^1.0.9",
|
|
124
|
-
"@libp2p/crypto": "
|
|
125
|
-
"@libp2p/interface": "
|
|
126
|
-
"@libp2p/interface-internal": "
|
|
127
|
-
"@libp2p/keychain": "
|
|
128
|
-
"@libp2p/logger": "
|
|
129
|
-
"@libp2p/multistream-select": "
|
|
130
|
-
"@libp2p/peer-collections": "
|
|
131
|
-
"@libp2p/peer-id": "
|
|
132
|
-
"@libp2p/peer-id-factory": "
|
|
133
|
-
"@libp2p/peer-record": "
|
|
134
|
-
"@libp2p/peer-store": "
|
|
135
|
-
"@libp2p/utils": "
|
|
124
|
+
"@libp2p/crypto": "2.0.6-346ff5a2",
|
|
125
|
+
"@libp2p/interface": "0.1.4-346ff5a2",
|
|
126
|
+
"@libp2p/interface-internal": "0.1.7-346ff5a2",
|
|
127
|
+
"@libp2p/keychain": "3.0.6-346ff5a2",
|
|
128
|
+
"@libp2p/logger": "3.0.4-346ff5a2",
|
|
129
|
+
"@libp2p/multistream-select": "4.0.4-346ff5a2",
|
|
130
|
+
"@libp2p/peer-collections": "4.0.6-346ff5a2",
|
|
131
|
+
"@libp2p/peer-id": "3.0.4-346ff5a2",
|
|
132
|
+
"@libp2p/peer-id-factory": "3.0.6-346ff5a2",
|
|
133
|
+
"@libp2p/peer-record": "6.0.7-346ff5a2",
|
|
134
|
+
"@libp2p/peer-store": "9.0.7-346ff5a2",
|
|
135
|
+
"@libp2p/utils": "4.0.5-346ff5a2",
|
|
136
136
|
"@multiformats/mafmt": "^12.1.2",
|
|
137
137
|
"@multiformats/multiaddr": "^12.1.5",
|
|
138
138
|
"@multiformats/multiaddr-matcher": "^1.0.0",
|
|
139
139
|
"any-signal": "^4.1.1",
|
|
140
140
|
"datastore-core": "^9.0.1",
|
|
141
141
|
"delay": "^6.0.0",
|
|
142
|
-
"events": "^3.3.0",
|
|
143
142
|
"interface-datastore": "^8.2.0",
|
|
144
143
|
"it-all": "^3.0.2",
|
|
145
144
|
"it-drain": "^3.0.2",
|
|
@@ -171,17 +170,17 @@
|
|
|
171
170
|
"@chainsafe/libp2p-gossipsub": "^10.0.0",
|
|
172
171
|
"@chainsafe/libp2p-noise": "^13.0.0",
|
|
173
172
|
"@chainsafe/libp2p-yamux": "^5.0.0",
|
|
174
|
-
"@libp2p/bootstrap": "
|
|
173
|
+
"@libp2p/bootstrap": "9.0.9-346ff5a2",
|
|
175
174
|
"@libp2p/daemon-client": "^7.0.0",
|
|
176
175
|
"@libp2p/daemon-server": "^6.0.0",
|
|
177
|
-
"@libp2p/floodsub": "
|
|
178
|
-
"@libp2p/interface-compliance-tests": "
|
|
176
|
+
"@libp2p/floodsub": "8.0.10-346ff5a2",
|
|
177
|
+
"@libp2p/interface-compliance-tests": "4.1.2-346ff5a2",
|
|
179
178
|
"@libp2p/interop": "^9.0.0",
|
|
180
|
-
"@libp2p/kad-dht": "
|
|
181
|
-
"@libp2p/mdns": "
|
|
182
|
-
"@libp2p/mplex": "
|
|
183
|
-
"@libp2p/tcp": "
|
|
184
|
-
"@libp2p/websockets": "
|
|
179
|
+
"@libp2p/kad-dht": "10.0.11-346ff5a2",
|
|
180
|
+
"@libp2p/mdns": "9.0.11-346ff5a2",
|
|
181
|
+
"@libp2p/mplex": "9.0.9-346ff5a2",
|
|
182
|
+
"@libp2p/tcp": "8.0.10-346ff5a2",
|
|
183
|
+
"@libp2p/websockets": "7.0.10-346ff5a2",
|
|
185
184
|
"@types/xsalsa20": "^1.1.0",
|
|
186
185
|
"aegir": "^41.0.2",
|
|
187
186
|
"execa": "^8.0.1",
|
package/src/autonat/index.ts
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { setMaxListeners } from 'events'
|
|
23
22
|
import { CodeError } from '@libp2p/interface/errors'
|
|
23
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
24
24
|
import { logger } from '@libp2p/logger'
|
|
25
25
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
26
26
|
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
@@ -164,10 +164,7 @@ class DefaultAutoNATService implements Startable {
|
|
|
164
164
|
|
|
165
165
|
// this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
|
|
166
166
|
// appearing in the console
|
|
167
|
-
|
|
168
|
-
// fails on node < 15.4
|
|
169
|
-
setMaxListeners?.(Infinity, signal)
|
|
170
|
-
} catch {}
|
|
167
|
+
setMaxListeners(Infinity, signal)
|
|
171
168
|
|
|
172
169
|
const ourHosts = this.components.addressManager.getAddresses()
|
|
173
170
|
.map(ma => ma.toOptions().host)
|
|
@@ -432,10 +429,7 @@ class DefaultAutoNATService implements Startable {
|
|
|
432
429
|
|
|
433
430
|
// this controller may be used while dialing lots of peers so prevent MaxListenersExceededWarning
|
|
434
431
|
// appearing in the console
|
|
435
|
-
|
|
436
|
-
// fails on node < 15.4
|
|
437
|
-
setMaxListeners?.(Infinity, signal)
|
|
438
|
-
} catch {}
|
|
432
|
+
setMaxListeners(Infinity, signal)
|
|
439
433
|
|
|
440
434
|
const self = this
|
|
441
435
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
|
-
import { TypedEventEmitter } from '@libp2p/interface/events'
|
|
1
|
+
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface/events'
|
|
3
2
|
import { logger } from '@libp2p/logger'
|
|
4
3
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
5
4
|
import { RecordEnvelope } from '@libp2p/peer-record'
|
|
@@ -134,10 +133,7 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
|
|
|
134
133
|
this.maxOutboundHopStreams = init.maxOutboundHopStreams
|
|
135
134
|
this.maxOutboundStopStreams = init.maxOutboundStopStreams ?? defaults.maxOutboundStopStreams
|
|
136
135
|
|
|
137
|
-
|
|
138
|
-
// fails on node < 15.4
|
|
139
|
-
setMaxListeners?.(Infinity, this.shutdownController.signal)
|
|
140
|
-
} catch { }
|
|
136
|
+
setMaxListeners(Infinity, this.shutdownController.signal)
|
|
141
137
|
|
|
142
138
|
if (init.advertise != null && init.advertise !== false) {
|
|
143
139
|
this.advertService = new AdvertService(components, init.advertise === true ? undefined : init.advertise)
|
|
@@ -57,6 +57,7 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
|
57
57
|
// register a topology listener for when new peers are encountered
|
|
58
58
|
// that support the hop protocol
|
|
59
59
|
this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC, {
|
|
60
|
+
notifyOnTransient: true,
|
|
60
61
|
onConnect: (peerId) => {
|
|
61
62
|
this.safeDispatchEvent('relay:discover', { detail: peerId })
|
|
62
63
|
}
|
package/src/connection/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { symbol } from '@libp2p/interface/connection'
|
|
3
2
|
import { CodeError } from '@libp2p/interface/errors'
|
|
3
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
4
4
|
import { logger } from '@libp2p/logger'
|
|
5
5
|
import type { AbortOptions } from '@libp2p/interface'
|
|
6
6
|
import type { Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions } from '@libp2p/interface/connection'
|
|
@@ -152,10 +152,7 @@ export class ConnectionImpl implements Connection {
|
|
|
152
152
|
|
|
153
153
|
options.signal = options?.signal ?? AbortSignal.timeout(CLOSE_TIMEOUT)
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
// fails on node < 15.4
|
|
157
|
-
setMaxListeners?.(Infinity, options.signal)
|
|
158
|
-
} catch { }
|
|
155
|
+
setMaxListeners(Infinity, options.signal)
|
|
159
156
|
|
|
160
157
|
try {
|
|
161
158
|
log.trace('closing all streams')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { AbortError, CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { defaultAddressSort } from '@libp2p/utils/address-sort'
|
|
5
5
|
import { type Multiaddr, type Resolver, resolvers } from '@multiformats/multiaddr'
|
|
@@ -96,10 +96,7 @@ export class DialQueue {
|
|
|
96
96
|
this.transportManager = components.transportManager
|
|
97
97
|
this.shutDownController = new AbortController()
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
// This emitter gets listened to a lot
|
|
101
|
-
setMaxListeners?.(Infinity, this.shutDownController.signal)
|
|
102
|
-
} catch {}
|
|
99
|
+
setMaxListeners(Infinity, this.shutDownController.signal)
|
|
103
100
|
|
|
104
101
|
this.pendingDialCount = components.metrics?.registerMetric('libp2p_dialler_pending_dials')
|
|
105
102
|
this.inProgressDialCount = components.metrics?.registerMetric('libp2p_dialler_in_progress_dials')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
1
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import { type ClearableSignal, anySignal } from 'any-signal'
|
|
@@ -55,10 +55,7 @@ export function combineSignals (...signals: Array<AbortSignal | undefined>): Cle
|
|
|
55
55
|
|
|
56
56
|
for (const sig of signals) {
|
|
57
57
|
if (sig != null) {
|
|
58
|
-
|
|
59
|
-
// fails on node < 15.4
|
|
60
|
-
setMaxListeners?.(Infinity, sig)
|
|
61
|
-
} catch { }
|
|
58
|
+
setMaxListeners(Infinity, sig)
|
|
62
59
|
sigs.push(sig)
|
|
63
60
|
}
|
|
64
61
|
}
|
|
@@ -66,10 +63,7 @@ export function combineSignals (...signals: Array<AbortSignal | undefined>): Cle
|
|
|
66
63
|
// let any signal abort the dial
|
|
67
64
|
const signal = anySignal(sigs)
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
// fails on node < 15.4
|
|
71
|
-
setMaxListeners?.(Infinity, signal)
|
|
72
|
-
} catch {}
|
|
66
|
+
setMaxListeners(Infinity, signal)
|
|
73
67
|
|
|
74
68
|
return signal
|
|
75
69
|
}
|
package/src/dcutr/dcutr.ts
CHANGED
|
@@ -72,6 +72,7 @@ export class DefaultDCUtRService implements Startable {
|
|
|
72
72
|
// register for notifications of when peers that support DCUtR connect
|
|
73
73
|
// nb. requires the identify service to be enabled
|
|
74
74
|
this.topologyId = await this.registrar.register(multicodec, {
|
|
75
|
+
notifyOnTransient: true,
|
|
75
76
|
onConnect: (peerId, connection) => {
|
|
76
77
|
if (!connection.transient) {
|
|
77
78
|
// the connection is already direct, no upgrade is required
|
package/src/fetch/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import first from 'it-first'
|
|
5
5
|
import * as lp from 'it-length-prefixed'
|
|
@@ -146,10 +146,7 @@ class DefaultFetchService implements Startable, FetchService {
|
|
|
146
146
|
log('using default timeout of %d ms', this.init.timeout)
|
|
147
147
|
signal = AbortSignal.timeout(this.init.timeout ?? DEFAULT_TIMEOUT)
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
// fails on node < 15.4
|
|
151
|
-
setMaxListeners?.(Infinity, signal)
|
|
152
|
-
} catch {}
|
|
149
|
+
setMaxListeners(Infinity, signal)
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
try {
|
package/src/identify/identify.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
5
5
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
|
|
@@ -187,10 +187,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
187
187
|
|
|
188
188
|
const signal = AbortSignal.timeout(this.timeout)
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
// fails on node < 15.4
|
|
192
|
-
setMaxListeners?.(Infinity, signal)
|
|
193
|
-
} catch {}
|
|
190
|
+
setMaxListeners(Infinity, signal)
|
|
194
191
|
|
|
195
192
|
try {
|
|
196
193
|
stream = await connection.newStream([this.identifyPushProtocolStr], {
|
|
@@ -318,22 +315,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
318
315
|
this.addressManager.addObservedAddr(cleanObservedAddr)
|
|
319
316
|
}
|
|
320
317
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const result: IdentifyResult = {
|
|
324
|
-
peerId: id,
|
|
325
|
-
protocolVersion: message.protocolVersion,
|
|
326
|
-
agentVersion: message.agentVersion,
|
|
327
|
-
publicKey: message.publicKey,
|
|
328
|
-
listenAddrs: message.listenAddrs.map(buf => multiaddr(buf)),
|
|
329
|
-
observedAddr: message.observedAddr == null ? undefined : multiaddr(message.observedAddr),
|
|
330
|
-
protocols: message.protocols,
|
|
331
|
-
signedPeerRecord
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
this.events.safeDispatchEvent('peer:identify', { detail: result })
|
|
335
|
-
|
|
336
|
-
return result
|
|
318
|
+
return this.#consumeIdentifyMessage(connection, message)
|
|
337
319
|
}
|
|
338
320
|
|
|
339
321
|
/**
|
|
@@ -345,10 +327,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
345
327
|
|
|
346
328
|
const signal = AbortSignal.timeout(this.timeout)
|
|
347
329
|
|
|
348
|
-
|
|
349
|
-
// fails on node < 15.4
|
|
350
|
-
setMaxListeners?.(Infinity, signal)
|
|
351
|
-
} catch {}
|
|
330
|
+
setMaxListeners(Infinity, signal)
|
|
352
331
|
|
|
353
332
|
try {
|
|
354
333
|
const publicKey = this.peerId.publicKey ?? new Uint8Array(0)
|
|
@@ -411,7 +390,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
411
390
|
const message = await pb.read(options)
|
|
412
391
|
await stream.close(options)
|
|
413
392
|
|
|
414
|
-
await this.#consumeIdentifyMessage(connection
|
|
393
|
+
await this.#consumeIdentifyMessage(connection, message)
|
|
415
394
|
} catch (err: any) {
|
|
416
395
|
log.error('received invalid message', err)
|
|
417
396
|
stream.abort(err)
|
|
@@ -421,8 +400,8 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
421
400
|
log('handled push from %p', connection.remotePeer)
|
|
422
401
|
}
|
|
423
402
|
|
|
424
|
-
async #consumeIdentifyMessage (
|
|
425
|
-
log('received identify from %p', remotePeer)
|
|
403
|
+
async #consumeIdentifyMessage (connection: Connection, message: Identify): Promise<IdentifyResult> {
|
|
404
|
+
log('received identify from %p', connection.remotePeer)
|
|
426
405
|
|
|
427
406
|
if (message == null) {
|
|
428
407
|
throw new Error('Message was null or undefined')
|
|
@@ -442,7 +421,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
442
421
|
|
|
443
422
|
// if the peer record has been sent, prefer the addresses in the record as they are signed by the remote peer
|
|
444
423
|
if (message.signedPeerRecord != null) {
|
|
445
|
-
log('received signedPeerRecord in push from %p', remotePeer)
|
|
424
|
+
log('received signedPeerRecord in push from %p', connection.remotePeer)
|
|
446
425
|
|
|
447
426
|
let peerRecordEnvelope = message.signedPeerRecord
|
|
448
427
|
const envelope = await RecordEnvelope.openAndCertify(peerRecordEnvelope, PeerRecord.DOMAIN)
|
|
@@ -454,7 +433,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
454
433
|
}
|
|
455
434
|
|
|
456
435
|
// Make sure remote peer is the one sending the record
|
|
457
|
-
if (!remotePeer.equals(peerRecord.peerId)) {
|
|
436
|
+
if (!connection.remotePeer.equals(peerRecord.peerId)) {
|
|
458
437
|
throw new Error('signing key does not match remote PeerId')
|
|
459
438
|
}
|
|
460
439
|
|
|
@@ -500,7 +479,7 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
500
479
|
addresses: peerRecord.multiaddrs
|
|
501
480
|
}
|
|
502
481
|
} else {
|
|
503
|
-
log('%p did not send a signed peer record', remotePeer)
|
|
482
|
+
log('%p did not send a signed peer record', connection.remotePeer)
|
|
504
483
|
}
|
|
505
484
|
|
|
506
485
|
if (message.agentVersion != null) {
|
|
@@ -511,9 +490,23 @@ export class DefaultIdentifyService implements Startable, IdentifyService {
|
|
|
511
490
|
peer.metadata.set('ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
|
|
512
491
|
}
|
|
513
492
|
|
|
514
|
-
await this.peerStore.patch(remotePeer, peer)
|
|
493
|
+
await this.peerStore.patch(connection.remotePeer, peer)
|
|
515
494
|
|
|
516
|
-
|
|
495
|
+
const result: IdentifyResult = {
|
|
496
|
+
peerId: connection.remotePeer,
|
|
497
|
+
protocolVersion: message.protocolVersion,
|
|
498
|
+
agentVersion: message.agentVersion,
|
|
499
|
+
publicKey: message.publicKey,
|
|
500
|
+
listenAddrs: message.listenAddrs.map(buf => multiaddr(buf)),
|
|
501
|
+
observedAddr: message.observedAddr == null ? undefined : multiaddr(message.observedAddr),
|
|
502
|
+
protocols: message.protocols,
|
|
503
|
+
signedPeerRecord: output,
|
|
504
|
+
connection
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
this.events.safeDispatchEvent('peer:identify', { detail: result })
|
|
508
|
+
|
|
509
|
+
return result
|
|
517
510
|
}
|
|
518
511
|
}
|
|
519
512
|
|
package/src/libp2p.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { unmarshalPublicKey } from '@libp2p/crypto/keys'
|
|
3
2
|
import { type ContentRouting, contentRouting } from '@libp2p/interface/content-routing'
|
|
4
3
|
import { CodeError } from '@libp2p/interface/errors'
|
|
5
|
-
import { TypedEventEmitter, CustomEvent } from '@libp2p/interface/events'
|
|
4
|
+
import { TypedEventEmitter, CustomEvent, setMaxListeners } from '@libp2p/interface/events'
|
|
6
5
|
import { peerDiscovery } from '@libp2p/interface/peer-discovery'
|
|
7
6
|
import { type PeerRouting, peerRouting } from '@libp2p/interface/peer-routing'
|
|
8
7
|
import { DefaultKeyChain } from '@libp2p/keychain'
|
|
@@ -70,10 +69,8 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
70
69
|
return internalResult || externalResult
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
setMaxListeners?.(Infinity, events)
|
|
76
|
-
} catch {}
|
|
72
|
+
// This emitter gets listened to a lot
|
|
73
|
+
setMaxListeners(Infinity, events)
|
|
77
74
|
|
|
78
75
|
this.#started = false
|
|
79
76
|
this.peerId = init.peerId
|
package/src/pnet/README.md
CHANGED
|
@@ -8,7 +8,6 @@ js-libp2p-pnet <!-- omit in toc -->
|
|
|
8
8
|
## Table of Contents <!-- omit in toc -->
|
|
9
9
|
|
|
10
10
|
- [Usage](#usage)
|
|
11
|
-
- [Examples](#examples)
|
|
12
11
|
- [Private Shared Keys](#private-shared-keys)
|
|
13
12
|
- [PSK Generation](#psk-generation)
|
|
14
13
|
- [From a module using libp2p](#from-a-module-using-libp2p)
|
|
@@ -32,9 +31,6 @@ const node = await createLibp2p({
|
|
|
32
31
|
})
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
## Examples
|
|
36
|
-
[Private Networks with IPFS](../../examples/pnet-ipfs)
|
|
37
|
-
|
|
38
34
|
## Private Shared Keys
|
|
39
35
|
|
|
40
36
|
Private Shared Keys are expected to be in the following format:
|
package/src/registrar.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CodeError } from '@libp2p/interface/errors'
|
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import merge from 'merge-options'
|
|
4
4
|
import { codes } from './errors.js'
|
|
5
|
-
import type { Libp2pEvents, PeerUpdate } from '@libp2p/interface'
|
|
5
|
+
import type { IdentifyResult, Libp2pEvents, PeerUpdate } from '@libp2p/interface'
|
|
6
6
|
import type { TypedEventTarget } from '@libp2p/interface/events'
|
|
7
7
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
8
8
|
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
@@ -37,11 +37,11 @@ export class DefaultRegistrar implements Registrar {
|
|
|
37
37
|
|
|
38
38
|
this._onDisconnect = this._onDisconnect.bind(this)
|
|
39
39
|
this._onPeerUpdate = this._onPeerUpdate.bind(this)
|
|
40
|
-
this.
|
|
40
|
+
this._onPeerIdentify = this._onPeerIdentify.bind(this)
|
|
41
41
|
|
|
42
42
|
this.components.events.addEventListener('peer:disconnect', this._onDisconnect)
|
|
43
|
-
this.components.events.addEventListener('peer:connect', this._onConnect)
|
|
44
43
|
this.components.events.addEventListener('peer:update', this._onPeerUpdate)
|
|
44
|
+
this.components.events.addEventListener('peer:identify', this._onPeerIdentify)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
getProtocols (): string[] {
|
|
@@ -183,52 +183,12 @@ export class DefaultRegistrar implements Registrar {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*/
|
|
189
|
-
_onConnect (evt: CustomEvent<PeerId>): void {
|
|
190
|
-
const remotePeer = evt.detail
|
|
191
|
-
|
|
192
|
-
void this.components.peerStore.get(remotePeer)
|
|
193
|
-
.then(peer => {
|
|
194
|
-
const connection = this.components.connectionManager.getConnections(peer.id)[0]
|
|
195
|
-
|
|
196
|
-
if (connection == null) {
|
|
197
|
-
log('peer %p connected but the connection manager did not have a connection', peer)
|
|
198
|
-
// peer disconnected while we were loading their details from the peer store
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
for (const protocol of peer.protocols) {
|
|
203
|
-
const topologies = this.topologies.get(protocol)
|
|
204
|
-
|
|
205
|
-
if (topologies == null) {
|
|
206
|
-
// no topologies are interested in this protocol
|
|
207
|
-
continue
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
for (const topology of topologies.values()) {
|
|
211
|
-
topology.onConnect?.(remotePeer, connection)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
})
|
|
215
|
-
.catch(err => {
|
|
216
|
-
if (err.code === codes.ERR_NOT_FOUND) {
|
|
217
|
-
// peer has not completed identify so they are not in the peer store
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
log.error('could not inform topologies of connecting peer %p', remotePeer, err)
|
|
222
|
-
})
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Check if a new peer support the multicodecs for this topology
|
|
186
|
+
* When a peer is updated, if they have removed supported protocols notify any
|
|
187
|
+
* topologies interested in the removed protocols.
|
|
227
188
|
*/
|
|
228
189
|
_onPeerUpdate (evt: CustomEvent<PeerUpdate>): void {
|
|
229
190
|
const { peer, previous } = evt.detail
|
|
230
191
|
const removed = (previous?.protocols ?? []).filter(protocol => !peer.protocols.includes(protocol))
|
|
231
|
-
const added = peer.protocols.filter(protocol => !(previous?.protocols ?? []).includes(protocol))
|
|
232
192
|
|
|
233
193
|
for (const protocol of removed) {
|
|
234
194
|
const topologies = this.topologies.get(protocol)
|
|
@@ -242,8 +202,18 @@ export class DefaultRegistrar implements Registrar {
|
|
|
242
202
|
topology.onDisconnect?.(peer.id)
|
|
243
203
|
}
|
|
244
204
|
}
|
|
205
|
+
}
|
|
245
206
|
|
|
246
|
-
|
|
207
|
+
/**
|
|
208
|
+
* After identify has completed and we have received the list of supported
|
|
209
|
+
* protocols, notify any topologies interested in those protocols.
|
|
210
|
+
*/
|
|
211
|
+
_onPeerIdentify (evt: CustomEvent<IdentifyResult>): void {
|
|
212
|
+
const protocols = evt.detail.protocols
|
|
213
|
+
const connection = evt.detail.connection
|
|
214
|
+
const peerId = evt.detail.peerId
|
|
215
|
+
|
|
216
|
+
for (const protocol of protocols) {
|
|
247
217
|
const topologies = this.topologies.get(protocol)
|
|
248
218
|
|
|
249
219
|
if (topologies == null) {
|
|
@@ -252,12 +222,11 @@ export class DefaultRegistrar implements Registrar {
|
|
|
252
222
|
}
|
|
253
223
|
|
|
254
224
|
for (const topology of topologies.values()) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (connection == null) {
|
|
225
|
+
if (connection.transient && topology.notifyOnTransient !== true) {
|
|
258
226
|
continue
|
|
259
227
|
}
|
|
260
|
-
|
|
228
|
+
|
|
229
|
+
topology.onConnect?.(peerId, connection)
|
|
261
230
|
}
|
|
262
231
|
}
|
|
263
232
|
}
|
package/src/upgrader.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setMaxListeners } from 'events'
|
|
2
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
+
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import * as mss from '@libp2p/multistream-select'
|
|
5
5
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
@@ -170,10 +170,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
170
170
|
|
|
171
171
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
// fails on node < 15.4
|
|
175
|
-
setMaxListeners?.(Infinity, signal)
|
|
176
|
-
} catch { }
|
|
173
|
+
setMaxListeners(Infinity, signal)
|
|
177
174
|
|
|
178
175
|
try {
|
|
179
176
|
if ((await this.components.connectionGater.denyInboundConnection?.(maConn)) === true) {
|
|
@@ -444,10 +441,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
444
441
|
|
|
445
442
|
options.signal = AbortSignal.timeout(30000)
|
|
446
443
|
|
|
447
|
-
|
|
448
|
-
// fails on node < 15.4
|
|
449
|
-
setMaxListeners?.(Infinity, options.signal)
|
|
450
|
-
} catch { }
|
|
444
|
+
setMaxListeners(Infinity, options.signal)
|
|
451
445
|
}
|
|
452
446
|
|
|
453
447
|
const { stream, protocol } = await mss.select(muxedStream, protocols, options)
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.46.
|
|
1
|
+
export const version = '0.46.16-346ff5a2'
|
|
2
2
|
export const name = 'libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
}
|