Fix siblings in peers list, fix meter.

This commit is contained in:
Adam Ierymenko 2019-09-03 12:44:09 -07:00
parent fd6e8d8c5c
commit 50709cbd21
No known key found for this signature in database
GPG Key ID: C8877CF2D7A5D7F3
2 changed files with 18 additions and 9 deletions

View File

@ -53,34 +53,40 @@ public:
{ {
_lock.lock(); _lock.lock();
const int64_t since = now - _ts; const int64_t since = now - _ts;
if (since >= 1000) { if (since >= ZT_METER_HISTORY_TICK_DURATION) {
_ts = now; _ts = now;
for(int i=1;i<ZT_METER_HISTORY_LENGTH;++i) for(int i=1;i<ZT_METER_HISTORY_LENGTH;++i)
_history[i-1] = _history[i]; _history[i-1] = _history[i];
_history[ZT_METER_HISTORY_LENGTH-1] = (double)_count / ((double)since / 1000.0); _history[ZT_METER_HISTORY_LENGTH-1] = (double)_count / ((double)since / 1000.0);
_count = 0; _count = 0;
} }
_count += (unsigned long)count; _count += (uint64_t)count;
_lock.unlock(); _lock.unlock();
} }
ZT_ALWAYS_INLINE double perSecond(const int64_t now) const ZT_ALWAYS_INLINE double perSecond(const int64_t now) const
{ {
double r = 0.0,n = 0.0;
_lock.lock(); _lock.lock();
int64_t since = (now - _ts); const int64_t since = (now - _ts);
if (since <= 0) since = 1; if (since >= ZT_METER_HISTORY_TICK_DURATION) {
double r = (double)_count / ((double)since / 1000.0); r += (double)_count / ((double)since / 1000.0);
for(int i=0;i<ZT_METER_HISTORY_LENGTH;++i) n += 1.0;
}
for(int i=0;i<ZT_METER_HISTORY_LENGTH;++i) {
r += _history[i]; r += _history[i];
r /= (double)(ZT_METER_HISTORY_LENGTH + 1); n += 1.0;
}
_lock.unlock(); _lock.unlock();
return r;
return r / n;
} }
private: private:
double _history[ZT_METER_HISTORY_LENGTH]; double _history[ZT_METER_HISTORY_LENGTH];
int64_t _ts; int64_t _ts;
unsigned long _count; uint64_t _count;
Mutex _lock; Mutex _lock;
}; };

View File

@ -779,6 +779,9 @@ int main(int argc,char **argv)
} }
rp->sibling = true; rp->sibling = true;
siblings.push_back(rp); siblings.push_back(rp);
peersByIdentity[id] = rp;
peersByVirtAddr[id.address()].insert(rp);
peersByPhysAddr[ip].insert(rp);
} else { } else {
printf("FATAL: invalid JSON while parsing siblings section in config file: sibling entry is not a JSON object" ZT_EOL_S); printf("FATAL: invalid JSON while parsing siblings section in config file: sibling entry is not a JSON object" ZT_EOL_S);
return 1; return 1;