diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-30 15:02:12 -0400 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-30 15:02:12 -0400 |
| commit | 4875eb49f851d7919587cbc2059ff552a24bcfc1 (patch) | |
| tree | 5e3080f1f264fa678d0223184db74db8d805c11d /node | |
| parent | 11774f7d5fe14226e99118f95346deda51baa254 (diff) | |
| download | infinitytier-4875eb49f851d7919587cbc2059ff552a24bcfc1.tar.gz infinitytier-4875eb49f851d7919587cbc2059ff552a24bcfc1.zip | |
Remove old launcher code, fix build error in idtool, add terminate command to control bus.
Diffstat (limited to 'node')
| -rw-r--r-- | node/Node.cpp | 30 | ||||
| -rw-r--r-- | node/Node.hpp | 10 | ||||
| -rw-r--r-- | node/NodeConfig.cpp | 6 | ||||
| -rw-r--r-- | node/RuntimeEnvironment.hpp | 3 |
4 files changed, 31 insertions, 18 deletions
diff --git a/node/Node.cpp b/node/Node.cpp index 785fc634..96d1f87a 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -183,20 +183,20 @@ struct _NodeImpl { RuntimeEnvironment renv; std::string reasonForTerminationStr; - Node::ReasonForTermination reasonForTermination; + volatile Node::ReasonForTermination reasonForTermination; volatile bool started; volatile bool running; - volatile bool terminateNow; - // run() calls this on all return paths - inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr) + inline Node::ReasonForTermination terminate() { RuntimeEnvironment *_r = &renv; - LOG("terminating: %s",rstr); + LOG("terminating: %s",reasonForTerminationStr.c_str()); renv.shutdownInProgress = true; Thread::sleep(500); + running = false; + #ifndef __WINDOWS__ delete renv.netconfService; #endif @@ -209,11 +209,14 @@ struct _NodeImpl delete renv.prng; delete renv.log; + return reasonForTermination; + } + + inline Node::ReasonForTermination terminateBecause(Node::ReasonForTermination r,const char *rstr) + { reasonForTerminationStr = rstr; reasonForTermination = r; - running = false; - - return r; + return terminate(); } }; @@ -279,7 +282,6 @@ Node::Node(const char *hp) impl->reasonForTermination = Node::NODE_RUNNING; impl->started = false; impl->running = false; - impl->terminateNow = false; } Node::~Node() @@ -377,6 +379,7 @@ Node::ReasonForTermination Node::run() // One is running. return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,(std::string("another instance of ZeroTier One appears to be running, or local control UDP port cannot be bound: ") + exc.what()).c_str()); } + _r->node = this; // TODO: make configurable bool boundPort = false; @@ -424,7 +427,7 @@ Node::ReasonForTermination Node::run() LOG("%s starting version %s",_r->identity.address().toString().c_str(),versionString()); - while (!impl->terminateNow) { + while (impl->reasonForTermination == NODE_RUNNING) { uint64_t now = Utils::now(); bool resynchronize = false; @@ -562,7 +565,7 @@ Node::ReasonForTermination Node::run() return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unexpected exception during outer main I/O loop"); } - return impl->terminateBecause(Node::NODE_NORMAL_TERMINATION,"normal termination"); + return impl->terminate(); } const char *Node::reasonForTermination() const @@ -573,10 +576,11 @@ const char *Node::reasonForTermination() const return ((_NodeImpl *)_impl)->reasonForTerminationStr.c_str(); } -void Node::terminate() +void Node::terminate(ReasonForTermination reason,const char *reasonText) throw() { - ((_NodeImpl *)_impl)->terminateNow = true; + ((_NodeImpl *)_impl)->reasonForTermination = reason; + ((_NodeImpl *)_impl)->reasonForTerminationStr = ((reasonText) ? reasonText : ""); ((_NodeImpl *)_impl)->renv.mainLoopWaitCondition.signal(); } diff --git a/node/Node.hpp b/node/Node.hpp index 9fb4666d..8e9f2777 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -86,8 +86,7 @@ public: NODE_RUNNING = 0, NODE_NORMAL_TERMINATION = 1, NODE_RESTART_FOR_RECONFIGURATION = 2, - NODE_UNRECOVERABLE_ERROR = 3, - NODE_NEW_VERSION_AVAILABLE = 4 + NODE_UNRECOVERABLE_ERROR = 3 }; /** @@ -124,13 +123,16 @@ public: throw(); /** - * Cause run() to return with NODE_NORMAL_TERMINATION + * Cause run() to return * * This can be called from a signal handler or another thread to signal a * running node to shut down. Shutdown may take a few seconds, so run() * may not return instantly. Multiple calls are ignored. + * + * @param reason Reason for termination + * @param reasonText Text to be returned by reasonForTermination() */ - void terminate() + void terminate(ReasonForTermination reason,const char *reasonText) throw(); /** diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index 2cfd0cae..bc7c35f4 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -55,6 +55,7 @@ #include "Peer.hpp" #include "Salsa20.hpp" #include "HMAC.hpp" +#include "Node.hpp" #ifdef __WINDOWS__ #define strtoull _strtoui64 @@ -170,6 +171,7 @@ std::vector<std::string> NodeConfig::execute(const char *command) _P("200 help listnetworks"); _P("200 help join <network ID>"); _P("200 help leave <network ID>"); + _P("200 help terminate [<reason>]"); } else if (cmd[0] == "listpeers") { _P("200 listpeers <ztaddr> <ipv4> <ipv6> <latency> <version>"); _r->topology->eachPeer(_DumpPeerStatistics(r)); @@ -231,6 +233,10 @@ std::vector<std::string> NodeConfig::execute(const char *command) } else { _P("400 leave requires a network ID (>0) in hexadecimal format"); } + } else if (cmd[0] == "terminate") { + if (cmd.size() > 1) + _r->node->terminate(Node::NODE_NORMAL_TERMINATION,cmd[1].c_str()); + else _r->node->terminate(Node::NODE_NORMAL_TERMINATION,(const char *)0); } else { _P("404 %s No such command. Use 'help' for help.",cmd[0].c_str()); } diff --git a/node/RuntimeEnvironment.hpp b/node/RuntimeEnvironment.hpp index 4be4f367..f8b39597 100644 --- a/node/RuntimeEnvironment.hpp +++ b/node/RuntimeEnvironment.hpp @@ -44,6 +44,7 @@ class SysEnv; class Multicaster; class CMWC4096; class Service; +class Node; /** * Holds global state for an instance of ZeroTier::Node @@ -96,7 +97,7 @@ public: Topology *topology; SysEnv *sysEnv; NodeConfig *nc; - + Node *node; #ifndef __WINDOWS__ Service *netconfService; // may be null #endif |
