diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-12-20 15:35:44 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-12-21 18:28:00 +0100 |
| commit | 6981666c6d8f639a1ff9c09a3bc08769e19928af (patch) | |
| tree | bdb94d76a7fb6a08ef200e9bbbbd5fff1d6b134c /client | |
| parent | 697dfed1f9f5d2916889a81a7a64bd1158caf2d2 (diff) | |
Failover: Initial implementation
Diffstat (limited to 'client')
| -rw-r--r-- | client/client.go | 4 | ||||
| -rw-r--r-- | client/fsm.go | 4 | ||||
| -rw-r--r-- | client/server.go | 39 |
3 files changed, 43 insertions, 4 deletions
diff --git a/client/client.go b/client/client.go index a31334a..b37c506 100644 --- a/client/client.go +++ b/client/client.go @@ -6,6 +6,7 @@ import ( "github.com/eduvpn/eduvpn-common/internal/config" "github.com/eduvpn/eduvpn-common/internal/discovery" + "github.com/eduvpn/eduvpn-common/internal/failover" "github.com/eduvpn/eduvpn-common/internal/fsm" "github.com/eduvpn/eduvpn-common/internal/log" "github.com/eduvpn/eduvpn-common/internal/server" @@ -62,6 +63,9 @@ type Client struct { // Whether to enable debugging Debug bool `json:"-"` + + // The Failover monitor for the current VPN connection + Failover *failover.DroppedConMon } // Register initializes the clientwith the following parameters: diff --git a/client/fsm.go b/client/fsm.go index c156fba..76dee05 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -212,7 +212,7 @@ func (c *Client) SetSearchServer() error { return err } - // TODO(jwijenbergh): Should we handle `false` returned value here? + //TODO(jwijenbergh): Should we handle `false` returned value here? c.FSM.GoTransition(StateSearchServer) return nil } @@ -325,7 +325,7 @@ func (c *Client) SetDisconnected(cleanup bool) error { func (c *Client) goBackInternal() { err := c.GoBack() if err != nil { - // TODO(jwijenbergh): Bit suspicious - logging level INFO, yet stacktrace logged. + //TODO(jwijenbergh): Bit suspicious - logging level INFO, yet stacktrace logged. c.Logger.Infof("failed going back: %s\nstacktrace:\n%s", err.Error(), err.(*errors.Error).ErrorStack()) } } diff --git a/client/server.go b/client/server.go index 4c00986..6802a47 100644 --- a/client/server.go +++ b/client/server.go @@ -1,6 +1,7 @@ package client import ( + "github.com/eduvpn/eduvpn-common/internal/failover" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/server" "github.com/eduvpn/eduvpn-common/internal/util" @@ -84,8 +85,8 @@ func (c *Client) getConfig(srv server.Server, preferTCP bool) (string, string, e // Save the config if err = c.Config.Save(&c); err != nil { - // TODO(jwijenbergh): Not sure why INFO level, yet stacktrace... - // TODO(jwijenbergh): Even worse, why logging it but then return nil? The calling code will think that everything went well. + //TODO(jwijenbergh): Not sure why INFO level, yet stacktrace... + //TODO(jwijenbergh): Even worse, why logging it but then return nil? The calling code will think that everything went well. c.Logger.Infof("c.Config.Save failed: %s\nstacktrace:\n%s", err.Error(), err.(*errors.Error).ErrorStack()) } @@ -584,3 +585,37 @@ func (c *Client) SetProfileID(profileID string) (err error) { b.Profiles.Current = profileID return nil } + +func (c *Client) StartFailover(gateway string, wgMTU int, readRxBytes func() (int64, error)) (bool, error) { + currentServer, currentServerErr := c.Servers.GetCurrentServer() + if currentServerErr != nil { + return false, currentServerErr + } + + // Check if the current profile supports OpenVPN + profile, profileErr := server.CurrentProfile(currentServer) + if profileErr != nil { + return false, profileErr + } + + if !profile.SupportsOpenVPN() { + return false, errors.New("Profile does not support OpenVPN fallback") + } + + monitor, monitorErr := failover.New(readRxBytes) + if monitorErr != nil { + return false, monitorErr + } + // Initialize the client's monitor + c.Failover = monitor + + return c.Failover.Start(gateway, wgMTU) +} + +func (c *Client) CancelFailover() error { + if c.Failover == nil { + return errors.New("No failover process") + } + c.Failover.Cancel() + return nil +} |
