diff --git a/src/dialer/queue.js b/src/dialer/queue.js index a2d79c3..6df9557 100644 --- a/src/dialer/queue.js +++ b/src/dialer/queue.js @@ -241,6 +241,10 @@ class Queue { // depending on the error. connectionFSM.once('error', (err) => { queuedDial.callback(err) + // Dont blacklist peers we have identified and that we are connected to + if (peerInfo.protocols.size > 0 && peerInfo.isConnected()) { + return + } this.blacklist() }) diff --git a/test/dial-fsm.node.js b/test/dial-fsm.node.js index fae69c5..7e71b29 100644 --- a/test/dial-fsm.node.js +++ b/test/dial-fsm.node.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 5] */ 'use strict' const chai = require('chai') @@ -132,6 +133,27 @@ describe('dialFSM', () => { }) }) + it('should not blacklist a peer that was successfully connected', (done) => { + protocol = '/noblacklist/1.0.0' + switchB.handle(protocol, () => { }) + + switchA.dialer.clearBlacklist(switchB._peerInfo) + switchA.dialFSM(switchB._peerInfo, protocol, (err, connFSM) => { + expect(err).to.not.exist() + connFSM.once('connection', () => { + connFSM.once('close', () => { + // peer should not be blacklisted + switchA.dialFSM(switchB._peerInfo, protocol, (err, conn) => { + expect(err).to.not.exist() + conn.once('close', done) + conn.close() + }) + }) + connFSM.close(new Error('bad things')) + }) + }) + }) + it('should emit a `closed` event when closed', (done) => { protocol = '/closed/1.0.0' switchB.handle(protocol, () => { })