mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
Merge pull request #203 from michael-loki/low_hanging
Fix some low hanging performance issues
This commit is contained in:
commit
e0db332130
@ -1,3 +1,5 @@
|
||||
#ifndef LLARP_DNS_DNS_HPP
|
||||
#define LLARP_DNS_DNS_HPP
|
||||
#include <dns/name.hpp>
|
||||
#include <dns/rr.hpp>
|
||||
#include <dns/serialize.hpp>
|
||||
@ -18,3 +20,5 @@ namespace llarp
|
||||
constexpr uint16_t qClassIN = 1;
|
||||
} // namespace dns
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,7 @@ namespace llarp
|
||||
|
||||
/// handle a hooked message
|
||||
virtual bool
|
||||
HandleHookedDNSMessage(Message query,
|
||||
HandleHookedDNSMessage(dns::Message&& query,
|
||||
std::function< void(Message) > sendReply) = 0;
|
||||
};
|
||||
|
||||
|
@ -160,7 +160,7 @@ namespace llarp
|
||||
{
|
||||
auto& msg = queue.front();
|
||||
msg.S = path->NextSeqNo();
|
||||
if(path->SendRoutingMessage(&msg, m_Parent->Router()))
|
||||
if(path->SendRoutingMessage(&msg, m_Parent->GetRouter()))
|
||||
{
|
||||
m_RxRate += msg.Size();
|
||||
sent = true;
|
||||
@ -177,7 +177,7 @@ namespace llarp
|
||||
llarp::path::IHopHandler*
|
||||
Endpoint::GetCurrentPath() const
|
||||
{
|
||||
auto router = m_Parent->Router();
|
||||
auto router = m_Parent->GetRouter();
|
||||
return router->paths.GetByUpstream(router->pubkey(), m_CurrentPath);
|
||||
}
|
||||
} // namespace exit
|
||||
|
@ -21,7 +21,7 @@ namespace llarp
|
||||
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_Resolver(r->netloop, this)
|
||||
, m_Name(name)
|
||||
@ -41,18 +41,18 @@ namespace llarp
|
||||
}
|
||||
|
||||
bool
|
||||
ExitEndpoint::ShouldHookDNSMessage(const llarp::dns::Message &msg) const
|
||||
ExitEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const
|
||||
{
|
||||
if(msg.questions.size() == 0)
|
||||
return false;
|
||||
if(msg.questions[0].qtype == llarp::dns::qTypePTR)
|
||||
if(msg.questions[0].qtype == dns::qTypePTR)
|
||||
{
|
||||
llarp::huint32_t ip;
|
||||
if(!llarp::dns::DecodePTR(msg.questions[0].qname, ip))
|
||||
huint32_t ip;
|
||||
if(!dns::DecodePTR(msg.questions[0].qname, ip))
|
||||
return false;
|
||||
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.")
|
||||
== (msg.questions[0].qname.size() - 7);
|
||||
@ -63,17 +63,16 @@ namespace llarp
|
||||
|
||||
bool
|
||||
ExitEndpoint::HandleHookedDNSMessage(
|
||||
llarp::dns::Message msg,
|
||||
std::function< void(llarp::dns::Message) > reply)
|
||||
dns::Message &&msg, std::function< void(dns::Message) > reply)
|
||||
{
|
||||
if(msg.questions[0].qtype == llarp::dns::qTypePTR)
|
||||
if(msg.questions[0].qtype == dns::qTypePTR)
|
||||
{
|
||||
llarp::huint32_t ip;
|
||||
if(!llarp::dns::DecodePTR(msg.questions[0].qname, ip))
|
||||
huint32_t ip;
|
||||
if(!dns::DecodePTR(msg.questions[0].qname, ip))
|
||||
return false;
|
||||
if(ip == m_IfAddr)
|
||||
{
|
||||
RouterID us = Router()->pubkey();
|
||||
RouterID us = GetRouter()->pubkey();
|
||||
msg.AddAReply(us.ToString(), 300);
|
||||
}
|
||||
else
|
||||
@ -89,7 +88,7 @@ namespace llarp
|
||||
msg.AddNXReply();
|
||||
}
|
||||
}
|
||||
else if(msg.questions[0].qtype == llarp::dns::qTypeA)
|
||||
else if(msg.questions[0].qtype == dns::qTypeA)
|
||||
{
|
||||
// forward dns for snode
|
||||
RouterID r;
|
||||
@ -134,14 +133,13 @@ namespace llarp
|
||||
ExitEndpoint::Flush()
|
||||
{
|
||||
m_InetToNetwork.Process([&](Pkt_t &pkt) {
|
||||
llarp::PubKey pk;
|
||||
PubKey pk;
|
||||
{
|
||||
auto itr = m_IPToKey.find(pkt.dst());
|
||||
if(itr == m_IPToKey.end())
|
||||
{
|
||||
// drop
|
||||
llarp::LogWarn(Name(), " dropping packet, has no session at ",
|
||||
pkt.dst());
|
||||
LogWarn(Name(), " dropping packet, has no session at ", pkt.dst());
|
||||
return;
|
||||
}
|
||||
pk = itr->second;
|
||||
@ -155,24 +153,23 @@ namespace llarp
|
||||
auto itr = m_SNodeSessions.find(pk);
|
||||
if(itr != m_SNodeSessions.end())
|
||||
{
|
||||
if(itr->second->QueueUpstreamTraffic(pkt,
|
||||
llarp::routing::ExitPadSize))
|
||||
if(itr->second->QueueUpstreamTraffic(pkt, routing::ExitPadSize))
|
||||
return;
|
||||
}
|
||||
}
|
||||
llarp::exit::Endpoint *ep = m_ChosenExits[pk];
|
||||
exit::Endpoint *ep = m_ChosenExits[pk];
|
||||
|
||||
if(ep == nullptr)
|
||||
{
|
||||
// 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");
|
||||
}
|
||||
else
|
||||
{
|
||||
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)");
|
||||
}
|
||||
}
|
||||
@ -183,8 +180,7 @@ namespace llarp
|
||||
{
|
||||
if(!itr->second->Flush())
|
||||
{
|
||||
llarp::LogWarn("exit session with ", itr->first,
|
||||
" dropped packets");
|
||||
LogWarn("exit session with ", itr->first, " dropped packets");
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
@ -195,7 +191,7 @@ namespace llarp
|
||||
{
|
||||
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");
|
||||
}
|
||||
++itr;
|
||||
@ -208,7 +204,7 @@ namespace llarp
|
||||
{
|
||||
if(m_ShouldInitTun)
|
||||
{
|
||||
if(!llarp_ev_add_tun(Router()->netloop, &m_Tun))
|
||||
if(!llarp_ev_add_tun(GetRouter()->netloop, &m_Tun))
|
||||
return false;
|
||||
if(m_UpstreamResolvers.size() == 0)
|
||||
m_UpstreamResolvers.emplace_back("8.8.8.8", 53);
|
||||
@ -217,13 +213,13 @@ namespace llarp
|
||||
return true;
|
||||
}
|
||||
|
||||
llarp::Router *
|
||||
ExitEndpoint::Router()
|
||||
Router *
|
||||
ExitEndpoint::GetRouter()
|
||||
{
|
||||
return m_Router;
|
||||
}
|
||||
|
||||
llarp::Crypto *
|
||||
Crypto *
|
||||
ExitEndpoint::Crypto()
|
||||
{
|
||||
return &m_Router->crypto;
|
||||
@ -253,13 +249,13 @@ namespace llarp
|
||||
}
|
||||
|
||||
bool
|
||||
ExitEndpoint::HasLocalMappedAddrFor(const llarp::PubKey &pk) const
|
||||
ExitEndpoint::HasLocalMappedAddrFor(const PubKey &pk) const
|
||||
{
|
||||
return m_KeyToIP.find(pk) != m_KeyToIP.end();
|
||||
}
|
||||
|
||||
huint32_t
|
||||
ExitEndpoint::GetIPForIdent(const llarp::PubKey pk)
|
||||
ExitEndpoint::GetIPForIdent(const PubKey pk)
|
||||
{
|
||||
huint32_t found = {0};
|
||||
if(!HasLocalMappedAddrFor(pk))
|
||||
@ -268,18 +264,18 @@ namespace llarp
|
||||
found.h = AllocateNewAddress().h;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if(HasLocalMappedAddrFor(pk))
|
||||
llarp::LogInfo(Name(), " mapping ", pk, " to ", found);
|
||||
LogInfo(Name(), " mapping ", pk, " to ", found);
|
||||
else
|
||||
llarp::LogError(Name(), "failed to map ", pk, " to ", found);
|
||||
LogError(Name(), "failed to map ", pk, " to ", found);
|
||||
}
|
||||
else
|
||||
found.h = m_KeyToIP[pk].h;
|
||||
@ -311,7 +307,7 @@ namespace llarp
|
||||
}
|
||||
// kick old ident off exit
|
||||
// TODO: DoS
|
||||
llarp::PubKey pk = m_IPToKey[found];
|
||||
PubKey pk = m_IPToKey[found];
|
||||
KickIdentOffExit(pk);
|
||||
|
||||
return found;
|
||||
@ -324,9 +320,9 @@ namespace llarp
|
||||
}
|
||||
|
||||
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];
|
||||
m_KeyToIP.erase(pk);
|
||||
m_IPToKey.erase(ip);
|
||||
@ -337,9 +333,9 @@ namespace llarp
|
||||
}
|
||||
|
||||
void
|
||||
ExitEndpoint::MarkIPActive(llarp::huint32_t ip)
|
||||
ExitEndpoint::MarkIPActive(huint32_t ip)
|
||||
{
|
||||
m_IPActivity[ip] = Router()->Now();
|
||||
m_IPActivity[ip] = GetRouter()->Now();
|
||||
}
|
||||
|
||||
void
|
||||
@ -350,9 +346,9 @@ namespace llarp
|
||||
}
|
||||
|
||||
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))
|
||||
return false;
|
||||
// rewrite ip
|
||||
@ -360,11 +356,11 @@ namespace llarp
|
||||
return llarp_ev_tun_async_write(&m_Tun, pkt.Buffer());
|
||||
}
|
||||
|
||||
llarp::exit::Endpoint *
|
||||
ExitEndpoint::FindEndpointByPath(const llarp::PathID_t &path)
|
||||
exit::Endpoint *
|
||||
ExitEndpoint::FindEndpointByPath(const PathID_t &path)
|
||||
{
|
||||
llarp::exit::Endpoint *endpoint = nullptr;
|
||||
llarp::PubKey pk;
|
||||
exit::Endpoint *endpoint = nullptr;
|
||||
PubKey pk;
|
||||
{
|
||||
auto itr = m_Paths.find(path);
|
||||
if(itr == m_Paths.end())
|
||||
@ -383,8 +379,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
bool
|
||||
ExitEndpoint::UpdateEndpointPath(const llarp::PubKey &remote,
|
||||
const llarp::PathID_t &next)
|
||||
ExitEndpoint::UpdateEndpointPath(const PubKey &remote, const PathID_t &next)
|
||||
{
|
||||
// check if already mapped
|
||||
auto itr = m_Paths.find(next);
|
||||
@ -417,8 +412,8 @@ namespace llarp
|
||||
resolverAddr = v.substr(0, pos);
|
||||
dnsport = std::atoi(v.substr(pos + 1).c_str());
|
||||
}
|
||||
m_LocalResolverAddr = llarp::Addr(resolverAddr, dnsport);
|
||||
llarp::LogInfo(Name(), " local dns set to ", m_LocalResolverAddr);
|
||||
m_LocalResolverAddr = Addr(resolverAddr, dnsport);
|
||||
LogInfo(Name(), " local dns set to ", m_LocalResolverAddr);
|
||||
}
|
||||
if(k == "upstream-dns")
|
||||
{
|
||||
@ -431,15 +426,15 @@ namespace llarp
|
||||
dnsport = std::atoi(v.substr(pos + 1).c_str());
|
||||
}
|
||||
m_UpstreamResolvers.emplace_back(resolverAddr, dnsport);
|
||||
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr,
|
||||
":", dnsport);
|
||||
LogInfo(Name(), " adding upstream dns set to ", resolverAddr, ":",
|
||||
dnsport);
|
||||
}
|
||||
if(k == "ifaddr")
|
||||
{
|
||||
auto pos = v.find("/");
|
||||
if(pos == std::string::npos)
|
||||
{
|
||||
llarp::LogError(Name(), " ifaddr is not a cidr: ", v);
|
||||
LogError(Name(), " ifaddr is not a cidr: ", v);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
m_Tun.netmask = std::atoi(nmask_str.c_str());
|
||||
|
||||
llarp::Addr ifaddr(host_str);
|
||||
Addr ifaddr(host_str);
|
||||
m_IfAddr = ifaddr.xtohl();
|
||||
m_OurRange.netmask_bits = netmask_ipv4_bits(m_Tun.netmask);
|
||||
m_OurRange.addr = m_IfAddr;
|
||||
m_NextAddr = m_IfAddr;
|
||||
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);
|
||||
}
|
||||
if(k == "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;
|
||||
}
|
||||
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")
|
||||
{
|
||||
@ -484,7 +479,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
huint32_t
|
||||
ExitEndpoint::ObtainServiceNodeIP(const llarp::RouterID &other)
|
||||
ExitEndpoint::ObtainServiceNodeIP(const RouterID &other)
|
||||
{
|
||||
PubKey pubKey(other);
|
||||
huint32_t ip = GetIPForIdent(pubKey);
|
||||
@ -493,32 +488,30 @@ namespace llarp
|
||||
// this is a new service node make an outbound session to them
|
||||
m_SNodeSessions.emplace(
|
||||
other,
|
||||
std::unique_ptr< llarp::exit::SNodeSession >(
|
||||
new llarp::exit::SNodeSession(
|
||||
std::unique_ptr< exit::SNodeSession >(new exit::SNodeSession(
|
||||
other,
|
||||
std::bind(&ExitEndpoint::QueueSNodePacket, this,
|
||||
std::placeholders::_1, ip),
|
||||
Router(), 2, 1, true)));
|
||||
GetRouter(), 2, 1, true)));
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
bool
|
||||
ExitEndpoint::AllocateNewExit(const llarp::PubKey pk,
|
||||
const llarp::PathID_t &path,
|
||||
ExitEndpoint::AllocateNewExit(const PubKey pk, const PathID_t &path,
|
||||
bool wantInternet)
|
||||
{
|
||||
if(wantInternet && !m_PermitExit)
|
||||
return false;
|
||||
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
|
||||
// mark it as such so we don't make an outbound session to them
|
||||
m_SNodeKeys.emplace(pk.as_array());
|
||||
}
|
||||
m_ActiveExits.emplace(pk,
|
||||
std::make_unique< llarp::exit::Endpoint >(
|
||||
std::make_unique< exit::Endpoint >(
|
||||
pk, path, !wantInternet, ip, this));
|
||||
|
||||
m_Paths[path] = pk;
|
||||
@ -532,13 +525,13 @@ namespace llarp
|
||||
}
|
||||
|
||||
void
|
||||
ExitEndpoint::DelEndpointInfo(const llarp::PathID_t &path)
|
||||
ExitEndpoint::DelEndpointInfo(const PathID_t &path)
|
||||
{
|
||||
m_Paths.erase(path);
|
||||
}
|
||||
|
||||
void
|
||||
ExitEndpoint::RemoveExit(const llarp::exit::Endpoint *ep)
|
||||
ExitEndpoint::RemoveExit(const exit::Endpoint *ep)
|
||||
{
|
||||
auto range = m_ActiveExits.equal_range(ep->PubKey());
|
||||
auto itr = range.first;
|
||||
|
@ -8,11 +8,12 @@
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct Router;
|
||||
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();
|
||||
|
||||
void
|
||||
@ -25,38 +26,36 @@ namespace llarp
|
||||
Name() const;
|
||||
|
||||
bool
|
||||
ShouldHookDNSMessage(const llarp::dns::Message& msg) const override;
|
||||
ShouldHookDNSMessage(const dns::Message& msg) const override;
|
||||
|
||||
bool
|
||||
HandleHookedDNSMessage(
|
||||
llarp::dns::Message,
|
||||
std::function< void(llarp::dns::Message) >) override;
|
||||
HandleHookedDNSMessage(dns::Message&& msg,
|
||||
std::function< void(dns::Message) >) override;
|
||||
|
||||
bool
|
||||
AllocateNewExit(const llarp::PubKey pk, const llarp::PathID_t& path,
|
||||
AllocateNewExit(const PubKey pk, const PathID_t& path,
|
||||
bool permitInternet);
|
||||
|
||||
llarp::exit::Endpoint*
|
||||
FindEndpointByPath(const llarp::PathID_t& path);
|
||||
exit::Endpoint*
|
||||
FindEndpointByPath(const PathID_t& path);
|
||||
|
||||
llarp::exit::Endpoint*
|
||||
exit::Endpoint*
|
||||
FindEndpointByIP(huint32_t ip);
|
||||
|
||||
bool
|
||||
UpdateEndpointPath(const llarp::PubKey& remote,
|
||||
const llarp::PathID_t& next);
|
||||
UpdateEndpointPath(const PubKey& remote, const PathID_t& next);
|
||||
|
||||
/// handle ip packet from outside
|
||||
void
|
||||
OnInetPacket(llarp_buffer_t buf);
|
||||
|
||||
llarp::Router*
|
||||
Router();
|
||||
Router*
|
||||
GetRouter();
|
||||
|
||||
llarp_time_t
|
||||
Now() const;
|
||||
|
||||
llarp::Crypto*
|
||||
Crypto*
|
||||
Crypto();
|
||||
|
||||
template < typename Stats >
|
||||
@ -74,11 +73,11 @@ namespace llarp
|
||||
|
||||
/// DO NOT CALL ME
|
||||
void
|
||||
DelEndpointInfo(const llarp::PathID_t& path);
|
||||
DelEndpointInfo(const PathID_t& path);
|
||||
|
||||
/// DO NOT CALL ME
|
||||
void
|
||||
RemoveExit(const llarp::exit::Endpoint* ep);
|
||||
RemoveExit(const exit::Endpoint* ep);
|
||||
|
||||
bool
|
||||
QueueOutboundTraffic(llarp_buffer_t buf);
|
||||
@ -94,7 +93,7 @@ namespace llarp
|
||||
ShouldRemove() const;
|
||||
|
||||
bool
|
||||
HasLocalMappedAddrFor(const llarp::PubKey& pk) const;
|
||||
HasLocalMappedAddrFor(const PubKey& pk) const;
|
||||
|
||||
huint32_t
|
||||
GetIfAddr() const;
|
||||
@ -104,7 +103,7 @@ namespace llarp
|
||||
|
||||
private:
|
||||
huint32_t
|
||||
GetIPForIdent(const llarp::PubKey pk);
|
||||
GetIPForIdent(const PubKey pk);
|
||||
|
||||
huint32_t
|
||||
AllocateNewAddress();
|
||||
@ -112,75 +111,64 @@ namespace llarp
|
||||
/// obtain ip for service node session, creates a new session if one does
|
||||
/// not existing already
|
||||
huint32_t
|
||||
ObtainServiceNodeIP(const llarp::RouterID& router);
|
||||
ObtainServiceNodeIP(const RouterID& router);
|
||||
|
||||
bool
|
||||
QueueSNodePacket(llarp_buffer_t buf, llarp::huint32_t from);
|
||||
QueueSNodePacket(llarp_buffer_t buf, huint32_t from);
|
||||
|
||||
void
|
||||
MarkIPActive(llarp::huint32_t ip);
|
||||
MarkIPActive(huint32_t ip);
|
||||
|
||||
void
|
||||
KickIdentOffExit(const llarp::PubKey& pk);
|
||||
KickIdentOffExit(const PubKey& pk);
|
||||
|
||||
llarp::Router* m_Router;
|
||||
llarp::dns::Proxy m_Resolver;
|
||||
Router* m_Router;
|
||||
dns::Proxy m_Resolver;
|
||||
bool m_ShouldInitTun;
|
||||
std::string m_Name;
|
||||
bool m_PermitExit;
|
||||
std::unordered_map< llarp::PathID_t, llarp::PubKey,
|
||||
llarp::PathID_t::Hash >
|
||||
m_Paths;
|
||||
std::unordered_map< PathID_t, PubKey, PathID_t::Hash > m_Paths;
|
||||
|
||||
std::unordered_map< llarp::PubKey, llarp::exit::Endpoint*,
|
||||
llarp::PubKey::Hash >
|
||||
m_ChosenExits;
|
||||
std::unordered_map< PubKey, exit::Endpoint*, PubKey::Hash > m_ChosenExits;
|
||||
|
||||
std::unordered_multimap< llarp::PubKey,
|
||||
std::unique_ptr< llarp::exit::Endpoint >,
|
||||
llarp::PubKey::Hash >
|
||||
std::unordered_multimap< PubKey, std::unique_ptr< exit::Endpoint >,
|
||||
PubKey::Hash >
|
||||
m_ActiveExits;
|
||||
|
||||
using KeyMap_t = std::unordered_map< llarp::PubKey, llarp::huint32_t,
|
||||
llarp::PubKey::Hash >;
|
||||
using KeyMap_t = std::unordered_map< PubKey, huint32_t, PubKey::Hash >;
|
||||
|
||||
KeyMap_t m_KeyToIP;
|
||||
|
||||
using SNodes_t = std::set< llarp::PubKey >;
|
||||
using SNodes_t = std::set< PubKey >;
|
||||
/// set of pubkeys we treat as snodes
|
||||
SNodes_t m_SNodeKeys;
|
||||
|
||||
using SNodeSessions_t =
|
||||
std::unordered_map< llarp::RouterID,
|
||||
std::unique_ptr< llarp::exit::SNodeSession >,
|
||||
llarp::RouterID::Hash >;
|
||||
std::unordered_map< RouterID, std::unique_ptr< exit::SNodeSession >,
|
||||
RouterID::Hash >;
|
||||
/// snode sessions we are talking to directly
|
||||
SNodeSessions_t m_SNodeSessions;
|
||||
|
||||
std::unordered_map< llarp::huint32_t, llarp::PubKey,
|
||||
llarp::huint32_t::Hash >
|
||||
m_IPToKey;
|
||||
std::unordered_map< huint32_t, PubKey, huint32_t::Hash > m_IPToKey;
|
||||
|
||||
huint32_t m_IfAddr;
|
||||
huint32_t m_HigestAddr;
|
||||
huint32_t m_NextAddr;
|
||||
llarp::IPRange m_OurRange;
|
||||
IPRange m_OurRange;
|
||||
|
||||
std::unordered_map< llarp::huint32_t, llarp_time_t,
|
||||
llarp::huint32_t::Hash >
|
||||
std::unordered_map< huint32_t, llarp_time_t, huint32_t::Hash >
|
||||
m_IPActivity;
|
||||
|
||||
llarp_tun_io m_Tun;
|
||||
|
||||
llarp::Addr m_LocalResolverAddr;
|
||||
std::vector< llarp::Addr > m_UpstreamResolvers;
|
||||
Addr m_LocalResolverAddr;
|
||||
std::vector< Addr > m_UpstreamResolvers;
|
||||
|
||||
using Pkt_t = llarp::net::IPv4Packet;
|
||||
using Pkt_t = net::IPv4Packet;
|
||||
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,
|
||||
llarp::util::DummyMutex,
|
||||
llarp::util::DummyLock, 5, 100, 1024 >;
|
||||
util::DummyMutex, util::DummyLock, 5, 100, 1024 >;
|
||||
|
||||
/// internet to llarp packet queue
|
||||
PacketQueue_t m_InetToNetwork;
|
||||
|
@ -194,7 +194,7 @@ namespace llarp
|
||||
|
||||
bool
|
||||
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)
|
||||
{
|
||||
@ -232,12 +232,13 @@ namespace llarp
|
||||
msg.AddINReply(ip);
|
||||
}
|
||||
else
|
||||
return EnsurePathToService(
|
||||
addr,
|
||||
std::bind(&TunEndpoint::SendDNSReply, this,
|
||||
std::placeholders::_1, std::placeholders::_2, msg,
|
||||
reply),
|
||||
2000);
|
||||
{
|
||||
service::Endpoint::PathEnsureHook hook = [&](service::Address addr,
|
||||
OutboundContext *ctx) {
|
||||
this->SendDNSReply(addr, ctx, std::move(msg), reply);
|
||||
};
|
||||
return EnsurePathToService(addr, hook, 2000);
|
||||
}
|
||||
}
|
||||
else if(addr.FromString(qname, ".snode"))
|
||||
{
|
||||
@ -320,7 +321,7 @@ namespace llarp
|
||||
void
|
||||
TunEndpoint::SendDNSReply(service::Address addr,
|
||||
service::Endpoint::OutboundContext *ctx,
|
||||
dns::Message request,
|
||||
dns::Message &&request,
|
||||
std::function< void(dns::Message) > reply)
|
||||
{
|
||||
if(ctx)
|
||||
|
@ -34,7 +34,7 @@ namespace llarp
|
||||
|
||||
bool
|
||||
HandleHookedDNSMessage(
|
||||
dns::Message query,
|
||||
dns::Message&& query,
|
||||
std::function< void(dns::Message) > sendreply) override;
|
||||
|
||||
void
|
||||
@ -181,7 +181,8 @@ namespace llarp
|
||||
|
||||
void
|
||||
SendDNSReply(service::Address addr,
|
||||
service::Endpoint::OutboundContext* ctx, dns::Message query,
|
||||
service::Endpoint::OutboundContext* ctx,
|
||||
dns::Message&& query,
|
||||
std::function< void(dns::Message) > reply);
|
||||
|
||||
#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
|
||||
/// pathbuilder's scope
|
||||
auto sz = entries.size();
|
||||
size_t sz = entries.size();
|
||||
if(sz < 3)
|
||||
return false;
|
||||
size_t tries = 5;
|
||||
@ -433,12 +433,6 @@ llarp_nodedb::select_random_hop(const llarp::RouterContact &prev,
|
||||
do
|
||||
{
|
||||
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(tries--)
|
||||
|
@ -917,11 +917,8 @@ namespace llarp
|
||||
|
||||
bool
|
||||
Endpoint::CheckPathIsDead(__attribute__((unused)) path::Path* p,
|
||||
llarp_time_t latency)
|
||||
__attribute__((unused)) llarp_time_t latency)
|
||||
{
|
||||
if(latency >= m_MinPathLatency)
|
||||
{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <net.hpp>
|
||||
#include <path.hpp>
|
||||
#include <pathbuilder.hpp>
|
||||
#include <service/address.hpp>
|
||||
#include <service/Identity.hpp>
|
||||
#include <service/handler.hpp>
|
||||
#include <service/protocol.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user