Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

feat/bring that dns #84

Merged
merged 10 commits into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ TODO

### API

Follows the interface defined by `interface-transport`

[![](https://raw.githubusercontent.com/diasdavid/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)

### Signalling server

Expand All @@ -63,24 +61,17 @@ Defaults:

## Hosted Signalling Server

We host a signalling server at `signalling.cloud.ipfs.team` that can be used for practical demos and experimentation, it **should not be used for apps in production**.

Since multiaddr doesn't have support for `DNS` yet, you have to add your libp2p-webrtc-star multiaddr by using the IP address instead. To know the Signalling server address, you can do:

```sh
» dig +short webrtc-star-signalling.cloud.ipfs.team
188.166.203.82
```
We host a signalling server at `star-signal.cloud.ipfs.team` that can be used for practical demos and experimentation, it **should not be used for apps in production**.

And so, a webrtc-star address should looking like: `/ip4/188.166.203.82/tcp/20000/ws/ipfs/<your-peer-id>`
A libp2p-webrtc-star address, using the signalling server we provide, looks like: `/libp2p-webrtc-star/dns/star-signal.cloud.ipfs.team/ws/ipfs/<your-peer-id>`

### Deployment

We have a [dokku](https://github.com/ipfs/ops-requests/issues/31) setup ready for this to be deployed, to deploy simple do (you have to have permission first):

```sh
# if you already have added the remote, you don't need to do it again
> git remote add dokku dokku@cloud.ipfs.team:webrtc-star-signalling
> git remote add dokku dokku@cloud.ipfs.team:star-signall
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, should be star-signal I'm assuming

> git push dokku master
```

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"test:dns": "DNS=1 gulp test",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
Expand Down Expand Up @@ -80,4 +81,4 @@
"interfect <interfect@gmail.com>",
"michaelfakhri <fakhrimichael@live.com>"
]
}
}
29 changes: 23 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const EE = require('events').EventEmitter
const wrtc = require('wrtc')
const isNode = require('detect-node')
const SimplePeer = require('simple-peer')
const peerId = require('peer-id')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const Connection = require('interface-connection').Connection
const toPull = require('stream-to-pull-stream')
Expand All @@ -22,6 +22,21 @@ const sioOptions = {
'force new connection': true
}

function cleanUrlSIO (ma) {
const maStrSplit = ma.toString().split('/')
if (!multiaddr.isName(ma)) {
return 'http://' + maStrSplit[3] + ':' + maStrSplit[5]
} else {
if (ma.protos()[2].name === 'ws') {
return 'http://' + maStrSplit[3]
} else if (ma.protos()[2].name === 'wss') {
return 'https://' + maStrSplit[3]
} else {
throw new Error('invalid multiaddr' + ma.toString())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simplify the code to avoid issues like before.

const wsToHttp = (name) => {
  if (name === 'ws') {
    return 'http'
  } 

  if (name === 'wss') {
    return 'https'
  } 

  throw new Error('sad face')
}

const protocol = wsToHttp(ma.protos()[2].name)
return `${protocol}://${maStrSplit[3]}`

}
}

class WebRTCStar {
constructor () {
this.maSelf = undefined
Expand Down Expand Up @@ -116,7 +131,7 @@ class WebRTCStar {

this.maSelf = ma

const sioUrl = 'http://' + ma.toString().split('/')[3] + ':' + ma.toString().split('/')[5]
const sioUrl = cleanUrlSIO(ma)

listener.io = io.connect(sioUrl, sioOptions)

Expand Down Expand Up @@ -200,10 +215,12 @@ class WebRTCStar {

_peerDiscovered (maStr) {
log('Peer Discovered:', maStr)
const id = peerId.createFromB58String(maStr.split('/')[8])
const peer = new PeerInfo(id)
peer.multiaddr.add(multiaddr(maStr))
this.discovery.emit('peer', peer)
const split = maStr.split('/ipfs/')
const peerIdStr = split[split.length - 1]
const peerId = PeerId.createFromB58String(peerIdStr)
const peerInfo = new PeerInfo(peerId)
peerInfo.multiaddr.add(multiaddr(maStr))
this.discovery.emit('peer', peerInfo)
}
}

Expand Down
36 changes: 20 additions & 16 deletions test/transport/dial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ describe('dial', () => {
}

let ws1
const ma1 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')
// deployed sig server
// const ma1 = multiaddr('/libp2p-webrtc-star/ip4/188.166.203.82/tcp/20000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')

let ws2
const ma2 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')
// deployed sig server
// const ma2 = multiaddr('/libp2p-webrtc-star/ip4/188.166.203.82/tcp/20000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')
let ma1
let ma2

const maHS = '/dns/webrtc-star-signalling.cloud.ipfs.team'
// const maHS = '/dns/star-signal.cloud.ipfs.team' NEXT

const maLS = '/ip4/127.0.0.1/tcp/15555'
const maGen = (base, id) => multiaddr(`/libp2p-webrtc-star${base}/ws/ipfs/${id}`)

if (process.env.DNS) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should prefix this env var so it becomes WEBRTC_START_DNS instead, just to avoid any collisions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The currently deployed thing is called webrtc-star-signalling(.cloud.ipfs.team), is it gonna change? (No problem with that, just checking)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgierth I would like it to be shorter, like star-signal. or signal., but I'm happy with any, really.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, just make a call and deploy :) and I'll take care of setting up Let's Encrypt for all cloud.ipfs.team apps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

» ssh dokku@cloud.ipfs.team apps
=====> My Apps
star-signal

@lgierth do your magic 🎩 :D

// test with deployed signalling server
ma1 = maGen(maHS, 'QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')
ma2 = maGen(maHS, 'QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')
} else {
ma1 = maGen(maLS, 'QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')
ma2 = maGen(maLS, 'QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')
}

before((done) => {
series([
Expand All @@ -33,20 +43,13 @@ describe('dial', () => {

function first (next) {
ws1 = new WebRTCStar()

const listener = ws1.createListener((conn) => {
pull(conn, conn)
})

const listener = ws1.createListener((conn) => pull(conn, conn))
listener.listen(ma1, next)
}

function second (next) {
ws2 = new WebRTCStar()

const listener = ws2.createListener((conn) => {
pull(conn, conn)
})
const listener = ws2.createListener((conn) => pull(conn, conn))
listener.listen(ma2, next)
}
})
Expand All @@ -68,6 +71,7 @@ describe('dial', () => {
)
})
})

it('dial offline / non-existent node on IPv4, check callback', (done) => {
let maOffline = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/ABCD')
ws1.dial(maOffline, (err, conn) => {
Expand Down
5 changes: 4 additions & 1 deletion test/transport/filter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ describe('filter', () => {
const maArr = [
multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'),
multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws'),
multiaddr('/libp2p-webrtc-star/dns/libp2p.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'),
multiaddr('/libp2p-webrtc-star/dns/signal.libp2p.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'),
multiaddr('/libp2p-webrtc-star/dns/signal.libp2p.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'),
multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2'),
multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3'),
multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'),
Expand All @@ -20,7 +23,7 @@ describe('filter', () => {
]

const filtered = ws.filter(maArr)
expect(filtered.length).to.equal(4)
expect(filtered.length).to.equal(7)
})

it('filter a single addr for this transport', () => {
Expand Down