mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Tweak new RX queue algorithm to "expire" old entries to prevent always needing to traverse the whole queue array.
This commit is contained in:
parent
8ef78e7e7d
commit
56096be8b6
3 changed files with 10 additions and 3 deletions
|
@ -169,6 +169,11 @@
|
||||||
*/
|
*/
|
||||||
#define ZT_RX_QUEUE_SIZE 64
|
#define ZT_RX_QUEUE_SIZE 64
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RX queue entries older than this do not "exist"
|
||||||
|
*/
|
||||||
|
#define ZT_RX_QUEUE_EXPIRE 4000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Length of secret key in bytes -- 256-bit -- do not change
|
* Length of secret key in bytes -- 256-bit -- do not change
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -138,7 +138,7 @@ void Switch::onRemotePacket(const InetAddress &localAddr,const InetAddress &from
|
||||||
// seeing a Packet::Fragment?
|
// seeing a Packet::Fragment?
|
||||||
|
|
||||||
Mutex::Lock _l(_rxQueue_m);
|
Mutex::Lock _l(_rxQueue_m);
|
||||||
RXQueueEntry *const rq = _findRXQueueEntry(fragmentPacketId);
|
RXQueueEntry *const rq = _findRXQueueEntry(now,fragmentPacketId);
|
||||||
|
|
||||||
if ((!rq->timestamp)||(rq->packetId != fragmentPacketId)) {
|
if ((!rq->timestamp)||(rq->packetId != fragmentPacketId)) {
|
||||||
// No packet found, so we received a fragment without its head.
|
// No packet found, so we received a fragment without its head.
|
||||||
|
@ -241,7 +241,7 @@ void Switch::onRemotePacket(const InetAddress &localAddr,const InetAddress &from
|
||||||
// Packet is the head of a fragmented packet series
|
// Packet is the head of a fragmented packet series
|
||||||
|
|
||||||
Mutex::Lock _l(_rxQueue_m);
|
Mutex::Lock _l(_rxQueue_m);
|
||||||
RXQueueEntry *const rq = _findRXQueueEntry(packetId);
|
RXQueueEntry *const rq = _findRXQueueEntry(now,packetId);
|
||||||
|
|
||||||
if ((!rq->timestamp)||(rq->packetId != packetId)) {
|
if ((!rq->timestamp)||(rq->packetId != packetId)) {
|
||||||
// If we have no other fragments yet, create an entry and save the head
|
// If we have no other fragments yet, create an entry and save the head
|
||||||
|
|
|
@ -184,7 +184,7 @@ private:
|
||||||
|
|
||||||
/* Returns the matching or oldest entry. Caller must check timestamp and
|
/* Returns the matching or oldest entry. Caller must check timestamp and
|
||||||
* packet ID to determine which. */
|
* packet ID to determine which. */
|
||||||
inline RXQueueEntry *_findRXQueueEntry(uint64_t packetId)
|
inline RXQueueEntry *_findRXQueueEntry(uint64_t now,uint64_t packetId)
|
||||||
{
|
{
|
||||||
RXQueueEntry *rq;
|
RXQueueEntry *rq;
|
||||||
RXQueueEntry *oldest = &(_rxQueue[ZT_RX_QUEUE_SIZE - 1]);
|
RXQueueEntry *oldest = &(_rxQueue[ZT_RX_QUEUE_SIZE - 1]);
|
||||||
|
@ -193,6 +193,8 @@ private:
|
||||||
rq = &(_rxQueue[--i]);
|
rq = &(_rxQueue[--i]);
|
||||||
if ((rq->packetId == packetId)&&(rq->timestamp))
|
if ((rq->packetId == packetId)&&(rq->timestamp))
|
||||||
return rq;
|
return rq;
|
||||||
|
if ((now - rq->timestamp) >= ZT_RX_QUEUE_EXPIRE)
|
||||||
|
rq->timestamp = 0;
|
||||||
if (rq->timestamp < oldest->timestamp)
|
if (rq->timestamp < oldest->timestamp)
|
||||||
oldest = rq;
|
oldest = rq;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue