Skip to content

Commit

Permalink
chore: run with mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 21, 2020
1 parent a2d5f83 commit be5778f
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 170 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- '**'

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- uses: gozala/typescript-error-reporter-action@v1.0.8
- run: yarn build
- run: yarn aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
name: size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
needs: check
runs-on: ${{ matrix.os }}
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: my-secret-pw
MYSQL_DATABASE: libp2p_rendezvous_db
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
matrix:
os: [ubuntu-latest]
node: [12, 14]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npx aegir test -t browser -t webworker --bail
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion mysql/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: mysql
volumes:
- mysql-db:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
#command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
# MYSQL_ROOT_PASSWORD: my-secret-pw
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"node": ">=12.0.0",
"npm": ">=6.0.0"
},
"browser": {
"mysql": false
},
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
Expand Down Expand Up @@ -59,14 +62,16 @@
"mysql": "^2.18.1",
"peer-id": "^0.14.1",
"protons": "^2.0.0",
"streaming-iterables": "^5.0.2"
"streaming-iterables": "^5.0.2",
"uint8arrays": "^2.0.5"
},
"devDependencies": {
"aegir": "^29.2.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"delay": "^4.4.0",
"dirty-chai": "^2.0.1",
"ipfs-utils": "^5.0.1",
"p-defer": "^3.0.0",
"p-times": "^3.0.0",
"p-wait-for": "^3.1.0",
Expand Down
27 changes: 27 additions & 0 deletions sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
USE libp2p_rendezvous_db

CREATE TABLE IF NOT EXISTS registration (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
namespace varchar(255) NOT NULL,
peer_id varchar(255) NOT NULL,
PRIMARY KEY (id),
INDEX (namespace, peer_id)
);

CREATE TABLE IF NOT EXISTS cookie (
id varchar(21),
namespace varchar(255),
reg_id INT UNSIGNED,
peer_id varchar(255) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id, namespace, reg_id),
INDEX (created_at)
);

INSERT INTO registration (namespace, peer_id) VALUES ('test-ns', 'QmW8rAgaaA6sRydK1k6vonShQME47aDxaFidbtMevWs73t');

SELECT * FROM registration

SELECT * FROM cookie

INSERT INTO registration (namespace, peer_id) VALUES ('test-ns', 'QmZqCdSzgpsmB3Qweb9s4fojAoqELWzqku21UVrqtVSKi4');
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Rendezvous {
const registerTasks = []

/**
* @param {Multiaddr} m
* @param {Multiaddr} m
* @returns {Promise<number>}
*/
const taskFn = async (m) => {
Expand Down Expand Up @@ -280,16 +280,19 @@ class Rendezvous {
// track registrations
yield registrationTransformer(r)

// Store cookie
const nsCookies = this._cookies.get(ns) || new Map()
nsCookies.set(m.toString(), toString(recMessage.discoverResponse.cookie))
this._cookies.set(ns, nsCookies)

limit--
if (limit === 0) {
return
break
}
}

// Store cookie
const c = recMessage.discoverResponse.cookie
if (c && c.length) {
const nsCookies = this._cookies.get(ns) || new Map()
nsCookies.set(m.toString(), toString(c))
this._cookies.set(ns, nsCookies)
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/server/datastores/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ class Memory {
return Promise.resolve()
}

stop () {
this.nsRegistrations.clear()
this.cookieRegistrations.clear()
}
stop () {}

reset () {
this.nsRegistrations.clear()
this.cookieRegistrations.clear()
return Promise.resolve()
}

Expand Down
Loading

0 comments on commit be5778f

Please sign in to comment.