Skip to content

Commit

Permalink
chore: update record, transport and stream muxer per latest interface…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
vasco-santos committed Dec 3, 2020
1 parent 32dd055 commit 6a56dac
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master
pull_request:
branches:
- '**'
- master

jobs:
check:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -35,33 +35,33 @@ 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
runs-on: ubuntu-latest
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
- 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
- run: npx xvfb-maybe 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 xvfb-maybe aegir test -t electron-renderer --bail
2 changes: 1 addition & 1 deletion src/record/envelope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions src/record/peer-record/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/transport-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
*/
Expand Down
13 changes: 7 additions & 6 deletions src/upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/record/envelope.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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')

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
}

Expand Down

0 comments on commit 6a56dac

Please sign in to comment.