From 36ad7c6a95b2c4f2349c8569a26d497f8e217bc2 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Sat, 28 Sep 2024 12:21:04 +0530 Subject: [PATCH] feat: add clusterID and shards config to c-bindings --- library/c/README.md | 2 ++ library/config.go | 2 ++ library/node.go | 2 ++ waku/v2/node/wakuoptions.go | 17 +++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/library/c/README.md b/library/c/README.md index 30c2e0607..92dc08bbc 100644 --- a/library/c/README.md +++ b/library/c/README.md @@ -285,6 +285,8 @@ interface JsonConfig { storeRetentionTimeSeconds?: number; websocket?: Websocket; dns4DomainName?: string; + clusterID: int; + shards: Array; } ``` diff --git a/library/config.go b/library/config.go index 344d88a37..1574b9109 100644 --- a/library/config.go +++ b/library/config.go @@ -31,6 +31,8 @@ type WakuConfig struct { RetentionTimeSeconds *int `json:"storeRetentionTimeSeconds,omitempty"` DNS4DomainName string `json:"dns4DomainName,omitempty"` Websockets *WebsocketConfig `json:"websockets,omitempty"` + ClusterID int `json:"clusterID"` + Shards []uint16 `json:"shards"` } // WebsocketConfig contains all the settings required to setup websocket support in waku diff --git a/library/node.go b/library/node.go index f084b85a7..5232f4d92 100644 --- a/library/node.go +++ b/library/node.go @@ -164,6 +164,8 @@ func NewNode(instance *WakuInstance, configJSON string) error { node.WithPrivateKey(prvKey), node.WithHostAddress(hostAddr), node.WithKeepAlive(10*time.Second, time.Duration(*config.KeepAliveInterval)*time.Second), + node.WithClusterID(uint16(config.ClusterID)), + node.WithShards(config.Shards), } if *config.EnableRelay { diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 112cafe61..7e7c5e103 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -319,6 +319,11 @@ func WithPrivateKey(privKey *ecdsa.PrivateKey) WakuNodeOption { func WithClusterID(clusterID uint16) WakuNodeOption { return func(params *WakuNodeParameters) error { params.clusterID = clusterID + if params.shards == nil { + var pshards protocol.RelayShards + pshards.ClusterID = params.clusterID + params.shards = &pshards + } return nil } } @@ -340,6 +345,18 @@ func WithPubSubTopics(topics []string) WakuNodeOption { } } +func WithShards(shards []uint16) WakuNodeOption { + return func(params *WakuNodeParameters) error { + if params.shards == nil { + var pshards protocol.RelayShards + pshards.ClusterID = params.clusterID + params.shards = &pshards + } + params.shards.ShardIDs = shards + return nil + } +} + // WithMaxConnectionsPerIP sets the max number of allowed peers from the same IP func WithMaxConnectionsPerIP(limit int) WakuNodeOption { return func(params *WakuNodeParameters) error {