summaryrefslogtreecommitdiff
path: root/node/Peer.hpp
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2017-09-22 10:22:22 -0700
committerGrant Limberg <grant.limberg@zerotier.com>2017-09-22 10:22:22 -0700
commiteb42ef68eeb7a19a9b841cd9f3fe67ffb999c827 (patch)
tree9665109ab82fffdfb34ebb90e9d5759cf1dfdd3a /node/Peer.hpp
parent6842490c1feb572936d8b3893f6d3d07e289a878 (diff)
parent52916eebcfae2559966d12d4be4b5376289a982d (diff)
downloadinfinitytier-eb42ef68eeb7a19a9b841cd9f3fe67ffb999c827.tar.gz
infinitytier-eb42ef68eeb7a19a9b841cd9f3fe67ffb999c827.zip
Merge branch 'dev' of http://git.int.zerotier.com/ZeroTier/ZeroTierOne into dev
Diffstat (limited to 'node/Peer.hpp')
-rw-r--r--node/Peer.hpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/node/Peer.hpp b/node/Peer.hpp
index c6423a59..af9163a5 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -439,6 +439,90 @@ public:
return false;
}
+ /**
+ * Serialize a peer for storage in local cache
+ *
+ * This does not serialize everything, just identity and addresses where the peer
+ * may be reached.
+ */
+ template<unsigned int C>
+ inline void serialize(Buffer<C> &b) const
+ {
+ b.append((uint8_t)0);
+
+ _id.serialize(b);
+
+ b.append(_lastReceive);
+ b.append(_lastNontrivialReceive);
+ b.append(_lastTriedMemorizedPath);
+ b.append(_lastDirectPathPushSent);
+ b.append(_lastDirectPathPushReceive);
+ b.append(_lastCredentialRequestSent);
+ b.append(_lastWhoisRequestReceived);
+ b.append(_lastEchoRequestReceived);
+ b.append(_lastComRequestReceived);
+ b.append(_lastComRequestSent);
+ b.append(_lastCredentialsReceived);
+ b.append(_lastTrustEstablishedPacketReceived);
+
+ b.append((uint16_t)_vProto);
+ b.append((uint16_t)_vMajor);
+ b.append((uint16_t)_vMinor);
+ b.append((uint16_t)_vRevision);
+
+ {
+ Mutex::Lock _l(_paths_m);
+ unsigned int pcount = 0;
+ if (_v4Path.p) ++pcount;
+ if (_v6Path.p) ++pcount;
+ b.append((uint8_t)pcount);
+ if (_v4Path.p) _v4Path.p->address().serialize(b);
+ if (_v6Path.p) _v6Path.p->address().serialize(b);
+ }
+
+ b.append((uint16_t)0);
+ }
+
+ template<unsigned int C>
+ inline static SharedPtr<Peer> deserializeFromCache(uint64_t now,void *tPtr,Buffer<C> &b,const RuntimeEnvironment *renv)
+ {
+ try {
+ unsigned int ptr = 0;
+ if (b[ptr++] != 0)
+ return SharedPtr<Peer>();
+
+ Identity id;
+ ptr += id.deserialize(b,ptr);
+ if (!id)
+ return SharedPtr<Peer>();
+
+ SharedPtr<Peer> p(new Peer(renv,renv->identity,id));
+
+ ptr += 12 * 8; // skip deserializing ephemeral state in this case
+
+ p->_vProto = b.template at<uint16_t>(ptr); ptr += 2;
+ p->_vMajor = b.template at<uint16_t>(ptr); ptr += 2;
+ p->_vMinor = b.template at<uint16_t>(ptr); ptr += 2;
+ p->_vRevision = b.template at<uint16_t>(ptr); ptr += 2;
+
+ const unsigned int pcount = (unsigned int)b[ptr++];
+ for(unsigned int i=0;i<pcount;++i) {
+ InetAddress inaddr;
+ try {
+ ptr += inaddr.deserialize(b,ptr);
+ if (inaddr)
+ p->attemptToContactAt(tPtr,-1,inaddr,now,true,0);
+ } catch ( ... ) {
+ break;
+ }
+ }
+
+ return p;
+ } catch ( ... ) {
+ return SharedPtr<Peer>();
+ }
+ }
+
private:
struct _PeerPath
{