Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit f31663f

Browse files
authored
fix: dont blacklist good peers (#319)
1 parent 0f05b9f commit f31663f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/dialer/queue.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ class Queue {
241241
// depending on the error.
242242
connectionFSM.once('error', (err) => {
243243
queuedDial.callback(err)
244+
// Dont blacklist peers we have identified and that we are connected to
245+
if (peerInfo.protocols.size > 0 && peerInfo.isConnected()) {
246+
return
247+
}
244248
this.blacklist()
245249
})
246250

test/dial-fsm.node.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 5] */
23
'use strict'
34

45
const chai = require('chai')
@@ -132,6 +133,27 @@ describe('dialFSM', () => {
132133
})
133134
})
134135

136+
it('should not blacklist a peer that was successfully connected', (done) => {
137+
protocol = '/noblacklist/1.0.0'
138+
switchB.handle(protocol, () => { })
139+
140+
switchA.dialer.clearBlacklist(switchB._peerInfo)
141+
switchA.dialFSM(switchB._peerInfo, protocol, (err, connFSM) => {
142+
expect(err).to.not.exist()
143+
connFSM.once('connection', () => {
144+
connFSM.once('close', () => {
145+
// peer should not be blacklisted
146+
switchA.dialFSM(switchB._peerInfo, protocol, (err, conn) => {
147+
expect(err).to.not.exist()
148+
conn.once('close', done)
149+
conn.close()
150+
})
151+
})
152+
connFSM.close(new Error('bad things'))
153+
})
154+
})
155+
})
156+
135157
it('should emit a `closed` event when closed', (done) => {
136158
protocol = '/closed/1.0.0'
137159
switchB.handle(protocol, () => { })

0 commit comments

Comments
 (0)