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

feat: limit the number of cold calls we can do #316

Merged
merged 16 commits into from
Apr 2, 2019
Merged

Conversation

jacobheun
Copy link
Contributor

This creates a separate queue for "cold calls" (dials without a protocol). Applications typically do this on peer discovery to connect to new peers. This is to prevent flooding the normal queue, which needs to be prioritized for normal operations, with dials to new peers that may not respond.

This is a workaround, until we can improve the peer discovery system and connection/peer tagging, to allow for proper priority. Right now all dials are treated the same, which includes just creating a new stream on an existing connection. Existing connections and new dials should not be throttled the same way.

This also adds a very basic backoff to blacklisted peers. On its 5th blacklisting the peer will be added to the blacklist permanently. The backoff time may need to be increased before merging this

@ghost ghost assigned jacobheun Apr 1, 2019
@ghost ghost added the in progress label Apr 1, 2019
src/dialer/queue.js Outdated Show resolved Hide resolved
src/dialer/queueManager.js Outdated Show resolved Hide resolved
@jacobheun
Copy link
Contributor Author

Found an unrelated connection management issue, https://github.com/libp2p/js-libp2p-switch/issues/317, as I was running this against my local js-ipfs daemon logging out some stats.

@jacobheun jacobheun marked this pull request as ready for review April 2, 2019 10:03
@jacobheun jacobheun changed the title [WIP] feat: limit the number of cold calls we can do feat: limit the number of cold calls we can do Apr 2, 2019
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @jacobheun ! Nice work

Approved, but left a minor suggestion to consider

src/dialer/queue.js Show resolved Hide resolved
// Clear if the queue has reached max blacklist
if (dialQueue.blackListed === Infinity) {
dialQueue.abort()
delete this._queues[dialQueue.id]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about doing this._queues[dialQueue.id] = undefined?

This is more efficient than deleting, but than we will need to verify that keys have a value when iterating the array, so I do not have a strong opinion here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only running on a 15min interval I think the performance hit should be fairly insignificant and would avoid us needing to check values.

@dirkmc
Copy link

dirkmc commented Apr 2, 2019

LGTM 👍

@jacobheun jacobheun merged commit 4a543cb into master Apr 2, 2019
@ghost ghost removed the in progress label Apr 2, 2019
@vasco-santos vasco-santos deleted the fix/cold-call branch April 3, 2019 08:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants