libp2p 0.37.2 → 0.37.3-de30c2c
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/hop.js +2 -2
- package/dist/src/circuit/circuit/hop.js.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/stop.js +1 -1
- package/dist/src/circuit/circuit/stop.js.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/config.d.ts.map +1 -1
- package/dist/src/config.js +11 -3
- package/dist/src/config.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/errors.d.ts +4 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +3 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/fetch/index.d.ts +7 -4
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +61 -39
- package/dist/src/fetch/index.js.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 +7 -7
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +15 -23
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +17 -17
- 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 +14 -14
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +14 -4
- 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 +6 -3
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +6 -2
- package/dist/src/ping/index.js.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 +10 -8
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +63 -44
- 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 +69 -8
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +51 -29
- package/src/address-manager/index.ts +2 -2
- package/src/circuit/auto-relay.ts +4 -4
- package/src/circuit/circuit/hop.ts +4 -4
- package/src/circuit/circuit/stop.ts +2 -2
- 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/config.ts +11 -3
- 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/errors.ts +4 -1
- package/src/fetch/index.ts +91 -50
- package/src/get-peer.ts +3 -3
- package/src/identify/index.ts +24 -29
- package/src/index.ts +17 -17
- package/src/insecure/index.ts +3 -3
- package/src/keychain/index.ts +2 -2
- package/src/libp2p.ts +31 -15
- 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 +12 -5
- package/src/pnet/index.ts +1 -2
- package/src/pubsub/dummy-pubsub.ts +2 -2
- package/src/registrar.ts +79 -55
- package/src/transport-manager.ts +3 -3
- package/src/upgrader.ts +94 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Components } from '@libp2p/
|
|
1
|
+
import type { Components } from '@libp2p/components';
|
|
2
2
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
3
3
|
export declare class PeerRecordUpdater implements Startable {
|
|
4
4
|
private readonly components;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-record-updater.d.ts","sourceRoot":"","sources":["../../src/peer-record-updater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"peer-record-updater.d.ts","sourceRoot":"","sources":["../../src/peer-record-updater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAM7D,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,OAAO,CAAS;gBAEX,UAAU,EAAE,UAAU;IAMnC,SAAS;IAIH,KAAK;IAOL,IAAI;IAOV;;OAEG;IACH,MAAM;CAeP"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { PeerId } from '@libp2p/
|
|
2
|
-
import type { PeerRouting } from '@libp2p/
|
|
1
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
2
|
+
import type { PeerRouting } from '@libp2p/interface-peer-routing';
|
|
3
3
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
4
4
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
5
|
-
import type { PeerInfo } from '@libp2p/
|
|
6
|
-
import type { Components } from '@libp2p/
|
|
5
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
6
|
+
import type { Components } from '@libp2p/components';
|
|
7
7
|
export interface RefreshManagerInit {
|
|
8
8
|
/**
|
|
9
9
|
* Whether to enable the Refresh manager
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-routing.d.ts","sourceRoot":"","sources":["../../src/peer-routing.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"peer-routing.d.ts","sourceRoot":"","sources":["../../src/peer-routing.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAA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
import type { PeerId } from '@libp2p/
|
|
1
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar';
|
|
2
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
3
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
4
|
-
import type { Components } from '@libp2p/
|
|
4
|
+
import type { Components } from '@libp2p/components';
|
|
5
5
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
6
6
|
export interface PingServiceInit {
|
|
7
7
|
protocolPrefix: string;
|
|
8
|
+
maxInboundStreams: number;
|
|
9
|
+
maxOutboundStreams: number;
|
|
8
10
|
}
|
|
9
11
|
export declare class PingService implements Startable {
|
|
10
12
|
readonly protocol: string;
|
|
11
13
|
private readonly components;
|
|
12
14
|
private started;
|
|
15
|
+
private readonly init;
|
|
13
16
|
constructor(components: Components, init: PingServiceInit);
|
|
14
17
|
start(): Promise<void>;
|
|
15
18
|
stop(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMtD,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,qBAAa,WAAY,YAAW,SAAS;IAC3C,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;gBAEzB,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe;IAOpD,KAAK;IAQL,IAAI;IAKV,SAAS;IAIT;;OAEG;IACH,aAAa,CAAE,IAAI,EAAE,kBAAkB;IASvC;;;;;OAKG;IACG,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CAgCvE"}
|
package/dist/src/ping/index.js
CHANGED
|
@@ -13,9 +13,13 @@ export class PingService {
|
|
|
13
13
|
this.components = components;
|
|
14
14
|
this.started = false;
|
|
15
15
|
this.protocol = `/${init.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
|
|
16
|
+
this.init = init;
|
|
16
17
|
}
|
|
17
18
|
async start() {
|
|
18
|
-
await this.components.getRegistrar().handle(this.protocol, this.handleMessage
|
|
19
|
+
await this.components.getRegistrar().handle(this.protocol, this.handleMessage, {
|
|
20
|
+
maxInboundStreams: this.init.maxInboundStreams,
|
|
21
|
+
maxOutboundStreams: this.init.maxOutboundStreams
|
|
22
|
+
});
|
|
19
23
|
this.started = true;
|
|
20
24
|
}
|
|
21
25
|
async stop() {
|
|
@@ -44,7 +48,7 @@ export class PingService {
|
|
|
44
48
|
async ping(peer, options = {}) {
|
|
45
49
|
log('dialing %s to %p', this.protocol, peer);
|
|
46
50
|
const connection = await this.components.getConnectionManager().openConnection(peer, options);
|
|
47
|
-
const
|
|
51
|
+
const stream = await connection.newStream([this.protocol], options);
|
|
48
52
|
const start = Date.now();
|
|
49
53
|
const data = randomBytes(PING_LENGTH);
|
|
50
54
|
let source = stream;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"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,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC7F,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAA;QACnE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACxB,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;QAErC,IAAI,MAAM,GAAuB,MAAM,CAAA;QAEvC,8CAA8C;QAC9C,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;YAC1B,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;SACjD;QAED,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,CAAC,IAAI,CAAC,EACN,MAAM,EACN,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,CACtC,CAAA;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAEtB,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;gBACrD,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;aAC9E;YAED,OAAO,GAAG,GAAG,KAAK,CAAA;SACnB;gBAAS;YACR,MAAM,CAAC,KAAK,EAAE,CAAA;SACf;IACH,CAAC;CACF"}
|
package/dist/src/pnet/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { MultiaddrConnection } from '@libp2p/
|
|
2
|
-
import type { ConnectionProtector } from '@libp2p/interfaces/connection';
|
|
1
|
+
import type { ConnectionProtector, MultiaddrConnection } from '@libp2p/interface-connection';
|
|
3
2
|
export { generateKey } from './key-generator.js';
|
|
4
3
|
export interface ProtectorInit {
|
|
5
4
|
enabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAI5F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,UAAU,CAAA;CAChB;AAED,qBAAa,+BAAgC,YAAW,mBAAmB;IAClE,GAAG,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;OAGG;gBACU,IAAI,EAAE,aAAa;IAahC;;;;OAIG;IACG,OAAO,CAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA2C9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACZ,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C,KAAK,CAAC,CAAA;QAElB,OAAO;YACL,GAAG,UAAU;YACb,GAAG,QAAQ;SACZ,CAAA;IACH,CAAC;CACF"}
|
|
@@ -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
|
export declare class DummyPubSub extends EventEmitter<PubSubEvents> implements PubSub {
|
|
5
5
|
isStarted(): boolean;
|
|
6
6
|
start(): void | Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummy-pubsub.d.ts","sourceRoot":"","sources":["../../../src/pubsub/dummy-pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dummy-pubsub.d.ts","sourceRoot":"","sources":["../../../src/pubsub/dummy-pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAI7G,qBAAa,WAAY,SAAQ,YAAY,CAAC,YAAY,CAAE,YAAW,MAAM;IAC3E,SAAS,IAAK,OAAO;IAIrB,KAAK,IAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9B,IAAI,IAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7B,IAAI,qBAAqB,IAAK,OAAO,UAAU,GAAG,OAAO,YAAY,CAEpE;IAED,IAAI,WAAW,IAAK,MAAM,EAAE,CAE3B;IAED,QAAQ,IAAK,MAAM,EAAE;IAIrB,SAAS,IAAK,MAAM,EAAE;IAItB,SAAS,IAAK,IAAI;IAIlB,WAAW,IAAK,IAAI;IAIpB,cAAc,IAAK,MAAM,EAAE;IAIrB,OAAO,IAAK,OAAO,CAAC,aAAa,CAAC;CAGzC"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Registrar, StreamHandler } from '@libp2p/
|
|
3
|
-
import type { PeerProtocolsChangeData } from '@libp2p/
|
|
4
|
-
import type { Connection } from '@libp2p/
|
|
5
|
-
import type { Components } from '@libp2p/
|
|
1
|
+
import { StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-registrar';
|
|
2
|
+
import type { Registrar, StreamHandler, Topology } from '@libp2p/interface-registrar';
|
|
3
|
+
import type { PeerProtocolsChangeData } from '@libp2p/interface-peer-store';
|
|
4
|
+
import type { Connection } from '@libp2p/interface-connection';
|
|
5
|
+
import type { Components } from '@libp2p/components';
|
|
6
|
+
export declare const DEFAULT_MAX_INBOUND_STREAMS = 1;
|
|
7
|
+
export declare const DEFAULT_MAX_OUTBOUND_STREAMS = 1;
|
|
6
8
|
/**
|
|
7
9
|
* Responsible for notifying registered protocols of events in the network.
|
|
8
10
|
*/
|
|
@@ -12,12 +14,12 @@ export declare class DefaultRegistrar implements Registrar {
|
|
|
12
14
|
private readonly components;
|
|
13
15
|
constructor(components: Components);
|
|
14
16
|
getProtocols(): string[];
|
|
15
|
-
getHandler(protocol: string):
|
|
17
|
+
getHandler(protocol: string): StreamHandlerRecord;
|
|
16
18
|
getTopologies(protocol: string): Topology[];
|
|
17
19
|
/**
|
|
18
20
|
* Registers the `handler` for each protocol
|
|
19
21
|
*/
|
|
20
|
-
handle(
|
|
22
|
+
handle(protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void>;
|
|
21
23
|
/**
|
|
22
24
|
* Removes the handler for each protocol. The protocol
|
|
23
25
|
* will no longer be supported on streams.
|
|
@@ -26,7 +28,7 @@ export declare class DefaultRegistrar implements Registrar {
|
|
|
26
28
|
/**
|
|
27
29
|
* Register handlers for a set of multicodecs given
|
|
28
30
|
*/
|
|
29
|
-
register(
|
|
31
|
+
register(protocol: string, topology: Topology): Promise<string>;
|
|
30
32
|
/**
|
|
31
33
|
* Unregister topology
|
|
32
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEnG,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACrF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAIpD,eAAO,MAAM,2BAA2B,IAAI,CAAA;AAC5C,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAE7C;;GAEG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAC/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;IAC3D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;gBAE1B,UAAU,EAAE,UAAU;IAcnC,YAAY;IAOZ,UAAU,CAAE,QAAQ,EAAE,MAAM;IAU5B,aAAa,CAAE,QAAQ,EAAE,MAAM;IAY/B;;OAEG;IACG,MAAM,CAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBnG;;;OAGG;IACG,QAAQ,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAW5C;;OAEG;IACG,QAAQ,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBtE;;OAEG;IACH,UAAU,CAAE,EAAE,EAAE,MAAM;IAYtB;;OAEG;IACH,aAAa,CAAE,GAAG,EAAE,WAAW,CAAC,UAAU,CAAC;IAuB3C;;OAEG;IACH,iBAAiB,CAAE,GAAG,EAAE,WAAW,CAAC,uBAAuB,CAAC;CAsC7D"}
|
package/dist/src/registrar.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
2
|
import errCode from 'err-code';
|
|
3
3
|
import { codes } from './errors.js';
|
|
4
|
-
import { isTopology } from '@libp2p/
|
|
4
|
+
import { isTopology } from '@libp2p/interface-registrar';
|
|
5
|
+
import merge from 'merge-options';
|
|
5
6
|
const log = logger('libp2p:registrar');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (topologyProtocols.includes(peerProtocol)) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
7
|
+
export const DEFAULT_MAX_INBOUND_STREAMS = 1;
|
|
8
|
+
export const DEFAULT_MAX_OUTBOUND_STREAMS = 1;
|
|
14
9
|
/**
|
|
15
10
|
* Responsible for notifying registered protocols of events in the network.
|
|
16
11
|
*/
|
|
@@ -26,44 +21,44 @@ export class DefaultRegistrar {
|
|
|
26
21
|
this.components.getPeerStore().addEventListener('change:protocols', this._onProtocolChange);
|
|
27
22
|
}
|
|
28
23
|
getProtocols() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (const protocol of this.handlers.keys()) {
|
|
34
|
-
protocols.add(protocol);
|
|
35
|
-
}
|
|
36
|
-
return Array.from(protocols).sort();
|
|
24
|
+
return Array.from(new Set([
|
|
25
|
+
...this.topologies.keys(),
|
|
26
|
+
...this.handlers.keys()
|
|
27
|
+
])).sort();
|
|
37
28
|
}
|
|
38
29
|
getHandler(protocol) {
|
|
39
30
|
const handler = this.handlers.get(protocol);
|
|
40
31
|
if (handler == null) {
|
|
41
|
-
throw new Error(`No handler registered for protocol ${protocol}`);
|
|
32
|
+
throw errCode(new Error(`No handler registered for protocol ${protocol}`), codes.ERR_NO_HANDLER_FOR_PROTOCOL);
|
|
42
33
|
}
|
|
43
34
|
return handler;
|
|
44
35
|
}
|
|
45
36
|
getTopologies(protocol) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
output.push(topology);
|
|
50
|
-
}
|
|
37
|
+
const topologies = this.topologies.get(protocol);
|
|
38
|
+
if (topologies == null) {
|
|
39
|
+
return [];
|
|
51
40
|
}
|
|
52
|
-
return
|
|
41
|
+
return [
|
|
42
|
+
...topologies.values()
|
|
43
|
+
];
|
|
53
44
|
}
|
|
54
45
|
/**
|
|
55
46
|
* Registers the `handler` for each protocol
|
|
56
47
|
*/
|
|
57
|
-
async handle(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (this.handlers.has(protocol)) {
|
|
61
|
-
throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);
|
|
62
|
-
}
|
|
63
|
-
this.handlers.set(protocol, handler);
|
|
48
|
+
async handle(protocol, handler, opts) {
|
|
49
|
+
if (this.handlers.has(protocol)) {
|
|
50
|
+
throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);
|
|
64
51
|
}
|
|
52
|
+
const options = merge.bind({ ignoreUndefined: true })({
|
|
53
|
+
maxInboundStreams: DEFAULT_MAX_INBOUND_STREAMS,
|
|
54
|
+
maxOutboundStreams: DEFAULT_MAX_OUTBOUND_STREAMS
|
|
55
|
+
}, opts);
|
|
56
|
+
this.handlers.set(protocol, {
|
|
57
|
+
handler,
|
|
58
|
+
options
|
|
59
|
+
});
|
|
65
60
|
// Add new protocols to self protocols in the Protobook
|
|
66
|
-
await this.components.getPeerStore().protoBook.add(this.components.getPeerId(),
|
|
61
|
+
await this.components.getPeerStore().protoBook.add(this.components.getPeerId(), [protocol]);
|
|
67
62
|
}
|
|
68
63
|
/**
|
|
69
64
|
* Removes the handler for each protocol. The protocol
|
|
@@ -80,17 +75,19 @@ export class DefaultRegistrar {
|
|
|
80
75
|
/**
|
|
81
76
|
* Register handlers for a set of multicodecs given
|
|
82
77
|
*/
|
|
83
|
-
async register(
|
|
78
|
+
async register(protocol, topology) {
|
|
84
79
|
if (!isTopology(topology)) {
|
|
85
80
|
log.error('topology must be an instance of interfaces/topology');
|
|
86
81
|
throw errCode(new Error('topology must be an instance of interfaces/topology'), codes.ERR_INVALID_PARAMETERS);
|
|
87
82
|
}
|
|
88
83
|
// Create topology
|
|
89
84
|
const id = `${(Math.random() * 1e9).toString(36)}${Date.now()}`;
|
|
90
|
-
this.topologies.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
let topologies = this.topologies.get(protocol);
|
|
86
|
+
if (topologies == null) {
|
|
87
|
+
topologies = new Map();
|
|
88
|
+
this.topologies.set(protocol, topologies);
|
|
89
|
+
}
|
|
90
|
+
topologies.set(id, topology);
|
|
94
91
|
// Set registrar
|
|
95
92
|
await topology.setRegistrar(this);
|
|
96
93
|
return id;
|
|
@@ -99,7 +96,14 @@ export class DefaultRegistrar {
|
|
|
99
96
|
* Unregister topology
|
|
100
97
|
*/
|
|
101
98
|
unregister(id) {
|
|
102
|
-
this.topologies.
|
|
99
|
+
for (const [protocol, topologies] of this.topologies.entries()) {
|
|
100
|
+
if (topologies.has(id)) {
|
|
101
|
+
topologies.delete(id);
|
|
102
|
+
if (topologies.size === 0) {
|
|
103
|
+
this.topologies.delete(protocol);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
105
109
|
* Remove a disconnected peer from the record
|
|
@@ -108,8 +112,13 @@ export class DefaultRegistrar {
|
|
|
108
112
|
const connection = evt.detail;
|
|
109
113
|
void this.components.getPeerStore().protoBook.get(connection.remotePeer)
|
|
110
114
|
.then(peerProtocols => {
|
|
111
|
-
for (const
|
|
112
|
-
|
|
115
|
+
for (const protocol of peerProtocols) {
|
|
116
|
+
const topologies = this.topologies.get(protocol);
|
|
117
|
+
if (topologies == null) {
|
|
118
|
+
// no topologies are interested in this protocol
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
for (const topology of topologies.values()) {
|
|
113
122
|
topology.onDisconnect(connection.remotePeer);
|
|
114
123
|
}
|
|
115
124
|
}
|
|
@@ -125,13 +134,23 @@ export class DefaultRegistrar {
|
|
|
125
134
|
const { peerId, protocols, oldProtocols } = evt.detail;
|
|
126
135
|
const removed = oldProtocols.filter(protocol => !protocols.includes(protocol));
|
|
127
136
|
const added = protocols.filter(protocol => !oldProtocols.includes(protocol));
|
|
128
|
-
for (const
|
|
129
|
-
|
|
137
|
+
for (const protocol of removed) {
|
|
138
|
+
const topologies = this.topologies.get(protocol);
|
|
139
|
+
if (topologies == null) {
|
|
140
|
+
// no topologies are interested in this protocol
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
for (const topology of topologies.values()) {
|
|
130
144
|
topology.onDisconnect(peerId);
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
|
-
for (const
|
|
134
|
-
|
|
147
|
+
for (const protocol of added) {
|
|
148
|
+
const topologies = this.topologies.get(protocol);
|
|
149
|
+
if (topologies == null) {
|
|
150
|
+
// no topologies are interested in this protocol
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
for (const topology of topologies.values()) {
|
|
135
154
|
const connection = this.components.getConnectionManager().getConnections(peerId)[0];
|
|
136
155
|
if (connection == null) {
|
|
137
156
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,UAAU,EAA6C,MAAM,6BAA6B,CAAA;AACnG,OAAO,KAAK,MAAM,eAAe,CAAA;AAMjC,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAA;AAC5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAK3B,YAAa,UAAsB;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAE5B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA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AAA;YAEhD,IAAI,UAAU,IAAI,IAAI,EAAE;gBACtB,gDAAgD;gBAChD,SAAQ;aACT;YAED,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE;gBAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;gBAEnF,IAAI,UAAU,IAAI,IAAI,EAAE;oBACtB,SAAQ;iBACT;gBAED,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;aACvC;SACF;IACH,CAAC;CACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Transport, TransportManager, TransportManagerEvents } from '@libp2p/
|
|
1
|
+
import type { Transport, TransportManager, TransportManagerEvents } from '@libp2p/interface-transport';
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
-
import type { Connection } from '@libp2p/
|
|
3
|
+
import type { Connection } from '@libp2p/interface-connection';
|
|
4
4
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
5
5
|
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
6
6
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
7
|
-
import type { Components } from '@libp2p/
|
|
7
|
+
import type { Components } from '@libp2p/components';
|
|
8
8
|
export interface TransportManagerInit {
|
|
9
9
|
faultTolerance?: FaultTolerance;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAY,SAAS,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAY,SAAS,EAAE,gBAAgB,EAAE,sBAAsB,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SAAS;CAQhB;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB;;OAEG;IACH,SAAS,IAAI;IAEb;;OAEG;IACH,QAAQ,IAAA;CACT"}
|
package/dist/src/upgrader.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
2
|
-
import type { Connection, Stream } from '@libp2p/
|
|
3
|
-
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/
|
|
4
|
-
import type { StreamMuxerFactory } from '@libp2p/
|
|
5
|
-
import type { PeerId } from '@libp2p/
|
|
6
|
-
import type {
|
|
2
|
+
import type { MultiaddrConnection, Connection, Stream } from '@libp2p/interface-connection';
|
|
3
|
+
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter';
|
|
4
|
+
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';
|
|
5
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
6
|
+
import type { Upgrader, UpgraderEvents } from '@libp2p/interface-transport';
|
|
7
7
|
import type { Duplex } from 'it-stream-types';
|
|
8
|
-
import
|
|
8
|
+
import { Components } from '@libp2p/components';
|
|
9
9
|
interface CreateConectionOptions {
|
|
10
10
|
cryptoProtocol: string;
|
|
11
11
|
direction: 'inbound' | 'outbound';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAe,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAe,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC3F,OAAO,KAAK,E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AAC;IAwFvE;;OAEG;IACG,eAAe,CAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8FxE;;OAEG;IACH,iBAAiB,CAAE,IAAI,EAAE,sBAAsB,GAAG,UAAU;IAuL5D;;OAEG;IACH,SAAS,CAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAOvC;;OAEG;IACG,eAAe,CAAE,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAwB7E;;;OAGG;IACG,gBAAgB,CAAE,UAAU,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAwBrG;;;OAGG;IACG,kBAAkB,CAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAAC,YAAY,CAAC,EAAE,kBAAkB,CAAA;KAAC,CAAC;IAe9K;;;OAGG;IACG,iBAAiB,CAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAAC,YAAY,CAAC,EAAE,kBAAkB,CAAA;KAAC,CAAC;CAa9K"}
|
package/dist/src/upgrader.js
CHANGED
|
@@ -8,7 +8,42 @@ 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 { isInitializable } from '@libp2p/components';
|
|
12
|
+
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js';
|
|
11
13
|
const log = logger('libp2p:upgrader');
|
|
14
|
+
function findIncomingStreamLimit(protocol, registrar) {
|
|
15
|
+
try {
|
|
16
|
+
const { options } = registrar.getHandler(protocol);
|
|
17
|
+
return options.maxInboundStreams;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) {
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return DEFAULT_MAX_INBOUND_STREAMS;
|
|
25
|
+
}
|
|
26
|
+
function findOutgoingStreamLimit(protocol, registrar) {
|
|
27
|
+
try {
|
|
28
|
+
const { options } = registrar.getHandler(protocol);
|
|
29
|
+
return options.maxOutboundStreams;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return DEFAULT_MAX_OUTBOUND_STREAMS;
|
|
37
|
+
}
|
|
38
|
+
function countStreams(protocol, direction, connection) {
|
|
39
|
+
let streamCount = 0;
|
|
40
|
+
connection.streams.forEach(stream => {
|
|
41
|
+
if (stream.stat.direction === direction && stream.stat.protocol === protocol) {
|
|
42
|
+
streamCount++;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return streamCount;
|
|
46
|
+
}
|
|
12
47
|
export class DefaultUpgrader extends EventEmitter {
|
|
13
48
|
constructor(components, init) {
|
|
14
49
|
super();
|
|
@@ -196,7 +231,7 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
196
231
|
let connection; // eslint-disable-line prefer-const
|
|
197
232
|
if (muxerFactory != null) {
|
|
198
233
|
// Create the muxer
|
|
199
|
-
muxer = muxerFactory.createStreamMuxer(
|
|
234
|
+
muxer = muxerFactory.createStreamMuxer({
|
|
200
235
|
// Run anytime a remote stream is created
|
|
201
236
|
onIncomingStream: muxedStream => {
|
|
202
237
|
if (connection == null) {
|
|
@@ -215,11 +250,20 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
215
250
|
if (connection == null) {
|
|
216
251
|
return;
|
|
217
252
|
}
|
|
218
|
-
|
|
253
|
+
const incomingLimit = findIncomingStreamLimit(protocol, this.components.getRegistrar());
|
|
254
|
+
const streamCount = countStreams(protocol, 'inbound', connection);
|
|
255
|
+
if (streamCount === incomingLimit) {
|
|
256
|
+
throw errCode(new Error('Too many incoming protocol streams'), codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);
|
|
257
|
+
}
|
|
258
|
+
muxedStream.stat.protocol = protocol;
|
|
259
|
+
connection.addStream(muxedStream);
|
|
219
260
|
this._onStream({ connection, stream: { ...muxedStream, ...stream }, protocol });
|
|
220
261
|
})
|
|
221
262
|
.catch(err => {
|
|
222
263
|
log.error(err);
|
|
264
|
+
if (muxedStream.stat.timeline.close == null) {
|
|
265
|
+
muxedStream.close();
|
|
266
|
+
}
|
|
223
267
|
});
|
|
224
268
|
},
|
|
225
269
|
// Run anytime a stream closes
|
|
@@ -227,6 +271,9 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
227
271
|
connection?.removeStream(muxedStream.id);
|
|
228
272
|
}
|
|
229
273
|
});
|
|
274
|
+
if (isInitializable(muxer)) {
|
|
275
|
+
muxer.init(this.components);
|
|
276
|
+
}
|
|
230
277
|
newStream = async (protocols, options = {}) => {
|
|
231
278
|
if (muxer == null) {
|
|
232
279
|
throw errCode(new Error('Stream is not multiplexed'), codes.ERR_MUXER_UNAVAILABLE);
|
|
@@ -240,10 +287,26 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
240
287
|
if (metrics != null) {
|
|
241
288
|
stream = metrics.trackStream({ stream, remotePeer, protocol });
|
|
242
289
|
}
|
|
243
|
-
|
|
290
|
+
const outgoingLimit = findOutgoingStreamLimit(protocol, this.components.getRegistrar());
|
|
291
|
+
const streamCount = countStreams(protocol, 'outbound', connection);
|
|
292
|
+
if (streamCount === outgoingLimit) {
|
|
293
|
+
throw errCode(new Error('Too many outgoing protocol streams'), codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);
|
|
294
|
+
}
|
|
295
|
+
muxedStream.stat.protocol = protocol;
|
|
296
|
+
return {
|
|
297
|
+
...muxedStream,
|
|
298
|
+
...stream,
|
|
299
|
+
stat: {
|
|
300
|
+
...muxedStream.stat,
|
|
301
|
+
protocol
|
|
302
|
+
}
|
|
303
|
+
};
|
|
244
304
|
}
|
|
245
305
|
catch (err) {
|
|
246
306
|
log.error('could not create new stream', err);
|
|
307
|
+
if (muxedStream.stat.timeline.close == null) {
|
|
308
|
+
muxedStream.close();
|
|
309
|
+
}
|
|
247
310
|
if (err.code != null) {
|
|
248
311
|
throw err;
|
|
249
312
|
}
|
|
@@ -300,9 +363,7 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
300
363
|
await maConn.close();
|
|
301
364
|
// Ensure remaining streams are closed
|
|
302
365
|
if (muxer != null) {
|
|
303
|
-
|
|
304
|
-
await stream.close();
|
|
305
|
-
}));
|
|
366
|
+
muxer.streams.forEach(s => s.close());
|
|
306
367
|
}
|
|
307
368
|
}
|
|
308
369
|
});
|
|
@@ -316,8 +377,8 @@ export class DefaultUpgrader extends EventEmitter {
|
|
|
316
377
|
*/
|
|
317
378
|
_onStream(opts) {
|
|
318
379
|
const { connection, stream, protocol } = opts;
|
|
319
|
-
const handler = this.components.getRegistrar().getHandler(protocol);
|
|
320
|
-
handler({ connection, stream
|
|
380
|
+
const { handler } = this.components.getRegistrar().getHandler(protocol);
|
|
381
|
+
handler({ connection, stream });
|
|
321
382
|
}
|
|
322
383
|
/**
|
|
323
384
|
* Attempts to encrypt the incoming `connection` with the provided `cryptos`
|