chore: address other review comments

This commit is contained in:
Vasco Santos 2020-12-10 11:50:22 +01:00
parent 9966c6ceb2
commit aa98bc2f0e
4 changed files with 10 additions and 7 deletions

View File

@ -14,7 +14,7 @@ const { validateAddrs } = require('./utils')
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('../../types').CircuitRequest} CircuitRequest * @typedef {import('../../types').CircuitRequest} CircuitRequest
* @typedef {import('./stream-handler')<Request>} StreamHandlerT * @typedef {import('./stream-handler')<CircuitRequest>} StreamHandlerT
*/ */
/** /**

View File

@ -24,6 +24,7 @@ const transportSymbol = Symbol.for('@libp2p/js-libp2p-circuit/circuit')
* @typedef {import('multiaddr')} Multiaddr * @typedef {import('multiaddr')} Multiaddr
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('../types').CircuitRequest} CircuitRequest
*/ */
class Circuit { class Circuit {
@ -53,6 +54,7 @@ class Circuit {
* @param {MuxedStream} props.stream * @param {MuxedStream} props.stream
*/ */
async _onProtocol ({ connection, stream }) { async _onProtocol ({ connection, stream }) {
/** @type {import('./circuit/stream-handler')<CircuitRequest>} */
const streamHandler = new StreamHandler({ stream }) const streamHandler = new StreamHandler({ stream })
const request = await streamHandler.read() const request = await streamHandler.read()
@ -101,7 +103,7 @@ class Circuit {
remoteAddr, remoteAddr,
localAddr 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) log('new %s connection %s', type, maConn.remoteAddr)
const conn = await this._upgrader.upgradeInbound(maConn) const conn = await this._upgrader.upgradeInbound(maConn)

View File

@ -95,9 +95,6 @@ class Libp2p extends EventEmitter {
super() super()
// validateConfig will ensure the config is correct, // validateConfig will ensure the config is correct,
// and add default values where appropriate // and add default values where appropriate
/**
* @private
*/
this._options = validateConfig(_options) this._options = validateConfig(_options)
/** @type {PeerId} */ /** @type {PeerId} */

View File

@ -66,10 +66,14 @@ class PeerRecord {
/** /**
* Returns true if `this` record equals the `other`. * Returns true if `this` record equals the `other`.
* *
* @param {PeerRecord} other * @param {unknown} other
* @returns {other is Record} * @returns {boolean}
*/ */
equals (other) { equals (other) {
if (!(other instanceof PeerRecord)) {
return false
}
// Validate PeerId // Validate PeerId
if (!this.peerId.equals(other.peerId)) { if (!this.peerId.equals(other.peerId)) {
return false return false