libp2p 0.44.0 → 0.45.0
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/index.min.js +30 -30
- package/dist/src/address-manager/index.d.ts +8 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +37 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/utils.d.ts +2 -0
- package/dist/src/address-manager/utils.d.ts.map +1 -0
- package/dist/src/address-manager/utils.js +12 -0
- package/dist/src/address-manager/utils.js.map +1 -0
- package/dist/src/autonat/constants.d.ts +16 -2
- package/dist/src/autonat/constants.d.ts.map +1 -1
- package/dist/src/autonat/constants.js +16 -2
- package/dist/src/autonat/constants.js.map +1 -1
- package/dist/src/autonat/index.d.ts +12 -33
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +36 -30
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +2 -2
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +10 -3
- 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 +4 -2
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +3 -0
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +6 -4
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +30 -26
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +5 -4
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +37 -30
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/components.d.ts +6 -63
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -164
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -62
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +36 -13
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +4 -0
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +23 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +2 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +36 -14
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +8 -7
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +23 -34
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +7 -42
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +3 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +7 -9
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/identify.d.ts +53 -0
- package/dist/src/identify/identify.d.ts.map +1 -0
- package/dist/src/identify/identify.js +405 -0
- package/dist/src/identify/identify.js.map +1 -0
- package/dist/src/identify/index.d.ts +12 -58
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +5 -388
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +13 -68
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +11 -42
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +137 -196
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +27 -25
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +11 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +19 -10
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +15 -10
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +39 -48
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- 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/dist/typedoc-urls.json +25 -10
- package/package.json +61 -45
- package/src/address-manager/index.ts +50 -8
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/constants.ts +17 -2
- package/src/autonat/index.ts +53 -45
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +11 -3
- package/src/circuit-relay/transport/discovery.ts +5 -3
- package/src/circuit-relay/transport/index.ts +9 -4
- package/src/circuit-relay/transport/listener.ts +38 -28
- package/src/circuit-relay/transport/reservation-store.ts +34 -20
- package/src/components.ts +71 -234
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -64
- package/src/connection-manager/auto-dial.ts +44 -15
- package/src/connection-manager/connection-pruner.ts +28 -8
- package/src/connection-manager/dial-queue.ts +41 -21
- package/src/connection-manager/index.ts +31 -43
- package/src/content-routing/index.ts +7 -55
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +51 -14
- package/src/identify/identify.ts +518 -0
- package/src/identify/index.ts +17 -507
- package/src/index.ts +14 -77
- package/src/insecure/index.ts +4 -4
- package/src/libp2p.ts +139 -260
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +27 -13
- package/src/upgrader.ts +62 -58
- package/src/{nat-manager.ts → upnp-nat/index.ts} +16 -17
- package/src/version.ts +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/dist/src/peer-record-updater.d.ts +0 -24
- package/dist/src/peer-record-updater.d.ts.map +0 -1
- package/dist/src/peer-record-updater.js +0 -44
- package/dist/src/peer-record-updater.js.map +0 -1
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
- package/src/peer-record-updater.ts +0 -65
package/dist/src/components.d.ts
CHANGED
|
@@ -9,12 +9,13 @@ import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
|
9
9
|
import type { Registrar } from '@libp2p/interface-registrar';
|
|
10
10
|
import type { TransportManager, Upgrader } from '@libp2p/interface-transport';
|
|
11
11
|
import type { Datastore } from 'interface-datastore';
|
|
12
|
-
import type { PubSub } from '@libp2p/interface-pubsub';
|
|
13
|
-
import type { DualDHT } from '@libp2p/interface-dht';
|
|
14
12
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager';
|
|
15
13
|
import type { ConnectionGater } from '@libp2p/interface-connection-gater';
|
|
16
|
-
|
|
14
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p';
|
|
15
|
+
import type { EventEmitter } from '@libp2p/interfaces/events';
|
|
16
|
+
export interface Components extends Record<string, any>, Startable {
|
|
17
17
|
peerId: PeerId;
|
|
18
|
+
events: EventEmitter<Libp2pEvents>;
|
|
18
19
|
addressManager: AddressManager;
|
|
19
20
|
peerStore: PeerStore;
|
|
20
21
|
upgrader: Upgrader;
|
|
@@ -27,11 +28,10 @@ export interface Components {
|
|
|
27
28
|
datastore: Datastore;
|
|
28
29
|
connectionProtector?: ConnectionProtector;
|
|
29
30
|
metrics?: Metrics;
|
|
30
|
-
dht?: DualDHT;
|
|
31
|
-
pubsub?: PubSub;
|
|
32
31
|
}
|
|
33
32
|
export interface ComponentsInit {
|
|
34
33
|
peerId?: PeerId;
|
|
34
|
+
events?: EventEmitter<Libp2pEvents>;
|
|
35
35
|
addressManager?: AddressManager;
|
|
36
36
|
peerStore?: PeerStore;
|
|
37
37
|
upgrader?: Upgrader;
|
|
@@ -44,63 +44,6 @@ export interface ComponentsInit {
|
|
|
44
44
|
peerRouting?: PeerRouting;
|
|
45
45
|
datastore?: Datastore;
|
|
46
46
|
connectionProtector?: ConnectionProtector;
|
|
47
|
-
dht?: DualDHT;
|
|
48
|
-
pubsub?: PubSub;
|
|
49
|
-
}
|
|
50
|
-
export declare class DefaultComponents implements Components, Startable {
|
|
51
|
-
private _peerId?;
|
|
52
|
-
private _addressManager?;
|
|
53
|
-
private _peerStore?;
|
|
54
|
-
private _upgrader?;
|
|
55
|
-
private _metrics?;
|
|
56
|
-
private _registrar?;
|
|
57
|
-
private _connectionManager?;
|
|
58
|
-
private _transportManager?;
|
|
59
|
-
private _connectionGater?;
|
|
60
|
-
private _contentRouting?;
|
|
61
|
-
private _peerRouting?;
|
|
62
|
-
private _datastore?;
|
|
63
|
-
private _connectionProtector?;
|
|
64
|
-
private _dht?;
|
|
65
|
-
private _pubsub?;
|
|
66
|
-
private _started;
|
|
67
|
-
constructor(init?: ComponentsInit);
|
|
68
|
-
isStarted(): boolean;
|
|
69
|
-
beforeStart(): Promise<void>;
|
|
70
|
-
start(): Promise<void>;
|
|
71
|
-
afterStart(): Promise<void>;
|
|
72
|
-
beforeStop(): Promise<void>;
|
|
73
|
-
stop(): Promise<void>;
|
|
74
|
-
afterStop(): Promise<void>;
|
|
75
|
-
get peerId(): PeerId;
|
|
76
|
-
set peerId(peerId: PeerId);
|
|
77
|
-
get addressManager(): AddressManager;
|
|
78
|
-
set addressManager(addressManager: AddressManager);
|
|
79
|
-
get peerStore(): PeerStore;
|
|
80
|
-
set peerStore(peerStore: PeerStore);
|
|
81
|
-
get upgrader(): Upgrader;
|
|
82
|
-
set upgrader(upgrader: Upgrader);
|
|
83
|
-
get registrar(): Registrar;
|
|
84
|
-
set registrar(registrar: Registrar);
|
|
85
|
-
get connectionManager(): ConnectionManager;
|
|
86
|
-
set connectionManager(connectionManager: ConnectionManager);
|
|
87
|
-
get transportManager(): TransportManager;
|
|
88
|
-
set transportManager(transportManager: TransportManager);
|
|
89
|
-
get connectionGater(): ConnectionGater;
|
|
90
|
-
set connectionGater(connectionGater: ConnectionGater);
|
|
91
|
-
get contentRouting(): ContentRouting;
|
|
92
|
-
set contentRouting(contentRouting: ContentRouting);
|
|
93
|
-
get peerRouting(): PeerRouting;
|
|
94
|
-
set peerRouting(peerRouting: PeerRouting);
|
|
95
|
-
get datastore(): Datastore;
|
|
96
|
-
set datastore(datastore: Datastore);
|
|
97
|
-
get connectionProtector(): ConnectionProtector | undefined;
|
|
98
|
-
set connectionProtector(connectionProtector: ConnectionProtector | undefined);
|
|
99
|
-
get metrics(): Metrics | undefined;
|
|
100
|
-
set metrics(metrics: Metrics | undefined);
|
|
101
|
-
get dht(): DualDHT | undefined;
|
|
102
|
-
set dht(dht: DualDHT | undefined);
|
|
103
|
-
get pubsub(): PubSub | undefined;
|
|
104
|
-
set pubsub(pubsub: PubSub | undefined);
|
|
105
47
|
}
|
|
48
|
+
export declare function defaultComponents(init?: ComponentsInit): Components;
|
|
106
49
|
//# sourceMappingURL=components.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAe,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAe,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,E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C,EAAE,SAAS,CAAA;IACrB,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CAC1C;AAyED,wBAAgB,iBAAiB,CAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CA+BxE"}
|
package/dist/src/components.js
CHANGED
|
@@ -1,189 +1,85 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interfaces/errors';
|
|
2
2
|
import { isStartable } from '@libp2p/interfaces/startable';
|
|
3
|
-
|
|
3
|
+
class DefaultComponents {
|
|
4
4
|
constructor(init = {}) {
|
|
5
|
+
this.components = {};
|
|
5
6
|
this._started = false;
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this._metrics = init.metrics;
|
|
11
|
-
this._registrar = init.registrar;
|
|
12
|
-
this._connectionManager = init.connectionManager;
|
|
13
|
-
this._transportManager = init.transportManager;
|
|
14
|
-
this._connectionGater = init.connectionGater;
|
|
15
|
-
this._contentRouting = init.contentRouting;
|
|
16
|
-
this._peerRouting = init.peerRouting;
|
|
17
|
-
this._datastore = init.datastore;
|
|
18
|
-
this._connectionProtector = init.connectionProtector;
|
|
19
|
-
this._dht = init.dht;
|
|
20
|
-
this._pubsub = init.pubsub;
|
|
7
|
+
this.components = {};
|
|
8
|
+
for (const [key, value] of Object.entries(init)) {
|
|
9
|
+
this.components[key] = value;
|
|
10
|
+
}
|
|
21
11
|
}
|
|
22
12
|
isStarted() {
|
|
23
13
|
return this._started;
|
|
24
14
|
}
|
|
25
|
-
async
|
|
26
|
-
await Promise.all(Object.values(this
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
async _invokeStartableMethod(methodName) {
|
|
16
|
+
await Promise.all(Object.values(this.components)
|
|
17
|
+
.filter(obj => isStartable(obj))
|
|
18
|
+
.map(async (startable) => {
|
|
19
|
+
await startable[methodName]?.();
|
|
30
20
|
}));
|
|
31
21
|
}
|
|
22
|
+
async beforeStart() {
|
|
23
|
+
await this._invokeStartableMethod('beforeStart');
|
|
24
|
+
}
|
|
32
25
|
async start() {
|
|
33
|
-
await
|
|
34
|
-
await startable.start();
|
|
35
|
-
}));
|
|
26
|
+
await this._invokeStartableMethod('start');
|
|
36
27
|
this._started = true;
|
|
37
28
|
}
|
|
38
29
|
async afterStart() {
|
|
39
|
-
await
|
|
40
|
-
if (startable.afterStart != null) {
|
|
41
|
-
await startable.afterStart();
|
|
42
|
-
}
|
|
43
|
-
}));
|
|
30
|
+
await this._invokeStartableMethod('afterStart');
|
|
44
31
|
}
|
|
45
32
|
async beforeStop() {
|
|
46
|
-
await
|
|
47
|
-
if (startable.beforeStop != null) {
|
|
48
|
-
await startable.beforeStop();
|
|
49
|
-
}
|
|
50
|
-
}));
|
|
33
|
+
await this._invokeStartableMethod('beforeStop');
|
|
51
34
|
}
|
|
52
35
|
async stop() {
|
|
53
|
-
await
|
|
54
|
-
await startable.stop();
|
|
55
|
-
}));
|
|
36
|
+
await this._invokeStartableMethod('stop');
|
|
56
37
|
this._started = false;
|
|
57
38
|
}
|
|
58
39
|
async afterStop() {
|
|
59
|
-
await
|
|
60
|
-
if (startable.afterStop != null) {
|
|
61
|
-
await startable.afterStop();
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
get peerId() {
|
|
66
|
-
if (this._peerId == null) {
|
|
67
|
-
throw new CodeError('peerId not set', 'ERR_SERVICE_MISSING');
|
|
68
|
-
}
|
|
69
|
-
return this._peerId;
|
|
40
|
+
await this._invokeStartableMethod('afterStop');
|
|
70
41
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
get connectionManager() {
|
|
111
|
-
if (this._connectionManager == null) {
|
|
112
|
-
throw new CodeError('connectionManager not set', 'ERR_SERVICE_MISSING');
|
|
113
|
-
}
|
|
114
|
-
return this._connectionManager;
|
|
115
|
-
}
|
|
116
|
-
set connectionManager(connectionManager) {
|
|
117
|
-
this._connectionManager = connectionManager;
|
|
118
|
-
}
|
|
119
|
-
get transportManager() {
|
|
120
|
-
if (this._transportManager == null) {
|
|
121
|
-
throw new CodeError('transportManager not set', 'ERR_SERVICE_MISSING');
|
|
122
|
-
}
|
|
123
|
-
return this._transportManager;
|
|
124
|
-
}
|
|
125
|
-
set transportManager(transportManager) {
|
|
126
|
-
this._transportManager = transportManager;
|
|
127
|
-
}
|
|
128
|
-
get connectionGater() {
|
|
129
|
-
if (this._connectionGater == null) {
|
|
130
|
-
throw new CodeError('connectionGater not set', 'ERR_SERVICE_MISSING');
|
|
131
|
-
}
|
|
132
|
-
return this._connectionGater;
|
|
133
|
-
}
|
|
134
|
-
set connectionGater(connectionGater) {
|
|
135
|
-
this._connectionGater = connectionGater;
|
|
136
|
-
}
|
|
137
|
-
get contentRouting() {
|
|
138
|
-
if (this._contentRouting == null) {
|
|
139
|
-
throw new CodeError('contentRouting not set', 'ERR_SERVICE_MISSING');
|
|
140
|
-
}
|
|
141
|
-
return this._contentRouting;
|
|
142
|
-
}
|
|
143
|
-
set contentRouting(contentRouting) {
|
|
144
|
-
this._contentRouting = contentRouting;
|
|
145
|
-
}
|
|
146
|
-
get peerRouting() {
|
|
147
|
-
if (this._peerRouting == null) {
|
|
148
|
-
throw new CodeError('peerRouting not set', 'ERR_SERVICE_MISSING');
|
|
149
|
-
}
|
|
150
|
-
return this._peerRouting;
|
|
151
|
-
}
|
|
152
|
-
set peerRouting(peerRouting) {
|
|
153
|
-
this._peerRouting = peerRouting;
|
|
154
|
-
}
|
|
155
|
-
get datastore() {
|
|
156
|
-
if (this._datastore == null) {
|
|
157
|
-
throw new CodeError('datastore not set', 'ERR_SERVICE_MISSING');
|
|
42
|
+
}
|
|
43
|
+
const OPTIONAL_SERVICES = [
|
|
44
|
+
'metrics',
|
|
45
|
+
'connectionProtector'
|
|
46
|
+
];
|
|
47
|
+
const NON_SERVICE_PROPERTIES = [
|
|
48
|
+
'components',
|
|
49
|
+
'isStarted',
|
|
50
|
+
'beforeStart',
|
|
51
|
+
'start',
|
|
52
|
+
'afterStart',
|
|
53
|
+
'beforeStop',
|
|
54
|
+
'stop',
|
|
55
|
+
'afterStop',
|
|
56
|
+
'then',
|
|
57
|
+
'_invokeStartableMethod'
|
|
58
|
+
];
|
|
59
|
+
export function defaultComponents(init = {}) {
|
|
60
|
+
const components = new DefaultComponents(init);
|
|
61
|
+
const proxy = new Proxy(components, {
|
|
62
|
+
get(target, prop, receiver) {
|
|
63
|
+
if (typeof prop === 'string' && !NON_SERVICE_PROPERTIES.includes(prop)) {
|
|
64
|
+
const service = components.components[prop];
|
|
65
|
+
if (service == null && !OPTIONAL_SERVICES.includes(prop)) {
|
|
66
|
+
throw new CodeError(`${prop} not set`, 'ERR_SERVICE_MISSING');
|
|
67
|
+
}
|
|
68
|
+
return service;
|
|
69
|
+
}
|
|
70
|
+
return Reflect.get(target, prop, receiver);
|
|
71
|
+
},
|
|
72
|
+
set(target, prop, value) {
|
|
73
|
+
if (typeof prop === 'string') {
|
|
74
|
+
components.components[prop] = value;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
Reflect.set(target, prop, value);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
158
80
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this._datastore = datastore;
|
|
163
|
-
}
|
|
164
|
-
get connectionProtector() {
|
|
165
|
-
return this._connectionProtector;
|
|
166
|
-
}
|
|
167
|
-
set connectionProtector(connectionProtector) {
|
|
168
|
-
this._connectionProtector = connectionProtector;
|
|
169
|
-
}
|
|
170
|
-
get metrics() {
|
|
171
|
-
return this._metrics;
|
|
172
|
-
}
|
|
173
|
-
set metrics(metrics) {
|
|
174
|
-
this._metrics = metrics;
|
|
175
|
-
}
|
|
176
|
-
get dht() {
|
|
177
|
-
return this._dht;
|
|
178
|
-
}
|
|
179
|
-
set dht(dht) {
|
|
180
|
-
this._dht = dht;
|
|
181
|
-
}
|
|
182
|
-
get pubsub() {
|
|
183
|
-
return this._pubsub;
|
|
184
|
-
}
|
|
185
|
-
set pubsub(pubsub) {
|
|
186
|
-
this._pubsub = pubsub;
|
|
187
|
-
}
|
|
81
|
+
});
|
|
82
|
+
// @ts-expect-error component keys are proxied
|
|
83
|
+
return proxy;
|
|
188
84
|
}
|
|
189
85
|
//# sourceMappingURL=components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAIrD,OAAO,EAAE,WAAW,EAAa,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAIrD,OAAO,EAAE,WAAW,EAAa,MAAM,8BAA8B,CAAA;AA+CrE,MAAM,iBAAiB;IA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AA;aACjC;YAED,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAC,CAAA;IAEF,8CAA8C;IAC9C,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConnectionGater } from '@libp2p/interface-connection-gater';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a connection gater that disallows dialling private addresses by
|
|
4
|
+
* default. Browsers are severely limited in their resource usage so don't
|
|
5
|
+
* waste time trying to dial undiallable addresses.
|
|
6
|
+
*/
|
|
7
|
+
export declare function connectionGater(gater?: ConnectionGater): ConnectionGater;
|
|
8
|
+
//# sourceMappingURL=connection-gater.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-gater.browser.d.ts","sourceRoot":"","sources":["../../../src/config/connection-gater.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAIzE;;;;GAIG;AACH,wBAAgB,eAAe,CAAE,KAAK,GAAE,eAAoB,GAAG,eAAe,CAqB7E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import isPrivate from 'private-ip';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a connection gater that disallows dialling private addresses by
|
|
4
|
+
* default. Browsers are severely limited in their resource usage so don't
|
|
5
|
+
* waste time trying to dial undiallable addresses.
|
|
6
|
+
*/
|
|
7
|
+
export function connectionGater(gater = {}) {
|
|
8
|
+
return {
|
|
9
|
+
denyDialPeer: async () => false,
|
|
10
|
+
denyDialMultiaddr: async (multiaddr) => {
|
|
11
|
+
const tuples = multiaddr.stringTuples();
|
|
12
|
+
if (tuples[0][0] === 4 || tuples[0][0] === 41) {
|
|
13
|
+
return Boolean(isPrivate(`${tuples[0][1]}`));
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
},
|
|
17
|
+
denyInboundConnection: async () => false,
|
|
18
|
+
denyOutboundConnection: async () => false,
|
|
19
|
+
denyInboundEncryptedConnection: async () => false,
|
|
20
|
+
denyOutboundEncryptedConnection: async () => false,
|
|
21
|
+
denyInboundUpgradedConnection: async () => false,
|
|
22
|
+
denyOutboundUpgradedConnection: async () => false,
|
|
23
|
+
filterMultiaddrForPeer: async () => true,
|
|
24
|
+
...gater
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=connection-gater.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-gater.browser.js","sourceRoot":"","sources":["../../../src/config/connection-gater.browser.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAA;AAElC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAE,QAAyB,EAAE;IAC1D,OAAO;QACL,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAC/B,iBAAiB,EAAE,KAAK,EAAE,SAAoB,EAAE,EAAE;YAChD,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,EAAE,CAAA;YAEvC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC7C,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;aAC7C;YAED,OAAO,KAAK,CAAA;QACd,CAAC;QACD,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACxC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACzC,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACjD,+BAA+B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAClD,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAChD,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACjD,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;QACxC,GAAG,KAAK;KACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ConnectionGater } from '@libp2p/interface-connection-gater';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a default connection gater implementation that allows everything
|
|
4
|
+
*/
|
|
5
|
+
export declare function connectionGater(gater?: ConnectionGater): ConnectionGater;
|
|
6
|
+
//# sourceMappingURL=connection-gater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-gater.d.ts","sourceRoot":"","sources":["../../../src/config/connection-gater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAEzE;;GAEG;AACH,wBAAgB,eAAe,CAAE,KAAK,GAAE,eAAoB,GAAG,eAAe,CAa7E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a default connection gater implementation that allows everything
|
|
3
|
+
*/
|
|
4
|
+
export function connectionGater(gater = {}) {
|
|
5
|
+
return {
|
|
6
|
+
denyDialPeer: async () => false,
|
|
7
|
+
denyDialMultiaddr: async () => false,
|
|
8
|
+
denyInboundConnection: async () => false,
|
|
9
|
+
denyOutboundConnection: async () => false,
|
|
10
|
+
denyInboundEncryptedConnection: async () => false,
|
|
11
|
+
denyOutboundEncryptedConnection: async () => false,
|
|
12
|
+
denyInboundUpgradedConnection: async () => false,
|
|
13
|
+
denyOutboundUpgradedConnection: async () => false,
|
|
14
|
+
filterMultiaddrForPeer: async () => true,
|
|
15
|
+
...gater
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=connection-gater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-gater.js","sourceRoot":"","sources":["../../../src/config/connection-gater.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAE,QAAyB,EAAE;IAC1D,OAAO;QACL,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAC/B,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACpC,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACxC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACzC,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACjD,+BAA+B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAClD,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QAChD,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;QACjD,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;QACxC,GAAG,KAAK;KACT,CAAA;AACH,CAAC"}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Libp2pInit } from './index.js';
|
|
2
2
|
import type { RecursivePartial } from '@libp2p/interfaces';
|
|
3
|
-
|
|
3
|
+
import type { ServiceMap } from '@libp2p/interface-libp2p';
|
|
4
|
+
export declare function validateConfig<T extends ServiceMap = {}>(opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T>;
|
|
4
5
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAoB1D,wBAAgB,cAAc,CAAE,CAAC,SAAS,UAAU,GAAG,EAAE,EAAG,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAgBhH"}
|
package/dist/src/config.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import mergeOptions from 'merge-options';
|
|
2
2
|
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers';
|
|
3
|
-
import { AGENT_VERSION } from './identify/consts.js';
|
|
4
3
|
import { publicAddressesFirst } from '@libp2p/utils/address-sort';
|
|
5
4
|
import { FaultTolerance } from '@libp2p/interface-transport';
|
|
6
5
|
import { codes, messages } from './errors.js';
|
|
7
6
|
import { CodeError } from '@libp2p/interfaces/errors';
|
|
8
|
-
import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe';
|
|
9
7
|
const DefaultConfig = {
|
|
10
8
|
addresses: {
|
|
11
9
|
listen: [],
|
|
@@ -21,57 +19,6 @@ const DefaultConfig = {
|
|
|
21
19
|
},
|
|
22
20
|
transportManager: {
|
|
23
21
|
faultTolerance: FaultTolerance.FATAL_ALL
|
|
24
|
-
},
|
|
25
|
-
peerRouting: {
|
|
26
|
-
refreshManager: {
|
|
27
|
-
enabled: true,
|
|
28
|
-
interval: 6e5,
|
|
29
|
-
bootDelay: 10e3
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
nat: {
|
|
33
|
-
enabled: true,
|
|
34
|
-
ttl: 7200,
|
|
35
|
-
keepAlive: true
|
|
36
|
-
},
|
|
37
|
-
identify: {
|
|
38
|
-
protocolPrefix: 'ipfs',
|
|
39
|
-
host: {
|
|
40
|
-
agentVersion: AGENT_VERSION
|
|
41
|
-
},
|
|
42
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L48
|
|
43
|
-
timeout: 60000,
|
|
44
|
-
maxInboundStreams: 1,
|
|
45
|
-
maxOutboundStreams: 1,
|
|
46
|
-
maxPushIncomingStreams: 1,
|
|
47
|
-
maxPushOutgoingStreams: 1,
|
|
48
|
-
maxObservedAddresses: 10
|
|
49
|
-
},
|
|
50
|
-
ping: {
|
|
51
|
-
protocolPrefix: 'ipfs',
|
|
52
|
-
// See https://github.com/libp2p/specs/blob/d4b5fb0152a6bb86cfd9ea/ping/ping.md?plain=1#L38-L43
|
|
53
|
-
// The dialing peer MUST NOT keep more than one outbound stream for the ping protocol per peer.
|
|
54
|
-
// The listening peer SHOULD accept at most two streams per peer since cross-stream behavior is
|
|
55
|
-
// non-linear and stream writes occur asynchronously. The listening peer may perceive the
|
|
56
|
-
// dialing peer closing and opening the wrong streams (for instance, closing stream B and
|
|
57
|
-
// opening stream A even though the dialing peer is opening stream B and closing stream A).
|
|
58
|
-
maxInboundStreams: 2,
|
|
59
|
-
maxOutboundStreams: 1,
|
|
60
|
-
timeout: 10000
|
|
61
|
-
},
|
|
62
|
-
fetch: {
|
|
63
|
-
protocolPrefix: 'libp2p',
|
|
64
|
-
maxInboundStreams: 1,
|
|
65
|
-
maxOutboundStreams: 1,
|
|
66
|
-
timeout: 10000
|
|
67
|
-
},
|
|
68
|
-
autonat: {
|
|
69
|
-
protocolPrefix: 'libp2p',
|
|
70
|
-
maxInboundStreams: 1,
|
|
71
|
-
maxOutboundStreams: 1,
|
|
72
|
-
timeout: 30000,
|
|
73
|
-
startupDelay: 5000,
|
|
74
|
-
refreshInterval: 60000
|
|
75
22
|
}
|
|
76
23
|
};
|
|
77
24
|
export function validateConfig(opts) {
|
|
@@ -85,15 +32,6 @@ export function validateConfig(opts) {
|
|
|
85
32
|
if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef
|
|
86
33
|
throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED);
|
|
87
34
|
}
|
|
88
|
-
// Append user agent version to default AGENT_VERSION depending on the environment
|
|
89
|
-
if (resultingOptions.identify.host.agentVersion === AGENT_VERSION) {
|
|
90
|
-
if (isNode || isElectronMain) {
|
|
91
|
-
resultingOptions.identify.host.agentVersion += ` UserAgent=${globalThis.process.version}`;
|
|
92
|
-
}
|
|
93
|
-
else if (isBrowser || isWebWorker || isElectronRenderer || isReactNative) {
|
|
94
|
-
resultingOptions.identify.host.agentVersion += ` UserAgent=${globalThis.navigator.userAgent}`;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
35
|
return resultingOptions;
|
|
98
36
|
}
|
|
99
37
|
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAG5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAIrD,MAAM,aAAa,GAAwB;IACzC,SAAS,EAAE;QACT,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,cAAc,EAAE,CAAC,UAAuB,EAAE,EAAE,CAAC,UAAU;KACxD;IACD,iBAAiB,EAAE;QACjB,SAAS,EAAE;YACT,OAAO,EAAE,eAAe;SACzB;QACD,aAAa,EAAE,oBAAoB;KACpC;IACD,gBAAgB,EAAE;QAChB,cAAc,EAAE,cAAc,CAAC,SAAS;KACzC;CACF,CAAA;AAED,MAAM,UAAU,cAAc,CAA8B,IAAqC;IAC/F,MAAM,gBAAgB,GAAkB,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;IAEzE,IAAI,gBAAgB,CAAC,UAAU,IAAI,IAAI,IAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACjF,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,uBAAuB,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACrF;IAED,IAAI,gBAAgB,CAAC,oBAAoB,IAAI,IAAI,IAAI,gBAAgB,CAAC,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE;QACvG,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,wBAAwB,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAA;KACvF;IAED,IAAI,gBAAgB,CAAC,mBAAmB,KAAK,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,IAAI,IAAI,EAAE,EAAE,+BAA+B;QACxI,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;KACnF;IAED,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
2
2
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager';
|
|
3
3
|
import type { Startable } from '@libp2p/interfaces/startable';
|
|
4
|
+
import type { EventEmitter } from '@libp2p/interfaces/events';
|
|
5
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p';
|
|
4
6
|
interface AutoDialInit {
|
|
5
7
|
minConnections?: number;
|
|
6
8
|
autoDialConcurrency?: number;
|
|
@@ -10,6 +12,7 @@ interface AutoDialInit {
|
|
|
10
12
|
interface AutoDialComponents {
|
|
11
13
|
connectionManager: ConnectionManager;
|
|
12
14
|
peerStore: PeerStore;
|
|
15
|
+
events: EventEmitter<Libp2pEvents>;
|
|
13
16
|
}
|
|
14
17
|
export declare class AutoDial implements Startable {
|
|
15
18
|
private readonly connectionManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dial.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dial.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAI7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"auto-dial.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dial.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAI7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAI5D,UAAU,YAAY;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,UAAU,kBAAkB;IAC1B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CACnC;AASD,qBAAa,QAAS,YAAW,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA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