Browse Source

Cleanup, including simplification of root server picking algorithm since we no longer need all that craziness.

Adam Ierymenko 9 years ago
parent
commit
8a7a0b6b88
3 changed files with 51 additions and 2 deletions
  1. 1 1
      node/Cluster.cpp
  2. 14 1
      node/Cluster.hpp
  3. 36 0
      node/Topology.cpp

+ 1 - 1
node/Cluster.cpp

@@ -239,7 +239,7 @@ void Cluster::handleIncomingStateMessage(const void *msg,unsigned int len)
 							const MAC mac(dmsg.field(ptr,6),6); ptr += 6;
 							const MAC mac(dmsg.field(ptr,6),6); ptr += 6;
 							const uint32_t adi = dmsg.at<uint32_t>(ptr); ptr += 4;
 							const uint32_t adi = dmsg.at<uint32_t>(ptr); ptr += 4;
 							RR->mc->add(RR->node->now(),nwid,MulticastGroup(mac,adi),address);
 							RR->mc->add(RR->node->now(),nwid,MulticastGroup(mac,adi),address);
-							TRACE("[%u] %s likes %s/%u on %.16llu",(unsigned int)fromMemberId,address.toString().c_str(),mac.toString().c_str(),(unsigned int)adi,nwid);
+							TRACE("[%u] %s likes %s/%.8x on %.16llu",(unsigned int)fromMemberId,address.toString().c_str(),mac.toString().c_str(),(unsigned int)adi,nwid);
 						}	break;
 						}	break;
 
 
 						case STATE_MESSAGE_COM: {
 						case STATE_MESSAGE_COM: {

+ 14 - 1
node/Cluster.hpp

@@ -158,7 +158,20 @@ public:
 		 * while PROXY_SEND is used to implement proxy sending (which right
 		 * while PROXY_SEND is used to implement proxy sending (which right
 		 * now is only used to send RENDEZVOUS).
 		 * now is only used to send RENDEZVOUS).
 		 */
 		 */
-		STATE_MESSAGE_PROXY_SEND = 6
+		STATE_MESSAGE_PROXY_SEND = 6,
+
+		/**
+		 * Replicate a network config for a network we belong to:
+		 *   <[8] 64-bit network ID>
+		 *   <[2] 16-bit length of network config>
+		 *   <[...] serialized network config>
+		 *
+		 * This is used by clusters to avoid every member having to query
+		 * for the same netconf for networks all members belong to.
+		 *
+		 * TODO: not implemented yet!
+		 */
+		STATE_MESSAGE_NETWORK_CONFIG = 7
 	};
 	};
 
 
 	/**
 	/**

+ 36 - 0
node/Topology.cpp

@@ -215,10 +215,45 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
 				}
 				}
 			}
 			}
 		}
 		}
+
 	} else {
 	} else {
 		/* If I am not a root server, the best root server is the active one with
 		/* If I am not a root server, the best root server is the active one with
 		 * the lowest latency. */
 		 * the lowest latency. */
 
 
+		unsigned int bestLatencyOverall = ~((unsigned int)0);
+		unsigned int bestLatencyNotAvoid = ~((unsigned int)0);
+		const SharedPtr<Peer> *bestOverall = (const SharedPtr<Peer> *)0;
+		const SharedPtr<Peer> *bestNotAvoid = (const SharedPtr<Peer> *)0;
+
+		for(std::vector< SharedPtr<Peer> >::const_iterator r(_rootPeers.begin());r!=_rootPeers.end();++r) {
+			if ((*r)->hasActiveDirectPath(now)) {
+				bool avoiding = false;
+				for(unsigned int i=0;i<avoidCount;++i) {
+					if (avoid[i] == (*r)->address()) {
+						avoiding = true;
+						break;
+					}
+				}
+				unsigned int l = (*r)->latency();
+				if (!l) l = ~l; // zero latency indicates no measurment, so make this 'max'
+				if (l <= bestLatencyOverall) {
+					bestLatencyOverall = l;
+					bestOverall = &(*r);
+				}
+				if ((!avoiding)&&(l <= bestLatencyNotAvoid)) {
+					bestLatencyNotAvoid = l;
+					bestNotAvoid = &(*r);
+				}
+			}
+		}
+
+		if (bestNotAvoid)
+			return *bestNotAvoid;
+		else if ((!strictAvoid)&&(bestOverall))
+			return *bestOverall;
+		return SharedPtr<Peer>();
+
+		/*
 		unsigned int l,bestLatency = 65536;
 		unsigned int l,bestLatency = 65536;
 		uint64_t lds,ldr;
 		uint64_t lds,ldr;
 
 
@@ -278,6 +313,7 @@ keep_searching_for_roots:
 				}
 				}
 			}
 			}
 		}
 		}
+		*/
 	}
 	}
 
 
 	if (bestRoot)
 	if (bestRoot)