From 507ba7d26a501928fef9217f14a93870e35105b7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 2 Oct 2019 17:55:15 -0700 Subject: [PATCH] Go build stuff, root stuff --- CMakeLists.txt | 8 ++++++++ go/pkg/zerotier/node.go | 2 +- include/ZeroTierCore.h | 7 +------ node/Constants.hpp | 14 ++++++++++++++ node/Locator.hpp | 4 ++-- node/Str.hpp | 17 +++++++++++++++++ node/Topology.hpp | 16 +++++++++++----- 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be34c7e51..7487351ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,14 @@ endif(WIN32) #target_link_libraries(${PROJECT_NAME} ${libs}) #target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) +add_custom_command( + OUTPUT zerotier + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/go + COMMAND go build -trimpath -ldflags -s -o ../build/zerotier cmd/zerotier/zerotier.go + DEPENDS zt_osdep zt_core zt_go_native +) +add_custom_target(build_zerotier ALL DEPENDS zerotier) + add_executable(zerotier-selftest selftest.cpp) target_link_libraries(zerotier-selftest ${libs} zt_core zt_osdep) target_compile_features(zerotier-selftest PUBLIC cxx_std_11) diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index d97115c70..139d5be9d 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -747,7 +747,7 @@ func (n *Node) makeStateObjectPath(objType int, id [2]uint64) (string, bool) { fp = path.Join(n.basePath, "networks.d") _ = os.Mkdir(fp, 0755) fp = path.Join(fp, fmt.Sprintf("%.16x.conf", id[0])) - case C.ZT_STATE_OBJECT_ROOT_LIST: + case C.ZT_STATE_OBJECT_ROOTS: fp = path.Join(n.basePath, "roots") } return fp, secret diff --git a/include/ZeroTierCore.h b/include/ZeroTierCore.h index 4a45b1139..c487dc46c 100644 --- a/include/ZeroTierCore.h +++ b/include/ZeroTierCore.h @@ -166,11 +166,6 @@ extern "C" { */ #define ZT_MAX_MULTICAST_SUBSCRIPTIONS 1024 -/** - * Maximum size for a state object (via state object put/get callbacks/API) - */ -#define ZT_MAX_STATE_OBJECT_SIZE 4096 - /** * Maximum value for link quality (min is 0) */ @@ -1342,7 +1337,7 @@ enum ZT_StateObjectType * Canonical path: /roots * Persitence: required if root settings should persist */ - ZT_STATE_OBJECT_ROOT_LIST = 7 + ZT_STATE_OBJECT_ROOTS = 7 }; /** diff --git a/node/Constants.hpp b/node/Constants.hpp index 79191f14c..99b10f456 100644 --- a/node/Constants.hpp +++ b/node/Constants.hpp @@ -189,6 +189,20 @@ */ #define ZT_ADDRESS_RESERVED_PREFIX 0xff +/** + * Secure DNS name for ZeroTier's default root + * + * This resolves via GeoDNS to the (probably) nearest actual root server's locator. + */ +#define ZT_DEFAULT_ROOT_NAME "ztl-aj4zes4l6zumq64na6borruuvd6diw2koxrjcaatolcekt2gj5rrhric.ztl-6lhxeo7n3z7kzkgcqzj3ndliaq.zerotier.network" + +/** + * Default locator for default root + * + * This is used before the root has been successfully fetched, or if DNS is unavailable. + */ +#define ZT_DEFAULT_ROOT_LOCATOR "AAAAAW2OuYyfOkbxvzAAduZvqzPihUmmLuIGTRhDJzwsMAukXD8gvvAtutIlcju1mpu0sTU1cwlhruz1oWOs5HfM6wcnAluZrBSlFmoJowAEBLm0DVInCQS5tA1SAbsGKgJuoMgVAAAAAAAAAAAAACcJBioCbqDIFQAAAAAAAAAAAAABuwAAYDvTNB2snbn7TYom4PBTh/ohRgCnI2/A/nfKakGCb+2hGJTtxTCiGTzKZdbjd0vyKAKQLJxhj7RaoCo3XjPn8w9nDEmhdNCgCM/IITCJIzc9tEKFsSQnJY4VmB3dopBAfQAA" + /** * Default virtual network MTU (not physical) */ diff --git a/node/Locator.hpp b/node/Locator.hpp index 63d9e9b07..81e57676a 100644 --- a/node/Locator.hpp +++ b/node/Locator.hpp @@ -27,8 +27,8 @@ #include // These are absolute maximums -- real locators are never this big -#define ZT_LOCATOR_MAX_PHYSICAL_ADDRESSES 255 -#define ZT_LOCATOR_MAX_VIRTUAL_ADDRESSES 255 +#define ZT_LOCATOR_MAX_PHYSICAL_ADDRESSES 64 +#define ZT_LOCATOR_MAX_VIRTUAL_ADDRESSES 64 namespace ZeroTier { diff --git a/node/Str.hpp b/node/Str.hpp index 647790e05..c805c2c7c 100644 --- a/node/Str.hpp +++ b/node/Str.hpp @@ -197,6 +197,23 @@ public: return h; } + template + inline void serialize(Buffer &b,const bool forSign = false) const + { + b.append(_l); + b.append(_s,(unsigned int)_l); + } + + template + inline unsigned int deserialize(const Buffer &b,unsigned int startAt = 0) + { + unsigned int p = startAt; + _l = (uint8_t)b[p++]; + memcpy(_s,b.field(p,(unsigned int)_l),(unsigned long)_l); + p += (unsigned int)_l; + return (p - startAt); + } + private: uint8_t _l; char _s[ZT_STR_CAPACITY+1]; diff --git a/node/Topology.hpp b/node/Topology.hpp index 344f83c8d..2cdd0e6a7 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -64,7 +64,7 @@ private: unsigned int bestRootLatency; }; - ZT_ALWAYS_INLINE void _updateDynamicRootIdentities() + ZT_ALWAYS_INLINE void _updateRoots() { // assumes _roots_l is locked _rootIdentities.clear(); @@ -334,11 +334,13 @@ public: Locator &ll = _roots[name]; if (ll.timestamp() < latestLocator.timestamp()) { ll = latestLocator; - _updateDynamicRootIdentities(); + _updateRoots(); + _rootsModified = true; return true; } } else if (!_roots.contains(name)) { - _roots[name]; + _roots.set(name,Locator()); // no locator known yet, but add name to name list to trigger DNS refreshing + _rootsModified = true; return true; } return false; @@ -350,8 +352,10 @@ public: inline void removeRoot(const Str &name) { Mutex::Lock l(_roots_l); - _roots.erase(name); - _updateDynamicRootIdentities(); + if (_roots.erase(name)) { + _updateRoots(); + _rootsModified = true; + } } /** @@ -529,8 +533,10 @@ private: Hashtable< Address,SharedPtr > _peers; Hashtable< Path::HashKey,SharedPtr > _paths; + Hashtable< Str,Locator > _roots; Hashtable< Identity,bool > _rootIdentities; + bool _rootsModified; int64_t _lastUpdatedBestRoot; SharedPtr _bestRoot;