libp2p-gossipsub
Version:
A typescript implementation of gossipsub
44 lines (43 loc) • 1.61 kB
TypeScript
/**
* IWantTracer is an internal tracer that tracks IWANT requests in order to penalize
* peers who don't follow up on IWANT requests after an IHAVE advertisement.
* The tracking of promises is probabilistic to avoid using too much memory.
*
* Note: Do not confuse these 'promises' with JS Promise objects.
* These 'promises' are merely expectations of a peer's behavior.
*/
export declare class IWantTracer {
/**
* Promises to deliver a message
* Map per message id, per peer, promise expiration time
*/
promises: Map<string, Map<string, number>>;
constructor();
/**
* Track a promise to deliver a message from a list of msgIds we are requesting
* @param {string} p peer id
* @param {string[]} msgIds
* @returns {void}
*/
addPromise(p: string, msgIds: Uint8Array[]): void;
/**
* Returns the number of broken promises for each peer who didn't follow up on an IWANT request.
* @returns {Map<string, number>}
*/
getBrokenPromises(): Map<string, number>;
/**
* Someone delivered a message, stop tracking promises for it
* @param {string} msgIdStr
* @returns {Promise<void>}
*/
deliverMessage(msgIdStr: string): Promise<void>;
/**
* A message got rejected, so we can stop tracking promises and let the score penalty apply from invalid message delivery,
* unless its an obviously invalid message.
* @param {string} msgIdStr
* @param {string} reason
* @returns {Promise<void>}
*/
rejectMessage(msgIdStr: string, reason: string): Promise<void>;
clear(): void;
}