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
Prev Previous commit
Next Next commit
chore: add docker setup docks
  • Loading branch information
vasco-santos committed Dec 28, 2020
commit 264ce2abfeb5fff917a3b2975671937fd51a024c
65 changes: 59 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,75 @@ libp2p-rendezvous-server --disableMetrics

### Docker Setup

TODO: Finish docker setup
When running the rendezvous server in Docker, you can configure the same parameters via environment variables, as follows:

```sh
PEER_ID='/etc/opt/rendezvous/id.json'
LISTEN_MULTIADDRS='/ip4/127.0.0.1/tcp/15002/ws,/ip4/127.0.0.1/tcp/8001'
ANNOUNCE_MULTIADDRS='/dns4/test.io/tcp/443/wss,/dns6/test.io/tcp/443/wss'
DATASTORE_HOST='localhost'
DATASTORE_USER='root'
DATASTORE_PASSWORD='your-secret-pw'
DATASTORE_DATABASE='libp2p_rendezvous_db'
```

Please note that you should expose the listening ports with the docker run command. The default ports used are `8003` for the metrics, `8000` for the tcp listener and `150003` for the websockets listener.

Example:

```sh
peer-id --type=ed25519 > id.json
docker build . -t libp2p-rendezvous
docker run -p 8003:8003 -p 15002:15002 -p 8000:8000 \
-e LISTEN_MULTIADDRS='/ip4/127.0.0.1/tcp/8000,/ip4/127.0.0.1/tcp/15002/ws' \
-e ANNOUNCE_MULTIADDRS='/dns4/localhost/tcp/8000,/dns4/localhost/tcp/15002/ws' \
-e DATASTORE_USER='root' \
-e DATASTORE_PASSWORD='your-secret-pw' \
-e DATASTORE_DATABASE='libp2p_rendezvous_db' \
-e PEER_ID='/etc/opt/rendezvous/id.json' \
-v $PWD/id.json:/etc/opt/rendezvous/id.json \
-d libp2p-rendezvous
```

### Docker compose setup with mysql

Here follows an example on how you can setup a rendezvous server with a mysql database.

```yml
version: '3.1'
version: '3.2'
services:
db:
image: mysql
image: mysql:8
volumes:
- mysql-db:/var/lib/mysql
- mysql-db:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: your-secret-pw
MYSQL_DATABASE: libp2p_rendezvous_db
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=libp2p_rendezvous_db
ports:
- "3306:3306"
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 2s
retries: 10
server:
image: libp2p/js-libp2p-rendezvous
volumes:
- ./id.json:/etc/opt/rendezvous/id.json
ports:
- "8000:8000"
- "8003:8003"
- "15003:15003"
restart: always
environment:
- DATASTORE_PASSWORD=my-secret-pw
- DATASTORE_DATABASE=libp2p_rendezvous_db
- DATASTORE_HOST=db
depends_on:
db:
condition: service_healthy
volumes:
mysql-db:
```
Expand Down
34 changes: 27 additions & 7 deletions mysql-local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
version: '3.1'
version: '3.2'
services:
db:
image: mysql
image: mysql:8
volumes:
- mysql-db:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw
MYSQL_USER: libp2p
MYSQL_PASSWORD: my-secret-pw
MYSQL_DATABASE: libp2p_rendezvous_db
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=libp2p_rendezvous_db
ports:
- "3306:3306"
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 2s
retries: 10
server:
image: libp2p-rendezvous
volumes:
- ./id.json:/etc/opt/rendezvous/id.json
ports:
- "8000:8000"
- "8003:8003"
- "15003:15003"
restart: always
environment:
- DATASTORE_PASSWORD=my-secret-pw
- DATASTORE_DATABASE=libp2p_rendezvous_db
- DATASTORE_HOST=db
- PEER_ID=/etc/opt/rendezvous/id.json
depends_on:
db:
condition: service_healthy
volumes:
mysql-db:
mysql-db:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"minimist": "^1.2.5",
"multiaddr": "^8.0.0",
"mysql": "^2.18.1",
"p-retry": "^4.2.0",
"peer-id": "^0.14.1",
"protons": "^2.0.0",
"set-delayed-interval": "^1.0.0",
Expand All @@ -85,7 +86,6 @@
"ipfs-utils": "^5.0.1",
"is-ci": "^2.0.0",
"p-defer": "^3.0.0",
"p-retry": "^4.2.0",
"p-times": "^3.0.0",
"p-wait-for": "^3.1.0",
"sinon": "^9.0.3"
Expand Down
4 changes: 2 additions & 2 deletions src/server/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async function main () {

// PeerId
let peerId
if (argv.peerId) {
const peerData = fs.readFileSync(argv.peerId)
if (argv.peerId || process.env.PEER_ID) {
const peerData = fs.readFileSync(argv.peerId || process.env.PEER_ID)
peerId = await PeerId.createFromJSON(JSON.parse(peerData.toString()))
} else {
peerId = await PeerId.create()
Expand Down
10 changes: 7 additions & 3 deletions src/server/datastores/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const errCode = require('err-code')
const { codes: errCodes } = require('../errors')

const mysql = require('mysql')
const pRetry = require('p-retry')

/**
* @typedef {import('peer-id')} PeerId
Expand Down Expand Up @@ -58,9 +59,8 @@ class Mysql {
* @returns {Promise<void>}
*/
async start () {
this.conn = mysql.createConnection(this.options)

await this._initDB()
// Retry starting the Database in case it is still booting
await pRetry(() => this._initDB())
}

/**
Expand Down Expand Up @@ -311,6 +311,8 @@ class Mysql {
* @returns {Promise<void>}
*/
_initDB () {
this.conn = mysql.createConnection(this.options)

return new Promise((resolve, reject) => {
this.conn.query(`
CREATE TABLE IF NOT EXISTS registration (
Expand All @@ -332,8 +334,10 @@ class Mysql {
);
`, (err) => {
if (err) {
log.error(err)
return reject(err)
}
log('db is initialized')
resolve()
})
})
Expand Down
8 changes: 4 additions & 4 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const { fallbackNullish } = require('./utils')
* @typedef {Object} RendezvousServerOptions
* @property {Datastore} datastore
* @property {number} [minTtl = MIN_TTL] minimum acceptable ttl to store a registration
* @property {number} [maxTtl = MAX_TTL] maxium acceptable ttl to store a registration
* @property {number} [maxNsLength = MAX_NS_LENGTH] maxium acceptable namespace length
* @property {number} [maxDiscoveryLimit = MAX_DISCOVER_LIMIT] maxium acceptable discover limit
* @property {number} [maxPeerRegistrations = MAX_PEER_REGISTRATIONS] maxium acceptable registrations per peer
* @property {number} [maxTtl = MAX_TTL] maximum acceptable ttl to store a registration
* @property {number} [maxNsLength = MAX_NS_LENGTH] maximum acceptable namespace length
* @property {number} [maxDiscoveryLimit = MAX_DISCOVER_LIMIT] maximum acceptable discover limit
* @property {number} [maxPeerRegistrations = MAX_PEER_REGISTRATIONS] maximum acceptable registrations per peer
* @property {number} [gcBootDelay = GC_BOOT_DELAY] delay before starting garbage collector job
* @property {number} [gcMinInterval = GC_MIN_INTERVAL] minimum interval between each garbage collector job, in case maximum threshold reached
* @property {number} [gcInterval = GC_INTERVAL] interval between each garbage collector job
Expand Down