diff options
| -rw-r--r-- | client/client.go | 13 | ||||
| -rw-r--r-- | client/fsm.go | 9 | ||||
| -rw-r--r-- | exports/exports.go | 4 | ||||
| -rw-r--r-- | internal/http/http.go | 3 | ||||
| -rw-r--r-- | internal/log/rotate.go | 4 |
5 files changed, 28 insertions, 5 deletions
diff --git a/client/client.go b/client/client.go index 5317907..d986fa6 100644 --- a/client/client.go +++ b/client/client.go @@ -174,6 +174,8 @@ func New(name string, version string, directory string, stateCallback func(FSMSt c.disco = c.cfg.Discovery() + slog.Debug("Client registered", "name", name, "version", version, "directory", directory) + if !c.hasDiscovery() { return c, nil } @@ -249,6 +251,7 @@ func (c *Client) TokensUpdated(id string, t srvtypes.Type, tok eduoauth.Token) { } if c.TokenSetter == nil { + slog.Debug("not updating client tokens") return } // Update the client @@ -335,7 +338,6 @@ func (c *Client) locationCallback(ck *cookie.Cookie, orgID string) error { // TrySave tries to save the internal state file // If an error occurs it logs it func (c *Client) TrySave() { - slog.Debug("saving state file") if c.cfg == nil { slog.Warn("no state file to save") return @@ -351,6 +353,7 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. c.mu.Lock() defer c.mu.Unlock() + slog.Debug("client wants to add a server", "id", identifier, "type", _type) if !c.hasDiscovery() && _type != srvtypes.TypeCustom { return i18nerr.NewInternalf("Adding a non-custom server when the client does not use discovery is not supported, identifier: %s, type: %v", identifier, _type) } @@ -426,6 +429,8 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes. defer c.mu.Unlock() previousState := c.FSM.Current + slog.Debug("client wants to get a VPN config", "server_id", identifier, "server_type", _type, "prefer_tcp", pTCP, "startup", startup) + if !c.hasDiscovery() && _type != srvtypes.TypeCustom { return nil, i18nerr.NewInternalf("Getting a non-custom server when the client does not use discovery is not supported, identifier: %s, type: %d", identifier, _type) } @@ -507,6 +512,7 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes. // RemoveServer removes a server func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error) { + slog.Debug("client wants to remove a server", "id", identifier, "type", _type) identifier, err = c.convertIdentifier(identifier, _type) if err != nil { return err @@ -533,6 +539,7 @@ func (c *Client) CurrentServer() (*srvtypes.Current, error) { // SetProfileID set the profile ID `pID` for the current server func (c *Client) SetProfileID(pID string) error { + slog.Debug("Client sets profile ID", "id", pID) srv, err := c.Servers.CurrentServer() if err != nil { return i18nerr.WrapInternalf(err, "Failed to set the profile ID: '%s'", pID) @@ -565,6 +572,7 @@ func (c *Client) retrieveTokens(sid string, t srvtypes.Type) (*eduoauth.Token, e // Cleanup cleans up the VPN connection by sending a /disconnect func (c *Client) Cleanup(ck *cookie.Cookie) error { + slog.Debug("client wants to cleanup VPN connection") defer c.TrySave() srv, err := c.Servers.CurrentServer() if err != nil { @@ -596,6 +604,7 @@ func (c *Client) SetSecureLocation(orgID string, countryCode string) error { if err != nil { return i18nerr.WrapInternalf(err, "Failed to get the secure internet server with id: '%s' for setting a location", orgID) } + slog.Debug("setting secure internet location", "org_id", orgID, "code", countryCode) srv.CountryCode = countryCode defer c.TrySave() @@ -614,6 +623,7 @@ func (c *Client) SetSecureLocation(orgID string, countryCode string) error { // 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 { + slog.Debug("client wants to renew the session") // getting the current serving with nil tokens means re-authorize srv, err := c.Servers.CurrentServer() if err != nil { @@ -636,6 +646,7 @@ func (c *Client) RenewSession(ck *cookie.Cookie) error { // 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) + slog.Debug("client wants to start the failover test", "gateway", gateway, "mtu", mtu) // get current profile d, err := f.Start(ck.Context(), gateway, mtu) diff --git a/client/fsm.go b/client/fsm.go index 673f3fb..e3a8cc0 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -170,7 +170,14 @@ func newFSM( }, } - return fsm.NewFSM(StateMain, states, callback, GetStateName) + cbLogged := func(oldState FSMStateID, newState FSMStateID, data any) bool { + if oldState != newState { + slog.Debug("FSM transition", "old", GetStateName(oldState), "new", GetStateName(newState)) + } + return callback(oldState, newState, data) + } + + return fsm.NewFSM(StateMain, states, cbLogged, GetStateName) } // SetState sets the state for the client FSM to `state` diff --git a/exports/exports.go b/exports/exports.go index 774875f..a20ffb8 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -57,9 +57,10 @@ func getCError(err error) *C.char { if err == nil { return nil } + enMsg := err.Error() retErr := errtypes.Error{ Message: errtypes.Translated{ - "en": err.Error(), + "en": enMsg, }, Misc: false, } @@ -72,6 +73,7 @@ func getCError(err error) *C.char { if err != nil { return C.CString(fmt.Sprintf("failed to get error return: %v", err)) } + slog.Debug("error returned to client", "error", enMsg) return C.CString(retData) } diff --git a/internal/http/http.go b/internal/http/http.go index 555c5bb..7b9b70d 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "path" @@ -203,6 +204,8 @@ func (c *Client) Do(ctx context.Context, method string, urlStr string, opts *Opt ctx, cncl := context.WithTimeout(ctx, timeout) defer cncl() + slog.Debug("sending request", "method", method, "url", urlStr) + // Create request object with the body reader generated from the optional arguments req, err := http.NewRequestWithContext(ctx, method, urlStr, optionalBodyReader(opts)) if err != nil { diff --git a/internal/log/rotate.go b/internal/log/rotate.go index fb93c3c..27907ce 100644 --- a/internal/log/rotate.go +++ b/internal/log/rotate.go @@ -10,13 +10,13 @@ import ( var ( // MaxSize is the maximum size in bytes from when to start trimming - MaxSize int64 = 1024 * 1024 + MaxSize int64 = 10 * 1024 * 1024 // TrimSize denotes how much to trim from the beginning TrimSize = MaxSize / 2 // TrimMsg is the message to display when it was trimmed - TrimMsg = "--- previous part was trimmed by eduvpn-common as the file was too big ---\n" + TrimMsg = "--- previous part was trimmed by eduvpn-common as the file was too big (10MB) ---\n" ) // FileRotater is a file that is trimmed when a maximum size is reached |
