summaryrefslogtreecommitdiff
path: root/internal/failover/failover.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-20 15:35:44 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-21 18:28:00 +0100
commit6981666c6d8f639a1ff9c09a3bc08769e19928af (patch)
treebdb94d76a7fb6a08ef200e9bbbbd5fff1d6b134c /internal/failover/failover.go
parent697dfed1f9f5d2916889a81a7a64bd1158caf2d2 (diff)
Failover: Initial implementation
Diffstat (limited to 'internal/failover/failover.go')
-rw-r--r--internal/failover/failover.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/failover/failover.go b/internal/failover/failover.go
new file mode 100644
index 0000000..f239eeb
--- /dev/null
+++ b/internal/failover/failover.go
@@ -0,0 +1,21 @@
+package failover
+
+import "time"
+
+const (
+ // Send a ping every 2 seconds to the gateway
+ pInterval time.Duration = 2 * time.Second
+
+ // pAlive is how many pings we need to have sent to check if the connection is alive
+ pAlive int = 3
+
+ // pDropped is how many pings we need to have sent to check if the connection is dropped
+ pDropped int = 5
+)
+
+// New creates a failover monitor for the gateway and the rx bytes function reader
+// This is a simple wrapper over `NewDroppedMonitor` to create one with the default settings
+// If this function returns True, the connection is dropped. False means it has exited and we don't know for sure if it's dropped or not
+func New(readRxBytes func() (int64, error)) (*DroppedConMon, error) {
+ return NewDroppedMonitor(pInterval, pAlive, pDropped, readRxBytes)
+}