import { CID } from 'multiformats/cid'; import { WantType } from '../pb/message.ts'; import type { Network } from '../network.ts'; import type { Wantlist } from '../pb/message.ts'; import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface'; import type { Blockstore } from 'interface-blockstore'; export interface LedgerComponents { peerId: PeerId; blockstore: Blockstore; network: Network; logger: ComponentLogger; } export interface LedgerInit { maxSizeReplaceHasWithBlock?: number; doNotResendBlockWindow?: number; maxWantListSize?: number; } export interface PeerWantListEntry { /** * The CID the peer has requested */ 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 the remote should tell us if they have the block or not */ sendDontHave: boolean; /** * If we don't have the block and we've told them we don't have the block */ sentDoNotHave?: boolean; /** * If the status is `sending` or `sent`, the block for this CID is or has been * sent to the peer so we should not attempt to send it again */ status: 'want' | 'sending' | 'sent'; /** * A timestamp for when this want should be removed from the list, typically * this is set with the `sent` status to prevent sending duplicate blocks to a * peer. Once it has expired the peer can request the block a subsequent time. */ expires?: number; /** * A timestamp of when this entry was created */ created: number; /** * If this field is false, we have attempted to send this WantList entry but * found there is no block for the CID in the blockstore and we are * optimistically waiting to see if we come across it later. * * We only perform the check when we are about to send the block, by which * point the entry status is 'sending' so this value with either be false or * not set */ haveBlock?: false; } export declare class Ledger { peerId: PeerId; private readonly blockstore; private readonly network; private wants; exchangeCount: number; bytesSent: number; bytesReceived: number; lastExchange?: number; private readonly maxSizeReplaceHasWithBlock; private readonly log; private readonly doNotResendBlockWindow; private readonly maxWantListSize; constructor(components: LedgerComponents, init: LedgerInit); sentBytes(n: number): void; receivedBytes(n: number): void; debtRatio(): number; removeExpiredWants(): void; addWants(wantlist?: Wantlist): void; private truncateWants; getWants(): PeerWantListEntry[]; hasWant(cid: CID): boolean; sendBlocksToPeer(options?: AbortOptions): Promise; } //# sourceMappingURL=ledger.d.ts.map