Skip to content

Commit

Permalink
chore: update aegir and jsdocs for eslint changes (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Oct 6, 2020
1 parent bb59b51 commit 96df4b7
Show file tree
Hide file tree
Showing 43 changed files with 425 additions and 263 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"abortable-iterator": "^3.0.0",
"aegir": "^26.0.0",
"aegir": "^27.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bytes": "^0.1.2",
Expand Down
17 changes: 10 additions & 7 deletions src/address-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const multiaddr = require('multiaddr')
*/
class AddressManager {
/**
* @constructor
* @class
* @param {object} [options]
* @param {Array<string>} [options.listen = []] list of multiaddrs string representation to listen.
* @param {Array<string>} [options.announce = []] list of multiaddrs string representation to announce.
* @param {Array<string>} [options.noAnnounce = []] list of multiaddrs string representation to not announce.
* @param {Array<string>} [options.listen = []] - list of multiaddrs string representation to listen.
* @param {Array<string>} [options.announce = []] - list of multiaddrs string representation to announce.
* @param {Array<string>} [options.noAnnounce = []] - list of multiaddrs string representation to not announce.
*/
constructor ({ listen = [], announce = [], noAnnounce = [] } = {}) {
this.listen = new Set(listen)
Expand All @@ -29,23 +29,26 @@ class AddressManager {

/**
* Get peer listen multiaddrs.
* @return {Array<Multiaddr>}
*
* @returns {Array<Multiaddr>}
*/
getListenAddrs () {
return Array.from(this.listen).map((a) => multiaddr(a))
}

/**
* Get peer announcing multiaddrs.
* @return {Array<Multiaddr>}
*
* @returns {Array<Multiaddr>}
*/
getAnnounceAddrs () {
return Array.from(this.announce).map((a) => multiaddr(a))
}

/**
* Get peer noAnnouncing multiaddrs.
* @return {Array<Multiaddr>}
*
* @returns {Array<Multiaddr>}
*/
getNoAnnounceAddrs () {
return Array.from(this.noAnnounce).map((a) => multiaddr(a))
Expand Down
8 changes: 6 additions & 2 deletions src/circuit/circuit/hop.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ module.exports.handleHop = async function handleHop ({
* peer. A new, virtual, connection will be created between the two via the relay.
*
* @param {object} options
* @param {Connection} options.connection Connection to the relay
* @param {Connection} options.connection - Connection to the relay
* @param {*} options.request
* @param {Circuit} options.circuit
* @returns {Promise<Connection>}
*/
module.exports.hop = async function hop ({
Expand All @@ -119,6 +118,11 @@ module.exports.hop = async function hop ({

/**
* Creates an unencoded CAN_HOP response based on the Circuits configuration
*
* @param {Object} options
* @param {Connection} options.connection
* @param {StreamHandler} options.streamHandler
* @param {Circuit} options.circuit
* @private
*/
module.exports.handleCanHop = function handleCanHop ({
Expand Down
5 changes: 3 additions & 2 deletions src/circuit/circuit/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log.error = debug('libp2p:circuit:stop:error')
* @private
* @param {*} options
* @param {Connection} options.connection
* @param {*} options.request The CircuitRelay protobuf request (unencoded)
* @param {*} options.request - The CircuitRelay protobuf request (unencoded)
* @param {StreamHandler} options.streamHandler
* @returns {Promise<*>} Resolves a duplex iterable
*/
Expand All @@ -42,10 +42,11 @@ module.exports.handleStop = function handleStop ({

/**
* Creates a STOP request
*
* @private
* @param {*} options
* @param {Connection} options.connection
* @param {*} options.request The CircuitRelay protobuf request (unencoded)
* @param {*} options.request - The CircuitRelay protobuf request (unencoded)
* @returns {Promise<*>} Resolves a duplex iterable
*/
module.exports.stop = async function stop ({
Expand Down
7 changes: 4 additions & 3 deletions src/circuit/circuit/stream-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StreamHandler {
*
* @param {object} options
* @param {*} options.stream - A duplex iterable
* @param {Number} options.maxLength - max bytes length of message
* @param {number} options.maxLength - max bytes length of message
*/
constructor ({ stream, maxLength = 4096 }) {
this.stream = stream
Expand All @@ -25,6 +25,7 @@ class StreamHandler {

/**
* Read and decode message
*
* @async
* @returns {void}
*/
Expand All @@ -44,7 +45,7 @@ class StreamHandler {
/**
* Encode and write array of buffers
*
* @param {*} msg An unencoded CircuitRelay protobuf message
* @param {*} msg - An unencoded CircuitRelay protobuf message
*/
write (msg) {
log('write message type %s', msg.type)
Expand All @@ -54,7 +55,7 @@ class StreamHandler {
/**
* Return the handshake rest stream and invalidate handler
*
* @return {*} A duplex iterable
* @returns {*} A duplex iterable
*/
rest () {
this.shake.rest()
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/circuit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function writeResponse (streamHandler, status) {
/**
* Validate incomming HOP/STOP message
*
* @param {*} msg A CircuitRelay unencoded protobuf message
* @param {*} msg - A CircuitRelay unencoded protobuf message
* @param {StreamHandler} streamHandler
*/
function validateAddrs (msg, streamHandler) {
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Circuit {
/**
* Creates an instance of Circuit.
*
* @constructor
* @class
* @param {object} options
* @param {Libp2p} options.libp2p
* @param {Upgrader} options.upgrader
Expand Down Expand Up @@ -152,7 +152,7 @@ class Circuit {
*
* @param {any} options
* @param {Function} handler
* @return {listener}
* @returns {listener}
*/
createListener (options, handler) {
if (typeof options === 'function') {
Expand Down
18 changes: 9 additions & 9 deletions src/circuit/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = (circuit) => {
* Add swarm handler and listen for incoming connections
*
* @param {Multiaddr} addr
* @return {void}
* @returns {void}
*/
listener.listen = async (addr) => {
const addrString = String(addr).split('/p2p-circuit').find(a => a !== '')
Expand All @@ -34,7 +34,7 @@ module.exports = (circuit) => {
/**
* TODO: Remove the peers from our topology
*
* @return {void}
* @returns {void}
*/
listener.close = () => {}

Expand All @@ -44,15 +44,15 @@ module.exports = (circuit) => {
* NOTE: This method will grab the peers multiaddrs and expand them such that:
*
* a) If it's an existing /p2p-circuit address for a specific relay i.e.
* `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit` this method will expand the
* address to `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer` where
* `QmPeer` is this peers id
* `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit` this method will expand the
* address to `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer` where
* `QmPeer` is this peers id
* b) If it's not a /p2p-circuit address, it will encapsulate the address as a /p2p-circuit
* addr, such when dialing over a relay with this address, it will create the circuit using
* the encapsulated transport address. This is useful when for example, a peer should only
* be dialed over TCP rather than any other transport
* addr, such when dialing over a relay with this address, it will create the circuit using
* the encapsulated transport address. This is useful when for example, a peer should only
* be dialed over TCP rather than any other transport
*
* @return {Multiaddr[]}
* @returns {Multiaddr[]}
*/
listener.getAddrs = () => {
const addrs = []
Expand Down
47 changes: 31 additions & 16 deletions src/connection-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ const defaultOptions = {

/**
* Responsible for managing known connections.
*
* @fires ConnectionManager#peer:connect Emitted when a new peer is connected.
* @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected.
*/
class ConnectionManager extends EventEmitter {
/**
* @constructor
* @class
* @param {Libp2p} libp2p
* @param {object} options
* @param {Number} options.maxConnections The maximum number of connections allowed. Default=Infinity
* @param {Number} options.minConnections The minimum number of connections to avoid pruning. Default=0
* @param {Number} options.maxData The max data (in and out), per average interval to allow. Default=Infinity
* @param {Number} options.maxSentData The max outgoing data, per average interval to allow. Default=Infinity
* @param {Number} options.maxReceivedData The max incoming data, per average interval to allow.. Default=Infinity
* @param {Number} options.maxEventLoopDelay The upper limit the event loop can take to run. Default=Infinity
* @param {Number} options.pollInterval How often, in milliseconds, metrics and latency should be checked. Default=2000
* @param {Number} options.movingAverageInterval How often, in milliseconds, to compute averages. Default=60000
* @param {Number} options.defaultPeerValue The value of the peer. Default=1
* @param {boolean} options.autoDial Should preemptively guarantee connections are above the low watermark. Default=true
* @param {Number} options.autoDialInterval How often, in milliseconds, it should preemptively guarantee connections are above the low watermark. Default=10000
* @param {number} options.maxConnections - The maximum number of connections allowed. Default=Infinity
* @param {number} options.minConnections - The minimum number of connections to avoid pruning. Default=0
* @param {number} options.maxData - The max data (in and out), per average interval to allow. Default=Infinity
* @param {number} options.maxSentData - The max outgoing data, per average interval to allow. Default=Infinity
* @param {number} options.maxReceivedData - The max incoming data, per average interval to allow.. Default=Infinity
* @param {number} options.maxEventLoopDelay - The upper limit the event loop can take to run. Default=Infinity
* @param {number} options.pollInterval - How often, in milliseconds, metrics and latency should be checked. Default=2000
* @param {number} options.movingAverageInterval - How often, in milliseconds, to compute averages. Default=60000
* @param {number} options.defaultPeerValue - The value of the peer. Default=1
* @param {boolean} options.autoDial - Should preemptively guarantee connections are above the low watermark. Default=true
* @param {number} options.autoDialInterval - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark. Default=10000
*/
constructor (libp2p, options) {
super()
Expand All @@ -69,12 +70,14 @@ class ConnectionManager extends EventEmitter {

/**
* Map of peer identifiers to their peer value for pruning connections.
*
* @type {Map<string, number>}
*/
this._peerValues = new Map()

/**
* Map of connections per peer
*
* @type {Map<string, Array<conn>>}
*/
this.connections = new Map()
Expand Down Expand Up @@ -119,6 +122,7 @@ class ConnectionManager extends EventEmitter {

/**
* Stops the Connection Manager
*
* @async
*/
async stop () {
Expand All @@ -133,6 +137,7 @@ class ConnectionManager extends EventEmitter {

/**
* Cleans up the connections
*
* @async
*/
async _close () {
Expand All @@ -151,8 +156,9 @@ class ConnectionManager extends EventEmitter {
/**
* Sets the value of the given peer. Peers with lower values
* will be disconnected first.
*
* @param {PeerId} peerId
* @param {number} value A number between 0 and 1
* @param {number} value - A number between 0 and 1
*/
setPeerValue (peerId, value) {
if (value < 0 || value > 1) {
Expand All @@ -167,6 +173,7 @@ class ConnectionManager extends EventEmitter {
/**
* Checks the libp2p metrics to determine if any values have exceeded
* the configured maximums.
*
* @private
*/
_checkMetrics () {
Expand All @@ -183,6 +190,7 @@ class ConnectionManager extends EventEmitter {

/**
* Tracks the incoming connection and check the connection limit
*
* @param {Connection} connection
*/
onConnect (connection) {
Expand All @@ -208,6 +216,7 @@ class ConnectionManager extends EventEmitter {

/**
* Removes the connection from tracking
*
* @param {Connection} connection
*/
onDisconnect (connection) {
Expand All @@ -226,6 +235,7 @@ class ConnectionManager extends EventEmitter {

/**
* Get a connection with a peer.
*
* @param {PeerId} peerId
* @returns {Connection}
*/
Expand All @@ -239,6 +249,7 @@ class ConnectionManager extends EventEmitter {

/**
* Get all open connections with a peer.
*
* @param {PeerId} peerId
* @returns {Array<Connection>}
*/
Expand All @@ -259,18 +270,20 @@ class ConnectionManager extends EventEmitter {

/**
* If the event loop is slow, maybe close a connection
*
* @private
* @param {*} summary The LatencyMonitor summary
* @param {*} summary - The LatencyMonitor summary
*/
_onLatencyMeasure (summary) {
this._checkMaxLimit('maxEventLoopDelay', summary.avgMs)
}

/**
* If the `value` of `name` has exceeded its limit, maybe close a connection
*
* @private
* @param {string} name The name of the field to check limits for
* @param {number} value The current value of the field
* @param {string} name - The name of the field to check limits for
* @param {number} value - The current value of the field
*/
_checkMaxLimit (name, value) {
const limit = this._options[name]
Expand All @@ -285,6 +298,7 @@ class ConnectionManager extends EventEmitter {
* Proactively tries to connect to known peers stored in the PeerStore.
* It will keep the number of connections below the upper limit and sort
* the peers to connect based on wether we know their keys and protocols.
*
* @async
* @private
*/
Expand Down Expand Up @@ -330,6 +344,7 @@ class ConnectionManager extends EventEmitter {
/**
* If we have more connections than our maximum, close a connection
* to the lowest valued peer.
*
* @private
*/
_maybeDisconnectOne () {
Expand Down
Loading

0 comments on commit 96df4b7

Please sign in to comment.