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

Commit

Permalink
fix: listener should emit connection (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and jacobheun committed Aug 15, 2018
1 parent a35ce50 commit 1ac430d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = (swarm, options, connHandler) => {
const utils = utilsFactory(swarm)

listener.stopHandler = new Stop(swarm)
listener.stopHandler.on('connection', (conn) => listener.emit('connection', conn))
listener.hopHandler = new Hop(swarm, options.hop)

/**
Expand Down
35 changes: 35 additions & 0 deletions test/listener.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ describe('listener', function () {
)
})

it(`should emit 'connection'`, function (done) {
handlerSpy(multicodec.relay, conn)

let relayMsg = {
type: proto.CircuitRelay.Type.STOP,
srcPeer: {
id: `QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`,
addrs: [`/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`]
},
dstPeer: {
id: `QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`,
addrs: [`/ipfs/QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`]
}
}

listener.stopHandler.handle = (message, sh) => {
const newConn = new Connection(sh.rest())
listener.stopHandler.emit('connection', newConn)
}

listener.on('connection', (conn) => {
expect(conn).to.be.instanceof(Connection)
done()
})

pull(
pull.values([proto.CircuitRelay.encode(relayMsg)]),
lp.encode(),
pull.collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
})
)
})

it(`should handle CAN_HOP`, function (done) {
handlerSpy(multicodec.relay, conn)

Expand Down

0 comments on commit 1ac430d

Please sign in to comment.