helia-coord 1.2.7 → 1.2.9
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.
|
@@ -255,7 +255,7 @@ class ThisNodeUseCases {
|
|
|
255
255
|
// Get connected peers
|
|
256
256
|
const connectedPeers = await this.adapters.ipfs.getPeers()
|
|
257
257
|
this.adapters.log.statusLog(
|
|
258
|
-
|
|
258
|
+
0,
|
|
259
259
|
'refreshPeerConnections() connectedPeers: ',
|
|
260
260
|
connectedPeers
|
|
261
261
|
)
|
|
@@ -270,15 +270,15 @@ class ThisNodeUseCases {
|
|
|
270
270
|
|
|
271
271
|
// Check if target peer is currently conected to the node.
|
|
272
272
|
const connectedPeer = connectedPeers.filter(
|
|
273
|
-
peerObj => peerObj
|
|
273
|
+
peerObj => peerObj === thisPeer
|
|
274
274
|
)
|
|
275
|
-
|
|
275
|
+
console.log('connectedPeer: ', connectedPeer)
|
|
276
276
|
|
|
277
277
|
// If this node is already connected to the peer, then skip this peers.
|
|
278
278
|
// We do not need to do anything.
|
|
279
279
|
if (connectedPeer.length) {
|
|
280
280
|
this.adapters.log.statusLog(
|
|
281
|
-
|
|
281
|
+
0,
|
|
282
282
|
`Skipping peer in refreshPeerConnections(). Already connected to peer ${thisPeer}`
|
|
283
283
|
)
|
|
284
284
|
continue
|
|
@@ -296,7 +296,7 @@ class ThisNodeUseCases {
|
|
|
296
296
|
continue
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
let connected = false
|
|
299
|
+
let connected = { success: false }
|
|
300
300
|
|
|
301
301
|
// If peer advertises itself as a Circuit Relay, connect to the circuit
|
|
302
302
|
// relay connection info
|
|
@@ -304,8 +304,9 @@ class ThisNodeUseCases {
|
|
|
304
304
|
const multiaddr = `/ip4/${peerData.data.circuitRelayInfo.ip4}/tcp/${peerData.data.circuitRelayInfo.tcpPort}/p2p/${thisPeer}`
|
|
305
305
|
|
|
306
306
|
connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
307
|
+
console.log('circuit relay data connected: ', connected)
|
|
307
308
|
|
|
308
|
-
if (connected) {
|
|
309
|
+
if (connected.success) {
|
|
309
310
|
this.adapters.log.statusLog(2,
|
|
310
311
|
`Successfully connected to Circuit Relay peer ${thisPeer} through direct connection: ${multiaddr}.`
|
|
311
312
|
)
|
|
@@ -330,10 +331,11 @@ class ThisNodeUseCases {
|
|
|
330
331
|
|
|
331
332
|
// Attempt to connect to the node through a circuit relay.
|
|
332
333
|
connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
334
|
+
console.log('direct connection connected: ', connected)
|
|
333
335
|
|
|
334
336
|
// If the connection was successful, break out of the relay loop.
|
|
335
337
|
// Otherwise try to connect through the next relay.
|
|
336
|
-
if (connected) {
|
|
338
|
+
if (connected.success) {
|
|
337
339
|
this.adapters.log.statusLog(2,
|
|
338
340
|
`Successfully connected to peer ${thisPeer} through direct connection: ${multiaddr}.`
|
|
339
341
|
)
|
|
@@ -348,39 +350,7 @@ class ThisNodeUseCases {
|
|
|
348
350
|
}
|
|
349
351
|
}
|
|
350
352
|
|
|
351
|
-
if (connected) {
|
|
352
|
-
continue
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// If we could not connect to the node through the v2 Circuit Relays,
|
|
356
|
-
// try connecting to it through the v1 Circuit Relays.
|
|
357
|
-
for (let j = 0; j < this.v1Relays.length; j++) {
|
|
358
|
-
const thisV1Relay = this.v1Relays[j]
|
|
359
|
-
|
|
360
|
-
// Generate a multiaddr for connecting to the peer through a circuit relay.
|
|
361
|
-
const multiaddr = `${thisV1Relay}/p2p-circuit/p2p/${thisPeer}`
|
|
362
|
-
|
|
363
|
-
console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
|
|
364
|
-
this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
|
|
365
|
-
|
|
366
|
-
// Attempt to connect to the node through a circuit relay.
|
|
367
|
-
connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
368
|
-
|
|
369
|
-
if (connected) {
|
|
370
|
-
this.adapters.log.statusLog(2,
|
|
371
|
-
`Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay}.`
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
// Add the connection multiaddr to the peer, so that we can see
|
|
375
|
-
// exactly how we're connected to the peer.
|
|
376
|
-
const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
|
|
377
|
-
thisPeerData[0].data.connectionAddr = multiaddr
|
|
378
|
-
|
|
379
|
-
break
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (connected) {
|
|
353
|
+
if (connected.success) {
|
|
384
354
|
continue
|
|
385
355
|
}
|
|
386
356
|
|
|
@@ -402,15 +372,16 @@ class ThisNodeUseCases {
|
|
|
402
372
|
|
|
403
373
|
// Skip the relay if this node is not connected to it.
|
|
404
374
|
if (thisRelay.connected) {
|
|
405
|
-
this.adapters.log.statusLog(
|
|
375
|
+
this.adapters.log.statusLog(0, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
|
|
406
376
|
|
|
407
377
|
// Attempt to connect to the node through a circuit relay.
|
|
408
378
|
connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
379
|
+
console.log('v2 relay connected: ', connected)
|
|
409
380
|
|
|
410
381
|
// If the connection was successful, break out of the relay loop.
|
|
411
382
|
// Otherwise try to connect through the next relay.
|
|
412
|
-
if (connected) {
|
|
413
|
-
this.adapters.log.statusLog(
|
|
383
|
+
if (connected.success) {
|
|
384
|
+
this.adapters.log.statusLog(0,
|
|
414
385
|
`Successfully connected to peer ${thisPeer} through v2 circuit relay ${thisRelay.multiaddr}.`
|
|
415
386
|
)
|
|
416
387
|
|
|
@@ -424,6 +395,42 @@ class ThisNodeUseCases {
|
|
|
424
395
|
}
|
|
425
396
|
}
|
|
426
397
|
}
|
|
398
|
+
|
|
399
|
+
if (connected.success) {
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// If we could not connect to the node through the v2 Circuit Relays,
|
|
404
|
+
// try connecting to it through the v1 Circuit Relays.
|
|
405
|
+
//
|
|
406
|
+
// Note 11/7/23 CT: v1 Circuit Relays do not appear to be supported by libp2p:
|
|
407
|
+
// https://github.com/libp2p/js-libp2p/issues/2208
|
|
408
|
+
for (let j = 0; j < this.v1Relays.length; j++) {
|
|
409
|
+
const thisV1Relay = this.v1Relays[j]
|
|
410
|
+
|
|
411
|
+
// Generate a multiaddr for connecting to the peer through a circuit relay.
|
|
412
|
+
const multiaddr = `${thisV1Relay}/p2p-circuit/p2p/${thisPeer}`
|
|
413
|
+
|
|
414
|
+
// console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
|
|
415
|
+
this.adapters.log.statusLog(0, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
|
|
416
|
+
|
|
417
|
+
// Attempt to connect to the node through a circuit relay.
|
|
418
|
+
connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
419
|
+
console.log('v1 relay connected: ', connected)
|
|
420
|
+
|
|
421
|
+
if (connected.success) {
|
|
422
|
+
this.adapters.log.statusLog(2,
|
|
423
|
+
`Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay}.`
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
// Add the connection multiaddr to the peer, so that we can see
|
|
427
|
+
// exactly how we're connected to the peer.
|
|
428
|
+
const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
|
|
429
|
+
thisPeerData[0].data.connectionAddr = multiaddr
|
|
430
|
+
|
|
431
|
+
break
|
|
432
|
+
}
|
|
433
|
+
}
|
|
427
434
|
}
|
|
428
435
|
|
|
429
436
|
const now = new Date()
|
package/package.json
CHANGED
|
@@ -204,7 +204,8 @@ describe('#thisNode-Use-Cases', () => {
|
|
|
204
204
|
await uut.addSubnetPeer(mockData.announceObj2)
|
|
205
205
|
|
|
206
206
|
// Mock dependencies
|
|
207
|
-
sandbox.stub(uut.adapters.ipfs, 'getPeers').resolves(mockData.swarmPeers)
|
|
207
|
+
// sandbox.stub(uut.adapters.ipfs, 'getPeers').resolves(mockData.swarmPeers)
|
|
208
|
+
sandbox.stub(uut.adapters.ipfs, 'getPeers').resolves(['QmbyYXKbnAmMbMGo8LRBZ58jYs58anqUzY1m4jxDmhDsjd'])
|
|
208
209
|
|
|
209
210
|
// Connect to that peer.
|
|
210
211
|
const result = await uut.refreshPeerConnections()
|
|
@@ -292,7 +293,7 @@ describe('#thisNode-Use-Cases', () => {
|
|
|
292
293
|
sandbox.stub(uut.adapters.ipfs, 'getPeers').resolves(mockData.swarmPeers)
|
|
293
294
|
sandbox.stub(uut, 'isFreshPeer').returns(true)
|
|
294
295
|
sandbox.stub(uut.adapters.ipfs, 'connectToPeer')
|
|
295
|
-
.onCall(0).resolves(true)
|
|
296
|
+
.onCall(0).resolves({ success: true })
|
|
296
297
|
sandbox.stub(uut.utils, 'filterMultiaddrs').returns([])
|
|
297
298
|
|
|
298
299
|
// Connect to that peer.
|
|
@@ -318,7 +319,7 @@ describe('#thisNode-Use-Cases', () => {
|
|
|
318
319
|
sandbox.stub(uut.adapters.ipfs, 'getPeers').resolves(mockData.swarmPeers)
|
|
319
320
|
sandbox.stub(uut, 'isFreshPeer').returns(true)
|
|
320
321
|
sandbox.stub(uut.adapters.ipfs, 'connectToPeer')
|
|
321
|
-
.onCall(0).resolves(true)
|
|
322
|
+
.onCall(0).resolves({ success: true })
|
|
322
323
|
sandbox.stub(uut.utils, 'filterMultiaddrs').returns(['/ip4/123.45.6.7/p2p/ipfs-id'])
|
|
323
324
|
|
|
324
325
|
// Connect to that peer.
|