Skip to content

Commit

Permalink
Merge pull request libp2p#48 from diasdavid/feat/unhandle
Browse files Browse the repository at this point in the history
unhandle a protocol
  • Loading branch information
daviddias committed May 6, 2016
2 parents 0aa7bb7 + 03d0c52 commit fb56cc3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ handle a new protocol.
- `protocol`
- `handler` - function called when we receive a dial on `protocol. Signature must be `function (conn) {}`

### `swarm.unhandle(protocol)`

unhandle a protocol.

- `protocol`

### `swarm.close(callback)`

close all the listeners and muxers.
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ function Swarm (peerInfo) {
this.protocols[protocol] = handler
}

this.unhandle = (protocol, handler) => {
if (this.protocols[protocol]) {
delete this.protocols[protocol]
}
}

this.close = (callback) => {
var count = 0

Expand Down
7 changes: 7 additions & 0 deletions test/08-swarm-without-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
conn.on('end', done)
})
})

it('unhandle', (done) => {
const proto = '/bananas/1.0.0'
swarmA.unhandle(proto)
expect(swarmA.protocols[proto]).to.not.exist
done()
})
})

0 comments on commit fb56cc3

Please sign in to comment.