Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Review of WebSocket Star #16

Merged
merged 12 commits into from
Sep 11, 2017
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
node_modules
*.bak
package-lock.json
yarn.lock

**/node_modules
**/*.log
test/setup/tmp-disposable-nodes-addrs.json
dist
coverage
**/*.swp
examples/sub-module/**/bundle.js
examples/sub-module/**/*-minified.js
examples/sub-module/*-bundle.js
23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
sudo: false
language: node_js
dist: trusty

matrix:
include:
- node_js: 4
- node_js: 6
env:
# - SAUCE=true
- node_js: stable

# Make sure we have new NPM.
before_install:
- npm install -g npm
env: CXX=g++-4.8
- node_js: 8
env: CXX=g++-4.8

script:
- cd sig-server && npm i && cd ..
- npm run lint
- npm test
- npm run test
- npm run coverage

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
# - npm run coverage-publish
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
65 changes: 25 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# libp2p-websocket-star

[![](https://img.shields.io/badge/made%20by-mkg20001-blue.svg?style=flat-square)](http://ipn.io)
[![Build Status](https://travis-ci.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://travis-ci.org/libp2p/js-libp2p-websocket-star)
[![Travis](https://travis-ci.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://travis-ci.org/libp2p/js-libp2p-websocket-star)
[![Circle](https://circleci.com/gh/libp2p/js-libp2p-websocket-star.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-websocket-star)
[![Coverage](https://coveralls.io/repos/github/libp2p/js-libp2p-websocket-star/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-websocket-star?branch=master)
[![david-dm](https://david-dm.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star)

![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)
![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)
Expand All @@ -10,9 +13,7 @@

## Description

`libp2p-websocket-star` is one of the Websocket transports available for libp2p. `libp2p-websocket-star` incorporates both a transport and a discovery service that is facilitated by the signalling server, also part of this module.

**Note:** This module uses [pull-streams](https://pull-stream.github.io) for all stream based interfaces.
`libp2p-websocket-star` is one of the multiple transports available for libp2p. `libp2p-websocket-star` incorporates both a transport and a discovery service that is facilitated by the rendezvous server, also available in this repo and module.

## Usage

Expand Down Expand Up @@ -42,7 +43,10 @@ Id.create((err, id) => {

const peerInfo = new Info(id)
peerInfo.multiaddrs.add(multiaddr("/dns4/ws-star-signal-1.servep2p.com/wss/p2p-websocket-star/"))
const ws = new WSStar({ id }) //the id is required for the crypto challenge

// TODO -> review why the ID can not be passed by the .listen call
const ws = new WSStar({ id: id }) // the id is required for the crypto challenge

const modules = {
transport: [
ws
Expand All @@ -51,25 +55,32 @@ Id.create((err, id) => {
ws.discovery
]
}
const swarm = new libp2p(modules, peerInfo)

swarm.handle("/test/1.0.0", (protocol, conn) => {
const node = new libp2p(modules, peerInfo)

node.handle("/test/1.0.0", (protocol, conn) => {
pull(
pull.values(['hello']),
conn,
pull.map(s => s.toString()),
pull.map((s) => s.toString()),
pull.log()
)
})

swarm.start(err => {
if (err) throw err
swarm.dial(peerInfo, "/test/1.0.0", (err, conn) => {
if (err) throw err
node.start((err) => {
if (err) {
throw err
}

node.dial(peerInfo, "/test/1.0.0", (err, conn) => {
if (err) {
throw err
}

pull(
pull.values(['hello from the other side']),
conn,
pull.map(s => s.toString()),
pull.map((s) => s.toString()),
pull.log()
)
})
Expand All @@ -83,33 +94,7 @@ hello
hello from the other side
```

### Signalling server

`libp2p-websocket-star` comes with its own signalling server, used for peers to handshake their signalling data and establish a connection. You can install it in your machine by installing the module globally:

```bash
> npm install --global libp2p-websocket-star-signal
```

This will expose a `ws-star-sig` cli tool. To spawn a server do:

```bash
> ws-star-signal --port=9090 --host=127.0.0.1
```

Defaults:

- `port` - 13579
- `host` - '0.0.0.0'

## Hosted Signalling Server

We host a signalling server at `ws-star-signal-1.servep2p.com` and `ws-star-signal-2.servep2p.com` that can be used for practical demos and experimentation, it **should not be used for apps in production**.
A libp2p-websocket-star address, using the signalling server we provide, looks like:

`/dns4/ws-star-signal-1.servep2p.com/wss/p2p-websocket-star/ipfs/<your-peer-id>`

Note: The address above indicates WebSockets Secure, which can be accessed from both http and https.
### [Rendezvous server](https://github.com/libp2p/js-libp2p-websocket-star-rendezvous)

### This module uses `pull-streams`

Expand Down
14 changes: 14 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome.deb || true
- sudo apt-get update
- sudo apt-get install -f
- sudo apt-get install --only-upgrade lsb-base
- sudo dpkg -i google-chrome.deb
- google-chrome --version
73 changes: 32 additions & 41 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
'use strict'

const gulp = require('gulp')
const sigServer = require('./sig-server/src')
const parallel = require('async/parallel')
const rendezvous = require('libp2p-websocket-star-rendezvous')

let sigS, sigS2, sigS3
let r1
let r2
let r3

gulp.task('test:node:before', boot)
gulp.task('test:node:after', stop)
gulp.task('test:browser:before', boot)
gulp.task('test:browser:after', stop)
gulp.task("wait", (cb) => {})

function boot(done) {
const options = {
port: 15555,
function boot (done) {
const base = {
host: '0.0.0.0',
cryptoChallenge: false,
strictMultiaddr: false
}

sigServer.start(options, (err, server) => {
if (err) {
throw err
}
sigS = server
console.log('signalling on:', server.info.uri)
const options = {
port: 14444,
host: '0.0.0.0'
}

sigServer.start(options, (err, server) => {
if (err) {
throw err
}
sigS2 = server
console.log('strict signalling on:', server.info.uri)
const options = {
port: 13333,
host: '::',
cryptoChallenge: false,
strictMultiaddr: false
}

sigServer.start(options, (err, server) => {
if (err) {
throw err
}
sigS3 = server
console.log('ipv6 signalling on:', server.info.uri)
done()
})
parallel([
(cb) => rendezvous.start(Object.assign({port: 15001}, base), (err, r) => {
if (err) { return cb(err) }
r1 = r
console.log('r1:', r.info.uri)
cb()
}),
(cb) => rendezvous.start(Object.assign({port: 15002}, base), (err, r) => {
if (err) { return cb(err) }
r2 = r
console.log('r2:', r.info.uri)
cb()
}),
(cb) => rendezvous.start(Object.assign({port: 15003, host: '::'}, base), (err, r) => {
if (err) { return cb(err) }
r3 = r
console.log('r3:', r.info.uri)
cb()
})
})
], done)
}

function stop(done) {
require("async/each")([sigS, sigS2, sigS3], (s, n) => s.stop(n), done)
function stop (done) {
parallel([
(cb) => r1.stop(cb),
(cb) => r2.stop(cb),
(cb) => r3.stop(cb)
], done)
}

require('aegir/gulp')(gulp)
Loading