From 347e98dcd2d29772d5b9cf23c307b0a6ce0d8858 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 14 Apr 2015 15:32:05 -0700 Subject: [PATCH] Just return files from listDirectory() since that is all we need, fix network request on network restore logic, and remember saved networks in service/One --- node/Network.cpp | 1 + osdep/OSUtils.cpp | 15 ++++++--------- osdep/OSUtils.hpp | 11 ++++------- service/One.cpp | 9 +++++++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/node/Network.cpp b/node/Network.cpp index 2a071f6fb..0575f48c3 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -67,6 +67,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t nwid) : std::string conf(RR->node->dataStoreGet(confn)); if (conf.length()) { setConfiguration(Dictionary(conf),false); + _lastConfigUpdate = 0; // we still want to re-request a new config from the network gotConf = true; } } catch ( ... ) {} // ignore invalids, we'll re-request diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 1fa2f8b06..60e6d6baa 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -75,38 +75,35 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath) } #endif // __UNIX_LIKE__ -std::map OSUtils::listDirectory(const char *path) +std::vector OSUtils::listDirectory(const char *path) { - std::map r; + std::vector r; #ifdef __WINDOWS__ HANDLE hFind; WIN32_FIND_DATAA ffd; if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { do { - if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))) - r[std::string(ffd.cFileName)] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); + if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) + r.push_back(std::string(ffd.cFileName)); } while (FindNextFileA(hFind,&ffd)); FindClose(hFind); } #else struct dirent de; struct dirent *dptr; - DIR *d = opendir(path); if (!d) return r; - dptr = (struct dirent *)0; for(;;) { if (readdir_r(d,&de,&dptr)) break; if (dptr) { - if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))) - r[std::string(dptr->d_name)] = (dptr->d_type == DT_DIR); + if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type != DT_DIR)) + r.push_back(std::string(dptr->d_name)); } else break; } - closedir(d); #endif diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp index a0cb1067f..142f0aed5 100644 --- a/osdep/OSUtils.hpp +++ b/osdep/OSUtils.hpp @@ -103,16 +103,13 @@ public: /** * List a directory's contents - * - * Keys in returned map are filenames only and don't include the leading - * path. Pseudo-paths like . and .. are not returned. Values are true if - * the item is a directory, false if it's a file. More detailed attributes - * aren't supported since the code that uses this doesn't need them. + * + * This returns only files, not sub-directories. * * @param path Path to list - * @return Map of entries and whether or not they are also directories (empty on failure) + * @return Names of files in directory */ - static std::map listDirectory(const char *path); + static std::vector listDirectory(const char *path); /** * Set modes on a file to something secure diff --git a/service/One.cpp b/service/One.cpp index 5e81bc61a..c4e1b251a 100644 --- a/service/One.cpp +++ b/service/One.cpp @@ -191,6 +191,15 @@ public: _controlPlane = new ControlPlane(_node); + { + std::vector networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str())); + for(std::vector::iterator f(networksDotD.begin());f!=networksDotD.end();++f) { + std::size_t dot = f->find_last_of('.'); + if ((dot == 16)&&(f->substr(16) == ".conf")) + _node->join(Utils::hexStrToU64(f->substr(0,dot).c_str())); + } + } + _nextBackgroundTaskDeadline = 0; for(;;) { _run_m.lock();