Documentation
¶
Overview ¶
Package client implements the public interface for creating eduVPN/Let's Connect! clients
Index ¶
- func CalculateGateway(cidr string) (string, error)
- func GetStateName(s FSMStateID) string
- type Client
- func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes.Type, ot *int64) (err error)
- func (c *Client) AuthDone(id string, t srvtypes.Type)
- func (c *Client) Cleanup(ck *cookie.Cookie) error
- func (c *Client) CurrentServer() (*srvtypes.Current, error)
- func (c *Client) Deregister()
- func (c *Client) DiscoOrganizations(ck *cookie.Cookie, cache bool, search string) (*discotypes.Organizations, error)
- func (c *Client) DiscoServers(ck *cookie.Cookie, cache bool, search string) (*discotypes.Servers, error)
- func (c *Client) ExpiryTimes() (*srvtypes.Expiry, error)
- func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.Type, pTCP bool, ...) (cfg *srvtypes.Configuration, err error)
- func (c *Client) GettingConfig() error
- func (c *Client) InState(state FSMStateID) bool
- func (c *Client) InvalidProfile(ctx context.Context, srv *server.Server) (string, error)
- func (c *Client) Register() error
- func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error)
- func (c *Client) RenewSession(ck *cookie.Cookie) error
- func (c *Client) ServerList() (*srvtypes.List, error)
- func (c *Client) SetProfileID(pID string) error
- func (c *Client) SetSecureLocation(orgID string, countryCode string) error
- func (c *Client) SetState(state FSMStateID) error
- func (c *Client) StartFailover(ck *cookie.Cookie, gateway string, mtu int, readRxBytes func() (int64, error)) (bool, error)
- func (c *Client) TokensUpdated(id string, t srvtypes.Type, tok eduoauth.Token)
- func (c *Client) TriggerAuth(ctx context.Context, url string, wait bool) (string, error)
- func (c *Client) TrySave()
- type FSMState
- type FSMStateID
- type FSMStates
- type FSMTransition
- type Logger
- type TokenCacher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateGateway ¶
CalculateGateway takes a CIDR encoded subnet `cidr` and returns the gateway and an error TODO: move this somewhere else?
func GetStateName ¶
func GetStateName(s FSMStateID) string
GetStateName gets the State name for state `s`
Types ¶
type Client ¶
type Client struct {
// The name of the client
Name string
// The servers
Servers server.Servers
// The fsm
FSM fsm.FSM
// TokenSetter sets the tokens in the client
TokenSetter func(sid string, stype srvtypes.Type, tok srvtypes.Tokens)
// TokenGetter gets the tokens from the client
TokenGetter func(sid string, stype srvtypes.Type) *srvtypes.Tokens
// contains filtered or unexported fields
}
Client is the main struct for the VPN client.
func New ¶
func New(name string, version string, directory string, stateCallback func(FSMStateID, FSMStateID, any) bool, logger Logger) (c *Client, err error)
New creates a new client with the following parameters:
- name: the name of the client
- directory: the directory where the config files are stored. Absolute or relative
- stateCallback: the callback function for the FSM that takes two states (old and new) and the data as an interface
- logger: the logger interface to use, if nil the default logger is used which logs to files in directory
It returns an error if initialization failed, for example when discovery cannot be obtained and when there are no servers.
func (*Client) AddServer ¶
func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes.Type, ot *int64) (err error)
AddServer adds a server with identifier and type
func (*Client) AuthDone ¶
AuthDone is called when authorization is done This is defined to satisfy the server.Callbacks interface
func (*Client) CurrentServer ¶
CurrentServer gets the current server that is configured
func (*Client) Deregister ¶
func (c *Client) Deregister()
Deregister 'deregisters' the client, meaning saving the log file and the config and emptying out the client struct.
func (*Client) DiscoOrganizations ¶
func (c *Client) DiscoOrganizations(ck *cookie.Cookie, cache bool, search string) (*discotypes.Organizations, error)
DiscoOrganizations gets the organizations list from the discovery server with search string `search` If the list cannot be retrieved an error is returned. If this is the case then a previous version of the list is returned if there is any. This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#organization-list. cache is set to true if there should be no network call done
func (*Client) DiscoServers ¶
func (c *Client) DiscoServers(ck *cookie.Cookie, cache bool, search string) (*discotypes.Servers, error)
DiscoServers gets the servers list from the discovery server with search string `search` If the list cannot be retrieved an error is returned. If this is the case then a previous version of the list is returned if there is any. This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#server-list. the cache argument is true if no network call should be done
func (*Client) ExpiryTimes ¶
ExpiryTimes returns the different Unix timestamps regarding expiry - The time starting at which the renew button should be shown, after 30 minutes and less than 24 hours - The time starting at which the countdown button should be shown, less than 24 hours - The list of times where notifications should be shown These times are reset when the VPN gets disconnected
func (*Client) GetConfig ¶
func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.Type, pTCP bool, startup bool) (cfg *srvtypes.Configuration, err error)
GetConfig gets a VPN configuration
func (*Client) GettingConfig ¶
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 (*Client) InState ¶
func (c *Client) InState(state FSMStateID) bool
InState returns whether or not the client is in state `state`
func (*Client) InvalidProfile ¶
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 (*Client) RemoveServer ¶
RemoveServer removes a server
func (*Client) RenewSession ¶
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 (*Client) ServerList ¶
ServerList gets the list of servers
func (*Client) SetProfileID ¶
SetProfileID set the profile ID `pID` for the current server
func (*Client) SetSecureLocation ¶
SetSecureLocation sets a secure internet location for organization ID `orgID` with country code `countryCode`
func (*Client) SetState ¶
func (c *Client) SetState(state FSMStateID) error
SetState sets the state for the client FSM to `state`
func (*Client) StartFailover ¶
func (c *Client) StartFailover(ck *cookie.Cookie, gateway string, mtu int, readRxBytes func() (int64, error)) (bool, error)
StartFailover starts the failover procedure
func (*Client) TokensUpdated ¶
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 (*Client) TriggerAuth ¶
TriggerAuth is called when authorization is triggered This function satisfies the server.Callbacks interface
type FSMStateID ¶
FSMStateID is an alias to the fsm state ID type
const ( // StateDeregistered is the state where we are deregistered StateDeregistered FSMStateID = iota // StateMain is the main state StateMain // StateAddingServer is the state where a server is being added StateAddingServer // StateOAuthStarted means the state where the OAuth procedure is triggered StateOAuthStarted // StateGettingConfig is the state a VPN config is being obtained StateGettingConfig // StateAskLocation is the state where a secure internet location is being asked StateAskLocation // StateAskProfile is the state where a profile is being asked for StateAskProfile // StateGotConfig is the state where a config is obtained StateGotConfig // StateConnecting is the state where the VPN is connecting StateConnecting // StateConnected is the state where the VPN is connected StateConnected // StateDisconnecting is the state where the VPN is disconnecting StateDisconnecting // StateDisconnected is the state where the VPN is disconnected StateDisconnected )
type FSMTransition ¶
type FSMTransition = fsm.Transition
FSMTransition is an alias to the fsm transition type
type Logger ¶
type Logger interface {
// Init initializes the logging through slog. The given directory can
// be used to store the log files.
Init(dir string) (*slog.Logger, error)
// Close is called after logging has ended and should release all
// resources from Init.
Close() error
}
Logger is used by Client to control its logging. Client uses slog for all logging which can be configured by implementations of this interface.
type TokenCacher ¶
type TokenCacher struct {
// InstituteAccess is the cached map for institute access servers
InstituteAccess cacheMap
// CustomServer is the cached map for custom server
CustomServer cacheMap
// SecureInternet is the cached map for the secure internet server
SecureInternet *eduoauth.Token
}
TokenCacher is a structure that caches tokens for each type of server