@libp2p/circuit-relay-v2 3.2.16-7eed3b40d → 3.2.17-439d2c9ce
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 +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/transport/discovery.d.ts +11 -6
- package/dist/src/transport/discovery.d.ts.map +1 -1
- package/dist/src/transport/discovery.js +69 -26
- package/dist/src/transport/discovery.js.map +1 -1
- package/package.json +10 -10
- package/src/transport/discovery.ts +86 -27
@@ -1,5 +1,5 @@
|
|
1
1
|
import { TypedEventEmitter } from 'main-event';
|
2
|
-
import type { ComponentLogger, PeerId, PeerStore, Startable, TopologyFilter } from '@libp2p/interface';
|
2
|
+
import type { ComponentLogger, Libp2pEvents, PeerId, PeerInfo, PeerStore, Startable, TopologyFilter, TypedEventTarget } from '@libp2p/interface';
|
3
3
|
import type { ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal';
|
4
4
|
export interface RelayDiscoveryEvents {
|
5
5
|
'relay:discover': CustomEvent<PeerId>;
|
@@ -11,6 +11,7 @@ export interface RelayDiscoveryComponents {
|
|
11
11
|
registrar: Registrar;
|
12
12
|
logger: ComponentLogger;
|
13
13
|
randomWalk: RandomWalk;
|
14
|
+
events: TypedEventTarget<Libp2pEvents>;
|
14
15
|
}
|
15
16
|
export interface RelayDiscoveryInit {
|
16
17
|
filter?: TopologyFilter;
|
@@ -20,10 +21,7 @@ export interface RelayDiscoveryInit {
|
|
20
21
|
* peers that support the circuit v2 HOP protocol.
|
21
22
|
*/
|
22
23
|
export declare class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> implements Startable {
|
23
|
-
private readonly
|
24
|
-
private readonly registrar;
|
25
|
-
private readonly connectionManager;
|
26
|
-
private readonly randomWalk;
|
24
|
+
private readonly components;
|
27
25
|
private started;
|
28
26
|
private running;
|
29
27
|
private topologyId?;
|
@@ -41,9 +39,16 @@ export declare class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEven
|
|
41
39
|
*
|
42
40
|
* 1. Check the metadata store for known relays, try to listen on the ones we are already connected to
|
43
41
|
* 2. Dial and try to listen on the peers we know that support hop but are not connected
|
44
|
-
* 3. Search the network
|
42
|
+
* 3. Search the network - this requires a peer routing implementation to be configured but will fail gracefully
|
43
|
+
* 4. Dial any peers discovered - this covers when no peer routing implementation has been configured but some peer discovery mechanism is also present
|
45
44
|
*/
|
46
45
|
startDiscovery(): void;
|
47
46
|
stopDiscovery(): void;
|
47
|
+
onPeer(evt: CustomEvent<PeerInfo>): void;
|
48
|
+
maybeDialPeer(evt: CustomEvent<PeerInfo>): Promise<void>;
|
49
|
+
dialPeer({ peerId, signal }: {
|
50
|
+
peerId: PeerId;
|
51
|
+
signal?: AbortSignal;
|
52
|
+
}): Promise<void>;
|
48
53
|
}
|
49
54
|
//# sourceMappingURL=discovery.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/transport/discovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAA;AAK/D,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/transport/discovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAA;AAK/D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAgB,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC9J,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE5G,MAAM,WAAW,oBAAo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AE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAY7F"}
|
@@ -8,10 +8,7 @@ import { RELAY_V2_HOP_CODEC } from '../constants.js';
|
|
8
8
|
* peers that support the circuit v2 HOP protocol.
|
9
9
|
*/
|
10
10
|
export class RelayDiscovery extends TypedEventEmitter {
|
11
|
-
|
12
|
-
registrar;
|
13
|
-
connectionManager;
|
14
|
-
randomWalk;
|
11
|
+
components;
|
15
12
|
started;
|
16
13
|
running;
|
17
14
|
topologyId;
|
@@ -22,15 +19,14 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
22
19
|
constructor(components, init = {}) {
|
23
20
|
super();
|
24
21
|
this.log = components.logger.forComponent('libp2p:circuit-relay:discover-relays');
|
22
|
+
this.components = components;
|
25
23
|
this.started = false;
|
26
24
|
this.running = false;
|
27
|
-
this.peerStore = components.peerStore;
|
28
|
-
this.registrar = components.registrar;
|
29
|
-
this.connectionManager = components.connectionManager;
|
30
|
-
this.randomWalk = components.randomWalk;
|
31
25
|
this.filter = init.filter;
|
32
26
|
this.discoveryController = new AbortController();
|
33
27
|
setMaxListeners(Infinity, this.discoveryController.signal);
|
28
|
+
this.dialPeer = this.dialPeer.bind(this);
|
29
|
+
this.onPeer = this.onPeer.bind(this);
|
34
30
|
}
|
35
31
|
isStarted() {
|
36
32
|
return this.started;
|
@@ -38,7 +34,7 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
38
34
|
async start() {
|
39
35
|
// register a topology listener for when new peers are encountered
|
40
36
|
// that support the hop protocol
|
41
|
-
this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC, {
|
37
|
+
this.topologyId = await this.components.registrar.register(RELAY_V2_HOP_CODEC, {
|
42
38
|
filter: this.filter,
|
43
39
|
onConnect: (peerId) => {
|
44
40
|
this.log.trace('discovered relay %p queue (length: %d, active %d)', peerId, this.queue?.size, this.queue?.running);
|
@@ -49,9 +45,11 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
49
45
|
}
|
50
46
|
stop() {
|
51
47
|
if (this.topologyId != null) {
|
52
|
-
this.registrar.unregister(this.topologyId);
|
48
|
+
this.components.registrar.unregister(this.topologyId);
|
49
|
+
}
|
50
|
+
if (this.running) {
|
51
|
+
this.stopDiscovery();
|
53
52
|
}
|
54
|
-
this.discoveryController?.abort();
|
55
53
|
this.started = false;
|
56
54
|
}
|
57
55
|
/**
|
@@ -60,7 +58,8 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
60
58
|
*
|
61
59
|
* 1. Check the metadata store for known relays, try to listen on the ones we are already connected to
|
62
60
|
* 2. Dial and try to listen on the peers we know that support hop but are not connected
|
63
|
-
* 3. Search the network
|
61
|
+
* 3. Search the network - this requires a peer routing implementation to be configured but will fail gracefully
|
62
|
+
* 4. Dial any peers discovered - this covers when no peer routing implementation has been configured but some peer discovery mechanism is also present
|
64
63
|
*/
|
65
64
|
startDiscovery() {
|
66
65
|
if (this.running) {
|
@@ -70,10 +69,12 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
70
69
|
this.running = true;
|
71
70
|
this.discoveryController = new AbortController();
|
72
71
|
setMaxListeners(Infinity, this.discoveryController.signal);
|
72
|
+
// dial any peer we discover
|
73
|
+
this.components.events.addEventListener('peer:discovery', this.onPeer);
|
73
74
|
Promise.resolve()
|
74
75
|
.then(async () => {
|
75
76
|
this.log('searching peer store for relays');
|
76
|
-
const peers = (await this.peerStore.all({
|
77
|
+
const peers = (await this.components.peerStore.all({
|
77
78
|
filters: [
|
78
79
|
// filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on
|
79
80
|
(peer) => {
|
@@ -108,19 +109,19 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
108
109
|
concurrency: 5
|
109
110
|
});
|
110
111
|
this.log('start random walk');
|
111
|
-
for await (const peer of this.randomWalk.walk({ signal: this.discoveryController.signal })) {
|
112
|
+
for await (const peer of this.components.randomWalk.walk({ signal: this.discoveryController.signal })) {
|
112
113
|
this.log.trace('found random peer %p', peer.id);
|
113
114
|
if (queue.has(peer.id)) {
|
114
115
|
this.log.trace('random peer %p was already in queue', peer.id);
|
115
116
|
// skip peers already in the queue
|
116
117
|
continue;
|
117
118
|
}
|
118
|
-
if (this.connectionManager.getConnections(peer.id)?.length > 0) {
|
119
|
+
if (this.components.connectionManager.getConnections(peer.id)?.length > 0) {
|
119
120
|
this.log.trace('random peer %p was already connected', peer.id);
|
120
121
|
// skip peers we are already connected to
|
121
122
|
continue;
|
122
123
|
}
|
123
|
-
if (!(await this.connectionManager.isDialable(peer.multiaddrs))) {
|
124
|
+
if (!(await this.components.connectionManager.isDialable(peer.multiaddrs))) {
|
124
125
|
this.log.trace('random peer %p was not dialable', peer.id, peer.multiaddrs.map(ma => ma.toString()));
|
125
126
|
// skip peers we can't dial
|
126
127
|
continue;
|
@@ -135,16 +136,7 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
135
136
|
this.log('adding random peer %p to dial queue (length: %d, active %d)', peer.id, queue.size, queue.running);
|
136
137
|
// dial the peer - this will cause identify to run and our topology to
|
137
138
|
// be notified and we'll attempt to create reservations
|
138
|
-
queue.add(
|
139
|
-
const signal = anySignal([this.discoveryController.signal, AbortSignal.timeout(5000)]);
|
140
|
-
setMaxListeners(Infinity, signal);
|
141
|
-
try {
|
142
|
-
await this.connectionManager.openConnection(peer.id, { signal });
|
143
|
-
}
|
144
|
-
finally {
|
145
|
-
signal.clear();
|
146
|
-
}
|
147
|
-
}, {
|
139
|
+
queue.add(this.dialPeer, {
|
148
140
|
peerId: peer.id,
|
149
141
|
signal: this.discoveryController.signal
|
150
142
|
})
|
@@ -165,6 +157,57 @@ export class RelayDiscovery extends TypedEventEmitter {
|
|
165
157
|
this.log('stop discovery');
|
166
158
|
this.running = false;
|
167
159
|
this.discoveryController?.abort();
|
160
|
+
this.queue?.clear();
|
161
|
+
// stop dialing any peer we discover
|
162
|
+
this.components.events.removeEventListener('peer:discovery', this.onPeer);
|
163
|
+
}
|
164
|
+
onPeer(evt) {
|
165
|
+
this.log.trace('maybe dialing discovered peer %p - %e', evt.detail.id);
|
166
|
+
this.maybeDialPeer(evt)
|
167
|
+
.catch(err => {
|
168
|
+
this.log.trace('error dialing discovered peer %p - %e', evt.detail.id, err);
|
169
|
+
});
|
170
|
+
}
|
171
|
+
async maybeDialPeer(evt) {
|
172
|
+
if (this.queue == null) {
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
const peerId = evt.detail.id;
|
176
|
+
const multiaddrs = evt.detail.multiaddrs;
|
177
|
+
if (this.queue.has(peerId)) {
|
178
|
+
this.log.trace('random peer %p was already in queue', peerId);
|
179
|
+
// skip peers already in the queue
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
if (this.components.connectionManager.getConnections(peerId)?.length > 0) {
|
183
|
+
this.log.trace('random peer %p was already connected', peerId);
|
184
|
+
// skip peers we are already connected to
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
if (!(await this.components.connectionManager.isDialable(multiaddrs))) {
|
188
|
+
this.log.trace('random peer %p was not dialable', peerId);
|
189
|
+
// skip peers we can't dial
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
this.queue?.add(this.dialPeer, {
|
193
|
+
peerId: evt.detail.id,
|
194
|
+
signal: this.discoveryController.signal
|
195
|
+
})
|
196
|
+
.catch(err => {
|
197
|
+
this.log.error('error opening connection to discovered peer %p', evt.detail.id, err);
|
198
|
+
});
|
199
|
+
}
|
200
|
+
async dialPeer({ peerId, signal }) {
|
201
|
+
const combinedSignal = anySignal([AbortSignal.timeout(5_000), signal]);
|
202
|
+
setMaxListeners(Infinity, combinedSignal);
|
203
|
+
try {
|
204
|
+
await this.components.connectionManager.openConnection(peerId, {
|
205
|
+
signal: combinedSignal
|
206
|
+
});
|
207
|
+
}
|
208
|
+
finally {
|
209
|
+
combinedSignal.clear();
|
210
|
+
}
|
168
211
|
}
|
169
212
|
}
|
170
213
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/transport/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/transport/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AAsBxB;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,iBAAuC;IACxD,UAAU,CAA0B;IAC7C,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,UAAU,CAAS;IACV,GAAG,CAAQ;IACpB,mBAAmB,CAAiB;IAC3B,MAAM,CAAiB;IAChC,KAAK,CAAY;IAEzB,YAAa,UAAoC,EAAE,OAA2B,EAAE;QAC9E,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,sCAAsC,CAAC,CAAA;QACjF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI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QAAQ,EAAE,cAAc,CAAC,CAAA;QAEzC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAAC,MAAM,EAAE;gBAC7D,MAAM,EAAE,cAAc;aACvB,CAAC,CAAA;QACJ,CAAC;gBAAS,CAAC;YACT,cAAc,CAAC,KAAK,EAAE,CAAA;QACxB,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,WAAW,CAAE,IAAU;IAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;IAEvD,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/circuit-relay-v2",
|
3
|
-
"version": "3.2.
|
3
|
+
"version": "3.2.17-439d2c9ce",
|
4
4
|
"description": "Implementation of Circuit Relay v2",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-circuit-relay-v2#readme",
|
@@ -45,13 +45,13 @@
|
|
45
45
|
"doc-check": "aegir doc-check"
|
46
46
|
},
|
47
47
|
"dependencies": {
|
48
|
-
"@libp2p/crypto": "5.1.6-
|
49
|
-
"@libp2p/interface": "2.10.4-
|
50
|
-
"@libp2p/interface-internal": "2.3.
|
51
|
-
"@libp2p/peer-collections": "6.0.
|
52
|
-
"@libp2p/peer-id": "5.1.7-
|
53
|
-
"@libp2p/peer-record": "8.0.
|
54
|
-
"@libp2p/utils": "6.
|
48
|
+
"@libp2p/crypto": "5.1.6-439d2c9ce",
|
49
|
+
"@libp2p/interface": "2.10.4-439d2c9ce",
|
50
|
+
"@libp2p/interface-internal": "2.3.17-439d2c9ce",
|
51
|
+
"@libp2p/peer-collections": "6.0.33-439d2c9ce",
|
52
|
+
"@libp2p/peer-id": "5.1.7-439d2c9ce",
|
53
|
+
"@libp2p/peer-record": "8.0.33-439d2c9ce",
|
54
|
+
"@libp2p/utils": "6.7.0-439d2c9ce",
|
55
55
|
"@multiformats/multiaddr": "^12.4.4",
|
56
56
|
"@multiformats/multiaddr-matcher": "^1.7.2",
|
57
57
|
"any-signal": "^4.1.1",
|
@@ -67,8 +67,8 @@
|
|
67
67
|
"uint8arrays": "^5.1.0"
|
68
68
|
},
|
69
69
|
"devDependencies": {
|
70
|
-
"@libp2p/interface-compliance-tests": "6.4.
|
71
|
-
"@libp2p/logger": "5.1.20-
|
70
|
+
"@libp2p/interface-compliance-tests": "6.4.11-439d2c9ce",
|
71
|
+
"@libp2p/logger": "5.1.20-439d2c9ce",
|
72
72
|
"aegir": "^47.0.14",
|
73
73
|
"delay": "^6.0.0",
|
74
74
|
"it-drain": "^3.0.9",
|
@@ -5,7 +5,7 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
5
5
|
import {
|
6
6
|
RELAY_V2_HOP_CODEC
|
7
7
|
} from '../constants.js'
|
8
|
-
import type { ComponentLogger, Logger, Peer, PeerId, PeerStore, Startable, TopologyFilter } from '@libp2p/interface'
|
8
|
+
import type { ComponentLogger, Libp2pEvents, Logger, Peer, PeerId, PeerInfo, PeerStore, Startable, TopologyFilter, TypedEventTarget } from '@libp2p/interface'
|
9
9
|
import type { ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal'
|
10
10
|
|
11
11
|
export interface RelayDiscoveryEvents {
|
@@ -19,6 +19,7 @@ export interface RelayDiscoveryComponents {
|
|
19
19
|
registrar: Registrar
|
20
20
|
logger: ComponentLogger
|
21
21
|
randomWalk: RandomWalk
|
22
|
+
events: TypedEventTarget<Libp2pEvents>
|
22
23
|
}
|
23
24
|
|
24
25
|
export interface RelayDiscoveryInit {
|
@@ -30,10 +31,7 @@ export interface RelayDiscoveryInit {
|
|
30
31
|
* peers that support the circuit v2 HOP protocol.
|
31
32
|
*/
|
32
33
|
export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> implements Startable {
|
33
|
-
private readonly
|
34
|
-
private readonly registrar: Registrar
|
35
|
-
private readonly connectionManager: ConnectionManager
|
36
|
-
private readonly randomWalk: RandomWalk
|
34
|
+
private readonly components: RelayDiscoveryComponents
|
37
35
|
private started: boolean
|
38
36
|
private running: boolean
|
39
37
|
private topologyId?: string
|
@@ -46,15 +44,14 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
46
44
|
super()
|
47
45
|
|
48
46
|
this.log = components.logger.forComponent('libp2p:circuit-relay:discover-relays')
|
47
|
+
this.components = components
|
49
48
|
this.started = false
|
50
49
|
this.running = false
|
51
|
-
this.peerStore = components.peerStore
|
52
|
-
this.registrar = components.registrar
|
53
|
-
this.connectionManager = components.connectionManager
|
54
|
-
this.randomWalk = components.randomWalk
|
55
50
|
this.filter = init.filter
|
56
51
|
this.discoveryController = new AbortController()
|
57
52
|
setMaxListeners(Infinity, this.discoveryController.signal)
|
53
|
+
this.dialPeer = this.dialPeer.bind(this)
|
54
|
+
this.onPeer = this.onPeer.bind(this)
|
58
55
|
}
|
59
56
|
|
60
57
|
isStarted (): boolean {
|
@@ -64,7 +61,7 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
64
61
|
async start (): Promise<void> {
|
65
62
|
// register a topology listener for when new peers are encountered
|
66
63
|
// that support the hop protocol
|
67
|
-
this.topologyId = await this.registrar.register(RELAY_V2_HOP_CODEC, {
|
64
|
+
this.topologyId = await this.components.registrar.register(RELAY_V2_HOP_CODEC, {
|
68
65
|
filter: this.filter,
|
69
66
|
onConnect: (peerId) => {
|
70
67
|
this.log.trace('discovered relay %p queue (length: %d, active %d)', peerId, this.queue?.size, this.queue?.running)
|
@@ -77,10 +74,13 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
77
74
|
|
78
75
|
stop (): void {
|
79
76
|
if (this.topologyId != null) {
|
80
|
-
this.registrar.unregister(this.topologyId)
|
77
|
+
this.components.registrar.unregister(this.topologyId)
|
78
|
+
}
|
79
|
+
|
80
|
+
if (this.running) {
|
81
|
+
this.stopDiscovery()
|
81
82
|
}
|
82
83
|
|
83
|
-
this.discoveryController?.abort()
|
84
84
|
this.started = false
|
85
85
|
}
|
86
86
|
|
@@ -90,7 +90,8 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
90
90
|
*
|
91
91
|
* 1. Check the metadata store for known relays, try to listen on the ones we are already connected to
|
92
92
|
* 2. Dial and try to listen on the peers we know that support hop but are not connected
|
93
|
-
* 3. Search the network
|
93
|
+
* 3. Search the network - this requires a peer routing implementation to be configured but will fail gracefully
|
94
|
+
* 4. Dial any peers discovered - this covers when no peer routing implementation has been configured but some peer discovery mechanism is also present
|
94
95
|
*/
|
95
96
|
startDiscovery (): void {
|
96
97
|
if (this.running) {
|
@@ -102,11 +103,14 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
102
103
|
this.discoveryController = new AbortController()
|
103
104
|
setMaxListeners(Infinity, this.discoveryController.signal)
|
104
105
|
|
106
|
+
// dial any peer we discover
|
107
|
+
this.components.events.addEventListener('peer:discovery', this.onPeer)
|
108
|
+
|
105
109
|
Promise.resolve()
|
106
110
|
.then(async () => {
|
107
111
|
this.log('searching peer store for relays')
|
108
112
|
|
109
|
-
const peers = (await this.peerStore.all({
|
113
|
+
const peers = (await this.components.peerStore.all({
|
110
114
|
filters: [
|
111
115
|
// filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on
|
112
116
|
(peer) => {
|
@@ -149,7 +153,7 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
149
153
|
|
150
154
|
this.log('start random walk')
|
151
155
|
|
152
|
-
for await (const peer of this.randomWalk.walk({ signal: this.discoveryController.signal })) {
|
156
|
+
for await (const peer of this.components.randomWalk.walk({ signal: this.discoveryController.signal })) {
|
153
157
|
this.log.trace('found random peer %p', peer.id)
|
154
158
|
|
155
159
|
if (queue.has(peer.id)) {
|
@@ -159,14 +163,14 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
159
163
|
continue
|
160
164
|
}
|
161
165
|
|
162
|
-
if (this.connectionManager.getConnections(peer.id)?.length > 0) {
|
166
|
+
if (this.components.connectionManager.getConnections(peer.id)?.length > 0) {
|
163
167
|
this.log.trace('random peer %p was already connected', peer.id)
|
164
168
|
|
165
169
|
// skip peers we are already connected to
|
166
170
|
continue
|
167
171
|
}
|
168
172
|
|
169
|
-
if (!(await this.connectionManager.isDialable(peer.multiaddrs))) {
|
173
|
+
if (!(await this.components.connectionManager.isDialable(peer.multiaddrs))) {
|
170
174
|
this.log.trace('random peer %p was not dialable', peer.id, peer.multiaddrs.map(ma => ma.toString()))
|
171
175
|
|
172
176
|
// skip peers we can't dial
|
@@ -186,16 +190,7 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
186
190
|
|
187
191
|
// dial the peer - this will cause identify to run and our topology to
|
188
192
|
// be notified and we'll attempt to create reservations
|
189
|
-
queue.add(
|
190
|
-
const signal = anySignal([this.discoveryController.signal, AbortSignal.timeout(5000)])
|
191
|
-
setMaxListeners(Infinity, signal)
|
192
|
-
|
193
|
-
try {
|
194
|
-
await this.connectionManager.openConnection(peer.id, { signal })
|
195
|
-
} finally {
|
196
|
-
signal.clear()
|
197
|
-
}
|
198
|
-
}, {
|
193
|
+
queue.add(this.dialPeer, {
|
199
194
|
peerId: peer.id,
|
200
195
|
signal: this.discoveryController.signal
|
201
196
|
})
|
@@ -219,6 +214,70 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
|
|
219
214
|
this.log('stop discovery')
|
220
215
|
this.running = false
|
221
216
|
this.discoveryController?.abort()
|
217
|
+
this.queue?.clear()
|
218
|
+
|
219
|
+
// stop dialing any peer we discover
|
220
|
+
this.components.events.removeEventListener('peer:discovery', this.onPeer)
|
221
|
+
}
|
222
|
+
|
223
|
+
onPeer (evt: CustomEvent<PeerInfo>): void {
|
224
|
+
this.log.trace('maybe dialing discovered peer %p - %e', evt.detail.id)
|
225
|
+
|
226
|
+
this.maybeDialPeer(evt)
|
227
|
+
.catch(err => {
|
228
|
+
this.log.trace('error dialing discovered peer %p - %e', evt.detail.id, err)
|
229
|
+
})
|
230
|
+
}
|
231
|
+
|
232
|
+
async maybeDialPeer (evt: CustomEvent<PeerInfo>): Promise<void> {
|
233
|
+
if (this.queue == null) {
|
234
|
+
return
|
235
|
+
}
|
236
|
+
|
237
|
+
const peerId = evt.detail.id
|
238
|
+
const multiaddrs = evt.detail.multiaddrs
|
239
|
+
|
240
|
+
if (this.queue.has(peerId)) {
|
241
|
+
this.log.trace('random peer %p was already in queue', peerId)
|
242
|
+
|
243
|
+
// skip peers already in the queue
|
244
|
+
return
|
245
|
+
}
|
246
|
+
|
247
|
+
if (this.components.connectionManager.getConnections(peerId)?.length > 0) {
|
248
|
+
this.log.trace('random peer %p was already connected', peerId)
|
249
|
+
|
250
|
+
// skip peers we are already connected to
|
251
|
+
return
|
252
|
+
}
|
253
|
+
|
254
|
+
if (!(await this.components.connectionManager.isDialable(multiaddrs))) {
|
255
|
+
this.log.trace('random peer %p was not dialable', peerId)
|
256
|
+
|
257
|
+
// skip peers we can't dial
|
258
|
+
return
|
259
|
+
}
|
260
|
+
|
261
|
+
this.queue?.add(this.dialPeer, {
|
262
|
+
peerId: evt.detail.id,
|
263
|
+
signal: this.discoveryController.signal
|
264
|
+
})
|
265
|
+
.catch(err => {
|
266
|
+
this.log.error('error opening connection to discovered peer %p', evt.detail.id, err)
|
267
|
+
})
|
268
|
+
}
|
269
|
+
|
270
|
+
async dialPeer ({ peerId, signal }: { peerId: PeerId, signal?: AbortSignal }): Promise<void> {
|
271
|
+
const combinedSignal = anySignal([AbortSignal.timeout(5_000), signal])
|
272
|
+
setMaxListeners(Infinity, combinedSignal)
|
273
|
+
|
274
|
+
try {
|
275
|
+
await this.components.connectionManager.openConnection(peerId, {
|
276
|
+
signal: combinedSignal
|
277
|
+
})
|
278
|
+
} finally {
|
279
|
+
combinedSignal.clear()
|
280
|
+
}
|
222
281
|
}
|
223
282
|
}
|
224
283
|
|