helia-coord 1.2.13 → 1.2.15

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  const config = {
6
- DEFAULT_COORDINATION_ROOM: 'psf-ipfs-coordination-002',
6
+ DEFAULT_COORDINATION_ROOM: 'psf-ipfs-coordination-003',
7
7
  BCH_COINJOIN_ROOM: 'bch-coinjoin-001',
8
8
 
9
9
  // Time between retrying private messages to a peer.
@@ -31,7 +31,15 @@ class Gist {
31
31
  const object = JSON.parse(content)
32
32
  // console.log('object: ', object)
33
33
 
34
- return object
34
+ // Keep the linter happy.
35
+ const nullFunc = () => {}
36
+ nullFunc(object)
37
+
38
+ // return object
39
+ return {
40
+ browser: [],
41
+ node: []
42
+ }
35
43
  } catch (err) {
36
44
  console.error('Error attempting to download GitHub Gist of alternative servers.')
37
45
  throw err
@@ -121,7 +121,7 @@ class TimerControllers {
121
121
  clearInterval(this.circuitRelayTimerHandle)
122
122
 
123
123
  // Renew connections to V1 Circuit Relays
124
- await useCases.relays.connectToV1Relays()
124
+ // await useCases.relays.connectToV1Relays()
125
125
 
126
126
  // Remove any duplicate entries
127
127
  useCases.relays.removeDuplicates(thisNode)
@@ -21,10 +21,10 @@ class RelayUseCases {
21
21
 
22
22
  // Initialize v1 relay list. Allows user to overwrite with local config.
23
23
  this.v1Relays = []
24
- if (localConfig.v1Relays) {
25
- this.v1Relays = localConfig.v1Relays
26
- // console.log('v1Relays: ', this.v1Relays)
27
- }
24
+ // if (localConfig.v1Relays) {
25
+ // this.v1Relays = localConfig.v1Relays
26
+ // // console.log('v1Relays: ', this.v1Relays)
27
+ // }
28
28
 
29
29
  // Bind 'this' object to all subfunctions
30
30
  this.connectToV1Relays = this.connectToV1Relays.bind(this)
@@ -262,6 +262,7 @@ class RelayUseCases {
262
262
  }
263
263
  }
264
264
 
265
+ // TODO: Remove. V1 Circuit Relays are deprecated in favor of v2 and webRTC.
265
266
  // If a list of v1 Circuit Relays is provided, then renew connections to them.
266
267
  async connectToV1Relays (relays) {
267
268
  try {
@@ -33,11 +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
- if (localConfig.v1Relays) {
37
- this.v1Relays = localConfig.v1Relays
38
- // console.log('v1Relays: ', this.v1Relays)
39
- }
40
- console.log('this-node-use-cases.js v1Relays: ', this.v1Relays)
36
+ // if (localConfig.v1Relays) {
37
+ // this.v1Relays = localConfig.v1Relays
38
+ // // console.log('v1Relays: ', this.v1Relays)
39
+ // }
40
+ // console.log('this-node-use-cases.js v1Relays: ', this.v1Relays)
41
41
 
42
42
  // Bind 'this' object to all subfunctions
43
43
  this.updateUseCases = this.updateUseCases.bind(this)
@@ -119,7 +119,10 @@ class ThisNodeUseCases {
119
119
  // pubsub-use-cases.js/initializePubSub() depends on this function.
120
120
  async addSubnetPeer (announceObj) {
121
121
  try {
122
- // console.log('announceObj: ', announceObj)
122
+ if (announceObj.from.includes('12D3KooWRqe7TwTj8apPxmpPqPgHiv7qv5YBJTo1VeQ7zrdyA2HN') ||
123
+ announceObj.from.includes('12D3KooWS2CmqrSXWyzeLAAGnPwJhpn4Ax5K562idzSxqua2YCTB')) {
124
+ console.log('announceObj: ', announceObj)
125
+ }
123
126
 
124
127
  // Exit if the announcement object is stale.
125
128
  if (!this.isFreshPeer(announceObj)) return
@@ -242,11 +245,10 @@ class ThisNodeUseCases {
242
245
  // Called by an Interval, ensures connections are maintained to known pubsub
243
246
  // peers. This will heal connections if nodes drop in and out of the network.
244
247
  // Connection workflow:
245
- // - If peer is advertised as a circuit relay, try to connect directly through
246
- // the advertised Circuit Relay IP address and port.
248
+ // - If the peer is a Circuit Relay, skip it. Connecting to it will handled by
249
+ // a Relay use-case function.
247
250
  // - Attempt to connect to peer directly through its advertised multiaddrs.
248
- // - Connect to peer through v1 Circuit Relays (standalone v1 Circuit Relay)
249
- // - Connect to peer through v2 Circuit Relays (built into ipfs-service-provider)
251
+ // - Connect to peer via v2 Circuit Relay over webRTC.
250
252
  async refreshPeerConnections () {
251
253
  try {
252
254
  // console.log('this.thisNode: ', this.thisNode)
@@ -305,29 +307,30 @@ class ThisNodeUseCases {
305
307
  // If peer advertises itself as a Circuit Relay, connect to the circuit
306
308
  // relay connection info
307
309
  if (peerData.data && peerData.data.isCircuitRelay) {
308
- const multiaddr = `/ip4/${peerData.data.circuitRelayInfo.ip4}/tcp/${peerData.data.circuitRelayInfo.tcpPort}/p2p/${thisPeer}`
310
+ continue
311
+ // const multiaddr = `/ip4/${peerData.data.circuitRelayInfo.ip4}/tcp/${peerData.data.circuitRelayInfo.tcpPort}/p2p/${thisPeer}`
309
312
 
310
- connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
313
+ // connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
311
314
  // console.log('circuit relay data connected: ', connected)
312
315
 
313
- if (connected.success) {
314
- this.adapters.log.statusLog(2,
315
- `Successfully connected to Circuit Relay peer ${thisPeer} through direct connection: ${multiaddr}.`
316
- )
317
-
318
- // Add the connection multiaddr to the peer, so that we can see
319
- // exactly how we're connected to the peer.
320
- // const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
321
- // thisPeerData[0].data.connectionAddr = multiaddr
322
- peerData.data.connectionAddr = multiaddr
323
-
324
- // Break out of the loop once we've made a successful connection.
325
- continue
326
- } else {
327
- this.adapters.log.statusLog(2,
328
- `Failed to connect to Circuit Relay peer ${thisPeer} through direct connection: ${multiaddr}. Reason: ${connected.details}`
329
- )
330
- }
316
+ // if (connected.success) {
317
+ // this.adapters.log.statusLog(2,
318
+ // `Successfully connected to Circuit Relay peer ${thisPeer} through direct connection: ${multiaddr}.`
319
+ // )
320
+ //
321
+ // // Add the connection multiaddr to the peer, so that we can see
322
+ // // exactly how we're connected to the peer.
323
+ // // const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
324
+ // // thisPeerData[0].data.connectionAddr = multiaddr
325
+ // // peerData.data.connectionAddr = multiaddr
326
+ //
327
+ // // Break out of the loop once we've made a successful connection.
328
+ // continue
329
+ // } else {
330
+ // this.adapters.log.statusLog(2,
331
+ // `Failed to connect to Circuit Relay peer ${thisPeer} through direct connection: ${multiaddr}. Reason: ${connected.details}`
332
+ // )
333
+ // }
331
334
  }
332
335
 
333
336
  // Try a direct connection with the peer by going through
@@ -345,7 +348,7 @@ class ThisNodeUseCases {
345
348
  // If the connection was successful, break out of the relay loop.
346
349
  // Otherwise try to connect through the next relay.
347
350
  if (connected.success) {
348
- this.adapters.log.statusLog(2,
351
+ this.adapters.log.statusLog(0,
349
352
  `Successfully connected to peer ${thisPeer} through direct connection: ${multiaddr}.`
350
353
  )
351
354
 
@@ -391,7 +394,7 @@ class ThisNodeUseCases {
391
394
 
392
395
  // Skip the relay if this node is not connected to it.
393
396
  if (thisRelay.connected) {
394
- this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
397
+ this.adapters.log.statusLog(0, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
395
398
 
396
399
  // Attempt to connect to the node through a circuit relay.
397
400
  connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
@@ -400,7 +403,7 @@ class ThisNodeUseCases {
400
403
  // If the connection was successful, break out of the relay loop.
401
404
  // Otherwise try to connect through the next relay.
402
405
  if (connected.success) {
403
- this.adapters.log.statusLog(2,
406
+ this.adapters.log.statusLog(0,
404
407
  `Successfully connected to peer ${thisPeer} through v2 circuit relay ${thisRelay.multiaddr}.`
405
408
  )
406
409
 
@@ -413,7 +416,7 @@ class ThisNodeUseCases {
413
416
  // Break out of the loop once we've made a successful connection.
414
417
  break
415
418
  } else {
416
- this.adapters.log.statusLog(2,
419
+ this.adapters.log.statusLog(0,
417
420
  `Failed to connect to peer ${thisPeer} through v2 circuit relay: ${multiaddr}. Reason: ${connected.details}`
418
421
  )
419
422
  }
@@ -429,37 +432,37 @@ class ThisNodeUseCases {
429
432
  //
430
433
  // Note 11/7/23 CT: v1 Circuit Relays do not appear to be supported by libp2p:
431
434
  // https://github.com/libp2p/js-libp2p/issues/2208
432
- for (let j = 0; j < this.v1Relays.length; j++) {
433
- const thisV1Relay = this.v1Relays[j]
434
-
435
- // Generate a multiaddr for connecting to the peer through a circuit relay.
436
- const multiaddr = `${thisV1Relay}/p2p-circuit/p2p/${thisPeer}`
437
-
438
- // console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
439
- this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
440
-
441
- // Attempt to connect to the node through a circuit relay.
442
- connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
443
- // console.log('v1 relay connected: ', connected)
444
-
445
- if (connected.success) {
446
- this.adapters.log.statusLog(2,
447
- `Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay}.`
448
- )
449
-
450
- // Add the connection multiaddr to the peer, so that we can see
451
- // exactly how we're connected to the peer.
452
- // const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
453
- // thisPeerData[0].data.connectionAddr = multiaddr
454
- peerData.data.connectionAddr = multiaddr
455
-
456
- break
457
- } else {
458
- this.adapters.log.statusLog(2,
459
- `Failed to connect to Circuit Relay peer ${thisPeer} through v1 Circuit Relay: ${multiaddr}. Reason: ${connected.details}`
460
- )
461
- }
462
- }
435
+ // for (let j = 0; j < this.v1Relays.length; j++) {
436
+ // const thisV1Relay = this.v1Relays[j]
437
+ //
438
+ // // Generate a multiaddr for connecting to the peer through a circuit relay.
439
+ // const multiaddr = `${thisV1Relay}/p2p-circuit/p2p/${thisPeer}`
440
+ //
441
+ // // console.log(`refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
442
+ // this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer through V1 Circuit Relay with this multiaddr: ${multiaddr}`)
443
+ //
444
+ // // Attempt to connect to the node through a circuit relay.
445
+ // connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
446
+ // // console.log('v1 relay connected: ', connected)
447
+ //
448
+ // if (connected.success) {
449
+ // this.adapters.log.statusLog(2,
450
+ // `Successfully connected to peer ${thisPeer} through v1 circuit relay ${thisV1Relay}.`
451
+ // )
452
+ //
453
+ // // Add the connection multiaddr to the peer, so that we can see
454
+ // // exactly how we're connected to the peer.
455
+ // // const thisPeerData = this.thisNode.peerData.filter(x => x.from === thisPeer)
456
+ // // thisPeerData[0].data.connectionAddr = multiaddr
457
+ // peerData.data.connectionAddr = multiaddr
458
+ //
459
+ // break
460
+ // } else {
461
+ // this.adapters.log.statusLog(2,
462
+ // `Failed to connect to Circuit Relay peer ${thisPeer} through v1 Circuit Relay: ${multiaddr}. Reason: ${connected.details}`
463
+ // )
464
+ // }
465
+ // }
463
466
  }
464
467
 
465
468
  const now = new Date()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "helia-coord",
3
- "version": "1.2.13",
3
+ "version": "1.2.15",
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",
@@ -23,24 +23,24 @@ describe('#Adapter-Gist', () => {
23
23
  afterEach(() => sandbox.restore())
24
24
 
25
25
  describe('#getCRList', () => {
26
- it('should get data from GitHub', async () => {
27
- // Mock network dependencies
28
- sandbox.stub(uut.axios, 'get').resolves({
29
- data: {
30
- files: {
31
- 'psf-public-circuit-relays.json': {
32
- content: JSON.stringify({ key: 'value' })
33
- }
34
- }
35
- }
36
- })
37
-
38
- const result = await uut.getCRList()
39
- // console.log('result: ', result)
40
-
41
- assert.property(result, 'key')
42
- assert.equal(result.key, 'value')
43
- })
26
+ // it('should get data from GitHub', async () => {
27
+ // // Mock network dependencies
28
+ // sandbox.stub(uut.axios, 'get').resolves({
29
+ // data: {
30
+ // files: {
31
+ // 'psf-public-circuit-relays.json': {
32
+ // content: JSON.stringify({ key: 'value' })
33
+ // }
34
+ // }
35
+ // }
36
+ // })
37
+ //
38
+ // const result = await uut.getCRList()
39
+ // // console.log('result: ', result)
40
+ //
41
+ // assert.property(result, 'key')
42
+ // assert.equal(result.key, 'value')
43
+ // })
44
44
 
45
45
  it('should catch and throw errors', async () => {
46
46
  try {