config

package
v0.0.0-...-a70aae6 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: GPL-3.0 Imports: 20 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 (
	ServerGroup_name = map[int32]string{
		0:  "UNDEFINED",
		1:  "DoubleVPN",
		3:  "ONION_OVER_VPN",
		5:  "ULTRA_FAST_TV",
		7:  "ANTI_DDOS",
		9:  "DEDICATED_IP",
		11: "STANDARD_VPN_SERVERS",
		13: "NETFLIX_USA",
		15: "P2P",
		17: "OBFUSCATED",
		19: "EUROPE",
		21: "THE_AMERICAS",
		23: "ASIA_PACIFIC",
		25: "AFRICA_MIDDLE_EAST_INDIA",
	}
	ServerGroup_value = map[string]int32{
		"UNDEFINED":                0,
		"DoubleVPN":                1,
		"ONION_OVER_VPN":           3,
		"ULTRA_FAST_TV":            5,
		"ANTI_DDOS":                7,
		"DEDICATED_IP":             9,
		"STANDARD_VPN_SERVERS":     11,
		"NETFLIX_USA":              13,
		"P2P":                      15,
		"OBFUSCATED":               17,
		"EUROPE":                   19,
		"THE_AMERICAS":             21,
		"ASIA_PACIFIC":             23,
		"AFRICA_MIDDLE_EAST_INDIA": 25,
	}
)

Enum value maps for ServerGroup.

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",
		3: "Webtunnel",
	}
	Protocol_value = map[string]int32{
		"UNKNOWN_PROTOCOL": 0,
		"UDP":              1,
		"TCP":              2,
		"Webtunnel":        3,
	}
)

Enum value maps for Protocol.

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

Enum value maps for Technology.

View Source
var File_protobuf_daemon_config_group_proto protoreflect.FileDescriptor
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":                       ServerGroup_DoubleVPN,
	"onion_over_vpn":                   ServerGroup_ONION_OVER_VPN,
	"dedicated_ip":                     ServerGroup_DEDICATED_IP,
	"standard_vpn_servers":             ServerGroup_STANDARD_VPN_SERVERS,
	"p2p":                              ServerGroup_P2P,
	"europe":                           ServerGroup_EUROPE,
	"the_americas":                     ServerGroup_THE_AMERICAS,
	"asia_pacific":                     ServerGroup_ASIA_PACIFIC,
	"africa_the_middle_east_and_india": ServerGroup_AFRICA_MIDDLE_EAST_INDIA,
	"obfuscated_servers":               ServerGroup_OBFUSCATED,
}

GroupMap maps group titles to IDs

Functions

func IsUnderSnap

func IsUnderSnap() bool

duplicate to avoid circular dependencies

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

func (*Allowlist) GetSubnets

func (a *Allowlist) GetSubnets() []string

GetSubnets returns a slice of all subnets within the allowlist

func (*Allowlist) GetTCPPorts

func (a *Allowlist) GetTCPPorts() []int64

GetTCPPorts returns a slice of all TCP ports within the allowlist

func (*Allowlist) GetUDPPorts

func (a *Allowlist) GetUDPPorts() []int64

GetUDPPorts returns a slice of all UDP ports within the allowlist

func (*Allowlist) UpdateSubnets

func (a *Allowlist) UpdateSubnets(subnet string, remove bool)

func (*Allowlist) UpdateTCPPorts

func (a *Allowlist) UpdateTCPPorts(ports []int64, remove bool)

func (*Allowlist) UpdateUDPPorts

func (a *Allowlist) UpdateUDPPorts(ports []int64, remove bool)

type AutoConnectData

type AutoConnectData struct {
	ID        int64  `json:"id,omitempty"`
	ServerTag string `json:"server_tag,omitempty"`
	Country   string
	City      string
	Group     ServerGroup
	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"`
	PostquantumVpn       bool      `json:"postquantum_vpn"`
}

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"`
	// Indicates whether the virtual servers are used. True by default
	VirtualLocation TrueField `json:"virtual_location,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 ConfigPublisher

type ConfigPublisher interface {
	Publish(*Config)
}

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 FileReader

type FileReader func(fileName string) ([]byte, error)

type FilesystemConfigManager

type FilesystemConfigManager struct {
	NewInstallation bool
	// 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,
	configPublisher ConfigPublisher) *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
	ReadFile(string) ([]byte, error)
	WriteFile(string, []byte, fs.FileMode) error
}

type HostNameReader

type HostNameReader func() (name string, err error)

type MachineID

type MachineID struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMachineID

func NewMachineID(fileReader FileReader, hostNameReader HostNameReader) *MachineID

func (*MachineID) GetMachineID

func (getter *MachineID) GetMachineID() (ret uuid.UUID)

func (*MachineID) GetUsedInformationMask

func (getter *MachineID) GetUsedInformationMask() int16

Return the bitmask to identify what information was used to generate the machine ID

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"`
	ExpirationDate time.Time `json:"timestamp,omitempty"`
}

func (*NCData) IsUserIDEmpty

func (d *NCData) IsUserIDEmpty() 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
	Protocol_Webtunnel        Protocol = 3
)

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 int32
const (
	ServerGroup_UNDEFINED                ServerGroup = 0
	ServerGroup_DoubleVPN                ServerGroup = 1
	ServerGroup_ONION_OVER_VPN           ServerGroup = 3
	ServerGroup_ULTRA_FAST_TV            ServerGroup = 5
	ServerGroup_ANTI_DDOS                ServerGroup = 7
	ServerGroup_DEDICATED_IP             ServerGroup = 9
	ServerGroup_STANDARD_VPN_SERVERS     ServerGroup = 11
	ServerGroup_NETFLIX_USA              ServerGroup = 13
	ServerGroup_P2P                      ServerGroup = 15
	ServerGroup_OBFUSCATED               ServerGroup = 17
	ServerGroup_EUROPE                   ServerGroup = 19
	ServerGroup_THE_AMERICAS             ServerGroup = 21
	ServerGroup_ASIA_PACIFIC             ServerGroup = 23
	ServerGroup_AFRICA_MIDDLE_EAST_INDIA ServerGroup = 25
)

func (ServerGroup) Descriptor

func (ServerGroup) Enum

func (x ServerGroup) Enum() *ServerGroup

func (ServerGroup) EnumDescriptor deprecated

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

Deprecated: Use ServerGroup.Descriptor instead.

func (ServerGroup) Number

func (x ServerGroup) Number() protoreflect.EnumNumber

func (ServerGroup) String

func (x ServerGroup) String() string

func (ServerGroup) Type

type StdFilesystemHandle

type StdFilesystemHandle struct {
}

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
	Technology_NORDWHISPER        Technology = 3
)

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"`
	IsOAuth            bool       `json:"is_oauth,omitempty"`
	TrustedPassToken   string     `json:"trusted_pass_token,omitempty"`
	TrustedPassOwnerID string     `json:"trusted_pass_owner_id,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"`
	IdempotencyKey     *uuid.UUID `json:"idempotency_key,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 UidBoolMap

type UidBoolMap map[int64]bool

UidBoolMap is a set of user ids.

func (*UidBoolMap) MarshalJSON

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

MarshalJSON into []float64

func (*UidBoolMap) UnmarshalJSON

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

UnmarshalJSON into map[int64]bool

type UsersData

type UsersData struct {
	Notify    UidBoolMap `json:"notify"` // To be removed in a next major version
	NotifyOff UidBoolMap `json:"notify_off"`
	TrayOff   UidBoolMap `json:"tray_off"`
}

UsersData stores users which will receive notifications and see the tray icon.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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