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

Commit

Permalink
feat: allowJoinWithDisabledChallenge
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Nov 27, 2017
1 parent 188e594 commit 257f92f
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function boot (done) {
refreshPeerListIntervalMS: 1000
}, v)

parallel([['r1', {port: 15001, metrics: f}], ['r2', {port: 15002}], ['r3', {port: 15003, host: '::'}]].map((v) => (cb) => {
parallel([['r1', {port: 15001, metrics: f}], ['r2', {port: 15002}], ['r3', {port: 15003, host: '::'}], ['r4', {port: 15004, cryptoChallenge: true}]].map((v) => (cb) => {
rendezvous.start(base(v.pop()), (err, r) => {
if (err) { return cb(err) }
_r.push(r)
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WebsocketStar {
options = options || {}

this.id = options.id
this.flag = options.allowJoinWithDisabledChallenge // let's just refer to it as "flag"

this.discovery = new EE()
this.discovery.start = (callback) => {
Expand Down Expand Up @@ -84,7 +85,8 @@ class WebsocketStar {
const listener = new Listener({
id: this.id,
handler,
listeners: this.listeners_list
listeners: this.listeners_list,
flag: this.flag
})

listener.on('peer', this._peerDiscovered)
Expand Down
2 changes: 2 additions & 0 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Listener extends EE {
this.canCrypto = Boolean(options.id)
this._handler = options.handler || noop
this.listeners_list = options.listeners || {}
this.flag = options.flag
}

// "private" functions
Expand Down Expand Up @@ -116,6 +117,7 @@ class Listener extends EE {
this._join(callback)
})
} else {
if (!this.flag) { return callback(new Error('Tried to listen on a server with crypto challenge disabled!\n This is prohibited by default and can lead to security issues!\n Please set "allowJoinWithDisabledChallenge" to true in the constructor options (but only if you know what you are doing)!')) }
this.signature = '_'
callback()
}
Expand Down
6 changes: 3 additions & 3 deletions test/dial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('dial', () => {

const maLocalIP4 = '/ip4/127.0.0.1/tcp/15001'
// const maLocalIP6 = '/ip6/::1/tcp/15003'
const maGen = (base, id, sec) => multiaddr(`/${base}/${sec ? "wss" : "ws"}/p2p-websocket-star/ipfs/${id}`)
const maGen = (base, id, sec) => multiaddr(`/${base}/${sec ? 'wss' : 'ws'}/p2p-websocket-star/ipfs/${id}`)

if (process.env.REMOTE_DNS) {
// test with deployed signalling server using DNS
Expand Down Expand Up @@ -65,8 +65,8 @@ describe('dial', () => {
before((done) => {
map(require('./ids.json'), PeerId.createFromJSON, (err, ids) => {
if (err) return done(err)
ws1 = new WebSocketsStar({ id: ids[0] })
ws2 = new WebSocketsStar({ id: ids[1] })
ws1 = new WebSocketsStar({ id: ids[0], allowJoinWithDisabledChallenge: true })
ws2 = new WebSocketsStar({ id: ids[1], allowJoinWithDisabledChallenge: true })

each([
[ws1, ma1],
Expand Down
4 changes: 2 additions & 2 deletions test/discovery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('peer discovery', () => {
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/15003/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo3B')

it('listen on the first', (done) => {
ws1 = new WebSocketStar()
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

const listener = ws1.createListener((/* conn */) => {})

Expand All @@ -32,7 +32,7 @@ describe('peer discovery', () => {
})

it('listen on the second, discover the first', (done) => {
ws2 = new WebSocketStar()
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

ws1.discovery.once('peer', (peerInfo) => {
expect(peerInfo.multiaddrs.has(ma2)).to.equal(true)
Expand Down
2 changes: 1 addition & 1 deletion test/listen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('listen', () => {
const mav6 = multiaddr('/ip6/::1/tcp/15003/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooooB')

before(() => {
ws = new WebSocketStar()
ws = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
})

it('listen, check for callback', (done) => {
Expand Down
6 changes: 3 additions & 3 deletions test/reconnect.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('reconnect to signaling server', () => {
after((done) => r.stop(done))

it('listen on the first', (done) => {
ws1 = new WebSocketStar()
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

const listener = ws1.createListener((conn) => {})
listener.listen(ma1, (err) => {
Expand All @@ -45,7 +45,7 @@ describe('reconnect to signaling server', () => {
})

it('listen on the second, discover the first', (done) => {
ws2 = new WebSocketStar()
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

ws1.discovery.once('peer', (peerInfo) => {
expect(peerInfo.multiaddrs.has(ma2)).to.equal(true)
Expand All @@ -71,7 +71,7 @@ describe('reconnect to signaling server', () => {
})

it('listen on the third, first discovers it', (done) => {
ws3 = new WebSocketStar()
ws3 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

const listener = ws3.createListener((conn) => {})
listener.listen(ma3, (err) => expect(err).to.not.exist())
Expand Down
7 changes: 5 additions & 2 deletions test/strict.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const pull = require('pull-stream')

const WebSocketStar = require('../src')

const SERVER_PORT = 15004

describe('strict', () => {
let id1
let ma1
Expand All @@ -32,8 +34,9 @@ describe('strict', () => {

id1 = keys.shift()
id2 = keys.shift()
ma1 = multiaddr('/ip4/127.0.0.1/tcp/15002/ws/p2p-websocket-star/ipfs/QmS8BL7M8jrXYhHo2ofEVeiq5aDKTr29ksmpcqWxjZGvpX')
ma2 = multiaddr('/ip4/127.0.0.1/tcp/15002/ws/p2p-websocket-star/ipfs/QmeJGHUQ4hsMvPzAoXCdkT1Z9NBgjT7BenVPENUgpufENP')
ma1 = multiaddr('/ip4/127.0.0.1/tcp/' + SERVER_PORT + '/ws/p2p-websocket-star/ipfs/' + id1.toB58String())
ma2 = multiaddr('/ip4/127.0.0.1/tcp/' + SERVER_PORT + '/ws/p2p-websocket-star/ipfs/' + id2.toB58String())

done()
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/valid-connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ describe('valid Connection', () => {
series([first, second], dial)

function first (next) {
ws1 = new WebSocketStar()
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

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

function second (next) {
ws2 = new WebSocketStar()
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })

const listener = ws2.createListener((conn) => pull(conn, conn))
listener.listen(ma2, next)
Expand Down

0 comments on commit 257f92f

Please sign in to comment.