mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-29 00:41:34 +00:00
chore: update record, transport and stream muxer per latest interface changes
This commit is contained in:
26
.github/workflows/main.yml
vendored
26
.github/workflows/main.yml
vendored
@ -14,9 +14,9 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- run: yarn lint
|
||||
# - uses: gozala/typescript-error-reporter-action@v1.0.4
|
||||
- run: yarn build
|
||||
- uses: gozala/typescript-error-reporter-action@v1.0.4
|
||||
- run: yarn aegir dep-check -- -i aegir
|
||||
- run: yarn aegir dep-check
|
||||
- uses: ipfs/aegir/actions/bundle-size@master
|
||||
name: size
|
||||
with:
|
||||
@ -26,7 +26,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||
node: [12, 14]
|
||||
fail-fast: true
|
||||
steps:
|
||||
@ -35,7 +35,7 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- run: yarn
|
||||
- run: npx nyc --reporter=lcov npm run test:node -- --bail
|
||||
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
|
||||
- uses: codecov/codecov-action@v1
|
||||
test-chrome:
|
||||
needs: check
|
||||
@ -43,25 +43,11 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- run: yarn aegir test -t browser -t webworker
|
||||
- run: npx aegir test -t browser -t webworker --bail
|
||||
test-firefox:
|
||||
needs: check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- run: yarn aegir test -t browser -t webworker -- --browsers FirefoxHeadless
|
||||
test-electron-main:
|
||||
needs: check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- run: npx xvfb-maybe yarn aegir test -t electron-main --bail
|
||||
test-electron-renderer:
|
||||
needs: check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- run: npx xvfb-maybe yarn aegir test -t electron-renderer --bail
|
||||
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
|
@ -12,7 +12,7 @@ const { codes } = require('../../errors')
|
||||
const Protobuf = require('./envelope.proto')
|
||||
|
||||
/**
|
||||
* @typedef {import('libp2p-interfaces/src/record')} Record
|
||||
* @typedef {import('libp2p-interfaces/src/record/types').Record} Record
|
||||
*/
|
||||
|
||||
class Envelope {
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
const multiaddr = require('multiaddr')
|
||||
const PeerId = require('peer-id')
|
||||
const Record = require('libp2p-interfaces/src/record')
|
||||
const arrayEquals = require('libp2p-utils/src/array-equals')
|
||||
|
||||
const Protobuf = require('./peer-record.proto')
|
||||
@ -14,12 +13,13 @@ const {
|
||||
/**
|
||||
* @typedef {import('peer-id')} PeerId
|
||||
* @typedef {import('multiaddr')} Multiaddr
|
||||
* @typedef {import('libp2p-interfaces/src/record/types').Record} Record
|
||||
*/
|
||||
|
||||
/**
|
||||
* @extends {Record}
|
||||
* @implements {Record}
|
||||
*/
|
||||
class PeerRecord extends Record {
|
||||
class PeerRecord {
|
||||
/**
|
||||
* The PeerRecord is used for distributing peer routing records across the network.
|
||||
* It contains the peer's reachable listen addresses.
|
||||
@ -31,7 +31,8 @@ class PeerRecord extends Record {
|
||||
* @param {number} [params.seqNumber] - monotonically-increasing sequence counter that's used to order PeerRecords in time.
|
||||
*/
|
||||
constructor ({ peerId, multiaddrs = [], seqNumber = Date.now() }) {
|
||||
super(ENVELOPE_DOMAIN_PEER_RECORD, ENVELOPE_PAYLOAD_TYPE_PEER_RECORD)
|
||||
this.domain = ENVELOPE_DOMAIN_PEER_RECORD
|
||||
this.codec = ENVELOPE_PAYLOAD_TYPE_PEER_RECORD
|
||||
|
||||
this.peerId = peerId
|
||||
this.multiaddrs = multiaddrs
|
||||
@ -66,7 +67,7 @@ class PeerRecord extends Record {
|
||||
* Returns true if `this` record equals the `other`.
|
||||
*
|
||||
* @param {PeerRecord} other
|
||||
* @returns {boolean}
|
||||
* @returns {other is Record}
|
||||
*/
|
||||
equals (other) {
|
||||
// Validate PeerId
|
||||
|
@ -14,6 +14,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
||||
/**
|
||||
* @typedef {import('multiaddr')} Multiaddr
|
||||
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
||||
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory
|
||||
* @typedef {import('libp2p-interfaces/src/transport/types').Transport} Transport
|
||||
*
|
||||
* @typedef {Object} TransportManagerProperties
|
||||
@ -32,6 +33,7 @@ class TransportManager {
|
||||
constructor ({ libp2p, upgrader, faultTolerance = FAULT_TOLERANCE.FATAL_ALL }) {
|
||||
this.libp2p = libp2p
|
||||
this.upgrader = upgrader
|
||||
/** @type {Map<string, Transport>} */
|
||||
this._transports = new Map()
|
||||
this._listeners = new Map()
|
||||
this.faultTolerance = faultTolerance
|
||||
@ -41,7 +43,7 @@ class TransportManager {
|
||||
* Adds a `Transport` to the manager
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {Transport} Transport
|
||||
* @param {TransportFactory} Transport
|
||||
* @param {*} transportOptions - Additional options to pass to the transport
|
||||
* @returns {void}
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ const { codes } = require('./errors')
|
||||
|
||||
/**
|
||||
* @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection
|
||||
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
|
||||
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').Muxer} Muxer
|
||||
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
|
||||
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
|
||||
@ -34,7 +35,7 @@ class Upgrader {
|
||||
* @param {PeerId} options.localPeer
|
||||
* @param {import('./metrics')} [options.metrics]
|
||||
* @param {Map<string, Crypto>} [options.cryptos]
|
||||
* @param {Map<string, Muxer>} [options.muxers]
|
||||
* @param {Map<string, MuxerFactory>} [options.muxers]
|
||||
* @param {(Connection) => void} options.onConnection - Called when a connection is upgraded
|
||||
* @param {(Connection) => void} options.onConnectionEnd
|
||||
*/
|
||||
@ -203,7 +204,7 @@ class Upgrader {
|
||||
* @param {string} options.direction - One of ['inbound', 'outbound']
|
||||
* @param {MultiaddrConnection} options.maConn - The transport layer connection
|
||||
* @param {MuxedStream | MultiaddrConnection} options.upgradedConn - A duplex connection returned from multiplexer and/or crypto selection
|
||||
* @param {Muxer} [options.Muxer] - The muxer to be used for muxing
|
||||
* @param {MuxerFactory} [options.Muxer] - The muxer to be used for muxing
|
||||
* @param {PeerId} options.remotePeer - The peer the connection is with
|
||||
* @returns {Connection}
|
||||
*/
|
||||
@ -405,8 +406,8 @@ class Upgrader {
|
||||
* @private
|
||||
* @async
|
||||
* @param {MultiaddrConnection} connection - A basic duplex connection to multiplex
|
||||
* @param {Map<string, Muxer>} muxers - The muxers to attempt multiplexing with
|
||||
* @returns {Promise<{ stream: MuxedStream, Muxer?: Muxer}>} A muxed connection
|
||||
* @param {Map<string, MuxerFactory>} muxers - The muxers to attempt multiplexing with
|
||||
* @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection
|
||||
*/
|
||||
async _multiplexOutbound (connection, muxers) {
|
||||
const dialer = new Multistream.Dialer(connection)
|
||||
@ -429,8 +430,8 @@ class Upgrader {
|
||||
* @private
|
||||
* @async
|
||||
* @param {MultiaddrConnection} connection - A basic duplex connection to multiplex
|
||||
* @param {Map<string, Muxer>} muxers - The muxers to attempt multiplexing with
|
||||
* @returns {Promise<{ stream: MuxedStream, Muxer?: Muxer}>} A muxed connection
|
||||
* @param {Map<string, MuxerFactory>} muxers - The muxers to attempt multiplexing with
|
||||
* @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection
|
||||
*/
|
||||
async _multiplexInbound (connection, muxers) {
|
||||
const listener = new Multistream.Listener(connection)
|
||||
|
@ -6,7 +6,6 @@ chai.use(require('chai-bytes'))
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
const uint8arrayEquals = require('uint8arrays/equals')
|
||||
const Envelope = require('../../src/record/envelope')
|
||||
const Record = require('libp2p-interfaces/src/record')
|
||||
const { codes: ErrorCodes } = require('../../src/errors')
|
||||
|
||||
const peerUtils = require('../utils/creators/peer')
|
||||
@ -14,9 +13,10 @@ const peerUtils = require('../utils/creators/peer')
|
||||
const domain = 'libp2p-testing'
|
||||
const codec = uint8arrayFromString('/libp2p/testdata')
|
||||
|
||||
class TestRecord extends Record {
|
||||
class TestRecord {
|
||||
constructor (data) {
|
||||
super(domain, codec)
|
||||
this.domain = domain
|
||||
this.codec = codec
|
||||
this.data = data
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user