-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: rendezvous protocol initial implementation #6
base: master
Are you sure you want to change the base?
Changes from all commits
b8bf044
d7290df
b080670
ebb22d1
9765a95
b6edaf3
0e304f9
b248924
47641f7
b668c8a
7e3c541
1a1590d
b357829
4abd363
7763df2
63d607b
5f45c6f
640b64f
8f6e148
894ad2e
ee10d69
3798fbb
cdf2f6b
9fe0691
52fa2bd
06d53ac
d501d97
a2d5f83
83cd4b7
9b294f5
9bf5bcb
7a569c7
c297156
e1cd224
264ce2a
01ec7bc
5f025d3
2840251
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
'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 delay = require('delay') | ||
const execa = require('execa') | ||
const pWaitFor = require('p-wait-for') | ||
const isCI = require('is-ci') | ||
|
||
let libp2p | ||
let containerId | ||
|
||
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() | ||
|
||
// TODO: if not running test suite in Node, can also stop here | ||
// https://github.com/ipfs/aegir/issues/707 | ||
// CI runs own datastore service | ||
if (isCI) { | ||
return | ||
} | ||
|
||
const procResult = execa.commandSync('docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test-secret-pw -e MYSQL_DATABASE=libp2p_rendezvous_db -d mysql:8 --default-authentication-plugin=mysql_native_password', { | ||
all: true | ||
}) | ||
containerId = procResult.stdout | ||
|
||
console.log(`wait for docker container ${containerId} to be ready`) | ||
|
||
await pWaitFor(() => { | ||
const procCheck = execa.commandSync(`docker logs ${containerId}`) | ||
const logs = procCheck.stdout + procCheck.stderr // Docker/MySQL sends to the stderr the ready for connections... | ||
|
||
return logs.includes('ready for connections') | ||
}, { | ||
interval: 5000 | ||
}) | ||
// Some more time waiting to guarantee the container is really ready | ||
await delay(12e3) | ||
} | ||
|
||
const after = async () => { | ||
await libp2p.stop() | ||
|
||
if (isCI) { | ||
return | ||
} | ||
|
||
console.log('docker container is stopping') | ||
execa.commandSync(`docker stop ${containerId}`) | ||
} | ||
|
||
module.exports = { | ||
bundlesize: { maxSize: '250kB' }, | ||
hooks: { | ||
pre: before, | ||
post: after | ||
}, | ||
webpack: { | ||
node: { | ||
// this is needed until bcrypto stops using node buffers in browser code | ||
Buffer: true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
!src | ||
!README.md | ||
!package.json |
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: test-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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept the memory datastore previously implemented in the repo. It might be useful for small tests without spinning up MySQL, as well as to run the tests in the browser. The browser tests are not useful as no one should run this in the browser, and I can remove them. For example, for testing the libp2p client in libp2p core, it is easier to use the memory datastore, in order to not have to spin a MySQL db for running the tests |
||
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 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM node:lts-alpine | ||
|
||
# Install deps | ||
RUN apk add --update git build-base python3 | ||
|
||
# Get dumb-init to allow quit running interactively | ||
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && chmod +x /usr/local/bin/dumb-init | ||
|
||
# Setup directories for the `node` user | ||
RUN mkdir -p /home/node/app/rendezvous/node_modules && chown -R node:node /home/node/app/rendezvous | ||
|
||
WORKDIR /home/node/app/rendezvous | ||
|
||
# Install node modules | ||
COPY package.json ./ | ||
# Switch to the node user for installation | ||
USER node | ||
RUN npm install --production | ||
|
||
# Copy over source files under the node user | ||
COPY --chown=node:node ./src ./src | ||
COPY --chown=node:node ./README.md ./ | ||
|
||
ENV DEBUG libp2p* | ||
|
||
# Available overrides (defaults shown): | ||
# Server logging can be enabled via the DEBUG environment variable | ||
CMD [ "/usr/local/bin/dumb-init", "node", "src/bin.js"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github actions does not support running services (mysql) when running tests on other OS... We can move into travis, but I feel we can just run it in ubuntu as I don't expect people will run a Rendezvous server in Windows/MacOS