Browse Source

Poll for network autoconf, and a few other documentation changes.

Adam Ierymenko 12 năm trước cách đây
mục cha
commit
3368330b77
4 tập tin đã thay đổi với 40 bổ sung13 xóa
  1. 18 8
      node/Constants.hpp
  2. 16 4
      node/Node.cpp
  3. 3 0
      node/SharedPtr.hpp
  4. 3 1
      node/SysEnv.hpp

+ 18 - 8
node/Constants.hpp

@@ -274,6 +274,24 @@ error_no_ZT_ARCH_defined;
  */
 #define ZT_PEER_DIRECT_PING_DELAY 120000
 
+/**
+ * Delay in ms between firewall opener packets to direct links
+ *
+ * This should be lower than the UDP conversation entry timeout in most
+ * stateful firewalls.
+ */
+#define ZT_FIREWALL_OPENER_DELAY 50000
+
+/**
+ * Delay between requests for updated network autoconf information
+ */
+#define ZT_NETWORK_AUTOCONF_DELAY 120000
+
+/**
+ * Delay in core loop between checks of network autoconf newness
+ */
+#define ZT_NETWORK_AUTOCONF_CHECK_DELAY 7000
+
 /**
  * Minimum delay in Node service loop
  * 
@@ -288,14 +306,6 @@ error_no_ZT_ARCH_defined;
  */
 #define ZT_PEER_LINK_ACTIVITY_TIMEOUT ((ZT_PEER_DIRECT_PING_DELAY * 2) + 1000)
 
-/**
- * Delay in ms between firewall opener packets to direct links
- *
- * This should be lower than the UDP conversation entry timeout in most
- * stateful firewalls.
- */
-#define ZT_FIREWALL_OPENER_DELAY 50000
-
 /**
  * IP hops (a.k.a. TTL) to set for firewall opener packets
  *

+ 16 - 4
node/Node.cpp

@@ -406,6 +406,7 @@ Node::ReasonForTermination Node::run()
 #endif
 
 	try {
+		uint64_t lastNetworkAutoconfCheck = 0;
 		uint64_t lastPingCheck = 0;
 		uint64_t lastClean = Utils::now(); // don't need to do this immediately
 		uint64_t lastNetworkFingerprintCheck = 0;
@@ -441,6 +442,17 @@ Node::ReasonForTermination Node::run()
 				}
 			}
 
+			// Request configuration for unconfigured nets, or nets with out of date
+			// configuration information.
+			if ((resynchronize)||((now - lastNetworkAutoconfCheck) >= ZT_NETWORK_AUTOCONF_CHECK_DELAY)) {
+				lastNetworkAutoconfCheck = now;
+				std::vector< SharedPtr<Network> > nets(_r->nc->networks());
+				for(std::vector< SharedPtr<Network> >::iterator n(nets.begin());n!=nets.end();++n) {
+					if ((now - (*n)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)
+						(*n)->requestConfiguration();
+				}
+			}
+
 			// Periodically check for changes in our local multicast subscriptions and broadcast
 			// those changes to peers.
 			if ((resynchronize)||((now - lastMulticastCheck) >= ZT_MULTICAST_LOCAL_POLL_PERIOD)) {
@@ -477,9 +489,9 @@ Node::ReasonForTermination Node::run()
 				lastPingCheck = now;
 				try {
 					if (_r->topology->amSupernode()) {
-						// Supernodes are so super they don't even have to ping out. Everyone
-						// comes to them! They're also never firewalled, so they don't
-						// send firewall openers.
+						// Supernodes are so super they don't even have to ping out, since
+						// all nodes ping them. They're also never firewalled so they
+						// don't need firewall openers. They just ping each other.
 						std::vector< SharedPtr<Peer> > sns(_r->topology->supernodePeers());
 						for(std::vector< SharedPtr<Peer> >::const_iterator p(sns.begin());p!=sns.end();++p) {
 							if ((now - (*p)->lastDirectSend()) > ZT_PEER_DIRECT_PING_DELAY)
@@ -532,7 +544,7 @@ Node::ReasonForTermination Node::run()
 				unsigned long delay = std::min((unsigned long)ZT_MIN_SERVICE_LOOP_INTERVAL,_r->sw->doTimerTasks());
 				uint64_t start = Utils::now();
 				_r->mainLoopWaitCondition.wait(delay);
-				lastDelayDelta = (long)(Utils::now() - start) - (long)delay;
+				lastDelayDelta = (long)(Utils::now() - start) - (long)delay; // used to detect sleep/wake
 			} catch (std::exception &exc) {
 				LOG("unexpected exception running Switch doTimerTasks: %s",exc.what());
 			} catch ( ... ) {

+ 3 - 0
node/SharedPtr.hpp

@@ -43,6 +43,9 @@ namespace ZeroTier {
  *
  * Because this is introspective, it is safe to apply to a naked pointer
  * multiple times provided there is always at least one holding SharedPtr.
+ *
+ * Once C++11 is ubiquitous, this and a few other things like Thread might get
+ * torn out for their standard equivalents.
  */
 template<typename T>
 class SharedPtr

+ 3 - 1
node/SysEnv.hpp

@@ -30,6 +30,8 @@
 
 #include <stdint.h>
 
+#include "NonCopyable.hpp"
+
 namespace ZeroTier {
 
 class RuntimeEnvironment;
@@ -37,7 +39,7 @@ class RuntimeEnvironment;
 /**
  * Local system environment monitoring utilities
  */
-class SysEnv
+class SysEnv : NonCopyable
 {
 public:
 	SysEnv(const RuntimeEnvironment *renv);