From 28a73b620e60dd5d9c77aa7494d4c71da8b1d08c Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 6 Aug 2013 01:28:56 -0400 Subject: Bunch more debugging and loop closing on new netconf. --- node/NodeConfig.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'node/NodeConfig.cpp') diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index b6d58e40..a8599508 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include @@ -58,6 +60,32 @@ NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken) SHA256_Init(&sha); SHA256_Update(&sha,authToken,strlen(authToken)); SHA256_Final(_controlSocketKey,&sha); + + std::map networksDotD(Utils::listDirectory((_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str())); + std::set nwids; + for(std::map::iterator d(networksDotD.begin());d!=networksDotD.end();++d) { + if (!d->second) { + std::string::size_type dot = d->first.rfind(".conf"); + if (dot != std::string::npos) { + uint64_t nwid = strtoull(d->first.substr(0,dot).c_str(),(char **)0,16); + if (nwid > 0) + nwids.insert(nwid); + } + } + } + + for(std::set::iterator nwid(nwids.begin());nwid!=nwids.end();++nwid) { + try { + SharedPtr nw(new Network(_r,*nwid)); + _networks[*nwid] = nw; + nw->restoreState(); + nw->requestConfiguration(); + } catch (std::exception &exc) { + LOG("unable to create network %.16llx: %s",(unsigned long long)*nwid,exc.what()); + } catch ( ... ) { + LOG("unable to create network %.16llx: (unknown exception)",(unsigned long long)*nwid); + } + } } NodeConfig::~NodeConfig() @@ -149,14 +177,20 @@ std::vector NodeConfig::execute(const char *command) uint64_t nwid = strtoull(cmd[1].c_str(),(char **)0,16); if (nwid > 0) { Mutex::Lock _l(_networks_m); - try { - SharedPtr nw(new Network(_r,nwid)); - _networks[nwid] = nw; - _P("200 join %.16llx OK",(unsigned long long)nwid); - } catch (std::exception &exc) { - _P("500 join %.16llx ERROR: %s",(unsigned long long)nwid,exc.what()); - } catch ( ... ) { - _P("500 join %.16llx ERROR: (unknown exception)",(unsigned long long)nwid); + if (_networks.count(nwid)) { + _P("400 already a member of %.16llx",(unsigned long long)nwid); + } else { + try { + SharedPtr nw(new Network(_r,nwid)); + _networks[nwid] = nw; + nw->restoreState(); + nw->requestConfiguration(); + _P("200 join %.16llx OK",(unsigned long long)nwid); + } catch (std::exception &exc) { + _P("500 join %.16llx ERROR: %s",(unsigned long long)nwid,exc.what()); + } catch ( ... ) { + _P("500 join %.16llx ERROR: (unknown exception)",(unsigned long long)nwid); + } } } else { _P("400 join requires a network ID (>0) in hexadecimal format"); -- cgit v1.2.3