-
Notifications
You must be signed in to change notification settings - Fork 94
feat/bring that dns #84
Changes from 3 commits
922635d
2dd7b8a
d47197b
a774de5
a57bdbc
81fff7e
1f1b9be
726e74c
353719a
ce6b409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
@@ -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()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should prefix this env var so it becomes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The currently deployed thing is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgierth I would like it to be shorter, like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@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([ | ||
|
@@ -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) | ||
} | ||
}) | ||
|
@@ -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) => { | ||
|
There was a problem hiding this comment.
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