summaryrefslogtreecommitdiff
path: root/internal/failover
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-02-28 10:37:00 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2023-02-28 10:37:00 +0100
commit15cb268440b54bcbdcae9d64e1d5d083e99d74e7 (patch)
tree6450b9a01de01d8c85e8e2a25c525358b121b959 /internal/failover
parent1557593401acaca1bac696195794103fcda07538 (diff)
Log: Use a global logger instance
Diffstat (limited to 'internal/failover')
-rw-r--r--internal/failover/failover.go6
-rw-r--r--internal/failover/monitor.go23
2 files changed, 12 insertions, 17 deletions
diff --git a/internal/failover/failover.go b/internal/failover/failover.go
index 1c4c32e..97b1da1 100644
--- a/internal/failover/failover.go
+++ b/internal/failover/failover.go
@@ -2,8 +2,6 @@ package failover
import (
"time"
-
- "github.com/eduvpn/eduvpn-common/internal/log"
)
const (
@@ -17,6 +15,6 @@ const (
// 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), logger log.FileLogger) *DroppedConMon {
- return NewDroppedMonitor(pInterval, pDropped, readRxBytes, logger)
+func New(readRxBytes func() (int64, error)) *DroppedConMon {
+ return NewDroppedMonitor(pInterval, pDropped, readRxBytes)
}
diff --git a/internal/failover/monitor.go b/internal/failover/monitor.go
index c437d30..f143f94 100644
--- a/internal/failover/monitor.go
+++ b/internal/failover/monitor.go
@@ -20,13 +20,10 @@ type DroppedConMon struct {
// The cancel context
// This is used to cancel the dropped connection monitor
cancel context.CancelFunc
-
- // logger is the logger for debugging purposes
- logger log.FileLogger
}
-func NewDroppedMonitor(pingInterval time.Duration, pDropped int, readRxBytes func() (int64, error), logger log.FileLogger) *DroppedConMon {
- return &DroppedConMon{pInterval: pingInterval, pDropped: pDropped, readRxBytes: readRxBytes, logger: logger}
+func NewDroppedMonitor(pingInterval time.Duration, pDropped int, readRxBytes func() (int64, error)) *DroppedConMon {
+ return &DroppedConMon{pInterval: pingInterval, pDropped: pDropped, readRxBytes: readRxBytes}
}
// Dropped checks whether or not the connection is 'dropped'
@@ -36,7 +33,7 @@ func (m *DroppedConMon) dropped(startBytes int64) (bool, error) {
if err != nil {
return false, err
}
- m.logger.Debugf("[Failover] Alive check, current Rx bytes: %d, start Rx bytes: %d", b, startBytes)
+ log.Logger.Debugf("[Failover] Alive check, current Rx bytes: %d, start Rx bytes: %d", b, startBytes)
return b <= startBytes, nil
}
@@ -68,17 +65,17 @@ func (m *DroppedConMon) Start(gateway string, mtuSize int) (bool, error) {
// Send a ping and wait for max 2 seconds
// If we have then increased Rx bytes we return early
if err = p.Send(gateway, 1); err != nil {
- m.logger.Debugf("[Failover] First ping failed, exiting...")
+ log.Logger.Debugf("[Failover] First ping failed, exiting...")
return false, err
}
- m.logger.Debugf("[Failover] Now we are doing alive check")
+ log.Logger.Debugf("[Failover] Now we are doing alive check")
// Read the pong, if we got the echo reply then everything is fine, early return
if err = p.Read(time.Now().Add(m.pInterval)); err == nil {
- m.logger.Debugf("[Failover] Got early pong, exiting...")
+ log.Logger.Debugf("[Failover] Got early pong, exiting...")
return false, err
}
- m.logger.Debugf("[Failover] Error reading pong: %v", err)
+ log.Logger.Debugf("[Failover] Error reading pong: %v", err)
// Create a new ticker that executes our ping function every 'interval' seconds
// It starts immediately and stops when we reach the end
@@ -86,15 +83,15 @@ func (m *DroppedConMon) Start(gateway string, mtuSize int) (bool, error) {
defer ticker.Stop()
// Otherwise send n pings, without waiting for pong and then check if dropped
- m.logger.Debugf("[Failover] Starting by sending pings and not waiting for pong...")
+ log.Logger.Debugf("[Failover] Starting by sending pings and not waiting for pong...")
// Loop until the max drop counter
// We begin with 2 as this is used as the sequence number for ping
// and we have already sent a ping
for s := 2; s <= m.pDropped; s++ {
- m.logger.Debugf("[Failover] Sending ping: %d, with size: %d", s, mtuSize)
+ log.Logger.Debugf("[Failover] Sending ping: %d, with size: %d", s, mtuSize)
// Send a ping and return if an error occurs
if err := p.Send(gateway, s); err != nil {
- m.logger.Debugf("[Failover] A ping failed, exiting...")
+ log.Logger.Debugf("[Failover] A ping failed, exiting...")
return false, err
}
// Wait for the next tick to continue