Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
refactor: async
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Switch to using async/await and async iterators.
  • Loading branch information
vasco-santos committed Oct 4, 2019
1 parent 8669709 commit 123c1ad
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 427 deletions.
78 changes: 35 additions & 43 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const pull = require('pull-stream')
const parallel = require('async/parallel')
const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous')

const Node = require('./test/utils/nodejs-bundle.js')
Expand All @@ -13,54 +12,47 @@ const {
let wsRendezvous
let node

const before = (done) => {
parallel([
(cb) => {
WebSocketStarRendezvous.start({
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port,
refreshPeerListIntervalMS: 1000,
strictMultiaddr: false,
cryptoChallenge: true
}, (err, _server) => {
if (err) {
return cb(err)
}
wsRendezvous = _server
cb()
})
},
(cb) => {
getPeerRelay((err, peerInfo) => {
if (err) {
return done(err)
}

node = new Node({
peerInfo,
config: {
relay: {
const before = async () => {
[wsRendezvous, node] = await Promise.all([
WebSocketStarRendezvous.start({
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port,
refreshPeerListIntervalMS: 1000,
strictMultiaddr: false,
cryptoChallenge: true
}),
new Promise(async (resolve, reject) => {
const peerInfo = await getPeerRelay()
const n = new Node({
peerInfo,
config: {
relay: {
enabled: true,
hop: {
enabled: true,
hop: {
enabled: true,
active: true
}
active: true
}
}
})

node.handle('/echo/1.0.0', (_, conn) => pull(conn, conn))
node.start(cb)
}
})
}
], done)

n.handle('/echo/1.0.0', (_, conn) => pull(conn, conn))
await n.start()

resolve(n)
})
])
}

const after = (done) => {
setTimeout(() =>
parallel(
[node, wsRendezvous].map((s) => (cb) => s.stop(cb)),
done),
2000)
const after = () => {
return new Promise((resolve) => {
setTimeout(async () => {
await Promise.all([
node.stop(),
wsRendezvous.stop()
])
resolve()
}, 2000)
})
}

module.exports = {
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ class PubsubImplementation extends Pubsub {

Validates the signature of a message.

#### `pubsub.validate(message, callback)`
#### `pubsub.validate(message)`

##### Parameters

| Name | Type | Description |
|------|------|-------------|
| message | `Message` | a pubsub message |
| callback | `function(Error, Boolean)` | calls back with true if the message is valid |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<Boolean>` | resolves to true if the message is valid |

## Implementations using this base protocol

Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,34 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-pubsub#readme",
"devDependencies": {
"aegir": "^18.2.1",
"aegir": "^20.3.1",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"dirty-chai": "^2.0.1",
"libp2p": "~0.24.4",
"libp2p": "~0.26.2",
"libp2p-secio": "~0.11.1",
"libp2p-spdy": "~0.13.3",
"libp2p-tcp": "~0.13.0",
"libp2p-tcp": "~0.13.1",
"libp2p-websocket-star": "~0.10.2",
"libp2p-websocket-star-rendezvous": "~0.3.0",
"lodash": "^4.17.11",
"multiaddr": "^6.0.6",
"peer-id": "~0.12.5",
"libp2p-websocket-star-rendezvous": "~0.4.1",
"lodash": "^4.17.15",
"multiaddr": "^6.1.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1"
},
"dependencies": {
"async": "^2.6.2",
"bs58": "^4.0.1",
"debug": "^4.1.1",
"err-code": "^1.1.2",
"err-code": "^2.0.0",
"length-prefixed-stream": "^2.0.0",
"libp2p-crypto": "~0.16.1",
"libp2p-crypto": "~0.17.0",
"protons": "^1.0.1",
"pull-length-prefixed": "^1.3.1",
"pull-length-prefixed": "^1.3.3",
"pull-pushable": "^2.2.0",
"pull-stream": "^3.6.9",
"sinon": "^7.3.2",
"pull-stream": "^3.6.14",
"sinon": "^7.5.0",
"time-cache": "~0.3.0"
},
"contributors": [
Expand Down
Loading

0 comments on commit 123c1ad

Please sign in to comment.