helia-coord 1.7.0 → 1.7.1
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.
|
@@ -213,22 +213,32 @@ class TimerControllers {
|
|
|
213
213
|
// Disable the timer interval while this function executes.
|
|
214
214
|
clearInterval(this.announceTimerHandle)
|
|
215
215
|
|
|
216
|
+
// Get multiaddrs that can be used to connect to this node.
|
|
217
|
+
const multiaddrs = useCases.peer.getMultiaddrs()
|
|
218
|
+
// console.log('manageAnnouncement(): multiaddrs: ', multiaddrs)
|
|
219
|
+
|
|
216
220
|
// Get the information needed for the announcement.
|
|
217
221
|
const announceObj = {
|
|
218
222
|
ipfsId: thisNode.ipfsId,
|
|
219
|
-
ipfsMultiaddrs: thisNode.ipfsMultiaddrs,
|
|
223
|
+
// ipfsMultiaddrs: thisNode.ipfsMultiaddrs,
|
|
224
|
+
ipfsMultiaddrs: multiaddrs,
|
|
220
225
|
type: thisNode.type,
|
|
221
226
|
// orbitdbId: thisNode.orbit.id,
|
|
222
227
|
|
|
223
228
|
// TODO: Allow node.js apps to pass a config setting to override this.
|
|
224
229
|
isCircuitRelay: false
|
|
225
230
|
}
|
|
231
|
+
// console.log('announceObj: ', announceObj)
|
|
226
232
|
|
|
227
233
|
// Generate the announcement message.
|
|
228
234
|
const announceMsgObj = thisNode.schema.announcement(announceObj)
|
|
229
235
|
// console.log(`announceMsgObj: ${JSON.stringify(announceMsgObj, null, 2)}`)
|
|
230
236
|
|
|
237
|
+
// Overwrite the default multiaddrs with the latest multiaddrs.
|
|
238
|
+
announceMsgObj.ipfsMultiaddrs = multiaddrs
|
|
239
|
+
|
|
231
240
|
const announceMsgStr = JSON.stringify(announceMsgObj)
|
|
241
|
+
console.log('announceMsgStr: ', announceMsgStr)
|
|
232
242
|
|
|
233
243
|
// Publish the announcement to the pubsub channel.
|
|
234
244
|
await this.adapters.pubsub.messaging.publishToPubsubChannel(
|
|
@@ -42,6 +42,8 @@ class PeerUseCases {
|
|
|
42
42
|
this.sendRPC = this.sendRPC.bind(this)
|
|
43
43
|
this.relayMetricsHandler = this.relayMetricsHandler.bind(this)
|
|
44
44
|
this.getWebRtcMultiaddr = this.getWebRtcMultiaddr.bind(this)
|
|
45
|
+
this.refreshPeerConnections = this.refreshPeerConnections.bind(this)
|
|
46
|
+
this.getMultiaddrs = this.getMultiaddrs.bind(this)
|
|
45
47
|
|
|
46
48
|
// Inject the relayMetricsHandler function into the pubsub adapter.
|
|
47
49
|
this.adapters.pubsub.injectMetricsHandler(this.relayMetricsHandler)
|
|
@@ -428,7 +430,7 @@ class PeerUseCases {
|
|
|
428
430
|
// Skip this section if the peer has a preference for direct connection.
|
|
429
431
|
if (connectPref !== 'direct') {
|
|
430
432
|
// Retrieve the webRTC multiaddrs from the peers announcement object.
|
|
431
|
-
const filteredMultiaddrs = peerData.data.ipfsMultiaddrs.filter(x => x.includes('/p2p-circuit/
|
|
433
|
+
const filteredMultiaddrs = peerData.data.ipfsMultiaddrs.filter(x => x.includes('/p2p-circuit/'))
|
|
432
434
|
this.adapters.log.statusLog(1, 'webRTC filteredMultiaddrs: ', filteredMultiaddrs)
|
|
433
435
|
|
|
434
436
|
// If the peer has no webRTC multiaddrs, then skip this peer
|
|
@@ -686,7 +688,7 @@ class PeerUseCases {
|
|
|
686
688
|
// Add them to the announcement object.
|
|
687
689
|
getWebRtcMultiaddr (inObj = {}) {
|
|
688
690
|
try {
|
|
689
|
-
console.log('---->Entering getWebRtcMultiaddr() Use Case.<----')
|
|
691
|
+
// console.log('---->Entering getWebRtcMultiaddr() Use Case.<----')
|
|
690
692
|
|
|
691
693
|
const { thisNode } = inObj
|
|
692
694
|
|
|
@@ -694,7 +696,7 @@ class PeerUseCases {
|
|
|
694
696
|
const addrs = this.adapters.ipfs.ipfs.libp2p.getMultiaddrs()
|
|
695
697
|
|
|
696
698
|
const webRtcAddrs = addrs.filter(x => WebRTC.matches(x))
|
|
697
|
-
console.log('webRTC addrs: ', webRtcAddrs)
|
|
699
|
+
// console.log('webRTC addrs: ', webRtcAddrs)
|
|
698
700
|
|
|
699
701
|
// If there are any webRTC multiaddrs, add them to the announcement object.
|
|
700
702
|
if (webRtcAddrs.length) {
|
|
@@ -709,7 +711,7 @@ class PeerUseCases {
|
|
|
709
711
|
|
|
710
712
|
// Add the new webRTC multiaddrs to the announcement object.
|
|
711
713
|
thisNode.ipfsMultiaddrs = noRtcAddrs
|
|
712
|
-
console.log(`Updated thisNode.ipfsMultiaddrs: ${JSON.stringify(thisNode.ipfsMultiaddrs, null, 2)}`)
|
|
714
|
+
// console.log(`Updated thisNode.ipfsMultiaddrs: ${JSON.stringify(thisNode.ipfsMultiaddrs, null, 2)}`)
|
|
713
715
|
}
|
|
714
716
|
|
|
715
717
|
// return webRtcAddrs
|
|
@@ -718,6 +720,39 @@ class PeerUseCases {
|
|
|
718
720
|
return false
|
|
719
721
|
}
|
|
720
722
|
}
|
|
723
|
+
|
|
724
|
+
// This function expects an array of multiaddrs. It removes any elements
|
|
725
|
+
// that contain /p2p-circuit/webrtc, retrieves any webRTC multiaddrs from
|
|
726
|
+
// the node, adds them to the array, and returns the updated array.
|
|
727
|
+
// This information is then used in the announcement object, to let other
|
|
728
|
+
// nodes know how to connect to this node using webRTC.
|
|
729
|
+
getMultiaddrs (inObj = {}) {
|
|
730
|
+
try {
|
|
731
|
+
// Get multiaddrs that can be used to connect to this node.
|
|
732
|
+
const addrs = this.adapters.ipfs.ipfs.libp2p.getMultiaddrs()
|
|
733
|
+
// console.log('addrs: ', addrs)
|
|
734
|
+
|
|
735
|
+
const addrStrs = addrs.map(x => x.toString())
|
|
736
|
+
// console.log('addrStrs: ', addrStrs)
|
|
737
|
+
|
|
738
|
+
// Filter out multiaddrs with a low chance of success
|
|
739
|
+
const filteredAddrs = addrStrs.filter(x => {
|
|
740
|
+
if (x.includes('127.0.0.1')) return false
|
|
741
|
+
if (x.includes('udp')) return false
|
|
742
|
+
if (x.includes('quic')) return false
|
|
743
|
+
if (x.includes('192.168.')) return false
|
|
744
|
+
if (x.includes('172.1') || x.includes('172.2') || x.includes('172.3')) return false
|
|
745
|
+
if (x.includes('/10.')) return false
|
|
746
|
+
return true
|
|
747
|
+
})
|
|
748
|
+
// console.log('filteredAddrs: ', filteredAddrs)
|
|
749
|
+
|
|
750
|
+
return filteredAddrs
|
|
751
|
+
} catch (err) {
|
|
752
|
+
console.error('Error in getMultiaddrs(): ', err)
|
|
753
|
+
return []
|
|
754
|
+
}
|
|
755
|
+
}
|
|
721
756
|
}
|
|
722
757
|
|
|
723
758
|
export default PeerUseCases
|
package/package.json
CHANGED