Danish Arora 877fe1dc1d
feat: peer-exchange uses error codes (#1907)
* setup a generic protocol result type (DRY)

* metadata: use generic

* lightpush: use generic

* peer-exchange: use error codes + generic + update tests

* add issue link to skipped test

* tests: improve while loop readability
2024-03-13 19:33:50 +05:30

31 lines
786 B
TypeScript

import type { PeerId } from "@libp2p/interface";
import type { PeerStore } from "@libp2p/interface";
import type { ConnectionManager } from "@libp2p/interface-internal";
import { IEnr } from "./enr.js";
import { IBaseProtocolCore, ProtocolResult } from "./protocols.js";
export interface IPeerExchange extends IBaseProtocolCore {
query(params: PeerExchangeQueryParams): Promise<PeerExchangeResult>;
}
export type PeerExchangeResult = ProtocolResult<"peerInfos", PeerInfo[]>;
export interface PeerExchangeQueryParams {
numPeers: number;
peerId: PeerId;
}
export interface PeerExchangeResponse {
peerInfos: PeerInfo[];
}
export interface PeerInfo {
ENR?: IEnr;
}
export interface PeerExchangeComponents {
connectionManager: ConnectionManager;
peerStore: PeerStore;
}