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

Commit

Permalink
fix: dont blacklist good peers (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored Apr 3, 2019
1 parent 0f05b9f commit f31663f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit f31663f

Please sign in to comment.