Browse Source

SIGHUP now causes resync with peers.

Adam Ierymenko 11 years ago
parent
commit
d75f2f7051
3 changed files with 27 additions and 2 deletions
  1. 7 1
      main.cpp
  2. 14 1
      node/Node.cpp
  3. 6 0
      node/Node.hpp

+ 7 - 1
main.cpp

@@ -357,6 +357,12 @@ static int main(int argc,char **argv)
 } // namespace ZeroTierIdTool ------------------------------------------------
 
 #ifdef __UNIX_LIKE__
+static void sighandlerHup(int sig)
+{
+	Node *n = node;
+	if (n)
+		n->resync();
+}
 static void sighandlerQuit(int sig)
 {
 	Node *n = node;
@@ -569,7 +575,7 @@ int main(int argc,char **argv)
 #endif
 {
 #ifdef __UNIX_LIKE__
-	signal(SIGHUP,SIG_IGN);
+	signal(SIGHUP,&sighandlerHup);
 	signal(SIGPIPE,SIG_IGN);
 	signal(SIGUSR1,SIG_IGN);
 	signal(SIGUSR2,SIG_IGN);

+ 14 - 1
node/Node.cpp

@@ -224,6 +224,7 @@ struct _NodeImpl
 	volatile Node::ReasonForTermination reasonForTermination;
 	volatile bool started;
 	volatile bool running;
+	volatile bool resynchronize;
 
 	inline Node::ReasonForTermination terminate()
 	{
@@ -359,6 +360,7 @@ Node::Node(const char *hp,unsigned int port,unsigned int controlPort)
 	impl->reasonForTermination = Node::NODE_RUNNING;
 	impl->started = false;
 	impl->running = false;
+	impl->resynchronize = false;
 }
 
 Node::~Node()
@@ -528,7 +530,11 @@ Node::ReasonForTermination Node::run()
 			}
 
 			uint64_t now = Utils::now();
-			bool resynchronize = false;
+			bool resynchronize = impl->resynchronize;
+			if (resynchronize) {
+				LOG("manual resynchronize ordered, resyncing with network");
+			}
+			impl->resynchronize = false;
 
 			// If it looks like the computer slept and woke, resynchronize.
 			if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) {
@@ -657,6 +663,13 @@ void Node::terminate(ReasonForTermination reason,const char *reasonText)
 	((_NodeImpl *)_impl)->renv.mainLoopWaitCondition.signal();
 }
 
+void Node::resync()
+	throw()
+{
+	((_NodeImpl *)_impl)->resynchronize = true;
+	((_NodeImpl *)_impl)->renv.mainLoopWaitCondition.signal();
+}
+
 class _VersionStringMaker
 {
 public:

+ 6 - 0
node/Node.hpp

@@ -180,6 +180,12 @@ public:
 	void terminate(ReasonForTermination reason,const char *reasonText)
 		throw();
 
+	/**
+	 * Forget p2p links and resynchronize with peers
+	 */
+	void resync()
+		throw();
+
 	/**
 	 * Get the ZeroTier version in major.minor.revision string format
 	 *