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