.
This commit is contained in:
parent
b19634d7e4
commit
2f7d3e655a
2 changed files with 20 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue