helia-coord 1.2.19 → 1.2.21

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.
@@ -23,20 +23,20 @@ const BOOTSTRAP_BROWSER_CRs = [
23
23
  ]
24
24
 
25
25
  const BOOTSTRAP_NODE_CRs = [
26
- {
27
- name: 'psf1.tokentiger.com',
28
- multiaddr: '/ip4/137.184.93.145/tcp/8001/p2p/12D3KooWGMEKkdJfyZbwdH9EafZbRTtMn7FnhWPrE4MhRty2763g',
29
- connected: false,
30
- ipfsId: '12D3KooWGMEKkdJfyZbwdH9EafZbRTtMn7FnhWPrE4MhRty2763g',
31
- isBootstrap: true
32
- },
33
- {
34
- name: 'cr1.psfoundatoin.info',
35
- multiaddr: '/ip4/78.46.129.7/tcp/4001/p2p/12D3KooWFQ11GQ5NubsJGhYZ4X3wrAGimLevxfm6HPExCrMYhpSL',
36
- connected: false,
37
- ipfsId: '12D3KooWFQ11GQ5NubsJGhYZ4X3wrAGimLevxfm6HPExCrMYhpSL',
38
- isBootstrap: true
39
- }
26
+ // {
27
+ // name: 'psf1.tokentiger.com',
28
+ // multiaddr: '/ip4/137.184.93.145/tcp/8001/p2p/12D3KooWGMEKkdJfyZbwdH9EafZbRTtMn7FnhWPrE4MhRty2763g',
29
+ // connected: false,
30
+ // ipfsId: '12D3KooWGMEKkdJfyZbwdH9EafZbRTtMn7FnhWPrE4MhRty2763g',
31
+ // isBootstrap: true
32
+ // },
33
+ // {
34
+ // name: 'cr1.psfoundatoin.info',
35
+ // multiaddr: '/ip4/78.46.129.7/tcp/4001/p2p/12D3KooWFQ11GQ5NubsJGhYZ4X3wrAGimLevxfm6HPExCrMYhpSL',
36
+ // connected: false,
37
+ // ipfsId: '12D3KooWFQ11GQ5NubsJGhYZ4X3wrAGimLevxfm6HPExCrMYhpSL',
38
+ // isBootstrap: true
39
+ // }
40
40
  ]
41
41
 
