Browse Source

Use getPeerNoCache() in Cluster to avoid keeping all peers cached everywhere.

Adam Ierymenko 9 years ago
parent
commit
4221552c0b
2 changed files with 20 additions and 2 deletions
  1. 3 2
      node/Cluster.cpp
  2. 17 0
      node/Topology.hpp

+ 3 - 2
node/Cluster.cpp

@@ -210,6 +210,7 @@ void Cluster::handleIncomingStateMessage(const void *msg,unsigned int len)
 						}	break;
 						}	break;
 
 
 						case STATE_MESSAGE_HAVE_PEER: {
 						case STATE_MESSAGE_HAVE_PEER: {
+							const uint64_t now = RR->node->now();
 							Identity id;
 							Identity id;
 							InetAddress physicalAddress;
 							InetAddress physicalAddress;
 							ptr += id.deserialize(dmsg,ptr);
 							ptr += id.deserialize(dmsg,ptr);
@@ -217,7 +218,7 @@ void Cluster::handleIncomingStateMessage(const void *msg,unsigned int len)
 							if (id) {
 							if (id) {
 								// Forget any paths that we have to this peer at its address
 								// Forget any paths that we have to this peer at its address
 								if (physicalAddress) {
 								if (physicalAddress) {
-									SharedPtr<Peer> myPeerRecord(RR->topology->getPeer(id.address()));
+									SharedPtr<Peer> myPeerRecord(RR->topology->getPeerNoCache(id.address(),now));
 									if (myPeerRecord)
 									if (myPeerRecord)
 										myPeerRecord->removePathByAddress(physicalAddress);
 										myPeerRecord->removePathByAddress(physicalAddress);
 								}
 								}
@@ -229,7 +230,7 @@ void Cluster::handleIncomingStateMessage(const void *msg,unsigned int len)
 								{
 								{
 									Mutex::Lock _l2(_peerAffinities_m);
 									Mutex::Lock _l2(_peerAffinities_m);
 									_PA &pa = _peerAffinities[id.address()];
 									_PA &pa = _peerAffinities[id.address()];
-									pa.ts = RR->node->now();
+									pa.ts = now;
 									pa.mid = fromMemberId;
 									pa.mid = fromMemberId;
 		 						}
 		 						}
 		 						TRACE("[%u] has %s @ %s",(unsigned int)fromMemberId,id.address().toString().c_str(),physicalAddress.toString().c_str());
 		 						TRACE("[%u] has %s @ %s",(unsigned int)fromMemberId,id.address().toString().c_str(),physicalAddress.toString().c_str());

+ 17 - 0
node/Topology.hpp

@@ -78,6 +78,23 @@ public:
 	 */
 	 */
 	SharedPtr<Peer> getPeer(const Address &zta);
 	SharedPtr<Peer> getPeer(const Address &zta);
 
 
+	/**
+	 * Get a peer only if it is presently in memory (no disk cache)
+	 *
+	 * @param zta ZeroTier address
+	 * @param now Current time
+	 */
+	inline SharedPtr<Peer> getPeerNoCache(const Address &zta,const uint64_t now)
+	{
+		Mutex::Lock _l(_lock);
+		const SharedPtr<Peer> *ap = _peers.get(zta);
+		if (ap) {
+			(*ap)->use(now);
+			return *ap;
+		}
+		return SharedPtr<Peer>();
+	}
+
 	/**
 	/**
 	 * Get the identity of a peer
 	 * Get the identity of a peer
 	 *
 	 *