summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
Diffstat (limited to 'node')
-rw-r--r--node/Constants.hpp5
-rw-r--r--node/Path.hpp12
-rw-r--r--node/Peer.cpp157
-rw-r--r--node/Peer.hpp31
-rw-r--r--node/Topology.cpp5
5 files changed, 1 insertions, 209 deletions
diff --git a/node/Constants.hpp b/node/Constants.hpp
index 274b9564..12bf8d28 100644
--- a/node/Constants.hpp
+++ b/node/Constants.hpp
@@ -219,11 +219,6 @@
#define ZT_HOUSEKEEPING_PERIOD 60000
/**
- * How often in ms to write peer state to storage and/or cluster (approximate)
- */
-#define ZT_PEER_STATE_WRITE_PERIOD 10000
-
-/**
* How long to remember peer records in RAM if they haven't been used
*/
#define ZT_PEER_IN_MEMORY_EXPIRATION 600000
diff --git a/node/Path.hpp b/node/Path.hpp
index 854b28e2..ac8e4c0e 100644
--- a/node/Path.hpp
+++ b/node/Path.hpp
@@ -284,18 +284,6 @@ public:
inline uint64_t lastTrustEstablishedPacketReceived() const { return _lastTrustEstablishedPacketReceived; }
/**
- * @param lo Last out send
- * @param li Last in send
- * @param lt Last trust established packet received
- */
- inline void updateFromRemoteState(const uint64_t lo,const uint64_t li,const uint64_t lt)
- {
- _lastOut = lo;
- _lastIn = li;
- _lastTrustEstablishedPacketReceived = lt;
- }
-
- /**
* Return and increment outgoing packet counter (used with Packet::armor())
*
* @return Next value that should be used for outgoing packet counter (only least significant 3 bits are used)
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 875d651e..fb9a72b1 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -38,8 +38,6 @@ namespace ZeroTier {
Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Identity &peerIdentity) :
RR(renv),
- _lastWroteState(0),
- _lastReceivedStateTimestamp(0),
_lastReceive(0),
_lastNontrivialReceive(0),
_lastTriedMemorizedPath(0),
@@ -184,7 +182,6 @@ void Peer::received(
if (verb == Packet::VERB_OK) {
potentialNewPeerPath->lr = now;
potentialNewPeerPath->p = path;
- _lastWroteState = 0; // force state write now
} else {
TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),path->address().toString().c_str());
attemptToContactAt(tPtr,path->localSocket(),path->address(),now,true,path->nextOutgoingCounter());
@@ -263,9 +260,6 @@ void Peer::received(
}
}
}
-
- if ((now - _lastWroteState) > ZT_PEER_STATE_WRITE_PERIOD)
- writeState(tPtr,now);
}
bool Peer::sendDirect(void *tPtr,const void *data,unsigned int len,uint64_t now,bool force)
@@ -428,155 +422,4 @@ bool Peer::doPingAndKeepalive(void *tPtr,uint64_t now,int inetAddressFamily)
return false;
}
-void Peer::writeState(void *tPtr,const uint64_t now)
-{
- try {
- Buffer<ZT_PEER_MAX_SERIALIZED_STATE_SIZE> b;
-
- b.append((uint8_t)1); // version
- b.append(now);
-
- _id.serialize(b);
-
- {
- Mutex::Lock _l(_paths_m);
- unsigned int count = 0;
- if (_v4Path.lr)
- ++count;
- if (_v6Path.lr)
- ++count;
- b.append((uint8_t)count);
- if (_v4Path.lr) {
- b.append(_v4Path.lr);
- b.append(_v4Path.p->lastOut());
- b.append(_v4Path.p->lastIn());
- b.append(_v4Path.p->lastTrustEstablishedPacketReceived());
- _v4Path.p->address().serialize(b);
- }
- if (_v6Path.lr) {
- b.append(_v6Path.lr);
- b.append(_v6Path.p->lastOut());
- b.append(_v6Path.p->lastIn());
- b.append(_v6Path.p->lastTrustEstablishedPacketReceived());
- _v6Path.p->address().serialize(b);
- }
- }
-
- // Save space by sending these as time since now at 100ms resolution
- b.append((uint16_t)(std::max(now - _lastReceive,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastNontrivialReceive,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastTriedMemorizedPath,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastDirectPathPushSent,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastDirectPathPushReceive,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastCredentialRequestSent,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastWhoisRequestReceived,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastEchoRequestReceived,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastComRequestReceived,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastComRequestSent,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastCredentialsReceived,(uint64_t)6553500) / 100));
- b.append((uint16_t)(std::max(now - _lastTrustEstablishedPacketReceived,(uint64_t)6553500) / 100));
-
- b.append((uint8_t)_vProto);
- b.append((uint8_t)_vMajor);
- b.append((uint8_t)_vMinor);
- b.append((uint16_t)_vRevision);
-
- b.append((uint16_t)0); // length of additional fields
-
- uint64_t tmp[2];
- tmp[0] = _id.address().toInt(); tmp[1] = 0;
- //RR->node->stateObjectPut(tPtr,ZT_STATE_OBJECT_PEER_STATE,tmp,b.data(),b.size());
-
- _lastWroteState = now;
- } catch ( ... ) {} // sanity check, should not be possible
-}
-
-bool Peer::applyStateUpdate(const void *data,unsigned int len)
-{
- try {
- Buffer<ZT_PEER_MAX_SERIALIZED_STATE_SIZE> b(data,len);
- unsigned int ptr = 0;
-
- if (b[ptr++] != 1)
- return false;
- const uint64_t ts = b.at<uint64_t>(ptr); ptr += 8;
- if (ts <= _lastReceivedStateTimestamp)
- return false;
-
- Identity id;
- ptr += id.deserialize(b,ptr);
- if (id != _id) // sanity check
- return false;
-
- const unsigned int pathCount = (unsigned int)b[ptr++];
- {
- Mutex::Lock _l(_paths_m);
- for(unsigned int i=0;i<pathCount;++i) {
- const uint64_t lr = b.at<uint64_t>(ptr); ptr += 8;
- const uint64_t lastOut = b.at<uint64_t>(ptr); ptr += 8;
- const uint64_t lastIn = b.at<uint64_t>(ptr); ptr += 8;
- const uint64_t lastTrustEstablishedPacketReceived = b.at<uint64_t>(ptr); ptr += 8;
- InetAddress addr;
- ptr += addr.deserialize(b,ptr);
- _PeerPath *p = (_PeerPath *)0;
- switch(addr.ss_family) {
- case AF_INET: p = &_v4Path; break;
- case AF_INET6: p = &_v6Path; break;
- }
- if (p) {
- if ( (!p->p) || (p->p->address() != addr) ) {
- p->p = RR->topology->getPath(-1,addr);
- }
- p->lr = lr;
- p->p->updateFromRemoteState(lastOut,lastIn,lastTrustEstablishedPacketReceived);
- }
- }
- }
-
- _lastReceive = std::max(_lastReceive,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastNontrivialReceive = std::max(_lastNontrivialReceive,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastTriedMemorizedPath = std::max(_lastTriedMemorizedPath,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastDirectPathPushSent = std::max(_lastDirectPathPushSent,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastDirectPathPushReceive = std::max(_lastDirectPathPushReceive,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastCredentialRequestSent = std::max(_lastCredentialRequestSent,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastWhoisRequestReceived = std::max(_lastWhoisRequestReceived,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastEchoRequestReceived = std::max(_lastEchoRequestReceived,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastComRequestReceived = std::max(_lastComRequestReceived,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastComRequestSent = std::max(_lastComRequestSent,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastCredentialsReceived = std::max(_lastCredentialsReceived,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
- _lastTrustEstablishedPacketReceived = std::max(_lastTrustEstablishedPacketReceived,ts - ((uint64_t)b.at<uint16_t>(ptr) * 100ULL)); ptr += 2;
-
- _vProto = (uint16_t)b[ptr++];
- _vMajor = (uint16_t)b[ptr++];
- _vMinor = (uint16_t)b[ptr++];
- _vRevision = b.at<uint16_t>(ptr); ptr += 2;
-
- _lastReceivedStateTimestamp = ts;
-
- return true;
- } catch ( ... ) {} // ignore invalid state updates
- return false;
-}
-
-SharedPtr<Peer> Peer::createFromStateUpdate(const RuntimeEnvironment *renv,void *tPtr,const void *data,unsigned int len)
-{
- try {
- Identity id;
- {
- Buffer<ZT_PEER_MAX_SERIALIZED_STATE_SIZE> b(data,len);
- unsigned int ptr = 0;
- if (b[ptr++] != 1)
- return SharedPtr<Peer>();
- ptr += 8; // skip TS, don't care
- id.deserialize(b,ptr);
- }
- if (id) {
- const SharedPtr<Peer> p(new Peer(renv,renv->identity,id));
- if (p->applyStateUpdate(data,len))
- return renv->topology->addPeer(tPtr,p);
- }
- } catch ( ... ) {}
- return SharedPtr<Peer>();
-}
-
} // namespace ZeroTier
diff --git a/node/Peer.hpp b/node/Peer.hpp
index 478c7232..ad2d0ddc 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -196,23 +196,6 @@ public:
bool doPingAndKeepalive(void *tPtr,uint64_t now,int inetAddressFamily);
/**
- * Write object state to external storage and/or cluster network
- *
- * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
- * @param now Current time
- */
- void writeState(void *tPtr,const uint64_t now);
-
- /**
- * Apply a state update received from e.g. a remote cluster member
- *
- * @param data State update data
- * @param len Length of state update
- * @return True if state update was applied, false if ignored or invalid
- */
- bool applyStateUpdate(const void *data,unsigned int len);
-
- /**
* Reset paths within a given IP scope and address family
*
* Resetting a path involves sending an ECHO to it and then deactivating
@@ -440,17 +423,6 @@ public:
return false;
}
- /**
- * Create a peer from a remote state update
- *
- * @param renv Runtime environment
- * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
- * @param data State update data
- * @param len State update length
- * @return Peer or NULL if data was invalid
- */
- static SharedPtr<Peer> createFromStateUpdate(const RuntimeEnvironment *renv,void *tPtr,const void *data,unsigned int len);
-
private:
struct _PeerPath
{
@@ -463,9 +435,6 @@ private:
const RuntimeEnvironment *RR;
- uint64_t _lastWroteState;
- uint64_t _lastReceivedStateTimestamp;
-
uint64_t _lastReceive; // direct or indirect
uint64_t _lastNontrivialReceive; // frames, things like netconf, etc.
uint64_t _lastTriedMemorizedPath;
diff --git a/node/Topology.cpp b/node/Topology.cpp
index d4632f43..809bc7e7 100644
--- a/node/Topology.cpp
+++ b/node/Topology.cpp
@@ -395,11 +395,8 @@ void Topology::doPeriodicTasks(void *tPtr,uint64_t now)
Address *a = (Address *)0;
SharedPtr<Peer> *p = (SharedPtr<Peer> *)0;
while (i.next(a,p)) {
- if ( (!(*p)->isAlive(now)) && (std::find(_upstreamAddresses.begin(),_upstreamAddresses.end(),*a) == _upstreamAddresses.end()) ) {
+ if ( (!(*p)->isAlive(now)) && (std::find(_upstreamAddresses.begin(),_upstreamAddresses.end(),*a) == _upstreamAddresses.end()) )
_peers.erase(*a);
- } else {
- (*p)->writeState(tPtr,now);
- }
}
}