This commit is contained in:
Adam Ierymenko 2019-09-22 19:25:40 -07:00
parent 90d4d79828
commit 70d5da1e2a
No known key found for this signature in database
GPG Key ID: C8877CF2D7A5D7F3
5 changed files with 86 additions and 6 deletions

View File

@ -100,6 +100,9 @@ struct ZT_GoNode_Impl
std::thread backgroundTaskThread; 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 */ /* These functions are implemented in Go in pkg/ztnode/node-callbacks.go */

View File

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

View File

@ -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
}

View File

@ -56,6 +56,9 @@ const (
// CoreVersionBuild is the build version of the ZeroTier core // CoreVersionBuild is the build version of the ZeroTier core
CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD 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 afInet = C.AF_INET
afInet6 = C.AF_INET6 afInet6 = C.AF_INET6
) )

View File

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