Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
feat: removing multihop (onion) dialing
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Aug 2, 2017
1 parent b6ce189 commit 1c7dd20
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 346 deletions.
33 changes: 28 additions & 5 deletions src/circuit/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@ class Dialer {
* Dial a peer over a relay
*
* @param {multiaddr} ma - the multiaddr of the peer to dial
* @param {Object} options - dial options
* @param {Function} cb - a callback called once dialed
* @returns {Connection} - the connection
*
* @memberOf Dialer
*/
dial (ma, options, cb) {
throw new Error('abstract class, method not implemented')
dial (ma, cb) {
const dstConn = new Connection()
setImmediate(this.dialPeer.bind(this), multiaddr(ma), (err, conn) => {
if (err) {
log.err(err)
return cb(err)
}
dstConn.setInnerConn(conn)
cb(null, dstConn)
})

return dstConn
}

/**
Expand Down Expand Up @@ -186,8 +195,22 @@ class Dialer {
return cb(err)
}

this.relayPeers.set(this.utils.getB58String(peer), peer)
cb(null)
streamHandler.read((err, msg) => {
if (err) {
log.err(err)
return cb(err)
}

const response = proto.CircuitRelay.decode(msg)

if (response.code !== proto.CircuitRelay.Status.SUCCESS) {
return log(`HOP not supported, skipping - ${this.utils.getB58String(peer)}`)
}

log(`HOP supported adding as relay - ${this.utils.getB58String(peer)}`)
this.relayPeers.set(this.utils.getB58String(peer), peer)
cb(null)
})
})
})
}
Expand Down
161 changes: 0 additions & 161 deletions src/circuit/onion-dialer.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const mafmt = require('mafmt')
const multiaddr = require('multiaddr')

const OnionDialer = require('./circuit/onion-dialer')
const CircuitDialer = require('./circuit/dialer')
const utilsFactory = require('./circuit/utils')

const debug = require('debug')
Expand Down Expand Up @@ -40,7 +40,7 @@ class Dialer {
}

// TODO: add flag for other types of dealers, ie telescope
this.dialer = new OnionDialer(swarm, options)
this.dialer = new CircuitDialer(swarm, options)

this.swarm.on('peer-mux-established', this.dialer.canHop.bind(this.dialer))
this.swarm.on('peer-mux-closed', (peerInfo) => {
Expand Down
7 changes: 1 addition & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
'use strict'

module.exports = {
Hop: require('./circuit/hop'),
Dialer: require('./dialer'),
multicodec: require('./multicodec'),
tag: 'Circuit'
}
module.exports = require('./dialer')
Loading

0 comments on commit 1c7dd20

Please sign in to comment.