* lower lookup timeout for introsets

* correct previous commit for dns stuff
* allow for multiple parallel introset lookups
pull/285/head
Jeff Becker 6 years ago
parent 2f369a3399
commit f84256d554
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -297,9 +297,10 @@ namespace llarp
} }
else else
{ {
dns::Message *replyMsg = new dns::Message(std::move(msg));
service::Endpoint::PathEnsureHook hook = std::bind( service::Endpoint::PathEnsureHook hook = std::bind(
&TunEndpoint::SendDNSReply, this, std::placeholders::_1, &TunEndpoint::SendDNSReply, this, std::placeholders::_1,
std::placeholders::_2, std::move(msg), reply); std::placeholders::_2, replyMsg, reply);
return EnsurePathToService(addr, hook, 2000); return EnsurePathToService(addr, hook, 2000);
} }
} }
@ -397,18 +398,19 @@ 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)
{ {
huint32_t ip = ObtainIPForAddr(addr, false); huint32_t ip = ObtainIPForAddr(addr, false);
request.AddINReply(ip); request->AddINReply(ip);
} }
else else
request.AddNXReply(); request->AddNXReply();
reply(request); reply(*request);
delete request;
} }
bool bool

@ -191,7 +191,7 @@ 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

@ -87,8 +87,18 @@ namespace llarp
bool bool
Endpoint::HasPendingPathToService(const Address& addr) const Endpoint::HasPendingPathToService(const Address& addr) const
{ {
return m_PendingServiceLookups.find(addr) if(m_PendingServiceLookups.find(addr) == m_PendingServiceLookups.end())
!= m_PendingServiceLookups.end(); {
auto range = m_RemoteSessions.equal_range(addr);
auto itr = range.first;
while(itr != range.second)
{
if(itr->second->ReadyToSend())
return false;
++itr;
}
}
return true;
} }
void void
@ -365,24 +375,7 @@ namespace llarp
if(!introset.Verify(crypto, Now())) if(!introset.Verify(crypto, Now()))
{ {
if(m_Identity.pub == introset.A && m_CurrentPublishTX == msg->T) if(m_Identity.pub == introset.A && m_CurrentPublishTX == msg->T)
{
IntroSetPublishFail(); IntroSetPublishFail();
}
else
{
auto itr = m_PendingLookups.find(msg->T);
if(itr == m_PendingLookups.end())
{
llarp::LogWarn(
"invalid lookup response for hidden service endpoint ",
Name(), " txid=", msg->T);
return true;
}
std::unique_ptr< IServiceLookup > lookup = std::move(itr->second);
m_PendingLookups.erase(itr);
lookup->HandleResponse({});
return true;
}
return true; return true;
} }
if(m_Identity.pub == introset.A && m_CurrentPublishTX == msg->T) if(m_Identity.pub == introset.A && m_CurrentPublishTX == msg->T)
@ -686,7 +679,13 @@ namespace llarp
llarp::LogInfo("found ", results.size(), " for ", remote.ToString()); llarp::LogInfo("found ", results.size(), " for ", remote.ToString());
if(results.size() > 0) if(results.size() > 0)
{ {
return handle(remote, &*results.begin(), endpoint); IntroSet selected;
for(const auto& introset : results)
{
if(selected.OtherIsNewer(introset) && introset.A.Addr() == remote)
selected = introset;
}
return handle(remote, &selected, endpoint);
} }
return handle(remote, nullptr, endpoint); return handle(remote, nullptr, endpoint);
} }
@ -728,13 +727,14 @@ namespace llarp
{ {
auto itr = m_RemoteSessions.find(addr); auto itr = m_RemoteSessions.find(addr);
auto i = m_PendingServiceLookups.find(addr); auto range = m_PendingServiceLookups.equal_range(addr);
if(i != m_PendingServiceLookups.end()) auto i = range.first;
if(i != range.second)
{ {
auto f = i->second; i->second(addr, itr->second.get());
m_PendingServiceLookups.erase(i); ++i;
f(addr, itr->second.get());
} }
m_PendingServiceLookups.erase(addr);
return; return;
} }
@ -744,13 +744,14 @@ namespace llarp
llarp::LogInfo("Created New outbound context for ", addr.ToString()); llarp::LogInfo("Created New outbound context for ", addr.ToString());
// inform pending // inform pending
auto itr = m_PendingServiceLookups.find(addr); auto range = m_PendingServiceLookups.equal_range(addr);
if(itr != m_PendingServiceLookups.end()) auto itr = range.first;
if(itr != range.second)
{ {
auto f = itr->second; itr->second(addr, ctx);
m_PendingServiceLookups.erase(itr); ++itr;
f(addr, ctx);
} }
m_PendingServiceLookups.erase(addr);
} }
bool bool
@ -965,16 +966,18 @@ namespace llarp
llarp::LogError(Name(), " failed to lookup ", addr.ToString(), " from ", llarp::LogError(Name(), " failed to lookup ", addr.ToString(), " from ",
endpoint); endpoint);
m_ServiceLookupFails[endpoint] = m_ServiceLookupFails[endpoint] + 1; m_ServiceLookupFails[endpoint] = m_ServiceLookupFails[endpoint] + 1;
auto itr = m_PendingServiceLookups.find(addr); auto range = m_PendingServiceLookups.equal_range(addr);
if(itr != m_PendingServiceLookups.end()) auto itr = range.first;
if(itr != range.second)
{ {
auto func = itr->second; itr->second(addr, nullptr);
m_PendingServiceLookups.erase(itr); ++itr;
func(addr, nullptr);
} }
m_PendingServiceLookups.erase(addr);
return false; return false;
} }
PutNewOutboundContext(*introset); else
PutNewOutboundContext(*introset);
return true; return true;
} }
@ -1004,18 +1007,6 @@ namespace llarp
return true; return true;
} }
} }
{
auto itr = m_PendingServiceLookups.find(remote);
if(itr != m_PendingServiceLookups.end())
{
// duplicate
llarp::LogWarn("duplicate pending service lookup to ",
remote.ToString());
return false;
}
}
m_PendingServiceLookups.insert(std::make_pair(remote, hook));
{ {
RouterID endpoint = path->Endpoint(); RouterID endpoint = path->Endpoint();
auto itr = m_ServiceLookupFails.find(endpoint); auto itr = m_ServiceLookupFails.find(endpoint);
@ -1042,7 +1033,10 @@ namespace llarp
remote, GenTXID()); remote, GenTXID());
llarp::LogInfo("doing lookup for ", remote, " via ", path->Endpoint()); llarp::LogInfo("doing lookup for ", remote, " via ", path->Endpoint());
if(job->SendRequestViaPath(path, Router())) if(job->SendRequestViaPath(path, Router()))
{
m_PendingServiceLookups.insert(std::make_pair(remote, hook));
return true; return true;
}
llarp::LogError("send via path failed"); llarp::LogError("send via path failed");
return false; return false;
} }

@ -485,7 +485,7 @@ namespace llarp
std::unordered_map< Address, ServiceInfo, Address::Hash > std::unordered_map< Address, ServiceInfo, Address::Hash >
m_AddressToService; m_AddressToService;
std::unordered_map< Address, PathEnsureHook, Address::Hash > std::unordered_multimap< Address, PathEnsureHook, Address::Hash >
m_PendingServiceLookups; m_PendingServiceLookups;
std::unordered_map< RouterID, uint32_t, RouterID::Hash > std::unordered_map< RouterID, uint32_t, RouterID::Hash >

@ -33,7 +33,7 @@ namespace llarp
/// determine if this request has timed out /// determine if this request has timed out
bool bool
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 20000) const IsTimedOut(llarp_time_t now, llarp_time_t timeout = 15000) const
{ {
if(now <= m_created) if(now <= m_created)
return false; return false;

Loading…
Cancel
Save