summaryrefslogtreecommitdiff
path: root/node/Peer.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-21 10:29:44 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-21 10:29:44 -0400
commit6e217dfcb01c923e54dd172d0dfca68ab8566bdd (patch)
tree703d1248b5ba010ed4669c2b9cf5a889419b0057 /node/Peer.hpp
parentbbfd43e03601add10aa04f8f2770285cb801d905 (diff)
downloadinfinitytier-6e217dfcb01c923e54dd172d0dfca68ab8566bdd.tar.gz
infinitytier-6e217dfcb01c923e54dd172d0dfca68ab8566bdd.zip
Get rid of DBM, which technically is a case of YAGNI. Supernodes will need a way to save identities, but that can be a different feature. Regular clients do not really need a permanent cache (yet). When/if we do need one we can do it then. Until then it only caused problems.
Diffstat (limited to 'node/Peer.hpp')
-rw-r--r--node/Peer.hpp60
1 files changed, 15 insertions, 45 deletions
diff --git a/node/Peer.hpp b/node/Peer.hpp
index 2106a787..6c123746 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -48,24 +48,6 @@
#include "NonCopyable.hpp"
#include "Mutex.hpp"
-/**
- * Max length of serialized peer record
- */
-#define ZT_PEER_MAX_SERIALIZED_LENGTH ( \
- ZT_PEER_SECRET_KEY_LENGTH + \
- ZT_IDENTITY_MAX_BINARY_SERIALIZED_LENGTH + \
- ( ( \
- (sizeof(uint64_t) * 4) + \
- sizeof(uint16_t) + \
- 1 + \
- sizeof(uint16_t) + \
- 16 + \
- 1 \
- ) * 2) + \
- (sizeof(uint64_t) * 3) + \
- (sizeof(uint16_t) * 3) \
-)
-
namespace ZeroTier {
/**
@@ -100,6 +82,16 @@ public:
throw(std::runtime_error);
/**
+ * @return Time peer record was last used in any way
+ */
+ inline uint64_t lastUsed() const throw() { return _lastUsed; }
+
+ /**
+ * @param now New time of last use
+ */
+ inline void setLastUsed(uint64_t now) throw() { _lastUsed = now; }
+
+ /**
* @return This peer's ZT address (short for identity().address())
*/
inline const Address &address() const throw() { return _id.address(); }
@@ -254,10 +246,8 @@ public:
{
if (addr == _ipv4p.addr) {
_ipv4p.latency = latency;
- _dirty = true;
} else if (addr == _ipv6p.addr) {
_ipv6p.latency = latency;
- _dirty = true;
}
}
@@ -357,33 +347,16 @@ public:
return std::string("?");
}
- /**
- * Get and reset dirty flag
- *
- * @return Previous value of dirty flag before reset
- */
- inline bool getAndResetDirty()
- throw()
- {
- bool d = _dirty;
- _dirty = false;
- return d;
- }
-
- /**
- * @return Current value of dirty flag
- */
- inline bool dirty() const throw() { return _dirty; }
-
template<unsigned int C>
inline void serialize(Buffer<C> &b)
throw(std::out_of_range)
{
- b.append((unsigned char)3); // version
+ b.append((unsigned char)4); // version
b.append(_key,sizeof(_key));
_id.serialize(b,false);
_ipv4p.serialize(b);
_ipv6p.serialize(b);
+ b.append(_lastUsed);
b.append(_lastUnicastFrame);
b.append(_lastMulticastFrame);
b.append(_lastAnnouncedTo);
@@ -398,13 +371,14 @@ public:
{
unsigned int p = startAt;
- if (b[p++] != 3)
+ if (b[p++] != 4)
throw std::invalid_argument("Peer: deserialize(): version mismatch");
memcpy(_key,b.field(p,sizeof(_key)),sizeof(_key)); p += sizeof(_key);
p += _id.deserialize(b,p);
p += _ipv4p.deserialize(b,p);
p += _ipv6p.deserialize(b,p);
+ _lastUsed = b.template at<uint64_t>(p); p += sizeof(uint64_t);
_lastUnicastFrame = b.template at<uint64_t>(p); p += sizeof(uint64_t);
_lastMulticastFrame = b.template at<uint64_t>(p); p += sizeof(uint64_t);
_lastAnnouncedTo = b.template at<uint64_t>(p); p += sizeof(uint64_t);
@@ -412,8 +386,6 @@ public:
_vMinor = b.template at<uint16_t>(p); p += sizeof(uint16_t);
_vRevision = b.template at<uint16_t>(p); p += sizeof(uint16_t);
- _dirty = false;
-
return (p - startAt);
}
@@ -538,14 +510,12 @@ private:
WanPath _ipv4p;
WanPath _ipv6p;
+ uint64_t _lastUsed;
uint64_t _lastUnicastFrame;
uint64_t _lastMulticastFrame;
uint64_t _lastAnnouncedTo;
unsigned int _vMajor,_vMinor,_vRevision;
- // Fields below this line are not persisted with serialize() ---------------
-
- bool _dirty;
AtomicCounter __refCount;
};