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