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: add basic dial queue to avoid many connections to peer #310
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a3e4dca
chore: dont log priviatized unless it actually happened
jacobheun 175dc6e
refactor: only get our addresses for filtering once
jacobheun 832c496
feat: add dial queue
jacobheun 06d60ad
refactor: do some cleanup
jacobheun 15153cd
feat: make the DialerQueue abort on switch stop
jacobheun 87ed0d5
docs: clean up jsdocs per feedback
jacobheun f753384
fix: use err codes
jacobheun 6e8241a
fix: dialer queue return order
jacobheun 5fcfb36
fix: improve connection close logic
jacobheun 988d212
fix: only add connection once muxed
jacobheun d5fa002
test: correct close event test
jacobheun d1ecc70
refactor: clean up based on feedback
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
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 |
---|---|---|
|
@@ -261,7 +261,7 @@ class ConnectionFSM extends BaseConnection { | |
* @returns {void} | ||
*/ | ||
_onDisconnecting () { | ||
this.log('disconnecting from %s', this.theirB58Id) | ||
this.log('disconnecting from %s', this.theirB58Id, Boolean(this.muxer)) | ||
|
||
// Issue disconnects on both Peers | ||
if (this.theirPeerInfo) { | ||
|
@@ -366,8 +366,6 @@ class ConnectionFSM extends BaseConnection { | |
const conn = observeConnection(null, key, _conn, this.switch.observer) | ||
|
||
this.muxer = this.switch.muxers[key].dialer(conn) | ||
// this.switch.muxedConns[this.theirB58Id] = this | ||
this.switch.connection.add(this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this no longer added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now controlled by the dialer queue. |
||
|
||
this.muxer.once('close', () => { | ||
this.close() | ||
|
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 was deleted.
Oops, something went wrong.
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,72 @@ | ||
'use strict' | ||
|
||
const DialerQueue = require('./queue') | ||
const getPeerInfo = require('../get-peer-info') | ||
|
||
module.exports = function (_switch) { | ||
const dialerQueue = new DialerQueue(_switch) | ||
|
||
_switch.state.on('STOPPING:enter', abort) | ||
|
||
/** | ||
* @param {object} options | ||
* @param {PeerInfo} options.peerInfo | ||
* @param {string} options.protocol | ||
* @param {boolean} options.useFSM If `callback` should return a ConnectionFSM | ||
* @param {function(Error, Connection)} options.callback | ||
jacobheun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns {void} | ||
*/ | ||
function _dial ({ peerInfo, protocol, useFSM, callback }) { | ||
if (typeof protocol === 'function') { | ||
callback = protocol | ||
protocol = null | ||
} | ||
|
||
try { | ||
peerInfo = getPeerInfo(peerInfo, _switch._peerBook) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
|
||
// Add it to the queue, it will automatically get executed | ||
dialerQueue.add({ peerInfo, protocol, useFSM, callback }) | ||
} | ||
|
||
/** | ||
* Aborts all dials that are queued. This should | ||
* only be used when the Switch is being stopped | ||
* | ||
* @param {function} callback | ||
*/ | ||
function abort (callback) { | ||
dialerQueue.abort() | ||
callback() | ||
} | ||
|
||
/** | ||
* Adds the dial request to the queue for the given `peerInfo` | ||
* @param {PeerInfo} peerInfo | ||
* @param {string} protocol | ||
* @param {function(Error, Connection)} callback | ||
*/ | ||
function dial (peerInfo, protocol, callback) { | ||
_dial({ peerInfo, protocol, useFSM: false, callback }) | ||
} | ||
|
||
/** | ||
* Behaves like dial, except it calls back with a ConnectionFSM | ||
* | ||
* @param {PeerInfo} peerInfo | ||
* @param {string} protocol | ||
* @param {function(Error, ConnectionFSM)} callback | ||
*/ | ||
function dialFSM (peerInfo, protocol, callback) { | ||
_dial({ peerInfo, protocol, useFSM: true, callback }) | ||
} | ||
|
||
return { | ||
dial, | ||
dialFSM, | ||
abort | ||
} | ||
} |
Oops, something went wrong.
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.