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.
- package/config/global-config.js +1 -1
- package/lib/adapters/gist.js +9 -1
- package/lib/controllers/timer-controller.js +1 -1
- package/lib/use-cases/relay-use-cases.js +5 -4
- package/lib/use-cases/this-node-use-cases.js +68 -65
- package/package.json +1 -1
- package/test/unit/adapters/gist.unit.adapters.js +18 -18
package/config/global-config.js
CHANGED
package/lib/adapters/gist.js
CHANGED
|
@@ -31,7 +31,15 @@ class Gist {
|
|
|
31
31
|
const object = JSON.parse(content)
|
|
32
32
|
// console.log('object: ', object)
|
|
33
33
|
|
|
34
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
246
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
} else {
|
|
327
|
-
|
|
328
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 {
|