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/Topology.cpp | |
| parent | 5ce3aac929ef217f3e813b5bc948dd28d021835f (diff) | |
| download | infinitytier-f9f60f89d95e43e5c439bf7c86b015e1b41a2f14.tar.gz infinitytier-f9f60f89d95e43e5c439bf7c86b015e1b41a2f14.zip | |
Peer save/restore fix.
Diffstat (limited to 'node/Topology.cpp')
| -rw-r--r-- | node/Topology.cpp | 31 |
1 files changed, 10 insertions, 21 deletions
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 } |
