This commit is contained in:
Adam Ierymenko 2019-08-28 14:26:13 -07:00
parent b19634d7e4
commit 2f7d3e655a
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
2 changed files with 20 additions and 5 deletions

View file

@ -18,6 +18,7 @@
#include <stdio.h>
#include "Packet.hpp"
#include "Mutex.hpp"
#ifdef _MSC_VER
#define FORCE_INLINE static __forceinline
@ -932,4 +933,16 @@ bool Packet::uncompress()
return true;
}
uint64_t Packet::nextPacketId()
{
static uint64_t ctr = 0;
static Mutex lock;
lock.lock();
if (unlikely(ctr == 0))
Utils::getSecureRandom(&ctr,sizeof(ctr));
const uint64_t i = ctr++;
lock.unlock();
return i;
}
} // namespace ZeroTier