diff --git a/package.json b/package.json index 34dcc4d2..3996c800 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "it-pipe": "^1.1.0", "it-protocol-buffers": "^0.2.0", "libp2p-crypto": "^0.18.0", - "libp2p-interfaces": "^0.7.2", + "libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/add-duplex-iterable-type-to-connection", "libp2p-utils": "^0.2.2", "mafmt": "^8.0.0", "merge-options": "^2.0.0", diff --git a/src/address-manager/index.js b/src/address-manager/index.js index 9a9bc0b0..d4811be7 100644 --- a/src/address-manager/index.js +++ b/src/address-manager/index.js @@ -6,10 +6,14 @@ log.error = debug('libp2p:addresses:error') const multiaddr = require('multiaddr') +/** + * @typedef {import('multiaddr')} Multiaddr + */ + /** * @typedef {Object} AddressManagerOptions - * @property {Array} [listen = []] - list of multiaddrs string representation to listen. - * @property {Array} [announce = []] - list of multiaddrs string representation to announce. + * @property {string[]} [listen = []] - list of multiaddrs string representation to listen. + * @property {string[]} [announce = []] - list of multiaddrs string representation to announce. */ class AddressManager { /** @@ -29,7 +33,7 @@ class AddressManager { /** * Get peer listen multiaddrs. * - * @returns {Array} + * @returns {Multiaddr[]} */ getListenAddrs () { return Array.from(this.listen).map((a) => multiaddr(a)) @@ -38,7 +42,7 @@ class AddressManager { /** * Get peer announcing multiaddrs. * - * @returns {Array} + * @returns {Multiaddr[]} */ getAnnounceAddrs () { return Array.from(this.announce).map((a) => multiaddr(a)) diff --git a/src/circuit/auto-relay.js b/src/circuit/auto-relay.js index 3740bc34..7cca1887 100644 --- a/src/circuit/auto-relay.js +++ b/src/circuit/auto-relay.js @@ -69,7 +69,7 @@ class AutoRelay { * * @param {Object} props * @param {PeerId} props.peerId - * @param {Array} props.protocols + * @param {string[]} props.protocols * @returns {Promise} */ async _onProtocolChange ({ peerId, protocols }) { @@ -182,7 +182,7 @@ class AutoRelay { * 2. Dial and try to listen on the peers we know that support hop but are not connected. * 3. Search the network. * - * @param {Array} [peersToIgnore] + * @param {string[]} [peersToIgnore] * @returns {Promise} */ async _listenOnAvailableHopRelays (peersToIgnore = []) { diff --git a/src/circuit/transport.js b/src/circuit/transport.js index cc798705..6ba27b2a 100644 --- a/src/circuit/transport.js +++ b/src/circuit/transport.js @@ -18,14 +18,19 @@ const { handleCanHop, handleHop, hop } = require('./circuit/hop') const { handleStop } = require('./circuit/stop') const StreamHandler = require('./circuit/stream-handler') +/** + * @typedef {import('multiaddr')} Multiaddr + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + */ + class Circuit { /** * Creates an instance of the Circuit Transport. * * @class * @param {object} options - * @param {Libp2p} options.libp2p - * @param {Upgrader} options.upgrader + * @param {import('../')} options.libp2p + * @param {import('../upgrader')} options.upgrader */ constructor ({ libp2p, upgrader }) { this._dialer = libp2p.dialer @@ -101,7 +106,7 @@ class Circuit { /** * Dial a peer over a relay * - * @param {multiaddr} ma - the multiaddr of the peer to dial + * @param {Multiaddr} ma - the multiaddr of the peer to dial * @param {Object} options - dial options * @param {AbortSignal} [options.signal] - An optional abort signal * @returns {Connection} - the connection @@ -176,8 +181,8 @@ class Circuit { /** * Filter check for all Multiaddrs that this transport can dial on * - * @param {Array} multiaddrs - * @returns {Array} + * @param {Multiaddr[]} multiaddrs + * @returns {Multiaddr[]} */ filter (multiaddrs) { multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs] diff --git a/src/connection-manager/index.js b/src/connection-manager/index.js index 388c9940..7b6ae5e4 100644 --- a/src/connection-manager/index.js +++ b/src/connection-manager/index.js @@ -51,7 +51,7 @@ const defaultOptions = { */ /** - * @extends {EventEmitter} + * @extends EventEmitter * * @fires ConnectionManager#peer:connect Emitted when a new peer is connected. * @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected. @@ -87,7 +87,7 @@ class ConnectionManager extends EventEmitter { /** * Map of connections per peer * - * @type {Map>} + * @type {Map} */ this.connections = new Map() @@ -168,6 +168,7 @@ class ConnectionManager extends EventEmitter { * * @param {PeerId} peerId * @param {number} value - A number between 0 and 1 + * @returns {void} */ setPeerValue (peerId, value) { if (value < 0 || value > 1) { @@ -201,6 +202,7 @@ class ConnectionManager extends EventEmitter { * Tracks the incoming connection and check the connection limit * * @param {Connection} connection + * @returns {void} */ onConnect (connection) { const peerId = connection.remotePeer @@ -227,6 +229,7 @@ class ConnectionManager extends EventEmitter { * Removes the connection from tracking * * @param {Connection} connection + * @returns {void} */ onDisconnect (connection) { const peerId = connection.remotePeer.toB58String() @@ -260,7 +263,7 @@ class ConnectionManager extends EventEmitter { * Get all open connections with a peer. * * @param {PeerId} peerId - * @returns {Array} + * @returns {Connection[]} */ getAll (peerId) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/content-routing.js b/src/content-routing.js index 4f49a43d..75131ba1 100644 --- a/src/content-routing.js +++ b/src/content-routing.js @@ -8,7 +8,13 @@ const pAny = require('p-any') /** * @typedef {import('peer-id')} PeerId - * @typedef {import('multiaddr')} multiaddr + * @typedef {import('multiaddr')} Multiaddr + */ + +/** + * @typedef {Object} GetData + * @property {PeerId} from + * @property {Uint8Array} val */ module.exports = (node) => { @@ -29,7 +35,7 @@ module.exports = (node) => { * @param {object} [options] * @param {number} [options.timeout] - How long the query should run * @param {number} [options.maxNumProviders] - maximum number of providers to find - * @returns {AsyncIterable<{ id: PeerId, multiaddrs: Array }>} + * @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} */ async * findProviders (key, options) { if (!routers.length) { @@ -91,7 +97,7 @@ module.exports = (node) => { * @param {Uint8Array} key * @param {Object} [options] - get options * @param {number} [options.timeout] - optional timeout (default: 60000) - * @returns {Promise<{from: PeerId, val: Uint8Array}>} + * @returns {Promise} */ async get (key, options) { // eslint-disable-line require-await if (!node.isStarted() || !dht.isStarted) { @@ -108,7 +114,7 @@ module.exports = (node) => { * @param {number} nVals * @param {Object} [options] - get options * @param {number} [options.timeout] - optional timeout (default: 60000) - * @returns {Promise>} + * @returns {Promise} */ async getMany (key, nVals, options) { // eslint-disable-line require-await if (!node.isStarted() || !dht.isStarted) { diff --git a/src/dialer/dial-request.js b/src/dialer/dial-request.js index 6caa8903..d91158ed 100644 --- a/src/dialer/dial-request.js +++ b/src/dialer/dial-request.js @@ -11,6 +11,7 @@ const pAny = require('p-any') /** * @typedef {import('./')} Dialer + * @typedef {import('multiaddr')} Multiaddr */ /** diff --git a/src/dialer/index.js b/src/dialer/index.js index c12926b2..18be09c1 100644 --- a/src/dialer/index.js +++ b/src/dialer/index.js @@ -20,6 +20,7 @@ const { } = require('../constants') /** + * @typedef {import('multiaddr')} Multiaddr * @typedef {import('peer-id')} PeerId * @typedef {import('../peer-store')} PeerStore * @typedef {import('../transport-manager')} TransportManager @@ -32,7 +33,7 @@ const { * @property {TransportManager} transportManager * * @typedef {Object} DialerOptions - * @param {(addresses: Array Array
} [options.addressSorter = publicAddressesFirst] - Sort the known addresses of a peer before trying to dial. + * @param {(addresses: Address[]) => Address[]} [options.addressSorter = publicAddressesFirst] - Sort the known addresses of a peer before trying to dial. * @property {number} [concurrency = MAX_PARALLEL_DIALS] - Number of max concurrent dials. * @property {number} [perPeerLimit = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer. * @property {number} [timeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take. @@ -40,7 +41,7 @@ const { * * @typedef DialTarget * @property {string} id - * @property {Array} addrs + * @property {Multiaddr[]} addrs * * @typedef PendingDial * @property {DialRequest} dialRequest @@ -96,7 +97,7 @@ class Dialer { * The dial to the first address that is successfully able to upgrade a connection * will be used. * - * @param {PeerId|multiaddr|string} peer - The peer to dial + * @param {PeerId|Multiaddr|string} peer - The peer to dial * @param {object} [options] * @param {AbortSignal} [options.signal] - An AbortController signal * @returns {Promise} @@ -131,7 +132,7 @@ class Dialer { * If a multiaddr is received it should be the first address attempted. * * @private - * @param {PeerId|multiaddr|string} peer - A PeerId or Multiaddr + * @param {PeerId|Multiaddr|string} peer - A PeerId or Multiaddr * @returns {Promise} */ async _createDialTarget (peer) { @@ -219,8 +220,8 @@ class Dialer { /** * Resolve multiaddr recursively. * - * @param {multiaddr} ma - * @returns {Promise>} + * @param {Multiaddr} ma + * @returns {Promise} */ async _resolve (ma) { // TODO: recursive logic should live in multiaddr once dns4/dns6 support is in place @@ -248,8 +249,8 @@ class Dialer { /** * Resolve a given multiaddr. If this fails, an empty array will be returned * - * @param {multiaddr} ma - * @returns {Promise>} + * @param {Multiaddr} ma + * @returns {Promise} */ async _resolveRecord (ma) { try { diff --git a/src/get-peer.js b/src/get-peer.js index 9ebd5356..29422334 100644 --- a/src/get-peer.js +++ b/src/get-peer.js @@ -8,7 +8,7 @@ const { codes } = require('./errors') /** * @typedef {import('peer-id')} PeerId - * @typedef {import('multiaddr')} multiaddr + * @typedef {import('multiaddr')} Multiaddr */ /** @@ -16,7 +16,7 @@ const { codes } = require('./errors') * If a multiaddr is received, the addressBook is updated. * * @param {PeerId|multiaddr|string} peer - * @returns {{ id: PeerId, multiaddrs: Array }} + * @returns {{ id: PeerId, multiaddrs: Multiaddr[] }} */ function getPeer (peer) { if (typeof peer === 'string') { diff --git a/src/identify/index.js b/src/identify/index.js index 871020da..7b1617e1 100644 --- a/src/identify/index.js +++ b/src/identify/index.js @@ -30,16 +30,15 @@ const { const { codes } = require('../errors') /** - * @typedef {import('../')} Libp2p * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection - * @typedef {import('../').DuplexIterable} DuplexIterable + * @typedef {import('libp2p-interfaces/src/connection/connection').DuplexIterableStream} DuplexIterableStream */ class IdentifyService { /** * @class * @param {Object} options - * @param {Libp2p} options.libp2p + * @param {import('../')} options.libp2p */ constructor ({ libp2p }) { this._libp2p = libp2p @@ -74,7 +73,7 @@ class IdentifyService { /** * Send an Identify Push update to the list of connections * - * @param {Array} connections + * @param {Connection[]} connections * @returns {Promise} */ async push (connections) { @@ -204,7 +203,7 @@ class IdentifyService { * * @param {Object} options * @param {string} options.protocol - * @param {DuplexIterable} options.stream + * @param {DuplexIterableStream} options.stream * @param {Connection} options.connection * @returns {Promise} */ @@ -225,7 +224,7 @@ class IdentifyService { * * @private * @param {Object} options - * @param {DuplexIterable} options.stream + * @param {DuplexIterableStream} options.stream * @param {Connection} options.connection */ async _handleIdentify ({ connection, stream }) { @@ -264,7 +263,7 @@ class IdentifyService { * * @private * @param {object} options - * @param {DuplexIterable} options.stream + * @param {DuplexIterableStream} options.stream * @param {Connection} options.connection */ async _handlePush ({ connection, stream }) { diff --git a/src/index.js b/src/index.js index 68b92f6c..eca2206f 100644 --- a/src/index.js +++ b/src/index.js @@ -34,6 +34,10 @@ const { multicodecs: IDENTIFY_PROTOCOLS } = require('./identify') +/** + * @typedef {import('multiaddr')} Multiaddr + */ + /** * @typedef {Object} PeerStoreOptions * @property {boolean} persistence @@ -55,7 +59,7 @@ const { * @property {Object} [transport] transport options indexed by transport key * * @typedef {Object} Libp2pOptions - * @property {Array} modules libp2p modules to use + * @property {Object[]} modules libp2p modules to use * @property {import('./address-manager').AddressManagerOptions} [addresses] * @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager] * @property {import('./dialer').DialerOptions} [dialer] @@ -399,7 +403,7 @@ class Libp2p extends EventEmitter { * by transports to listen with the announce addresses. * Duplicated addresses and noAnnounce addresses are filtered out. * - * @returns {Array} + * @returns {Multiaddr[]} */ get multiaddrs () { const announceAddrs = this.addressManager.getAnnounceAddrs() @@ -416,7 +420,7 @@ class Libp2p extends EventEmitter { /** * Disconnects all connections to the given `peer` * - * @param {PeerId|multiaddr|string} peer - the peer to close connections to + * @param {PeerId|Multiaddr|string} peer - the peer to close connections to * @returns {Promise} */ async hangUp (peer) { @@ -544,7 +548,7 @@ class Libp2p extends EventEmitter { * Known peers may be emitted. * * @private - * @param {{ id: PeerId, multiaddrs: Array, protocols: Array }} peer + * @param {{ id: PeerId, multiaddrs: Multiaddr[], protocols: string[] }} peer */ _onDiscoveryPeer (peer) { if (peer.id.toB58String() === this.peerId.toB58String()) { @@ -654,10 +658,4 @@ Libp2p.create = async function create (options = {}) { return new Libp2p(options) } -/** - * @typedef {Object} DuplexIterable - * @property {(source: AsyncIterator<*>) => Promise} sink - * @property {AsyncIterator<*>} source - */ - module.exports = Libp2p diff --git a/src/insecure/plaintext.js b/src/insecure/plaintext.js index 2a6a3a4b..0e9f8dd9 100644 --- a/src/insecure/plaintext.js +++ b/src/insecure/plaintext.js @@ -25,7 +25,7 @@ function lpEncodeExchange (exchange) { * * @param {PeerId} localId * @param {Connection} conn - * @param {PeerId} remoteId + * @param {PeerId} [remoteId] */ async function encrypt (localId, conn, remoteId) { const shake = handshake(conn) diff --git a/src/metrics/index.js b/src/metrics/index.js index 49827bde..3d9593ce 100644 --- a/src/metrics/index.js +++ b/src/metrics/index.js @@ -17,6 +17,10 @@ const directionToEvent = { out: 'dataSent' } +/** + * @typedef {import('peer-id')} PeerId + */ + /** * @typedef MetricsProperties * @property {ConnectionManager} connectionManager @@ -24,7 +28,7 @@ const directionToEvent = { * @typedef MetricsOptions * @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize] * @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout] - * @property {Array} [movingAverageIntervals = defaultOptions.movingAverageIntervals] + * @property {number[]} [movingAverageIntervals = defaultOptions.movingAverageIntervals] * @property {number} [maxOldPeersRetention = defaultOptions.maxOldPeersRetention] */ @@ -82,7 +86,7 @@ class Metrics { /** * Returns a list of `PeerId` strings currently being tracked * - * @returns {Array} + * @returns {string[]} */ get peers () { return Array.from(this._peerStats.keys()) @@ -103,7 +107,7 @@ class Metrics { /** * Returns a list of all protocol strings currently being tracked. * - * @returns {Array} + * @returns {string[]} */ get protocols () { return Array.from(this._protocolStats.keys()) @@ -182,6 +186,7 @@ class Metrics { * * @param {PeerId} placeholder - A peerId string * @param {PeerId} peerId + * @returns {void} */ updatePlaceholder (placeholder, peerId) { if (!this._running) return diff --git a/src/metrics/stats.js b/src/metrics/stats.js index 35177663..d2593762 100644 --- a/src/metrics/stats.js +++ b/src/metrics/stats.js @@ -8,7 +8,7 @@ const retimer = require('retimer') /** * A queue based manager for stat processing * - * @param {Array} initialCounters + * @param {string[]} initialCounters * @param {any} options */ class Stats extends EventEmitter { @@ -77,7 +77,7 @@ class Stats extends EventEmitter { /** * Returns a clone of the internal movingAverages * - * @returns {Array} + * @returns {MovingAverage[]} */ get movingAverages () { return Object.assign({}, this._movingAverages) @@ -229,7 +229,7 @@ class Stats extends EventEmitter { * will be updated or initialized if they don't already exist. * * @private - * @param {Array} op + * @param {{string, number}[]} op * @throws {InvalidNumber} * @returns {void} */ diff --git a/src/peer-routing.js b/src/peer-routing.js index c05fdebe..841a3279 100644 --- a/src/peer-routing.js +++ b/src/peer-routing.js @@ -16,10 +16,6 @@ const { * @typedef {import('peer-id')} PeerId * @typedef {import('multiaddr')} Multiaddr */ - -/** - * Responsible for managing the usage of the available Peer Routing modules. - */ class PeerRouting { /** * @class @@ -73,6 +69,7 @@ class PeerRouting { clearDelayedInterval(this._timeoutId) } +<<<<<<< HEAD /** * Iterates over all peer routers in series to find the given peer. * @@ -92,6 +89,20 @@ class PeerRouting { // If we don't have a result, we need to provide an error to keep trying if (!result || Object.keys(result).length === 0) { throw errCode(new Error('not found'), 'NOT_FOUND') +======= + return { + /** + * Iterates over all peer routers in series to find the given peer. + * + * @param {string} id - The id of the peer to find + * @param {object} [options] + * @param {number} [options.timeout] - How long the query should run + * @returns {Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>} + */ + findPeer: async (id, options) => { // eslint-disable-line require-await + if (!routers.length) { + throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE') +>>>>>>> chore: address review } return result diff --git a/src/peer-store/address-book.js b/src/peer-store/address-book.js index 3bd6995e..bbfc30c8 100644 --- a/src/peer-store/address-book.js +++ b/src/peer-store/address-book.js @@ -16,11 +16,15 @@ const { } = require('../errors') const Envelope = require('../record/envelope') +/** + * @typedef {import('multiaddr')} Multiaddr + */ + /** * Address object * * @typedef {Object} Address - * @property {multiaddr} multiaddr peer multiaddr. + * @property {Multiaddr} multiaddr peer multiaddr. * @property {boolean} isCertified obtained from a signed peer record. */ @@ -36,7 +40,7 @@ const Envelope = require('../record/envelope') * Entry object for the addressBook * * @typedef {Object} Entry - * @property {Array
} addresses peer Addresses. + * @property {Address[]} addresses peer Addresses. * @property {CertifiedRecord} record certified peer record. */ @@ -71,7 +75,7 @@ class AddressBook extends Book { /** * Map known peers to their known Address Entries. * - * @type {Map>} + * @type {Map} */ this.data = new Map() } @@ -172,7 +176,7 @@ class AddressBook extends Book { * * @override * @param {PeerId} peerId - * @param {Array} multiaddrs + * @param {Multiaddr[]} multiaddrs * @returns {AddressBook} */ set (peerId, multiaddrs) { @@ -222,7 +226,7 @@ class AddressBook extends Book { * If the peer is not known, it is set with the given addresses. * * @param {PeerId} peerId - * @param {Array} multiaddrs + * @param {Multiaddr[]} multiaddrs * @returns {AddressBook} */ add (peerId, multiaddrs) { @@ -271,7 +275,7 @@ class AddressBook extends Book { * * @override * @param {PeerId} peerId - * @returns {Array
|undefined} + * @returns {Address[]|undefined} */ get (peerId) { if (!PeerId.isPeerId(peerId)) { @@ -287,9 +291,9 @@ class AddressBook extends Book { * Transforms received multiaddrs into Address. * * @private - * @param {Array} multiaddrs + * @param {Multiaddr[]} multiaddrs * @param {boolean} [isCertified] - * @returns {Array
} + * @returns {Address[]} */ _toAddresses (multiaddrs, isCertified = false) { if (!multiaddrs) { @@ -320,8 +324,8 @@ class AddressBook extends Book { * Returns `undefined` if there are no known multiaddrs for the given peer. * * @param {PeerId} peerId - * @param {(addresses: Array Array
} [addressSorter] - * @returns {Array|undefined} + * @param {(addresses: Address[]) => Address[]} [addressSorter] + * @returns {Multiaddr[]|undefined} */ getMultiaddrsForPeer (peerId, addressSorter = (ms) => ms) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/peer-store/book.js b/src/peer-store/book.js index e1893ce9..cbfafdd6 100644 --- a/src/peer-store/book.js +++ b/src/peer-store/book.js @@ -13,12 +13,14 @@ class Book { /** * The Book is the skeleton for the PeerStore books. * + * @template T + * * @class * @param {Object} properties * @param {PeerStore} properties.peerStore - PeerStore instance. * @param {string} properties.eventName - Name of the event to emit by the PeerStore. * @param {string} properties.eventProperty - Name of the property to emit by the PeerStore. - * @param {(data: *) => Array<*>} [properties.eventTransformer] - Transformer function of the provided data for being emitted. + * @param {(data: T) => T[]} [properties.eventTransformer] - Transformer function of the provided data for being emitted. */ constructor ({ peerStore, eventName, eventProperty, eventTransformer = passthrough }) { this._ps = peerStore @@ -29,7 +31,7 @@ class Book { /** * Map known peers to their data. * - * @type {Map} + * @type {Map|Data} data + * @param {T[]|T} data */ set (peerId, data) { throw errcode(new Error('set must be implemented by the subclass'), 'ERR_NOT_IMPLEMENTED') @@ -49,7 +51,7 @@ class Book { * * @private * @param {PeerId} peerId - peerId of the data to store - * @param {*} data - data to store. + * @param {T} data - data to store. * @param {Object} [options] - storing options. * @param {boolean} [options.emit = true] - emit the provided data. * @returns {void} @@ -69,7 +71,7 @@ class Book { * * @private * @param {PeerId} peerId - * @param {*} data + * @param {T} data */ _emit (peerId, data) { this._ps.emit(this.eventName, { @@ -83,7 +85,7 @@ class Book { * Returns `undefined` if there is no available data for the given peer. * * @param {PeerId} peerId - * @returns {Array|undefined} + * @returns {T[]|undefined} */ get (peerId) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/peer-store/index.js b/src/peer-store/index.js index ab3f6327..3713d7d4 100644 --- a/src/peer-store/index.js +++ b/src/peer-store/index.js @@ -17,6 +17,10 @@ const { ERR_INVALID_PARAMETERS } = require('../errors') +/** + * @typedef {import('./address-book').Address} Address + */ + /** * @extends {EventEmitter} * @@ -32,9 +36,9 @@ class PeerStore extends EventEmitter { * * @typedef {Object} Peer * @property {PeerId} id peer's peer-id instance. - * @property {Array
} addresses peer's addresses containing its multiaddrs and metadata. - * @property {Array} protocols peer's supported protocols. - * @property {Map} metadata peer's metadata map. + * @property {Address[]} addresses peer's addresses containing its multiaddrs and metadata. + * @property {string[]} protocols peer's supported protocols. + * @property {Map} metadata peer's metadata map. */ /** diff --git a/src/peer-store/metadata-book.js b/src/peer-store/metadata-book.js index 7a8b794c..796c9ee8 100644 --- a/src/peer-store/metadata-book.js +++ b/src/peer-store/metadata-book.js @@ -53,7 +53,7 @@ class MetadataBook extends Book { * @param {PeerId} peerId * @param {string} key - metadata key * @param {Uint8Array} value - metadata value - * @returns {ProtoBook} + * @returns {MetadataBook} */ set (peerId, key, value) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/peer-store/proto-book.js b/src/peer-store/proto-book.js index 009d0ba8..60b9c503 100644 --- a/src/peer-store/proto-book.js +++ b/src/peer-store/proto-book.js @@ -52,7 +52,7 @@ class ProtoBook extends Book { * * @override * @param {PeerId} peerId - * @param {Array} protocols + * @param {string[]} protocols * @returns {ProtoBook} */ set (peerId, protocols) { @@ -90,7 +90,7 @@ class ProtoBook extends Book { * If the peer was not known before, it will be added. * * @param {PeerId} peerId - * @param {Array} protocols + * @param {string[]} protocols * @returns {ProtoBook} */ add (peerId, protocols) { @@ -125,7 +125,7 @@ class ProtoBook extends Book { * If the protocols did not exist before, nothing will be done. * * @param {PeerId} peerId - * @param {Array} protocols + * @param {string[]} protocols * @returns {ProtoBook} */ remove (peerId, protocols) { diff --git a/src/ping/index.js b/src/ping/index.js index 415f4000..5ad54021 100644 --- a/src/ping/index.js +++ b/src/ping/index.js @@ -14,7 +14,7 @@ const { PROTOCOL, PING_LENGTH } = require('./constants') /** * @typedef {import('../')} Libp2p - * @typedef {import('multiaddr')} multiaddr + * @typedef {import('multiaddr')} Multiaddr * @typedef {import('peer-id')} PeerId */ @@ -22,7 +22,7 @@ const { PROTOCOL, PING_LENGTH } = require('./constants') * Ping a given peer and wait for its response, getting the operation latency. * * @param {Libp2p} node - * @param {PeerId|multiaddr} peer + * @param {PeerId|Multiaddr} peer * @returns {Promise} */ async function ping (node, peer) { diff --git a/src/pnet/index.js b/src/pnet/index.js index d49e13df..d2b97b2c 100644 --- a/src/pnet/index.js +++ b/src/pnet/index.js @@ -21,7 +21,7 @@ log.error = debug('libp2p:pnet:err') /** * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection - * @typedef {import('../').DuplexIterable} DuplexIterable + * @typedef {import('libp2p-interfaces/src/connection/connection').DuplexIterableStream} DuplexIterableStream */ class Protector { @@ -44,7 +44,7 @@ class Protector { * created with. * * @param {Connection} connection - The connection to protect - * @returns {DuplexIterable} A protected duplex iterable + * @returns {DuplexIterableStream} A protected duplex iterable */ async protect (connection) { if (!connection) { diff --git a/src/pubsub-adapter.js b/src/pubsub-adapter.js index 1f42cc7d..4f2134fe 100644 --- a/src/pubsub-adapter.js +++ b/src/pubsub-adapter.js @@ -1,5 +1,9 @@ 'use strict' +/** + * @typedef {import('libp2p-interfaces/src/pubsub').InMessage} InMessage + */ + // Pubsub adapter to keep API with handlers while not removed. module.exports = (PubsubRouter, libp2p, options) => { class Pubsub extends PubsubRouter { diff --git a/src/record/peer-record/index.js b/src/record/peer-record/index.js index faeac81d..2fadc3b9 100644 --- a/src/record/peer-record/index.js +++ b/src/record/peer-record/index.js @@ -13,7 +13,7 @@ const { /** * @typedef {import('peer-id')} PeerId - * @typedef {import('multiaddr')} multiaddr + * @typedef {import('multiaddr')} Multiaddr */ /** @@ -27,7 +27,7 @@ class PeerRecord extends Record { * @class * @param {Object} params * @param {PeerId} params.peerId - * @param {Array} params.multiaddrs - addresses of the associated peer. + * @param {Multiaddr[]} params.multiaddrs - addresses of the associated peer. * @param {number} [params.seqNumber] - monotonically-increasing sequence counter that's used to order PeerRecords in time. */ constructor ({ peerId, multiaddrs = [], seqNumber = Date.now() }) { diff --git a/src/transport-manager.js b/src/transport-manager.js index f6c62d14..06ab69b7 100644 --- a/src/transport-manager.js +++ b/src/transport-manager.js @@ -10,7 +10,7 @@ log.error = debug('libp2p:transports:error') const { updateSelfPeerRecord } = require('./record/utils') /** - * @typedef {import('multiaddr')} multiaddr + * @typedef {import('multiaddr')} Multiaddr * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * * @typedef {Object} TransportManagerProperties @@ -90,7 +90,7 @@ class TransportManager { /** * Dials the given Multiaddr over it's supported transport * - * @param {multiaddr} ma + * @param {Multiaddr} ma * @param {*} options * @returns {Promise} */ @@ -111,7 +111,7 @@ class TransportManager { /** * Returns all Multiaddr's the listeners are using * - * @returns {Array} + * @returns {Multiaddr[]} */ getAddrs () { let addrs = [] @@ -135,7 +135,7 @@ class TransportManager { /** * Finds a transport that matches the given Multiaddr * - * @param {multiaddr} ma + * @param {Multiaddr} ma * @returns {Transport|null} */ transportForMultiaddr (ma) { @@ -150,7 +150,7 @@ class TransportManager { * Starts listeners for each listen Multiaddr. * * @async - * @param {Array} addrs - addresses to attempt to listen on + * @param {Multiaddr[]} addrs - addresses to attempt to listen on */ async listen (addrs) { if (!addrs || addrs.length === 0) {