Compare commits

..

8 Commits

Author SHA1 Message Date
David Dias
b0aeff8f53 chore: release version v0.12.6 2016-05-06 14:29:24 +01:00
David Dias
998c71fc84 chore: update contributors 2016-05-06 14:29:24 +01:00
David Dias
b31245adc8 Merge pull request #49 from diasdavid/fix/close-count
fix: call cb in close after all transport are closed
2016-05-06 14:19:13 +01:00
Friedel Ziegelmayer
85a064765a fix: call cb in close after all transport are closed 2016-05-06 15:05:34 +02:00
David Dias
fb56cc3c30 Merge pull request #48 from diasdavid/feat/unhandle
unhandle a protocol
2016-05-06 13:11:58 +01:00
David Dias
03d0c52d4d unhandle a protocol 2016-05-06 12:49:31 +01:00
David Dias
0aa7bb72e7 Merge pull request #47 from diasdavid/test/swarm-dial-no-proto
dialing in no proto is fine
2016-05-06 12:43:26 +01:00
David Dias
e9b3d3496f dialing in no proto is fine 2016-05-06 12:31:23 +01:00
5 changed files with 40 additions and 12 deletions

View File

@@ -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.

View File

@@ -1,6 +1,6 @@
{
"name": "libp2p-swarm",
"version": "0.12.5",
"version": "0.12.6",
"description": "libp2p swarm implementation in JavaScript",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
@@ -54,6 +54,7 @@
"stream-pair": "^1.0.3"
},
"dependencies": {
"async": "^2.0.0-rc.4",
"babel-runtime": "^6.6.1",
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
"ip-address": "^5.8.0",
@@ -74,8 +75,8 @@
"David Dias <daviddias.p@gmail.com>",
"David Dias <mail@daviddias.me>",
"Francisco Baio Dias <xicombd@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Pau Ramon Revilla <masylum@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>"
"Richard Littauer <richard.littauer@gmail.com>"
]
}

View File

@@ -1,5 +1,6 @@
'use strict'
const async = require('async')
const multistream = require('multistream-select')
const identify = require('./identify')
const DuplexPassThrough = require('duplex-passthrough')
@@ -360,20 +361,25 @@ function Swarm (peerInfo) {
this.protocols[protocol] = handler
}
this.close = (callback) => {
var count = 0
this.unhandle = (protocol, handler) => {
if (this.protocols[protocol]) {
delete this.protocols[protocol]
}
}
this.close = (callback) => {
Object.keys(this.muxedConns).forEach((key) => {
this.muxedConns[key].muxer.end()
})
Object.keys(this.transports).forEach((key) => {
this.transports[key].close(() => {
if (++count === Object.keys(this.transports).length) {
callback()
}
})
})
async.each(
Object.keys(this.transports),
(key, cb) => this.transports[key].close(cb),
() => {
// Ignoring close errors
callback()
}
)
}
}

View File

@@ -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()
})
})

View File

@@ -153,6 +153,14 @@ describe('high level API - with everything mixed all together!', function () {
})
})
it('dial from ws to ws no proto', (done) => {
swarmD.dial(peerE, (err) => {
expect(err).to.not.exist
expect(Object.keys(swarmD.muxedConns).length).to.equal(1)
done()
})
})
it('dial from ws to ws', (done) => {
swarmE.handle('/abacaxi/1.0.0', (conn) => {
conn.pipe(conn)