client

package
v0.0.0-...-5aefab3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package client implements the public interface for creating eduVPN/Let's Connect! clients

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateGateway

func CalculateGateway(cidr string) (string, error)

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

func (c *Client) AuthDone(id string, t srvtypes.Type)

AuthDone is called when authorization is done This is defined to satisfy the server.Callbacks interface

func (*Client) Cleanup

func (c *Client) Cleanup(ck *cookie.Cookie) error

Cleanup cleans up the VPN connection by sending a /disconnect

func (*Client) CurrentServer

func (c *Client) CurrentServer() (*srvtypes.Current, error)

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

func (c *Client) ExpiryTimes() (*srvtypes.Expiry, error)

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

func (c *Client) GettingConfig() error

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

func (c *Client) InvalidProfile(ctx context.Context, srv *server.Server) (string, error)

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) Register

func (c *Client) Register() error

Register means updating the FSM to get to the initial state correctly

func (*Client) RemoveServer

func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error)

RemoveServer removes a server

func (*Client) RenewSession

func (c *Client) RenewSession(ck *cookie.Cookie) 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 (*Client) ServerList

func (c *Client) ServerList() (*srvtypes.List, error)

ServerList gets the list of servers

func (*Client) SetProfileID

func (c *Client) SetProfileID(pID string) error

SetProfileID set the profile ID `pID` for the current server

func (*Client) SetSecureLocation

func (c *Client) SetSecureLocation(orgID string, countryCode string) error

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

func (c *Client) TokensUpdated(id string, t srvtypes.Type, tok eduoauth.Token)

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

func (c *Client) TriggerAuth(ctx context.Context, url string, wait bool) (string, error)

TriggerAuth is called when authorization is triggered This function satisfies the server.Callbacks interface

func (*Client) TrySave

func (c *Client) TrySave()

TrySave tries to save the internal state file If an error occurs it logs it

type FSMState

type FSMState = fsm.State

FSMState is an alias to the fsm state type

type FSMStateID

type FSMStateID = fsm.StateID

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 FSMStates

type FSMStates = fsm.States

FSMStates is an alias to the fsm states type

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

func (*TokenCacher) Get

func (tc *TokenCacher) Get(id string, t srvtypes.Type) (*eduoauth.Token, error)

Get gets tokens using a server id and type from the cacher

func (*TokenCacher) Set

func (tc *TokenCacher) Set(id string, t srvtypes.Type, tok eduoauth.Token) error

Set updates the top-level cacher for a specific server type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL