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.
pull/1619/head
Jeff Becker 3 years ago
parent f89c3f6b21
commit 54f9e1b44e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -659,6 +659,21 @@ namespace llarp
m_SRVRecords.push_back(std::move(newSRV)); m_SRVRecords.push_back(std::move(newSRV));
}); });
conf.defineOption<int>(
"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: // Deprecated options:
conf.defineOption<std::string>("network", "enabled", Deprecated); conf.defineOption<std::string>("network", "enabled", Deprecated);
} }

@ -125,6 +125,8 @@ namespace llarp
std::set<IPRange> m_OwnedRanges; std::set<IPRange> m_OwnedRanges;
std::optional<net::TrafficPolicy> m_TrafficPolicy; std::optional<net::TrafficPolicy> m_TrafficPolicy;
std::optional<llarp_time_t> m_PathAlignmentTimeout;
// TODO: // TODO:
// on-up // on-up
// on-down // on-down

@ -131,6 +131,8 @@ namespace llarp
m_Resolver->Restart(); m_Resolver->Restart();
} }
constexpr auto DefaultAlignmentTimeout = 10s;
bool bool
TunEndpoint::Configure(const NetworkConfig& conf, const DnsConfig& dnsConf) TunEndpoint::Configure(const NetworkConfig& conf, const DnsConfig& dnsConf)
{ {
@ -167,6 +169,13 @@ namespace llarp
m_BaseV6Address = conf.m_baseV6Address; 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) for (const auto& item : conf.m_mapAddrs)
{ {
if (not MapAddress(item.second, item.first, false)) if (not MapAddress(item.second, item.first, false))
@ -259,8 +268,6 @@ namespace llarp
return service::Address{itr->second.as_array()}; return service::Address{itr->second.as_array()};
} }
constexpr auto TrafficAlignmentTimeout = 10s;
bool bool
TunEndpoint::HandleHookedDNSMessage(dns::Message msg, std::function<void(dns::Message)> reply) TunEndpoint::HandleHookedDNSMessage(dns::Message msg, std::function<void(dns::Message)> reply)
{ {
@ -272,7 +279,7 @@ namespace llarp
SendDNSReply(snode, s, msg, reply, isV6); 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 { service::Address addr, auto msg, bool isV6) -> bool {
using service::Address; using service::Address;
using service::OutboundContext; using service::OutboundContext;
@ -281,7 +288,7 @@ namespace llarp
[this, addr, msg, reply, isV6](const Address&, OutboundContext* ctx) { [this, addr, msg, reply, isV6](const Address&, OutboundContext* ctx) {
SendDNSReply(addr, ctx, msg, reply, isV6); SendDNSReply(addr, ctx, msg, reply, isV6);
}, },
TrafficAlignmentTimeout); timeout);
}; };
auto ReplyToDNSWhenReady = [ReplyToLokiDNSWhenReady, ReplyToSNodeDNSWhenReady]( 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::Address;
using service::OutboundContext; using service::OutboundContext;
@ -312,7 +320,7 @@ namespace llarp
msg->AddSRVReply(introset.GetMatchingSRVRecords(addr.subdomain)); msg->AddSRVReply(introset.GetMatchingSRVRecords(addr.subdomain));
reply(*msg); reply(*msg);
}, },
TrafficAlignmentTimeout); timeout);
}; };
if (msg.answers.size() > 0) if (msg.answers.size() > 0)
@ -924,7 +932,7 @@ namespace llarp
} }
self->SendToOrQueue(addr, pkt.ConstBuffer(), service::ProtocolType::Exit); self->SendToOrQueue(addr, pkt.ConstBuffer(), service::ProtocolType::Exit);
}, },
TrafficAlignmentTimeout); m_PathAlignmentTimeout);
return; return;
} }
bool rewriteAddrs = true; bool rewriteAddrs = true;

@ -267,6 +267,8 @@ namespace llarp
std::optional<net::TrafficPolicy> m_TrafficPolicy; std::optional<net::TrafficPolicy> m_TrafficPolicy;
/// ranges we advetise as reachable /// ranges we advetise as reachable
std::set<IPRange> m_OwnedRanges; std::set<IPRange> m_OwnedRanges;
/// how long to wait for path alignment
llarp_time_t m_PathAlignmentTimeout;
}; };
} // namespace handlers } // namespace handlers

Loading…
Cancel
Save