mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 02:40:13 +00:00
Clean peers.d periodically and delete peers older than 30 days.
This commit is contained in:
parent
fac7dc9c91
commit
2cc4dc5a6f
@ -133,7 +133,7 @@ std::vector<std::string> OSUtils::listDirectory(const char *path,bool includeDir
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
long OSUtils::cleanDirectory(const char *path,const int64_t olderThan)
|
||||||
{
|
{
|
||||||
long cleaned = 0;
|
long cleaned = 0;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
|||||||
date.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
|
date.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
|
||||||
if (date.QuadPart > 0) {
|
if (date.QuadPart > 0) {
|
||||||
date.QuadPart -= adjust.QuadPart;
|
date.QuadPart -= adjust.QuadPart;
|
||||||
if ((uint64_t)((date.QuadPart / 10000000) * 1000) < olderThan) {
|
if ((int64_t)((date.QuadPart / 10000000) * 1000) < olderThan) {
|
||||||
ztsnprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
ztsnprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
||||||
if (DeleteFileA(tmp))
|
if (DeleteFileA(tmp))
|
||||||
++cleaned;
|
++cleaned;
|
||||||
@ -176,7 +176,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
|||||||
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type == DT_REG)) {
|
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type == DT_REG)) {
|
||||||
ztsnprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
ztsnprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
||||||
if (stat(tmp,&st) == 0) {
|
if (stat(tmp,&st) == 0) {
|
||||||
uint64_t mt = (uint64_t)(st.st_mtime);
|
int64_t mt = (int64_t)(st.st_mtime);
|
||||||
if ((mt > 0)&&((mt * 1000) < olderThan)) {
|
if ((mt > 0)&&((mt * 1000) < olderThan)) {
|
||||||
if (unlink(tmp) == 0)
|
if (unlink(tmp) == 0)
|
||||||
++cleaned;
|
++cleaned;
|
||||||
|
@ -142,7 +142,7 @@ public:
|
|||||||
* @param olderThan Last modified older than timestamp (ms since epoch)
|
* @param olderThan Last modified older than timestamp (ms since epoch)
|
||||||
* @return Number of cleaned files or negative on fatal error
|
* @return Number of cleaned files or negative on fatal error
|
||||||
*/
|
*/
|
||||||
static long cleanDirectory(const char *path,const uint64_t olderThan);
|
static long cleanDirectory(const char *path,const int64_t olderThan);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory and all its files and subdirectories recursively
|
* Delete a directory and all its files and subdirectories recursively
|
||||||
|
@ -762,6 +762,7 @@ public:
|
|||||||
int64_t lastTapMulticastGroupCheck = 0;
|
int64_t lastTapMulticastGroupCheck = 0;
|
||||||
int64_t lastBindRefresh = 0;
|
int64_t lastBindRefresh = 0;
|
||||||
int64_t lastUpdateCheck = clockShouldBe;
|
int64_t lastUpdateCheck = clockShouldBe;
|
||||||
|
int64_t lastCleanedPeersDb = 0;
|
||||||
int64_t lastLocalInterfaceAddressCheck = (clockShouldBe - ZT_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give portmapper time to configure and other things time to settle
|
int64_t lastLocalInterfaceAddressCheck = (clockShouldBe - ZT_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give portmapper time to configure and other things time to settle
|
||||||
for(;;) {
|
for(;;) {
|
||||||
_run_m.lock();
|
_run_m.lock();
|
||||||
@ -856,6 +857,12 @@ public:
|
|||||||
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*i)));
|
_node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean peers.d periodically
|
||||||
|
if ((now - lastCleanedPeersDb) >= 3600000) {
|
||||||
|
lastCleanedPeersDb = now;
|
||||||
|
OSUtils::cleanDirectory((_homePath + ZT_PATH_SEPARATOR_S "peers.d").c_str(),now - 2592000000LL); // delete older than 30 days
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned long delay = (dl > now) ? (unsigned long)(dl - now) : 100;
|
const unsigned long delay = (dl > now) ? (unsigned long)(dl - now) : 100;
|
||||||
clockShouldBe = now + (uint64_t)delay;
|
clockShouldBe = now + (uint64_t)delay;
|
||||||
_phy.poll(delay);
|
_phy.poll(delay);
|
||||||
|
Loading…
Reference in New Issue
Block a user