diff --git a/include/llarp/codel.hpp b/include/llarp/codel.hpp index 2a015f5df..55ff61f12 100644 --- a/include/llarp/codel.hpp +++ b/include/llarp/codel.hpp @@ -116,27 +116,6 @@ namespace llarp } } - template < typename Q > - void - _sort(Q& queue) - { - /* - std::vector< std::unique_ptr< T > > q; - while(queue.size()) - { - q.emplace_back(std::move(queue.front())); - queue.pop(); - } - std::sort(q.begin(), q.end(), Compare()); - auto itr = q.begin(); - while(itr != q.end()) - { - queue.push(std::move(*itr)); - ++itr; - } - */ - } - /// visit returns true to discard entry otherwise the entry is /// re quened template < typename Visit > @@ -147,13 +126,12 @@ namespace llarp // auto start = llarp_time_now_ms(); // llarp::LogInfo("CoDelQueue::Process - start at ", start); Lock_t lock(m_QueueMutex); - _sort(m_Queue); auto start = firstPut; - std::queue< T* > requeue; + Queue_t requeue; while(m_Queue.size()) { llarp::LogDebug("CoDelQueue::Process - queue has ", m_Queue.size()); - T* item = m_Queue.front(); + T* item = m_Queue.top(); auto dlt = start - GetTime()(item); // llarp::LogInfo("CoDelQueue::Process - dlt ", dlt); lowest = std::min(dlt, lowest); @@ -175,14 +153,13 @@ namespace llarp } } // llarp::LogInfo("CoDelQueue::Process - passing"); - if(!visitor(item)) + if(visitor(item)) { - // requeue item as we are not done - requeue.push(item); + delete item; } else { - delete item; + requeue.push(item); } m_Queue.pop(); } @@ -204,7 +181,8 @@ namespace llarp size_t dropNum = 0; llarp_time_t nextTickInterval = initialIntervalMs; Mutex_t m_QueueMutex; - std::queue< T* > m_Queue; + typedef std::priority_queue< T*, std::vector< T* >, Compare > Queue_t; + Queue_t m_Queue; std::string m_name; }; } // namespace util diff --git a/include/llarp/crypto_async.h b/include/llarp/crypto_async.h index 4c879e569..bfbd678b1 100644 --- a/include/llarp/crypto_async.h +++ b/include/llarp/crypto_async.h @@ -201,8 +201,7 @@ struct FrameGetTime struct FrameCompareTime { bool - operator()(const std::unique_ptr< iwp_async_frame > &left, - const std::unique_ptr< iwp_async_frame > &right) const + operator()(const iwp_async_frame *left, const iwp_async_frame *right) const { return left->created < right->created; } diff --git a/include/llarp/ip.hpp b/include/llarp/ip.hpp index 05b8123e4..3e01b655e 100644 --- a/include/llarp/ip.hpp +++ b/include/llarp/ip.hpp @@ -84,8 +84,7 @@ namespace llarp struct CompareOrder { bool - operator()(const std::unique_ptr< IPv4Packet >& left, - const std::unique_ptr< IPv4Packet >& right) + operator()(const IPv4Packet* left, const IPv4Packet* right) { return left->timestamp < right->timestamp; } diff --git a/include/llarp/iwp/inbound_message.hpp b/include/llarp/iwp/inbound_message.hpp index e153e6a3b..fc86d2cef 100644 --- a/include/llarp/iwp/inbound_message.hpp +++ b/include/llarp/iwp/inbound_message.hpp @@ -42,8 +42,7 @@ struct InboundMessage struct OrderCompare { bool - operator()(const std::unique_ptr< InboundMessage > &left, - const std::unique_ptr< InboundMessage > &right) const + operator()(const InboundMessage *left, const InboundMessage *right) const { return left->msgid < right->msgid; } diff --git a/include/llarp/iwp/sendbuf.hpp b/include/llarp/iwp/sendbuf.hpp index b6ac27060..c646d1a06 100644 --- a/include/llarp/iwp/sendbuf.hpp +++ b/include/llarp/iwp/sendbuf.hpp @@ -65,10 +65,9 @@ struct sendbuf_t struct Compare { bool - operator()(const std::unique_ptr< sendbuf_t > &left, - const std::unique_ptr< sendbuf_t > &right) const + operator()(const sendbuf_t *left, const sendbuf_t *right) const { - return left->priority < right->priority; + return left->timestamp < right->timestamp; } }; diff --git a/llarp/ev.hpp b/llarp/ev.hpp index bba2aab83..0eba64a3d 100644 --- a/llarp/ev.hpp +++ b/llarp/ev.hpp @@ -109,8 +109,7 @@ namespace llarp struct Compare { bool - operator()(const std::unique_ptr< WriteBuffer >& left, - const std::unique_ptr< WriteBuffer >& right) const + operator()(const WriteBuffer* left, const WriteBuffer* right) const { return left->timestamp < right->timestamp; } diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 68cbd6f3b..f4fc0f482 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -98,8 +98,8 @@ namespace llarp { llarp::LogWarn("could not publish descriptors for endpoint ", Name(), " because we couldn't get any introductions"); - // if(ShouldBuildMore()) - ManualRebuild(1); + if(ShouldBuildMore()) + ManualRebuild(1); return; } m_IntroSet.I.clear();