Skip to content

Commit

Permalink
feat: add clusterID and shards config to c-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Sep 28, 2024
1 parent 12abd04 commit 36ad7c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ interface JsonConfig {
storeRetentionTimeSeconds?: number;
websocket?: Websocket;
dns4DomainName?: string;
clusterID: int;
shards: Array<uint16>;
}
```
Expand Down
2 changes: 2 additions & 0 deletions library/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions library/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions waku/v2/node/wakuoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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 {
Expand Down

0 comments on commit 36ad7c6

Please sign in to comment.