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

rc3 #1181

Merged
merged 28 commits into from
Mar 12, 2020
Merged

rc3 #1181

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e155eb3
try fixing leak in libabyss
majestrate Mar 7, 2020
1441115
Merge pull request #1170 from majestrate/libabyss-memleak-2020-03-07
majestrate Mar 9, 2020
f40ce50
Reduce log verbosity when DNS RR decode fails
notlesh Mar 9, 2020
f3d23d6
strip rr from dns reply for .snode and .loki (#1172)
majestrate Mar 9, 2020
6715b86
Fix IPv6 lookups to return empty response
jagerman Mar 9, 2020
51516f7
return NS record for localhost.loki to squash errors in host lookups
majestrate Mar 9, 2020
327ab6f
prune nodedb as client and service node with no whitelist
majestrate Mar 8, 2020
d8da3f0
simplify logic
majestrate Mar 8, 2020
b3f2c71
add comment
majestrate Mar 8, 2020
bce5cd7
add additional case check and documentation comments for pruning logic
majestrate Mar 9, 2020
5d86587
typo fix
majestrate Mar 9, 2020
5191af1
typo fix
majestrate Mar 9, 2020
677e19e
limit path builds on snode sessions
majestrate Mar 9, 2020
667b761
Merge pull request #1173 from jagerman/ipv6-lookup-fix
majestrate Mar 9, 2020
a6a3d77
Merge pull request #1174 from notlesh/reduce-rr-decode-fail-verbosity…
majestrate Mar 9, 2020
bc85082
Merge pull request #1171 from majestrate/prune-nodedb-as-client-2020-…
majestrate Mar 10, 2020
6047d57
fully randomize hop selection
majestrate Mar 10, 2020
69126c6
code dedup
majestrate Mar 11, 2020
9cdc7f4
remove dead code
majestrate Mar 11, 2020
c6fd007
Merge pull request #1176 from majestrate/randomize-hop-selection-more…
majestrate Mar 11, 2020
bf82740
only try fetching identity key once so we can interrupt lokinet (#1178)
majestrate Mar 11, 2020
1ea210a
typo fix
majestrate Mar 11, 2020
a1e8500
use for loop
majestrate Mar 11, 2020
c19c83a
Merge pull request #1179 from majestrate/comparision-fix-2020-03-11
majestrate Mar 11, 2020
3f4b2a5
add additional case (#1180)
majestrate Mar 11, 2020
ac80357
Merge pull request #1175 from majestrate/limit-snode-session-build-ra…
majestrate Mar 11, 2020
7ba30ee
squash commits
majestrate Mar 11, 2020
ec2f691
Merge pull request #1168 from majestrate/inter-node-commit-fixes-2020…
majestrate Mar 11, 2020
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
1 change: 1 addition & 0 deletions libabyss/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ namespace abyss
llarp::LogDebug("connection closed");
ConnImpl* self = static_cast< ConnImpl* >(conn->user);
self->_conn = nullptr;
self->m_State = eCloseMe;
}

static void
Expand Down
89 changes: 41 additions & 48 deletions llarp/config/key_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,68 +240,61 @@ namespace llarp
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_RecvIdentKey);
do

resp.clear();
LogInfo("Getting Identity Keys from lokid...");
if(curl_easy_perform(curl) == CURLE_OK)
{
resp.clear();
LogInfo("Getting Identity Keys from lokid...");
if(curl_easy_perform(curl) == CURLE_OK)
try
{
try
auto j = nlohmann::json::parse(resp);
if(not j.is_object())
return false;

const auto itr = j.find("result");
if(itr == j.end())
return false;
if(not itr->is_object())
return false;
const auto k =
(*itr)["service_node_ed25519_privkey"].get< std::string >();
if(k.size() != (identityKey.size() * 2))
{
auto j = nlohmann::json::parse(resp);
if(not j.is_object())
continue;

const auto itr = j.find("result");
if(itr == j.end())
continue;
if(not itr->is_object())
continue;
const auto k =
(*itr)["service_node_ed25519_privkey"].get< std::string >();
if(k.size() != (identityKey.size() * 2))
{
if(k.empty())
{
LogError("lokid gave no identity key");
}
else
{
LogError("lokid gave invalid identity key");
}
return false;
}
if(not HexDecode(k.c_str(), identityKey.data(), identityKey.size()))
continue;
if(CryptoManager::instance()->check_identity_privkey(identityKey))
if(k.empty())
{
ret = true;
LogError("lokid gave no identity key");
}
else
{
LogError("lokid gave bogus identity key");
LogError("lokid gave invalid identity key");
}
return false;
}
catch(nlohmann::json::exception& ex)
if(not HexDecode(k.c_str(), identityKey.data(), identityKey.size()))
return false;
if(CryptoManager::instance()->check_identity_privkey(identityKey))
{
LogError("Bad response from lokid: ", ex.what());
ret = true;
}
else
{
LogError("lokid gave bogus identity key");
}
}
else
{
LogError("failed to get identity keys");
}
if(ret)
{
LogInfo("Got Identity Keys from lokid: ",
RouterID(seckey_topublic(identityKey)));
break;
}
else
catch(nlohmann::json::exception& ex)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
LogError("Bad response from lokid: ", ex.what());
}
} while(true);
}
else
{
LogError("failed to get identity keys");
}
if(ret)
{
LogInfo("Got Identity Keys from lokid: ",
RouterID(seckey_topublic(identityKey)));
}
curl_easy_cleanup(curl);
curl_slist_free_all(list);
return ret;
Expand Down
76 changes: 42 additions & 34 deletions llarp/dns/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ namespace llarp
hdr.fields = hdr_fields;
hdr.qd_count = questions.size();
hdr.an_count = answers.size();
hdr.ns_count = authorities.size();
hdr.ar_count = additional.size();
hdr.ns_count = 0;
hdr.ar_count = 0;

