-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rendezvous protocol full implementation
- Loading branch information
1 parent
d3923da
commit b23fc7a
Showing
30 changed files
with
1,456 additions
and
754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
const Libp2p = require('libp2p') | ||
const { MULTIADDRS_WEBSOCKETS } = require('./test/fixtures/browser') | ||
const Peers = require('./test/fixtures/peers') | ||
const PeerId = require('peer-id') | ||
const WebSockets = require('libp2p-websockets') | ||
const Muxer = require('libp2p-mplex') | ||
const { NOISE: Crypto } = require('libp2p-noise') | ||
|
||
const Rendezvous = require('.') | ||
|
||
let libp2p, rendezvous | ||
|
||
const before = async () => { | ||
// Use the last peer | ||
const peerId = await PeerId.createFromJSON(Peers[Peers.length - 1]) | ||
|
||
libp2p = new Libp2p({ | ||
addresses: { | ||
listen: [MULTIADDRS_WEBSOCKETS[0]] | ||
}, | ||
peerId, | ||
modules: { | ||
transport: [WebSockets], | ||
streamMuxer: [Muxer], | ||
connEncryption: [Crypto] | ||
}, | ||
config: { | ||
relay: { | ||
enabled: true, | ||
hop: { | ||
enabled: true, | ||
active: false | ||
} | ||
} | ||
} | ||
}) | ||
|
||
await libp2p.start() | ||
|
||
// rendezvous = new Rendezvous({ libp2p }) | ||
// await rendezvous.start() | ||
} | ||
|
||
const after = async () => { | ||
// await rendezvous.stop() | ||
await libp2p.stop() | ||
} | ||
|
||
module.exports = { | ||
bundlesize: { maxSize: '100kB' }, | ||
hooks: { | ||
pre: before, | ||
post: after | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
sudo: false | ||
language: node_js | ||
cache: npm | ||
stages: | ||
- check | ||
- test | ||
- cov | ||
|
||
matrix: | ||
include: | ||
- node_js: 6 | ||
env: CXX=g++-4.8 | ||
- node_js: 8 | ||
env: CXX=g++-4.8 | ||
# - node_js: stable | ||
# env: CXX=g++-4.8 | ||
node_js: | ||
- '10' | ||
- '12' | ||
|
||
os: | ||
- linux | ||
- osx | ||
- windows | ||
|
||
script: | ||
- npm run lint | ||
- npm run test | ||
- npm run coverage | ||
script: npx nyc -s npm run test:node -- --bail | ||
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov | ||
|
||
jobs: | ||
include: | ||
- stage: check | ||
script: | ||
- npx aegir dep-check | ||
- npm run lint | ||
|
||
before_script: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start | ||
- stage: test | ||
name: chrome | ||
addons: | ||
chrome: stable | ||
script: | ||
- npx aegir test -t browser -t webworker | ||
|
||
after_success: | ||
- npm run coverage-publish | ||
- stage: test | ||
name: firefox | ||
addons: | ||
firefox: latest | ||
script: | ||
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless | ||
|
||
addons: | ||
firefox: 'latest' | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- g++-4.8 | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,118 @@ | ||
# libp2p-rendezvous | ||
# js-libp2p-rendezvous | ||
|
||
A javascript implementation of the rendezvous protocol for libp2p | ||
[](http://protocol.ai) | ||
[](http://libp2p.io/) | ||
[](http://webchat.freenode.net/?channels=%23libp2p) | ||
[](https://discuss.libp2p.io) | ||
|
||
> Javascript implementation of the rendezvous protocol for libp2p | ||
## Overview | ||
|
||
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. | ||
|
||
See https://github.com/libp2p/specs/tree/master/rendezvous for more details | ||
|
||
## Lead Maintainer | ||
|
||
[Vasco Santos](https://github.com/vasco-santos). | ||
|
||
See https://github.com/libp2p/specs/pull/44 for more details | ||
## API | ||
|
||
### rendezvous.register | ||
|
||
Registers the peer in a given namespace. | ||
|
||
`rendezvous.register(namespace, multiaddrs, [ttl])` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| namespace | `string` | namespace to register | | ||
| multiaddrs | `Array<Multiaddr>` | [`Multiaddrs`][multiaddr] to announce | | ||
| ttl | `number` | registration ttl in ms (default: `7200e3` and minimum `120`) | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<number>` | Remaining ttl value | | ||
|
||
#### Example | ||
|
||
```js | ||
// ... | ||
const ttl = await rendezvous.register(namespace, multiaddrs) | ||
``` | ||
|
||
### rendezvous.unregister | ||
|
||
Unregisters the peer from a given namespace. | ||
|
||
`rendezvous.unregister(namespace)` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| namespace | `string` | namespace to unregister | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `Promise<void>` | Operation resolved | | ||
|
||
#### Example | ||
|
||
```js | ||
// ... | ||
await rendezvous.register(namespace, multiaddrs) | ||
await rendezvous.unregister(namespace) | ||
``` | ||
|
||
### rendezvous.discover | ||
|
||
Discovers peers registered under a given namespace. | ||
|
||
`rendezvous.discover(namespace, [limit], [cookie])` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| namespace | `string` | namespace to discover | | ||
| limit | `number` | limit of peers to discover | | ||
| cookie | `Buffer` | | | ||
|
||
#### Returns | ||
|
||
| Type | Description | | ||
|------|-------------| | ||
| `AsyncIterable<{ id: PeerId, multiaddrs: Array<Multiaddr>, ns: string, ttl: number }>` | Async Iterable registrations | | ||
|
||
#### Example | ||
|
||
```js | ||
// ... | ||
await rendezvous.register(namespace, multiaddrs) | ||
|
||
for await (const reg of rendezvous.discover(namespace)) { | ||
console.log(reg.id, reg.multiaddrs, reg.ns, reg.ttl) | ||
} | ||
``` | ||
|
||
## Contribute | ||
|
||
Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues)! | ||
|
||
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). | ||
|
||
[](https://github.com/ipfs/community/blob/master/contributing.md) | ||
|
||
## License | ||
|
||
MIT - Protocol Labs 2020 | ||
|
||
[multiaddr]: https://github.com/multiformats/js-multiaddr |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,66 @@ | ||
{ | ||
"name": "libp2p-rendezvous", | ||
"version": "0.0.0", | ||
"description": "A javascript implementation of the rendezvous protocol for libp2p", | ||
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "aegir test" | ||
"description": "Javascript implementation of the rendezvous protocol for libp2p", | ||
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>", | ||
"main": "src/index.js", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/libp2p/js-libp2p-rendezvous.git" | ||
}, | ||
"keywords": [ | ||
"libp2p", | ||
"rendezvous", | ||
"protocol", | ||
"discovery" | ||
], | ||
"author": "Maciej Krüger <mkg20001@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"chai": "^4.1.2", | ||
"dirty-chai": "^2.0.1", | ||
"protons": "^1.0.1", | ||
"pull-protocol-buffers": "^0.1.2" | ||
"bugs": { | ||
"url": "https://github.com/libp2p/js-libp2p-rendezvous/issues" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^13.1.0", | ||
"libp2p": "^0.20.2", | ||
"libp2p-mplex": "^0.7.0", | ||
"libp2p-secio": "^0.10.0", | ||
"libp2p-spdy": "^0.12.1", | ||
"libp2p-tcp": "^0.12.0" | ||
"homepage": "https://libp2p.io", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">=6.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mkg20001/libp2p-rendezvous.git" | ||
"scripts": { | ||
"lint": "aegir lint", | ||
"build": "aegir build", | ||
"test": "aegir test", | ||
"test:node": "aegir test -t node", | ||
"test:browser": "aegir test -t browser", | ||
"release": "aegir release", | ||
"release-minor": "aegir release --type minor", | ||
"release-major": "aegir release --type major", | ||
"coverage": "nyc --reporter=text --reporter=lcov npm test" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mkg20001/libp2p-rendezvous/issues" | ||
"dependencies": { | ||
"debug": "^4.1.1", | ||
"err-code": "^2.0.3", | ||
"it-buffer": "^0.1.2", | ||
"it-length-prefixed": "^3.0.1", | ||
"it-pipe": "^1.1.0", | ||
"libp2p-interfaces": "^0.3.0", | ||
"multiaddr": "^7.5.0", | ||
"peer-id": "^0.13.13", | ||
"protons": "^1.2.0", | ||
"streaming-iterables": "^4.1.2" | ||
}, | ||
"homepage": "https://github.com/mkg20001/libp2p-rendezvous#readme" | ||
"devDependencies": { | ||
"aegir": "^23.0.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"dirty-chai": "^2.0.1", | ||
"libp2p": "^0.28.3", | ||
"libp2p-mplex": "^0.9.5", | ||
"libp2p-noise": "^1.1.2", | ||
"libp2p-websockets": "^0.13.6", | ||
"p-times": "^3.0.0", | ||
"p-wait-for": "^3.1.0", | ||
"sinon": "^9.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
exports.PROTOCOL_MULTICODEC = '/rendezvous/1.0.0' | ||
exports.MAX_NS_LENGTH = 255 // TODO: spec this | ||
exports.MAX_LIMIT = 1000 // TODO: spec this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
exports.codes = { | ||
INVALID_NAMESPACE: 'ERR_INVALID_NAMESPACE', | ||
INVALID_TTL: 'ERR_INVALID_TTL', | ||
INVALID_MULTIADDRS: 'ERR_INVALID_MULTIADDRS', | ||
NO_CONNECTED_RENDEZVOUS_SERVERS: 'ERR_NO_CONNECTED_RENDEZVOUS_SERVERS' | ||
} |
Oops, something went wrong.