Merge pull request #271 from neuroscr/master

fix random.snode on MacOS and .snode not found
This commit is contained in:
Ryan Tharp 2019-02-04 19:57:30 -08:00 committed by GitHub
commit da556b4f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,6 +199,7 @@ namespace llarp
TunEndpoint::HandleHookedDNSMessage( TunEndpoint::HandleHookedDNSMessage(
dns::Message &&msg, std::function< void(dns::Message) > reply) dns::Message &&msg, std::function< void(dns::Message) > reply)
{ {
//llarp::LogInfo("Tun.HandleHookedDNSMessage ", msg.questions[0].qname);
if(msg.questions.size() != 1) if(msg.questions.size() != 1)
{ {
llarp::LogWarn("bad number of dns questions: ", msg.questions.size()); llarp::LogWarn("bad number of dns questions: ", msg.questions.size());
@ -247,8 +248,17 @@ namespace llarp
else if(msg.questions[0].qtype == dns::qTypeA) else if(msg.questions[0].qtype == dns::qTypeA)
{ {
llarp::service::Address addr; llarp::service::Address addr;
// forward dns // on MacOS this is a typeA query
if(msg.questions[0].qname == "localhost.loki" if(msg.questions[0].qname == "random.snode"
|| msg.questions[0].qname == "random.snode.")
{
RouterID random;
if(Router()->GetRandomGoodRouter(random))
msg.AddCNAMEReply(random.ToString(), 1);
else
msg.AddNXReply();
}
else if(msg.questions[0].qname == "localhost.loki"
|| msg.questions[0].qname == "localhost.loki.") || msg.questions[0].qname == "localhost.loki.")
{ {
size_t counter = 0; size_t counter = 0;
@ -287,9 +297,16 @@ namespace llarp
// TODO: add hook to EnsurePathToSNode // TODO: add hook to EnsurePathToSNode
EnsurePathToSNode(addr.as_array()); EnsurePathToSNode(addr.as_array());
huint32_t ip = ObtainIPForAddr(addr, true); huint32_t ip = ObtainIPForAddr(addr, true);
msg.AddINReply(ip); if (ip.h)
msg.AddINReply(ip);
else
{
llarp::LogWarn("no ip found for ", addr);
msg.AddNXReply();
}
} }
else else
// forward dns
msg.AddNXReply(); msg.AddNXReply();
reply(msg); reply(msg);