helia-coord 1.1.4 → 1.2.0
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,6 +23,12 @@ class IpfsAdapter {
|
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Bind 'this' object to all subfunctions
|
|
27
|
+
this.start = this.start.bind(this)
|
|
28
|
+
this.connectToPeer = this.connectToPeer.bind(this)
|
|
29
|
+
this.disconnectFromPeer = this.disconnectFromPeer.bind(this)
|
|
30
|
+
this.getPeers = this.getPeers.bind(this)
|
|
31
|
+
|
|
26
32
|
// 'embedded' node type used as default, will use embedded js-ipfs.
|
|
27
33
|
// Alternative is 'external' which will use ipfs-http-client to control an
|
|
28
34
|
// external IPFS node.
|
|
@@ -69,23 +75,34 @@ class IpfsAdapter {
|
|
|
69
75
|
|
|
70
76
|
// Attempts to connect to an IPFS peer, given its IPFS multiaddr.
|
|
71
77
|
// Returns true if the connection succeeded. Otherwise returns false.
|
|
72
|
-
async connectToPeer (
|
|
78
|
+
async connectToPeer (inObj = {}) {
|
|
73
79
|
try {
|
|
80
|
+
// console.log('connectToPeer() inObj: ', inObj)
|
|
81
|
+
|
|
74
82
|
// TODO: Throw error if ipfs ID is passed, instead of a multiaddr.
|
|
75
83
|
// console.log('ipfsAddr: ', ipfsAddr)
|
|
76
84
|
|
|
85
|
+
const { multiaddr } = inObj
|
|
86
|
+
|
|
77
87
|
// await this.ipfs.swarm.connect(ipfsAddr, { timeout: CONNECTION_TIMEOUT })
|
|
78
|
-
await this.ipfs.libp2p.dial(this.multiaddr(
|
|
88
|
+
await this.ipfs.libp2p.dial(this.multiaddr(multiaddr))
|
|
89
|
+
// console.log('connectToPeer() result: ', result)
|
|
79
90
|
|
|
80
|
-
this.log.statusLog(1, `Successfully connected to peer node ${
|
|
91
|
+
this.log.statusLog(1, `Successfully connected to peer node ${multiaddr}`)
|
|
81
92
|
|
|
82
|
-
return
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
details: null
|
|
96
|
+
}
|
|
83
97
|
} catch (err) {
|
|
84
98
|
/* exit quietly */
|
|
99
|
+
// console.log('connectToPeer() Error connecting to peer: ', err)
|
|
100
|
+
this.log.statusLog(2, 'Error trying to connect to peer node : ', err.message)
|
|
85
101
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
details: err.message
|
|
105
|
+
}
|
|
89
106
|
}
|
|
90
107
|
}
|
|
91
108
|
|
|
@@ -37,7 +37,7 @@ class RelayUseCases {
|
|
|
37
37
|
|
|
38
38
|
// Attempt to connect to the Circuit Relay peer.
|
|
39
39
|
const connectionStatus = await this.adapters.ipfs.connectToPeer(
|
|
40
|
-
thisRelay.multiaddr
|
|
40
|
+
{ multiaddr: thisRelay.multiaddr }
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
const now = new Date()
|
|
@@ -92,7 +92,7 @@ class RelayUseCases {
|
|
|
92
92
|
// console.log(`getCRGist() Connecting to Circuit Relay ${thisRelay.multiaddr}`)
|
|
93
93
|
this.adapters.log.statusLog(1, `getCRGist() Connecting to Circuit Relay ${thisRelay.multiaddr}`)
|
|
94
94
|
const connectionStatus = await this.adapters.ipfs.connectToPeer(
|
|
95
|
-
thisRelay.multiaddr
|
|
95
|
+
{ multiaddr: thisRelay.multiaddr }
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
const now = new Date()
|
|
@@ -156,7 +156,7 @@ class RelayUseCases {
|
|
|
156
156
|
// If this node is not connected, try to connect again.
|
|
157
157
|
console.log(`Connecting to Circuit Relay ${thisRelay.multiaddr}`)
|
|
158
158
|
thisRelay.connected = await this.adapters.ipfs.connectToPeer(
|
|
159
|
-
thisRelay.multiaddr
|
|
159
|
+
{ multiaddr: thisRelay.multiaddr }
|
|
160
160
|
)
|
|
161
161
|
console.log(`thisRelay.connected: ${thisRelay.connected}`)
|
|
162
162
|
|
|
@@ -309,7 +309,7 @@ class RelayUseCases {
|
|
|
309
309
|
// console.log('thisAddr: ', thisAddr)
|
|
310
310
|
|
|
311
311
|
// Try to connect to the IPFS peer.
|
|
312
|
-
connectSuccess = await this.adapters.ipfs.connectToPeer(thisAddr)
|
|
312
|
+
connectSuccess = await this.adapters.ipfs.connectToPeer({ multiaddr: thisAddr })
|
|
313
313
|
|
|
314
314
|
if (connectSuccess) {
|
|
315
315
|
multiaddr = thisAddr
|
|
@@ -289,7 +289,7 @@ class ThisNodeUseCases {
|
|
|
289
289
|
this.adapters.log.statusLog(2, `refreshPeerConnections() connecting to peer with this multiaddr: ${multiaddr}`)
|
|
290
290
|
|
|
291
291
|
// Attempt to connect to the node through a circuit relay.
|
|
292
|
-
const connected = await this.adapters.ipfs.connectToPeer(multiaddr)
|
|
292
|
+
const connected = await this.adapters.ipfs.connectToPeer({ multiaddr })
|
|
293
293
|
|
|
294
294
|
// If the connection was successful, break out of the relay loop.
|
|
295
295
|
// Otherwise try to connect through the next relay.
|
package/package.json
CHANGED
|
@@ -104,18 +104,18 @@ describe('#Adapter - IPFS', () => {
|
|
|
104
104
|
sandbox.stub(uut.ipfs.libp2p, 'dial').resolves()
|
|
105
105
|
sandbox.stub(uut, 'multiaddr').returns()
|
|
106
106
|
|
|
107
|
-
const result = await uut.connectToPeer('fakeId')
|
|
107
|
+
const result = await uut.connectToPeer({ multiaddr: 'fakeId' })
|
|
108
108
|
|
|
109
|
-
assert.equal(result, true)
|
|
109
|
+
assert.equal(result.success, true)
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
it('should return false when issues connecting to peer', async () => {
|
|
113
113
|
// Force an error
|
|
114
114
|
sandbox.stub(uut.ipfs.swarm, 'connect').rejects(new Error('test error'))
|
|
115
115
|
|
|
116
|
-
const result = await uut.connectToPeer('fakeId')
|
|
116
|
+
const result = await uut.connectToPeer({ multiaddr: 'fakeId' })
|
|
117
117
|
|
|
118
|
-
assert.equal(result, false)
|
|
118
|
+
assert.equal(result.success, false)
|
|
119
119
|
})
|
|
120
120
|
|
|
121
121
|
it('should report connection errors at debugLevel 1', async () => {
|
|
@@ -124,9 +124,9 @@ describe('#Adapter - IPFS', () => {
|
|
|
124
124
|
// Force an error
|
|
125
125
|
sandbox.stub(uut.ipfs.swarm, 'connect').rejects(new Error('test error'))
|
|
126
126
|
|
|
127
|
-
const result = await uut.connectToPeer('fakeId')
|
|
127
|
+
const result = await uut.connectToPeer({ multiaddr: 'fakeId' })
|
|
128
128
|
|
|
129
|
-
assert.equal(result, false)
|
|
129
|
+
assert.equal(result.success, false)
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
it('should report full errors at debugLevel 2', async () => {
|
|
@@ -135,9 +135,9 @@ describe('#Adapter - IPFS', () => {
|
|
|
135
135
|
// Force an error
|
|
136
136
|
sandbox.stub(uut.ipfs.swarm, 'connect').rejects(new Error('test error'))
|
|
137
137
|
|
|
138
|
-
const result = await uut.connectToPeer('fakeId')
|
|
138
|
+
const result = await uut.connectToPeer({ multiaddr: 'fakeId' })
|
|
139
139
|
|
|
140
|
-
assert.equal(result, false)
|
|
140
|
+
assert.equal(result.success, false)
|
|
141
141
|
})
|
|
142
142
|
})
|
|
143
143
|
|