This repository was archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: limit the number of cold calls we can do #316
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6194d58
feat: limit the number of cold calls we can do
jacobheun a982c14
refactor: cleanup
jacobheun 483557d
fix: constant reference
jacobheun a654c68
refactor: make cold calls configurable
jacobheun e9c67d4
chore: fix linting
jacobheun 253cd9e
fix: make blacklist duration longer
jacobheun 14adab6
fix: improve blacklisting
jacobheun eac4b6b
test: add some tests for queue
jacobheun 0075cc8
fix: make number of attempts configurable
jacobheun 87d9bdc
fix: ensure peers are only added to 1 queue
jacobheun a3e08cf
test: validate cold queue is removed
jacobheun d3889cf
docs: revert bad jsdocs change
jacobheun 9f5c86b
feat: purge old queues every hour
jacobheun 6203879
test: fix aegir post script node shutdown
jacobheun ca4a0b3
fix: abort the cold call queue on manager abort
jacobheun 6b85d63
fix: improve queue cleanup and lower interval to 15 mins
jacobheun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
BLACK_LIST_TTL: 120e3, // How long before an errored peer can be dialed again | ||
BLACK_LIST_TTL: 5 * 60 * 1e3, // How long before an errored peer can be dialed again | ||
BLACK_LIST_ATTEMPTS: 5, // Num of unsuccessful dials before a peer is permanently blacklisted | ||
DIAL_TIMEOUT: 30e3, // How long in ms a dial attempt is allowed to take | ||
MAX_PARALLEL_DIALS: 50 // Maximum allowed concurrent dials | ||
MAX_COLD_CALLS: 50, // How many dials w/o protocols that can be queued | ||
MAX_PARALLEL_DIALS: 100 // Maximum allowed concurrent dials | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(require('chai-checkmark')) | ||
chai.use(dirtyChai) | ||
const sinon = require('sinon') | ||
|
||
const PeerBook = require('peer-book') | ||
const Queue = require('../src/dialer/queue') | ||
const QueueManager = require('../src/dialer/queueManager') | ||
const Switch = require('../src') | ||
|
||
const utils = require('./utils') | ||
const createInfos = utils.createInfos | ||
|
||
describe('dialer', () => { | ||
let switchA | ||
|
||
before((done) => createInfos(1, (err, infos) => { | ||
expect(err).to.not.exist() | ||
|
||
switchA = new Switch(infos[0], new PeerBook()) | ||
|
||
done() | ||
})) | ||
|
||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('queue', () => { | ||
it('should blacklist forever after 5 blacklists', () => { | ||
const queue = new Queue('QM', switchA) | ||
for (var i = 0; i < 4; i++) { | ||
queue.blacklist() | ||
expect(queue.blackListed).to.be.a('number') | ||
expect(queue.blackListed).to.not.eql(Infinity) | ||
} | ||
|
||
queue.blacklist() | ||
expect(queue.blackListed).to.eql(Infinity) | ||
}) | ||
}) | ||
|
||
describe('queue manager', () => { | ||
let queueManager | ||
before(() => { | ||
queueManager = new QueueManager(switchA) | ||
}) | ||
|
||
it('should abort cold calls when the queue is full', (done) => { | ||
sinon.stub(queueManager._coldCallQueue, 'size').value(switchA.dialer.MAX_COLD_CALLS) | ||
const dialRequest = { | ||
peerInfo: { | ||
id: { toB58String: () => 'QmA' } | ||
}, | ||
protocol: null, | ||
useFSM: true, | ||
callback: (err) => { | ||
expect(err.code).to.eql('DIAL_ABORTED') | ||
done() | ||
} | ||
} | ||
|
||
queueManager.add(dialRequest) | ||
}) | ||
|
||
it('should add a protocol dial to the normal queue', () => { | ||
const dialRequest = { | ||
peerInfo: { | ||
id: { toB58String: () => 'QmA' }, | ||
isConnected: () => null | ||
}, | ||
protocol: '/echo/1.0.0', | ||
useFSM: true, | ||
callback: () => {} | ||
} | ||
|
||
const runSpy = sinon.stub(queueManager, 'run') | ||
const addSpy = sinon.stub(queueManager._queue, 'add') | ||
const deleteSpy = sinon.stub(queueManager._coldCallQueue, 'delete') | ||
|
||
queueManager.add(dialRequest) | ||
|
||
expect(runSpy.called).to.eql(true) | ||
expect(addSpy.called).to.eql(true) | ||
expect(addSpy.getCall(0).args[0]).to.eql('QmA') | ||
expect(deleteSpy.called).to.eql(true) | ||
expect(deleteSpy.getCall(0).args[0]).to.eql('QmA') | ||
}) | ||
|
||
it('should add a cold call to the cold call queue', () => { | ||
const dialRequest = { | ||
peerInfo: { | ||
id: { toB58String: () => 'QmA' }, | ||
isConnected: () => null | ||
}, | ||
protocol: null, | ||
useFSM: true, | ||
callback: () => {} | ||
} | ||
|
||
const runSpy = sinon.stub(queueManager, 'run') | ||
const addSpy = sinon.stub(queueManager._coldCallQueue, 'add') | ||
|
||
queueManager.add(dialRequest) | ||
|
||
expect(runSpy.called).to.eql(true) | ||
expect(addSpy.called).to.eql(true) | ||
expect(addSpy.getCall(0).args[0]).to.eql('QmA') | ||
}) | ||
|
||
it('should abort a cold call if it\'s in the normal queue', (done) => { | ||
const dialRequest = { | ||
peerInfo: { | ||
id: { toB58String: () => 'QmA' }, | ||
isConnected: () => null | ||
}, | ||
protocol: null, | ||
useFSM: true, | ||
callback: (err) => { | ||
expect(runSpy.called).to.eql(false) | ||
expect(hasSpy.called).to.eql(true) | ||
expect(hasSpy.getCall(0).args[0]).to.eql('QmA') | ||
expect(err.code).to.eql('DIAL_ABORTED') | ||
done() | ||
} | ||
} | ||
|
||
const runSpy = sinon.stub(queueManager, 'run') | ||
const hasSpy = sinon.stub(queueManager._queue, 'has').returns(true) | ||
|
||
queueManager.add(dialRequest) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.