mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-28 00:38:51 +00:00
Fix siblings in peers list, fix meter.
This commit is contained in:
parent
fd6e8d8c5c
commit
50709cbd21
@ -53,34 +53,40 @@ public:
|
||||
{
|
||||
_lock.lock();
|
||||
const int64_t since = now - _ts;
|
||||
if (since >= 1000) {
|
||||
if (since >= ZT_METER_HISTORY_TICK_DURATION) {
|
||||
_ts = now;
|
||||
for(int i=1;i<ZT_METER_HISTORY_LENGTH;++i)
|
||||
_history[i-1] = _history[i];
|
||||
_history[ZT_METER_HISTORY_LENGTH-1] = (double)_count / ((double)since / 1000.0);
|
||||
_count = 0;
|
||||
}
|
||||
_count += (unsigned long)count;
|
||||
_count += (uint64_t)count;
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
ZT_ALWAYS_INLINE double perSecond(const int64_t now) const
|
||||
{
|
||||
double r = 0.0,n = 0.0;
|
||||
|
||||
_lock.lock();
|
||||
int64_t since = (now - _ts);
|
||||
if (since <= 0) since = 1;
|
||||
double r = (double)_count / ((double)since / 1000.0);
|
||||
for(int i=0;i<ZT_METER_HISTORY_LENGTH;++i)
|
||||
const int64_t since = (now - _ts);
|
||||
if (since >= ZT_METER_HISTORY_TICK_DURATION) {
|
||||
r += (double)_count / ((double)since / 1000.0);
|
||||
n += 1.0;
|
||||
}
|
||||
for(int i=0;i<ZT_METER_HISTORY_LENGTH;++i) {
|
||||
r += _history[i];
|
||||
r /= (double)(ZT_METER_HISTORY_LENGTH + 1);
|
||||
n += 1.0;
|
||||
}
|
||||
_lock.unlock();
|
||||
return r;
|
||||
|
||||
return r / n;
|
||||
}
|
||||
|
||||
private:
|
||||
double _history[ZT_METER_HISTORY_LENGTH];
|
||||
int64_t _ts;
|
||||
unsigned long _count;
|
||||
uint64_t _count;
|
||||
Mutex _lock;
|
||||
};
|
||||
|
||||
|
@ -779,6 +779,9 @@ int main(int argc,char **argv)
|
||||
}
|
||||
rp->sibling = true;
|
||||
siblings.push_back(rp);
|
||||
peersByIdentity[id] = rp;
|
||||
peersByVirtAddr[id.address()].insert(rp);
|
||||
peersByPhysAddr[ip].insert(rp);
|
||||
} else {
|
||||
printf("FATAL: invalid JSON while parsing siblings section in config file: sibling entry is not a JSON object" ZT_EOL_S);
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user