From 21ad496d42011d34e10ba04d92c38c17f37ea120 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 14 Mar 2023 06:38:56 -0400 Subject: [PATCH] feat(c-bindings): seenTTL --- library/README.md | 3 +++ library/api.go | 1 + mobile/api.go | 2 ++ mobile/config.go | 11 +++++++++++ 4 files changed, 17 insertions(+) diff --git a/library/README.md b/library/README.md index d5f598f7..0bda6b4d 100644 --- a/library/README.md +++ b/library/README.md @@ -439,6 +439,9 @@ If a key is `undefined`, or `null`, a default value will be set. Default `10` - `iWantFollowupTimeSeconds`: Time to wait for a message requested through IWANT following an IHAVE advertisement. Default `3` seconds +- `seenMessagesTTLSeconds`: configures when a previously seen message ID can be forgotten about. + Default `120` seconds + ### `extern char* waku_new(char* jsonConfig)` diff --git a/library/api.go b/library/api.go index ea95fb15..82727d9d 100644 --- a/library/api.go +++ b/library/api.go @@ -57,6 +57,7 @@ func main() {} // - maxIHaveLength: max number of messages to include in an IHAVE message, also controls the max number of IHAVE ids we will accept and request with IWANT from a peer within a heartbeat. Default `5000` // - maxIHaveMessages: max number of IHAVE messages to accept from a peer within a heartbeat. Default `10` // - iWantFollowupTimeSeconds: Time to wait for a message requested through IWANT following an IHAVE advertisement. Default `3` seconds +// - seenMessagesTTLSeconds: configures when a previously seen message ID can be forgotten about. Default `120` seconds // // - minPeersToPublish: The minimum number of peers required on a topic to allow broadcasting a message. Default `0` // - filter: Enable Filter. Default `false` diff --git a/mobile/api.go b/mobile/api.go index 81cdcb22..bad12f9b 100644 --- a/mobile/api.go +++ b/mobile/api.go @@ -101,6 +101,8 @@ func NewNode(configJSON string) string { pubsubOpt = append(pubsubOpt, pubsub.WithGossipSubParams(params)) } + pubsubOpt = append(pubsubOpt, pubsub.WithSeenMessagesTTL(GetSeenTTL(config))) + opts = append(opts, node.WithWakuRelayAndMinPeers(*config.MinPeersToPublish, pubsubOpt...)) } diff --git a/mobile/config.go b/mobile/config.go index 4ddc74d2..89bc792f 100644 --- a/mobile/config.go +++ b/mobile/config.go @@ -185,6 +185,9 @@ type GossipSubParams struct { // If the message is not received within this window, a broken promise is declared and // the router may apply bahavioural penalties. IWantFollowupTimeSeconds *int `json:"iWantFollowupTimeSeconds,omitempty"` + + // configures when a previously seen message ID can be forgotten about + SeenMessagesTTLSeconds *int `json:"seenMessagesTTLSeconds"` } func getConfig(configJSON string) (wakuConfig, error) { @@ -255,6 +258,14 @@ func getConfig(configJSON string) (wakuConfig, error) { return config, nil } +func GetSeenTTL(cfg wakuConfig) time.Duration { + if cfg.GossipSubParams == nil || *cfg.GossipSubParams.SeenMessagesTTLSeconds == 0 { + return pubsub.TimeCacheDuration + } + + return time.Duration(*cfg.GossipSubParams.SeenMessagesTTLSeconds) +} + func GetGossipSubParams(cfg *GossipSubParams) pubsub.GossipSubParams { params := pubsub.DefaultGossipSubParams()