summaryrefslogtreecommitdiff
path: root/internal/failover
diff options
context:
space:
mode:
Diffstat (limited to 'internal/failover')
-rw-r--r--internal/failover/failover.go2
-rw-r--r--internal/failover/monitor.go4
-rw-r--r--internal/failover/ping.go3
-rw-r--r--internal/failover/ping_default.go1
4 files changed, 10 insertions, 0 deletions
diff --git a/internal/failover/failover.go b/internal/failover/failover.go
index 97b1da1..bbd1978 100644
--- a/internal/failover/failover.go
+++ b/internal/failover/failover.go
@@ -1,3 +1,5 @@
+// Package failover implements the failover procedure
+// by sending pings and checking if the VPN is up
package failover
import (
diff --git a/internal/failover/monitor.go b/internal/failover/monitor.go
index d9028f2..5d81f22 100644
--- a/internal/failover/monitor.go
+++ b/internal/failover/monitor.go
@@ -20,6 +20,10 @@ type DroppedConMon struct {
readRxBytes func() (int64, error)
}
+// NewDroppedMonitor creates a new failover monitor
+// `pingInterval` is the interval in which to send pings
+// `pDropped` is how many pings we need to send before we deem it is dropped
+// `readRxBytes` is a function that gets the rx bytes from the client
func NewDroppedMonitor(pingInterval time.Duration, pDropped int, readRxBytes func() (int64, error)) *DroppedConMon {
return &DroppedConMon{pInterval: pingInterval, pDropped: pDropped, readRxBytes: readRxBytes}
}
diff --git a/internal/failover/ping.go b/internal/failover/ping.go
index 3b5faa8..59dbcc9 100644
--- a/internal/failover/ping.go
+++ b/internal/failover/ping.go
@@ -13,12 +13,14 @@ import (
// mtuOverhead defines the total MTU overhead for an ICMP ECHO message: 20 bytes IP header + 8 bytes ICMP header
var mtuOverhead = 28
+// Pinger sends pings
type Pinger struct {
listener net.PacketConn
buffer []byte
gateway net.Addr
}
+// Read reads from the ping listener with deadline `deadline`
func (p Pinger) Read(deadline time.Time) error {
// First set the deadline to read
err := p.listener.SetReadDeadline(deadline)
@@ -43,6 +45,7 @@ func (p Pinger) Read(deadline time.Time) error {
}
}
+// Send sends a single ping
func (p Pinger) Send(seq int) error {
errorMessage := fmt.Sprintf("failed sending ping, seq %d", seq)
// Make a new ICMP message
diff --git a/internal/failover/ping_default.go b/internal/failover/ping_default.go
index c490869..11401bb 100644
--- a/internal/failover/ping_default.go
+++ b/internal/failover/ping_default.go
@@ -9,6 +9,7 @@ import (
"golang.org/x/net/icmp"
)
+// NewPinger creates a new pinger with gateway `gateway` and size `size`
func NewPinger(gateway string, size int) (*Pinger, error) {
l, err := icmp.ListenPacket("udp4", "0.0.0.0")
if err != nil {