summaryrefslogtreecommitdiff
path: root/node/Topology.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2015-11-13 12:14:28 -0800
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2015-11-13 12:14:28 -0800
commit0d9f33dc4f14b7339d1893e79772a8e49b4821eb (patch)
treee7b3e1ee8ec92d57ce71482c64738f4211e5d9ff /node/Topology.cpp
parent90f9415107fded22346bfa94f98afa73c6c2811e (diff)
downloadinfinitytier-0d9f33dc4f14b7339d1893e79772a8e49b4821eb.tar.gz
infinitytier-0d9f33dc4f14b7339d1893e79772a8e49b4821eb.zip
Fix: (1) Windows stack overflow due to buffer too large in peer deserialize, (2) clean up some other stuff seen during debugging and reduce the sizes of some buffers due to Windows small stack size, (3) remove a redundant try/catch.
Diffstat (limited to 'node/Topology.cpp')
-rw-r--r--node/Topology.cpp31
1 files changed, 11 insertions, 20 deletions
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];