Compare commits

...

12 Commits

Author SHA1 Message Date
Jacob Heun
8c4dbe2766 docs: apply suggestions from code review
Co-Authored-By: dirkmc <dirkmdev@gmail.com>
2019-06-25 14:52:53 +02:00
Jacob Heun
27af24ffc1 docs: update delegate example to include ipfs setup instructions
docs: add the ability to add content via delegate routing
2019-06-25 10:23:07 +02:00
Jacob Heun
10811e9ced chore: update keywords and description (#370)
* chore: update keywords and description

chore: reorganize package.json fields

* test: bump timeouts for peer generation
2019-06-12 14:18:34 +02:00
Jacob Heun
9c2789bc15 chore: release version v0.25.4 2019-06-07 17:10:07 +02:00
Jacob Heun
24be691bc1 chore: update contributors 2019-06-07 17:10:07 +02:00
Jacob Heun
9433c6c398 docs: add createLibp2p to readme (#368)
* chore: update deps
* test(fix): account for wrtcrendezvous now being thenable
2019-06-07 15:50:23 +02:00
Jacob Heun
04faf1806c feat: add createLibp2p to generate a PeerInfo instance (#367)
createLibp2p is a new exported helper function that allows users to create a libp2p instance without worrying about creating a PeerInfo instance first.
2019-06-06 12:21:31 +02:00
Guy Sviry
b06ca1b3c7 feat: pass libp2p as option to transport creation (#363) 2019-05-17 12:11:22 +02:00
Jacob Heun
bde30cac45 chore: remove commitlint from travis
Commit messages should be fixed on PR squash and merge
2019-05-17 10:31:16 +02:00
Jacob Heun
28c054c21e chore: release version v0.25.3 2019-05-07 13:49:03 +02:00
Jacob Heun
c346e8066b chore: update contributors 2019-05-07 13:49:02 +02:00
Jacob Heun
40978a1940 feat: sign pubsub messages (#362)
* fix: forward pubsub publish callback to floodsub

chore: update floodsub version

* test: add random walk delay to config

* chore: update floodsub
2019-05-07 13:45:59 +02:00
14 changed files with 239 additions and 112 deletions

View File

@@ -22,13 +22,12 @@ const before = (done) => {
sigServer.start({
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
}, (err, server) => {
if (err) {
return cb(err)
}
})
.then(server => {
wrtcRendezvous = server
cb()
})
.catch(cb)
},
(cb) => {
WebSocketStarRendezvous.start({
@@ -72,14 +71,16 @@ const before = (done) => {
const after = (done) => {
setTimeout(() =>
parallel(
[node, wrtcRendezvous, wsRendezvous].map((s) => (cb) => s.stop(cb)),
done),
2000)
parallel([
(cb) => wrtcRendezvous.stop().then(cb).catch(cb),
...[node, wsRendezvous].map((s) => (cb) => s.stop(cb)),
], done),
2000
)
}
module.exports = {
bundlesize: { maxSize: '218kB' },
bundlesize: { maxSize: '220kB' },
hooks: {
pre: before,
post: after

View File

@@ -7,11 +7,12 @@ stages:
node_js:
- '10'
- '12'
os:
- linux
- osx
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
@@ -20,7 +21,6 @@ jobs:
- stage: check
script:
- npx aegir build --bundlesize
- npx aegir commitlint --travis
- npx aegir dep-check -- -i wrtc -i electron-webrtc
- npm run lint

View File

@@ -1,3 +1,24 @@
<a name="0.25.4"></a>
## [0.25.4](https://github.com/libp2p/js-libp2p/compare/v0.25.3...v0.25.4) (2019-06-07)
### Features
* add createLibp2p to generate a PeerInfo instance ([#367](https://github.com/libp2p/js-libp2p/issues/367)) ([04faf18](https://github.com/libp2p/js-libp2p/commit/04faf18))
* pass libp2p as option to transport creation ([#363](https://github.com/libp2p/js-libp2p/issues/363)) ([b06ca1b](https://github.com/libp2p/js-libp2p/commit/b06ca1b))
<a name="0.25.3"></a>
## [0.25.3](https://github.com/libp2p/js-libp2p/compare/v0.25.2...v0.25.3) (2019-05-07)
### Features
* sign pubsub messages ([#362](https://github.com/libp2p/js-libp2p/issues/362)) ([40978a1](https://github.com/libp2p/js-libp2p/commit/40978a1))
<a name="0.25.2"></a>
## [0.25.2](https://github.com/libp2p/js-libp2p/compare/v0.25.1...v0.25.2) (2019-04-17)

View File

@@ -111,7 +111,7 @@ The libp2p module acts as a glue for every libp2p module that you can use to cre
// crypto-channel: secio
// discovery: multicast-dns
const libp2p = require('libp2p')
const Libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets')
const SPDY = require('libp2p-spdy')
@@ -124,7 +124,7 @@ const Protector = require('libp2p-pnet')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
class Node extends libp2p {
class Node extends Libp2p {
constructor (_options) {
const peerInfo = _options.peerInfo
const defaults = {
@@ -204,13 +204,31 @@ class Node extends libp2p {
### API
#### Create a Node - `new libp2p.Node(options)`
#### Create a Node - `Libp2p.createLibp2p(options, callback)`
> Creates an instance of the libp2p.Node.
> Behaves exactly like `new Libp2p(options)`, but doesn't require a PeerInfo. One will be generated instead
```js
const { createLibp2p } = require('libp2p')
createLibp2p(options, (err, libp2p) => {
if (err) throw err
libp2p.start((err) => {
if (err) throw err
})
})
```
- `options`: Object of libp2p configuration options
- `callback`: Function with signature `function (Error, Libp2p) {}`
#### Create a Node alternative - `new Libp2p(options)`
> Creates an instance of Libp2p with a custom `PeerInfo` provided via `options.peerInfo`.
Required keys in the `options` object:
- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node.
- `modules.transport`: An array that must include at least 1 transport, such as `libp2p-tcp`.
#### `libp2p.start(callback)`

View File

@@ -10,18 +10,17 @@ The starting [Libp2p Bundle](./src/libp2p-bundle.js) in this example starts by d
Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the
various Peer Discovery modules and see the impact it has on your Peer count.
## Prerequisite
**NOTE**: This example is currently dependent on a clone of the [delegated routing support branch of go-ipfs](https://github.com/ipfs/go-ipfs/pull/4595).
## Running this example
1. Install IPFS locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/)
2. Run the IPFS daemon: `ipfs daemon`
3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`
4. In another window output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws/` in the address.
5. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them.
6. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 4.
7. Start this example:
1. Install go-ipfs locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/).
1. Run the IPFS daemon: `ipfs daemon`.
1. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`.
1. In another window, while the daemon is running, Configure the IPFS Gateway to support delegate routing `ipfs config Gateway.APICommands --json '["dht/findprovs", "dht/findpeer", "refs", "swarm/connect"]'`.
1. In the same window, output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws` in the address, like `/ip4/127.0.0.1/tcp/8081/ws`.
1. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them.
1. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 3. **Also**, in `./src/App.js` set BootstrapNodeID to your nodes id, which is displayed when running `ipfs id` in the `ID` property.
1. Start this example:
```sh
npm install
@@ -47,3 +46,12 @@ This will do a few things:
2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`.
3. In your browser, paste the CID into the *Peer* field and hit `Find`.
4. You should see information about the peer including its addresses.
### Adding Content via the Delegate
1. In one browser, such as Firefox, enter some text in the `Add Data` field and click `Add`.
2. Once added, JSON will be printed in the browser. Copy the value of `"hash"`.
3. Close your Firefox tab. Open a new browser window in a **different** browser, such as Chrome.
4. In the new window, copy the hash from step 2 into the `Hash` field and click `Find`.
5. The text you entered in step 1 should display.
**Note**: By closing the first window before fetching the content, you are ensuring that data cannot be retrieved from it, and instead the delegate must be relied on.

View File

@@ -3,16 +3,16 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"ipfs": "~0.34.4",
"ipfs": "~0.36.1",
"libp2p": "github:libp2p/js-libp2p#master",
"libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-kad-dht": "~0.14.12",
"libp2p-mplex": "~0.8.5",
"libp2p-kad-dht": "~0.15.0",
"libp2p-secio": "~0.11.1",
"libp2p-webrtc-star": "~0.15.8",
"libp2p-webrtc-star": "~0.16.1",
"libp2p-websocket-star": "~0.10.2",
"libp2p-websockets": "~0.12.2",
"pull-mplex": "~0.1.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "2.1.8"

View File

@@ -6,7 +6,10 @@ import Ipfs from 'ipfs'
import libp2pBundle from './libp2p-bundle'
const Component = React.Component
const BootstrapNode = '/ip4/127.0.0.1/tcp/8081/ws/p2p/QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8'
/* TODO: Add your go IPFS nodes ID here by running `ipfs id` */
const BootstrapNodeID = 'Qm...'
/* TODO: Ensure the IP and port match your nodes Websocket address shown when running the daemon `ipfs daemon` */
const BootstrapNode = `/ip4/127.0.0.1/tcp/8081/ws/p2p/${BootstrapNodeID}`
class App extends Component {
constructor (props) {
@@ -17,6 +20,7 @@ class App extends Component {
hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB',
// This peer is one of the Bootstrap nodes for IPFS
peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc',
data: '',
isLoading: 0
}
this.peerInterval = null
@@ -25,6 +29,8 @@ class App extends Component {
this.handleHashSubmit = this.handleHashSubmit.bind(this)
this.handlePeerChange = this.handlePeerChange.bind(this)
this.handlePeerSubmit = this.handlePeerSubmit.bind(this)
this.handleDataChange = this.handleDataChange.bind(this)
this.handleDataSubmit = this.handleDataSubmit.bind(this)
}
handleHashChange (event) {
@@ -37,6 +43,11 @@ class App extends Component {
peer: event.target.value
})
}
handleDataChange (event) {
this.setState({
data: event.target.value
})
}
handleHashSubmit (event) {
event.preventDefault()
@@ -44,7 +55,7 @@ class App extends Component {
isLoading: this.state.isLoading + 1
})
this.ipfs.files.cat(this.state.hash, (err, data) => {
this.ipfs.cat(this.state.hash, (err, data) => {
if (err) console.log('Error', err)
this.setState({
@@ -59,7 +70,22 @@ class App extends Component {
isLoading: this.state.isLoading + 1
})
this.ipfs.dht.findpeer(this.state.peer, (err, results) => {
this.ipfs.dht.findPeer(this.state.peer, (err, results) => {
if (err) console.log('Error', err)
this.setState({
response: JSON.stringify(results, null, 2),
isLoading: this.state.isLoading - 1
})
})
}
handleDataSubmit (event) {
event.preventDefault()
this.setState({
isLoading: this.state.isLoading + 1
})
this.ipfs.add(Buffer.from(this.state.data), (err, results) => {
if (err) console.log('Error', err)
this.setState({
@@ -135,6 +161,13 @@ class App extends Component {
<input type="submit" value="Find" />
</label>
</form>
<form onSubmit={this.handleDataSubmit}>
<label>
Add Data:
<input type="text" value={this.state.data} onChange={this.handleDataChange} />
<input type="submit" value="Add" />
</label>
</form>
</section>
<section className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}>
<div className="lds-ripple"><div></div><div></div></div>

View File

@@ -5,7 +5,7 @@ const Libp2p = require('libp2p')
const Websockets = require('libp2p-websockets')
const WebSocketStar = require('libp2p-websocket-star')
const WebRTCStar = require('libp2p-webrtc-star')
const MPLEX = require('libp2p-mplex')
const MPLEX = require('pull-mplex')
const SECIO = require('libp2p-secio')
const KadDHT = require('libp2p-kad-dht')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
@@ -14,8 +14,9 @@ const DelegatedContentRouter = require('libp2p-delegated-content-routing')
export default function Libp2pBundle ({peerInfo, peerBook}) {
const wrtcstar = new WebRTCStar({id: peerInfo.id})
const wsstar = new WebSocketStar({id: peerInfo.id})
/* TODO: Ensure the delegatedApiOptions match your IPFS nodes API server */
const delegatedApiOptions = {
host: '0.0.0.0',
host: '127.0.0.1',
protocol: 'http',
port: '8080'
}
@@ -25,7 +26,8 @@ export default function Libp2pBundle ({peerInfo, peerBook}) {
peerBook,
// Lets limit the connection managers peers and have it check peer health less frequently
connectionManager: {
maxPeers: 10,
minPeers: 20,
maxPeers: 50,
pollInterval: 5000
},
modules: {

View File

@@ -1,7 +1,7 @@
{
"name": "libp2p",
"version": "0.25.2",
"description": "JavaScript base class for libp2p bundles",
"version": "0.25.4",
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
"files": [
@@ -23,68 +23,73 @@
"url": "https://github.com/libp2p/js-libp2p.git"
},
"keywords": [
"libp2p",
"network",
"p2p",
"peer",
"peer-to-peer",
"IPFS"
],
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p",
"homepage": "https://libp2p.io",
"license": "MIT",
"browser": {
"./test/utils/bundle-nodejs": "./test/utils/bundle-browser"
},
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
"dependencies": {
"async": "^2.6.2",
"debug": "^4.1.1",
"err-code": "^1.1.2",
"fsm-event": "^2.1.0",
"libp2p-connection-manager": "~0.1.0",
"libp2p-floodsub": "~0.15.8",
"libp2p-ping": "~0.8.5",
"libp2p-switch": "~0.42.9",
"libp2p-websockets": "~0.12.2",
"libp2p-connection-manager": "^0.1.0",
"libp2p-floodsub": "^0.16.1",
"libp2p-ping": "^0.8.5",
"libp2p-switch": "^0.42.12",
"libp2p-websockets": "^0.12.2",
"mafmt": "^6.0.7",
"multiaddr": "^6.0.6",
"multiaddr": "^6.1.0",
"once": "^1.4.0",
"peer-book": "~0.9.1",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"superstruct": "~0.6.0"
"peer-book": "^0.9.1",
"peer-id": "^0.12.2",
"peer-info": "^0.15.1",
"superstruct": "^0.6.0"
},
"devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"aegir": "^18.2.1",
"aegir": "^19.0.3",
"chai": "^4.2.0",
"chai-checkmark": "^1.0.1",
"cids": "~0.5.8",
"cids": "^0.7.1",
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"interface-datastore": "~0.6.0",
"libp2p-bootstrap": "~0.9.7",
"libp2p-circuit": "~0.3.6",
"libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-kad-dht": "~0.14.8",
"libp2p-mdns": "~0.12.2",
"libp2p-mplex": "~0.8.4",
"libp2p-secio": "~0.11.1",
"libp2p-spdy": "~0.13.2",
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.8",
"electron-webrtc": "^0.3.0",
"interface-datastore": "^0.6.0",
"libp2p-bootstrap": "^0.9.7",
"libp2p-circuit": "^0.3.7",
"libp2p-delegated-content-routing": "^0.2.2",
"libp2p-delegated-peer-routing": "^0.2.2",
"libp2p-kad-dht": "^0.15.2",
"libp2p-mdns": "^0.12.3",
"libp2p-mplex": "^0.8.4",
"libp2p-secio": "^0.11.1",
"libp2p-spdy": "^0.13.2",
"libp2p-tcp": "^0.13.0",
"libp2p-webrtc-star": "^0.16.1",
"libp2p-websocket-star": "~0.10.2",
"libp2p-websocket-star-rendezvous": "~0.3.0",
"lodash.times": "^4.3.2",
"nock": "^10.0.6",
"pull-goodbye": "0.0.2",
"pull-mplex": "~0.1.2",
"pull-serializer": "~0.3.2",
"pull-stream": "^3.6.9",
"pull-mplex": "^0.1.2",
"pull-serializer": "^0.3.2",
"pull-stream": "^3.6.12",
"sinon": "^7.2.7",
"wrtc": "~0.3.5"
"wrtc": "^0.4.1"
},
"contributors": [
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
@@ -101,6 +106,7 @@
"Florian-Merle <florian.david.merle@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Giovanni T. Parra <fiatjaf@gmail.com>",
"Guy Sviry <32539816+guysv@users.noreply.github.com>",
"Henrique Dias <hacdias@gmail.com>",
"Hugo Dias <mail@hugodias.me>",
"Hugo Dias <hugomrdias@gmail.com>",

View File

@@ -10,8 +10,10 @@ const errCode = require('err-code')
const each = require('async/each')
const series = require('async/series')
const parallel = require('async/parallel')
const nextTick = require('async/nextTick')
const PeerBook = require('peer-book')
const PeerInfo = require('peer-info')
const Switch = require('libp2p-switch')
const Ping = require('libp2p-ping')
const WebSockets = require('libp2p-websockets')
@@ -34,14 +36,14 @@ const notStarted = (action, state) => {
}
/**
* @fires Node#error Emitted when an error occurs
* @fires Node#peer:connect Emitted when a peer is connected to this node
* @fires Node#peer:disconnect Emitted when a peer disconnects from this node
* @fires Node#peer:discovery Emitted when a peer is discovered
* @fires Node#start Emitted when the node and its services has started
* @fires Node#stop Emitted when the node and its services has stopped
* @fires Libp2p#error Emitted when an error occurs
* @fires Libp2p#peer:connect Emitted when a peer is connected to this node
* @fires Libp2p#peer:disconnect Emitted when a peer disconnects from this node
* @fires Libp2p#peer:discovery Emitted when a peer is discovered
* @fires Libp2p#start Emitted when the node and its services has started
* @fires Libp2p#stop Emitted when the node and its services has stopped
*/
class Node extends EventEmitter {
class Libp2p extends EventEmitter {
constructor (_options) {
super()
// validateConfig will ensure the config is correct,
@@ -345,7 +347,7 @@ class Node extends EventEmitter {
let t
if (typeof Transport === 'function') {
t = new Transport()
t = new Transport({ libp2p: this })
} else {
t = Transport
}
@@ -547,4 +549,21 @@ class Node extends EventEmitter {
}
}
module.exports = Node
module.exports = Libp2p
/**
* Like `new Libp2p(options)` except it will create a `PeerInfo`
* instance if one is not provided in options.
* @param {object} options Libp2p configuration options
* @param {function(Error, Libp2p)} callback
* @returns {void}
*/
module.exports.createLibp2p = (options, callback) => {
if (options.peerInfo) {
return nextTick(callback, null, new Libp2p(options))
}
PeerInfo.create((err, peerInfo) => {
if (err) return callback(err)
options.peerInfo = peerInfo
callback(null, new Libp2p(options))
})
}

View File

@@ -63,9 +63,7 @@ module.exports = (node) => {
return nextTick(callback, errCode(new Error('data must be a Buffer'), 'ERR_DATA_IS_NOT_A_BUFFER'))
}
floodSub.publish(topic, data)
nextTick(() => callback())
floodSub.publish(topic, data, callback)
},
ls: (callback) => {

View File

@@ -7,8 +7,15 @@ const expect = chai.expect
const series = require('async/series')
const createNode = require('./utils/create-node')
const sinon = require('sinon')
const { createLibp2p } = require('../src')
const WS = require('libp2p-websockets')
const PeerInfo = require('peer-info')
describe('libp2p creation', () => {
afterEach(() => {
sinon.restore()
})
it('should be able to start and stop successfully', (done) => {
createNode([], {
config: {
@@ -101,4 +108,36 @@ describe('libp2p creation', () => {
node._switch.emit('error', error)
})
})
it('createLibp2p should create a peerInfo instance', function (done) {
this.timeout(10e3)
createLibp2p({
modules: {
transport: [ WS ]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
expect(libp2p).to.exist()
done()
})
})
it('createLibp2p should allow for a provided peerInfo instance', function (done) {
this.timeout(10e3)
PeerInfo.create((err, peerInfo) => {
expect(err).to.not.exist()
sinon.spy(PeerInfo, 'create')
createLibp2p({
peerInfo,
modules: {
transport: [ WS ]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
expect(libp2p).to.exist()
expect(PeerInfo.create.callCount).to.eql(0)
done()
})
})
})
})

View File

@@ -5,34 +5,24 @@ const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const sinon = require('sinon')
const signalling = require('libp2p-webrtc-star/src/sig-server')
const parallel = require('async/parallel')
const crypto = require('crypto')
const createNode = require('./utils/create-node')
const echo = require('./utils/echo')
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
describe('peer discovery', () => {
let nodeA
let nodeB
let nodeC
let port = 24642
let ss
function setup (options) {
before((done) => {
port++
parallel([
(cb) => {
signalling.start({ port: port }, (err, server) => {
expect(err).to.not.exist()
ss = server
cb()
})
},
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], options, (err, node) => {
expect(err).to.not.exist()
nodeA = node
@@ -41,7 +31,7 @@ describe('peer discovery', () => {
}),
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], options, (err, node) => {
expect(err).to.not.exist()
nodeB = node
@@ -50,7 +40,7 @@ describe('peer discovery', () => {
}),
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], options, (err, node) => {
expect(err).to.not.exist()
nodeC = node
@@ -64,8 +54,7 @@ describe('peer discovery', () => {
parallel([
(cb) => nodeA.stop(cb),
(cb) => nodeB.stop(cb),
(cb) => nodeC.stop(cb),
(cb) => ss.stop(cb)
(cb) => nodeC.stop(cb)
], done)
})
@@ -423,6 +412,7 @@ describe('peer discovery', () => {
randomWalk: {
enabled: true,
queriesPerPeriod: 1,
delay: 100,
interval: 200, // start the query sooner
timeout: 3000
}

View File

@@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const parallel = require('async/parallel')
const series = require('async/series')
const signalling = require('libp2p-webrtc-star/src/sig-server')
const rendezvous = require('libp2p-websocket-star-rendezvous')
const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets')
@@ -18,6 +17,8 @@ const createNode = require('./utils/create-node.js')
const tryEcho = require('./utils/try-echo')
const echo = require('./utils/echo')
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
describe('transports', () => {
describe('TCP only', () => {
let nodeA
@@ -409,24 +410,17 @@ describe('transports', () => {
let nodeWS
let nodeWebRTCStar
let ss
before(function (done) {
this.timeout(5 * 1000)
parallel([
(cb) => signalling.start({ port: 24642 }, (err, server) => {
expect(err).to.not.exist()
ss = server
cb()
}),
(cb) => {
const wstar = new WRTCStar({ wrtc: wrtc })
createNode([
'/ip4/0.0.0.0/tcp/0',
'/ip4/127.0.0.1/tcp/25011/ws',
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], {
modules: {
transport: [
@@ -479,12 +473,11 @@ describe('transports', () => {
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => {
const wstar = new WRTCStar({ wrtc: wrtc })
createNode([
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], {
modules: {
transport: [wstar],
@@ -515,8 +508,7 @@ describe('transports', () => {
(cb) => nodeAll.stop(cb),
(cb) => nodeTCP.stop(cb),
(cb) => nodeWS.stop(cb),
(cb) => nodeWebRTCStar.stop(cb),
(cb) => ss.stop(cb)
(cb) => nodeWebRTCStar.stop(cb)
], done)
})