From aa98bc2f0e03b6e1c03815e78be1f709a9fda6a6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 10 Dec 2020 11:50:22 +0100 Subject: [PATCH] chore: address other review comments --- src/circuit/circuit/stop.js | 2 +- src/circuit/transport.js | 4 +++- src/index.js | 3 --- src/record/peer-record/index.js | 8 ++++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/circuit/circuit/stop.js b/src/circuit/circuit/stop.js index 46a9f8af..111b811d 100644 --- a/src/circuit/circuit/stop.js +++ b/src/circuit/circuit/stop.js @@ -14,7 +14,7 @@ const { validateAddrs } = require('./utils') * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * @typedef {import('../../types').CircuitRequest} CircuitRequest - * @typedef {import('./stream-handler')} StreamHandlerT + * @typedef {import('./stream-handler')} StreamHandlerT */ /** diff --git a/src/circuit/transport.js b/src/circuit/transport.js index 650bb97d..fc2ddad4 100644 --- a/src/circuit/transport.js +++ b/src/circuit/transport.js @@ -24,6 +24,7 @@ const transportSymbol = Symbol.for('@libp2p/js-libp2p-circuit/circuit') * @typedef {import('multiaddr')} Multiaddr * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('../types').CircuitRequest} CircuitRequest */ class Circuit { @@ -53,6 +54,7 @@ class Circuit { * @param {MuxedStream} props.stream */ async _onProtocol ({ connection, stream }) { + /** @type {import('./circuit/stream-handler')} */ const streamHandler = new StreamHandler({ stream }) const request = await streamHandler.read() @@ -101,7 +103,7 @@ class Circuit { remoteAddr, localAddr }) - const type = request.Type === CircuitPB.Type.HOP ? 'relay' : 'inbound' + const type = request.type === CircuitPB.Type.HOP ? 'relay' : 'inbound' log('new %s connection %s', type, maConn.remoteAddr) const conn = await this._upgrader.upgradeInbound(maConn) diff --git a/src/index.js b/src/index.js index 9ad8986c..c22b022d 100644 --- a/src/index.js +++ b/src/index.js @@ -95,9 +95,6 @@ class Libp2p extends EventEmitter { super() // validateConfig will ensure the config is correct, // and add default values where appropriate - /** - * @private - */ this._options = validateConfig(_options) /** @type {PeerId} */ diff --git a/src/record/peer-record/index.js b/src/record/peer-record/index.js index 334e717e..32d018ab 100644 --- a/src/record/peer-record/index.js +++ b/src/record/peer-record/index.js @@ -66,10 +66,14 @@ class PeerRecord { /** * Returns true if `this` record equals the `other`. * - * @param {PeerRecord} other - * @returns {other is Record} + * @param {unknown} other + * @returns {boolean} */ equals (other) { + if (!(other instanceof PeerRecord)) { + return false + } + // Validate PeerId if (!this.peerId.equals(other.peerId)) { return false