v2

package
v0.0.0-...-f308040 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package v2 implements version 2 of the state file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// Profiles are the list of profiles
	Profiles server.Profiles `json:"profiles"`
	// LastAuthorizeTime is the time we last authorized
	// This is used for determining when to show e.g. the renew button
	LastAuthorizeTime time.Time `json:"last_authorize_time,omitempty"`
	// ExpireTime is the time at which the VPN expires
	ExpireTime time.Time `json:"expire_time,omitempty"`

	// CountryCode is the country code for the server in case of secure internet
	// Otherwise it is an empty string
	CountryCode string `json:"country_code,omitempty"`

	// LocationProfiles are current profiles for each secure internet location
	LocationProfiles map[string]string `json:"location_profiles,omitempty"`
}

Server is the struct for each server

type ServerKey

type ServerKey struct {
	// T is the type of server, e.g. secure internet
	T server.Type
	// ID is the identifier for the server
	ID string
}

ServerKey is the key type of the server map

func (ServerKey) MarshalText

func (st ServerKey) MarshalText() ([]byte, error)

MarshalText convers the server key into one that can be used in a map

func (*ServerKey) UnmarshalText

func (st *ServerKey) UnmarshalText(text []byte) error

UnmarshalText converts the marshaled key into a ServerType struct

type V2

type V2 struct {
	// List is the list of servers
	List map[ServerKey]*Server `json:"server_list,omitempty"`
	// LastChosen represents the key of the last chosen server
	// A server is chosen if we got a config for it
	LastChosen *ServerKey `json:"last_chosen_id,omitempty"`
	// Discovery is the cached list of discovery JSON
	Discovery discovery.Discovery `json:"discovery"`
}

V2 is the top-level struct for the state file

func FromV1

func FromV1(ver1 *v1.V1) *V2

FromV1 converts a version 1 state struct into a v2 one

func (*V2) AddServer

func (cfg *V2) AddServer(id string, t server.Type, srv Server) error

AddServer adds a server with id `id`, type `t` and server `srv`

func (*V2) CurrentServer

func (cfg *V2) CurrentServer() (*Server, *ServerKey, error)

CurrentServer gets the last chosen server It returns the server, the server type and an error if it doesn't exist

func (*V2) GetServer

func (cfg *V2) GetServer(id string, t server.Type) (*Server, error)

GetServer gets a server with id `id` and type `t` If the server doesn't exist it returns nil and an error

func (*V2) HasSecureInternet

func (cfg *V2) HasSecureInternet() bool

HasSecureInternet returns true whether or not the state file has a secure internet server in it

func (*V2) PublicCurrent

func (cfg *V2) PublicCurrent(disco *discovery.Discovery) (*server.Current, error)

PublicCurrent gets the current server as a type that should be returned to the client It returns this server or nil and an error if it doesn't exist

func (*V2) PublicList

func (cfg *V2) PublicList(disco *discovery.Discovery) *server.List

PublicList gets all the servers in a format that is returned to the client

func (*V2) RemoveServer

func (cfg *V2) RemoveServer(id string, t server.Type) error

RemoveServer removes a server with id `id` and type `t` from the V2 struct It returns an error if no such server exists

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