import { TypedEventEmitter } from '@libp2p/interface'; import { CID } from 'multiformats/cid'; import { BitswapMessage } from './pb/message.ts'; import type { WantOptions } from './bitswap.ts'; import type { Block } from './pb/message.ts'; import type { QueuedBitswapMessage } from './utils/bitswap-message.ts'; import type { BlockBrokerGetBlockProgressEvents } from '@helia/interface'; import type { Provider, Routing, RoutingFindProvidersProgressEvents } from '@helia/interface/routing'; import type { Libp2p, AbortOptions, Connection, PeerId, ComponentLogger, Metrics, Stream, OpenConnectionProgressEvents, NewStreamProgressEvents } from '@libp2p/interface'; import type { Multiaddr } from '@multiformats/multiaddr'; import type { ProgressEvent, ProgressOptions } from 'progress-events'; export interface BitswapProvider { /** * The type of provider */ type: 'bitswap'; /** * the CID the provider can supply the block for */ cid: CID; /** * The provider info */ provider: Provider; /** * Which routing subsystem found the provider */ routing: string; } export type BitswapNetworkProgressEvents = ProgressEvent<'bitswap:dial', PeerId | Multiaddr | Multiaddr[]> | OpenConnectionProgressEvents | NewStreamProgressEvents; export type BitswapNetworkWantProgressEvents = ProgressEvent<'bitswap:send-wantlist', PeerId> | ProgressEvent<'bitswap:send-wantlist:error', { peer: PeerId; error: Error; }> | ProgressEvent<'bitswap:find-providers', CID> | ProgressEvent<'bitswap:found-provider', BitswapProvider> | BitswapNetworkProgressEvents | RoutingFindProvidersProgressEvents | BlockBrokerGetBlockProgressEvents; export type BitswapNetworkNotifyProgressEvents = BitswapNetworkProgressEvents | ProgressEvent<'bitswap:send-block', PeerId>; export interface NetworkInit { maxInboundStreams?: number; maxOutboundStreams?: number; messageReceiveTimeout?: number; messageSendTimeout?: number; messageSendConcurrency?: number; protocols?: string[]; runOnLimitedConnections?: boolean; maxOutgoingMessageSize?: number; maxIncomingMessageSize?: number; } export interface NetworkComponents { routing: Routing; logger: ComponentLogger; libp2p: Libp2p; metrics?: Metrics; } export interface BitswapMessageEventDetail { /** * @deprecated access the peer via connection.remotePeer instead */ peer: PeerId; message: BitswapMessage; connection: Connection; } export interface NetworkEvents { 'bitswap:message': CustomEvent; 'peer:connected': CustomEvent; 'peer:disconnected': CustomEvent; } export declare class Network extends TypedEventEmitter { private readonly log; private readonly libp2p; private readonly routing; private readonly protocols; private running; private readonly maxInboundStreams; private readonly maxOutboundStreams; private readonly messageReceiveTimeout; private readonly messageSendTimeout; private registrarIds; private readonly metrics; private readonly sendQueue; private readonly runOnLimitedConnections; private readonly maxOutgoingMessageSize; private readonly maxIncomingMessageSize; constructor(components: NetworkComponents, init?: NetworkInit); start(): Promise; stop(): Promise; /** * Handles incoming bitswap messages */ _onStream(stream: Stream, connection: Connection): void; /** * Find bitswap providers for a given `cid`. */ findProviders(cid: CID, options?: AbortOptions & ProgressOptions): AsyncIterable; /** * Find the providers of a given `cid` and connect to them. */ findAndConnect(cid: CID, options?: WantOptions): Promise; /** * Connect to the specified peer and send the given message */ sendMessage(peerId: PeerId, message: QueuedBitswapMessage, options?: AbortOptions & ProgressOptions): Promise; /** * Connects to another peer */ connectTo(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions & ProgressOptions): Promise; _updateSentStats(blocks: Map): void; } //# sourceMappingURL=network.d.ts.map