2018-11-12 16:43:40 +00:00
|
|
|
#ifndef LLARP_EXIT_SESSION_HPP
|
|
|
|
#define LLARP_EXIT_SESSION_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-06-15 14:55:14 +00:00
|
|
|
#include <exit/exit_messages.hpp>
|
2020-05-20 19:02:48 +00:00
|
|
|
#include <net/ip_packet.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/pathbuilder.hpp>
|
2019-06-19 22:30:07 +00:00
|
|
|
#include <routing/transfer_traffic_message.hpp>
|
2020-05-20 19:25:57 +00:00
|
|
|
#include <constants/path.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2018-11-28 16:38:20 +00:00
|
|
|
#include <deque>
|
2018-12-20 12:41:17 +00:00
|
|
|
#include <queue>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace exit
|
|
|
|
{
|
2019-03-01 19:10:42 +00:00
|
|
|
struct BaseSession;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using BaseSession_ptr = std::shared_ptr<BaseSession>;
|
2019-04-23 16:13:22 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using SessionReadyFunc = std::function<void(BaseSession_ptr)>;
|
2019-03-01 19:10:42 +00:00
|
|
|
|
2020-02-24 19:40:45 +00:00
|
|
|
static constexpr auto LifeSpan = path::default_lifetime;
|
|
|
|
|
2019-02-01 01:58:06 +00:00
|
|
|
/// a persisting exit session with an exit router
|
2019-04-23 16:13:22 +00:00
|
|
|
struct BaseSession : public llarp::path::Builder,
|
2020-04-07 18:38:56 +00:00
|
|
|
public std::enable_shared_from_this<BaseSession>
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2018-11-29 13:12:35 +00:00
|
|
|
static constexpr size_t MaxUpstreamQueueLength = 256;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
BaseSession(
|
|
|
|
const llarp::RouterID& exitRouter,
|
|
|
|
std::function<bool(const llarp_buffer_t&)> writepkt,
|
|
|
|
AbstractRouter* r,
|
|
|
|
size_t numpaths,
|
|
|
|
size_t hoplen,
|
|
|
|
bool bundleRC);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~BaseSession() override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::shared_ptr<path::PathSet>
|
2019-04-23 16:13:22 +00:00
|
|
|
GetSelf() override
|
|
|
|
{
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:19:33 +00:00
|
|
|
void
|
2020-05-21 14:18:23 +00:00
|
|
|
BlacklistSNode(const RouterID snode) override;
|
2019-05-10 16:19:33 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
2019-04-19 15:10:26 +00:00
|
|
|
ExtractStatus() const;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-04-18 11:49:54 +00:00
|
|
|
bool
|
|
|
|
ShouldBundleRC() const override
|
|
|
|
{
|
2019-05-02 18:11:44 +00:00
|
|
|
return m_BundleRC;
|
2019-04-18 11:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
void
|
2019-05-07 18:15:22 +00:00
|
|
|
ResetInternalState() override;
|
|
|
|
|
2019-05-07 17:46:38 +00:00
|
|
|
bool UrgentBuild(llarp_time_t) const override;
|
2019-05-07 15:08:57 +00:00
|
|
|
|
2019-03-30 13:02:10 +00:00
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathDied(llarp::path::Path_ptr p) override;
|
2019-03-30 13:02:10 +00:00
|
|
|
|
2019-04-16 19:39:58 +00:00
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
CheckPathDead(path::Path_ptr p, llarp_time_t dlt);
|
2019-04-16 19:39:58 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
std::optional<std::vector<RouterContact>>
|
|
|
|
GetHopsForBuild() override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-16 14:03:13 +00:00
|
|
|
bool
|
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathBuilt(llarp::path::Path_ptr p) override;
|
2018-11-14 19:34:17 +00:00
|
|
|
|
|
|
|
bool
|
2019-06-11 16:44:05 +00:00
|
|
|
QueueUpstreamTraffic(llarp::net::IPPacket pkt, const size_t packSize);
|
2018-11-28 16:38:20 +00:00
|
|
|
|
2019-04-30 13:56:39 +00:00
|
|
|
/// flush upstream to exit via paths
|
2018-11-28 16:38:20 +00:00
|
|
|
bool
|
2019-04-30 13:56:39 +00:00
|
|
|
FlushUpstream();
|
|
|
|
|
|
|
|
/// flush downstream to user via tun
|
|
|
|
void
|
|
|
|
FlushDownstream();
|
2018-11-28 16:38:20 +00:00
|
|
|
|
2019-03-07 15:17:29 +00:00
|
|
|
path::PathRole
|
|
|
|
GetRoles() const override
|
|
|
|
{
|
|
|
|
return path::ePathRoleExit;
|
|
|
|
}
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
/// send close and stop session
|
|
|
|
bool
|
|
|
|
Stop() override;
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
bool
|
2018-11-29 13:12:35 +00:00
|
|
|
IsReady() const;
|
|
|
|
|
2018-12-10 15:44:18 +00:00
|
|
|
const llarp::RouterID
|
|
|
|
Endpoint() const
|
|
|
|
{
|
|
|
|
return m_ExitRouter;
|
|
|
|
}
|
|
|
|
|
2018-12-13 12:27:14 +00:00
|
|
|
bool
|
|
|
|
IsExpired(llarp_time_t now) const;
|
|
|
|
|
2018-12-13 16:14:44 +00:00
|
|
|
bool
|
|
|
|
LoadIdentityFromFile(const char* fname);
|
|
|
|
|
2019-03-01 19:10:42 +00:00
|
|
|
void
|
|
|
|
AddReadyHook(SessionReadyFunc func);
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
protected:
|
|
|
|
llarp::RouterID m_ExitRouter;
|
2018-12-13 16:14:44 +00:00
|
|
|
llarp::SecretKey m_ExitIdentity;
|
2020-04-07 18:38:56 +00:00
|
|
|
std::function<bool(const llarp_buffer_t&)> m_WritePacket;
|
2018-12-02 18:07:07 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const = 0;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleTrafficDrop(llarp::path::Path_ptr p, const llarp::PathID_t& path, uint64_t s);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
HandleGotExit(llarp::path::Path_ptr p, llarp_time_t b);
|
2018-11-14 19:34:17 +00:00
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleTraffic(llarp::path::Path_ptr p, const llarp_buffer_t& buf, uint64_t seqno);
|
2018-11-14 19:34:17 +00:00
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
private:
|
2020-04-07 18:38:56 +00:00
|
|
|
std::set<RouterID> m_SnodeBlacklist;
|
2019-05-10 16:19:33 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using UpstreamTrafficQueue_t = std::deque<llarp::routing::TransferTrafficMessage>;
|
|
|
|
using TieredQueue_t = std::map<uint8_t, UpstreamTrafficQueue_t>;
|
2018-11-29 15:45:27 +00:00
|
|
|
TieredQueue_t m_Upstream;
|
2018-12-20 12:41:17 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using DownstreamPkt = std::pair<uint64_t, llarp::net::IPPacket>;
|
2018-12-20 12:41:17 +00:00
|
|
|
|
|
|
|
struct DownstreamPktSorter
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
operator()(const DownstreamPkt& left, const DownstreamPkt& right) const
|
|
|
|
{
|
2018-12-20 13:06:36 +00:00
|
|
|
return left.first < right.first;
|
2018-12-20 12:41:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using DownstreamTrafficQueue_t =
|
2020-04-07 18:38:56 +00:00
|
|
|
std::priority_queue<DownstreamPkt, std::vector<DownstreamPkt>, DownstreamPktSorter>;
|
2018-12-20 12:41:17 +00:00
|
|
|
DownstreamTrafficQueue_t m_Downstream;
|
|
|
|
|
2018-11-29 21:19:20 +00:00
|
|
|
uint64_t m_Counter;
|
2018-12-13 12:27:14 +00:00
|
|
|
llarp_time_t m_LastUse;
|
2019-03-01 19:10:42 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::vector<SessionReadyFunc> m_PendingCallbacks;
|
2019-05-02 18:11:44 +00:00
|
|
|
const bool m_BundleRC;
|
2019-03-07 15:17:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CallPendingCallbacks(bool success);
|
2018-11-12 16:43:40 +00:00
|
|
|
};
|
|
|
|
|
2018-11-29 13:12:35 +00:00
|
|
|
struct ExitSession final : public BaseSession
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
ExitSession(
|
|
|
|
const llarp::RouterID& snodeRouter,
|
|
|
|
std::function<bool(const llarp_buffer_t&)> writepkt,
|
|
|
|
AbstractRouter* r,
|
|
|
|
size_t numpaths,
|
|
|
|
size_t hoplen,
|
|
|
|
bool bundleRC)
|
2019-05-02 18:11:44 +00:00
|
|
|
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen, bundleRC)
|
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-12-02 18:07:07 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~ExitSession() override = default;
|
2018-12-02 18:07:07 +00:00
|
|
|
|
2019-03-22 14:10:30 +00:00
|
|
|
std::string
|
|
|
|
Name() const override;
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
virtual void
|
|
|
|
SendPacketToRemote(const llarp_buffer_t& pkt) override;
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
protected:
|
2019-07-30 23:42:13 +00:00
|
|
|
void
|
2018-12-02 18:07:07 +00:00
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
|
|
|
// TODO: set expiration time
|
|
|
|
msg.X = 0;
|
|
|
|
msg.E = 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SNodeSession final : public BaseSession
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
SNodeSession(
|
|
|
|
const llarp::RouterID& snodeRouter,
|
|
|
|
std::function<bool(const llarp_buffer_t&)> writepkt,
|
|
|
|
AbstractRouter* r,
|
|
|
|
size_t numpaths,
|
|
|
|
size_t hoplen,
|
|
|
|
bool useRouterSNodeKey,
|
|
|
|
bool bundleRC);
|
2018-11-29 13:12:35 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~SNodeSession() override = default;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
2019-03-22 14:10:30 +00:00
|
|
|
std::string
|
|
|
|
Name() const override;
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
virtual void
|
|
|
|
SendPacketToRemote(const llarp_buffer_t& pkt) override;
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
protected:
|
|
|
|
void
|
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
|
|
|
// TODO: set expiration time
|
|
|
|
msg.X = 0;
|
|
|
|
msg.E = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
} // namespace exit
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-12-10 15:44:18 +00:00
|
|
|
#endif
|