From 74f707ee01bb5ab6999b2904947ebd475abcc439 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 13 Feb 2021 14:46:23 -0500 Subject: [PATCH 1/7] only do single ack packets --- llarp/iwp/session.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index dc9113372..e8b0f4545 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -779,7 +779,9 @@ namespace llarp const llarp_buffer_t buf(msg.m_Data); m_Parent->HandleMessage(this, buf); if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second) - m_SendMACKs.emplace(rxid); + { + EncryptAndSend(msg.ACKS()); + } m_RXMsgs.erase(rxid); } } @@ -831,7 +833,9 @@ namespace llarp const llarp_buffer_t buf(msg.m_Data); m_Parent->HandleMessage(this, buf); if (m_ReplayFilter.emplace(itr->first, m_Parent->Now()).second) - m_SendMACKs.emplace(itr->first); + { + EncryptAndSend(msg.ACKS()); + } } else { From e6ac7e721deb3acfa49744c88403f6626394a6db Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 14 Feb 2021 07:57:47 -0500 Subject: [PATCH 2/7] use a std::map instead of a std::unordered_map for holding message buffers by their sequentially increasing message id. when retransmissions happen, they will be executed in a deterministic order by their delivery id. this reduces the jitter from delayed message delivery on link layer as with an unordered map the order of iteration is "random", so when we iterate all messages for retransmission we do it lowest id first (the messages queued first). --- llarp/iwp/session.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llarp/iwp/session.hpp b/llarp/iwp/session.hpp index 83c37e4a8..976ef3ace 100644 --- a/llarp/iwp/session.hpp +++ b/llarp/iwp/session.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -185,8 +186,8 @@ namespace llarp void ResetRates(); - std::unordered_map m_RXMsgs; - std::unordered_map m_TXMsgs; + std::map m_RXMsgs; + std::map m_TXMsgs; /// maps rxid to time recieved std::unordered_map m_ReplayFilter; From 5cffc3b0f8e6958b0496855d13fa95d7b5ef8fb9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 14 Feb 2021 08:24:13 -0500 Subject: [PATCH 3/7] consolidate rx message handling in iwp * add toggle flag for using multi ack * check replay filter before processing message --- llarp/iwp/session.cpp | 37 +++++++++++++++++++++---------------- llarp/iwp/session.hpp | 5 ++++- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index e8b0f4545..5d55e7a18 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -775,14 +775,7 @@ namespace llarp return; } } - auto msg = std::move(itr->second); - const llarp_buffer_t buf(msg.m_Data); - m_Parent->HandleMessage(this, buf); - if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second) - { - EncryptAndSend(msg.ACKS()); - } - m_RXMsgs.erase(rxid); + HandleRecvMsgCompleted(itr->second); } } else @@ -829,22 +822,34 @@ namespace llarp { if (itr->second.Verify()) { - auto msg = std::move(itr->second); - const llarp_buffer_t buf(msg.m_Data); - m_Parent->HandleMessage(this, buf); - if (m_ReplayFilter.emplace(itr->first, m_Parent->Now()).second) - { - EncryptAndSend(msg.ACKS()); - } + HandleRecvMsgCompleted(itr->second); } else { LogError("hash mismatch for message ", itr->first); } - m_RXMsgs.erase(itr); } } + void + Session::HandleRecvMsgCompleted(const InboundMessage& msg) + { + /// should we send a multiack? + constexpr bool UseMACK = false; + + const auto rxid = msg.m_MsgID; + if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second) + { + const llarp_buffer_t buf(msg.m_Data); + m_Parent->HandleMessage(this, buf); + if (UseMACK) + m_SendMACKs.emplace(rxid); + else + EncryptAndSend(msg.ACKS()); + } + m_RXMsgs.erase(rxid); + } + void Session::HandleACKS(Packet_t data) { diff --git a/llarp/iwp/session.hpp b/llarp/iwp/session.hpp index 976ef3ace..4555e3349 100644 --- a/llarp/iwp/session.hpp +++ b/llarp/iwp/session.hpp @@ -192,7 +192,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; + std::priority_queue m_SendMACKs; using CryptoQueue_t = std::vector; @@ -228,6 +228,9 @@ namespace llarp void SendMACK(); + void + HandleRecvMsgCompleted(const InboundMessage& msg); + void GenerateAndSendIntro(); From ad3c23ba2b8275d5aff4d6f298d7faba619a438a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 14 Feb 2021 08:26:19 -0500 Subject: [PATCH 4/7] simplify call --- llarp/iwp/session.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index 5d55e7a18..e910ae476 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -840,8 +840,7 @@ namespace llarp const auto rxid = msg.m_MsgID; if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second) { - const llarp_buffer_t buf(msg.m_Data); - m_Parent->HandleMessage(this, buf); + m_Parent->HandleMessage(this, msg.m_Data); if (UseMACK) m_SendMACKs.emplace(rxid); else From c9ff917e0dfdc438e0e8ac17d2ee13dea6aeaf41 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 14 Feb 2021 08:34:37 -0500 Subject: [PATCH 5/7] revert priority queue ordering change --- llarp/iwp/session.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/iwp/session.hpp b/llarp/iwp/session.hpp index 4555e3349..be360a44e 100644 --- a/llarp/iwp/session.hpp +++ b/llarp/iwp/session.hpp @@ -192,7 +192,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 m_SendMACKs; + std::priority_queue, std::greater> m_SendMACKs; using CryptoQueue_t = std::vector; From 8a4417cb1ab76414ea3e2d8666dc328556dcc5f3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 15 Feb 2021 10:49:26 -0500 Subject: [PATCH 6/7] reduce test message count so it can pass --- test/iwp/test_iwp_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/iwp/test_iwp_session.cpp b/test/iwp/test_iwp_session.cpp index a4c355aec..1d4fc297a 100644 --- a/test/iwp/test_iwp_session.cpp +++ b/test/iwp/test_iwp_session.cpp @@ -252,7 +252,7 @@ TEST_CASE("IWP send messages", "[iwp]") std::function endTestNow, Context_ptr alice, Context_ptr bob) { - constexpr int numSend = 128; + constexpr int numSend = 64; // when alice makes a session to bob send `aliceNumSend` messages to him alice->InitLink([endIfDone, alice, &aliceNumSent](auto session) { for (auto index = 0; index < numSend; index++) From 7dbd25f271d1310b60d59159f2e50c92d9c21e3e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 4 Mar 2021 15:25:11 -0500 Subject: [PATCH 7/7] don't leave old multi ack codepath in --- llarp/iwp/session.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index e910ae476..8197a9593 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -834,17 +834,11 @@ namespace llarp void Session::HandleRecvMsgCompleted(const InboundMessage& msg) { - /// should we send a multiack? - constexpr bool UseMACK = false; - const auto rxid = msg.m_MsgID; if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second) { m_Parent->HandleMessage(this, msg.m_Data); - if (UseMACK) - m_SendMACKs.emplace(rxid); - else - EncryptAndSend(msg.ACKS()); + EncryptAndSend(msg.ACKS()); } m_RXMsgs.erase(rxid); }