diff --git a/LICENSE.txt b/LICENSE.txt index 78daf4c2a..fac95b787 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -10,7 +10,7 @@ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. Parameters Licensor: ZeroTier, Inc. -Licensed Work: ZeroTier Network Virtualization Engine 1.4.4 +Licensed Work: ZeroTier Network Virtualization Engine The Licensed Work is (c)2019 ZeroTier, Inc. Additional Use Grant: You may make use of the Licensed Work, provided you do not use it in any of the following ways: @@ -26,7 +26,7 @@ Additional Use Grant: You may make use of the Licensed Work, provided you ZeroTier behind the scenes to operate a service not related to ZeroTier network administration. - * Create Non-Open-Source Commercial Derviative Works + * Create Non-Open-Source Commercial Derivative Works (2) Link or directly include the Licensed Work in a commercial or for-profit application or other product diff --git a/node/Locator.hpp b/node/Locator.hpp index 81e57676a..06c278bfa 100644 --- a/node/Locator.hpp +++ b/node/Locator.hpp @@ -22,6 +22,7 @@ #include "SHA512.hpp" #include "Str.hpp" #include "ScopedPtr.hpp" +#include "SharedPtr.hpp" #include #include @@ -43,6 +44,8 @@ namespace ZeroTier { */ class Locator { + friend class SharedPtr; + public: ZT_ALWAYS_INLINE Locator() : _ts(0),_signatureLength(0) {} @@ -371,6 +374,7 @@ private: std::vector _virtual; unsigned int _signatureLength; uint8_t _signature[ZT_SIGNATURE_BUFFER_SIZE]; + AtomicCounter __refCount; }; } // namespace ZeroTier diff --git a/node/Node.cpp b/node/Node.cpp index 9aeccf8aa..ddd888d21 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -639,6 +639,33 @@ void Node::setController(void *networkControllerInstance) /* Node methods used only within node/ */ /****************************************************************************/ +SharedPtr< const Locator > Node::locator() +{ + Mutex::Lock lck(_locator_m); + if (!_locator) { + Locator *l = new Locator(); + try { + RR->topology->eachRoot([l](const SharedPtr &p,const std::vector &phyAddr) -> bool { + l->add(p->identity()); + return true; + }); + { + Mutex::Lock lck2(_localInterfaceAddresses_m); + for(std::vector< ZT_InterfaceAddress >::const_iterator a(_localInterfaceAddresses.begin());a!=_localInterfaceAddresses.end();++a) { + if (a->permanent != 0) { + l->add(*reinterpret_cast(&(a->address))); + } + } + } + } catch ( ... ) { + delete l; + throw; + } + _locator.set(l); + } + return _locator; +} + bool Node::shouldUsePathForZeroTierTraffic(void *tPtr,const Address &ztaddr,const int64_t localSocket,const InetAddress &remoteAddress) { if (!Path::isAddressValidForPath(remoteAddress)) diff --git a/node/Node.hpp b/node/Node.hpp index 6136c2d8e..16e6824fc 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -41,6 +41,8 @@ namespace ZeroTier { +class Locator; + /** * Implementation of Node object as defined in CAPI * @@ -175,6 +177,7 @@ public: void setInterfaceAddresses(const ZT_InterfaceAddress *addrs,unsigned int addrCount); + SharedPtr< const Locator > locator(); ZT_ALWAYS_INLINE void postEvent(void *tPtr,ZT_Event ev,const void *md = (const void *)0) { _cb.eventCallback(reinterpret_cast(this),_uPtr,tPtr,ev,md); } ZT_ALWAYS_INLINE void configureVirtualNetworkPort(void *tPtr,uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { _cb.virtualNetworkConfigFunction(reinterpret_cast(this),_uPtr,tPtr,nwid,nuptr,op,nc); } ZT_ALWAYS_INLINE bool online() const { return _online; } @@ -284,14 +287,14 @@ private: ZT_ALWAYS_INLINE bool operator!=(const _LocalControllerAuth &a) const { return ((a.nwid != nwid)||(a.address != address)); } }; Hashtable< _LocalControllerAuth,int64_t > _localControllerAuthorizations; - Mutex _localControllerAuthorizations_m; - Hashtable< uint64_t,SharedPtr > _networks; + SharedPtr< const Locator > _locator; + std::vector< ZT_InterfaceAddress > _localInterfaceAddresses; + + Mutex _localControllerAuthorizations_m; Mutex _networks_m; - - std::vector _localInterfaceAddresses; + Mutex _locator_m; Mutex _localInterfaceAddresses_m; - Mutex _backgroundTasksLock; uint8_t _multipathMode; diff --git a/node/Peer.hpp b/node/Peer.hpp index 0ac413f1b..3f658b555 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -525,8 +525,6 @@ private: unsigned int _QoSCutoffCount; unsigned int _ACKCutoffCount; - AtomicCounter __refCount; - RingBuffer _pathChoiceHist; bool _linkIsBalanced; @@ -537,6 +535,8 @@ private: int64_t _lastAggregateAllocation; char _interfaceListStr[256]; // 16 characters * 16 paths in a link + + AtomicCounter __refCount; }; } // namespace ZeroTier diff --git a/node/Topology.hpp b/node/Topology.hpp index 2cdd0e6a7..fc66b665a 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -70,7 +70,7 @@ private: _rootIdentities.clear(); Hashtable< Str,Locator >::Iterator i(_roots); Str *k = (Str *)0; - Locator *v = (Locator *)0; + SharedPtr< const Locator > *v = (SharedPtr< const Locator > *)0; while (i.next(k,v)) { if (*v) _rootIdentities.set(v->id(),true); @@ -534,7 +534,7 @@ private: Hashtable< Address,SharedPtr > _peers; Hashtable< Path::HashKey,SharedPtr > _paths; - Hashtable< Str,Locator > _roots; + Hashtable< Str,SharedPtr > _roots; Hashtable< Identity,bool > _rootIdentities; bool _rootsModified;