diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-16 10:45:58 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-16 10:45:58 -0700 |
commit | f9f60f89d95e43e5c439bf7c86b015e1b41a2f14 (patch) | |
tree | 80c9428afced097efc914907a6432634ad155b2a /node | |
parent | 5ce3aac929ef217f3e813b5bc948dd28d021835f (diff) | |
download | infinitytier-f9f60f89d95e43e5c439bf7c86b015e1b41a2f14.tar.gz infinitytier-f9f60f89d95e43e5c439bf7c86b015e1b41a2f14.zip |
Peer save/restore fix.
Diffstat (limited to 'node')
-rw-r--r-- | node/Peer.hpp | 8 | ||||
-rw-r--r-- | node/Topology.cpp | 31 |
2 files changed, 14 insertions, 25 deletions
diff --git a/node/Peer.hpp b/node/Peer.hpp index 043519d4..7e7e7f46 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -470,7 +470,7 @@ public: b.append((uint16_t)_vRevision); b.append((uint32_t)_latency); - b.append((uint32_t)_numPaths); + b.append((uint16_t)_numPaths); for(unsigned int i=0;i<_numPaths;++i) _paths[i].serialize(b); @@ -497,7 +497,7 @@ public: } } - b.setAt(recSizePos,(uint32_t)((b.size() - 4) - recSizePos)); // set size + b.template setAt<uint32_t>(recSizePos,(uint32_t)(b.size() - (recSizePos + 4))); // set size } /** @@ -511,7 +511,7 @@ public: template<unsigned int C> static inline SharedPtr<Peer> deserializeNew(const Identity &myIdentity,const Buffer<C> &b,unsigned int &p) { - const uint32_t recSize = b.template at<uint32_t>(p); p += 4; + const unsigned int recSize = b.template at<uint32_t>(p); p += 4; if ((p + recSize) > b.size()) return SharedPtr<Peer>(); // size invalid if (b.template at<uint16_t>(p) != 1) @@ -540,7 +540,7 @@ public: np->_vRevision = b.template at<uint16_t>(p); p += 2; np->_latency = b.template at<uint32_t>(p); p += 4; - const unsigned int numPaths = b.template at<uint32_t>(p); p += 4; + const unsigned int numPaths = b.template at<uint16_t>(p); p += 2; for(unsigned int i=0;i<numPaths;++i) { if (i < ZT_MAX_PEER_NETWORK_PATHS) { p += np->_paths[np->_numPaths++].deserialize(b,p); diff --git a/node/Topology.cpp b/node/Topology.cpp index a3558558..6e8467c1 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -47,31 +47,20 @@ Topology::Topology(const RuntimeEnvironment *renv) : unsigned int ptr = 0; while ((ptr + 4) < alls.size()) { - // Each Peer serializes itself prefixed by a record length (not including the size of the length itself) - unsigned int reclen = (unsigned int)all[ptr] & 0xff; - reclen <<= 8; - reclen |= (unsigned int)all[ptr + 1] & 0xff; - reclen <<= 8; - reclen |= (unsigned int)all[ptr + 2] & 0xff; - reclen <<= 8; - reclen |= (unsigned int)all[ptr + 3] & 0xff; - - if (((ptr + reclen) > alls.size())||(reclen > ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE)) - break; - try { + const unsigned int reclen = ( // each Peer serialized record is prefixed by a record length + ((((unsigned int)all[ptr]) & 0xff) << 24) | + ((((unsigned int)all[ptr + 1]) & 0xff) << 16) | + ((((unsigned int)all[ptr + 2]) & 0xff) << 8) | + (((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),pos)); - if (pos != reclen) - break; + SharedPtr<Peer> p(Peer::deserializeNew(RR->identity,Buffer<ZT_PEER_SUGGESTED_SERIALIZATION_BUFFER_SIZE>(all + ptr,reclen + 4),pos)); ptr += pos; - if ((p)&&(p->address() != RR->identity.address())) { - _peers[p->address()] = p; - } else { + if (!p) break; // stop if invalid records - } - } catch (std::exception &exc) { - break; + if (p->address() != RR->identity.address()) + _peers[p->address()] = p; } catch ( ... ) { break; // stop if invalid records } |