diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-11-10 09:46:14 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-11-10 09:46:14 -0800 |
commit | 4328c6c3bc402feffc06aade0059a6632b34c087 (patch) | |
tree | 4d6d921cee7c0ad62d0dc5df2fb5f64cc1254bc8 | |
parent | b171c9a0db89dbb6ce29b3b32bb4468d77ed184b (diff) | |
download | infinitytier-4328c6c3bc402feffc06aade0059a6632b34c087.tar.gz infinitytier-4328c6c3bc402feffc06aade0059a6632b34c087.zip |
Fix delete oldest logic.
-rw-r--r-- | node/Cluster.cpp | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/node/Cluster.cpp b/node/Cluster.cpp index 0859c8d3..0a7de93d 100644 --- a/node/Cluster.cpp +++ b/node/Cluster.cpp @@ -112,34 +112,32 @@ class _ClusterSendQueue { public: _ClusterSendQueue() : - _poolCount(0) - { - } - + _poolCount(0) {} ~_ClusterSendQueue() {} // memory is automatically freed when _chunks is destroyed - inline void enqueue(uint64_t ts,const Address &from,const Address &to,const void *data,unsigned int len,bool unite) + inline void enqueue(uint64_t now,const Address &from,const Address &to,const void *data,unsigned int len,bool unite) { if (len > ZT_CLUSTER_SEND_QUEUE_DATA_MAX) return; Mutex::Lock _l(_lock); - // Delete oldest queue entry if sender has too many queued packets + // Delete oldest queue entry for this sender if this enqueue() would take them over the per-sender limit { std::set< std::pair<Address,_ClusterSendQueueEntry *> >::iterator qi(_bySrc.lower_bound(std::pair<Address,_ClusterSendQueueEntry *>(from,(_ClusterSendQueueEntry *)0))); - std::set< std::pair<Address,_ClusterSendQueueEntry *> >::iterator oldest(_bySrc.end()); + std::set< std::pair<Address,_ClusterSendQueueEntry *> >::iterator oldest(qi); unsigned long countForSender = 0; while ((qi != _bySrc.end())&&(qi->first == from)) { - if (++countForSender > ZT_CLUSTER_MAX_QUEUE_PER_SENDER) { - _byDest.erase(std::pair<Address,_ClusterSendQueueEntry *>(oldest->second->toPeerAddress,oldest->second)); - _pool[_poolCount++] = oldest->second; - _bySrc.erase(oldest); - break; - } else if (oldest == _bySrc.end()) + if (qi->second->timestamp < oldest->second->timestamp) oldest = qi; + ++countForSender; ++qi; } + if (countForSender >= ZT_CLUSTER_MAX_QUEUE_PER_SENDER) { + _byDest.erase(std::pair<Address,_ClusterSendQueueEntry *>(oldest->second->toPeerAddress,oldest->second)); + _pool[_poolCount++] = oldest->second; + _bySrc.erase(oldest); + } } _ClusterSendQueueEntry *e; @@ -154,7 +152,7 @@ public: _pool[_poolCount++] = &(_chunks.back().data[i]); } - e->timestamp = ts; + e->timestamp = now; e->fromPeerAddress = from; e->toPeerAddress = to; memcpy(e->data,data,len); |