client

package
v0.0.0-...-580f94b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 24 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

View Source
var ErrNoProxyGuardCancel = errors.New("no ProxyGuard cancel function")

ErrNoProxyGuardCancel indicates that no ProxyGuard cancel function was ever defined. You probably forgot to call `Tunnel`

View Source
var ErrNoProxyGuardClient = errors.New("no ProxyGuard client created")

ErrNoProxyGuardClient is an error that is returned when no ProxyGuard client is created

Functions

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

	// Whether to enable debugging
	Debug bool

	// 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, interface{}) bool, debug bool) (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
  • debug: whether or not we want to enable debugging

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, ni bool) (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) (orgs *discotypes.Organizations, err error)

DiscoOrganizations gets the organizations list from the discovery server 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.

func (*Client) DiscoServers

func (c *Client) DiscoServers(ck *cookie.Cookie) (dss *discotypes.Servers, err error)

DiscoServers gets the servers list from the discovery server 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.

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

func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string, gotFD func(fd int, pips string), ready func()) error

StartProxyguard starts proxyguard for proxied WireGuard connections

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 Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is a wrapper around ProxyGuard that has the client and a cancel for cancellation by common and a mutex to protect against race conditions

func (*Proxy) Cancel

func (p *Proxy) Cancel() error

Cancel cancels a running ProxyGuard tunnel it returns an error if it cannot be canceled

func (*Proxy) Delete

func (p *Proxy) Delete()

Delete sets the inner client to nil

func (*Proxy) NewClient

func (p *Proxy) NewClient(c *proxyguard.Client)

NewClient creates a new ProxyGuard wrapper from client `c`

func (*Proxy) Tunnel

func (p *Proxy) Tunnel(ctx context.Context, peer string) error

Tunnel is a wrapper around ProxyGuard tunnel that that creates a new context that can be canceled

type ProxyLogger

type ProxyLogger struct{}

ProxyLogger is defined here such that we can update the proxyguard logger

func (*ProxyLogger) Log

func (pl *ProxyLogger) Log(msg string)

Log logs a message

func (*ProxyLogger) Logf

func (pl *ProxyLogger) Logf(msg string, params ...interface{})

Logf logs a message with parameters

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