Skip to content

Commit 6a56dac

Browse files
committed
chore: update record, transport and stream muxer per latest interface changes
1 parent 32dd055 commit 6a56dac

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

.github/workflows/main.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- master
66
pull_request:
77
branches:
8-
- '**'
8+
- master
99

1010
jobs:
1111
check:
@@ -14,9 +14,9 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- run: yarn
1616
- run: yarn lint
17+
# - uses: gozala/[email protected]
1718
- run: yarn build
18-
- uses: gozala/[email protected]
19-
- run: yarn aegir dep-check -- -i aegir
19+
- run: yarn aegir dep-check
2020
- uses: ipfs/aegir/actions/bundle-size@master
2121
name: size
2222
with:
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ${{ matrix.os }}
2727
strategy:
2828
matrix:
29-
os: [ubuntu-latest, macos-latest]
29+
os: [windows-latest, ubuntu-latest, macos-latest]
3030
node: [12, 14]
3131
fail-fast: true
3232
steps:
@@ -35,33 +35,33 @@ jobs:
3535
with:
3636
node-version: ${{ matrix.node }}
3737
- run: yarn
38-
- run: npx nyc --reporter=lcov npm run test:node -- --bail
38+
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
3939
- uses: codecov/codecov-action@v1
4040
test-chrome:
4141
needs: check
4242
runs-on: ubuntu-latest
4343
steps:
4444
- uses: actions/checkout@v2
4545
- run: yarn
46-
- run: yarn aegir test -t browser -t webworker
46+
- run: npx aegir test -t browser -t webworker --bail
4747
test-firefox:
4848
needs: check
4949
runs-on: ubuntu-latest
5050
steps:
5151
- uses: actions/checkout@v2
5252
- run: yarn
53-
- run: yarn aegir test -t browser -t webworker -- --browsers FirefoxHeadless
53+
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
5454
test-electron-main:
5555
needs: check
5656
runs-on: ubuntu-latest
5757
steps:
5858
- uses: actions/checkout@v2
5959
- run: yarn
60-
- run: npx xvfb-maybe yarn aegir test -t electron-main --bail
60+
- run: npx xvfb-maybe aegir test -t electron-main --bail
6161
test-electron-renderer:
6262
needs: check
6363
runs-on: ubuntu-latest
6464
steps:
6565
- uses: actions/checkout@v2
6666
- run: yarn
67-
- run: npx xvfb-maybe yarn aegir test -t electron-renderer --bail
67+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

src/record/envelope/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { codes } = require('../../errors')
1212
const Protobuf = require('./envelope.proto')
1313

1414
/**
15-
* @typedef {import('libp2p-interfaces/src/record')} Record
15+
* @typedef {import('libp2p-interfaces/src/record/types').Record} Record
1616
*/
1717

