/// import { ENR } from '@chainsafe/enr'; import { BitArray } from '@chainsafe/ssz'; import { EventEmitter } from 'events'; import { PortalNetworkRoutingTable } from '../index.js'; import type { ContentRequest, FindContentMessage, INewRequest, NetworkId, NodesMessage, OfferMessage, PingMessage, PongMessage, PortalNetwork, PortalNetworkMetrics, StateNetworkRoutingTable } from '../index.js'; import type { INodeAddress } from '@chainsafe/discv5/lib/session/nodeInfo.js'; import type { ITalkReqMessage } from '@chainsafe/discv5/message'; import type { SignableENR } from '@chainsafe/enr'; import type { Union } from '@chainsafe/ssz/lib/interface.js'; import type { Debugger } from 'debug'; export declare abstract class BaseNetwork extends EventEmitter { routingTable: PortalNetworkRoutingTable | StateNetworkRoutingTable; metrics: PortalNetworkMetrics | undefined; nodeRadius: bigint; private checkIndex; abstract logger: Debugger; abstract networkId: NetworkId; abstract networkName: string; enr: SignableENR; blockIndex: () => Promise>; setBlockIndex: (blockIndex: Map) => Promise; handleNewRequest: (request: INewRequest) => Promise; sendMessage: (enr: ENR | string, payload: Uint8Array, networkId: NetworkId, utpMessage?: boolean) => Promise; sendResponse: (src: INodeAddress, requestId: bigint, payload: Uint8Array) => Promise; findEnr: (nodeId: string) => ENR | undefined; put: (network: NetworkId, contentKey: string, content: string) => void; get: (network: NetworkId, contentKey: string) => Promise; _prune: (network: NetworkId, radius: bigint) => Promise; portal: PortalNetwork; constructor(client: PortalNetwork, radius?: bigint); abstract store(contentType: any, hashKey: string, value: Uint8Array): Promise; handle(message: ITalkReqMessage, src: INodeAddress): Promise; /** * Sends a Portal Network Wire Network PING message to a specified node * @param dstId the nodeId of the peer to send a ping to * @param payload custom payload to be sent in PING message * @param networkId subnetwork ID * @returns the PING payload specified by the subnetwork or undefined */ sendPing: (enr: ENR | string) => Promise; handlePing: (src: INodeAddress, id: bigint, pingMessage: PingMessage) => Promise; sendPong: (src: INodeAddress, requestId: bigint) => Promise; /** * * Sends a Portal Network FINDNODES request to a peer requesting other node ENRs * @param dstId node id or enr of peer * @param distances distances as defined by subnetwork for node ENRs being requested * @param networkId subnetwork id for message being * @returns a {@link `NodesMessage`} or undefined */ sendFindNodes: (dstId: string, distances: number[]) => Promise; private handleFindNodes; /** * Offers content corresponding to `contentKeys` to peer corresponding to `dstId` * @param dstId node ID of a peer * @param contentKeys content keys being offered as specified by the subnetwork * @param networkId network ID of subnetwork being used */ sendOffer: (dstId: string, contentKeys: Uint8Array[]) => Promise; protected handleOffer: (src: INodeAddress, requestId: bigint, msg: OfferMessage) => Promise; protected sendAccept: (src: INodeAddress, requestId: bigint, desiredContentAccepts: boolean[], desiredContentKeys: Uint8Array[]) => Promise; protected handleFindContent: (src: INodeAddress, requestId: bigint, network: Uint8Array, decodedContentMessage: FindContentMessage) => Promise; /** * * This method maintains the liveness of peers in the subnetwork routing tables. * @param srcId nodeId of peer being updated in subnetwork routing table * @param networkId subnetwork Id of routing table being updated * @param customPayload payload of the PING/PONG message being decoded */ private updateRoutingTable; abstract findContentLocally: (contentKey: Uint8Array) => Promise; abstract sendFindContent?: (dstId: string, key: Uint8Array) => Promise | undefined>; /** * Pings each node in a 20% sample of the routing table. * Uses the existing PING/PONG liveness logic to evict nodes that do not respond. */ private livenessCheck; /** * Follows below algorithm to refresh a bucket in the routing table * 1: Look at your routing table and select all buckets at distance greater than 239 that are not full. * 2: Select a number of buckets to refresh using this logic (48+ nodes known, refresh 1 bucket, 24+ nodes known, * refresh half of not full buckets, <25 nodes known, refresh all not empty buckets * 3: Randomly generate a NodeID that falls within each bucket to be refreshed. * Do the random lookup on this node-id. */ bucketRefresh: () => Promise; /** * Adds a bootnode which triggers a `findNodes` request to the Bootnode to populate the routing table * @param bootnode `string` encoded ENR of a bootnode * @param networkId network ID of the subnetwork routing table to add the bootnode to */ addBootNode: (bootnode: string) => Promise; prune(radius: bigint): Promise; gossipContent(contentKey: Uint8Array, content: Uint8Array): Promise; retrieve(contentKey: string): Promise; } //# sourceMappingURL=network.d.ts.map