mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
chore: address other review comments
This commit is contained in:
parent
9966c6ceb2
commit
aa98bc2f0e
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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)
|
||||||
|
@ -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} */
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user