Fix some low hanging performance issues

pull/203/head
Michael 6 years ago
parent 576af013e6
commit df4fd0ef56
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -1,3 +1,5 @@
#ifndef LLARP_DNS_DNS_HPP
#define LLARP_DNS_DNS_HPP
#include <dns/name.hpp> #include <dns/name.hpp>
#include <dns/rr.hpp> #include <dns/rr.hpp>
#include <dns/serialize.hpp> #include <dns/serialize.hpp>
@ -17,4 +19,6 @@ namespace llarp
constexpr uint16_t qClassIN = 1; constexpr uint16_t qClassIN = 1;
} // namespace dns } // namespace dns
} // namespace llarp } // namespace llarp
#endif

@ -23,7 +23,7 @@ namespace llarp
/// handle a hooked message /// handle a hooked message
virtual bool virtual bool
HandleHookedDNSMessage(Message query, HandleHookedDNSMessage(dns::Message&& query,
std::function< void(Message) > sendReply) = 0; std::function< void(Message) > sendReply) = 0;
}; };

@ -78,7 +78,7 @@ namespace llarp
if(!path) if(!path)
return true; return true;
auto lastPing = path->LastRemoteActivityAt(); auto lastPing = path->LastRemoteActivityAt();
if(lastPing == 0 || ( now > lastPing && now - lastPing > timeout)) if(lastPing == 0 || (now > lastPing && now - lastPing > timeout))
return now > m_LastActive && now - m_LastActive > timeout; return now > m_LastActive && now - m_LastActive > timeout;
else if(lastPing) else if(lastPing)
return now > lastPing && now - lastPing > timeout; return now > lastPing && now - lastPing > timeout;
@ -160,7 +160,7 @@ namespace llarp
{ {
auto& msg = queue.front(); auto& msg = queue.front();
msg.S = path->NextSeqNo(); msg.S = path->NextSeqNo();
if(path->SendRoutingMessage(&msg, m_Parent->Router())) if(path->SendRoutingMessage(&msg, m_Parent->GetRouter()))
{ {
m_RxRate += msg.Size(); m_RxRate += msg.Size();
sent = true; sent = true;
@ -177,7 +177,7 @@ namespace llarp
llarp::path::IHopHandler* llarp::path::IHopHandler*
Endpoint::GetCurrentPath() const Endpoint::GetCurrentPath() const
{ {
auto router = m_Parent->Router(); auto router = m_Parent->GetRouter();
return router->paths.GetByUpstream(router->pubkey(), m_CurrentPath); return router->paths.GetByUpstream(router->pubkey(), m_CurrentPath);
} }
} // namespace exit } // namespace exit

@ -21,7 +21,7 @@ namespace llarp
static_cast< ExitEndpoint * >(tun->user)->Flush(); static_cast< ExitEndpoint * >(tun->user)->Flush();
} }
ExitEndpoint::ExitEndpoint(const std::string &name, llarp::Router *r) ExitEndpoint::ExitEndpoint(const std::string &name, Router *r)
: m_Router(r) : m_Router(r)
, m_Resolver(r->netloop, this) , m_Resolver(r->netloop, this)
, m_Name(name) , m_Name(name)
@ -41,18 +41,18 @@ namespace llarp
} }
bool bool
ExitEndpoint::ShouldHookDNSMessage(const llarp::dns::Message &msg) const ExitEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const
{ {
if(msg.questions.size() == 0) if(msg.questions.size() == 0)
return false; return false;
if(msg.questions[0].qtype == llarp::dns::qTypePTR) if(msg.questions[0].qtype == dns::qTypePTR)
{ {
llarp::huint32_t ip; huint32_t ip;
if(!llarp::dns::DecodePTR(msg.questions[0].qname, ip)) if(!dns::DecodePTR(msg.questions[0].qname, ip))
return false; return false;
return m_OurRange.Contains(ip); return m_OurRange.Contains(ip);
} }
else if(msg.questions[0].qtype == llarp::dns::qTypeA) else if(msg.questions[0].qtype == dns::qTypeA)
{ {
return msg.questions[0].qname.find(".snode.") return msg.questions[0].qname.find(".snode.")
== (msg.questions[0].qname.size() - 7); == (msg.questions[0].qname.size() - 7);
@ -63,17 +63,16 @@ namespace llarp
bool bool
ExitEndpoint::HandleHookedDNSMessage( ExitEndpoint::HandleHookedDNSMessage(
llarp::dns::Message msg, dns::Message &&msg, std::function< void(dns::Message) > reply)
std::function< void(llarp::dns::Message) > reply)
{ {
if(msg.questions[0].qtype == llarp::dns::qTypePTR) if(msg.questions[0].qtype == dns::qTypePTR)
{ {
llarp::huint32_t ip; huint32_t ip;
if(!llarp::dns::DecodePTR(msg.questions[0].qname, ip)) if(!dns::DecodePTR(msg.questions[0].qname, ip))
return false; return false;
if(ip == m_IfAddr) if(ip == m_IfAddr)
{ {
RouterID us = Router()->pubkey(); RouterID us = GetRouter()->pubkey();
msg.AddAReply(us.ToString(), 300); msg.AddAReply(us.ToString(), 300);
} }
else else
@ -89,7 +88,7 @@ namespace llarp
msg.AddNXReply(); msg.AddNXReply();
} }
} }
else if(msg.questions[0].qtype == llarp::dns::qTypeA) else if(msg.questions[0].qtype == dns::qTypeA)
{ {
// forward dns for snode // forward dns for snode
RouterID r; RouterID r;
@ -134,14 +133,13 @@ namespace llarp
ExitEndpoint::Flush() ExitEndpoint::Flush()
{ {
m_InetToNetwork.Process([&](Pkt_t &pkt) { m_InetToNetwork.Process([&](Pkt_t &pkt) {
llarp::PubKey pk; PubKey pk;
{ {
auto itr = m_IPToKey.find(pkt.dst()); auto itr = m_IPToKey.find(pkt.dst());
if(itr == m_IPToKey.end()) if(itr == m_IPToKey.end())
{ {
// drop // drop
llarp::LogWarn(Name(), " dropping packet, has no session at ", LogWarn(Name(), " dropping packet, has no session at ", pkt.dst());
pkt.dst());
return; return;
} }
pk = itr->second; pk = itr->second;
@ -155,25 +153,24 @@ namespace llarp
auto itr = m_SNodeSessions.find(pk); auto itr = m_SNodeSessions.find(pk);
if(itr != m_SNodeSessions.end()) if(itr != m_SNodeSessions.end())
{ {
if(itr->second->QueueUpstreamTraffic(pkt, if(itr->second->QueueUpstreamTraffic(pkt, routing::ExitPadSize))
llarp::routing::ExitPadSize))
return; return;
} }
} }
llarp::exit::Endpoint *ep = m_ChosenExits[pk]; exit::Endpoint *ep = m_ChosenExits[pk];
if(ep == nullptr) if(ep == nullptr)
{ {
// we may have all dead sessions, wtf now? // we may have all dead sessions, wtf now?
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk, LogWarn(Name(), " dropped inbound traffic for session ", pk,
" as we have no working endpoints"); " as we have no working endpoints");
} }
else else
{ {
if(!ep->QueueInboundTraffic(pkt.Buffer())) if(!ep->QueueInboundTraffic(pkt.Buffer()))
{ {
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk, LogWarn(Name(), " dropped inbound traffic for session ", pk,
" as we are overloaded (probably)"); " as we are overloaded (probably)");
} }
} }
}); });
@ -183,8 +180,7 @@ namespace llarp
{ {
if(!itr->second->Flush()) if(!itr->second->Flush())
{ {
llarp::LogWarn("exit session with ", itr->first, LogWarn("exit session with ", itr->first, " dropped packets");
" dropped packets");
} }
++itr; ++itr;
} }
@ -195,8 +191,8 @@ namespace llarp
{ {
if(!itr->second->Flush()) if(!itr->second->Flush())
{ {
llarp::LogWarn("failed to flush snode traffic to ", itr->first, LogWarn("failed to flush snode traffic to ", itr->first,
" via outbound session"); " via outbound session");
} }
++itr; ++itr;
} }
@ -208,7 +204,7 @@ namespace llarp
{ {
if(m_ShouldInitTun) if(m_ShouldInitTun)
{ {
if(!llarp_ev_add_tun(Router()->netloop, &m_Tun)) if(!llarp_ev_add_tun(GetRouter()->netloop, &m_Tun))
return false; return false;
if(m_UpstreamResolvers.size() == 0) if(m_UpstreamResolvers.size() == 0)
m_UpstreamResolvers.emplace_back("8.8.8.8", 53); m_UpstreamResolvers.emplace_back("8.8.8.8", 53);
@ -217,13 +213,13 @@ namespace llarp
return true; return true;
} }
llarp::Router * Router *
ExitEndpoint::Router() ExitEndpoint::GetRouter()
{ {
return m_Router; return m_Router;
} }
llarp::Crypto * Crypto *
ExitEndpoint::Crypto() ExitEndpoint::Crypto()
{ {
return &m_Router->crypto; return &m_Router->crypto;
@ -253,13 +249,13 @@ namespace llarp
} }
bool bool
ExitEndpoint::HasLocalMappedAddrFor(const llarp::PubKey &pk) const ExitEndpoint::HasLocalMappedAddrFor(const PubKey &pk) const
{ {
return m_KeyToIP.find(pk) != m_KeyToIP.end(); return m_KeyToIP.find(pk) != m_KeyToIP.end();
} }
huint32_t huint32_t
ExitEndpoint::GetIPForIdent(const llarp::PubKey pk) ExitEndpoint::GetIPForIdent(const PubKey pk)
{ {
huint32_t found = {0}; huint32_t found = {0};
if(!HasLocalMappedAddrFor(pk)) if(!HasLocalMappedAddrFor(pk))
@ -268,18 +264,18 @@ namespace llarp
found.h = AllocateNewAddress().h; found.h = AllocateNewAddress().h;
if(!m_KeyToIP.emplace(pk, found).second) if(!m_KeyToIP.emplace(pk, found).second)
{ {
llarp::LogError(Name(), "failed to map ", pk, " to ", found); LogError(Name(), "failed to map ", pk, " to ", found);
return found; return found;
} }
if(!m_IPToKey.emplace(found, pk).second) if(!m_IPToKey.emplace(found, pk).second)
{ {
llarp::LogError(Name(), "failed to map ", found, " to ", pk); LogError(Name(), "failed to map ", found, " to ", pk);
return found; return found;
} }
if(HasLocalMappedAddrFor(pk)) if(HasLocalMappedAddrFor(pk))
llarp::LogInfo(Name(), " mapping ", pk, " to ", found); LogInfo(Name(), " mapping ", pk, " to ", found);
else else
llarp::LogError(Name(), "failed to map ", pk, " to ", found); LogError(Name(), "failed to map ", pk, " to ", found);
} }
else else
found.h = m_KeyToIP[pk].h; found.h = m_KeyToIP[pk].h;
@ -311,7 +307,7 @@ namespace llarp
} }
// kick old ident off exit // kick old ident off exit
// TODO: DoS // TODO: DoS
llarp::PubKey pk = m_IPToKey[found]; PubKey pk = m_IPToKey[found];
KickIdentOffExit(pk); KickIdentOffExit(pk);
return found; return found;
@ -324,9 +320,9 @@ namespace llarp
} }
void void
ExitEndpoint::KickIdentOffExit(const llarp::PubKey &pk) ExitEndpoint::KickIdentOffExit(const PubKey &pk)
{ {
llarp::LogInfo(Name(), " kicking ", pk, " off exit"); LogInfo(Name(), " kicking ", pk, " off exit");
huint32_t ip = m_KeyToIP[pk]; huint32_t ip = m_KeyToIP[pk];
m_KeyToIP.erase(pk); m_KeyToIP.erase(pk);
m_IPToKey.erase(ip); m_IPToKey.erase(ip);
@ -337,9 +333,9 @@ namespace llarp
} }
void void
ExitEndpoint::MarkIPActive(llarp::huint32_t ip) ExitEndpoint::MarkIPActive(huint32_t ip)
{ {
m_IPActivity[ip] = Router()->Now(); m_IPActivity[ip] = GetRouter()->Now();
} }
void void
@ -350,9 +346,9 @@ namespace llarp
} }
bool bool
ExitEndpoint::QueueSNodePacket(llarp_buffer_t buf, llarp::huint32_t from) ExitEndpoint::QueueSNodePacket(llarp_buffer_t buf, huint32_t from)
{ {
llarp::net::IPv4Packet pkt; net::IPv4Packet pkt;
if(!pkt.Load(buf)) if(!pkt.Load(buf))
return false; return false;
// rewrite ip // rewrite ip
@ -360,11 +356,11 @@ namespace llarp
return llarp_ev_tun_async_write(&m_Tun, pkt.Buffer()); return llarp_ev_tun_async_write(&m_Tun, pkt.Buffer());
} }
llarp::exit::Endpoint * exit::Endpoint *
ExitEndpoint::FindEndpointByPath(const llarp::PathID_t &path) ExitEndpoint::FindEndpointByPath(const PathID_t &path)
{ {
llarp::exit::Endpoint *endpoint = nullptr; exit::Endpoint *endpoint = nullptr;
llarp::PubKey pk; PubKey pk;
{ {
auto itr = m_Paths.find(path); auto itr = m_Paths.find(path);
if(itr == m_Paths.end()) if(itr == m_Paths.end())
@ -383,8 +379,7 @@ namespace llarp
} }
bool bool
ExitEndpoint::UpdateEndpointPath(const llarp::PubKey &remote, ExitEndpoint::UpdateEndpointPath(const PubKey &remote, const PathID_t &next)
const llarp::PathID_t &next)
{ {
// check if already mapped // check if already mapped
auto itr = m_Paths.find(next); auto itr = m_Paths.find(next);
@ -417,8 +412,8 @@ namespace llarp
resolverAddr = v.substr(0, pos); resolverAddr = v.substr(0, pos);
dnsport = std::atoi(v.substr(pos + 1).c_str()); dnsport = std::atoi(v.substr(pos + 1).c_str());
} }
m_LocalResolverAddr = llarp::Addr(resolverAddr, dnsport); m_LocalResolverAddr = Addr(resolverAddr, dnsport);
llarp::LogInfo(Name(), " local dns set to ", m_LocalResolverAddr); LogInfo(Name(), " local dns set to ", m_LocalResolverAddr);
} }
if(k == "upstream-dns") if(k == "upstream-dns")
{ {
@ -431,15 +426,15 @@ namespace llarp
dnsport = std::atoi(v.substr(pos + 1).c_str()); dnsport = std::atoi(v.substr(pos + 1).c_str());
} }
m_UpstreamResolvers.emplace_back(resolverAddr, dnsport); m_UpstreamResolvers.emplace_back(resolverAddr, dnsport);
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr, LogInfo(Name(), " adding upstream dns set to ", resolverAddr, ":",
":", dnsport); dnsport);
} }
if(k == "ifaddr") if(k == "ifaddr")
{ {
auto pos = v.find("/"); auto pos = v.find("/");
if(pos == std::string::npos) if(pos == std::string::npos)
{ {
llarp::LogError(Name(), " ifaddr is not a cidr: ", v); LogError(Name(), " ifaddr is not a cidr: ", v);
return false; return false;
} }
std::string nmask_str = v.substr(1 + pos); std::string nmask_str = v.substr(1 + pos);
@ -448,24 +443,24 @@ namespace llarp
strncpy(m_Tun.ifaddr, host_str.c_str(), sizeof(m_Tun.ifaddr) - 1); strncpy(m_Tun.ifaddr, host_str.c_str(), sizeof(m_Tun.ifaddr) - 1);
m_Tun.netmask = std::atoi(nmask_str.c_str()); m_Tun.netmask = std::atoi(nmask_str.c_str());
llarp::Addr ifaddr(host_str); Addr ifaddr(host_str);
m_IfAddr = ifaddr.xtohl(); m_IfAddr = ifaddr.xtohl();
m_OurRange.netmask_bits = netmask_ipv4_bits(m_Tun.netmask); m_OurRange.netmask_bits = netmask_ipv4_bits(m_Tun.netmask);
m_OurRange.addr = m_IfAddr; m_OurRange.addr = m_IfAddr;
m_NextAddr = m_IfAddr; m_NextAddr = m_IfAddr;
m_HigestAddr = m_IfAddr | (~m_OurRange.netmask_bits); m_HigestAddr = m_IfAddr | (~m_OurRange.netmask_bits);
llarp::LogInfo(Name(), " set ifaddr range to ", m_Tun.ifaddr, "/", LogInfo(Name(), " set ifaddr range to ", m_Tun.ifaddr, "/",
m_Tun.netmask, " lo=", m_IfAddr, " hi=", m_HigestAddr); m_Tun.netmask, " lo=", m_IfAddr, " hi=", m_HigestAddr);
} }
if(k == "ifname") if(k == "ifname")
{ {
if(v.length() >= sizeof(m_Tun.ifname)) if(v.length() >= sizeof(m_Tun.ifname))
{ {
llarp::LogError(Name() + " ifname '", v, "' is too long"); LogError(Name() + " ifname '", v, "' is too long");
return false; return false;
} }
strncpy(m_Tun.ifname, v.c_str(), sizeof(m_Tun.ifname) - 1); strncpy(m_Tun.ifname, v.c_str(), sizeof(m_Tun.ifname) - 1);
llarp::LogInfo(Name(), " set ifname to ", m_Tun.ifname); LogInfo(Name(), " set ifname to ", m_Tun.ifname);
} }
if(k == "exit-whitelist") if(k == "exit-whitelist")
{ {
@ -484,7 +479,7 @@ namespace llarp
} }
huint32_t huint32_t
ExitEndpoint::ObtainServiceNodeIP(const llarp::RouterID &other) ExitEndpoint::ObtainServiceNodeIP(const RouterID &other)
{ {
PubKey pubKey(other); PubKey pubKey(other);
huint32_t ip = GetIPForIdent(pubKey); huint32_t ip = GetIPForIdent(pubKey);
@ -493,32 +488,30 @@ namespace llarp
// this is a new service node make an outbound session to them // this is a new service node make an outbound session to them
m_SNodeSessions.emplace( m_SNodeSessions.emplace(
other, other,
std::unique_ptr< llarp::exit::SNodeSession >( std::unique_ptr< exit::SNodeSession >(new exit::SNodeSession(
new llarp::exit::SNodeSession( other,
other, std::bind(&ExitEndpoint::QueueSNodePacket, this,
std::bind(&ExitEndpoint::QueueSNodePacket, this, std::placeholders::_1, ip),
std::placeholders::_1, ip), GetRouter(), 2, 1, true)));
Router(), 2, 1, true)));
} }
return ip; return ip;
} }
bool bool
ExitEndpoint::AllocateNewExit(const llarp::PubKey pk, ExitEndpoint::AllocateNewExit(const PubKey pk, const PathID_t &path,
const llarp::PathID_t &path,
bool wantInternet) bool wantInternet)
{ {
if(wantInternet && !m_PermitExit) if(wantInternet && !m_PermitExit)
return false; return false;
huint32_t ip = GetIPForIdent(pk); huint32_t ip = GetIPForIdent(pk);
if(Router()->paths.TransitHopPreviousIsRouter(path, pk.as_array())) if(GetRouter()->paths.TransitHopPreviousIsRouter(path, pk.as_array()))
{ {
// we think this path belongs to a service node // we think this path belongs to a service node
// mark it as such so we don't make an outbound session to them // mark it as such so we don't make an outbound session to them
m_SNodeKeys.emplace(pk.as_array()); m_SNodeKeys.emplace(pk.as_array());
} }
m_ActiveExits.emplace(pk, m_ActiveExits.emplace(pk,
std::make_unique< llarp::exit::Endpoint >( std::make_unique< exit::Endpoint >(
pk, path, !wantInternet, ip, this)); pk, path, !wantInternet, ip, this));
m_Paths[path] = pk; m_Paths[path] = pk;
@ -532,13 +525,13 @@ namespace llarp
} }
void void
ExitEndpoint::DelEndpointInfo(const llarp::PathID_t &path) ExitEndpoint::DelEndpointInfo(const PathID_t &path)
{ {
m_Paths.erase(path); m_Paths.erase(path);
} }
void void
ExitEndpoint::RemoveExit(const llarp::exit::Endpoint *ep) ExitEndpoint::RemoveExit(const exit::Endpoint *ep)
{ {
auto range = m_ActiveExits.equal_range(ep->PubKey()); auto range = m_ActiveExits.equal_range(ep->PubKey());
auto itr = range.first; auto itr = range.first;

@ -8,11 +8,12 @@
namespace llarp namespace llarp
{ {
struct Router;
namespace handlers namespace handlers
{ {
struct ExitEndpoint : public llarp::dns::IQueryHandler struct ExitEndpoint : public dns::IQueryHandler
{ {
ExitEndpoint(const std::string& name, llarp::Router* r); ExitEndpoint(const std::string& name, Router* r);
~ExitEndpoint(); ~ExitEndpoint();
void void
@ -25,38 +26,36 @@ namespace llarp
Name() const; Name() const;
bool bool
ShouldHookDNSMessage(const llarp::dns::Message& msg) const override; ShouldHookDNSMessage(const dns::Message& msg) const override;
bool bool
HandleHookedDNSMessage( HandleHookedDNSMessage(dns::Message&& msg,
llarp::dns::Message, std::function< void(dns::Message) >) override;
std::function< void(llarp::dns::Message) >) override;
bool bool
AllocateNewExit(const llarp::PubKey pk, const llarp::PathID_t& path, AllocateNewExit(const PubKey pk, const PathID_t& path,
bool permitInternet); bool permitInternet);
llarp::exit::Endpoint* exit::Endpoint*
FindEndpointByPath(const llarp::PathID_t& path); FindEndpointByPath(const PathID_t& path);
llarp::exit::Endpoint* exit::Endpoint*
FindEndpointByIP(huint32_t ip); FindEndpointByIP(huint32_t ip);
bool bool
UpdateEndpointPath(const llarp::PubKey& remote, UpdateEndpointPath(const PubKey& remote, const PathID_t& next);
const llarp::PathID_t& next);
/// handle ip packet from outside /// handle ip packet from outside
void void
OnInetPacket(llarp_buffer_t buf); OnInetPacket(llarp_buffer_t buf);
llarp::Router* Router*
Router(); GetRouter();
llarp_time_t llarp_time_t
Now() const; Now() const;
llarp::Crypto* Crypto*
Crypto(); Crypto();
template < typename Stats > template < typename Stats >
@ -74,11 +73,11 @@ namespace llarp
/// DO NOT CALL ME /// DO NOT CALL ME
void void
DelEndpointInfo(const llarp::PathID_t& path); DelEndpointInfo(const PathID_t& path);
/// DO NOT CALL ME /// DO NOT CALL ME
void void
RemoveExit(const llarp::exit::Endpoint* ep); RemoveExit(const exit::Endpoint* ep);
bool bool
QueueOutboundTraffic(llarp_buffer_t buf); QueueOutboundTraffic(llarp_buffer_t buf);
@ -94,7 +93,7 @@ namespace llarp
ShouldRemove() const; ShouldRemove() const;
bool bool
HasLocalMappedAddrFor(const llarp::PubKey& pk) const; HasLocalMappedAddrFor(const PubKey& pk) const;
huint32_t huint32_t
GetIfAddr() const; GetIfAddr() const;
@ -104,7 +103,7 @@ namespace llarp
private: private:
huint32_t huint32_t
GetIPForIdent(const llarp::PubKey pk); GetIPForIdent(const PubKey pk);
huint32_t huint32_t
AllocateNewAddress(); AllocateNewAddress();
@ -112,75 +111,64 @@ namespace llarp
/// obtain ip for service node session, creates a new session if one does /// obtain ip for service node session, creates a new session if one does
/// not existing already /// not existing already
huint32_t huint32_t
ObtainServiceNodeIP(const llarp::RouterID& router); ObtainServiceNodeIP(const RouterID& router);
bool bool
QueueSNodePacket(llarp_buffer_t buf, llarp::huint32_t from); QueueSNodePacket(llarp_buffer_t buf, huint32_t from);
void void
MarkIPActive(llarp::huint32_t ip); MarkIPActive(huint32_t ip);
void void
KickIdentOffExit(const llarp::PubKey& pk); KickIdentOffExit(const PubKey& pk);
llarp::Router* m_Router; Router* m_Router;
llarp::dns::Proxy m_Resolver; dns::Proxy m_Resolver;
bool m_ShouldInitTun; bool m_ShouldInitTun;
std::string m_Name; std::string m_Name;
bool m_PermitExit; bool m_PermitExit;
std::unordered_map< llarp::PathID_t, llarp::PubKey, std::unordered_map< PathID_t, PubKey, PathID_t::Hash > m_Paths;
llarp::PathID_t::Hash >
m_Paths;
std::unordered_map< llarp::PubKey, llarp::exit::Endpoint*, std::unordered_map< PubKey, exit::Endpoint*, PubKey::Hash > m_ChosenExits;
llarp::PubKey::Hash >
m_ChosenExits;
std::unordered_multimap< llarp::PubKey, std::unordered_multimap< PubKey, std::unique_ptr< exit::Endpoint >,
std::unique_ptr< llarp::exit::Endpoint >, PubKey::Hash >
llarp::PubKey::Hash >
m_ActiveExits; m_ActiveExits;
using KeyMap_t = std::unordered_map< llarp::PubKey, llarp::huint32_t, using KeyMap_t = std::unordered_map< PubKey, huint32_t, PubKey::Hash >;
llarp::PubKey::Hash >;
KeyMap_t m_KeyToIP; KeyMap_t m_KeyToIP;
using SNodes_t = std::set< llarp::PubKey >; using SNodes_t = std::set< PubKey >;
/// set of pubkeys we treat as snodes /// set of pubkeys we treat as snodes
SNodes_t m_SNodeKeys; SNodes_t m_SNodeKeys;
using SNodeSessions_t = using SNodeSessions_t =
std::unordered_map< llarp::RouterID, std::unordered_map< RouterID, std::unique_ptr< exit::SNodeSession >,
std::unique_ptr< llarp::exit::SNodeSession >, RouterID::Hash >;
llarp::RouterID::Hash >;
/// snode sessions we are talking to directly /// snode sessions we are talking to directly
SNodeSessions_t m_SNodeSessions; SNodeSessions_t m_SNodeSessions;
std::unordered_map< llarp::huint32_t, llarp::PubKey, std::unordered_map< huint32_t, PubKey, huint32_t::Hash > m_IPToKey;
llarp::huint32_t::Hash >
m_IPToKey;
huint32_t m_IfAddr; huint32_t m_IfAddr;
huint32_t m_HigestAddr; huint32_t m_HigestAddr;
huint32_t m_NextAddr; huint32_t m_NextAddr;
llarp::IPRange m_OurRange; IPRange m_OurRange;
std::unordered_map< llarp::huint32_t, llarp_time_t, std::unordered_map< huint32_t, llarp_time_t, huint32_t::Hash >
llarp::huint32_t::Hash >
m_IPActivity; m_IPActivity;
llarp_tun_io m_Tun; llarp_tun_io m_Tun;
llarp::Addr m_LocalResolverAddr; Addr m_LocalResolverAddr;
std::vector< llarp::Addr > m_UpstreamResolvers; std::vector< Addr > m_UpstreamResolvers;
using Pkt_t = llarp::net::IPv4Packet; using Pkt_t = net::IPv4Packet;
using PacketQueue_t = using PacketQueue_t =
llarp::util::CoDelQueue< Pkt_t, Pkt_t::GetTime, Pkt_t::PutTime, util::CoDelQueue< Pkt_t, Pkt_t::GetTime, Pkt_t::PutTime,
Pkt_t::CompareOrder, Pkt_t::GetNow, Pkt_t::CompareOrder, Pkt_t::GetNow,
llarp::util::DummyMutex, util::DummyMutex, util::DummyLock, 5, 100, 1024 >;
llarp::util::DummyLock, 5, 100, 1024 >;
/// internet to llarp packet queue /// internet to llarp packet queue
PacketQueue_t m_InetToNetwork; PacketQueue_t m_InetToNetwork;

@ -194,7 +194,7 @@ namespace llarp
bool bool
TunEndpoint::HandleHookedDNSMessage( TunEndpoint::HandleHookedDNSMessage(
dns::Message msg, std::function< void(dns::Message) > reply) dns::Message &&msg, std::function< void(dns::Message) > reply)
{ {
if(msg.questions.size() != 1) if(msg.questions.size() != 1)
{ {
@ -232,12 +232,13 @@ namespace llarp
msg.AddINReply(ip); msg.AddINReply(ip);
} }
else else
return EnsurePathToService( {
addr, service::Endpoint::PathEnsureHook hook = [&](service::Address addr,
std::bind(&TunEndpoint::SendDNSReply, this, OutboundContext *ctx) {
std::placeholders::_1, std::placeholders::_2, msg, this->SendDNSReply(addr, ctx, std::move(msg), reply);
reply), };
2000); return EnsurePathToService(addr, hook, 2000);
}
} }
else if(addr.FromString(qname, ".snode")) else if(addr.FromString(qname, ".snode"))
{ {
@ -320,7 +321,7 @@ namespace llarp
void void
TunEndpoint::SendDNSReply(service::Address addr, TunEndpoint::SendDNSReply(service::Address addr,
service::Endpoint::OutboundContext *ctx, service::Endpoint::OutboundContext *ctx,
dns::Message request, dns::Message &&request,
std::function< void(dns::Message) > reply) std::function< void(dns::Message) > reply)
{ {
if(ctx) if(ctx)

@ -34,7 +34,7 @@ namespace llarp
bool bool
HandleHookedDNSMessage( HandleHookedDNSMessage(
dns::Message query, dns::Message&& query,
std::function< void(dns::Message) > sendreply) override; std::function< void(dns::Message) > sendreply) override;
void void
@ -181,7 +181,8 @@ namespace llarp
void void
SendDNSReply(service::Address addr, SendDNSReply(service::Address addr,
service::Endpoint::OutboundContext* ctx, dns::Message query, service::Endpoint::OutboundContext* ctx,
dns::Message&& query,
std::function< void(dns::Message) > reply); std::function< void(dns::Message) > reply);
#ifndef WIN32 #ifndef WIN32

@ -423,7 +423,7 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
{ {
/// checking for "guard" status for N = 0 is done by caller inside of /// checking for "guard" status for N = 0 is done by caller inside of
/// pathbuilder's scope /// pathbuilder's scope
auto sz = entries.size(); size_t sz = entries.size();
if(sz < 3) if(sz < 3)
return false; return false;
size_t tries = 5; size_t tries = 5;
@ -433,12 +433,6 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
do do
{ {
auto itr = entries.begin(); auto itr = entries.begin();
if(sz > 1)
{
auto idx = llarp::randint() % sz;
if(idx)
std::advance(itr, idx - 1);
}
if(prev.pubkey == itr->second.pubkey) if(prev.pubkey == itr->second.pubkey)
{ {
if(tries--) if(tries--)

@ -917,11 +917,8 @@ namespace llarp
bool bool
Endpoint::CheckPathIsDead(__attribute__((unused)) path::Path* p, Endpoint::CheckPathIsDead(__attribute__((unused)) path::Path* p,
llarp_time_t latency) __attribute__((unused)) llarp_time_t latency)
{ {
if(latency >= m_MinPathLatency)
{
}
return false; return false;
} }

@ -7,6 +7,7 @@
#include <net.hpp> #include <net.hpp>
#include <path.hpp> #include <path.hpp>
#include <pathbuilder.hpp> #include <pathbuilder.hpp>
#include <service/address.hpp>
#include <service/Identity.hpp> #include <service/Identity.hpp>
#include <service/handler.hpp> #include <service/handler.hpp>
#include <service/protocol.hpp> #include <service/protocol.hpp>

Loading…
Cancel
Save