import { TypedEventEmitter } from '@libp2p/interface'; import { CID } from 'multiformats/cid'; import { WantType } from './pb/message.ts'; import type { BitswapNotifyProgressEvents } from './index.ts'; import type { BitswapNetworkWantProgressEvents, Network } from './network.ts'; import type { HasherLoader } from '@helia/interface'; import type { ComponentLogger, PeerId, Startable, AbortOptions, Libp2p, TypedEventTarget, Metrics, Connection } from '@libp2p/interface'; import type { PeerMap } from '@libp2p/peer-collections'; import type { ProgressEventListener, ProgressOptions } from 'progress-events'; export interface WantListComponents { network: Network; logger: ComponentLogger; libp2p: Libp2p; getHasher: HasherLoader; metrics?: Metrics; } export interface WantListInit { sendWantlistDebounce?: number; } export interface ProgressCallback { onProgress: ProgressEventListener; signal?: AbortSignal; } export interface WantListEntry { /** * The CID we send to the remote */ cid: CID; /** * The priority with which the remote should return the block */ priority: number; /** * If we want the block or if we want the remote to tell us if they have the * block - note if the block is small they'll send it to us anyway. */ wantType: WantType; /** * Whether we are cancelling the block want or not */ cancel: boolean; /** * Whether the remote should tell us if they have the block or not */ sendDontHave: boolean; /** * Progress event handlers interested in this CID */ onProgress: ProgressCallback[]; } export interface WantOptions extends AbortOptions, ProgressOptions { /** * Allow prioritizing blocks */ priority?: number; } export interface WantBlockResult { /** * @deprecated access the sender via connection.remotePeer instead */ sender: PeerId; connection: Connection; cid: CID; block: Uint8Array; } export interface WantDoNotHaveResult { sender: PeerId; cid: CID; has: false; } export interface WantHaveResult { sender: PeerId; cid: CID; has: true; block?: Uint8Array; } export type WantPresenceResult = WantDoNotHaveResult | WantHaveResult; export interface WantListEvents { block: CustomEvent; presence: CustomEvent; } export declare class WantList extends TypedEventEmitter implements Startable, TypedEventTarget { /** * Tracks what CIDs we've previously sent to which peers */ readonly peers: PeerMap>; readonly wants: Map; private readonly network; private readonly log; private readonly sendWantlistDebounce; private sendMessagesTimeout?; private readonly getHasher; private sendingMessages?; constructor(components: WantListComponents, init?: WantListInit); private addEntry; private sendMessagesDebounced; private sendMessages; has(cid: CID): boolean; /** * Add a CID to the wantlist */ wantSessionPresence(cid: CID, peerId: PeerId, options?: WantOptions): Promise; /** * Add a CID to the wantlist */ wantBlock(cid: CID, options?: WantOptions): Promise; /** * Add a CID to the wantlist */ wantSessionBlock(cid: CID, peerId: PeerId, options?: WantOptions): Promise; /** * Invoked when a block has been received from an external source */ receivedBlock(cid: CID, options: ProgressOptions & AbortOptions): Promise; /** * Invoked when a message is received from a bitswap peer */ private receiveMessage; /** * Invoked when the network topology notices a new peer that supports Bitswap */ peerConnected(peerId: PeerId): Promise; /** * Invoked when the network topology notices peer that supports Bitswap has * disconnected */ peerDisconnected(peerId: PeerId): void; start(): void; stop(): void; } //# sourceMappingURL=want-list.d.ts.map