From 54f9e1b44e79f3b0d7555eaf58f1a05d9ad86c1f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 1 May 2021 16:25:32 -0400 Subject: [PATCH] make path alignment timeout configuable adds [network] section parameter called path-alignment-timeout that allows configring the timeout for optional name lookup + introset lookup + aligned path build, used by tun endpoint dns, provided as milliseconds. --- llarp/config/config.cpp | 15 +++++++++++++++ llarp/config/config.hpp | 2 ++ llarp/handlers/tun.cpp | 22 +++++++++++++++------- llarp/handlers/tun.hpp | 2 ++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index e6deec451..6ce3971a3 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -659,6 +659,21 @@ namespace llarp m_SRVRecords.push_back(std::move(newSRV)); }); + conf.defineOption( + "network", + "path-alignment-timeout", + ClientOnly, + Comment{ + "time in milliseconds how long to wait for a path to align to pivot routers", + "if not provided a sensible default will be used", + }, + [this](int val) { + if (val <= 200) + throw std::invalid_argument{ + "invalid path alignment timeout: " + std::to_string(val) + " <= 200"}; + m_PathAlignmentTimeout = std::chrono::milliseconds{val}; + }); + // Deprecated options: conf.defineOption("network", "enabled", Deprecated); } diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 399fac8a2..7fb212df4 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -125,6 +125,8 @@ namespace llarp std::set m_OwnedRanges; std::optional m_TrafficPolicy; + std::optional m_PathAlignmentTimeout; + // TODO: // on-up // on-down diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index cc7dd67e5..172479ddd 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -131,6 +131,8 @@ namespace llarp m_Resolver->Restart(); } + constexpr auto DefaultAlignmentTimeout = 10s; + bool TunEndpoint::Configure(const NetworkConfig& conf, const DnsConfig& dnsConf) { @@ -167,6 +169,13 @@ namespace llarp m_BaseV6Address = conf.m_baseV6Address; + if (conf.m_PathAlignmentTimeout) + { + m_PathAlignmentTimeout = *conf.m_PathAlignmentTimeout; + } + else + m_PathAlignmentTimeout = DefaultAlignmentTimeout; + for (const auto& item : conf.m_mapAddrs) { if (not MapAddress(item.second, item.first, false)) @@ -259,8 +268,6 @@ namespace llarp return service::Address{itr->second.as_array()}; } - constexpr auto TrafficAlignmentTimeout = 10s; - bool TunEndpoint::HandleHookedDNSMessage(dns::Message msg, std::function reply) { @@ -272,7 +279,7 @@ namespace llarp SendDNSReply(snode, s, msg, reply, isV6); }); }; - auto ReplyToLokiDNSWhenReady = [this, reply]( + auto ReplyToLokiDNSWhenReady = [this, reply, timeout = m_PathAlignmentTimeout]( service::Address addr, auto msg, bool isV6) -> bool { using service::Address; using service::OutboundContext; @@ -281,7 +288,7 @@ namespace llarp [this, addr, msg, reply, isV6](const Address&, OutboundContext* ctx) { SendDNSReply(addr, ctx, msg, reply, isV6); }, - TrafficAlignmentTimeout); + timeout); }; auto ReplyToDNSWhenReady = [ReplyToLokiDNSWhenReady, ReplyToSNodeDNSWhenReady]( @@ -298,7 +305,8 @@ namespace llarp } }; - auto ReplyToLokiSRVWhenReady = [this, reply](service::Address addr, auto msg) -> bool { + auto ReplyToLokiSRVWhenReady = [this, reply, timeout = m_PathAlignmentTimeout]( + service::Address addr, auto msg) -> bool { using service::Address; using service::OutboundContext; @@ -312,7 +320,7 @@ namespace llarp msg->AddSRVReply(introset.GetMatchingSRVRecords(addr.subdomain)); reply(*msg); }, - TrafficAlignmentTimeout); + timeout); }; if (msg.answers.size() > 0) @@ -924,7 +932,7 @@ namespace llarp } self->SendToOrQueue(addr, pkt.ConstBuffer(), service::ProtocolType::Exit); }, - TrafficAlignmentTimeout); + m_PathAlignmentTimeout); return; } bool rewriteAddrs = true; diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 77054fb6f..f1626d468 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -267,6 +267,8 @@ namespace llarp std::optional m_TrafficPolicy; /// ranges we advetise as reachable std::set m_OwnedRanges; + /// how long to wait for path alignment + llarp_time_t m_PathAlignmentTimeout; }; } // namespace handlers