mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-28 15:22:15 +00:00
chore: address review
This commit is contained in:
parent
0801fc3c0b
commit
5cb2025c2a
@ -27,12 +27,10 @@
|
|||||||
"test": "aegir test",
|
"test": "aegir test",
|
||||||
"test:node": "aegir test --target node",
|
"test:node": "aegir test --target node",
|
||||||
"test:browser": "aegir test --target browser",
|
"test:browser": "aegir test --target browser",
|
||||||
"test:types": "aegir ts -p check",
|
|
||||||
"prepublishOnly": "npm run generate:types",
|
"prepublishOnly": "npm run generate:types",
|
||||||
"release": "aegir release -t node -t browser",
|
"release": "aegir release -t node -t browser",
|
||||||
"release-minor": "aegir release --type minor -t node -t browser",
|
"release-minor": "aegir release --type minor -t node -t browser",
|
||||||
"release-major": "aegir release --type major -t node -t browser",
|
"release-major": "aegir release --type major -t node -t browser"
|
||||||
"remove:types": "rimraf './src/**/*.d.ts'"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -49,6 +47,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-interfaces#readme",
|
"homepage": "https://github.com/libp2p/js-interfaces#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/bl": "^2.1.0",
|
||||||
"abort-controller": "^3.0.0",
|
"abort-controller": "^3.0.0",
|
||||||
"abortable-iterator": "^3.0.0",
|
"abortable-iterator": "^3.0.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
@ -21,6 +21,17 @@ const {
|
|||||||
verifySignature
|
verifySignature
|
||||||
} = require('./message/sign')
|
} = require('./message/sign')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {any} Libp2p
|
||||||
|
* @typedef {import('peer-id')} PeerId
|
||||||
|
* @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('./signature-policy').SignaturePolicyType} SignaturePolicyType
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} InMessage
|
* @typedef {Object} InMessage
|
||||||
* @property {string} [from]
|
* @property {string} [from]
|
||||||
@ -30,9 +41,6 @@ const {
|
|||||||
* @property {Uint8Array} data
|
* @property {Uint8Array} data
|
||||||
* @property {Uint8Array} [signature]
|
* @property {Uint8Array} [signature]
|
||||||
* @property {Uint8Array} [key]
|
* @property {Uint8Array} [key]
|
||||||
*
|
|
||||||
* @typedef PeerId
|
|
||||||
* @type import('peer-id')
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -213,7 +221,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* On an inbound stream opened.
|
* On an inbound stream opened.
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {Object} props
|
* @param {Object} props
|
||||||
* @param {string} props.protocol
|
* @param {string} props.protocol
|
||||||
* @param {MuxedStream} props.stream
|
* @param {MuxedStream} props.stream
|
||||||
@ -231,7 +239,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Registrar notifies an established connection with pubsub protocol.
|
* Registrar notifies an established connection with pubsub protocol.
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {PeerId} peerId - remote peer-id
|
* @param {PeerId} peerId - remote peer-id
|
||||||
* @param {Connection} conn - connection to the peer
|
* @param {Connection} conn - connection to the peer
|
||||||
*/
|
*/
|
||||||
@ -254,7 +262,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Registrar notifies a closing connection with pubsub protocol.
|
* Registrar notifies a closing connection with pubsub protocol.
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {PeerId} peerId - peerId
|
* @param {PeerId} peerId - peerId
|
||||||
* @param {Error} [err] - error for connection end
|
* @param {Error} [err] - error for connection end
|
||||||
*/
|
*/
|
||||||
@ -268,7 +276,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Notifies the router that a peer has been connected
|
* Notifies the router that a peer has been connected
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {PeerId} peerId
|
* @param {PeerId} peerId
|
||||||
* @param {string} protocol
|
* @param {string} protocol
|
||||||
* @returns {PeerStreams}
|
* @returns {PeerStreams}
|
||||||
@ -299,7 +307,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Notifies the router that a peer has been disconnected.
|
* Notifies the router that a peer has been disconnected.
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {PeerId} peerId
|
* @param {PeerId} peerId
|
||||||
* @returns {PeerStreams | undefined}
|
* @returns {PeerStreams | undefined}
|
||||||
*/
|
*/
|
||||||
@ -341,7 +349,6 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
stream,
|
stream,
|
||||||
async (source) => {
|
async (source) => {
|
||||||
for await (const data of source) {
|
for await (const data of source) {
|
||||||
// @ts-ignore data slice from BufferList
|
|
||||||
const rpcBytes = data instanceof Uint8Array ? data : data.slice()
|
const rpcBytes = data instanceof Uint8Array ? data : data.slice()
|
||||||
const rpcMsg = this._decodeRpc(rpcBytes)
|
const rpcMsg = this._decodeRpc(rpcBytes)
|
||||||
|
|
||||||
@ -589,7 +596,7 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
* Normalizes the message and signs it, if signing is enabled.
|
* Normalizes the message and signs it, if signing is enabled.
|
||||||
* Should be used by the routers to create the message to send.
|
* Should be used by the routers to create the message to send.
|
||||||
*
|
*
|
||||||
* @private
|
* @protected
|
||||||
* @param {RPCMessage} message
|
* @param {RPCMessage} message
|
||||||
* @returns {Promise<RPCMessage>}
|
* @returns {Promise<RPCMessage>}
|
||||||
*/
|
*/
|
||||||
@ -728,17 +735,6 @@ class PubsubBaseProtocol extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {any} Libp2p
|
|
||||||
* @typedef {object} MuxedStream
|
|
||||||
* @type import('../stream-muxer/types').MuxedStream
|
|
||||||
* @typedef {import('../connection/connection')} Connection
|
|
||||||
* @typedef {import('./message').RPC} RPC
|
|
||||||
* @typedef {import('./message').SubOpts} RPCSubOpts
|
|
||||||
* @typedef {import('./message').Message} RPCMessage
|
|
||||||
* @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType
|
|
||||||
*/
|
|
||||||
|
|
||||||
PubsubBaseProtocol.message = message
|
PubsubBaseProtocol.message = message
|
||||||
PubsubBaseProtocol.utils = utils
|
PubsubBaseProtocol.utils = utils
|
||||||
PubsubBaseProtocol.SignaturePolicy = SignaturePolicy
|
PubsubBaseProtocol.SignaturePolicy = SignaturePolicy
|
||||||
|
@ -65,7 +65,10 @@ async function verifySignature (message) {
|
|||||||
*/
|
*/
|
||||||
async function messagePublicKey (message) {
|
async function messagePublicKey (message) {
|
||||||
// should be available in the from property of the message (peer id)
|
// should be available in the from property of the message (peer id)
|
||||||
// @ts-ignore - from type changed
|
if (!message.from) {
|
||||||
|
throw new Error('Could not get the public key from the originator id')
|
||||||
|
}
|
||||||
|
|
||||||
const from = PeerId.createFromCID(message.from)
|
const from = PeerId.createFromCID(message.from)
|
||||||
|
|
||||||
if (message.key) {
|
if (message.key) {
|
||||||
|
@ -16,18 +16,9 @@ const log = debug('libp2p-pubsub:peer-streams')
|
|||||||
log.error = debug('libp2p-pubsub:peer-streams:error')
|
log.error = debug('libp2p-pubsub:peer-streams:error')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback Sink
|
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
|
||||||
* @param {Uint8Array} source
|
* @typedef {import('peer-id')} PeerId
|
||||||
* @returns {Promise<Uint8Array>}
|
* @typedef {import('it-pushable').Pushable<Uint8Array>} PushableStream
|
||||||
*
|
|
||||||
* @typedef {object} MuxedStream
|
|
||||||
* @type import('../stream-muxer/types').MuxedStream
|
|
||||||
*
|
|
||||||
* @typedef PeerId
|
|
||||||
* @type import('peer-id')
|
|
||||||
*
|
|
||||||
* @typedef PushableStream
|
|
||||||
* @type import('it-pushable').Pushable<Uint8Array>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import BufferList from 'bl'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A libp2p stream muxer
|
* A libp2p stream muxer
|
||||||
*/
|
*/
|
||||||
@ -5,6 +7,7 @@ export interface Muxer {
|
|||||||
new (options: MuxerOptions): Muxer; // eslint-disable-line
|
new (options: MuxerOptions): Muxer; // eslint-disable-line
|
||||||
multicodec: string;
|
multicodec: string;
|
||||||
readonly streams: Array<MuxedStream>;
|
readonly streams: Array<MuxedStream>;
|
||||||
|
prototype: Muxer;
|
||||||
/**
|
/**
|
||||||
* Initiate a new stream with the given name. If no name is
|
* Initiate a new stream with the given name. If no name is
|
||||||
* provided, the id of th stream will be used.
|
* provided, the id of th stream will be used.
|
||||||
@ -33,15 +36,14 @@ export type MuxedTimeline = {
|
|||||||
close?: number;
|
close?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MuxedStream = {
|
export interface MuxedStream extends AsyncIterable<Uint8Array | BufferList> {
|
||||||
close: () => void;
|
close: () => void;
|
||||||
abort: () => void;
|
abort: () => void;
|
||||||
reset: () => void;
|
reset: () => void;
|
||||||
sink: Sink;
|
sink: Sink;
|
||||||
source: () => AsyncIterable<Uint8Array>;
|
source: () => AsyncIterable<Uint8Array | BufferList>;
|
||||||
timeline: MuxedTimeline;
|
timeline: MuxedTimeline;
|
||||||
id: string;
|
id: string;
|
||||||
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sink = (source: Uint8Array) => Promise<Uint8Array>;
|
export type Sink = (source: Uint8Array) => Promise<Uint8Array>;
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import events from 'events'
|
import events from 'events'
|
||||||
import Multiaddr from 'multiaddr'
|
import Multiaddr from 'multiaddr'
|
||||||
import Connection from '../connection/connection'
|
import Connection from '../connection/connection'
|
||||||
|
import { Sink } from '../stream-muxer/types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A libp2p transport is understood as something that offers a dial and listen interface to establish connections.
|
* A libp2p transport is understood as something that offers a dial and listen interface to establish connections.
|
||||||
*/
|
*/
|
||||||
export interface Transport {
|
export interface Transport {
|
||||||
new (upgrader: Upgrader, ...others: any): Transport; // eslint-disable-line
|
new (upgrader: Upgrader, ...others: any): Transport; // eslint-disable-line
|
||||||
|
prototype: Transport;
|
||||||
/**
|
/**
|
||||||
* Dial a given multiaddr.
|
* Dial a given multiaddr.
|
||||||
*/
|
*/
|
||||||
@ -65,5 +67,3 @@ export type MultiaddrConnection = {
|
|||||||
localAddr?: Multiaddr;
|
localAddr?: Multiaddr;
|
||||||
timeline: MultiaddrConnectionTimeline;
|
timeline: MultiaddrConnectionTimeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Sink = (source: Uint8Array) => Promise<Uint8Array>;
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user