libp2p-gossipsub
Version:
A typescript implementation of gossipsub
61 lines (60 loc) • 1.82 kB
TypeScript
import { InMessage } from 'libp2p-interfaces/src/pubsub';
import { MessageIdFunction } from './interfaces';
export interface CacheEntry {
msgId: Uint8Array;
topics: string[];
}
export declare class MessageCache {
msgs: Map<string, InMessage>;
peertx: Map<string, Map<string, number>>;
history: CacheEntry[][];
gossip: number;
msgIdFn: MessageIdFunction;
/**
* @param {Number} gossip
* @param {Number} history
* @param {msgIdFn} msgIdFn a function that returns message id from a message
*
* @constructor
*/
constructor(gossip: number, history: number);
/**
* Adds a message to the current window and the cache
*
* @param {string} msgIdStr
* @param {RPC.Message} msg
* @returns {Promise<void>}
*/
put(msg: InMessage, msgIdStr: string): Promise<void>;
/**
* Retrieves a message from the cache by its ID, if it is still present
*
* @param {Uint8Array} msgId
* @returns {Message}
*/
get(msgId: Uint8Array): InMessage | undefined;
/**
* Retrieves a message from the cache by its ID, if it is present
* for a specific peer.
* Returns the message and the number of times the peer has requested the message
*
* @param {string} msgIdStr
* @param {string} p
* @returns {[InMessage | undefined, number]}
*/
getForPeer(msgIdStr: string, p: string): [InMessage | undefined, number];
/**
* Retrieves a list of message IDs for a given topic
*
* @param {String} topic
*
* @returns {Array<Uint8Array>}
*/
getGossipIDs(topic: string): Uint8Array[];
/**
* Shifts the current window, discarding messages older than this.history.length of the cache
*
* @returns {void}
*/
shift(): void;
}