2021-03-09 22:24:35 +00:00
|
|
|
#include "path.hpp"
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/dht/context.hpp>
|
|
|
|
#include <llarp/exit/context.hpp>
|
|
|
|
#include <llarp/exit/exit_messages.hpp>
|
|
|
|
#include <llarp/link/i_link_manager.hpp>
|
|
|
|
#include <llarp/messages/discard.hpp>
|
|
|
|
#include <llarp/messages/relay_commit.hpp>
|
|
|
|
#include <llarp/messages/relay_status.hpp>
|
|
|
|
#include "path_context.hpp"
|
|
|
|
#include "transit_hop.hpp"
|
|
|
|
#include <llarp/router/abstractrouter.hpp>
|
|
|
|
#include <llarp/routing/path_latency_message.hpp>
|
|
|
|
#include <llarp/routing/path_transfer_message.hpp>
|
|
|
|
#include <llarp/routing/handler.hpp>
|
|
|
|
#include <llarp/util/buffer.hpp>
|
2022-04-28 15:09:51 +00:00
|
|
|
|
|
|
|
#include <oxenc/endian.h>
|
2018-06-22 00:25:30 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-06-25 15:12:08 +00:00
|
|
|
namespace path
|
2018-06-22 00:25:30 +00:00
|
|
|
{
|
2019-06-17 23:19:39 +00:00
|
|
|
std::ostream&
|
|
|
|
TransitHopInfo::print(std::ostream& stream, int level, int spaces) const
|
|
|
|
{
|
|
|
|
Printer printer(stream, level, spaces);
|
|
|
|
printer.printAttribute("tx", txID);
|
|
|
|
printer.printAttribute("rx", rxID);
|
|
|
|
printer.printAttribute("upstream", upstream);
|
|
|
|
printer.printAttribute("downstream", downstream);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2020-06-01 13:17:44 +00:00
|
|
|
TransitHop::TransitHop()
|
|
|
|
: m_UpstreamGather(transit_hop_queue_size), m_DownstreamGather(transit_hop_queue_size)
|
2019-11-28 15:52:10 +00:00
|
|
|
{
|
|
|
|
m_UpstreamGather.enable();
|
|
|
|
m_DownstreamGather.enable();
|
2020-04-07 18:38:56 +00:00
|
|
|
m_UpstreamWorkCounter = 0;
|
2019-11-28 21:12:46 +00:00
|
|
|
m_DownstreamWorkCounter = 0;
|
2019-11-28 15:52:10 +00:00
|
|
|
}
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
TransitHop::Expired(llarp_time_t now) const
|
|
|
|
{
|
2019-07-25 23:54:10 +00:00
|
|
|
return destroy || (now >= ExpireTime());
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-08-22 16:19:51 +00:00
|
|
|
llarp_time_t
|
|
|
|
TransitHop::ExpireTime() const
|
|
|
|
{
|
|
|
|
return started + lifetime;
|
|
|
|
}
|
|
|
|
|
2019-06-04 18:31:17 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHop::HandleLRSM(
|
|
|
|
uint64_t status, std::array<EncryptedFrame, 8>& frames, AbstractRouter* r)
|
2019-06-04 18:31:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
auto msg = std::make_shared<LR_StatusMessage>(frames);
|
2019-06-04 18:31:17 +00:00
|
|
|
msg->status = status;
|
|
|
|
msg->pathid = info.rxID;
|
|
|
|
|
|
|
|
// TODO: add to IHopHandler some notion of "path status"
|
|
|
|
|
2019-07-25 23:54:10 +00:00
|
|
|
const uint64_t ourStatus = LR_StatusRecord::SUCCESS;
|
|
|
|
|
2021-06-07 12:39:38 +00:00
|
|
|
msg->AddFrame(pathKey, ourStatus);
|
|
|
|
LR_StatusMessage::QueueSendMessage(r, info.downstream, msg, shared_from_this());
|
2019-06-04 18:31:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHopInfo::TransitHopInfo(const RouterID& down, const LR_CommitRecord& record)
|
|
|
|
: txID(record.txid), rxID(record.rxid), upstream(record.nextHop), downstream(down)
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
{}
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHop::SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r)
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!IsEndpoint(r->pubkey()))
|
2018-10-02 15:00:34 +00:00
|
|
|
return false;
|
2019-02-02 23:12:42 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, MAX_LINK_MSG_SIZE - 128> tmp;
|
2019-02-02 23:12:42 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!msg.BEncode(&buf))
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2018-07-05 15:44:06 +00:00
|
|
|
llarp::LogError("failed to encode routing message");
|
2018-06-25 15:12:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TunnelNonce N;
|
|
|
|
N.Randomize();
|
2018-07-23 22:36:46 +00:00
|
|
|
buf.sz = buf.cur - buf.base;
|
2018-10-02 15:00:34 +00:00
|
|
|
// pad to nearest MESSAGE_PAD_SIZE bytes
|
2019-04-05 14:58:22 +00:00
|
|
|
auto dlt = buf.sz % pad_size;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (dlt)
|
2018-07-23 22:36:46 +00:00
|
|
|
{
|
2019-04-05 14:58:22 +00:00
|
|
|
dlt = pad_size - dlt;
|
2018-07-23 22:36:46 +00:00
|
|
|
// randomize padding
|
2019-05-28 19:45:08 +00:00
|
|
|
CryptoManager::instance()->randbytes(buf.cur, dlt);
|
2018-10-02 15:00:34 +00:00
|
|
|
buf.sz += dlt;
|
2018-07-23 22:36:46 +00:00
|
|
|
}
|
2018-06-25 15:12:08 +00:00
|
|
|
buf.cur = buf.base;
|
|
|
|
return HandleDownstream(buf, N, r);
|
|
|
|
}
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
void
|
2021-11-15 14:20:57 +00:00
|
|
|
TransitHop::DownstreamWork(TrafficQueue_t msgs, AbstractRouter* r)
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2019-11-28 21:12:46 +00:00
|
|
|
auto flushIt = [self = shared_from_this(), r]() {
|
2020-04-07 18:38:56 +00:00
|
|
|
std::vector<RelayDownstreamMessage> msgs;
|
2021-03-02 07:02:59 +00:00
|
|
|
while (auto maybe = self->m_DownstreamGather.tryPopFront())
|
2019-11-28 21:12:46 +00:00
|
|
|
{
|
2021-03-02 07:02:59 +00:00
|
|
|
msgs.push_back(*maybe);
|
|
|
|
}
|
2019-11-28 21:12:46 +00:00
|
|
|
self->HandleAllDownstream(std::move(msgs), r);
|
|
|
|
};
|
2021-11-15 14:20:57 +00:00
|
|
|
for (auto& ev : msgs)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2019-11-28 15:52:10 +00:00
|
|
|
RelayDownstreamMessage msg;
|
2019-09-05 17:39:09 +00:00
|
|
|
const llarp_buffer_t buf(ev.first);
|
|
|
|
msg.pathid = info.rxID;
|
2020-04-07 18:38:56 +00:00
|
|
|
msg.Y = ev.second ^ nonceXOR;
|
2019-09-05 17:39:09 +00:00
|
|
|
CryptoManager::instance()->xchacha20(buf, pathKey, ev.second);
|
|
|
|
msg.X = buf;
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp::LogDebug(
|
|
|
|
"relay ",
|
|
|
|
msg.X.size(),
|
|
|
|
" bytes downstream from ",
|
|
|
|
info.upstream,
|
|
|
|
" to ",
|
|
|
|
info.downstream);
|
|
|
|
if (m_DownstreamGather.full())
|
2019-11-28 15:52:10 +00:00
|
|
|
{
|
2021-03-02 07:02:59 +00:00
|
|
|
r->loop()->call(flushIt);
|
2019-11-28 15:52:10 +00:00
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_DownstreamGather.enabled())
|
2019-11-29 00:34:31 +00:00
|
|
|
m_DownstreamGather.pushBack(msg);
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
2021-03-02 07:02:59 +00:00
|
|
|
r->loop()->call(flushIt);
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
void
|
2021-11-15 14:20:57 +00:00
|
|
|
TransitHop::UpstreamWork(TrafficQueue_t msgs, AbstractRouter* r)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-11-15 14:20:57 +00:00
|
|
|
for (auto& ev : msgs)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
|
|
|
const llarp_buffer_t buf(ev.first);
|
2019-11-28 15:52:10 +00:00
|
|
|
RelayUpstreamMessage msg;
|
2019-09-05 17:39:09 +00:00
|
|
|
CryptoManager::instance()->xchacha20(buf, pathKey, ev.second);
|
|
|
|
msg.pathid = info.txID;
|
2020-04-07 18:38:56 +00:00
|
|
|
msg.Y = ev.second ^ nonceXOR;
|
|
|
|
msg.X = buf;
|
2021-11-09 23:48:41 +00:00
|
|
|
if (m_UpstreamGather.tryPushBack(msg) != thread::QueueReturn::Success)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush it:
|
|
|
|
r->loop()->call([self = shared_from_this(), r] {
|
|
|
|
std::vector<RelayUpstreamMessage> msgs;
|
|
|
|
while (auto maybe = self->m_UpstreamGather.tryPopFront())
|
2019-11-28 15:52:10 +00:00
|
|
|
{
|
2021-11-09 23:48:41 +00:00
|
|
|
msgs.push_back(*maybe);
|
2019-11-28 15:52:10 +00:00
|
|
|
}
|
2021-11-09 23:48:41 +00:00
|
|
|
self->HandleAllUpstream(std::move(msgs), r);
|
|
|
|
});
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHop::HandleAllUpstream(std::vector<RelayUpstreamMessage> msgs, AbstractRouter* r)
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (IsEndpoint(r->pubkey()))
|
2018-06-26 16:23:43 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& msg : msgs)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
|
|
|
const llarp_buffer_t buf(msg.X);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!r->ParseRoutingMessageBuffer(buf, this, info.rxID))
|
2019-09-16 10:21:12 +00:00
|
|
|
{
|
|
|
|
LogWarn("invalid upstream data on endpoint ", info);
|
|
|
|
}
|
2019-09-05 17:39:09 +00:00
|
|
|
m_LastActivity = r->Now();
|
|
|
|
}
|
2019-09-16 16:12:05 +00:00
|
|
|
FlushDownstream(r);
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& other : m_FlushOthers)
|
2019-11-21 14:34:30 +00:00
|
|
|
{
|
2020-05-21 14:18:23 +00:00
|
|
|
other->FlushDownstream(r);
|
2019-11-21 14:34:30 +00:00
|
|
|
}
|
|
|
|
m_FlushOthers.clear();
|
2018-06-26 16:23:43 +00:00
|
|
|
}
|
2019-09-05 17:39:09 +00:00
|
|
|
else
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& msg : msgs)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp::LogDebug(
|
|
|
|
"relay ",
|
|
|
|
msg.X.size(),
|
|
|
|
" bytes upstream from ",
|
|
|
|
info.downstream,
|
|
|
|
" to ",
|
|
|
|
info.upstream);
|
2021-04-12 11:39:07 +00:00
|
|
|
r->SendToOrQueue(info.upstream, msg);
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-12 13:51:39 +00:00
|
|
|
r->TriggerPump();
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHop::HandleAllDownstream(std::vector<RelayDownstreamMessage> msgs, AbstractRouter* r)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& msg : msgs)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp::LogDebug(
|
|
|
|
"relay ",
|
|
|
|
msg.X.size(),
|
|
|
|
" bytes downstream from ",
|
|
|
|
info.upstream,
|
|
|
|
" to ",
|
|
|
|
info.downstream);
|
2021-04-12 11:39:07 +00:00
|
|
|
r->SendToOrQueue(info.downstream, msg);
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
2021-11-12 13:51:39 +00:00
|
|
|
r->TriggerPump();
|
2019-09-05 17:39:09 +00:00
|
|
|
}
|
2019-07-06 17:03:40 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
void
|
2019-09-16 10:21:12 +00:00
|
|
|
TransitHop::FlushUpstream(AbstractRouter* r)
|
2019-09-05 17:39:09 +00:00
|
|
|
{
|
2021-11-15 14:20:57 +00:00
|
|
|
if (not m_UpstreamQueue.empty())
|
2020-06-01 13:17:44 +00:00
|
|
|
{
|
2021-11-15 14:20:57 +00:00
|
|
|
r->QueueWork([self = shared_from_this(),
|
|
|
|
data = std::exchange(m_UpstreamQueue, {}),
|
|
|
|
r]() mutable { self->UpstreamWork(std::move(data), r); });
|
2020-06-01 13:17:44 +00:00
|
|
|
}
|
2019-09-16 10:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TransitHop::FlushDownstream(AbstractRouter* r)
|
|
|
|
{
|
2021-11-15 14:20:57 +00:00
|
|
|
if (not m_DownstreamQueue.empty())
|
2020-06-01 13:17:44 +00:00
|
|
|
{
|
2021-11-15 14:20:57 +00:00
|
|
|
r->QueueWork([self = shared_from_this(),
|
|
|
|
data = std::exchange(m_DownstreamQueue, {}),
|
|
|
|
r]() mutable { self->DownstreamWork(std::move(data), r); });
|
2020-06-01 13:17:44 +00:00
|
|
|
}
|
2018-06-26 16:23:43 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 16:46:50 +00:00
|
|
|
/// this is where a DHT message is handled at the end of a path, that is,
|
|
|
|
/// where a SNode receives a DHT message from a client along a path.
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
TransitHop::HandleDHTMessage(const llarp::dht::IMessage& msg, AbstractRouter* r)
|
2018-06-26 16:23:43 +00:00
|
|
|
{
|
2019-02-22 15:08:00 +00:00
|
|
|
return r->dht()->impl->RelayRequestForPath(info.rxID, msg);
|
2018-06-26 16:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TransitHop::HandlePathLatencyMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::PathLatencyMessage& msg, AbstractRouter* r)
|
2018-06-26 16:23:43 +00:00
|
|
|
{
|
|
|
|
llarp::routing::PathLatencyMessage reply;
|
2019-04-22 17:38:29 +00:00
|
|
|
reply.L = msg.T;
|
2021-03-31 16:06:50 +00:00
|
|
|
reply.S = msg.S;
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(reply, r);
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
2018-06-26 16:23:43 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
TransitHop::HandlePathConfirmMessage(
|
2021-03-03 20:44:32 +00:00
|
|
|
[[maybe_unused]] const llarp::routing::PathConfirmMessage& msg,
|
|
|
|
[[maybe_unused]] AbstractRouter* r)
|
2018-06-26 16:23:43 +00:00
|
|
|
{
|
2018-11-07 15:30:22 +00:00
|
|
|
llarp::LogWarn("unwarranted path confirm message on ", info);
|
2018-06-26 16:23:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
|
|
|
TransitHop::HandleDataDiscardMessage(
|
2021-03-03 20:44:32 +00:00
|
|
|
[[maybe_unused]] const llarp::routing::DataDiscardMessage& msg,
|
|
|
|
[[maybe_unused]] AbstractRouter* r)
|
2018-09-11 15:28:36 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn("unwarranted path data discard message on ", info);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
|
|
|
TransitHop::HandleObtainExitMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::ObtainExitMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (msg.Verify() && r->exitContext().ObtainNewExit(msg.I, info.rxID, msg.E != 0))
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
|
|
|
llarp::routing::GrantExitMessage grant;
|
|
|
|
grant.S = NextSeqNo();
|
2019-04-22 17:38:29 +00:00
|
|
|
grant.T = msg.T;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!grant.Sign(r->identity()))
|
2018-11-14 21:16:11 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("Failed to sign grant exit message");
|
2018-11-14 18:02:27 +00:00
|
|
|
return false;
|
2018-11-14 21:16:11 +00:00
|
|
|
}
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(grant, r);
|
2018-11-14 12:23:08 +00:00
|
|
|
}
|
|
|
|
// TODO: exponential backoff
|
|
|
|
// TODO: rejected policies
|
|
|
|
llarp::routing::RejectExitMessage reject;
|
|
|
|
reject.S = NextSeqNo();
|
2019-04-22 17:38:29 +00:00
|
|
|
reject.T = msg.T;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!reject.Sign(r->identity()))
|
2018-11-14 21:16:11 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("Failed to sign reject exit message");
|
2018-11-14 18:02:27 +00:00
|
|
|
return false;
|
2018-11-14 21:16:11 +00:00
|
|
|
}
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(reject, r);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TransitHop::HandleCloseExitMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::CloseExitMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-05-07 18:27:21 +00:00
|
|
|
const llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
|
2019-02-11 19:45:42 +00:00
|
|
|
auto ep = r->exitContext().FindEndpointForPath(info.rxID);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (ep && msg.Verify(ep->PubKey()))
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
|
|
|
llarp::routing::CloseExitMessage reply;
|
2019-05-07 18:27:21 +00:00
|
|
|
reply.Y = msg.Y;
|
2018-11-14 18:02:27 +00:00
|
|
|
reply.S = NextSeqNo();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (reply.Sign(r->identity()))
|
2019-05-07 18:27:21 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (SendRoutingMessage(reply, r))
|
2019-05-07 18:27:21 +00:00
|
|
|
{
|
|
|
|
ep->Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-11-14 18:02:27 +00:00
|
|
|
}
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(discard, r);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-11-14 12:23:08 +00:00
|
|
|
TransitHop::HandleUpdateExitVerifyMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::UpdateExitVerifyMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
(void)msg;
|
|
|
|
(void)r;
|
2018-11-14 12:23:08 +00:00
|
|
|
llarp::LogError("unwarranted exit verify on ", info);
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
bool
|
|
|
|
TransitHop::HandleUpdateExitMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::UpdateExitMessage& msg, AbstractRouter* r)
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
auto ep = r->exitContext().FindEndpointForPath(msg.P);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (ep)
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!msg.Verify(ep->PubKey()))
|
2018-11-14 18:02:27 +00:00
|
|
|
return false;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (ep->UpdateLocalPath(info.rxID))
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
2018-11-14 18:02:27 +00:00
|
|
|
llarp::routing::UpdateExitVerifyMessage reply;
|
2019-04-22 17:38:29 +00:00
|
|
|
reply.T = msg.T;
|
2018-11-14 18:02:27 +00:00
|
|
|
reply.S = NextSeqNo();
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(reply, r);
|
2018-11-14 12:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// on fail tell message was discarded
|
2019-04-22 17:38:29 +00:00
|
|
|
llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
|
|
|
|
return SendRoutingMessage(discard, r);
|
2018-11-14 12:23:08 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
|
|
|
TransitHop::HandleRejectExitMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::RejectExitMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
(void)msg;
|
|
|
|
(void)r;
|
2019-02-11 19:45:42 +00:00
|
|
|
llarp::LogError(info, " got unwarranted RXM");
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TransitHop::HandleGrantExitMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::GrantExitMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
(void)msg;
|
|
|
|
(void)r;
|
2019-02-11 19:45:42 +00:00
|
|
|
llarp::LogError(info, " got unwarranted GXM");
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TransitHop::HandleTransferTrafficMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::TransferTrafficMessage& msg, AbstractRouter* r)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
auto endpoint = r->exitContext().FindEndpointForPath(info.rxID);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (endpoint)
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
2018-11-28 17:29:29 +00:00
|
|
|
bool sent = true;
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& pkt : msg.X)
|
2018-11-29 21:19:20 +00:00
|
|
|
{
|
|
|
|
// check short packet buffer
|
2020-04-07 18:38:56 +00:00
|
|
|
if (pkt.size() <= 8)
|
2018-11-29 21:19:20 +00:00
|
|
|
continue;
|
2022-04-28 15:09:51 +00:00
|
|
|
auto counter = oxenc::load_big_to_host<uint64_t>(pkt.data());
|
2018-12-02 18:07:07 +00:00
|
|
|
sent &= endpoint->QueueOutboundTraffic(
|
2021-04-07 11:07:53 +00:00
|
|
|
info.rxID,
|
2021-03-29 16:31:55 +00:00
|
|
|
ManagedBuffer(llarp_buffer_t(pkt.data() + 8, pkt.size() - 8)),
|
|
|
|
counter,
|
|
|
|
msg.protocol);
|
2018-11-29 21:19:20 +00:00
|
|
|
}
|
2018-11-28 17:29:29 +00:00
|
|
|
return sent;
|
2018-11-14 18:02:27 +00:00
|
|
|
}
|
2019-07-06 17:03:40 +00:00
|
|
|
|
|
|
|
llarp::LogError("No exit endpoint on ", info);
|
2018-11-14 18:02:27 +00:00
|
|
|
// discarded
|
2019-04-22 17:38:29 +00:00
|
|
|
llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
|
|
|
|
return SendRoutingMessage(discard, r);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
|
|
|
TransitHop::HandlePathTransferMessage(
|
2019-04-22 17:38:29 +00:00
|
|
|
const llarp::routing::PathTransferMessage& msg, AbstractRouter* r)
|
2018-06-26 16:23:43 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
auto path = r->pathContext().GetPathForTransfer(msg.P);
|
2021-03-31 16:06:50 +00:00
|
|
|
llarp::routing::DataDiscardMessage discarded{msg.P, msg.S};
|
2020-04-07 18:38:56 +00:00
|
|
|
if (path == nullptr || msg.T.F != info.txID)
|
2018-08-12 17:22:29 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(discarded, r);
|
2018-08-12 17:22:29 +00:00
|
|
|
}
|
2021-04-03 12:20:22 +00:00
|
|
|
// send routing message
|
|
|
|
if (path->SendRoutingMessage(msg.T, r))
|
2019-11-21 14:34:30 +00:00
|
|
|
{
|
|
|
|
m_FlushOthers.emplace(path);
|
2018-11-14 18:02:27 +00:00
|
|
|
return true;
|
2019-11-21 14:34:30 +00:00
|
|
|
}
|
2019-04-22 17:38:29 +00:00
|
|
|
return SendRoutingMessage(discarded, r);
|
2018-06-26 16:23:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
std::ostream&
|
|
|
|
TransitHop::print(std::ostream& stream, int level, int spaces) const
|
|
|
|
{
|
|
|
|
Printer printer(stream, level, spaces);
|
|
|
|
printer.printAttribute("TransitHop", info);
|
2020-02-24 19:40:45 +00:00
|
|
|
printer.printAttribute("started", started.count());
|
|
|
|
printer.printAttribute("lifetime", lifetime.count());
|
2019-06-17 23:19:39 +00:00
|
|
|
return stream;
|
|
|
|
}
|
2019-07-25 23:54:10 +00:00
|
|
|
|
2019-11-29 00:34:31 +00:00
|
|
|
void
|
|
|
|
TransitHop::Stop()
|
|
|
|
{
|
|
|
|
m_UpstreamGather.disable();
|
|
|
|
m_DownstreamGather.disable();
|
|
|
|
}
|
|
|
|
|
2019-07-25 23:54:10 +00:00
|
|
|
void
|
|
|
|
TransitHop::SetSelfDestruct()
|
|
|
|
{
|
|
|
|
destroy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TransitHop::QueueDestroySelf(AbstractRouter* r)
|
|
|
|
{
|
2021-03-02 07:02:59 +00:00
|
|
|
r->loop()->call([self = shared_from_this()] { self->SetSelfDestruct(); });
|
2019-07-25 23:54:10 +00:00
|
|
|
}
|
2018-06-25 15:12:08 +00:00
|
|
|
} // namespace path
|
2018-06-22 05:44:19 +00:00
|
|
|
} // namespace llarp
|