helia-coord 1.2.6 → 1.2.8

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.
@@ -33,12 +33,11 @@ class ThisNodeUseCases {
33
33
  this.circuitRelayInfo = localConfig.circuitRelayInfo
34
34
 
35
35
  // Initialize v1 relay list. Allows user to overwrite with local config.
36
- this.v1Relays = []
37
36
  if (localConfig.v1Relays) {
38
37
  this.v1Relays = localConfig.v1Relays
39
38
  // console.log('v1Relays: ', this.v1Relays)
40
39
  }
41
- // console.log('this-node-use-cases.js v1Relays: ', this.v1Relays)
40
+ console.log('this-node-use-cases.js v1Relays: ', this.v1Relays)
42
41
 
43
42
  // Bind 'this' object to all subfunctions
44
43
  this.updateUseCases = this.updateUseCases.bind(this)
@@ -242,8 +241,8 @@ class ThisNodeUseCases {
242
241
  // - If peer is advertised as a circuit relay, try to connect directly through
243
242
  // the advertised Circuit Relay IP address and port.
244
243
  // - Attempt to connect to peer directly through its advertised multiaddrs.
245
- // - Connect to peer through v2 Circuit Relays (built into ipfs-service-provider)
246
244
  // - Connect to peer through v1 Circuit Relays (standalone v1 Circuit Relay)
245
+ // - Connect to peer through v2 Circuit Relays (built into ipfs-service-provider)
247
246
  async refreshPeerConnections () {
248
247
  try {
249
248
  // console.log('this.thisNode: ', this.thisNode)
@@ -256,7 +255,7 @@ class ThisNodeUseCases {
256
255
  // Get connected peers
257
256
  const connectedPeers = await this.adapters.ipfs.getPeers()
258
257
  this.adapters.log.statusLog(
259
- 2,
258
+ 0,
260
259
  'refreshPeerConnections() connectedPeers: ',
261
260
  connectedPeers
262
261
  )
@@ -271,15 +270,15 @@ class ThisNodeUseCases {
271
270
 
272
271
  // Check if target peer is currently conected to the node.
273
272
  const connectedPeer = connectedPeers.filter(
274
- peerObj => peerObj.peer === thisPeer
273
+ peerObj => peerObj === thisPeer
275
274
  )
276
- // console.log('connectedPeer: ', connectedPeer)
275
+ console.log('connectedPeer: ', connectedPeer)
277
276
 
278
277
  // If this node is already connected to the peer, then skip this peers.
279
278
  // We do not need to do anything.
280
279
  if (connectedPeer.length) {
281
280
  this.adapters.log.statusLog(
282
- 2,
281
+ 0,
283
282
  `Skipping peer in refreshPeerConnections(). Already connected to peer ${thisPeer}`
284
283
  )
285
284
  continue
@@ -348,6 +347,7 @@ class ThisNodeUseCases {
348
347
  break
349
348
  }
350
349
  }
350
+
351
351
  if (connected) {
352
352
  continue
353
353
  }
@@ -370,7 +370,7 @@ class ThisNodeUseCases {
370
370
 
371
371
  // Skip the relay if this node is not connected to it.
372
372
  if (thisRelay.connected) {
373
- this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
373
+ this.adapters.log.statusLog(0, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
374
374
 
375
375
  // Attempt to connect to the node through a circuit relay.
376
376
  connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
@@ -378,7 +378,7 @@ class ThisNodeUseCases {
378
378
  // If the connection was successful, break out of the relay loop.
379
379
  // Otherwise try to connect through the next relay.
380
380
  if (connected) {
381
- this.adapters.log.statusLog(2,
381
+ this.adapters.log.statusLog(0,
382
382
  `Successfully connected to peer ${thisPeer} through v2 circuit relay ${thisRelay.multiaddr}.`
383
383
  )
384
384
 
@@ -393,33 +393,38 @@ class ThisNodeUseCases {
393
393
  }
394
394
  }
395
395
 
396
+ if (connected) {
397
+ continue
398
+ }
399
+
396
400
  // If we could not connect to the node through the v2 Circuit Relays,
397
401
  // try connecting to it through the v1 Circuit Relays.
398
- if (!connected) {
399
- for (let j = 0; j < this.v1Relays.length; j++) {
400
- const thisV1Relay = this.v1Relays[j]
402
+ //
403
+ // Note 11/7/23 CT: v1 Circuit Relays do not appear to be supported by libp2p:
404
+ // https://github.com/libp2p/js-libp2p/issues/2208
405
+ for (let j = 0; j < this.v1Relays.length; j++) {
406
+ const thisV1Relay = this.v1Relays[j]
401
407
 
402
- // Generate a multiaddr for connecting to the peer through a circuit relay.
403
- const multiaddr = `${thisV1Relay.multiaddr}/p2p-circuit/p2p/${thisPeer}`
408
+ // Generate a multiaddr for connecting to the peer through a circuit relay.
409
+ const multiaddr = `${thisV1Relay}/p2p-circuit/p2p/${thisPeer}`
404
410
 
405
- console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
406
- this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
411
+ // console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
412
+ this.adapters.log.statusLog(0, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
407
413
 
408
- // Attempt to connect to the node through a circuit relay.
409
- connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
414
+ // Attempt to connect to the node through a circuit relay.
415
+ connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
410
416
 
411
- if (connected) {
412
- this.adapters.log.statusLog(2,
413
- `Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay.multiaddr}.`
414
- )
417
+ if (connected) {
418
+ this.adapters.log.statusLog(2,
419
+ `Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay}.`
420
+ )
415
421
 
416
- // Add the connection multiaddr to the peer, so that we can see
417
- // exactly how we're connected to the peer.
418
- const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
419
- thisPeerData[0].data.connectionAddr = multiaddr
422
+ // Add the connection multiaddr to the peer, so that we can see
423
+ // exactly how we're connected to the peer.
424
+ const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
425
+ thisPeerData[0].data.connectionAddr = multiaddr
420
426
 
421
- break
422
- }
427
+ break
423
428
  }
424
429
  }
425
430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "helia-coord",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "A JS library for helping IPFS peers coordinate, find a common interest, and stay connected around that interest.",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -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()