42
42
  const bootstrapCircuitRelays = {
@@ -36,10 +36,11 @@ class Gist {
36
36
  nullFunc(object)
37
37
 
38
38
  // return object
39
- return {
40
- browser: [],
41
- node: []
42
- }
39
+ return object
40
+ // return {
41
+ // browser: [],
42
+ // node: []
43
+ // }
43
44
  } catch (err) {
44
45
  console.error('Error attempting to download GitHub Gist of alternative servers.')
45
46
  throw err
@@ -19,6 +19,9 @@ class RelayUseCases {
19
19
  )
20
20
  }
21
21
 
22
+ // Encapsulate dependencies
23
+ this.bootstrapCircuitRelays = bootstrapCircuitRelays
24
+
22
25
  // Initialize v1 relay list. Allows user to overwrite with local config.
23
26
  this.bootstrapRelays = []
24
27
  if (localConfig.bootstrapRelays) {
@@ -43,9 +46,9 @@ class RelayUseCases {
43
46
  // Set the initial CR bootstrap nodes based on the type of IPFS node.
44
47
  let bootstrapRelays = []
45
48
  if (thisNode.type === 'browser') {
46
- bootstrapRelays = bootstrapCircuitRelays.browser
49
+ bootstrapRelays = this.bootstrapCircuitRelays.browser
47
50
  } else {
48
- bootstrapRelays = bootstrapCircuitRelays.node
51
+ bootstrapRelays = this.bootstrapCircuitRelays.node
49
52
  }
50
53
 
51
54
  // Loop through each bootstrap Relay.
@@ -6,6 +6,7 @@
6
6
  import ThisNodeEntity from '../entities/this-node-entity.js'
7
7
  import Schema from './schema.js'
8
8
  import Util from '../util/utils.js'
9
+ import { publicIpv4 } from 'public-ip'
9
10
 
10
11
  class ThisNodeUseCases {
11
12
  constructor (localConfig = {}) {
@@ -19,9 +20,11 @@ class ThisNodeUseCases {
19
20
 
20
21
  // Encapsulate dependencies
21
22
  this.utils = new Util()
23
+ this.publicIp = publicIpv4
22
24
 
23
25
  // Optional JSON-LD used for announcements. If present, will override
24
26
  // default announcement object in Schema library.
27
+ this.tcpPort = localConfig.tcpPort
25
28
  this.announceJsonLd = localConfig.announceJsonLd
26
29
 
27
30
  // If consuming app wants to configure itself as a Circuit Relay, it can
@@ -70,6 +73,15 @@ class ThisNodeUseCases {
70
73
  selfData.ipfsId = this.adapters.ipfs.ipfsPeerId
71
74
  selfData.ipfsMultiaddrs = this.adapters.ipfs.ipfsMultiaddrs
72
75
 
76
+ // Try to auto-detect the public multiaddr and add it.
77
+ if (this.tcpPort) {
78
+ const ip4 = await this.publicIp()
79
+ console.log(`helia-coord using this IP address: ${ip4}, and this TCP port: ${this.tcpPort}`)
80
+ const detectedMultiaddr = `/ip4/${ip4}/tcp/${this.tcpPort}/p2p/${selfData.ipfsId}`
81
+ // detectedMultiaddr = this.multiaddr(detectedMultiaddr)
82
+ selfData.ipfsMultiaddrs.push(detectedMultiaddr)
83
+ }
84
+
73
85
  // Aggregate data from the BCH adapter.
74
86
  const bchData = await this.adapters.bch.generateBchId()
75
87
  selfData.bchAddr = bchData.cashAddress
@@ -256,7 +268,7 @@ class ThisNodeUseCases {
256
268
  // Get connected peers
257
269
  const connectedPeers = await this.adapters.ipfs.getPeers()
258
270
  this.adapters.log.statusLog(
259
- 2,
271
+ 0,
260
272
  'refreshPeerConnections() connectedPeers: ',
261
273
  connectedPeers
262
274
  )
@@ -279,7 +291,7 @@ class ThisNodeUseCases {
279
291
  // We do not need to do anything.
280
292
  if (connectedPeer.length) {
281
293
  this.adapters.log.statusLog(
282
- 2,
294
+ 0,
283
295
  `Skipping peer in refreshPeerConnections(). Already connected to peer ${thisPeer}`
284
296
  )
285
297
  continue
@@ -293,7 +305,7 @@ class ThisNodeUseCases {
293
305
  // If broadcastedAt value is older than 10 minutes, skip connecting
294
306
  // to the peer. It may be stale information.
295
307
  if (!this.isFreshPeer(peerData)) {
296
- this.adapters.log.statusLog(2, `Peer ${peerData.from} is stale. Skipping.`)
308
+ this.adapters.log.statusLog(0, `Peer ${peerData.from} is stale. Skipping.`)
297
309
  continue
298
310
  }
299
311
 
@@ -331,10 +343,13 @@ class ThisNodeUseCases {
331
343
  // Try a direct connection with the peer by going through
332
344
  // the multiaddrs in the announcement object.
333
345
  const filteredMultiaddrs = this.utils.filterMultiaddrs(peerData.data.ipfsMultiaddrs)
334
- // console.log('filteredMultiaddrs: ', filteredMultiaddrs)
346
+ console.log('filteredMultiaddrs: ', filteredMultiaddrs)
335
347
 
336
348
  for (let j = 0; j < filteredMultiaddrs.length; j++) {
337
349
  const multiaddr = filteredMultiaddrs[j]
350
+ this.adapters.log.statusLog(0,
351
+ `Trying a direct connecto to peer ${thisPeer} with this multiaddr: ${multiaddr}.`
352
+ )
338
353
 
339
354
  // Attempt to connect to the node through a circuit relay.
340
355
  connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
@@ -356,7 +371,7 @@ class ThisNodeUseCases {
356
371
  // Break out of the loop once we've made a successful connection.
357
372
  break
358
373
  } else {
359
- this.adapters.log.statusLog(2,
374
+ this.adapters.log.statusLog(0,
360
375
  `Failed to connect to peer ${thisPeer} through direct connection: ${multiaddr}. Reason: ${connected.details}`
361
376
  )
362
377
  }
package/lib/util/utils.js CHANGED
@@ -11,6 +11,7 @@ class Util {
11
11
  // This function takes an array of multiaddrs as input, and returns an array
12
12
  // filtered to remove any local network IP addresses.
13
13
  filterMultiaddrs (multiaddrs) {
14
+ console.log('filterMultiaddrs() input: ', multiaddrs)
14
15
  try {
15
16
  const filteredMultiaddrs = multiaddrs.filter((x) => {
16
17
  if (x.includes('127.0.0.1')) return false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "helia-coord",
3
- "version": "1.2.19",
3
+ "version": "1.2.21",
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",
@@ -34,6 +34,7 @@
34
34
  "@chris.troutner/retry-queue": "1.0.8",
35
35
  "@multiformats/multiaddr": "12.1.8",
36
36
  "bch-encrypt-lib": "2.1.1",
37
+ "public-ip": "6.0.1",
37
38
  "uuid": "9.0.0"
38
39
  },
39
40
  "peerDependencies": {
@@ -80,6 +80,12 @@ describe('#relay-Use-Cases', () => {
80
80
  .stub(uut.adapters.ipfs, 'connectToPeer')
81
81
  .rejects(new Error('test error'))
82
82
 
83
+ uut.bootstrapCircuitRelays = {
84
+ node: [{
85
+ multiaddr: 'fake-multiaddr'
86
+ }]
87
+ }
88
+
83
89
  await uut.initializeRelays(thisNode)
84
90
 
85
91
  assert.fail('Unexpected code path')