summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-01-13 13:56:26 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2023-01-13 13:57:29 +0100
commitb320b13b5d019c26928d2f00d8cba0febacb104b (patch)
tree1622ea3088dc933944867c26b141227f6fa6e28f /client
parent26abec61db10c3b86d9d168f093d4e5a75cc8783 (diff)
Client + Exports: Separate cleanup from disconnect
Diffstat (limited to 'client')
-rw-r--r--client/fsm.go15
-rw-r--r--client/server.go24
2 files changed, 25 insertions, 14 deletions
diff --git a/client/fsm.go b/client/fsm.go
index 88f2cf9..f9c7976 100644
--- a/client/fsm.go
+++ b/client/fsm.go
@@ -2,7 +2,6 @@ package client
import (
"github.com/eduvpn/eduvpn-common/internal/fsm"
- "github.com/eduvpn/eduvpn-common/internal/oauth"
"github.com/eduvpn/eduvpn-common/internal/server"
"github.com/go-errors/errors"
)
@@ -295,7 +294,7 @@ func (c *Client) SetDisconnecting() error {
// This indicates that the VPN is currently disconnected from the server.
// This also sends the /disconnect API call to the server.
// Returns an error if this state transition is not possible.
-func (c *Client) SetDisconnected(cleanup bool, ct oauth.Token) error {
+func (c *Client) SetDisconnected() error {
if c.InFSMState(StateDisconnected) {
// already disconnected, show no error
c.Logger.Warningf("Already disconnected")
@@ -312,18 +311,6 @@ func (c *Client) SetDisconnected(cleanup bool, ct oauth.Token) error {
return err
}
- if cleanup {
- // If we need to relogin, update tokens
- if server.NeedsRelogin(srv) {
- server.UpdateTokens(srv, ct)
- }
- // Do the /disconnect API call and go to disconnected after...
- err := server.Disconnect(srv)
- if err != nil {
- c.Logger.Warningf("Error disconnecting %v", err)
- }
- }
-
c.FSM.GoTransitionWithData(StateDisconnected, srv)
return nil
diff --git a/client/server.go b/client/server.go
index bc6b1fe..4070705 100644
--- a/client/server.go
+++ b/client/server.go
@@ -95,6 +95,30 @@ func (c *Client) getConfig(srv server.Server, preferTCP bool, t oauth.Token) (*C
return cfg, nil
}
+// Cleanup cleans up the VPN connection by sending a /disconnect to the server
+func (c *Client) Cleanup(ct oauth.Token) error {
+ srv, err := c.Servers.GetCurrentServer()
+ if err != nil {
+ c.logError(err)
+ return err
+ }
+
+ // If we need to relogin, update tokens
+ if server.NeedsRelogin(srv) {
+ server.UpdateTokens(srv, ct)
+ }
+ // Do the /disconnect API call
+ err = server.Disconnect(srv)
+ if err != nil {
+ // We log nothing here because this can happen regularly
+ // Maybe we should not log errors that we return directly anyways?
+ return err
+ }
+ // TODO: Tokens might be refreshed, return updated tokens
+ // Not implemented yet, because ideally we want this implemented with an interface
+ return nil
+}
+
// SetSecureLocation sets the location for the current secure location server. countryCode is the secure location to be chosen.
// This function returns an error e.g. if the server cannot be found or the location is wrong.
func (c *Client) SetSecureLocation(countryCode string) error {