Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b8bf044
feat: rendezvous protocol full implementation
vasco-santos May 20, 2020
d7290df
chore: interface-peer-discovery compliance
vasco-santos Jul 10, 2020
b080670
feat: garbage collector
vasco-santos Jul 13, 2020
ebb22d1
feat: cookie for discovery
vasco-santos Jul 13, 2020
9765a95
chore: cleanup
vasco-santos Jul 15, 2020
b6edaf3
chore: update aegir
vasco-santos Jul 17, 2020
0e304f9
chore: convert to seconds in the wire
vasco-santos Jul 17, 2020
b248924
chore: remove unregister comments for response
vasco-santos Jul 20, 2020
47641f7
feat: use signed peer records to exchange multiaddrs
vasco-santos Jul 22, 2020
b668c8a
chore: tests
vasco-santos Jul 22, 2020
7e3c541
chore: change readme
vasco-santos Jul 27, 2020
1a1590d
chore: update deps
vasco-santos Sep 22, 2020
b357829
chore: remove peer discovery interface as we will be creating libp2p.…
vasco-santos Sep 22, 2020
4abd363
chore: use uint8array instead of buffer
vasco-santos Sep 22, 2020
7763df2
chore: update libp2p integration doc
vasco-santos Sep 28, 2020
63d607b
chore: fix register ttl param return
vasco-santos Sep 28, 2020
5f45c6f
chore: update docs
vasco-santos Sep 29, 2020
640b64f
chore: remove enabled property from libp2p integration doc
vasco-santos Oct 5, 2020
8f6e148
chore: apply suggestions from code review
vasco-santos Nov 16, 2020
894ad2e
chore: separate server and client rendezvous
vasco-santos Nov 17, 2020
ee10d69
chore: add docker
vasco-santos Nov 17, 2020
3798fbb
fix: changed default values and moved them into the server with prope…
vasco-santos Nov 17, 2020
cdf2f6b
chore: update docs and constants
vasco-santos Nov 17, 2020
9fe0691
chore: add tests for protocol with direct connection to server
vasco-santos Nov 18, 2020
52fa2bd
chore: DoS protection with max registrations
vasco-santos Nov 19, 2020
06d53ac
chore: refactor client
vasco-santos Nov 21, 2020
d501d97
chore: add datastore and types
vasco-santos Dec 8, 2020
a2d5f83
chore: fix build
vasco-santos Dec 13, 2020
83cd4b7
chore: run with mysql
vasco-santos Dec 21, 2020
9b294f5
feat: gc
vasco-santos Dec 24, 2020
9bf5bcb
chore: add gc tests
vasco-santos Dec 24, 2020
7a569c7
chore: review docs and binary
vasco-santos Dec 24, 2020
c297156
chore: add datastore docs and model picture
vasco-santos Dec 28, 2020
e1cd224
chore: add library docs
vasco-santos Dec 28, 2020
264ce2a
chore: add docker setup docks
vasco-santos Dec 28, 2020
01ec7bc
chore: remove client code and move server into src
vasco-santos Jan 4, 2021
5f025d3
chore: use connection pool
vasco-santos Jan 11, 2021
2840251
fix: bin stdout addresses and ports correctly
vasco-santos Jan 15, 2021
9da390f
chore: add benchmarks
vasco-santos Jan 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: rendezvous protocol full implementation
  • Loading branch information
vasco-santos committed Jul 9, 2020
commit b8bf044e562349b002b8d4b4f6cb644240f0d17e
57 changes: 57 additions & 0 deletions .aegir.js
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
}
}
61 changes: 36 additions & 25 deletions .travis.yml
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
47 changes: 47 additions & 0 deletions LIBP2P.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Rendezvous Protocol in js-libp2p

The rendezvous protocol can be used in different contexts across libp2p. For using it, the libp2p network needs to have well known libp2p nodes acting as rendezvous servers. These nodes will have an extra role in the network. They will collect and maintain a list of registrations per rendezvous namespace. Other peers in the network will act as rendezvous clients and will register themselves on given namespaces by messaging a rendezvous server node. Taking into account these registrations, a rendezvous client is able to discover other peers in a given namespace by querying a server.

## Usage

`js-libp2p` supports the usage of the rendezvous protocol through its configuration. It allows to enable the rendezvous protocol, as well as its server mode, enable automatic peer discover and to specify the topics to register from startup.

The rendezvous comes with a discovery service that enables libp2p to automatically discover other peers in the provided namespaces and eventually connect to them.
**TODO: it should be compliant with the peer-discovery interface and configured as any other discovery service instead!!**

You can configure it through libp2p as follows:

```js
const Libp2p = require('libp2p')

const node = await Libp2p.create({
// ... required configurations
rendezvous: {
enabled: true,
namespaces: ['/namespace/1', '/namespace/2'],
discovery: {
enabled: true,
interval: 1000
},
server: {
enabled: true
}
}
})
```

While `js-libp2p` supports the rendezvous protocol out of the box, it also provides a rendezvous API that users can interact with. This API should allow users to register new rendezvous namespaces, unregister from previously registered namespaces and to manually discover other peers.

## Libp2p Flow

When a libp2p node with the rendezvous protocol enabled starts, it should start by connecting to a rendezvous server and ask for nodes in the given namespaces. The rendezvous server can be added to the bootstrap nodes or manually dialed. An example of a namespace could be a relay namespace, so that undiable nodes can register themselves as reachable through that relay.

If the discovery service is disabled, the rendezvous API should allow users to discover peers registered on provided namespaces.

When a libp2p node running the rendezvous protocol is going to stop, it should unregister from all the namespaces previously registered.

In the event of a rendezvous client getting connected to a second rendezvous server, it should propagate its registrations to it. The rendezvous server should clean its registrations for a peer when it is not connected with it anymore.

## Other notes:

After a query is made, who is responsible for determining if we need more records? (cookie reuse)
113 changes: 110 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,117 @@
# libp2p-rendezvous
# js-libp2p-rendezvous

A javascript implementation of the rendezvous protocol for libp2p
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](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, [ttl])`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| namespace | `string` | namespace to register |
| 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)
```

### 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)
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, signedPeerRecord: Envelope, ns: string, ttl: number }>` | Async Iterable registrations |

#### Example

```js
// ...
await rendezvous.register(namespace)

for await (const reg of rendezvous.discover(namespace)) {
console.log(reg.id, reg.signedPeerRecord, 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://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)

## License

MIT - Protocol Labs 2020

[multiaddr]: https://github.com/multiformats/js-multiaddr
28 changes: 0 additions & 28 deletions appveyor.yml

This file was deleted.

Loading