Danish Arora 124a29ebba
feat(static-sharding): filter peer connections per shards (#1626)
* add interface for `ShardInfo`

* enr: add deserialization logic & setup getters

* add sharding related utils

* utils: add shard<-> bytes conversion helpers

* pass `pubSubTopics` to `Waku`

* add `rs`/`rsv` details during discovery

* connection-manager: discard irrelevant peers

* add tests for static sharding - peer exchange

* update `ConnectionManager` tests to account for topic validity

* add js suffix to import

* address some comments

* move shardInfo encoding to ENR

* test: update for new API

* enr: add tests for serialisation & deserialisation

* address comment

* update test

* move getPeershardInfo to ConnectionManager and return ShardInfo instead of bytes

* update encoding and decoding relay shards to also factor for shards>64

* relay shard encoding decoding: use DataView and verbose spec tests

* improve tests for relay shard encoding decoding

* rm: only

* improve log message for unconfigured pubsub topic

* minor improvement

* fix: buffer <> Uint8array problems with shard decoding

* fix: test

* rm: only
2023-10-10 20:18:02 +05:30

49 lines
1.1 KiB
TypeScript

import type { PeerId } from "@libp2p/interface/peer-id";
import type { PeerInfo } from "@libp2p/interface/peer-info";
import type { Multiaddr } from "@multiformats/multiaddr";
export type ENRKey = string;
export type ENRValue = Uint8Array;
/**
* We represent NodeId as a hex string, since node equality is used very heavily
* and it is convenient to index data by NodeId
*/
export type NodeId = string;
export type SequenceNumber = bigint;
export interface Waku2 {
relay: boolean;
store: boolean;
filter: boolean;
lightPush: boolean;
}
export interface ShardInfo {
cluster: number;
indexList: number[];
}
export interface IEnr extends Map<ENRKey, ENRValue> {
nodeId?: NodeId;
peerId?: PeerId;
id: string;
seq: SequenceNumber;
publicKey?: Uint8Array;
signature?: Uint8Array;
ip?: string;
tcp?: number;
udp?: number;
ip6?: string;
tcp6?: number;
udp6?: number;
multiaddrs?: Multiaddr[];
waku2?: Waku2;
peerInfo: PeerInfo | undefined;
shardInfo?: ShardInfo;
/**
* @deprecated: use { @link IEnr.peerInfo } instead.
*/
getFullMultiaddrs(): Multiaddr[];
}