diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-08 10:41:17 -0400 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-08 10:41:17 -0400 |
commit | 5cabb60a6f82b8a00b157fde3655356835285d82 (patch) | |
tree | ac19c54637a8dbeef7b62cecc43f141d2c3f37ba | |
parent | 86056fdbd923fbf55f85b3db704bba021ea90c4f (diff) | |
download | infinitytier-5cabb60a6f82b8a00b157fde3655356835285d82.tar.gz infinitytier-5cabb60a6f82b8a00b157fde3655356835285d82.zip |
Actually report a meaningful network status instead of always OK
-rw-r--r-- | node/Network.cpp | 20 | ||||
-rw-r--r-- | node/Network.hpp | 22 | ||||
-rw-r--r-- | node/NodeConfig.cpp | 7 |
3 files changed, 46 insertions, 3 deletions
diff --git a/node/Network.cpp b/node/Network.cpp index 94eef23f..a93740f8 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -104,6 +104,17 @@ bool Network::Certificate::qualifyMembership(const Network::Certificate &mc) con return true; } +const char *Network::statusString(const Status s) + throw() +{ + switch(s) { + case NETWORK_WAITING_FOR_FIRST_AUTOCONF: return "WAITING_FOR_FIRST_AUTOCONF"; + case NETWORK_OK: return "OK"; + case NETWORK_ACCESS_DENIED: return "ACCESS_DENIED"; + } + return "(invalid)"; +} + Network::~Network() { delete _tap; @@ -202,6 +213,7 @@ void Network::clean() std::string mcdbPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".mcerts"); Mutex::Lock _l(_lock); + if (_configuration.isOpen()) { _membershipCertificates.clear(); Utils::rm(mcdbPath); @@ -242,6 +254,14 @@ void Network::clean() } } +Network::Status Network::status() const +{ + Mutex::Lock _l(_lock); + if (_configuration.containsAllFields()) + return NETWORK_OK; + return NETWORK_WAITING_FOR_FIRST_AUTOCONF; +} + void Network::_CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data) { const RuntimeEnvironment *_r = ((Network *)arg)->_r; diff --git a/node/Network.hpp b/node/Network.hpp index 6d35b961..b42e09c1 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -265,6 +265,23 @@ public: } }; + /** + * Status for networks + */ + enum Status + { + NETWORK_WAITING_FOR_FIRST_AUTOCONF, + NETWORK_OK, + NETWORK_ACCESS_DENIED + }; + + /** + * @param s Status + * @return String description + */ + static const char *statusString(const Status s) + throw(); + private: // Only NodeConfig can create, only SharedPtr can delete @@ -404,6 +421,11 @@ public: return _lastConfigUpdate; } + /** + * @return Status of this network + */ + Status status() const; + private: static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data); void _restoreState(); diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index 259c1b82..87f85c22 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -175,11 +175,12 @@ std::vector<std::string> NodeConfig::execute(const char *command) } // TODO: display network status, such as "permission denied to closed // network" or "waiting". - _P("200 listnetworks %.16llx OK %s %s %s", + _P("200 listnetworks %.16llx %s %s %s %s", (unsigned long long)nw->first, - (nw->second->isOpen() ? "public" : "private"), + Network::statusString(nw->second->status()), + (nw->second->isOpen() ? "open" : "private"), nw->second->tap().deviceName().c_str(), - tmp.c_str()); + ((tmp.length() > 0) ? tmp.c_str() : "-")); } } else if (cmd[0] == "join") { if (cmd.size() > 1) { |