diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-13 13:56:26 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-13 13:57:29 +0100 |
| commit | b320b13b5d019c26928d2f00d8cba0febacb104b (patch) | |
| tree | 1622ea3088dc933944867c26b141227f6fa6e28f /client/server.go | |
| parent | 26abec61db10c3b86d9d168f093d4e5a75cc8783 (diff) | |
Client + Exports: Separate cleanup from disconnect
Diffstat (limited to 'client/server.go')
| -rw-r--r-- | client/server.go | 24 |
1 files changed, 24 insertions, 0 deletions
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 { |
