diff --git a/src/swarm.js b/src/swarm.js index cb4dda5e..06ee8ffb 100644 --- a/src/swarm.js +++ b/src/swarm.js @@ -19,26 +19,32 @@ function Swarm () { } self.port = parseInt(process.env.IPFS_SWARM_PORT, 10) || 4001 - self.connections = {} self.handles = [] // set the listener self.listen = function (port, ready) { - if (!ready) { ready = function noop () {} } + if (!ready) { + ready = function noop () {} + } if (typeof port === 'function') { ready = port } else if (port) { self.port = port } + // + self.listener = tcp.createServer(function (socket) { - errorUp(self, socket) + socket.on('error', function (err) { + console.log('listener socket err - ', err) + }) + var ms = new Select() ms.handle(socket) ms.addHandler('/spdy/3.1.0', function (ds) { log.info('Negotiated spdy with incoming socket') - var conn = new Muxer().attach(ds, false) + var conn = new Muxer().attach(ds, true) // attach multistream handlers to incoming streams diff --git a/tests/swarm-test.js b/tests/swarm-test.js index dc3e1870..807ae8f0 100644 --- a/tests/swarm-test.js +++ b/tests/swarm-test.js @@ -41,7 +41,7 @@ afterEach(function (done) { swarmB.closeListener() done() }) -/* + experiment('BASE', function () { test('Open a stream', function (done) { var protocol = '/sparkles/3.3.3' @@ -73,7 +73,7 @@ experiment('BASE', function () { }) }) }) -*/ + experiment('IDENTIFY', function () { test('Attach Identify, open a stream, see a peer update', function (done) { swarmA.on('error', function (err) { @@ -102,31 +102,31 @@ experiment('IDENTIFY', function () { identifyA.on('peer-update', function (answer) {}) }, 500) }) -/* -test('Attach Identify, open a stream, reuse stream', function (done) { - var protocol = '/sparkles/3.3.3' - var identifyA = new Identify(swarmA, peerA) - var identifyB = new Identify(swarmB, peerB) + test('Attach Identify, open a stream, reuse stream', function (done) { + var protocol = '/sparkles/3.3.3' - swarmA.registerHandler(protocol, function (stream) {}) - swarmB.registerHandler(protocol, function (stream) {}) + var identifyA = new Identify(swarmA, peerA) + var identifyB = new Identify(swarmB, peerB) - swarmA.openStream(peerB, protocol, function theOTHER (err, stream) { - expect(err).to.not.be.instanceof(Error) - }) + swarmA.registerHandler(protocol, function (stream) {}) + swarmB.registerHandler(protocol, function (stream) {}) - identifyB.on('peer-update', function (answer) { - expect(Object.keys(swarmB.connections).length).to.equal(1) - swarmB.openStream(peerA, protocol, function theCALLBACK (err, stream) { + swarmA.openStream(peerB, protocol, function theOTHER (err, stream) { expect(err).to.not.be.instanceof(Error) - expect(Object.keys(swarmB.connections).length).to.equal(1) - done() }) + + identifyB.on('peer-update', function (answer) { + expect(Object.keys(swarmB.connections).length).to.equal(1) + swarmB.openStream(peerA, protocol, function theCALLBACK (err, stream) { + expect(err).to.not.be.instanceof(Error) + expect(Object.keys(swarmB.connections).length).to.equal(1) + done() + }) + }) + identifyA.on('peer-update', function (answer) {}) }) - identifyA.on('peer-update', function (answer) {}) -}) -*/ + }) experiment('HARDNESS', function () {})