From 3a11ac217e5137b7455d2202dc0d5077d9742256 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 14 Aug 2024 14:38:43 -0600 Subject: [PATCH] client: make ping interval and timeout configurable Signed-off-by: Sumner Evans --- pkg/connector/client.go | 3 +++ pkg/connector/config.go | 7 +++++++ pkg/connector/example-config.yaml | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/pkg/connector/client.go b/pkg/connector/client.go index 4dd7f27a..e8003b81 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -8,6 +8,7 @@ import ( "slices" "strconv" "strings" + "time" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/updates" @@ -177,6 +178,8 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge OnSession: func() { login.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected}) }, + PingTimeout: time.Duration(tc.Config.Ping.TimeoutSeconds) * time.Second, + PingInterval: time.Duration(tc.Config.Ping.IntervalSeconds) * time.Second, }) client.clientCancel, err = connectTelegramClient(ctx, client.client) diff --git a/pkg/connector/config.go b/pkg/connector/config.go index a1b3444d..003025ac 100644 --- a/pkg/connector/config.go +++ b/pkg/connector/config.go @@ -37,6 +37,11 @@ type TelegramConfig struct { MemberList MemberListConfig `yaml:"member_list"` MaxMemberCount int `yaml:"max_member_count"` + + Ping struct { + IntervalSeconds int `yaml:"interval_seconds"` + TimeoutSeconds int `yaml:"timeout_seconds"` + } `yaml:"ping"` } func (c TelegramConfig) ShouldBridge(participantCount int) bool { @@ -58,6 +63,8 @@ func upgradeConfig(helper up.Helper) { helper.Copy(up.Bool, "member_list", "sync_broadcast_channels") helper.Copy(up.Bool, "member_list", "skip_deleted") helper.Copy(up.Int, "max_member_count") + helper.Copy(up.Int, "ping", "interval_seconds") + helper.Copy(up.Int, "ping", "timeout_seconds") } func (tg *TelegramConnector) GetConfig() (example string, data any, upgrader up.Upgrader) { diff --git a/pkg/connector/example-config.yaml b/pkg/connector/example-config.yaml index d409d03e..6d155992 100644 --- a/pkg/connector/example-config.yaml +++ b/pkg/connector/example-config.yaml @@ -47,3 +47,10 @@ member_list: # # -1 means no limit (which means all chats can be bridged) max_member_count: -1 + +# Settings for pings to the Telegram server. +ping: + # The interval (in seconds) between pings. + interval_seconds: 30 + # The timeout (in seconds) for a single ping. + timeout_seconds: 10