Sasha eab8ce81b4
feat!: local peer discovery improvements (#2557)
* update local peer discovery, make it configurable for cache

* move to separate file

* up tests, remove local storage from tests

* pass local peer cache options

* add e2e tests

* add aditional e2e tests for local cache

* rename local-peer-cache into peer-cache

* update tests, ci

* prevent filterign ws addresses
2025-08-15 00:14:32 +02:00

53 lines
1.0 KiB
TypeScript

/**
* Options for the discovery.
*/
export type DiscoveryOptions = {
peerExchange: boolean;
dns: boolean;
peerCache: boolean;
};
/**
* Partial peer information used to store in the cache.
*/
export type PartialPeerInfo = {
id: string;
multiaddrs: string[];
};
/**
* A cache interface for persisting peer information.
*/
export type PeerCache = {
/**
* Get the peer information from the cache.
*
* @returns The peer information from the cache or empty array if no peer information is found.
*/
get: () => PartialPeerInfo[];
/**
* Set the peer information in the cache.
*
* @param value The peer information to set in the cache.
*/
set: (value: PartialPeerInfo[]) => void;
/**
* Remove the peer information from the cache.
*/
remove: () => void;
};
/**
* Options for the peer cache discovery.
*/
export type PeerCacheDiscoveryOptions = {
/**
* The cache to use for getting and storing cached peer information.
*
* @default LocalStorage
*/
cache: PeerCache;
};