export = PeerStreams; /** * @callback Sink * @param {Uint8Array} source * @returns {Promise} * * @typedef {object} DuplexIterableStream * @property {Sink} sink * @property {() AsyncIterator} source * * @typedef PeerId * @type import('peer-id') */ /** * Thin wrapper around a peer's inbound / outbound pubsub streams */ declare class PeerStreams { /** * @param {object} properties - properties of the PeerStreams. * @param {PeerId} properties.id * @param {string} properties.protocol */ constructor({ id, protocol }: { id: PeerId; protocol: string; }); /** * @type {import('peer-id')} */ id: import('peer-id'); /** * Established protocol * * @type {string} */ protocol: string; /** * The raw outbound stream, as retrieved from conn.newStream * * @private * @type {DuplexIterableStream} */ private _rawOutboundStream; /** * The raw inbound stream, as retrieved from the callback from libp2p.handle * * @private * @type {DuplexIterableStream} */ private _rawInboundStream; /** * An AbortController for controlled shutdown of the inbound stream * * @private * @type {typeof AbortController} */ private _inboundAbortController; /** * Write stream -- its preferable to use the write method * * @type {import('it-pushable').Pushable>} */ outboundStream: import('it-pushable').Pushable; /** * Read stream * * @type {DuplexIterableStream} */ inboundStream: DuplexIterableStream; /** * Do we have a connection to read from? * * @type {boolean} */ get isReadable(): boolean; /** * Do we have a connection to write on? * * @type {boolean} */ get isWritable(): boolean; /** * Send a message to this peer. * Throws if there is no `stream` to write to available. * * @param {Uint8Array} data * @returns {void} */ write(data: Uint8Array): void; /** * Attach a raw inbound stream and setup a read stream * * @param {DuplexIterableStream} stream * @returns {void} */ attachInboundStream(stream: DuplexIterableStream): void; /** * Attach a raw outbound stream and setup a write stream * * @param {Stream} stream * @returns {Promise} */ attachOutboundStream(stream: any): Promise; /** * Closes the open connection to peer * * @returns {void} */ close(): void; } declare namespace PeerStreams { export { Sink, DuplexIterableStream, PeerId }; } type DuplexIterableStream = { sink: Sink; source: () => AsyncIterator; }; type PeerId = import("peer-id"); type Sink = (source: Uint8Array) => Promise;