Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from libp2p:master #38

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/discovery-mechanisms/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const createNode = async (bootstrappers) => {
const peer = evt.detail
console.log(`Peer ${node1.peerId.toString()} discovered: ${peer.id.toString()}`)
})
node2.addEventListener('peer:discovery',(evt) => {
node2.addEventListener('peer:discovery', (evt) => {
const peer = evt.detail
console.log(`Peer ${node2.peerId.toString()} discovered: ${peer.id.toString()}`)
})
Expand All @@ -77,4 +77,4 @@ const createNode = async (bootstrappers) => {
node1.start(),
node2.start()
])
})();
})()
2 changes: 1 addition & 1 deletion examples/discovery-mechanisms/test-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function test () {
})
})

await pWaitFor(() => discoveredNodes > 1)
await pWaitFor(() => discoveredNodes > 1, 600000)

proc.kill()
}
15 changes: 10 additions & 5 deletions examples/discovery-mechanisms/test-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

export async function test () {
let discoveredNodes = 0
const discoveredPeers = []

process.stdout.write('3.js\n')

Expand All @@ -19,15 +19,20 @@ export async function test () {
proc.all.on('data', async (data) => {
process.stdout.write(data)
const str = uint8ArrayToString(data)

const discoveredPeersRegex = /Peer\s+(?<Peer1>[^\s]+)\s+discovered:\s+(?<Peer2>[^\s]+)/
str.split('\n').forEach(line => {
if (line.includes('discovered:')) {
discoveredNodes++
const peers = line.match(discoveredPeersRegex)
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()
}
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"license": "MIT",
"dependencies": {
"@libp2p/pubsub-peer-discovery": "^6.0.1",
"@libp2p/pubsub-peer-discovery": "^6.0.2",
"@libp2p/floodsub": "^3.0.3",
"@nodeutils/defaults-deep": "^1.1.0",
"execa": "^6.1.0",
Expand Down