config

package
v0.0.0-...-851e5e8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config provides functions for managing configuration of the daemon application.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// InstallFilePath defines filename of install id file
	InstallFilePath = filepath.Join(internal.DatFilesPathCommon, "install.dat")
	// SettingsDataFilePath defines path to app configs file
	SettingsDataFilePath = filepath.Join(internal.DatFilesPath, "settings.dat")
)
View Source
var (
	Protocol_name = map[int32]string{
		0: "UNKNOWN_PROTOCOL",
		1: "UDP",
		2: "TCP",
	}
	Protocol_value = map[string]int32{
		"UNKNOWN_PROTOCOL": 0,
		"UDP":              1,
		"TCP":              2,
	}
)

Enum value maps for Protocol.

View Source
var (
	Technology_name = map[int32]string{
		0: "UNKNOWN_TECHNOLOGY",
		1: "OPENVPN",
		2: "NORDLYNX",
	}
	Technology_value = map[string]int32{
		"UNKNOWN_TECHNOLOGY": 0,
		"OPENVPN":            1,
		"NORDLYNX":           2,
	}
)

Enum value maps for Technology.

View Source
var File_protobuf_daemon_config_protocol_proto protoreflect.FileDescriptor
View Source
var File_protobuf_daemon_config_technology_proto protoreflect.FileDescriptor
View Source
var GroupMap = map[string]ServerGroup{
	"double_vpn":                       DoubleVPN,
	"onion_over_vpn":                   OnionOverVPN,
	"dedicated_ip":                     DedicatedIP,
	"standard_vpn_servers":             StandardVPNServers,
	"p2p":                              P2P,
	"europe":                           Europe,
	"the_americas":                     TheAmericas,
	"asia_pacific":                     AsiaPacific,
	"africa_the_middle_east_and_india": AfricaMiddleEastIndia,
	"obfuscated_servers":               Obfuscated,
}

GroupMap maps group titles to IDs

Functions

This section is empty.

Types

type Allowlist

type Allowlist struct {
	Ports   Ports   `json:"ports"`
	Subnets Subnets `json:"subnets"`
}

Allowlist is a collection of ports and subnets

func NewAllowlist

func NewAllowlist(udpPorts []int64, tcpPorts []int64, subnets []string) Allowlist

NewAllowlist ready to use

type AutoConnectData

type AutoConnectData struct {
	ID        int64    `json:"id,omitempty"`
	ServerTag string   `json:"server_tag,omitempty"`
	Protocol  Protocol `json:"protocol,omitempty"`
	// TODO: rename json key when v4 comes out.
	ThreatProtectionLite bool      `json:"cybersec,omitempty"`
	Obfuscate            bool      `json:"obfuscate,omitempty"`
	DNS                  DNS       `json:"dns,omitempty"`
	Allowlist            Allowlist `json:"whitelist,omitempty"`
}

type Config

type Config struct {
	Technology   Technology `json:"technology,omitempty"`
	Firewall     bool       `json:"firewall"` // omitempty breaks this
	FirewallMark uint32     `json:"fwmark"`
	Routing      TrueField  `json:"routing"`
	Analytics    TrueField  `json:"analytics"`
	Mesh         bool       `json:"mesh"`
	// MeshPrivateKey is base64 encoded
	MeshPrivateKey  string              `json:"mesh_private_key"`
	MeshDevice      *mesh.Machine       `json:"mesh_device"`
	KillSwitch      bool                `json:"kill_switch,omitempty"`
	AutoConnect     bool                `json:"auto_connect,omitempty"`
	IPv6            bool                `json:"ipv6"`
	Meshnet         meshnet             `json:"meshnet"`
	AutoConnectData AutoConnectData     `json:"auto_connect_data"` // omitempty breaks this
	UsersData       *UsersData          `json:"users_data,omitempty"`
	TokensData      map[int64]TokenData `json:"tokens_data,omitempty"`
	MachineID       uuid.UUID           `json:"machine_id,omitempty"`
	LanDiscovery    bool                `json:"lan_discovery"`
	RemoteConfig    string              `json:"remote_config,omitempty"`
	RCLastUpdate    time.Time           `json:"rc_last_update,omitempty"`
}

Config stores application settings and tokens.

Config should be evolved is such a way, that it does not require any use of constructors by the caller.

type DNS

type DNS []string

func (DNS) Or

func (d DNS) Or(defaultValue []string) DNS

