mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 10:37:33 -07:00
.
This commit is contained in:
parent
70d5da1e2a
commit
536bc59abb
5 changed files with 390 additions and 55 deletions
|
@ -14,7 +14,11 @@
|
|||
package zerotier
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
rand "math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
|
@ -41,33 +45,48 @@ type LocalConfigSettings struct {
|
|||
|
||||
// LocalConfig is the local.conf file and stores local settings for the node.
|
||||
type LocalConfig struct {
|
||||
Physical map[string]LocalConfigPhysicalPathConfiguration
|
||||
Virtual map[Address]LocalConfigVirtualAddressConfiguration
|
||||
Physical map[string]*LocalConfigPhysicalPathConfiguration
|
||||
Virtual map[Address]*LocalConfigVirtualAddressConfiguration
|
||||
Network map[NetworkID]*NetworkLocalSettings
|
||||
Settings LocalConfigSettings
|
||||
}
|
||||
|
||||
// NewLocalConfig creates a new local.conf file with defaults
|
||||
func NewLocalConfig() *LocalConfig {
|
||||
lc := &LocalConfig{
|
||||
Physical: make(map[string]LocalConfigPhysicalPathConfiguration),
|
||||
Virtual: make(map[Address]LocalConfigVirtualAddressConfiguration),
|
||||
Settings: LocalConfigSettings{
|
||||
PrimaryPort: 9993,
|
||||
SecondaryPort: 0,
|
||||
TertiaryPort: 0,
|
||||
PortMappingEnabled: true,
|
||||
MuiltipathMode: 0,
|
||||
},
|
||||
// Read this local config from a file, initializing to defaults if the file does not exist
|
||||
func (lc *LocalConfig) Read(p string) error {
|
||||
if lc.Physical == nil {
|
||||
lc.Physical = make(map[string]*LocalConfigPhysicalPathConfiguration)
|
||||
lc.Virtual = make(map[Address]*LocalConfigVirtualAddressConfiguration)
|
||||
lc.Network = make(map[NetworkID]*NetworkLocalSettings)
|
||||
lc.Settings.PrimaryPort = 9993
|
||||
lc.Settings.SecondaryPort = 16384 + (rand.Int() % 16384)
|
||||
lc.Settings.TertiaryPort = 32768 + (rand.Int() % 16384)
|
||||
lc.Settings.PortMappingEnabled = true
|
||||
lc.Settings.MuiltipathMode = 0
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"utun", "tun", "tap", "feth", "lo", "zt"}
|
||||
case "linux":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "lo", "zt"}
|
||||
case "freebsd", "openbsd", "netbsd", "illumos", "solaris", "dragonfly":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "zt"}
|
||||
case "android":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap"}
|
||||
}
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"utun", "tun", "tap", "feth", "lo", "zt"}
|
||||
case "linux":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "lo", "zt"}
|
||||
case "freebsd", "openbsd", "netbsd", "illumos", "solaris", "dragonfly":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "zt"}
|
||||
case "android":
|
||||
lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap"}
|
||||
|
||||
data, err := ioutil.ReadFile(p)
|
||||
if err != nil && err != os.ErrNotExist {
|
||||
return err
|
||||
}
|
||||
return lc
|
||||
|
||||
return json.Unmarshal(data, lc)
|
||||
}
|
||||
|
||||
// Write this local config to a file
|
||||
func (lc *LocalConfig) Write(p string) error {
|
||||
data, err := json.MarshalIndent(lc, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(p, data, 0644)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue