Merge pull request #454 from majestrate/master

staging
This commit is contained in:
Jeff 2019-03-27 10:00:14 -04:00 committed by GitHub
commit e80f2609dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 34 deletions

View File

@ -98,13 +98,8 @@ namespace llarp
// explicit next peer provided // explicit next peer provided
peer = *next; peer = *next;
} }
else if(!GetNextPeer(peer, peersAsked)) else if(GetNextPeer(peer, peersAsked))
{ {
// no more peers
llarp::LogInfo("no more peers for request asking for ", target);
return false;
}
const Key_t targetKey{target}; const Key_t targetKey{target};
if((prevPeer ^ targetKey) < (peer ^ targetKey)) if((prevPeer ^ targetKey) < (peer ^ targetKey))
{ {
@ -113,10 +108,13 @@ namespace llarp
" than ", prevPeer); " than ", prevPeer);
return false; return false;
} }
}
else else
{ {
peersAsked.insert(peer); llarp::LogInfo("no more peers for request asking for ", target);
return false;
} }
peersAsked.insert(peer);
DoNextRequest(peer); DoNextRequest(peer);
return true; return true;
} }

View File

@ -153,7 +153,7 @@ namespace llarp
} }
void void
Message::AddINReply(llarp::huint32_t ip, RR_TTL_t ttl) Message::AddINReply(llarp::huint32_t ip, bool isV6, RR_TTL_t ttl)
{ {
if(questions.size()) if(questions.size())
{ {
@ -161,11 +161,19 @@ namespace llarp
const auto& question = questions[0]; const auto& question = questions[0];
ResourceRecord rec; ResourceRecord rec;
rec.rr_name = question.qname; rec.rr_name = question.qname;
rec.rr_type = qTypeA;
rec.rr_class = qClassIN; rec.rr_class = qClassIN;
rec.ttl = ttl; rec.ttl = ttl;
if(isV6)
{
rec.rr_type = qTypeAAAA;
ip.SIIT(rec.rData);
}
else
{
rec.rr_type = qTypeA;
rec.rData.resize(4); rec.rData.resize(4);
htobe32buf(rec.rData.data(), ip.h); htobe32buf(rec.rData.data(), ip.h);
}
answers.emplace_back(std::move(rec)); answers.emplace_back(std::move(rec));
} }
} }

View File

@ -61,7 +61,7 @@ namespace llarp
AddCNAMEReply(std::string name, RR_TTL_t ttl = 1); AddCNAMEReply(std::string name, RR_TTL_t ttl = 1);
void void
AddINReply(llarp::huint32_t addr, RR_TTL_t ttl = 1); AddINReply(llarp::huint32_t addr, bool isV6, RR_TTL_t ttl = 1);
void void
AddAReply(std::string name, RR_TTL_t ttl = 1); AddAReply(std::string name, RR_TTL_t ttl = 1);

View File

@ -70,7 +70,8 @@ namespace llarp
return m_OurRange.Contains(ip); return m_OurRange.Contains(ip);
} }
else if(msg.questions[0].qtype == dns::qTypeA else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeCNAME) || msg.questions[0].qtype == dns::qTypeCNAME
|| msg.questions[0].qtype == dns::qTypeAAAA)
{ {
// hook for forward dns or cname when using snode tld // hook for forward dns or cname when using snode tld
if(msg.questions[0].qname.find(".snode.") if(msg.questions[0].qname.find(".snode.")
@ -130,8 +131,10 @@ namespace llarp
else else
msg.AddNXReply(); msg.AddNXReply();
} }
else if(msg.questions[0].qtype == dns::qTypeA) else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{ {
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
if(msg.questions[0].qname == "random.snode" if(msg.questions[0].qname == "random.snode"
|| msg.questions[0].qname == "random.snode.") || msg.questions[0].qname == "random.snode.")
{ {
@ -146,7 +149,7 @@ namespace llarp
if(msg.questions[0].qname == "localhost.loki." if(msg.questions[0].qname == "localhost.loki."
|| msg.questions[0].qname == "localhost.loki") || msg.questions[0].qname == "localhost.loki")
{ {
msg.AddINReply(GetIfAddr()); msg.AddINReply(GetIfAddr(), isV6);
reply(msg); reply(msg);
return true; return true;
} }
@ -161,7 +164,7 @@ namespace llarp
// we do not have it mapped // we do not have it mapped
// map it // map it
ip = ObtainServiceNodeIP(r); ip = ObtainServiceNodeIP(r);
msg.AddINReply(ip); msg.AddINReply(ip, isV6);
} }
else else
{ {
@ -170,7 +173,7 @@ namespace llarp
if(itr != m_KeyToIP.end()) if(itr != m_KeyToIP.end())
{ {
ip = itr->second; ip = itr->second;
msg.AddINReply(ip); msg.AddINReply(ip, isV6);
} }
else // fallback case that should never happen (probably) else // fallback case that should never happen (probably)
msg.AddNXReply(); msg.AddNXReply();

View File

@ -248,7 +248,8 @@ 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, " of type", msg.questions[0].qtype); // llarp::LogInfo("Tun.HandleHookedDNSMessage ", msg.questions[0].qname, "
// of type", msg.questions[0].qtype);
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());
@ -294,8 +295,10 @@ namespace llarp
msg.AddNXReply(); msg.AddNXReply();
reply(msg); reply(msg);
} }
else if(msg.questions[0].qtype == dns::qTypeA) else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{ {
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
llarp::service::Address addr; llarp::service::Address addr;
// on MacOS this is a typeA query // on MacOS this is a typeA query
if(is_random_snode(msg)) if(is_random_snode(msg))
@ -315,7 +318,7 @@ namespace llarp
huint32_t ip = service->GetIfAddr(); huint32_t ip = service->GetIfAddr();
if(ip.h) if(ip.h)
{ {
msg.AddINReply(ip); msg.AddINReply(ip, isV6);
++counter; ++counter;
} }
return true; return true;
@ -328,7 +331,7 @@ namespace llarp
if(HasAddress(addr)) if(HasAddress(addr))
{ {
huint32_t ip = ObtainIPForAddr(addr, false); huint32_t ip = ObtainIPForAddr(addr, false);
msg.AddINReply(ip); msg.AddINReply(ip, isV6);
} }
else else
{ {
@ -336,7 +339,7 @@ namespace llarp
return EnsurePathToService( return EnsurePathToService(
addr, addr,
[=](const service::Address &remote, OutboundContext *ctx) { [=](const service::Address &remote, OutboundContext *ctx) {
SendDNSReply(remote, ctx, replyMsg, reply, false); SendDNSReply(remote, ctx, replyMsg, reply, false, isV6);
}, },
2000); 2000);
} }
@ -346,7 +349,8 @@ namespace llarp
dns::Message *replyMsg = new dns::Message(std::move(msg)); dns::Message *replyMsg = new dns::Message(std::move(msg));
EnsurePathToSNode(addr.as_array(), EnsurePathToSNode(addr.as_array(),
[=](const RouterID &remote, exit::BaseSession *s) { [=](const RouterID &remote, exit::BaseSession *s) {
SendDNSReply(remote, s, replyMsg, reply, true); SendDNSReply(remote, s, replyMsg, reply, true,
isV6);
}); });
return true; return true;
} }

View File

@ -196,12 +196,13 @@ namespace llarp
template < typename Addr_t, typename Endpoint_t > template < typename Addr_t, typename Endpoint_t >
void void
SendDNSReply(Addr_t addr, Endpoint_t* ctx, dns::Message* query, SendDNSReply(Addr_t addr, Endpoint_t* ctx, dns::Message* query,
std::function< void(dns::Message) > reply, bool snode) std::function< void(dns::Message) > reply, bool snode,
bool sendIPv6)
{ {
if(ctx) if(ctx)
{ {
huint32_t ip = ObtainIPForAddr(addr, snode); huint32_t ip = ObtainIPForAddr(addr, snode);
query->AddINReply(ip); query->AddINReply(ip, sendIPv6);
} }
else else
query->AddNXReply(); query->AddNXReply();

View File

@ -53,6 +53,16 @@ namespace llarp
return out; return out;
} }
template<typename Container>
void SIIT(Container & c)
{
c.resize(16);
std::fill(c.begin(), c.end(), 0);
htobe32buf(c.data() + 12, h);
c[11] = 0xff;
c[10] = 0xff;
}
std::string ToString() const std::string ToString() const
{ {
uint32_t n = htonl(h); uint32_t n = htonl(h);

View File

@ -118,7 +118,6 @@ TEST_F(TestDhtTx, ask_next_peer)
const auto key0 = makeBuf< dht::Key_t >(0x00); const auto key0 = makeBuf< dht::Key_t >(0x00);
const auto key1 = makeBuf< dht::Key_t >(0x01); const auto key1 = makeBuf< dht::Key_t >(0x01);
const auto key2 = makeBuf< dht::Key_t >(0x02); const auto key2 = makeBuf< dht::Key_t >(0x02);
{ {
// GetNextPeer fails // GetNextPeer fails
EXPECT_CALL(tx, GetNextPeer(_, _)).WillOnce(Return(false)); EXPECT_CALL(tx, GetNextPeer(_, _)).WillOnce(Return(false));

View File

@ -115,7 +115,7 @@ TEST_F(DNSLibTest, TestSerializeMessage)
q.qname = "whatever.tld"; q.qname = "whatever.tld";
q.qclass = 1; q.qclass = 1;
q.qtype = 1; q.qtype = 1;
m.AddINReply({1}); m.AddINReply({1}, false);
ASSERT_EQ(m.questions.size(), 1U); ASSERT_EQ(m.questions.size(), 1U);
ASSERT_EQ(m.answers.size(), 1U); ASSERT_EQ(m.answers.size(), 1U);
ASSERT_TRUE(m.Encode(&buf)); ASSERT_TRUE(m.Encode(&buf));