Skip to content

Commit f2fc803

Browse files
committed
feat: rendezvous protocol full implementation
1 parent d3923da commit f2fc803

31 files changed

+1489
-772
lines changed

.aegir.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict'
2+
3+
const Libp2p = require('libp2p')
4+
const { MULTIADDRS_WEBSOCKETS } = require('./test/fixtures/browser')
5+
const Peers = require('./test/fixtures/peers')
6+
const PeerId = require('peer-id')
7+
const WebSockets = require('libp2p-websockets')
8+
const Muxer = require('libp2p-mplex')
9+
const { NOISE: Crypto } = require('libp2p-noise')
10+
11+
const Rendezvous = require('.')
12+
13+
let libp2p, rendezvous
14+
15+
const before = async () => {
16+
// Use the last peer
17+
const peerId = await PeerId.createFromJSON(Peers[Peers.length - 1])
18+
19+
libp2p = new Libp2p({
20+
addresses: {
21+
listen: [MULTIADDRS_WEBSOCKETS[0]]
22+
},
23+
peerId,
24+
modules: {
25+
transport: [WebSockets],
26+
streamMuxer: [Muxer],
27+
connEncryption: [Crypto]
28+
},
29+
config: {
30+
relay: {
31+
enabled: true,
32+
hop: {
33+
enabled: true,
34+
active: false
35+
}
36+
}
37+
}
38+
})
39+
40+
await libp2p.start()
41+
42+
// rendezvous = new Rendezvous({ libp2p })
43+
// await rendezvous.start()
44+
}
45+
46+
const after = async () => {
47+
// await rendezvous.stop()
48+
await libp2p.stop()
49+
}
50+
51+
module.exports = {
52+
bundlesize: { maxSize: '100kB' },
53+
hooks: {
54+
pre: before,
55+
post: after
56+
}
57+
}

.travis.yml

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
sudo: false
21
language: node_js
2+
cache: npm
3+
stages:
4+
- check
5+
- test
6+
- cov
37

4-
matrix:
5-
include:
6-
- node_js: 6
7-
env: CXX=g++-4.8
8-
- node_js: 8
9-
env: CXX=g++-4.8
10-
# - node_js: stable
11-
# env: CXX=g++-4.8
8+
node_js:
9+
- '10'
10+
- '12'
11+
12+
os:
13+
- linux
14+
- osx
15+
- windows
1216

13-
script:
14-
- npm run lint
15-
- npm run test
16-
- npm run coverage
17+
script: npx nyc -s npm run test:node -- --bail
18+
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
19+
20+
jobs:
21+
include:
22+
- stage: check
23+
script:
24+
- npx aegir dep-check
25+
- npm run lint
1726

18-
before_script:
19-
- export DISPLAY=:99.0
20-
- sh -e /etc/init.d/xvfb start
27+
- stage: test
28+
name: chrome
29+
addons:
30+
chrome: stable
31+
script:
32+
- npx aegir test -t browser -t webworker
2133

22-
after_success:
23-
- npm run coverage-publish
34+
- stage: test
35+
name: firefox
36+
addons:
37+
firefox: latest
38+
script:
39+
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
2440

25-
addons:
26-
firefox: 'latest'
27-
apt:
28-
sources:
29-
- ubuntu-toolchain-r-test
30-
packages:
31-
- g++-4.8
41+
notifications:
42+
email: false

README.md

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,118 @@
1-
# libp2p-rendezvous
1+
# js-libp2p-rendezvous
22

