Skip to content

Commit

Permalink
chore: update peer-id (#173)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: requires node 15+
  • Loading branch information
achingbrain committed Dec 2, 2021
1 parent 6d7b2aa commit e61668e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm install
- run: npm run lint
- run: npm run prebuild
Expand All @@ -22,11 +25,11 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [14]
node: [16]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install
Expand All @@ -38,6 +41,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm install
- run: npm run prebuild
- run: npx aegir test -t browser -t webworker --bail
Expand All @@ -46,6 +52,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm install
- run: npm run prebuild
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"denque": "^1.5.0",
"err-code": "^3.0.1",
"it-pipe": "^1.1.0",
"libp2p-interfaces": "^1.1.0",
"peer-id": "^0.15.3",
"libp2p-interfaces": "^2.0.1",
"peer-id": "^0.16.0",
"protobufjs": "^6.11.2",
"time-cache": "^0.3.0",
"uint8arrays": "^3.0.0"
Expand All @@ -56,7 +56,7 @@
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"aegir": "^35.0.1",
"aegir": "^36.0.2",
"benchmark": "^2.1.4",
"buffer": "^6.0.3",
"chai": "^4.2.0",
Expand All @@ -71,9 +71,9 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"it-pair": "^1.0.0",
"libp2p": "^0.32.0",
"libp2p-floodsub": "^0.27.0",
"libp2p-interfaces-compliance-tests": "^1.0.1",
"libp2p": "^0.35.0",
"libp2p-floodsub": "^0.28.0",
"libp2p-interfaces-compliance-tests": "^2.0.3",
"libp2p-mplex": "^0.10.3",
"libp2p-websockets": "^0.16.1",
"lodash": "^4.17.15",
Expand Down
9 changes: 7 additions & 2 deletions test/2-nodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,14 @@ describe('2 nodes', () => {
})

it('Publish to a topic after unsubscribe', async () => {
const promises = [
new Promise((resolve) => nodes[1].once('pubsub:subscription-change', resolve)),
new Promise((resolve) => nodes[1].once('gossipsub:heartbeat', resolve))
]

nodes[0].unsubscribe(topic)
await new Promise((resolve) => nodes[1].once('pubsub:subscription-change', resolve))
await new Promise((resolve) => nodes[1].once('gossipsub:heartbeat', resolve))

await Promise.all(promises)

const promise = new Promise((resolve, reject) => {
nodes[0].once(topic, reject)
Expand Down
10 changes: 6 additions & 4 deletions test/gossip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
first,
createGossipsubs,
connectGossipsubs,
stopNode
stopNode,
waitForAllNodesToBePeered
} = require('./utils')

describe('gossip', () => {
Expand All @@ -31,9 +32,9 @@ describe('gossip', () => {
// add subscriptions to each node
nodes.forEach((n) => n.subscribe(topic))

// every node connected to every other
await connectGossipsubs(nodes)
// await subscription propagation
await delay(50)
await waitForAllNodesToBePeered(nodes)

// await mesh rebalancing
await Promise.all(nodes.map((n) => new Promise((resolve) => n.once('gossipsub:heartbeat', resolve))))
Expand Down Expand Up @@ -67,7 +68,8 @@ describe('gossip', () => {

// every node connected to every other
await connectGossipsubs(nodes)
await delay(500)
await waitForAllNodesToBePeered(nodes)

// await mesh rebalancing
await Promise.all(nodes.map((n) => new Promise((resolve) => n.once('gossipsub:heartbeat', resolve))))
await delay(500)
Expand Down
20 changes: 20 additions & 0 deletions test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { expect } = require('chai')

const FloodSub = require('libp2p-floodsub')
const PeerId = require('peer-id')
const delay = require('delay')

exports.first = (map) => map.values().next().value

Expand Down Expand Up @@ -52,3 +53,22 @@ exports.getMsgId = (msg) => {
result.set(seqno, from.length)
return result
}

exports.waitForAllNodesToBePeered = async (peers, attempts = 10, delayMs = 100) => {
const nodeIds = peers.map(peer => peer.peerId.toB58String())

for (let i = 0; i < attempts; i++) {
for (const node of peers) {
const nodeId = node.peerId.toB58String()
const others = nodeIds.filter(peerId => peerId !== nodeId)

const missing = others.some(other => !node.peers.has(other))

if (!missing) {
return
}
}

await delay(delayMs)
}
}

0 comments on commit e61668e

Please sign in to comment.