Skip to content
This repository has been 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
54 changes: 34 additions & 20 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,28 +94,31 @@ hello
hello from the other side
```

### Signalling server
### Rendezvous 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:
Nodes using `libp2p-websocket-star` will connect to a known point in the network, a rendezvous point where they can learn about other nodes (Discovery) and route their messages to other nodes (2 hop message routing, also known as relay).

`libp2p-websocket-star` comes with batteries included, that means that you can also spawn your own rendezvous point right from this module. To do that, first insall the module globally in your machine with:

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

This will expose a `ws-star-sig` cli tool. To spawn a server do:
This will install a `websockets-star` CLI tool. Now you can spawn the server with:

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

Defaults:

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

## Hosted Signalling Server
## Hosted Rendezvous server

We host a rendezvous 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**.

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>`
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
Loading