summaryrefslogtreecommitdiff
path: root/client/server.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 /client/server.go
parent697dfed1f9f5d2916889a81a7a64bd1158caf2d2 (diff)
Failover: Initial implementation
Diffstat (limited to 'client/server.go')
-rw-r--r--client/server.go39
1 files changed, 37 insertions, 2 deletions
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
+}