From 41807f1763a7722e17d99444f6efb15e9aa79b92 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 9 Nov 2021 19:48:41 -0400 Subject: [PATCH] transit hop: drop instead of flushing when full If full happens we are going to trigger a bunch of flushes which probably isn't very useful, so drop instead. --- llarp/path/transit_hop.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/llarp/path/transit_hop.cpp b/llarp/path/transit_hop.cpp index 09cd6059c..2e09a6f74 100644 --- a/llarp/path/transit_hop.cpp +++ b/llarp/path/transit_hop.cpp @@ -142,14 +142,6 @@ namespace llarp void TransitHop::UpstreamWork(TrafficQueue_ptr msgs, AbstractRouter* r) { - auto flushIt = [self = shared_from_this(), r]() { - std::vector msgs; - while (auto maybe = self->m_UpstreamGather.tryPopFront()) - { - msgs.push_back(*maybe); - } - self->HandleAllUpstream(std::move(msgs), r); - }; for (auto& ev : *msgs) { const llarp_buffer_t buf(ev.first); @@ -158,14 +150,19 @@ namespace llarp msg.pathid = info.txID; msg.Y = ev.second ^ nonceXOR; msg.X = buf; - if (m_UpstreamGather.full()) + if (m_UpstreamGather.tryPushBack(msg) != thread::QueueReturn::Success) + break; + } + + // Flush it: + r->loop()->call([self = shared_from_this(), r] { + std::vector msgs; + while (auto maybe = self->m_UpstreamGather.tryPopFront()) { - r->loop()->call(flushIt); + msgs.push_back(*maybe); } - if (m_UpstreamGather.enabled()) - m_UpstreamGather.pushBack(msg); - } - r->loop()->call(flushIt); + self->HandleAllUpstream(std::move(msgs), r); + }); } void