libp2p 0.37.2 → 0.37.3-5371729
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/dist/src/address-manager/index.d.ts +2 -2
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/circuit/auto-relay.d.ts +4 -4
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.d.ts +2 -2
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.d.ts +1 -1
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts +1 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/index.d.ts +2 -2
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/listener.d.ts +3 -3
- package/dist/src/circuit/listener.d.ts.map +1 -1
- package/dist/src/circuit/transport.d.ts +5 -5
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/circuit/transport.js +2 -2
- package/dist/src/circuit/transport.js.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts +2 -2
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts +1 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.d.ts +5 -5
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +1 -1
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +9 -9
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +42 -32
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +4 -4
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/utils.d.ts +2 -2
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +3 -3
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.d.ts +5 -5
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dummy-dht.d.ts +3 -3
- package/dist/src/dht/dummy-dht.d.ts.map +1 -1
- package/dist/src/dht/dummy-dht.js +1 -1
- package/dist/src/dht/dummy-dht.js.map +1 -1
- package/dist/src/fetch/index.d.ts +4 -4
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/get-peer.d.ts +2 -2
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +1 -1
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/identify/index.d.ts +3 -7
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +7 -20
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +15 -15
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/insecure/index.d.ts +2 -2
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/keychain/index.d.ts +2 -2
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/libp2p.d.ts +13 -13
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +13 -3
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/metrics/index.d.ts +2 -2
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/moving-average.d.ts +1 -1
- package/dist/src/metrics/moving-average.d.ts.map +1 -1
- package/dist/src/metrics/stats.d.ts +1 -1
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/nat-manager.d.ts +1 -1
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/peer-record-updater.d.ts +1 -1
- package/dist/src/peer-record-updater.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +4 -4
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/ping/index.d.ts +3 -3
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/pnet/index.d.ts +1 -2
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js.map +1 -1
- package/dist/src/pubsub/dummy-pubsub.d.ts +2 -2
- package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +8 -8
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +62 -43
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +3 -3
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/upgrader.d.ts +6 -6
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +12 -2
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +50 -28
- package/src/address-manager/index.ts +2 -2
- package/src/circuit/auto-relay.ts +4 -4
- package/src/circuit/circuit/hop.ts +2 -2
- package/src/circuit/circuit/stop.ts +1 -1
- package/src/circuit/circuit/stream-handler.ts +1 -1
- package/src/circuit/index.ts +2 -2
- package/src/circuit/listener.ts +3 -3
- package/src/circuit/transport.ts +5 -5
- package/src/connection-manager/auto-dialler.ts +1 -1
- package/src/connection-manager/dialer/auto-dialer.ts +2 -2
- package/src/connection-manager/dialer/dial-request.ts +1 -1
- package/src/connection-manager/dialer/index.ts +5 -5
- package/src/connection-manager/index.ts +55 -39
- package/src/content-routing/index.ts +2 -2
- package/src/content-routing/utils.ts +2 -2
- package/src/dht/dht-content-routing.ts +2 -2
- package/src/dht/dht-peer-routing.ts +3 -3
- package/src/dht/dummy-dht.ts +3 -3
- package/src/fetch/index.ts +4 -4
- package/src/get-peer.ts +3 -3
- package/src/identify/index.ts +10 -26
- package/src/index.ts +15 -15
- package/src/insecure/index.ts +3 -3
- package/src/keychain/index.ts +2 -2
- package/src/libp2p.ts +30 -14
- package/src/metrics/index.ts +2 -2
- package/src/metrics/moving-average.ts +1 -1
- package/src/metrics/stats.ts +1 -1
- package/src/nat-manager.ts +1 -1
- package/src/peer-record-updater.ts +1 -1
- package/src/peer-routing.ts +4 -4
- package/src/ping/index.ts +3 -3
- package/src/pnet/index.ts +1 -2
- package/src/pubsub/dummy-pubsub.ts +2 -2
- package/src/registrar.ts +78 -54
- package/src/transport-manager.ts +3 -3
- package/src/upgrader.ts +20 -8
package/src/fetch/index.ts
CHANGED
|
@@ -5,11 +5,11 @@ import * as lp from 'it-length-prefixed'
|
|
|
5
5
|
import { FetchRequest, FetchResponse } from './pb/proto.js'
|
|
6
6
|
import { handshake } from 'it-handshake'
|
|
7
7
|
import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
|
|
8
|
-
import type { PeerId } from '@libp2p/
|
|
8
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
9
9
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
10
|
-
import type { Stream } from '@libp2p/
|
|
11
|
-
import type { IncomingStreamData } from '@libp2p/
|
|
12
|
-
import type { Components } from '@libp2p/
|
|
10
|
+
import type { Stream } from '@libp2p/interface-connection'
|
|
11
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar'
|
|
12
|
+
import type { Components } from '@libp2p/components'
|
|
13
13
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
14
14
|
import type { Duplex } from 'it-stream-types'
|
|
15
15
|
import { abortableDuplex } from 'abortable-iterator'
|
package/src/get-peer.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { peerIdFromString } from '@libp2p/peer-id'
|
|
|
2
2
|
import { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import errCode from 'err-code'
|
|
4
4
|
import { codes } from './errors.js'
|
|
5
|
-
import { isPeerId } from '@libp2p/
|
|
6
|
-
import type { PeerId } from '@libp2p/
|
|
7
|
-
import type { PeerInfo } from '@libp2p/
|
|
5
|
+
import { isPeerId } from '@libp2p/interface-peer-id'
|
|
6
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
8
8
|
|
|
9
9
|
function peerIdFromMultiaddr (ma: Multiaddr) {
|
|
10
10
|
const idStr = ma.getPeerId()
|
package/src/identify/index.ts
CHANGED
|
@@ -18,11 +18,11 @@ import {
|
|
|
18
18
|
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
|
|
19
19
|
} from './consts.js'
|
|
20
20
|
import { codes } from '../errors.js'
|
|
21
|
-
import type { IncomingStreamData } from '@libp2p/
|
|
22
|
-
import type { Connection, Stream } from '@libp2p/
|
|
21
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar'
|
|
22
|
+
import type { Connection, Stream } from '@libp2p/interface-connection'
|
|
23
23
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
24
24
|
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
25
|
-
import type { Components } from '@libp2p/
|
|
25
|
+
import type { Components } from '@libp2p/components'
|
|
26
26
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
27
27
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
28
28
|
import { abortableDuplex } from 'abortable-iterator'
|
|
@@ -79,8 +79,6 @@ export class IdentifyService implements Startable {
|
|
|
79
79
|
this.started = false
|
|
80
80
|
this.init = init
|
|
81
81
|
|
|
82
|
-
this.handleMessage = this.handleMessage.bind(this)
|
|
83
|
-
|
|
84
82
|
this.identifyProtocolStr = `/${init.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}`
|
|
85
83
|
this.identifyPushProtocolStr = `/${init.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}`
|
|
86
84
|
|
|
@@ -127,11 +125,13 @@ export class IdentifyService implements Startable {
|
|
|
127
125
|
await this.components.getPeerStore().metadataBook.setValue(this.components.getPeerId(), 'AgentVersion', uint8ArrayFromString(this.host.agentVersion))
|
|
128
126
|
await this.components.getPeerStore().metadataBook.setValue(this.components.getPeerId(), 'ProtocolVersion', uint8ArrayFromString(this.host.protocolVersion))
|
|
129
127
|
|
|
130
|
-
await this.components.getRegistrar().handle(
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
await this.components.getRegistrar().handle(this.identifyProtocolStr, (data) => {
|
|
129
|
+
void this._handleIdentify(data).catch(err => {
|
|
130
|
+
log.error(err)
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
await this.components.getRegistrar().handle(this.identifyPushProtocolStr, (data) => {
|
|
134
|
+
void this._handlePush(data).catch(err => {
|
|
135
135
|
log.error(err)
|
|
136
136
|
})
|
|
137
137
|
})
|
|
@@ -353,22 +353,6 @@ export class IdentifyService implements Startable {
|
|
|
353
353
|
// this.components.getAddressManager().addObservedAddr(observedAddr)
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
/**
|
|
357
|
-
* A handler to register with Libp2p to process identify messages
|
|
358
|
-
*/
|
|
359
|
-
handleMessage (data: IncomingStreamData) {
|
|
360
|
-
const { protocol } = data
|
|
361
|
-
|
|
362
|
-
switch (protocol) {
|
|
363
|
-
case this.identifyProtocolStr:
|
|
364
|
-
return this._handleIdentify(data)
|
|
365
|
-
case this.identifyPushProtocolStr:
|
|
366
|
-
return this._handlePush(data)
|
|
367
|
-
default:
|
|
368
|
-
log.error('cannot handle unknown protocol %s', protocol)
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
356
|
/**
|
|
373
357
|
* Sends the `Identify` response with the Signed Peer Record
|
|
374
358
|
* to the requesting peer over the given `connection`
|
package/src/index.ts
CHANGED
|
@@ -5,23 +5,23 @@ import type { Startable } from '@libp2p/interfaces/startable'
|
|
|
5
5
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
6
6
|
import type { FaultTolerance } from './transport-manager.js'
|
|
7
7
|
import type { IdentifyServiceInit } from './identify/index.js'
|
|
8
|
-
import type { DualDHT } from '@libp2p/
|
|
8
|
+
import type { DualDHT } from '@libp2p/interface-dht'
|
|
9
9
|
import type { Datastore } from 'interface-datastore'
|
|
10
|
-
import type { PeerStore, PeerStoreInit } from '@libp2p/
|
|
11
|
-
import type { PeerId } from '@libp2p/
|
|
10
|
+
import type { PeerStore, PeerStoreInit } from '@libp2p/interface-peer-store'
|
|
11
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
12
12
|
import type { AutoRelayConfig, RelayAdvertiseConfig } from './circuit/index.js'
|
|
13
|
-
import type { PeerDiscovery } from '@libp2p/
|
|
14
|
-
import type { Connection, ConnectionGater, ConnectionProtector, ProtocolStream } from '@libp2p/
|
|
15
|
-
import type { Transport } from '@libp2p/
|
|
16
|
-
import type { StreamMuxerFactory } from '@libp2p/
|
|
17
|
-
import type { ConnectionEncrypter } from '@libp2p/
|
|
18
|
-
import type { PeerRouting } from '@libp2p/
|
|
19
|
-
import type { ContentRouting } from '@libp2p/
|
|
20
|
-
import type { PubSub } from '@libp2p/
|
|
21
|
-
import type { Registrar, StreamHandler } from '@libp2p/
|
|
22
|
-
import type { ConnectionManager } from '@libp2p/
|
|
23
|
-
import type { Metrics, MetricsInit } from '@libp2p/
|
|
24
|
-
import type { PeerInfo } from '@libp2p/
|
|
13
|
+
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
|
|
14
|
+
import type { Connection, ConnectionGater, ConnectionProtector, ProtocolStream } from '@libp2p/interface-connection'
|
|
15
|
+
import type { Transport } from '@libp2p/interface-transport'
|
|
16
|
+
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
17
|
+
import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
|
|
18
|
+
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
19
|
+
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
20
|
+
import type { PubSub } from '@libp2p/interface-pubsub'
|
|
21
|
+
import type { Registrar, StreamHandler } from '@libp2p/interface-registrar'
|
|
22
|
+
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
23
|
+
import type { Metrics, MetricsInit } from '@libp2p/interface-metrics'
|
|
24
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
25
25
|
import type { KeyChain } from './keychain/index.js'
|
|
26
26
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
27
27
|
import type { PingServiceInit } from './ping/index.js'
|
package/src/insecure/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { handshake } from 'it-handshake'
|
|
3
3
|
import * as lp from 'it-length-prefixed'
|
|
4
|
-
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/
|
|
4
|
+
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface-connection-encrypter/errors'
|
|
5
5
|
import { Exchange, KeyType } from './pb/proto.js'
|
|
6
|
-
import type { PeerId } from '@libp2p/
|
|
6
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
7
7
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
8
|
-
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/
|
|
8
|
+
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
9
9
|
import type { Duplex } from 'it-stream-types'
|
|
10
10
|
|
|
11
11
|
const log = logger('libp2p:plaintext')
|
package/src/keychain/index.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { codes } from '../errors.js'
|
|
|
10
10
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
11
11
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
12
12
|
import { generateKeyPair, importKey, unmarshalPrivateKey } from '@libp2p/crypto/keys'
|
|
13
|
-
import type { PeerId } from '@libp2p/
|
|
14
|
-
import type { Components } from '@libp2p/
|
|
13
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
14
|
+
import type { Components } from '@libp2p/components'
|
|
15
15
|
import { pbkdf2, randomBytes } from '@libp2p/crypto'
|
|
16
16
|
|
|
17
17
|
const log = logger('libp2p:keychain')
|
package/src/libp2p.ts
CHANGED
|
@@ -27,25 +27,25 @@ import { DHTPeerRouting } from './dht/dht-peer-routing.js'
|
|
|
27
27
|
import { PersistentPeerStore } from '@libp2p/peer-store'
|
|
28
28
|
import { DHTContentRouting } from './dht/dht-content-routing.js'
|
|
29
29
|
import { AutoDialer } from './connection-manager/dialer/auto-dialer.js'
|
|
30
|
-
import { Initializable, Components, isInitializable } from '@libp2p/
|
|
31
|
-
import type { PeerId } from '@libp2p/
|
|
32
|
-
import type { Connection } from '@libp2p/
|
|
33
|
-
import type { PeerRouting } from '@libp2p/
|
|
34
|
-
import type { ContentRouting } from '@libp2p/
|
|
35
|
-
import type { PubSub } from '@libp2p/
|
|
36
|
-
import type { Registrar, StreamHandler } from '@libp2p/
|
|
37
|
-
import type { ConnectionManager } from '@libp2p/
|
|
38
|
-
import type { PeerInfo } from '@libp2p/
|
|
30
|
+
import { Initializable, Components, isInitializable } from '@libp2p/components'
|
|
31
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
32
|
+
import type { Connection } from '@libp2p/interface-connection'
|
|
33
|
+
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
34
|
+
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
35
|
+
import type { PubSub } from '@libp2p/interface-pubsub'
|
|
36
|
+
import type { Registrar, StreamHandler } from '@libp2p/interface-registrar'
|
|
37
|
+
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
38
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
39
39
|
import type { Libp2p, Libp2pEvents, Libp2pInit, Libp2pOptions } from './index.js'
|
|
40
40
|
import { validateConfig } from './config.js'
|
|
41
41
|
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
42
|
-
import type { PeerStore } from '@libp2p/
|
|
43
|
-
import type { DualDHT } from '@libp2p/
|
|
42
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
43
|
+
import type { DualDHT } from '@libp2p/interface-dht'
|
|
44
44
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
45
45
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
46
46
|
import errCode from 'err-code'
|
|
47
47
|
import { unmarshalPublicKey } from '@libp2p/crypto/keys'
|
|
48
|
-
import type { Metrics } from '@libp2p/
|
|
48
|
+
import type { Metrics } from '@libp2p/interface-metrics'
|
|
49
49
|
import { DummyDHT } from './dht/dummy-dht.js'
|
|
50
50
|
import { DummyPubSub } from './pubsub/dummy-pubsub.js'
|
|
51
51
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
@@ -491,11 +491,27 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
async handle (protocols: string | string[], handler: StreamHandler): Promise<void> {
|
|
494
|
-
|
|
494
|
+
if (!Array.isArray(protocols)) {
|
|
495
|
+
protocols = [protocols]
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
await Promise.all(
|
|
499
|
+
protocols.map(async protocol => {
|
|
500
|
+
await this.components.getRegistrar().handle(protocol, handler)
|
|
501
|
+
})
|
|
502
|
+
)
|
|
495
503
|
}
|
|
496
504
|
|
|
497
505
|
async unhandle (protocols: string[] | string): Promise<void> {
|
|
498
|
-
|
|
506
|
+
if (!Array.isArray(protocols)) {
|
|
507
|
+
protocols = [protocols]
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
await Promise.all(
|
|
511
|
+
protocols.map(async protocol => {
|
|
512
|
+
await this.components.getRegistrar().unhandle(protocol)
|
|
513
|
+
})
|
|
514
|
+
)
|
|
499
515
|
}
|
|
500
516
|
|
|
501
517
|
/**
|
package/src/metrics/index.ts
CHANGED
|
@@ -3,8 +3,8 @@ import each from 'it-foreach'
|
|
|
3
3
|
import LRU from 'hashlru'
|
|
4
4
|
import { METRICS as defaultOptions } from '../constants.js'
|
|
5
5
|
import { DefaultStats, StatsInit } from './stats.js'
|
|
6
|
-
import type { ComponentMetricsUpdate, Metrics, Stats, TrackStreamOptions } from '@libp2p/
|
|
7
|
-
import type { PeerId } from '@libp2p/
|
|
6
|
+
import type { ComponentMetricsUpdate, Metrics, Stats, TrackStreamOptions } from '@libp2p/interface-metrics'
|
|
7
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
8
8
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
9
9
|
import type { Duplex } from 'it-stream-types'
|
|
10
10
|
|
package/src/metrics/stats.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
|
2
2
|
import { createMovingAverage } from './moving-average.js'
|
|
3
3
|
// @ts-expect-error no types
|
|
4
4
|
import retimer from 'retimer'
|
|
5
|
-
import type { MovingAverages, Stats, TransferStats } from '@libp2p/
|
|
5
|
+
import type { MovingAverages, Stats, TransferStats } from '@libp2p/interface-metrics'
|
|
6
6
|
|
|
7
7
|
export interface StatsEvents {
|
|
8
8
|
'update': CustomEvent<TransferStats>
|
package/src/nat-manager.ts
CHANGED
|
@@ -8,7 +8,7 @@ import errCode from 'err-code'
|
|
|
8
8
|
import { codes } from './errors.js'
|
|
9
9
|
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
|
|
10
10
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
11
|
-
import type { Components } from '@libp2p/
|
|
11
|
+
import type { Components } from '@libp2p/components'
|
|
12
12
|
|
|
13
13
|
const log = logger('libp2p:nat')
|
|
14
14
|
const DEFAULT_TTL = 7200
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
|
|
2
|
-
import type { Components } from '@libp2p/
|
|
2
|
+
import type { Components } from '@libp2p/components'
|
|
3
3
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
4
4
|
import { logger } from '@libp2p/logger'
|
|
5
5
|
import { protocols } from '@multiformats/multiaddr'
|
package/src/peer-routing.ts
CHANGED
|
@@ -18,12 +18,12 @@ import {
|
|
|
18
18
|
// @ts-expect-error module with no types
|
|
19
19
|
} from 'set-delayed-interval'
|
|
20
20
|
import { setMaxListeners } from 'events'
|
|
21
|
-
import type { PeerId } from '@libp2p/
|
|
22
|
-
import type { PeerRouting } from '@libp2p/
|
|
21
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
22
|
+
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
23
23
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
24
24
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
25
|
-
import type { PeerInfo } from '@libp2p/
|
|
26
|
-
import type { Components } from '@libp2p/
|
|
25
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
26
|
+
import type { Components } from '@libp2p/components'
|
|
27
27
|
|
|
28
28
|
const log = logger('libp2p:peer-routing')
|
|
29
29
|
|
package/src/ping/index.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { pipe } from 'it-pipe'
|
|
|
6
6
|
import first from 'it-first'
|
|
7
7
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
8
8
|
import { PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION } from './constants.js'
|
|
9
|
-
import type { IncomingStreamData } from '@libp2p/
|
|
10
|
-
import type { PeerId } from '@libp2p/
|
|
9
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar'
|
|
10
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
11
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
12
|
-
import type { Components } from '@libp2p/
|
|
12
|
+
import type { Components } from '@libp2p/components'
|
|
13
13
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
14
14
|
import type { Duplex } from 'it-stream-types'
|
|
15
15
|
import { abortableDuplex } from 'abortable-iterator'
|
package/src/pnet/index.ts
CHANGED
|
@@ -12,8 +12,7 @@ import {
|
|
|
12
12
|
} from './crypto.js'
|
|
13
13
|
import { handshake } from 'it-handshake'
|
|
14
14
|
import { NONCE_LENGTH } from './key-generator.js'
|
|
15
|
-
import type { MultiaddrConnection } from '@libp2p/
|
|
16
|
-
import type { ConnectionProtector } from '@libp2p/interfaces/connection'
|
|
15
|
+
import type { ConnectionProtector, MultiaddrConnection } from '@libp2p/interface-connection'
|
|
17
16
|
|
|
18
17
|
const log = logger('libp2p:pnet')
|
|
19
18
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
2
|
-
import type { PeerId } from '@libp2p/
|
|
3
|
-
import type { PublishResult, PubSub, PubSubEvents, StrictNoSign, StrictSign } from '@libp2p/
|
|
2
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
3
|
+
import type { PublishResult, PubSub, PubSubEvents, StrictNoSign, StrictSign } from '@libp2p/interface-pubsub'
|
|
4
4
|
import errCode from 'err-code'
|
|
5
5
|
import { messages, codes } from '../errors.js'
|
|
6
6
|
|
package/src/registrar.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import errCode from 'err-code'
|
|
3
3
|
import { codes } from './errors.js'
|
|
4
|
-
import { isTopology,
|
|
5
|
-
import
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
4
|
+
import { isTopology, StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-registrar'
|
|
5
|
+
import merge from 'merge-options'
|
|
6
|
+
import type { Registrar, StreamHandler, Topology } from '@libp2p/interface-registrar'
|
|
7
|
+
import type { PeerProtocolsChangeData } from '@libp2p/interface-peer-store'
|
|
8
|
+
import type { Connection } from '@libp2p/interface-connection'
|
|
9
|
+
import type { Components } from '@libp2p/components'
|
|
9
10
|
|
|
10
11
|
const log = logger('libp2p:registrar')
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (topologyProtocols.includes(peerProtocol)) {
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
13
|
+
const DEFAULT_MAX_INCOMING_STREAMS = 1
|
|
14
|
+
const DEFAULT_MAX_OUTGOING_STREAMS = 1
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* Responsible for notifying registered protocols of events in the network.
|
|
24
18
|
*/
|
|
25
19
|
export class DefaultRegistrar implements Registrar {
|
|
26
|
-
private readonly topologies: Map<string,
|
|
27
|
-
private readonly handlers: Map<string,
|
|
20
|
+
private readonly topologies: Map<string, Map<string, Topology>>
|
|
21
|
+
private readonly handlers: Map<string, StreamHandlerRecord>
|
|
28
22
|
private readonly components: Components
|
|
29
23
|
|
|
30
24
|
constructor (components: Components) {
|
|
@@ -42,17 +36,10 @@ export class DefaultRegistrar implements Registrar {
|
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
getProtocols () {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
for (const protocol of this.handlers.keys()) {
|
|
52
|
-
protocols.add(protocol)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return Array.from(protocols).sort()
|
|
39
|
+
return Array.from(new Set<string>([
|
|
40
|
+
...this.topologies.keys(),
|
|
41
|
+
...this.handlers.keys()
|
|
42
|
+
])).sort()
|
|
56
43
|
}
|
|
57
44
|
|
|
58
45
|
getHandler (protocol: string) {
|
|
@@ -66,33 +53,37 @@ export class DefaultRegistrar implements Registrar {
|
|
|
66
53
|
}
|
|
67
54
|
|
|
68
55
|
getTopologies (protocol: string) {
|
|
69
|
-
const
|
|
56
|
+
const topologies = this.topologies.get(protocol)
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
output.push(topology)
|
|
74
|
-
}
|
|
58
|
+
if (topologies == null) {
|
|
59
|
+
return []
|
|
75
60
|
}
|
|
76
61
|
|
|
77
|
-
return
|
|
62
|
+
return [
|
|
63
|
+
...topologies.values()
|
|
64
|
+
]
|
|
78
65
|
}
|
|
79
66
|
|
|
80
67
|
/**
|
|
81
68
|
* Registers the `handler` for each protocol
|
|
82
69
|
*/
|
|
83
|
-
async handle (
|
|
84
|
-
|
|
70
|
+
async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void> {
|
|
71
|
+
if (this.handlers.has(protocol)) {
|
|
72
|
+
throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED)
|
|
73
|
+
}
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
const options = merge({
|
|
76
|
+
maxIncomingStreams: DEFAULT_MAX_INCOMING_STREAMS,
|
|
77
|
+
maxOutgoingStreams: DEFAULT_MAX_OUTGOING_STREAMS
|
|
78
|
+
}, opts)
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
this.handlers.set(protocol, {
|
|
81
|
+
handler,
|
|
82
|
+
options
|
|
83
|
+
})
|
|
93
84
|
|
|
94
85
|
// Add new protocols to self protocols in the Protobook
|
|
95
|
-
await this.components.getPeerStore().protoBook.add(this.components.getPeerId(),
|
|
86
|
+
await this.components.getPeerStore().protoBook.add(this.components.getPeerId(), [protocol])
|
|
96
87
|
}
|
|
97
88
|
|
|
98
89
|
/**
|
|
@@ -113,7 +104,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
113
104
|
/**
|
|
114
105
|
* Register handlers for a set of multicodecs given
|
|
115
106
|
*/
|
|
116
|
-
async register (
|
|
107
|
+
async register (protocol: string, topology: Topology): Promise<string> {
|
|
117
108
|
if (!isTopology(topology)) {
|
|
118
109
|
log.error('topology must be an instance of interfaces/topology')
|
|
119
110
|
throw errCode(new Error('topology must be an instance of interfaces/topology'), codes.ERR_INVALID_PARAMETERS)
|
|
@@ -122,10 +113,14 @@ export class DefaultRegistrar implements Registrar {
|
|
|
122
113
|
// Create topology
|
|
123
114
|
const id = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
|
|
124
115
|
|
|
125
|
-
this.topologies.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
let topologies = this.topologies.get(protocol)
|
|
117
|
+
|
|
118
|
+
if (topologies == null) {
|
|
119
|
+
topologies = new Map<string, Topology>()
|
|
120
|
+
this.topologies.set(protocol, topologies)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
topologies.set(id, topology)
|
|
129
124
|
|
|
130
125
|
// Set registrar
|
|
131
126
|
await topology.setRegistrar(this)
|
|
@@ -137,7 +132,15 @@ export class DefaultRegistrar implements Registrar {
|
|
|
137
132
|
* Unregister topology
|
|
138
133
|
*/
|
|
139
134
|
unregister (id: string) {
|
|
140
|
-
this.topologies.
|
|
135
|
+
for (const [protocol, topologies] of this.topologies.entries()) {
|
|
136
|
+
if (topologies.has(id)) {
|
|
137
|
+
topologies.delete(id)
|
|
138
|
+
|
|
139
|
+
if (topologies.size === 0) {
|
|
140
|
+
this.topologies.delete(protocol)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
/**
|
|
@@ -148,8 +151,15 @@ export class DefaultRegistrar implements Registrar {
|
|
|
148
151
|
|
|
149
152
|
void this.components.getPeerStore().protoBook.get(connection.remotePeer)
|
|
150
153
|
.then(peerProtocols => {
|
|
151
|
-
for (const
|
|
152
|
-
|
|
154
|
+
for (const protocol of peerProtocols) {
|
|
155
|
+
const topologies = this.topologies.get(protocol)
|
|
156
|
+
|
|
157
|
+
if (topologies == null) {
|
|
158
|
+
// no topologies are interested in this protocol
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const topology of topologies.values()) {
|
|
153
163
|
topology.onDisconnect(connection.remotePeer)
|
|
154
164
|
}
|
|
155
165
|
}
|
|
@@ -168,14 +178,28 @@ export class DefaultRegistrar implements Registrar {
|
|
|
168
178
|
const removed = oldProtocols.filter(protocol => !protocols.includes(protocol))
|
|
169
179
|
const added = protocols.filter(protocol => !oldProtocols.includes(protocol))
|
|
170
180
|
|
|
171
|
-
for (const
|
|
172
|
-
|
|
181
|
+
for (const protocol of removed) {
|
|
182
|
+
const topologies = this.topologies.get(protocol)
|
|
183
|
+
|
|
184
|
+
if (topologies == null) {
|
|
185
|
+
// no topologies are interested in this protocol
|
|
186
|
+
continue
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (const topology of topologies.values()) {
|
|
173
190
|
topology.onDisconnect(peerId)
|
|
174
191
|
}
|
|
175
192
|
}
|
|
176
193
|
|
|
177
|
-
for (const
|
|
178
|
-
|
|
194
|
+
for (const protocol of added) {
|
|
195
|
+
const topologies = this.topologies.get(protocol)
|
|
196
|
+
|
|
197
|
+
if (topologies == null) {
|
|
198
|
+
// no topologies are interested in this protocol
|
|
199
|
+
continue
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (const topology of topologies.values()) {
|
|
179
203
|
const connection = this.components.getConnectionManager().getConnections(peerId)[0]
|
|
180
204
|
|
|
181
205
|
if (connection == null) {
|
package/src/transport-manager.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import pSettle from 'p-settle'
|
|
3
3
|
import { codes } from './errors.js'
|
|
4
4
|
import errCode from 'err-code'
|
|
5
|
-
import type { Listener, Transport, TransportManager, TransportManagerEvents } from '@libp2p/
|
|
5
|
+
import type { Listener, Transport, TransportManager, TransportManagerEvents } from '@libp2p/interface-transport'
|
|
6
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
7
|
-
import type { Connection } from '@libp2p/
|
|
7
|
+
import type { Connection } from '@libp2p/interface-connection'
|
|
8
8
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
9
9
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
10
10
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
11
|
-
import type { Components } from '@libp2p/
|
|
11
|
+
import type { Components } from '@libp2p/components'
|
|
12
12
|
import { trackedMap } from '@libp2p/tracked-map'
|
|
13
13
|
|
|
14
14
|
const log = logger('libp2p:transports')
|
package/src/upgrader.ts
CHANGED
|
@@ -8,13 +8,13 @@ import { codes } from './errors.js'
|
|
|
8
8
|
import { createConnection } from '@libp2p/connection'
|
|
9
9
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
10
10
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
11
|
-
import type { Connection, ProtocolStream, Stream } from '@libp2p/
|
|
12
|
-
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/
|
|
13
|
-
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/
|
|
14
|
-
import type { PeerId } from '@libp2p/
|
|
15
|
-
import type {
|
|
11
|
+
import type { MultiaddrConnection, Connection, ProtocolStream, Stream } from '@libp2p/interface-connection'
|
|
12
|
+
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
13
|
+
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
14
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
15
|
+
import type { Upgrader, UpgraderEvents } from '@libp2p/interface-transport'
|
|
16
16
|
import type { Duplex } from 'it-stream-types'
|
|
17
|
-
import
|
|
17
|
+
import { Components, isInitializable } from '@libp2p/components'
|
|
18
18
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
19
19
|
|
|
20
20
|
const log = logger('libp2p:upgrader')
|
|
@@ -272,7 +272,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
272
272
|
|
|
273
273
|
if (muxerFactory != null) {
|
|
274
274
|
// Create the muxer
|
|
275
|
-
muxer = muxerFactory.createStreamMuxer(
|
|
275
|
+
muxer = muxerFactory.createStreamMuxer({
|
|
276
276
|
// Run anytime a remote stream is created
|
|
277
277
|
onIncomingStream: muxedStream => {
|
|
278
278
|
if (connection == null) {
|
|
@@ -301,6 +301,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
301
301
|
})
|
|
302
302
|
.catch(err => {
|
|
303
303
|
log.error(err)
|
|
304
|
+
|
|
305
|
+
if (muxedStream.timeline.close == null) {
|
|
306
|
+
muxedStream.close()
|
|
307
|
+
}
|
|
304
308
|
})
|
|
305
309
|
},
|
|
306
310
|
// Run anytime a stream closes
|
|
@@ -309,6 +313,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
309
313
|
}
|
|
310
314
|
})
|
|
311
315
|
|
|
316
|
+
if (isInitializable(muxer)) {
|
|
317
|
+
muxer.init(this.components)
|
|
318
|
+
}
|
|
319
|
+
|
|
312
320
|
newStream = async (protocols: string[], options: AbortOptions = {}): Promise<ProtocolStream> => {
|
|
313
321
|
if (muxer == null) {
|
|
314
322
|
throw errCode(new Error('Stream is not multiplexed'), codes.ERR_MUXER_UNAVAILABLE)
|
|
@@ -330,6 +338,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
330
338
|
} catch (err: any) {
|
|
331
339
|
log.error('could not create new stream', err)
|
|
332
340
|
|
|
341
|
+
if (muxedStream.timeline.close == null) {
|
|
342
|
+
muxedStream.close()
|
|
343
|
+
}
|
|
344
|
+
|
|
333
345
|
if (err.code != null) {
|
|
334
346
|
throw err
|
|
335
347
|
}
|
|
@@ -409,7 +421,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
409
421
|
*/
|
|
410
422
|
_onStream (opts: OnStreamOptions): void {
|
|
411
423
|
const { connection, stream, protocol } = opts
|
|
412
|
-
const handler = this.components.getRegistrar().getHandler(protocol)
|
|
424
|
+
const { handler } = this.components.getRegistrar().getHandler(protocol)
|
|
413
425
|
handler({ connection, stream, protocol })
|
|
414
426
|
}
|
|
415
427
|
|