summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-12 19:18:05 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commit74e36f0ead717105f26087c2cab08b41ba5a7ce8 (patch)
tree1eb2b7516bea705c9b5a50ce0965e170414ed880 /client
parent682d70091af2044ff6d8b350da9dff13163232e2 (diff)
All: Document everything to pass revive lint
Diffstat (limited to 'client')
-rw-r--r--client/client.go33
-rw-r--r--client/client_test.go2
-rw-r--r--client/fsm.go13
-rw-r--r--client/proxy.go4
-rw-r--r--client/token.go12
5 files changed, 54 insertions, 10 deletions
diff --git a/client/client.go b/client/client.go
index 07287cf..f00d56e 100644
--- a/client/client.go
+++ b/client/client.go
@@ -55,6 +55,9 @@ type Client struct {
mu sync.Mutex
}
+// GettingConfig is defined here to satisfy the server.Callbacks interface
+// It is called when internally we are getting a config
+// We go to the GettingConfig state
func (c *Client) GettingConfig() error {
if c.FSM.InState(StateGettingConfig) {
return nil
@@ -63,6 +66,9 @@ func (c *Client) GettingConfig() error {
return err
}
+// InvalidProfile is defined here to satisfy the server.Callbacks interface
+// It is called when a profile is invalid
+// Here we call the AskProfile transition
func (c *Client) InvalidProfile(ctx context.Context, srv *server.Server) (string, error) {
// TODO: should this have profiles as a parameter
ck := cookie.NewWithContext(ctx)
@@ -157,6 +163,8 @@ func New(name string, version string, directory string, stateCallback func(FSMSt
return c, nil
}
+// TriggerAuth is called when authorization is triggered
+// This function satisfies the server.Callbacks interface
func (c *Client) TriggerAuth(ctx context.Context, url string, wait bool) (string, error) {
// Get a reply from the client
if wait {
@@ -185,6 +193,8 @@ func (c *Client) TriggerAuth(ctx context.Context, url string, wait bool) (string
return "", nil
}
+// AuthDone is called when authorization is done
+// This is defined to satisfy the server.Callbacks interface
func (c *Client) AuthDone(id string, t srvtypes.Type) {
srv, err := c.Servers.GetServer(id, t)
if err == nil {
@@ -198,6 +208,9 @@ func (c *Client) AuthDone(id string, t srvtypes.Type) {
}
}
+// TokensUpdated is called when tokens are updated
+// It updates the cache map and the client tokens
+// This is defined to satisfy the server.Callbacks interface
func (c *Client) TokensUpdated(id string, t srvtypes.Type, tok eduoauth.Token) {
if tok.Access == "" {
return
@@ -219,7 +232,7 @@ func (c *Client) TokensUpdated(id string, t srvtypes.Type, tok eduoauth.Token) {
})
}
-// Registering means updating the FSM to get to the initial state correctly
+// Register means updating the FSM to get to the initial state correctly
func (c *Client) Register() error {
err := c.goTransition(StateMain)
if err != nil {
@@ -289,6 +302,8 @@ func (c *Client) locationCallback(ck *cookie.Cookie, orgID string) error {
return nil
}
+// TrySave tries to save the internal state file
+// If an error occurs it logs it
func (c *Client) TrySave() {
err := c.cfg.Save()
if err != nil {
@@ -375,7 +390,7 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.
if err == nil {
// it could be that we are not in getting config yet if we have just done authorization
c.FSM.GoTransition(StateGettingConfig) //nolint:errcheck
- c.FSM.GoTransition(StateGotConfig) //nolint:errcheck
+ c.FSM.GoTransition(StateGotConfig) //nolint:errcheck
} else if !c.FSM.InState(previousState) {
// go back to the previous state if an error occurred
c.FSM.GoTransition(previousState) //nolint:errcheck
@@ -402,7 +417,7 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.
case srvtypes.TypeSecureInternet:
srv, err = c.Servers.GetSecure(ck.Context(), identifier, c.cfg.Discovery(), tok, startup)
- var cErr *discovery.CountryNotFoundError
+ var cErr *discovery.ErrCountryNotFound
if errors.As(err, &cErr) {
err = c.locationCallback(ck, identifier)
if err == nil {
@@ -431,6 +446,7 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.
return cfg, nil
}
+// RemoveServer removes a server
func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error) {
identifier, err = c.convertIdentifier(identifier, _type)
if err != nil {
@@ -443,6 +459,7 @@ func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error
return nil
}
+// CurrentServer gets the current server that is configured
func (c *Client) CurrentServer() (*srvtypes.Current, error) {
curr, err := c.Servers.PublicCurrent(c.cfg.Discovery())
if err != nil {
@@ -451,6 +468,7 @@ func (c *Client) CurrentServer() (*srvtypes.Current, error) {
return curr, nil
}
+// SetProfileID set the profile ID `pID` for the current server
func (c *Client) SetProfileID(pID string) error {
srv, err := c.Servers.CurrentServer()
if err != nil {
@@ -481,12 +499,13 @@ func (c *Client) retrieveTokens(sid string, t srvtypes.Type) (*eduoauth.Token, e
}, nil
}
+// Cleanup cleans up the VPN connection by sending a /disconnect
func (c *Client) Cleanup(ck *cookie.Cookie) error {
srv, err := c.Servers.CurrentServer()
if err != nil {
return i18nerr.Wrap(err, "The current server was not found when cleaning up the connection")
}
- tok, err := c.retrieveTokens(srv.T.ID, srv.T.T)
+ tok, err := c.retrieveTokens(srv.Key.ID, srv.Key.T)
if err != nil {
return i18nerr.Wrap(err, "No OAuth tokens were found when cleaning up the connection")
}
@@ -501,6 +520,8 @@ func (c *Client) Cleanup(ck *cookie.Cookie) error {
return nil
}
+// SetSecureLocation sets a secure internet location for
+// organization ID `orgID` with country code `countryCode`
func (c *Client) SetSecureLocation(orgID string, countryCode string) error {
// not supported with Let's Connect! & govVPN
if !c.hasDiscovery() {
@@ -514,6 +535,8 @@ func (c *Client) SetSecureLocation(orgID string, countryCode string) error {
return nil
}
+// RenewSession is called when the user clicks on the renew session button
+// It re-authorized the server by getting a server without passing tokens
func (c *Client) RenewSession(ck *cookie.Cookie) error {
// getting the current serving with nil tokens means re-authorize
srv, err := c.Servers.CurrentServer()
@@ -529,6 +552,7 @@ func (c *Client) RenewSession(ck *cookie.Cookie) error {
return nil
}
+// StartFailover starts the failover procedure
func (c *Client) StartFailover(ck *cookie.Cookie, gateway string, mtu int, readRxBytes func() (int64, error)) (bool, error) {
f := failover.New(readRxBytes)
@@ -540,6 +564,7 @@ func (c *Client) StartFailover(ck *cookie.Cookie, gateway string, mtu int, readR
return d, nil
}
+// ServerList gets the list of servers
func (c *Client) ServerList() (*srvtypes.List, error) {
g := c.cfg.V2.PublicList(c.cfg.Discovery())
return g, nil
diff --git a/client/client_test.go b/client/client_test.go
index 1d4bf44..a221c93 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -370,7 +370,7 @@ func TestInvalidClientID(t *testing.T) {
k,
"0.1.0-test",
dir,
- func(old FSMStateID, new FSMStateID, data interface{}) bool {
+ func(_ FSMStateID, _ FSMStateID, _ interface{}) bool {
return true
},
false,
diff --git a/client/fsm.go b/client/fsm.go
index 42c0029..175b832 100644
--- a/client/fsm.go
+++ b/client/fsm.go
@@ -9,9 +9,13 @@ import (
)
type (
- FSMStateID = fsm.StateID
- FSMStates = fsm.States
- FSMState = fsm.State
+ // FSMStateID is an alias to the fsm state ID type
+ FSMStateID = fsm.StateID
+ // FSMStates is an alias to the fsm states type
+ FSMStates = fsm.States
+ // FSMState is an alias to the fsm state type
+ FSMState = fsm.State
+ // FSMTransition is an alias to the fsm transition type
FSMTransition = fsm.Transition
)
@@ -53,6 +57,7 @@ const (
StateDisconnected
)
+// GetStateName gets the State name for state `s`
func GetStateName(s FSMStateID) string {
switch s {
case StateDeregistered:
@@ -166,6 +171,7 @@ func newFSM(
return returnedFSM
}
+// SetState sets the state for the client FSM to `state`
func (c *Client) SetState(state FSMStateID) error {
c.mu.Lock()
defer c.mu.Unlock()
@@ -182,6 +188,7 @@ func (c *Client) SetState(state FSMStateID) error {
return nil
}
+// InState returns whether or not the client is in state `state`
func (c *Client) InState(state FSMStateID) bool {
c.mu.Lock()
defer c.mu.Unlock()
diff --git a/client/proxy.go b/client/proxy.go
index 0e78792..4165c0f 100644
--- a/client/proxy.go
+++ b/client/proxy.go
@@ -7,17 +7,21 @@ import (
"github.com/eduvpn/eduvpn-common/types/cookie"
)
+// ProxyLogger is defined here such that we can update the proxyguard logger
type ProxyLogger struct{}
+// Logf logs a message with parameters
func (pl *ProxyLogger) Logf(msg string, params ...interface{}) {
log.Logger.Debugf(msg, params...)
}
+// Log logs a message
func (pl *ProxyLogger) Log(msg string) {
log.Logger.Debugf("%s", msg)
}
func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string) error {
+// StartProxyguard starts proxyguard for proxied WireGuard connections
var err error
proxyguard.UpdateLogger(&ProxyLogger{})
err = proxyguard.Client(ck.Context(), listen, tcpsp, peer, -1)
diff --git a/client/token.go b/client/token.go
index d62308b..03ec1d6 100644
--- a/client/token.go
+++ b/client/token.go
@@ -10,12 +10,17 @@ import (
type cacheMap map[string]eduoauth.Token
+// TokenCacher is a structure that caches tokens for each type of server
type TokenCacher struct {
+ // InstituteAccess is the cached map for institute access servers
InstituteAccess cacheMap
- CustomServer cacheMap
- SecureInternet *eduoauth.Token
+ // CustomServer is the cached map for custom server
+ CustomServer cacheMap
+ // SecureInternet is the cached map for the secure internet server
+ SecureInternet *eduoauth.Token
}
+// Get gets tokens from the cache map
func (c *cacheMap) Get(id string) (*eduoauth.Token, error) {
if c == nil || len(*c) == 0 {
return nil, errors.New("no cache map available")
@@ -26,6 +31,7 @@ func (c *cacheMap) Get(id string) (*eduoauth.Token, error) {
return nil, fmt.Errorf("identifier: '%s' does not exist in token cache map", id)
}
+// Get gets tokens using a server id and type from the cacher
func (tc *TokenCacher) Get(id string, t srvtypes.Type) (*eduoauth.Token, error) {
switch t {
case srvtypes.TypeCustom:
@@ -41,6 +47,7 @@ func (tc *TokenCacher) Get(id string, t srvtypes.Type) (*eduoauth.Token, error)
return nil, fmt.Errorf("invalid type for token cacher get: %d", t)
}
+// Set updates the cache for the server id `id` with tokens `t`
func (c *cacheMap) Set(id string, t eduoauth.Token) {
if c == nil || len(*c) == 0 {
*c = make(cacheMap)
@@ -48,6 +55,7 @@ func (c *cacheMap) Set(id string, t eduoauth.Token) {
(*c)[id] = t
}
+// Set updates the top-level cacher for a specific server type
func (tc *TokenCacher) Set(id string, t srvtypes.Type, tok eduoauth.Token) error {
switch t {
case srvtypes.TypeCustom: