summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-21 18:04:44 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-12-21 18:28:52 +0100
commite378d715a02ca749aec3e54f8496a51daea61404 (patch)
tree5d371152edb521d0ada4a112a02ebc75de8bc065
parenta8e71f7f20a1d5640d08ff637dc209206f536b8d (diff)
Failover: Pass logger and add debug statements
-rw-r--r--client/server.go2
-rw-r--r--internal/failover/failover.go10
-rw-r--r--internal/failover/monitor.go15
3 files changed, 21 insertions, 6 deletions
diff --git a/client/server.go b/client/server.go
index 27cb79b..32b7687 100644
--- a/client/server.go
+++ b/client/server.go
@@ -613,7 +613,7 @@ func (c *Client) StartFailover(gateway string, wgMTU int, readRxBytes func() (in
return false, errors.New("Profile does not support OpenVPN fallback")
}
- monitor, monitorErr := failover.New(readRxBytes)
+ monitor, monitorErr := failover.New(readRxBytes, c.Logger)
if monitorErr != nil {
return false, monitorErr
}
diff --git a/internal/failover/failover.go b/internal/failover/failover.go
index f239eeb..31fb2b0 100644
--- a/internal/failover/failover.go
+++ b/internal/failover/failover.go
@@ -1,6 +1,10 @@
package failover
-import "time"
+import (
+ "time"
+
+ "github.com/eduvpn/eduvpn-common/internal/log"
+)
const (
// Send a ping every 2 seconds to the gateway
@@ -16,6 +20,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)) (*DroppedConMon, error) {
- return NewDroppedMonitor(pInterval, pAlive, pDropped, readRxBytes)
+func New(readRxBytes func() (int64, error), logger log.FileLogger) (*DroppedConMon, error) {
+ return NewDroppedMonitor(pInterval, pAlive, pDropped, readRxBytes, logger)
}
diff --git a/internal/failover/monitor.go b/internal/failover/monitor.go
index d14fb9e..ed532f7 100644
--- a/internal/failover/monitor.go
+++ b/internal/failover/monitor.go
@@ -5,6 +5,7 @@ import (
"time"
"github.com/go-errors/errors"
+ "github.com/eduvpn/eduvpn-common/internal/log"
)
// The DroppedConMon is a connection monitor that checks for an increase in rx bytes in certain intervals
@@ -21,13 +22,16 @@ 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, pAlive int, pDropped int, readRxBytes func() (int64, error)) (*DroppedConMon, error) {
+func NewDroppedMonitor(pingInterval time.Duration, pAlive int, pDropped int, readRxBytes func() (int64, error), logger log.FileLogger) (*DroppedConMon, error) {
if pAlive >= pDropped {
return nil, errors.New("pAlive must be smaller than pDropped")
}
- return &DroppedConMon{pInterval: pingInterval, pAlive: pAlive, pDropped: pDropped, readRxBytes: readRxBytes}, nil
+ return &DroppedConMon{pInterval: pingInterval, pAlive: pAlive, pDropped: pDropped, readRxBytes: readRxBytes, logger: logger}, nil
}
// Dropped checks whether or not the connection is 'dropped'
@@ -37,6 +41,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)
return b <= startBytes, nil
}
@@ -70,20 +75,26 @@ func (m *DroppedConMon) Start(gateway string, mtuSize int) (bool, error) {
ticker := time.NewTicker(m.pInterval)
defer ticker.Stop()
+ m.logger.Debugf("[Failover] Starting...")
// Loop until the max drop counter
// We begin with 1 as this is used as the sequence number for ping
for s := 1; s <= m.pDropped; s++ {
+ m.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...")
return false, err
}
// Early alive check
// If not dropped, return
if s == m.pAlive {
+ m.logger.Debugf("[Failover] Doing check if we are alive")
if d, err := m.dropped(b); !d {
+ m.logger.Debugf("[Failover] We are alive")
return false, err
}
+ m.logger.Debugf("[Failover] Not alive currently, ticking further...")
}
// Wait for the next tick to continue
select {