1818
class Envelope {

src/record/peer-record/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const multiaddr = require('multiaddr')
44
const PeerId = require('peer-id')
5-
const Record = require('libp2p-interfaces/src/record')
65
const arrayEquals = require('libp2p-utils/src/array-equals')
76

87
const Protobuf = require('./peer-record.proto')
@@ -14,12 +13,13 @@ const {
1413
/**
1514
* @typedef {import('peer-id')} PeerId
1615
* @typedef {import('multiaddr')} Multiaddr
16+
* @typedef {import('libp2p-interfaces/src/record/types').Record} Record
1717
*/
1818

1919
/**
20-
* @extends {Record}
20+
* @implements {Record}
2121
*/
22-
class PeerRecord extends Record {
22+
class PeerRecord {
2323
/**
2424
* The PeerRecord is used for distributing peer routing records across the network.
2525
* It contains the peer's reachable listen addresses.
@@ -31,7 +31,8 @@ class PeerRecord extends Record {
3131
* @param {number} [params.seqNumber] - monotonically-increasing sequence counter that's used to order PeerRecords in time.
3232
*/
3333
constructor ({ peerId, multiaddrs = [], seqNumber = Date.now() }) {
34-
super(ENVELOPE_DOMAIN_PEER_RECORD, ENVELOPE_PAYLOAD_TYPE_PEER_RECORD)
34+
this.domain = ENVELOPE_DOMAIN_PEER_RECORD
35+
this.codec = ENVELOPE_PAYLOAD_TYPE_PEER_RECORD
3536

3637
this.peerId = peerId
3738
this.multiaddrs = multiaddrs
@@ -66,7 +67,7 @@ class PeerRecord extends Record {
6667
* Returns true if `this` record equals the `other`.
6768
*
6869
* @param {PeerRecord} other
69-
* @returns {boolean}
70+
* @returns {other is Record}
7071
*/
7172
equals (other) {
7273
// Validate PeerId

src/transport-manager.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
1414
/**
1515
* @typedef {import('multiaddr')} Multiaddr
1616
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
17+
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory
1718
* @typedef {import('libp2p-interfaces/src/transport/types').Transport} Transport
1819
*
1920
* @typedef {Object} TransportManagerProperties
@@ -32,6 +33,7 @@ class TransportManager {
3233
constructor ({ libp2p, upgrader, faultTolerance = FAULT_TOLERANCE.FATAL_ALL }) {
3334
this.libp2p = libp2p
3435
this.upgrader = upgrader
36+
/** @type {Map<string, Transport>} */
3537
this._transports = new Map()
3638
this._listeners = new Map()
3739
this.faultTolerance = faultTolerance
@@ -41,7 +43,7 @@ class TransportManager {
4143
* Adds a `Transport` to the manager
4244
*
4345
* @param {string} key
44-
* @param {Transport} Transport
46+
* @param {TransportFactory} Transport
4547
* @param {*} transportOptions - Additional options to pass to the transport
4648
* @returns {void}
4749
*/

src/upgrader.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { codes } = require('./errors')
1515

1616
/**
1717
* @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection
18+
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
1819
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').Muxer} Muxer
1920
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
2021
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
@@ -34,7 +35,7 @@ class Upgrader {
3435
* @param {PeerId} options.localPeer
3536
* @param {import('./metrics')} [options.metrics]
3637
* @param {Map<string, Crypto>} [options.cryptos]
37-
* @param {Map<string, Muxer>} [options.muxers]
38+
* @param {Map<string, MuxerFactory>} [options.muxers]
3839
* @param {(Connection) => void} options.onConnection - Called when a connection is upgraded
3940
* @param {(Connection) => void} options.onConnectionEnd
4041
*/
@@ -203,7 +204,7 @@ class Upgrader {
203204
* @param {string} options.direction - One of ['inbound', 'outbound']
204205
* @param {MultiaddrConnection} options.maConn - The transport layer connection
205206
* @param {MuxedStream | MultiaddrConnection} options.upgradedConn - A duplex connection returned from multiplexer and/or crypto selection
206-
* @param {Muxer} [options.Muxer] - The muxer to be used for muxing
207+
* @param {MuxerFactory} [options.Muxer] - The muxer to be used for muxing
207208
* @param {PeerId} options.remotePeer - The peer the connection is with
208209
* @returns {Connection}
209210
*/
@@ -405,8 +406,8 @@ class Upgrader {
405406
* @private
406407
* @async
407408
* @param {MultiaddrConnection} connection - A basic duplex connection to multiplex
408-
* @param {Map<string, Muxer>} muxers - The muxers to attempt multiplexing with
409-
* @returns {Promise<{ stream: MuxedStream, Muxer?: Muxer}>} A muxed connection
409+
* @param {Map<string, MuxerFactory>} muxers - The muxers to attempt multiplexing with
410+
* @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection
410411
*/
411412
async _multiplexOutbound (connection, muxers) {
412413
const dialer = new Multistream.Dialer(connection)
@@ -429,8 +430,8 @@ class Upgrader {
429430
* @private
430431
* @async
431432
* @param {MultiaddrConnection} connection - A basic duplex connection to multiplex
432-
* @param {Map<string, Muxer>} muxers - The muxers to attempt multiplexing with
433-
* @returns {Promise<{ stream: MuxedStream, Muxer?: Muxer}>} A muxed connection
433+
* @param {Map<string, MuxerFactory>} muxers - The muxers to attempt multiplexing with
434+
* @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection
434435
*/
435436
async _multiplexInbound (connection, muxers) {
436437
const listener = new Multistream.Listener(connection)

test/record/envelope.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ chai.use(require('chai-bytes'))
66
const uint8arrayFromString = require('uint8arrays/from-string')
77
const uint8arrayEquals = require('uint8arrays/equals')
88
const Envelope = require('../../src/record/envelope')
9-
const Record = require('libp2p-interfaces/src/record')
109
const { codes: ErrorCodes } = require('../../src/errors')
1110

1211
const peerUtils = require('../utils/creators/peer')
1312

1413
const domain = 'libp2p-testing'
1514
const codec = uint8arrayFromString('/libp2p/testdata')
1615

17-
class TestRecord extends Record {
16+
class TestRecord {
1817
constructor (data) {
19-
super(domain, codec)
18+
this.domain = domain
19+
this.codec = codec
2020
this.data = data
2121
}
2222

0 commit comments

Comments
 (0)