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/stream-muxer/types').MuxedStream} MuxedStream
* @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('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')<CircuitRequest>} */
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)

View File

@ -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} */

View File

@ -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