Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: pass duplex to stream-to-ma-conn not stream (#33)
Browse files Browse the repository at this point in the history
Stream is a (possibly) multiplexed stream which comes later in the flow.  stream-to-ma-conn takes the low-level byte stream.

Also removes some redundant comments.
  • Loading branch information
achingbrain authored Mar 2, 2022
1 parent 9b22f46 commit ebc5c60
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"abortable-iterator": "^4.0.2",
"err-code": "^3.0.1",
"is-loopback-addr": "^2.0.1",
"it-stream-types": "^1.0.4",
"private-ip": "^2.1.1"
},
"devDependencies": {
Expand Down
10 changes: 0 additions & 10 deletions src/address-sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ interface Address {
isCertified: boolean
}

/**
* @typedef {Object} Address
* @property {Multiaddr} multiaddr peer multiaddr.
* @property {boolean} isCertified obtained from a signed peer record.
*/

/**
* Compare function for array.sort().
* This sort aims to move the private adresses to the end of the array.
* In case of equality, a certified address will come first.
*
* @param {Address} a
* @param {Address} b
* @returns {number}
*/
function addressesPublicFirstCompareFunction (a: Address, b: Address) {
const isAPrivate = isPrivate(a.multiaddr)
Expand Down
11 changes: 2 additions & 9 deletions src/stream-to-ma-conn.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { abortableSource } from 'abortable-iterator'
import { logger } from '@libp2p/logger'
import type { Stream } from '@libp2p/interfaces/connection'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
import type { Duplex } from 'it-stream-types'

const log = logger('libp2p:stream:converter')

/**
* @typedef {Object} Timeline
* @property {number} open -
* @property {number} [upgraded] - .
* @property {number} [close]
*/

export interface Timeline {
/**
* Connection opening timestamp
Expand All @@ -36,7 +29,7 @@ interface StreamOptions {
}

interface StreamProperties {
stream: Stream
stream: Duplex<Uint8Array>
remoteAddr: Multiaddr
localAddr: Multiaddr
}
Expand Down

0 comments on commit ebc5c60

Please sign in to comment.