diff options
Diffstat (limited to 'node')
-rw-r--r-- | node/AntiRecursion.hpp | 7 | ||||
-rw-r--r-- | node/Cluster.cpp | 4 | ||||
-rw-r--r-- | node/Identity.cpp | 2 | ||||
-rw-r--r-- | node/Node.cpp | 33 | ||||
-rw-r--r-- | node/Topology.cpp | 31 | ||||
-rw-r--r-- | node/Topology.hpp | 16 |
6 files changed, 51 insertions, 42 deletions
diff --git a/node/AntiRecursion.hpp b/node/AntiRecursion.hpp index 8629d19a..4d9df465 100644 --- a/node/AntiRecursion.hpp +++ b/node/AntiRecursion.hpp @@ -58,7 +58,12 @@ class AntiRecursion public: AntiRecursion() { - memset(_history,0,sizeof(_history)); + for(int i=0;i<ZT_ANTIRECURSION_HISTORY_SIZE;++i) { + _history[i].tail[0] = 0; + _history[i].tail[1] = 0; + _history[i].tail[2] = 0; + _history[i].tail[3] = 0; + } _ptr = 0; } diff --git a/node/Cluster.cpp b/node/Cluster.cpp index af9ab854..fa9a1611 100644 --- a/node/Cluster.cpp +++ b/node/Cluster.cpp @@ -628,7 +628,7 @@ void Cluster::doPeriodicTasks() } alive.append((uint64_t)now); alive.append((uint64_t)0); // TODO: compute and send load average - alive.append((uint64_t)RR->topology->countActive()); + alive.append((uint64_t)RR->topology->countActive(now)); alive.append((uint64_t)0); // unused/reserved flags alive.append((uint8_t)_zeroTierPhysicalEndpoints.size()); for(std::vector<InetAddress>::const_iterator pe(_zeroTierPhysicalEndpoints.begin());pe!=_zeroTierPhysicalEndpoints.end();++pe) @@ -769,7 +769,7 @@ void Cluster::status(ZT_ClusterStatus &status) const s->y = _y; s->z = _z; s->load = 0; // TODO - s->peers = RR->topology->countActive(); + s->peers = RR->topology->countActive(now); for(std::vector<InetAddress>::const_iterator ep(_zeroTierPhysicalEndpoints.begin());ep!=_zeroTierPhysicalEndpoints.end();++ep) { if (s->numZeroTierPhysicalEndpoints >= ZT_CLUSTER_MAX_ZT_PHYSICAL_ADDRESSES) // sanity check break; diff --git a/node/Identity.cpp b/node/Identity.cpp index e5aaf13d..4611f6a5 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -158,7 +158,7 @@ bool Identity::fromString(const char *str) return false; char *saveptr = (char *)0; - char tmp[4096]; + char tmp[1024]; if (!Utils::scopy(tmp,sizeof(tmp),str)) return false; diff --git a/node/Node.cpp b/node/Node.cpp index 4b449401..f077424b 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -93,21 +93,22 @@ Node::Node( _prng.encrypt12(_prngStream,_prngStream,sizeof(_prngStream)); } - std::string idtmp(dataStoreGet("identity.secret")); - if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) { - TRACE("identity.secret not found, generating..."); - RR->identity.generate(); - idtmp = RR->identity.toString(true); - if (!dataStorePut("identity.secret",idtmp,true)) - throw std::runtime_error("unable to write identity.secret"); - } - RR->publicIdentityStr = RR->identity.toString(false); - RR->secretIdentityStr = RR->identity.toString(true); - - idtmp = dataStoreGet("identity.public"); - if (idtmp != RR->publicIdentityStr) { - if (!dataStorePut("identity.public",RR->publicIdentityStr,false)) - throw std::runtime_error("unable to write identity.public"); + { + std::string idtmp(dataStoreGet("identity.secret")); + if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) { + TRACE("identity.secret not found, generating..."); + RR->identity.generate(); + idtmp = RR->identity.toString(true); + if (!dataStorePut("identity.secret",idtmp,true)) + throw std::runtime_error("unable to write identity.secret"); + } + RR->publicIdentityStr = RR->identity.toString(false); + RR->secretIdentityStr = RR->identity.toString(true); + idtmp = dataStoreGet("identity.public"); + if (idtmp != RR->publicIdentityStr) { + if (!dataStorePut("identity.public",RR->publicIdentityStr,false)) + throw std::runtime_error("unable to write identity.public"); + } } try { @@ -662,7 +663,7 @@ void Node::backgroundThreadMain() std::string Node::dataStoreGet(const char *name) { - char buf[16384]; + char buf[1024]; std::string r; unsigned long olen = 0; do { diff --git a/node/Topology.cpp b/node/Topology.cpp index 5379ac1f..1617dd94 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -50,6 +50,7 @@ Topology::Topology(const RuntimeEnvironment *renv) : const uint8_t *all = reinterpret_cast<const uint8_t *>(alls.data()); RR->node->dataStoreDelete("peers.save"); + Buffer<ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE> *deserializeBuf = new Buffer<ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE>(); unsigned int ptr = 0; while ((ptr + 4) < alls.size()) { try { @@ -60,7 +61,8 @@ Topology::Topology(const RuntimeEnvironment *renv) : (((unsigned int)all[ptr + 3]) & 0xff) ); unsigned int pos = 0; - SharedPtr<Peer> p(Peer::deserializeNew(RR->identity,Buffer<ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE>(all + ptr,reclen + 4),pos)); + deserializeBuf->copyFrom(all + ptr,reclen + 4); + SharedPtr<Peer> p(Peer::deserializeNew(RR->identity,*deserializeBuf,pos)); ptr += pos; if (!p) break; // stop if invalid records @@ -70,16 +72,19 @@ Topology::Topology(const RuntimeEnvironment *renv) : break; // stop if invalid records } } + delete deserializeBuf; clean(RR->node->now()); std::string dsWorld(RR->node->dataStoreGet("world")); World cachedWorld; - try { - Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> dswtmp(dsWorld.data(),(unsigned int)dsWorld.length()); - cachedWorld.deserialize(dswtmp,0); - } catch ( ... ) { - cachedWorld = World(); // clear if cached world is invalid + if (dsWorld.length() > 0) { + try { + Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> dswtmp(dsWorld.data(),(unsigned int)dsWorld.length()); + cachedWorld.deserialize(dswtmp,0); + } catch ( ... ) { + cachedWorld = World(); // clear if cached world is invalid + } } World defaultWorld; { @@ -315,20 +320,6 @@ void Topology::clean(uint64_t now) } } -unsigned long Topology::countActive() const -{ - const uint64_t now = RR->node->now(); - unsigned long cnt = 0; - Mutex::Lock _l(_lock); - Hashtable< Address,SharedPtr<Peer> >::Iterator i(const_cast<Topology *>(this)->_peers); - Address *a = (Address *)0; - SharedPtr<Peer> *p = (SharedPtr<Peer> *)0; - while (i.next(a,p)) { - cnt += (unsigned long)((*p)->hasActiveDirectPath(now)); - } - return cnt; -} - Identity Topology::_getIdentity(const Address &zta) { char p[128]; diff --git a/node/Topology.hpp b/node/Topology.hpp index 68ad273f..a9a5f2f9 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -200,9 +200,21 @@ public: void clean(uint64_t now); /** + * @param now Current time * @return Number of peers with active direct paths */ - unsigned long countActive() const; + inline unsigned long countActive(uint64_t now) const + { + unsigned long cnt = 0; + Mutex::Lock _l(_lock); + Hashtable< Address,SharedPtr<Peer> >::Iterator i(const_cast<Topology *>(this)->_peers); + Address *a = (Address *)0; + SharedPtr<Peer> *p = (SharedPtr<Peer> *)0; + while (i.next(a,p)) { + cnt += (unsigned long)((*p)->hasActiveDirectPath(now)); + } + return cnt; + } /** * Apply a function or function object to all peers @@ -253,7 +265,7 @@ private: Identity _getIdentity(const Address &zta); void _setWorld(const World &newWorld); - const RuntimeEnvironment *RR; + const RuntimeEnvironment *const RR; World _world; Hashtable< Address,SharedPtr<Peer> > _peers; |