Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.0 #1189

Merged
merged 7 commits into from
Mar 16, 2020
Merged

0.7.0 #1189

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llarp/ev/ev_libuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace libuv
m_Accept->close = &ExplicitCloseAccept;
m_Conn.write = nullptr;
m_Conn.closed = nullptr;
m_Conn.tick = nullptr;
}

conn_glue(conn_glue* parent) : m_TCP(nullptr), m_Accept(nullptr)
Expand Down Expand Up @@ -304,9 +305,13 @@ namespace libuv
Tick()
{
if(m_Accept && m_Accept->tick)
{
m_Accept->tick(m_Accept);
}
if(m_Conn.tick)
{
m_Conn.tick(&m_Conn);
}
}

void
Expand Down Expand Up @@ -346,6 +351,7 @@ namespace libuv
bool
Server()
{
uv_check_start(&m_Ticker, &OnTick);
m_Accept->close = &ExplicitCloseAccept;
return uv_tcp_bind(&m_Handle, m_Addr, 0) == 0
&& uv_listen(Stream(), 5, &OnAccept) == 0;
Expand Down
81 changes: 34 additions & 47 deletions llarp/handlers/tun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,26 @@ 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);
auto ReplyToSNodeDNSWhenReady = [self = this, reply = reply](
RouterID snode, auto msg,
bool isV6) -> bool {
return self->EnsurePathToSNode(
snode, [=](const RouterID &, exit::BaseSession_ptr s) {
self->SendDNSReply(snode, s, msg, reply, true, isV6);
});
};
auto ReplyToLokiDNSWhenReady = [self = this, reply = reply](
service::Address addr, auto msg,
bool isV6) -> bool {
using service::Address;
using service::OutboundContext;
return self->EnsurePathToService(
addr,
[=](const Address &, OutboundContext *ctx) {
self->SendDNSReply(addr, ctx, msg, reply, false, isV6);
},
2s);
};
std::string qname;
if(msg.answers.size() > 0)
{
Expand All @@ -424,10 +442,7 @@ namespace llarp
return false;
auto replyMsg =
std::make_shared< dns::Message >(clear_dns_message(msg));
return EnsurePathToSNode(
addr.as_array(), [=](const RouterID &, exit::BaseSession_ptr s) {
SendDNSReply(addr, s, replyMsg, reply, true, false);
});
return ReplyToSNodeDNSWhenReady(addr, std::move(replyMsg), false);
}
else if(answer.HasCNameForTLD(".loki"))
{
Expand All @@ -438,26 +453,9 @@ namespace llarp
service::Address addr;
if(not addr.FromString(qname))
return false;
clear_dns_message(msg);
if(HasAddress(addr))
{
huint128_t ip = ObtainIPForAddr(addr, false);
msg.AddINReply(ip, false);
reply(msg);
return true;
}
else
{
auto replyMsg = std::make_shared< dns::Message >(std::move(msg));
using service::Address;
using service::OutboundContext;
return EnsurePathToService(
addr,
[=](const Address &, OutboundContext *ctx) {
SendDNSReply(addr, ctx, replyMsg, reply, false, false);
},
2s);
}
auto replyMsg =
std::make_shared< dns::Message >(clear_dns_message(msg));
return ReplyToLokiDNSWhenReady(addr, replyMsg, false);
}
}
if(msg.questions.size() != 1)
Expand All @@ -484,7 +482,9 @@ namespace llarp
{
RouterID random;
if(Router()->GetRandomGoodRouter(random))
{
msg.AddCNAMEReply(random.ToString(), 1);
}
else
msg.AddNXReply();
}
Expand Down Expand Up @@ -521,7 +521,11 @@ namespace llarp
{
RouterID random;
if(Router()->GetRandomGoodRouter(random))
{
msg.AddCNAMEReply(random.ToString(), 1);
return ReplyToSNodeDNSWhenReady(
random, std::make_shared< dns::Message >(msg), isV6);
}
else
msg.AddNXReply();
}
Expand Down Expand Up @@ -550,23 +554,10 @@ namespace llarp
{
msg.hdr_fields |= dns::flags_QR | dns::flags_AA | dns::flags_RA;
}
else if(HasAddress(addr))
{
huint128_t ip = ObtainIPForAddr(addr, false);
msg.AddINReply(ip, isV6);
}
else
{
auto replyMsg = std::make_shared< dns::Message >(msg);
using service::Address;
using service::OutboundContext;
return EnsurePathToService(
addr,
[=](const Address &, OutboundContext *ctx) {
SendDNSReply(addr, ctx, replyMsg, reply, false,
isV6 || !isV4);
},
2s);
return ReplyToLokiDNSWhenReady(
addr, std::make_shared< dns::Message >(msg), isV6);
}
}
else if(addr.FromString(qname, ".snode"))
Expand All @@ -577,12 +568,8 @@ namespace llarp
}
else
{
auto replyMsg = std::make_shared< dns::Message >(std::move(msg));
return EnsurePathToSNode(
addr.as_array(),
[=](const RouterID &, exit::BaseSession_ptr s) {
SendDNSReply(addr, s, replyMsg, reply, true, isV6);
});
return ReplyToSNodeDNSWhenReady(
addr.as_array(), std::make_shared< dns::Message >(msg), isV6);
}
}
else
Expand Down
5 changes: 4 additions & 1 deletion llarp/service/intro_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ namespace llarp
if(!BEncodeMaybeReadDictEntry("z", Z, read, key, buf))
return false;

return read;
if(read)
return true;

return bencode_discard(buf);
}

bool
Expand Down