Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
feat: Use better codestyle and new ws-star
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Dec 7, 2017
1 parent 498514d commit aecb2a6
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 15,367 deletions.
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
# File is synced from zeronet-js repo

# Configs, etc.
*.pem
config.json

# NodeJS
node_modules
coverage
.nyc_output
package-lock.json

# aegir
dist
docs

# pkg
zeronet-linux*
zeronet-macos*
zeronet-win*
.pkg

# Other garbage
*.bak
*.log
tmp
/data
.zeronet

# Python
*.pyc

# snap
parts
prime
stage
*.tar.bz2
*.snap
snap/.snapcraft
33 changes: 26 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
language: node_js
node_js:
- "8"
- "6"
dist: trusty
after_success:
- npm run coverage-publish
sudo: false
language: node_js

matrix:
include:
- node_js: 6
env: CXX=g++-4.8
- node_js: 8
env: CXX=g++-4.8
# - node_js: stable
# 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
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
### Example

```js
const libp2p = require("libp2p")
const Id = require("peer-id")
const Info = require("peer-info")
const multiaddr = require("multiaddr")
'use strict'

const Libp2p = require('libp2p')
const Id = require('peer-id')
const Info = require('peer-info')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const WSStarMulti = require('libp2p-websocket-star-multi')
Expand All @@ -44,11 +46,14 @@ Id.create((err, id) => {
peerInfo.multiaddrs.add(multiaddr('/p2p-websocket-star')) // will get replaced to the multiaddr of the individual servers
const ws = new WSStarMulti({
servers: [ // servers are Multiaddr[]
'/dns/ws-star-signal-1.servep2p.com/wss/p2p-websocket-star',
'/dns/ws-star-signal-2.servep2p.com/wss/p2p-websocket-star',
'/dns4/localhost/ws/p2p-websocket-star'
'/dns/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-3.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-4.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
'/dns4/localhost/tcp/80/ws/p2p-websocket-star'
],
//ignore_no_online: true, // enable this to prevent wstar-multi from returning a listen error if no servers are online
// ignore_no_online: true, // enable this to prevent wstar-multi from returning a listen error if no servers are online
id // the id is required for the crypto challenge
})

Expand All @@ -61,9 +66,9 @@ Id.create((err, id) => {
]
}

const node = new libp2p(modules, peerInfo)
const node = new Libp2p(modules, peerInfo)

node.handle("/test/1.0.0", (protocol, conn) => {
node.handle('/test/1.0.0', (protocol, conn) => {
pull(
pull.values(['hello']),
conn,
Expand All @@ -77,7 +82,7 @@ Id.create((err, id) => {
throw err
}

node.dial(peerInfo, "/test/1.0.0", (err, conn) => {
node.dial(peerInfo, '/test/1.0.0', (err, conn) => {
if (err) {
throw err
}
Expand Down
28 changes: 28 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "{build}"

environment:
matrix:
- nodejs_version: "6"
- nodejs_version: "8"

matrix:
fast_finish: true

install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version

# Upgrade npm
- npm install -g npm

# Output our current versions for debugging
- node --version
- npm --version

# Install our package dependencies
- npm install

test_script:
- npm run test:node

build: off
67 changes: 67 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'

const Libp2p = require('libp2p')
const Id = require('peer-id')
const Info = require('peer-info')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const WSStarMulti = require('libp2p-websocket-star-multi')

Id.create((err, id) => {
if (err) throw err

const peerInfo = new Info(id)
peerInfo.multiaddrs.add(multiaddr('/p2p-websocket-star')) // will get replaced to the multiaddr of the individual servers
const ws = new WSStarMulti({
servers: [ // servers are Multiaddr[]
'/dns/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-3.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star-signal-4.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
'/dns4/localhost/tcp/80/ws/p2p-websocket-star'
],
// ignore_no_online: true, // enable this to prevent wstar-multi from returning a listen error if no servers are online
id // the id is required for the crypto challenge
})

const modules = {
transport: [
ws
],
discovery: [
ws.discovery
]
}

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.log()
)
})

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.log()
)
})
})
})
Loading

0 comments on commit aecb2a6

Please sign in to comment.