diff --git a/src/index.js b/src/index.js index f0aafa1451..c24a823a70 100644 --- a/src/index.js +++ b/src/index.js @@ -152,14 +152,25 @@ function Swarm (peerInfo) { var peerIdForConn muxedConn.on('stream', (conn) => { - if (peerIdForConn) { - conn.peerId = peerIdForConn + function gotId () { + if (peerIdForConn) { + conn.peerId = peerIdForConn + connHandler(conn) + } else { + setTimeout(gotId, 100) + } + } + + if (this.identify) { + return gotId() } + connHandler(conn) }) // if identify is enabled, attempt to do it for muxer reuse if (this.identify) { + console.log('exec identify') identify.exec(conn, muxedConn, peerInfo, (err, pi) => { if (err) { return console.log('Identify exec failed', err) diff --git a/test/09-swarm-with-muxing.node.js b/test/09-swarm-with-muxing.node.js index 03748ddb7e..939c0d1ad4 100644 --- a/test/09-swarm-with-muxing.node.js +++ b/test/09-swarm-with-muxing.node.js @@ -190,6 +190,7 @@ describe('high level API - with everything mixed all together!', function () { it('dial from tcp+ws to tcp+ws', (done) => { swarmC.handle('/mamao/1.0.0', (conn) => { + expect(conn.peerId).to.exist conn.pipe(conn) }) @@ -204,21 +205,6 @@ describe('high level API - with everything mixed all together!', function () { }) }) - it('again, so that identify had time', (done) => { - swarmC.handle('/mamao/1.0.0', (conn) => { - expect(conn.peerId).to.exist - conn.pipe(conn) - }) - - swarmA.dial(peerC, '/mamao/1.0.0', (err, conn) => { - expect(err).to.not.exist - expect(conn.peerId).to.exist - conn.end() - conn.on('data', () => {}) // let it flow.. let it flooooow - conn.on('end', done) - }) - }) - it('close a muxer emits event', (done) => { swarmC.close(() => {}) swarmA.once('peer-mux-closed', (peerInfo) => {