-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
97 lines (85 loc) · 3.43 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Package config provides functions for managing configuration of the daemon application.
package config
import (
"time"
"github.com/google/uuid"
"github.com/NordSecurity/nordvpn-linux/core/mesh"
)
const defaultFWMarkValue uint32 = 0xe1f1
func newConfig(machineIDGetter MachineIDGetter) *Config {
return &Config{
Technology: Technology_NORDLYNX,
Firewall: true,
FirewallMark: defaultFWMarkValue,
AutoConnectData: AutoConnectData{
Protocol: Protocol_UDP,
},
MachineID: machineIDGetter.GetMachineID(),
UsersData: &UsersData{Notify: UidBoolMap{}, NotifyOff: UidBoolMap{}, TrayOff: UidBoolMap{}},
TokensData: map[int64]TokenData{},
}
}
// 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 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"`
}
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 DNS []string
// Or provides defaultValue in case of an empty/nil slice.
// Inspired by https://doc.rust-lang.org/std/option/enum.Option.html#method.or
func (d DNS) Or(defaultValue []string) DNS {
if len(d) == 0 { // also covers nil slices
return DNS(defaultValue)
}
return d
}
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"`
}
type meshnet struct {
EnabledByUID uint32 `json:"enabled_by_uid"` // Linux user which enabled meshnet
EnabledByGID uint32 `json:"enabled_by_gid"` // Group of Linux user which enabled meshnet
}
func (d *NCData) IsUserIDEmpty() bool {
return d.UserID == uuid.Nil
}