mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 21:22:33 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
96d4a118db | ||
|
d14c37d14b | ||
|
9340ec9d98 | ||
|
d9224d5409 | ||
|
edb8ca60e9 | ||
|
810642d8ff | ||
|
64a478d313 |
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||
node: [12, 14]
|
||||
node: [14, 15]
|
||||
fail-fast: true
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -1,3 +1,7 @@
|
||||
# [0.9.0](https://github.com/libp2p/js-interfaces/compare/v0.8.4...v0.9.0) (2021-04-07)
|
||||
|
||||
|
||||
|
||||
## [0.8.4](https://github.com/libp2p/js-interfaces/compare/v0.8.3...v0.8.4) (2021-03-22)
|
||||
|
||||
|
||||
|
38
package.json
38
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-interfaces",
|
||||
"version": "0.8.4",
|
||||
"version": "0.9.0",
|
||||
"description": "Interfaces for JS Libp2p",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@ -22,9 +22,9 @@
|
||||
"extends": "ipfs"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "aegir build --no-bundle",
|
||||
"lint": "aegir lint",
|
||||
"build": "aegir build",
|
||||
"prepare": "aegir build --no-bundle",
|
||||
"test": "aegir test",
|
||||
"test:node": "aegir test --target node",
|
||||
"test:browser": "aegir test --target browser",
|
||||
@ -47,39 +47,43 @@
|
||||
},
|
||||
"homepage": "https://github.com/libp2p/js-interfaces#readme",
|
||||
"dependencies": {
|
||||
"@types/bl": "^2.1.0",
|
||||
"@types/bl": "4.1.0",
|
||||
"abort-controller": "^3.0.0",
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai": "^4.3.4",
|
||||
"chai-checkmark": "^1.0.1",
|
||||
"debug": "^4.3.1",
|
||||
"delay": "^4.4.0",
|
||||
"delay": "^5.0.0",
|
||||
"detect-node": "^2.0.4",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"err-code": "^2.0.3",
|
||||
"err-code": "^3.0.1",
|
||||
"it-goodbye": "^2.0.2",
|
||||
"it-length-prefixed": "^3.1.0",
|
||||
"it-pair": "^1.0.0",
|
||||
"it-pipe": "^1.1.0",
|
||||
"it-pushable": "^1.4.0",
|
||||
"libp2p-crypto": "^0.19.0",
|
||||
"libp2p-tcp": "^0.15.0",
|
||||
"multiaddr": "^8.1.2",
|
||||
"multibase": "^3.1.1",
|
||||
"multihashes": "^3.1.1",
|
||||
"it-pushable": "^1.4.2",
|
||||
"libp2p-crypto": "fluencelabs/js-libp2p-crypto",
|
||||
"libp2p-tcp": "fluencelabs/js-libp2p-tcp",
|
||||
"multiaddr": "^9.0.1",
|
||||
"multibase": "^4.0.2",
|
||||
"multihashes": "^4.0.2",
|
||||
"p-defer": "^3.0.0",
|
||||
"p-limit": "^3.1.0",
|
||||
"p-wait-for": "^3.2.0",
|
||||
"peer-id": "^0.14.2",
|
||||
"peer-id": "fluencelabs/js-peer-id",
|
||||
"protons": "^2.0.0",
|
||||
"sinon": "^9.2.4",
|
||||
"sinon": "^10.0.0",
|
||||
"streaming-iterables": "^5.0.4",
|
||||
"uint8arrays": "^2.0.5"
|
||||
"uint8arrays": "^2.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^29.2.0",
|
||||
"@types/debug": "^4.1.5",
|
||||
"aegir": "^32.1.0",
|
||||
"cids": "^1.1.6",
|
||||
"events": "^3.3.0",
|
||||
"it-handshake": "^1.0.2",
|
||||
"rimraf": "^3.0.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"util": "^0.12.3"
|
||||
},
|
||||
"contributors": [
|
||||
"Alan Shaw <alan.shaw@protocol.ai>",
|
||||
|
@ -230,8 +230,17 @@ class Connection {
|
||||
|
||||
module.exports = Connection
|
||||
|
||||
/**
|
||||
* @param {multiaddr|undefined} localAddr
|
||||
* @param {PeerId} localPeer
|
||||
* @param {PeerId} remotePeer
|
||||
* @param {(protocols: string | string[]) => Promise<{ stream: import("../stream-muxer/types").MuxedStream; protocol: string; }>} newStream
|
||||
* @param {() => Promise<void>} close
|
||||
* @param {() => import("../stream-muxer/types").MuxedStream[]} getStreams
|
||||
* @param {{ direction: any; timeline: any; multiplexer?: string | undefined; encryption?: string | undefined; }} stat
|
||||
*/
|
||||
function validateArgs (localAddr, localPeer, remotePeer, newStream, close, getStreams, stat) {
|
||||
if (localAddr && !multiaddr.isMultiaddr(localAddr)) {
|
||||
if (localAddr && !multiaddr.Multiaddr.isMultiaddr(localAddr)) {
|
||||
throw errCode(new Error('localAddr must be an instance of multiaddr'), 'ERR_INVALID_PARAMETERS')
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
|
||||
'use strict'
|
||||
|
11
src/content-routing/types.d.ts
vendored
Normal file
11
src/content-routing/types.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
export = ContentRouting;
|
||||
|
||||
import PeerId from 'peer-id'
|
||||
import { Multiaddr } from 'multiaddr'
|
||||
import CID from 'cids'
|
||||
|
||||
declare class ContentRouting {
|
||||
constructor (options: Object);
|
||||
provide (cid: CID): Promise<void>;
|
||||
findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
@ -54,7 +55,7 @@ module.exports = (common) => {
|
||||
expect(PeerId.isPeerId(id)).to.eql(true)
|
||||
expect(multiaddrs).to.exist()
|
||||
|
||||
multiaddrs.forEach((m) => expect(multiaddr.isMultiaddr(m)).to.eql(true))
|
||||
multiaddrs.forEach((m) => expect(multiaddr.Multiaddr.isMultiaddr(m)).to.eql(true))
|
||||
|
||||
defer.resolve()
|
||||
})
|
||||
|
10
src/peer-discovery/types.d.ts
vendored
Normal file
10
src/peer-discovery/types.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
export = PeerDiscovery;
|
||||
|
||||
import events from 'events';
|
||||
|
||||
declare class PeerDiscovery extends events.EventEmitter {
|
||||
constructor (options: Object);
|
||||
start (): Promise<void>;
|
||||
stop (): Promise<void>;
|
||||
tag: string;
|
||||
}
|
10
src/peer-routing/types.d.ts
vendored
Normal file
10
src/peer-routing/types.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
export = PeerRouting;
|
||||
|
||||
import PeerId from 'peer-id'
|
||||
import { Multiaddr } from 'multiaddr'
|
||||
|
||||
declare class PeerRouting {
|
||||
constructor (options?: Object);
|
||||
findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>;
|
||||
getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>;
|
||||
}
|
@ -10,9 +10,7 @@ const { pipe } = require('it-pipe')
|
||||
|
||||
const MulticodecTopology = require('../topology/multicodec-topology')
|
||||
const { codes } = require('./errors')
|
||||
/**
|
||||
* @type {typeof import('./message')}
|
||||
*/
|
||||
|
||||
const message = require('./message')
|
||||
const PeerStreams = require('./peer-streams')
|
||||
const { SignaturePolicy } = require('./signature-policy')
|
||||
@ -29,9 +27,9 @@ const {
|
||||
* @typedef {import('bl')} BufferList
|
||||
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
|
||||
* @typedef {import('../connection/connection')} Connection
|
||||
* @typedef {import('./message').RPC} RPC
|
||||
* @typedef {import('./message').SubOpts} RPCSubOpts
|
||||
* @typedef {import('./message').Message} RPCMessage
|
||||
* @typedef {import('./message/types').RPC} RPC
|
||||
* @typedef {import('./message/types').SubOpts} RPCSubOpts
|
||||
* @typedef {import('./message/types').Message} RPCMessage
|
||||
* @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType
|
||||
*/
|
||||
|
||||
@ -44,6 +42,16 @@ const {
|
||||
* @property {Uint8Array} data
|
||||
* @property {Uint8Array} [signature]
|
||||
* @property {Uint8Array} [key]
|
||||
*
|
||||
* @typedef {Object} PubsubProperties
|
||||
* @property {string} debugName - log namespace
|
||||
* @property {Array<string>|string} multicodecs - protocol identificers to connect
|
||||
* @property {Libp2p} libp2p
|
||||
*
|
||||
* @typedef {Object} PubsubOptions
|
||||
* @property {SignaturePolicyType} [globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled
|
||||
* @property {boolean} [canRelayMessage = false] - if can relay messages not subscribed
|
||||
* @property {boolean} [emitSelf = false] - if publish should emit to self, if subscribed
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -52,13 +60,7 @@ const {
|
||||
*/
|
||||
class PubsubBaseProtocol extends EventEmitter {
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @param {string} props.debugName - log namespace
|
||||
* @param {Array<string>|string} props.multicodecs - protocol identificers to connect
|
||||
* @param {Libp2p} props.libp2p
|
||||
* @param {SignaturePolicyType} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled
|
||||
* @param {boolean} [props.canRelayMessage = false] - if can relay messages not subscribed
|
||||
* @param {boolean} [props.emitSelf = false] - if publish should emit to self, if subscribed
|
||||
* @param {PubsubProperties & PubsubOptions} props
|
||||
* @abstract
|
||||
*/
|
||||
constructor ({
|
||||
@ -83,8 +85,9 @@ class PubsubBaseProtocol extends EventEmitter {
|
||||
|
||||
super()
|
||||
|
||||
this.log = debug(debugName)
|
||||
this.log.err = debug(`${debugName}:error`)
|
||||
this.log = Object.assign(debug(debugName), {
|
||||
err: debug(`${debugName}:error`)
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {Array<string>}
|
||||
@ -122,7 +125,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
||||
|
||||
// validate signature policy
|
||||
if (!SignaturePolicy[globalSignaturePolicy]) {
|
||||
throw errcode(new Error('Invalid global signature policy'), codes.ERR_INVALID_SIGUATURE_POLICY)
|
||||
throw errcode(new Error('Invalid global signature policy'), codes.ERR_INVALID_SIGNATURE_POLICY)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -379,7 +382,9 @@ class PubsubBaseProtocol extends EventEmitter {
|
||||
|
||||
if (subs.length) {
|
||||
// update peer subscriptions
|
||||
subs.forEach((subOpt) => this._processRpcSubOpt(idB58Str, subOpt))
|
||||
subs.forEach((/** @type {RPCSubOpts} */ subOpt) => {
|
||||
this._processRpcSubOpt(idB58Str, subOpt)
|
||||
})
|
||||
this.emit('pubsub:subscription-change', peerStreams.id, subs)
|
||||
}
|
||||
|
||||
@ -389,8 +394,9 @@ class PubsubBaseProtocol extends EventEmitter {
|
||||
}
|
||||
|
||||
if (msgs.length) {
|
||||
msgs.forEach(message => {
|
||||
if (!(this.canRelayMessage || message.topicIDs.some((topic) => this.subscriptions.has(topic)))) {
|
||||
// @ts-ignore RPC message is modified
|
||||
msgs.forEach((message) => {
|
||||
if (!(this.canRelayMessage || message.topicIDs.some((/** @type {string} */ topic) => this.subscriptions.has(topic)))) {
|
||||
this.log('received message we didn\'t subscribe to. Dropping.')
|
||||
return
|
||||
}
|
||||
@ -589,7 +595,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
||||
for (const topic of message.topicIDs) {
|
||||
const validatorFn = this.topicValidators.get(topic)
|
||||
if (!validatorFn) {
|
||||
continue
|
||||
continue // eslint-disable-line
|
||||
}
|
||||
await validatorFn(topic, message)
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
// @ts-ignore protons not typed
|
||||
const protons = require('protons')
|
||||
|
||||
const rpcProto = protons(require('./rpc.proto.js'))
|
||||
const RPC = rpcProto.RPC
|
||||
const topicDescriptorProto = protons(require('./topic-descriptor.proto.js'))
|
||||
|
||||
/**
|
||||
* @module pubsub/message/index
|
||||
*/
|
||||
exports = module.exports
|
||||
exports.rpc = rpcProto
|
||||
exports.td = topicDescriptorProto
|
||||
exports.RPC = RPC
|
||||
exports.Message = RPC.Message
|
||||
exports.SubOpts = RPC.SubOpts
|
||||
module.exports = {
|
||||
rpc: rpcProto,
|
||||
td: topicDescriptorProto,
|
||||
RPC,
|
||||
Message: RPC.Message,
|
||||
SubOpts: RPC.SubOpts
|
||||
}
|
||||
|
5
src/pubsub/message/types.d.ts
vendored
Normal file
5
src/pubsub/message/types.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { RPC, Message, SubOpts } from './types'
|
||||
|
||||
export type RPC = RPC
|
||||
export type Message = Message
|
||||
export type SubOpts = SubOpts
|
@ -1,5 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const debug = require('debug')
|
||||
const log = Object.assign(debug('libp2p-pubsub:peer-streams'), {
|
||||
error: debug('libp2p-pubsub:peer-streams:err')
|
||||
})
|
||||
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
@ -10,10 +15,6 @@ const pushable = require('it-pushable')
|
||||
const { pipe } = require('it-pipe')
|
||||
const { source: abortable } = require('abortable-iterator')
|
||||
const AbortController = require('abort-controller').default
|
||||
const debug = require('debug')
|
||||
|
||||
const log = debug('libp2p-pubsub:peer-streams')
|
||||
log.error = debug('libp2p-pubsub:peer-streams:error')
|
||||
|
||||
/**
|
||||
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
|
||||
@ -168,7 +169,7 @@ class PeerStreams extends EventEmitter {
|
||||
this.outboundStream,
|
||||
lp.encode(),
|
||||
this._rawOutboundStream
|
||||
).catch(err => {
|
||||
).catch(/** @param {Error} err */ err => {
|
||||
log.error(err)
|
||||
})
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-nested-callbacks: ["error", 6] */
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-nested-callbacks: ["error", 6] */
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
|
@ -1,11 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
// @ts-ignore libp2p crypto has no types
|
||||
const randomBytes = require('libp2p-crypto/src/random-bytes')
|
||||
const uint8ArrayToString = require('uint8arrays/to-string')
|
||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||
const PeerId = require('peer-id')
|
||||
const multihash = require('multihashes')
|
||||
exports = module.exports
|
||||
|
||||
/**
|
||||
* Generatea random sequence number.
|
||||
@ -13,7 +13,7 @@ exports = module.exports
|
||||
* @returns {Uint8Array}
|
||||
* @private
|
||||
*/
|
||||
exports.randomSeqno = () => {
|
||||
const randomSeqno = () => {
|
||||
return randomBytes(8)
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ exports.randomSeqno = () => {
|
||||
* @returns {Uint8Array}
|
||||
* @private
|
||||
*/
|
||||
exports.msgId = (from, seqno) => {
|
||||
const msgId = (from, seqno) => {
|
||||
const fromBytes = PeerId.createFromB58String(from).id
|
||||
const msgId = new Uint8Array(fromBytes.length + seqno.length)
|
||||
msgId.set(fromBytes, 0)
|
||||
@ -40,22 +40,28 @@ exports.msgId = (from, seqno) => {
|
||||
* @returns {Uint8Array}
|
||||
* @private
|
||||
*/
|
||||
exports.noSignMsgId = (data) => multihash.encode(data, 'sha2-256')
|
||||
const noSignMsgId = (data) => multihash.encode(data, 'sha2-256')
|
||||
|
||||
/**
|
||||
* Check if any member of the first set is also a member
|
||||
* of the second set.
|
||||
*
|
||||
* @param {Set|Array} a
|
||||
* @param {Set|Array} b
|
||||
* @param {Set<number>|Array<number>} a
|
||||
* @param {Set<number>|Array<number>} b
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
exports.anyMatch = (a, b) => {
|
||||
const anyMatch = (a, b) => {
|
||||
let bHas
|
||||
if (Array.isArray(b)) {
|
||||
/**
|
||||
* @param {number} val
|
||||
*/
|
||||
bHas = (val) => b.indexOf(val) > -1
|
||||
} else {
|
||||
/**
|
||||
* @param {number} val
|
||||
*/
|
||||
bHas = (val) => b.has(val)
|
||||
}
|
||||
|
||||
@ -76,7 +82,7 @@ exports.anyMatch = (a, b) => {
|
||||
* @returns {T[]}
|
||||
* @private
|
||||
*/
|
||||
exports.ensureArray = (maybeArray) => {
|
||||
const ensureArray = (maybeArray) => {
|
||||
if (!Array.isArray(maybeArray)) {
|
||||
return [maybeArray]
|
||||
}
|
||||
@ -92,7 +98,7 @@ exports.ensureArray = (maybeArray) => {
|
||||
* @param {string} [peerId]
|
||||
* @returns {T & {from?: string, peerId?: string }}
|
||||
*/
|
||||
exports.normalizeInRpcMessage = (message, peerId) => {
|
||||
const normalizeInRpcMessage = (message, peerId) => {
|
||||
const m = Object.assign({}, message)
|
||||
if (message.from instanceof Uint8Array) {
|
||||
m.from = uint8ArrayToString(message.from, 'base58btc')
|
||||
@ -109,7 +115,7 @@ exports.normalizeInRpcMessage = (message, peerId) => {
|
||||
* @param {T} message
|
||||
* @returns {T & {from?: Uint8Array, data?: Uint8Array}}
|
||||
*/
|
||||
exports.normalizeOutRpcMessage = (message) => {
|
||||
const normalizeOutRpcMessage = (message) => {
|
||||
const m = Object.assign({}, message)
|
||||
if (typeof message.from === 'string') {
|
||||
m.from = uint8ArrayFromString(message.from, 'base58btc')
|
||||
@ -119,3 +125,13 @@ exports.normalizeOutRpcMessage = (message) => {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
randomSeqno,
|
||||
msgId,
|
||||
noSignMsgId,
|
||||
anyMatch,
|
||||
ensureArray,
|
||||
normalizeInRpcMessage,
|
||||
normalizeOutRpcMessage
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-nested-callbacks: ["error", 8] */
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -43,9 +43,9 @@ export interface MuxedStream extends AsyncIterable<Uint8Array | BufferList> {
|
||||
abort: () => void;
|
||||
reset: () => void;
|
||||
sink: Sink;
|
||||
source: () => AsyncIterable<Uint8Array | BufferList>;
|
||||
source: AsyncIterable<Uint8Array | BufferList>;
|
||||
timeline: MuxedTimeline;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export type Sink = (source: Uint8Array) => Promise<Uint8Array>;
|
||||
export type Sink = (source: Uint8Array) => Promise<void>;
|
@ -62,6 +62,9 @@ class Topology {
|
||||
return Boolean(other && other[topologySymbol])
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} registrar
|
||||
*/
|
||||
set registrar (registrar) { // eslint-disable-line
|
||||
this._registrar = registrar
|
||||
}
|
||||
|
@ -56,6 +56,9 @@ class MulticodecTopology extends Topology {
|
||||
return Boolean(other && other[multicodecTopologySymbol])
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} registrar
|
||||
*/
|
||||
set registrar (registrar) { // eslint-disable-line
|
||||
this._registrar = registrar
|
||||
this._registrar.peerStore.on('change:protocols', this._onProtocolChange)
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
|
||||
'use strict'
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck interface tests
|
||||
/* eslint max-nested-callbacks: ["error", 8] */
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
@ -1,5 +1,6 @@
|
||||
import BufferList from 'bl'
|
||||
import events from 'events'
|
||||
import Multiaddr from 'multiaddr'
|
||||
import { Multiaddr } from 'multiaddr'
|
||||
import Connection from '../connection/connection'
|
||||
import { Sink } from '../stream-muxer/types'
|
||||
|
||||
@ -62,7 +63,7 @@ export type MultiaddrConnectionTimeline = {
|
||||
|
||||
export type MultiaddrConnection = {
|
||||
sink: Sink;
|
||||
source: () => AsyncIterable<Uint8Array>;
|
||||
source: AsyncIterable<Uint8Array | BufferList>;
|
||||
close: (err?: Error) => Promise<void>;
|
||||
conn: unknown;
|
||||
remoteAddr: Multiaddr;
|
14
src/types.ts → src/types.d.ts
vendored
14
src/types.ts → src/types.d.ts
vendored
@ -3,13 +3,13 @@ export interface EventEmitterFactory {
|
||||
}
|
||||
|
||||
export interface EventEmitter {
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void);
|
||||
on(event: string | symbol, listener: (...args: any[]) => void);
|
||||
once(event: string | symbol, listener: (...args: any[]) => void);
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void);
|
||||
off(event: string | symbol, listener: (...args: any[]) => void);
|
||||
removeAllListeners(event?: string | symbol);
|
||||
setMaxListeners(n: number);
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
|
||||
on(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
|
||||
once(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
|
||||
off(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
|
||||
removeAllListeners(event?: string | symbol): EventEmitter;
|
||||
setMaxListeners(n: number): EventEmitter;
|
||||
getMaxListeners(): number;
|
||||
listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
|
||||
rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
|
@ -17,8 +17,8 @@ describe('compliance tests', () => {
|
||||
* @param {*} properties
|
||||
*/
|
||||
async setup (properties) {
|
||||
const localAddr = multiaddr('/ip4/127.0.0.1/tcp/8080')
|
||||
const remoteAddr = multiaddr('/ip4/127.0.0.1/tcp/8081')
|
||||
const localAddr = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8080')
|
||||
const remoteAddr = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8081')
|
||||
const [localPeer, remotePeer] = await Promise.all([
|
||||
PeerId.createFromJSON(peers[0]),
|
||||
PeerId.createFromJSON(peers[1])
|
||||
|
@ -41,7 +41,7 @@ class MockDiscovery extends EventEmitter {
|
||||
this._timer = setTimeout(() => {
|
||||
this.emit('peer', {
|
||||
id: peerId,
|
||||
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')]
|
||||
multiaddrs: [new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000')]
|
||||
})
|
||||
}, this.options.discoveryDelay || 1000)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user