if(!hdr.Encode(buf))
return false;
Expand All @@ -98,14 +98,6 @@ namespace llarp
if(!answer.Encode(buf))
return false;

for(const auto& auth : authorities)
if(!auth.Encode(buf))
return false;

for(const auto& rr : additional)
if(!rr.Encode(buf))
return false;

return true;
}

Expand All @@ -125,28 +117,10 @@ namespace llarp
{
if(not an.Decode(buf))
{
llarp::LogError("failed to decode answer");
return false;
}
}
/*
for(auto& auth : authorities)
{
if(!auth.Decode(buf))
{
llarp::LogError("failed to decode auth");
llarp::LogDebug("failed to decode answer");
return false;
}
}
for(auto& rr : additional)
{
if(!rr.Decode(buf))
{
llarp::LogError("failed to decode additional");
return false;
}
}
*/
return true;
}

Expand All @@ -162,12 +136,18 @@ namespace llarp
}
}

static constexpr uint16_t
reply_flags(uint16_t setbits)
{
return setbits | flags_QR | flags_AA | flags_RA;
}

void
Message::AddINReply(llarp::huint128_t ip, bool isV6, RR_TTL_t ttl)
{
if(questions.size())
{
hdr_fields |= flags_QR | flags_AA | flags_RA;
hdr_fields = reply_flags(hdr_fields);
ResourceRecord rec;
rec.rr_name = questions[0].qname;
rec.rr_class = qClassIN;
Expand All @@ -193,7 +173,8 @@ namespace llarp
{
if(questions.size())
{
hdr_fields |= flags_QR | flags_AA | flags_RA;
hdr_fields = reply_flags(hdr_fields);

const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
Expand All @@ -212,12 +193,38 @@ namespace llarp
}
}

void
Message::AddNSReply(std::string name, RR_TTL_t ttl)
{
if(not questions.empty())
{
hdr_fields = reply_flags(hdr_fields);

const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = qTypeNS;
rec.rr_class = qClassIN;
rec.ttl = ttl;
std::array< byte_t, 512 > tmp = {{0}};
llarp_buffer_t buf(tmp);
if(EncodeName(&buf, name))
{
buf.sz = buf.cur - buf.base;
rec.rData.resize(buf.sz);
memcpy(rec.rData.data(), buf.base, buf.sz);
}
}
}

void
Message::AddCNAMEReply(std::string name, RR_TTL_t ttl)
{
if(questions.size())
{
hdr_fields |= flags_QR | flags_AA | flags_RA;
hdr_fields = reply_flags(hdr_fields);

const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
Expand All @@ -241,7 +248,8 @@ namespace llarp
{
if(questions.size())
{
hdr_fields |= flags_QR | flags_AA;
hdr_fields = reply_flags(hdr_fields);

const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
Expand All @@ -266,7 +274,7 @@ namespace llarp
if(questions.size())
{
// authorative response with recursion available
hdr_fields |= flags_QR | flags_AA | flags_RA;
hdr_fields = reply_flags(hdr_fields);
// don't allow recursion on this request
hdr_fields &= ~flags_RD;
hdr_fields |= flags_RCODENameError;
Expand Down
3 changes: 3 additions & 0 deletions llarp/dns/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ namespace llarp
void
AddAReply(std::string name, RR_TTL_t ttl = 1);

void
AddNSReply(std::string name, RR_TTL_t ttl = 1);

bool
Encode(llarp_buffer_t* buf) const override;

Expand Down
8 changes: 4 additions & 4 deletions llarp/dns/rr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ namespace llarp
return false;
if(!buf->read_uint16(rr_type))
{
llarp::LogError("failed to decode rr type");
llarp::LogDebug("failed to decode rr type");
return false;
}
if(!buf->read_uint16(rr_class))
{
llarp::LogError("failed to decode rr class");
llarp::LogDebug("failed to decode rr class");
return false;
}
if(!buf->read_uint32(ttl))
{
llarp::LogError("failed to decode ttl");
llarp::LogDebug("failed to decode ttl");
return false;
}
if(!DecodeRData(buf, rData))
{
llarp::LogError("failed to decode rr rdata ", *this);
llarp::LogDebug("failed to decode rr rdata ", *this);
return false;
}
return true;
Expand Down
6 changes: 5 additions & 1 deletion llarp/exit/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ namespace llarp
bool
BaseSession::ShouldBuildMore(llarp_time_t now) const
{
if(BuildCooldownHit(now))
return false;
const size_t expect = (1 + (numPaths / 2));
// check 30 seconds into the future and see if we need more paths
const llarp_time_t future = now + 30s + buildIntervalLimit;
return NumPathsExistingAt(future) < expect && !BuildCooldownHit(now);
return NumPathsExistingAt(future) < expect;
}

void
Expand Down Expand Up @@ -259,6 +261,8 @@ namespace llarp
bool
BaseSession::UrgentBuild(llarp_time_t now) const
{
if(BuildCooldownHit(now))
return false;
if(!IsReady())
return NumInStatus(path::ePathBuilding) < numPaths;
return path::Builder::UrgentBuild(now);
Expand Down
13 changes: 8 additions & 5 deletions llarp/handlers/tun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ namespace llarp
}
else
{
auto replyMsg = std::make_shared< dns::Message >(msg);
auto replyMsg = std::make_shared< dns::Message >(std::move(msg));
using service::Address;
using service::OutboundContext;
return EnsurePathToService(
Expand Down Expand Up @@ -509,12 +509,15 @@ namespace llarp
else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{
const bool isV6 =
msg.questions[0].qtype == dns::qTypeAAAA && SupportsV6();
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
const bool isV4 = msg.questions[0].qtype == dns::qTypeA;
llarp::service::Address addr;
if(isV6 && !SupportsV6())
{ // empty reply but not a NXDOMAIN so that client can retry IPv4
msg.AddNSReply("localhost.loki.");
}
// on MacOS this is a typeA query
if(is_random_snode(msg))
else if(is_random_snode(msg))
{
RouterID random;
if(Router()->GetRandomGoodRouter(random))
Expand Down Expand Up @@ -554,7 +557,7 @@ namespace llarp
}
else
{
auto replyMsg = std::make_shared< dns::Message >(std::move(msg));
auto replyMsg = std::make_shared< dns::Message >(msg);
using service::Address;
using service::OutboundContext;
return EnsurePathToService(
Expand Down
1 change: 1 addition & 0 deletions llarp/handlers/tun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ namespace llarp
if(ctx)
{
huint128_t ip = ObtainIPForAddr(addr, snode);
query->answers.clear();
query->AddINReply(ip, sendIPv6);
}
else
Expand Down
10 changes: 4 additions & 6 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ namespace llarp
return;

util::Lock l(_mutex);

m_PersistingSessions[remote] =
std::max(until, m_PersistingSessions[remote]);
LogDebug("persist session to ", remote, " until ",
m_PersistingSessions[remote].count());
auto &curr = m_PersistingSessions[remote];
if(until > curr)
curr = until;
LogDebug("persist session to ", remote, " until ", curr - time_now_ms());
}

void
Expand Down Expand Up @@ -307,7 +306,6 @@ namespace llarp
auto link = GetLinkWithSessionTo(itr->first);
if(link)
{
LogDebug("keepalive to ", itr->first);
link->KeepAliveSessionTo(itr->first);
}
else
Expand Down
Loading