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
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};
if((prevPeer ^ targetKey) < (peer ^ targetKey))
{
@ -113,10 +108,13 @@ namespace llarp
" than ", prevPeer);
return false;
}
}
else
{
peersAsked.insert(peer);
llarp::LogInfo("no more peers for request asking for ", target);
return false;
}
peersAsked.insert(peer);
DoNextRequest(peer);
return true;
}

View File

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

View File

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

View File

@ -70,7 +70,8 @@ namespace llarp
return m_OurRange.Contains(ip);
}
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
if(msg.questions[0].qname.find(".snode.")
@ -130,8 +131,10 @@ namespace llarp
else
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"
|| msg.questions[0].qname == "random.snode.")
{
@ -146,7 +149,7 @@ namespace llarp
if(msg.questions[0].qname == "localhost.loki."
|| msg.questions[0].qname == "localhost.loki")
{
msg.AddINReply(GetIfAddr());
msg.AddINReply(GetIfAddr(), isV6);
reply(msg);
return true;
}
@ -161,7 +164,7 @@ namespace llarp
// we do not have it mapped
// map it
ip = ObtainServiceNodeIP(r);
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
}
else
{
@ -170,7 +173,7 @@ namespace llarp
if(itr != m_KeyToIP.end())
{
ip = itr->second;
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
}
else // fallback case that should never happen (probably)
msg.AddNXReply();

View File

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

View File

@ -196,12 +196,13 @@ namespace llarp
template < typename Addr_t, typename Endpoint_t >
void
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)
{
huint32_t ip = ObtainIPForAddr(addr, snode);
query->AddINReply(ip);
query->AddINReply(ip, sendIPv6);
}
else
query->AddNXReply();

View File

@ -53,6 +53,16 @@ namespace llarp
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
{
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 key1 = makeBuf< dht::Key_t >(0x01);
const auto key2 = makeBuf< dht::Key_t >(0x02);
{
// GetNextPeer fails
EXPECT_CALL(tx, GetNextPeer(_, _)).WillOnce(Return(false));

View File

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