3-
A javascript implementation of the rendezvous protocol for libp2p
3+
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
4+
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
5+
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
6+
[![](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
47

8+
> Javascript implementation of the rendezvous protocol for libp2p
9+
10+
## Overview
11+
12+
Libp2p rendezvous is a lightweight mechanism for generalized peer discovery. It can be used for bootstrap purposes, real time peer discovery, application specific routing, and so on. Any node implementing the rendezvous protocol can act as a rendezvous point, allowing the discovery of relevant peers in a decentralized fashion.
13+
14+
See https://github.com/libp2p/specs/tree/master/rendezvous for more details
515

616
## Lead Maintainer
717

818
[Vasco Santos](https://github.com/vasco-santos).
919

10-
See https://github.com/libp2p/specs/pull/44 for more details
20+
## API
21+
22+
### rendezvous.register
23+
24+
Registers the peer in a given namespace.
25+
26+
`rendezvous.register(namespace, multiaddrs, [ttl])`
27+
28+
#### Parameters
29+
30+
| Name | Type | Description |
31+
|------|------|-------------|
32+
| namespace | `string` | namespace to register |
33+
| multiaddrs | `Array<Multiaddr>` | [`Multiaddrs`][multiaddr] to announce |
34+
| ttl | `number` | registration ttl in ms (default: `7200e3` and minimum `120`) |
35+
36+
#### Returns
37+
38+
| Type | Description |
39+
|------|-------------|
40+
| `Promise<number>` | Remaining ttl value |
41+
42+
#### Example
43+
44+
```js
45+
// ...
46+
const ttl = await rendezvous.register(namespace, multiaddrs)
47+
```
48+
49+
### rendezvous.unregister
50+
51+
Unregisters the peer from a given namespace.
52+
53+
`rendezvous.unregister(namespace)`
54+
55+
#### Parameters
56+
57+
| Name | Type | Description |
58+
|------|------|-------------|
59+
| namespace | `string` | namespace to unregister |
60+
61+
#### Returns
62+
63+
| Type | Description |
64+
|------|-------------|
65+
| `Promise<void>` | Operation resolved |
66+
67+
#### Example
68+
69+
```js
70+
// ...
71+
await rendezvous.register(namespace, multiaddrs)
72+
await rendezvous.unregister(namespace)
73+
```
74+
75+
### rendezvous.discover
76+
77+
Discovers peers registered under a given namespace.
78+
79+
`rendezvous.discover(namespace, [limit], [cookie])`
80+
81+
#### Parameters
82+
83+
| Name | Type | Description |
84+
|------|------|-------------|
85+
| namespace | `string` | namespace to discover |
86+
| limit | `number` | limit of peers to discover |
87+
| cookie | `Buffer` | |
88+
89+
#### Returns
90+
91+
| Type | Description |
92+
|------|-------------|
93+
| `AsyncIterable<{ id: PeerId, multiaddrs: Array<Multiaddr>, ns: string, ttl: number }>` | Async Iterable registrations |
94+
95+
#### Example
96+
97+
```js
98+
// ...
99+
await rendezvous.register(namespace, multiaddrs)
100+
101+
for await (const reg of rendezvous.discover(namespace)) {
102+
console.log(reg.id, reg.multiaddrs, reg.ns, reg.ttl)
103+
}
104+
```
105+
106+
## Contribute
107+
108+
Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues)!
109+
110+
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
111+
112+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)
113+
114+
## License
115+
116+
MIT - Protocol Labs 2020
117+
118+
[multiaddr]: https://github.com/multiformats/js-multiaddr

appveyor.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

package.json

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
11
{
22
"name": "libp2p-rendezvous",
33
"version": "0.0.0",
4-
"description": "A javascript implementation of the rendezvous protocol for libp2p",
5-
"leadMaintainer": "Vasco Santos <[email protected]>",
6-
"main": "index.js",
7-
"scripts": {
8-
"test": "aegir test"
4+
"description": "Javascript implementation of the rendezvous protocol for libp2p",
5+
"leadMaintainer": "Vasco Santos <[email protected]>",
6+
"main": "src/index.js",
7+
"files": [
8+
"dist",
9+
"src"
10+
],
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/libp2p/js-libp2p-rendezvous.git"
914
},
1015
"keywords": [
1116
"libp2p",
1217
"rendezvous",
1318
"protocol",
1419
"discovery"
1520
],
16-
"author": "Maciej Krüger <[email protected]>",
21+
"bugs": {
22+
"url": "https://github.com/libp2p/js-libp2p-rendezvous/issues"
23+
},
24+
"homepage": "https://libp2p.io",
1725
"license": "MIT",
26+
"engines": {
27+
"node": ">=10.0.0",
28+
"npm": ">=6.0.0"
29+
},
30+
"scripts": {
31+
"lint": "aegir lint",
32+
"build": "aegir build",
33+
"test": "aegir test",
34+
"test:node": "aegir test -t node",
35+
"test:browser": "aegir test -t browser",
36+
"release": "aegir release",
37+
"release-minor": "aegir release --type minor",
38+
"release-major": "aegir release --type major",
39+
"coverage": "nyc --reporter=text --reporter=lcov npm test"
40+
},
1841
"dependencies": {
19-
"chai": "^4.1.2",
42+
"chai": "^4.2.0",
43+
"debug": "^4.1.1",
2044
"dirty-chai": "^2.0.1",
21-
"protons": "^1.0.1",
22-
"pull-protocol-buffers": "^0.1.2"
45+
"err-code": "^2.0.0",
46+
"it-buffer": "^0.1.2",
47+
"it-length-prefixed": "^3.0.1",
48+
"it-pipe": "^1.1.0",
49+
"libp2p-interfaces": "^0.3.0",
50+
"multiaddr": "^7.4.3",
51+
"peer-id": "^0.13.11",
52+
"protons": "^1.2.0",
53+
"streaming-iterables": "^4.1.2"
2354
},
2455
"devDependencies": {
25-
"aegir": "^13.1.0",
26-
"libp2p": "^0.20.2",
27-
"libp2p-mplex": "^0.7.0",
28-
"libp2p-secio": "^0.10.0",
29-
"libp2p-spdy": "^0.12.1",
30-
"libp2p-tcp": "^0.12.0"
31-
},
32-
"repository": {
33-
"type": "git",
34-
"url": "git+https://github.com/mkg20001/libp2p-rendezvous.git"
35-
},
36-
"bugs": {
37-
"url": "https://github.com/mkg20001/libp2p-rendezvous/issues"
38-
},
39-
"homepage": "https://github.com/mkg20001/libp2p-rendezvous#readme"
56+
"aegir": "^22.0.0",
57+
"chai-as-promised": "^7.1.1",
58+
"libp2p": "^0.28.0-rc.0",
59+
"libp2p-mplex": "^0.9.5",
60+
"libp2p-noise": "^1.1.1",
61+
"libp2p-websockets": "^0.13.6",
62+
"p-times": "^3.0.0",
63+
"p-wait-for": "^3.1.0",
64+
"sinon": "^9.0.2"
65+
}
4066
}

src/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
exports.PROTOCOL_MULTICODEC = '/rendezvous/1.0.0'
4+
exports.MAX_NS_LENGTH = 255 // TODO: spec this
5+
exports.MAX_LIMIT = 1000 // TODO: spec this

src/errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
3+
exports.codes = {
4+
INVALID_NAMESPACE: 'ERR_INVALID_NAMESPACE',
5+
INVALID_TTL: 'ERR_INVALID_TTL',
6+
INVALID_MULTIADDRS: 'ERR_INVALID_MULTIADDRS',
7+
NO_CONNECTED_RENDEZVOUS_POINTS: 'ERR_NO_CONNECTED_RENDEZVOUS_POINTS'
8+
}

0 commit comments

Comments
 (0)