Or provides defaultValue in case of an empty/nil slice. Inspired by https://doc.rust-lang.org/std/option/enum.Option.html#method.or

type Field

type Field[T any] struct {
	// contains filtered or unexported fields
}

Field will unmarshal to null if unset.

func (Field[T]) MarshalJSON

func (f Field[T]) MarshalJSON() ([]byte, error)

MarshalJSON has to be a value receiver or else nil f.value will be marshaled as {}.

func (*Field[T]) Set

func (f *Field[T]) Set(value T)

Set the inner value.

Example
var b Field[bool]
fmt.Printf("%t\n", b.Get())
b.Set(false)
fmt.Printf("%t\n", b.Get())
b.Set(true)
fmt.Printf("%t\n", b.Get())
Output:

false
false
true

func (*Field[T]) UnmarshalJSON

func (f *Field[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON has to be a pointer receiver or else f.value will not update.

type FilesystemConfigManager

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

FilesystemConfigManager implements config persistence and retrieval from disk.

Thread-safe.

func NewFilesystemConfigManager

func NewFilesystemConfigManager(location, vault, salt string,
	machineIDGetter MachineIDGetter,
	fsHandle FilesystemHandle) *FilesystemConfigManager

NewFilesystemConfigManager is constructed from a given location and salt.

func (*FilesystemConfigManager) Load

func (f *FilesystemConfigManager) Load(c *Config) error

Load encrypted config from the filesystem.

Thread-safe.

func (*FilesystemConfigManager) Reset

func (f *FilesystemConfigManager) Reset() error

Reset config values to defaults.

Thread-safe.

func (*FilesystemConfigManager) SaveWith

func (f *FilesystemConfigManager) SaveWith(fn SaveFunc) error

SaveWith modifications provided by fn.

Thread-safe.

type FilesystemHandle

type FilesystemHandle interface {
	FileExists(string) bool
	CreateFile(string, fs.FileMode) error
	ReadFile(string) ([]byte, error)
	WriteFile(string, []byte, fs.FileMode) error
}

type LinuxMachineIDGetter

type LinuxMachineIDGetter struct {
}

func (LinuxMachineIDGetter) GetMachineID

func (LinuxMachineIDGetter) GetMachineID() uuid.UUID

type MachineIDGetter

type MachineIDGetter interface {
	GetMachineID() uuid.UUID
}

type Manager

type Manager interface {
	// SaveWith updates parts of the config specified by the SaveFunc.
	SaveWith(SaveFunc) error
	// Load config into a given struct.
	Load(*Config) error
	// Reset config to default values.
	Reset() error
}

Manager is responsible for persisting and retrieving the config.

type NCData

type NCData struct {
	UserID   uuid.UUID `json:"user_id,omitempty"`
	Username string    `json:"username,omitempty"`
	Password string    `json:"password,omitempty"`
	Endpoint string    `json:"endpoint,omitempty"`
}

func (*NCData) IsUserIDEmpty

func (d *NCData) IsUserIDEmpty() bool

type Notify

type Notify map[int64]bool

Notify is a set of user ids.

func (*Notify) MarshalJSON

func (n *Notify) MarshalJSON() ([]byte, error)

MarshalJSON into []float64

func (*Notify) UnmarshalJSON

func (n *Notify) UnmarshalJSON(b []byte) error

UnmarshalJSON into map[int64]bool

type PortSet

type PortSet map[int64]bool

PortSet is a set of ports.

func (PortSet) MarshalJSON

func (p PortSet) MarshalJSON() ([]byte, error)

MarshalJSON into []float64.

func (*PortSet) ToSlice

func (p *PortSet) ToSlice() []int64

func (*PortSet) UnmarshalJSON

func (p *PortSet) UnmarshalJSON(b []byte) error

UnmarshalJSON into map[int64]bool.

type Ports

type Ports struct {
	TCP PortSet `json:"tcp"`
	UDP PortSet `json:"udp"`
}

Ports is a collection of TCP and UDP ports.

type Protocol

type Protocol int32
const (
	Protocol_UNKNOWN_PROTOCOL Protocol = 0
	Protocol_UDP              Protocol = 1
	Protocol_TCP              Protocol = 2
)

func (Protocol) Descriptor

func (Protocol) Descriptor() protoreflect.EnumDescriptor

func (Protocol) Enum

func (x Protocol) Enum() *Protocol

func (Protocol) EnumDescriptor deprecated

func (Protocol) EnumDescriptor() ([]byte, []int)

Deprecated: Use Protocol.Descriptor instead.

func (Protocol) Number

func (x Protocol) Number() protoreflect.EnumNumber

func (Protocol) String

func (x Protocol) String() string

func (Protocol) Type

type SaveFunc

type SaveFunc func(Config) Config

SaveFunc is used by Manager to save the config.

type ServerGroup

type ServerGroup int64

ServerGroup represents a server group type

This should be in the core package, but cannot be there due to import cycles because of dimensions package.

const (
	// UndefinedGroup represents non existing server group
	UndefinedGroup ServerGroup = 0
	// DoubleVPN represents the double vpn server group
	DoubleVPN ServerGroup = 1
	// OnionOverVPN represents a OnionOverVPN server group
	OnionOverVPN ServerGroup = 3
	// UltraFastTV represents a UltraFastTV server group
	UltraFastTV ServerGroup = 5
	// AntiDDoS represents an AntiDDoS server group
	AntiDDoS ServerGroup = 7
	// DedicatedIP servers represents the Dedicated IP servers
	DedicatedIP ServerGroup = 9
	// StandardVPNServers represents a StandardVPNServers group
	StandardVPNServers ServerGroup = 11
	// NetflixUSA represents a NetflixUSA server group
	NetflixUSA ServerGroup = 13
	// P2P represents a P2P server group
	P2P ServerGroup = 15
	// Obfuscated represents an Obfuscated server group
	Obfuscated ServerGroup = 17
	// Europe servers represents the European servers
	Europe ServerGroup = 19
	// TheAmericas represents TheAmericas servers
	TheAmericas ServerGroup = 21
	// AsiaPacific represents a AsiaPacific server group
	AsiaPacific ServerGroup = 23
	// AfricaMiddleEastIndia represents a Africa, the Middle East and India server group
	AfricaMiddleEastIndia ServerGroup = 25
)

type StdFilesystemHandle

type StdFilesystemHandle struct {
}

func (StdFilesystemHandle) CreateFile

func (StdFilesystemHandle) CreateFile(location string, mode fs.FileMode) error

func (StdFilesystemHandle) FileExists

func (StdFilesystemHandle) FileExists(location string) bool

func (StdFilesystemHandle) ReadFile

func (StdFilesystemHandle) ReadFile(location string) ([]byte, error)

func (StdFilesystemHandle) WriteFile

func (StdFilesystemHandle) WriteFile(location string, data []byte, mode fs.FileMode) error

type Subnets

type Subnets map[string]bool

Subnets is a set of subnets.

func (Subnets) MarshalJSON

func (s Subnets) MarshalJSON() ([]byte, error)

MarshalJSON into []string.

func (*Subnets) ToSlice

func (s *Subnets) ToSlice() []string

func (*Subnets) UnmarshalJSON

func (s *Subnets) UnmarshalJSON(b []byte) error

UnmarshalJSON into map[string]bool.

type Technology

type Technology int32
const (
	Technology_UNKNOWN_TECHNOLOGY Technology = 0
	Technology_OPENVPN            Technology = 1
	Technology_NORDLYNX           Technology = 2
)

func (Technology) Descriptor

func (Technology) Descriptor() protoreflect.EnumDescriptor

func (Technology) Enum

func (x Technology) Enum() *Technology

func (Technology) EnumDescriptor deprecated

func (Technology) EnumDescriptor() ([]byte, []int)

Deprecated: Use Technology.Descriptor instead.

func (Technology) Number

func (x Technology) Number() protoreflect.EnumNumber

func (Technology) String

func (x Technology) String() string

func (Technology) Type

type TokenData

type TokenData struct {
	Token              string `json:"token,omitempty"`
	TokenExpiry        string `json:"token_expiry,omitempty"`
	RenewToken         string `json:"renew_token,omitempty"`
	ServiceExpiry      string `json:"service_expiry,omitempty"`
	NordLynxPrivateKey string `json:"nordlynx_private_key"`
	OpenVPNUsername    string `json:"openvpn_username"`
	OpenVPNPassword    string `json:"openvpn_password"`
	NCData             NCData `json:"nc_data,omitempty"`
}

type TrueField

type TrueField struct{ Field[bool] }

TrueField is a boolean, which is true by default.

func (TrueField) Get

func (t TrueField) Get() bool

type UsersData

type UsersData struct {
	Notify Notify `json:"notify"`
}

UsersData stores users which will receive notifications.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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