Adam Ierymenko 5 years ago
parent
commit
70d5da1e2a
5 changed files with 86 additions and 6 deletions
  1. 3 0
      go/native/GoGlue.cpp
  2. 1 0
      go/native/GoGlue.h
  3. 73 0
      go/pkg/zerotier/localconfig.go
  4. 3 0
      go/pkg/zerotier/node.go
  5. 6 6
      osdep/OSUtils.cpp

+ 3 - 0
go/native/GoGlue.cpp

@@ -100,6 +100,9 @@ struct ZT_GoNode_Impl
 	std::thread backgroundTaskThread;
 };
 
+static const std::string defaultHomePath(OSUtils::platformDefaultHomePath());
+extern "C" const char *ZT_PLATFORM_DEFAULT_HOMEPATH = defaultHomePath.c_str();
+
 /****************************************************************************/
 
 /* These functions are implemented in Go in pkg/ztnode/node-callbacks.go */

+ 1 - 0
go/native/GoGlue.h

@@ -48,6 +48,7 @@ extern "C" {
 
 /****************************************************************************/
 
+const char *ZT_PLATFORM_DEFAULT_HOMEPATH;
 
 /****************************************************************************/
 

+ 73 - 0
go/pkg/zerotier/localconfig.go

@@ -0,0 +1,73 @@
+/*
+ * Copyright (c)2019 ZeroTier, Inc.
+ *
+ * Use of this software is governed by the Business Source License included
+ * in the LICENSE.TXT file in the project's root directory.
+ *
+ * Change Date: 2023-01-01
+ *
+ * On the date above, in accordance with the Business Source License, use
+ * of this software will be governed by version 2.0 of the Apache License.
+ */
+/****/
+
+package zerotier
+
+import (
+	"net"
+	"runtime"
+)
+
+// LocalConfigPhysicalPathConfiguration contains settings for physical paths
+type LocalConfigPhysicalPathConfiguration struct {
+	Blacklist     bool
+	TrustedPathID uint64
+}
+
+// LocalConfigVirtualAddressConfiguration contains settings for virtual addresses
+type LocalConfigVirtualAddressConfiguration struct {
+	Try []net.Addr
+}
+
+// LocalConfigSettings contains node settings
+type LocalConfigSettings struct {
+	PrimaryPort              int
+	SecondaryPort            int
+	TertiaryPort             int
+	PortMappingEnabled       bool
+	MuiltipathMode           int
+	InterfacePrefixBlacklist []string
+}
+
+// LocalConfig is the local.conf file and stores local settings for the node.
+type LocalConfig struct {
+	Physical map[string]LocalConfigPhysicalPathConfiguration
+	Virtual  map[Address]LocalConfigVirtualAddressConfiguration
+	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,
+		},
+	}
+	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"}
+	}
+	return lc
+}

+ 3 - 0
go/pkg/zerotier/node.go

@@ -56,6 +56,9 @@ const (
 	// CoreVersionBuild is the build version of the ZeroTier core
 	CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD
 
+	// PlatformDefaultHomePath is the default location of ZeroTier's working path on this system
+	PlatformDefaultHomePath string = C.GoString(C.ZT_PLATFORM_DEFAULT_HOMEPATH)
+
 	afInet  = C.AF_INET
 	afInet6 = C.AF_INET6
 )

+ 6 - 6
osdep/OSUtils.cpp

@@ -406,15 +406,15 @@ std::string OSUtils::platformDefaultHomePath()
 
 #ifdef __APPLE__
 	// /Library/... on Apple
-	return std::string("/Library/Application Support/ZeroTier/One");
+	return std::string("/Library/Application Support/ZeroTier");
 #else
 
 #ifdef __BSD__
 	// BSD likes /var/db instead of /var/lib
-	return std::string("/var/db/zerotier-one");
+	return std::string("/var/db/zerotier");
 #else
 	// Use /var/lib for Linux and other *nix
-	return std::string("/var/lib/zerotier-one");
+	return std::string("/var/lib/zerotier");
 #endif
 
 #endif
@@ -425,11 +425,11 @@ std::string OSUtils::platformDefaultHomePath()
 	// Look up app data folder on Windows, e.g. C:\ProgramData\...
 	char buf[16384];
 	if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
-		return (std::string(buf) + "\\ZeroTier\\One");
-	else return std::string("C:\\ZeroTier\\One");
+		return (std::string(buf) + "\\ZeroTier");
+	else return std::string("C:\\ZeroTier");
 #else
 
-	return (std::string(ZT_PATH_SEPARATOR_S) + "ZeroTier" + ZT_PATH_SEPARATOR_S + "One"); // UNKNOWN PLATFORM
+	return (std::string(ZT_PATH_SEPARATOR_S) + "ZeroTier"); // UNKNOWN PLATFORM
 
 #endif