mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-21 10:01:46 +00:00
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
This commit is contained in:
parent
29a2175b7a
commit
347e98dcd2
@ -67,6 +67,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t nwid) :
|
|||||||
std::string conf(RR->node->dataStoreGet(confn));
|
std::string conf(RR->node->dataStoreGet(confn));
|
||||||
if (conf.length()) {
|
if (conf.length()) {
|
||||||
setConfiguration(Dictionary(conf),false);
|
setConfiguration(Dictionary(conf),false);
|
||||||
|
_lastConfigUpdate = 0; // we still want to re-request a new config from the network
|
||||||
gotConf = true;
|
gotConf = true;
|
||||||
}
|
}
|
||||||
} catch ( ... ) {} // ignore invalids, we'll re-request
|
} catch ( ... ) {} // ignore invalids, we'll re-request
|
||||||
|
@ -75,38 +75,35 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
|
|||||||
}
|
}
|
||||||
#endif // __UNIX_LIKE__
|
#endif // __UNIX_LIKE__
|
||||||
|
|
||||||
std::map<std::string,bool> OSUtils::listDirectory(const char *path)
|
std::vector<std::string> OSUtils::listDirectory(const char *path)
|
||||||
{
|
{
|
||||||
std::map<std::string,bool> r;
|
std::vector<std::string> r;
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
WIN32_FIND_DATAA ffd;
|
WIN32_FIND_DATAA ffd;
|
||||||
if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) {
|
if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) {
|
||||||
do {
|
do {
|
||||||
if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,"..")))
|
if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
|
||||||
r[std::string(ffd.cFileName)] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
r.push_back(std::string(ffd.cFileName));
|
||||||
} while (FindNextFileA(hFind,&ffd));
|
} while (FindNextFileA(hFind,&ffd));
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct dirent de;
|
struct dirent de;
|
||||||
struct dirent *dptr;
|
struct dirent *dptr;
|
||||||
|
|
||||||
DIR *d = opendir(path);
|
DIR *d = opendir(path);
|
||||||
if (!d)
|
if (!d)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
dptr = (struct dirent *)0;
|
dptr = (struct dirent *)0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if (readdir_r(d,&de,&dptr))
|
if (readdir_r(d,&de,&dptr))
|
||||||
break;
|
break;
|
||||||
if (dptr) {
|
if (dptr) {
|
||||||
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,"..")))
|
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type != DT_DIR))
|
||||||
r[std::string(dptr->d_name)] = (dptr->d_type == DT_DIR);
|
r.push_back(std::string(dptr->d_name));
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -103,16 +103,13 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List a directory's contents
|
* List a directory's contents
|
||||||
*
|
*
|
||||||
* Keys in returned map are filenames only and don't include the leading
|
* This returns only files, not sub-directories.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @param path Path to list
|
* @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<std::string,bool> listDirectory(const char *path);
|
static std::vector<std::string> listDirectory(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set modes on a file to something secure
|
* Set modes on a file to something secure
|
||||||
|
@ -191,6 +191,15 @@ public:
|
|||||||
|
|
||||||
_controlPlane = new ControlPlane(_node);
|
_controlPlane = new ControlPlane(_node);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));
|
||||||
|
for(std::vector<std::string>::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;
|
_nextBackgroundTaskDeadline = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
_run_m.lock();
|
_run_m.lock();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user