mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-04 06:52:14 +00:00
fix: discovery mechanism examples not working (#1365)
Co-authored-by: achingbrain <alex@achingbrain.net>- fixed tests that were passing even though the example isn't working - added timeouts to avoid infinite wait Fixes #1229
This commit is contained in:
parent
fc2224a1e8
commit
d281a60dac
@ -67,7 +67,7 @@ const createNode = async (bootstrappers) => {
|
|||||||
const peer = evt.detail
|
const peer = evt.detail
|
||||||
console.log(`Peer ${node1.peerId.toString()} discovered: ${peer.id.toString()}`)
|
console.log(`Peer ${node1.peerId.toString()} discovered: ${peer.id.toString()}`)
|
||||||
})
|
})
|
||||||
node2.addEventListener('peer:discovery',(evt) => {
|
node2.addEventListener('peer:discovery', (evt) => {
|
||||||
const peer = evt.detail
|
const peer = evt.detail
|
||||||
console.log(`Peer ${node2.peerId.toString()} discovered: ${peer.id.toString()}`)
|
console.log(`Peer ${node2.peerId.toString()} discovered: ${peer.id.toString()}`)
|
||||||
})
|
})
|
||||||
@ -77,4 +77,4 @@ const createNode = async (bootstrappers) => {
|
|||||||
node1.start(),
|
node1.start(),
|
||||||
node2.start()
|
node2.start()
|
||||||
])
|
])
|
||||||
})();
|
})()
|
||||||
|
@ -27,7 +27,7 @@ export async function test () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
await pWaitFor(() => discoveredNodes > 1)
|
await pWaitFor(() => discoveredNodes > 1, 600000)
|
||||||
|
|
||||||
proc.kill()
|
proc.kill()
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { fileURLToPath } from 'url'
|
|||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
export async function test () {
|
export async function test () {
|
||||||
let discoveredNodes = 0
|
const discoveredPeers = []
|
||||||
|
|
||||||
process.stdout.write('3.js\n')
|
process.stdout.write('3.js\n')
|
||||||
|
|
||||||
@ -19,15 +19,20 @@ export async function test () {
|
|||||||
proc.all.on('data', async (data) => {
|
proc.all.on('data', async (data) => {
|
||||||
process.stdout.write(data)
|
process.stdout.write(data)
|
||||||
const str = uint8ArrayToString(data)
|
const str = uint8ArrayToString(data)
|
||||||
|
const discoveredPeersRegex = /Peer\s+(?<Peer1>[^\s]+)\s+discovered:\s+(?<Peer2>[^\s]+)/
|
||||||
str.split('\n').forEach(line => {
|
str.split('\n').forEach(line => {
|
||||||
if (line.includes('discovered:')) {
|
const peers = line.match(discoveredPeersRegex)
|
||||||
discoveredNodes++
|
if (peers != null) {
|
||||||
|
// sort so we don't count reversed pair twice
|
||||||
|
const match = [peers.groups.Peer1, peers.groups.Peer2].sort().join(',')
|
||||||
|
if (!discoveredPeers.includes(match)) {
|
||||||
|
discoveredPeers.push(match)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
await pWaitFor(() => discoveredNodes > 3)
|
await pWaitFor(() => discoveredPeers.length > 2, 600000)
|
||||||
|
|
||||||
proc.kill()
|
proc.kill()
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@libp2p/pubsub-peer-discovery": "^6.0.1",
|
"@libp2p/pubsub-peer-discovery": "^6.0.2",
|
||||||
"@libp2p/floodsub": "^3.0.3",
|
"@libp2p/floodsub": "^3.0.3",
|
||||||
"@nodeutils/defaults-deep": "^1.1.0",
|
"@nodeutils/defaults-deep": "^1.1.0",
|
||||||
"execa": "^6.1.0",
|
"execa": "^6.1.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user