From 26c8063fc90c28b3db0d903c54c2c4b940b39fba Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 4 Apr 2022 18:12:27 -0400 Subject: [PATCH] convert priority queues --- llarp/handlers/tun.hpp | 10 ++++++---- llarp/iwp/session.cpp | 8 ++++---- llarp/iwp/session.hpp | 4 ++-- llarp/router/outbound_message_handler.hpp | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 37fe9f37d..fe93dfdae 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -12,10 +12,12 @@ #include #include -#include + #include #include + #include +#include namespace llarp { @@ -185,14 +187,14 @@ namespace llarp net::IPPacket pkt; bool - operator<(const WritePacket& other) const + operator>(const WritePacket& other) const { - return other.seqno < seqno; + return seqno > other.seqno; } }; /// queue for sending packets to user from network - std::priority_queue m_NetworkToUserPktQueue; + util::ascending_priority_queue m_NetworkToUserPktQueue; void Pump(llarp_time_t now) override; diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index 200fa7130..604a9eaf0 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -260,15 +260,15 @@ namespace llarp OutboundMessage*, std::vector, ComparePtr> - resend; + to_resend; for (auto& [id, msg] : m_TXMsgs) { if (msg.ShouldFlush(now)) - resend.push(&msg); + to_resend.push(&msg); } - if (not resend.empty()) + if (not to_resend.empty()) { - for (auto& msg = resend.top(); not resend.empty(); resend.pop()) + for (auto& msg = to_resend.top(); not to_resend.empty(); to_resend.pop()) msg->FlushUnAcked(util::memFn(&Session::EncryptAndSend, this), now); } } diff --git a/llarp/iwp/session.hpp b/llarp/iwp/session.hpp index 212b32812..210a37a1e 100644 --- a/llarp/iwp/session.hpp +++ b/llarp/iwp/session.hpp @@ -8,8 +8,8 @@ #include #include #include -#include +#include #include namespace llarp @@ -197,7 +197,7 @@ namespace llarp /// maps rxid to time recieved std::unordered_map m_ReplayFilter; /// rx messages to send in next round of multiacks - std::priority_queue, std::greater<>> m_SendMACKs; + util::ascending_priority_queue m_SendMACKs; using CryptoQueue_t = std::vector; diff --git a/llarp/router/outbound_message_handler.hpp b/llarp/router/outbound_message_handler.hpp index 9e4c7fcdc..232568f64 100644 --- a/llarp/router/outbound_message_handler.hpp +++ b/llarp/router/outbound_message_handler.hpp @@ -6,12 +6,12 @@ #include #include #include +#include #include #include #include #include -#include struct llarp_buffer_t; @@ -86,9 +86,9 @@ namespace llarp RouterID router; bool - operator<(const MessageQueueEntry& other) const + operator>(const MessageQueueEntry& other) const { - return other.priority < priority; + return priority > other.priority; } }; @@ -103,7 +103,7 @@ namespace llarp uint32_t numTicks = 0; }; - using MessageQueue = std::priority_queue; + using MessageQueue = util::ascending_priority_queue; /* If a session is not yet created with the destination router for a message, * a special queue is created for that router and an attempt is made to