Skip to content

Commit fb56cc3

Browse files
committed
Merge pull request libp2p#48 from diasdavid/feat/unhandle
unhandle a protocol
2 parents 0aa7bb7 + 03d0c52 commit fb56cc3

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ handle a new protocol.
109109
- `protocol`
110110
- `handler` - function called when we receive a dial on `protocol. Signature must be `function (conn) {}`
111111

112+
### `swarm.unhandle(protocol)`
113+
114+
unhandle a protocol.
115+
116+
- `protocol`
117+
112118
### `swarm.close(callback)`
113119

114120
close all the listeners and muxers.

src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ function Swarm (peerInfo) {
360360
this.protocols[protocol] = handler
361361
}
362362

363+
this.unhandle = (protocol, handler) => {
364+
if (this.protocols[protocol]) {
365+
delete this.protocols[protocol]
366+
}
367+
}
368+
363369
this.close = (callback) => {
364370
var count = 0
365371

test/08-swarm-without-muxing.node.js

+7
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
103103
conn.on('end', done)
104104
})
105105
})
106+
107+
it('unhandle', (done) => {
108+
const proto = '/bananas/1.0.0'
109+
swarmA.unhandle(proto)
110+
expect(swarmA.protocols[proto]).to.not.exist
111+
done()
112+
})
106113
})

0 commit comments

Comments
 (0)