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

Commit

Permalink
v0.1.0 (#1)
Browse files Browse the repository at this point in the history
* here it goes

* kick to start ci
  • Loading branch information
daviddias committed Sep 8, 2017
1 parent 258d07d commit 9009dcc
Show file tree
Hide file tree
Showing 13 changed files with 825 additions and 59 deletions.
67 changes: 10 additions & 57 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,12 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
yarn.lock

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
**/node_modules
**/*.log
test/setup/tmp-disposable-nodes-addrs.json
dist
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

**/*.swp
examples/sub-module/**/bundle.js
examples/sub-module/**/*-minified.js
examples/sub-module/*-bundle.js
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
sudo: false
language: node_js

matrix:
include:
- node_js: 6
env: CXX=g++-4.8
- node_js: 8
env: CXX=g++-4.8

script:
- npm run lint
- 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

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# js-libp2p-websocket-star-rendezvous
The rendezvous service for libp2p-websocket-star enabled nodes meet and talk with each other
# libp2p-websocket-star-rendezvous

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

> The rendezvous service for [libp2p-webrtc-star](https://github.com/libp2p/js-libp2p-websocket-star).
## Descriptions

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).

## Usage

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

This will install a `websockets-star` CLI tool. Now you can spawn the server with:

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

Defaults:

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

## 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**.

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.

LICENSE MIT
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
60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "libp2p-websocket-star-rendezvous",
"version": "0.0.0",
"description": "The rendezvous service for libp2p-webrtc-star",
"bin": {
"websockets-star": "src/rendezvous/bin.js"
},
"scripts": {
"rendezvous": "node sig-server/src/bin.js",
"lint": "aegir-lint",
"test": "aegir-test --env node",
"release": "aegir-release --env no-build",
"release-minor": "aegir-release --type minor --env no-build",
"release-major": "aegir-release --type major --env no-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
},
"keywords": [
"libp2p",
"websocket"
],
"author": "Maciej Krüger <mkg20001@gmail.com>",
"license": "MIT",
"dependencies": {
"async": "^2.5.0",
"data-queue": "0.0.2",
"debug": "^3.0.1",
"hapi": "^16.5.2",
"inert": "^4.2.1",
"libp2p-crypto": "^0.10.3",
"mafmt": "^3.0.1",
"merge-recursive": "0.0.3",
"minimist": "^1.2.0",
"multiaddr": "^3.0.1",
"once": "^1.4.0",
"peer-id": "^0.10.1",
"peer-info": "^0.11.0",
"socket.io": "^2.0.3",
"socket.io-client": "^2.0.3",
"socket.io-pull-stream": "^0.1.1",
"uuid": "^3.1.0"
},
"directories": {
"test": "test"
},
"devDependencies": {
"aegir": "^11.0.2",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"lodash": "^4.17.4"
},
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-websocket-star.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-websocket-star/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p-websocket-star#readme"
}
28 changes: 28 additions & 0 deletions src/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

'use strict'

const signalling = require('./index')
const argv = require('minimist')(process.argv.slice(2))

let server

signalling.start({
port: argv.port || argv.p || process.env.PORT || 9090,
host: argv.host || argv.h || process.env.HOST || '0.0.0.0',
cryptoChallenge: !(argv.disableCryptoChallenge || process.env.DISABLE_CRYPTO_CHALLENGE)
}, (err, _server) => {
if (err) {
throw err
}
server = _server

console.log('Listening on:', server.info.uri)
})

process.on('SIGINT', () => {
server.stop(() => {
console.log('Signalling server stopped')
process.exit()
})
})
23 changes: 23 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const debug = require('debug')
const log = debug('signalling-server')
log.error = debug('signalling-server:error')

module.exports = {
log: log,
hapi: {
port: process.env.PORT || 13579,
host: '0.0.0.0',
options: {
connections: {
routes: {
cors: true
}
}
}
},
refreshPeerListIntervalMS: 10000,
cryptoChallenge: true,
strictMultiaddr: true
}
60 changes: 60 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Signalling Server</title>
<link rel="shortcut icon" href="https://libp2p.io/img/favicon.png" type="image/png">
<style>
body {
font-family: sans-serif;
}

tt {
background: #AFAFAF;
padding: 4px;
border-radius: 2px;
}
</style>
</head>

<body>
<center>
<h2>This is a libp2p-websocket-star signalling-server</h2>
<p>Signaling Servers are used in libp2p to allow browsers and clients with restricted port-forwarding to communicate</p>
<div id="addr"></div>
</center>
</body>

<script>
var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/;
var ipv6Regex =
/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
var addr = ""
var f = window.location
if (f.hostname.startsWith("[") && f.hostname.endsWith("]")) f.h = f.hostname.match(/\[(.+)\]/)[1]
else f.h = f.hostname
f.protoport = f.port ? f.port : f.protocol == "https:" ? 443 : 80
if (f.port && ipv4Regex.test()) {
addr += "/ip4/" + f.h + "/tcp/" + f.port + "/"
} else if (f.port && ipv6Regex.test(f.h)) {
addr += "/ip6/" + f.h + "/tcp/" + f.port + "/"
} else if (f.port) {
addr += "/dns/" + f.h + "/tcp/" + f.port + "/"
} else if (ipv4Regex.test(f.h)) {
addr += "/ip4/" + f.h + "/tcp/" + f.protoport + "/"
} else if (ipv6Regex.test(f.h)) {
addr += "/ip6/" + f.h + "/tcp/" + f.protoport + "/"
} else {
addr += "/dns/" + f.h + "/"
}
if (f.protocol == "https:") addr += "wss/"
else addr += "ws/"

addr += "p2p-websocket-star/"

document.getElementById("addr").innerHTML = "You can add this signaling-server with the address <tt>" + addr + "</tt>"
</script>

</html>
57 changes: 57 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'

const Hapi = require('hapi')
const merge = require('merge-recursive').recursive
const path = require('path')

exports = module.exports

exports.start = (options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}

const config = merge(require('./config'), options)
const log = config.log

const port = options.port || config.hapi.port
const host = options.host || config.hapi.host

const http = new Hapi.Server(config.hapi.options)

http.connection({
port,
host
})

http.register({
register: require('inert')
}, err => {
if (err) {
return callback(err)
}

http.start((err) => {
if (err) {
return callback(err)
}

log('signaling server has started on: ' + http.info.uri)

http.peers = require('./routes')(config, http).peers

http.route({
method: 'GET',
path: '/',
handler: (request, reply) => reply.file(path.join(__dirname, 'index.html'), {
confine: false
})
})

callback(null, http)
})
})

return http
}

0 comments on commit 9009dcc

Please sign in to comment.