Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dialer/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
22 changes: 22 additions & 0 deletions test/dial-fsm.node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 5] */
'use strict'

const chai = require('chai')
Expand Down Expand Up @@ -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, () => { })
Expand Down