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

Commit

Permalink
feat: adding relay (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Apr 7, 2017
1 parent ccbf0db commit ea3b9ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ module.exports = function connection (swarm) {

relay (config) {
swarm.relay = true
let circuitDialer = new Circuit.Dialer(swarm, config)
circuitDialer.installSwarmHandler((err, conn) => {
if (err) {
log(err)
return
}

if (conn) {
// TODO: we shouldn't have to pass a handler to the dialer here,
// since the default dialer init should do exactly the same, but
// so far I haven't been able to make it work like that...
let circuitDialer = new Circuit.Dialer(swarm,
config,
(err, conn) => {
if (err) {
log(err)
return
}

protocolMuxer(swarm.protocols, conn)
}
})
})

swarm.transport.add(Circuit.tag, circuitDialer)
},

Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ function Swarm (peerInfo, peerBook) {
}, cb)
}, cb)
}
], callback)
], (err) => {
callback(err)
})
}
}

0 comments on commit ea3b9ff

Please sign in to comment.