Merge branch 'masylum-patch-1'

This commit is contained in:
David Dias 2015-09-28 16:11:45 +01:00
commit 1c8fbb2c5b
4 changed files with 35 additions and 13 deletions

View File

@ -56,8 +56,8 @@ sw.addStreamMuxer(streamMuxer, [options])
### Dial to another peer
```JavaScript
sw.dial(PeerInfo, options, protocol)
sw.dial(PeerInfo, options)
sw.dial(PeerInfo, options, protocol, callback)
sw.dial(PeerInfo, options, callback)
```
dial uses the best transport (whatever works first, in the future we can have some criteria), and jump starts the connection until the point we have to negotiate the protocol. If a muxer is available, then drop the muxer onto that connection. Good to warm up connections or to check for connectivity. If we have already a muxer for that peerInfo, than do nothing.

View File

@ -6,7 +6,8 @@
"scripts": {
"test": "./node_modules/.bin/lab tests/*-test.js",
"coverage": "./node_modules/.bin/lab -t 88 tests/*-test.js",
"lint": "./node_modules/.bin/standard"
"lint": "./node_modules/.bin/standard",
"validate": "npm ls"
},
"repository": {
"type": "git",

View File

@ -136,6 +136,11 @@ function Swarm (peerInfo) {
})
})
if (!multiaddrs.length) {
callback(new Error("The swarm doesn't support any of the peer transports"))
return
}
var conn
async.eachSeries(multiaddrs, function (multiaddr, next) {
@ -185,6 +190,7 @@ function Swarm (peerInfo) {
// if protocol is selected, multistream that protocol
if (!conn) {
callback(new Error('Unable to open a connection'))
return
}
if (self.muxers['spdy']) {

View File

@ -16,19 +16,20 @@ var Swarm = require('../src')
var tcp = require('libp2p-tcp')
var Spdy = require('libp2p-spdy')
/* TODO
experiment('Basics', function () {
test('enforces creation with new', function (done) {done() })
})
*/
// because of Travis-CI
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err)
})
experiment('Without a peer', function () {
test('it throws an exception', function (done) {
experiment('Basics', function () {
test('enforces creation with new', function (done) {
expect(function () {
Swarm()
}).to.throw()
done()
})
test('it throws an exception without peerSelf', function (done) {
expect(function () {
var sw = new Swarm()
sw.close()
@ -37,6 +38,21 @@ experiment('Without a peer', function () {
})
})
experiment('When dialing', function () {
experiment('if the swarm does add any of the peer transports', function () {
test('it returns an error', function (done) {
var peerOne = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8090')])
var peerTwo = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8091')])
var swarm = new Swarm(peerOne)
swarm.dial(peerTwo, {}, function (err) {
expect(err).to.exist()
done()
})
})
})
})
experiment('Without a Stream Muxer', function () {
experiment('and one swarm over tcp', function () {
test('add the transport', function (done) {
@ -218,7 +234,6 @@ experiment('With a SPDY Stream Muxer', function () {
}
test('dial a conn on a protocol', function (done) {
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
// formallity so that the conn starts flowing
conn.on('data', function (chunk) {})