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>
pull/1401/head
Jason Rhinelander 4 years ago committed by GitHub
parent 62a90f4c82
commit af6caf776a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,7 +14,23 @@ AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: All
AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'true'
Cpp11BracedListStyle: 'true'

@ -259,7 +259,8 @@ run_main_context(const fs::path confFile, const llarp::RuntimeOptions opts)
llarp::LogInfo("Using config file: ", confFile);
llarp::Config conf;
conf.Load(confFile, opts.isRouter, confFile.parent_path());
if (!conf.Load(confFile, opts.isRouter, confFile.parent_path()))
throw std::runtime_error{"Config file parsing failed"};
ctx = std::make_shared<llarp::Context>();
ctx->Configure(conf);

@ -133,18 +133,15 @@ struct lokinet_jni_vpnio : public lokinet::VPNIO
{
void
InjectSuccess() override
{
}
{}
void
InjectFail() override
{
}
{}
void
Tick() override
{
}
{}
};
#endif

File diff suppressed because it is too large Load Diff

@ -63,7 +63,6 @@ namespace llarp
std::string m_identityKeyFile;
std::string m_transportKeyFile;
bool m_enablePeerStats = false;
bool m_isRelay = false;
void
@ -73,7 +72,6 @@ namespace llarp
struct NetworkConfig
{
std::optional<bool> m_enableProfiling;
std::string m_routerProfilesFile;
std::string m_strictConnect;
std::string m_ifname;
IPRange m_ifaddr;
@ -153,7 +151,6 @@ namespace llarp
struct LokidConfig
{
bool usingSNSeed = false;
bool whitelistRouters = false;
fs::path ident_keyfile;
lokimq::address lokidRPCAddr;

@ -1,22 +1,13 @@
#include <config/definition.hpp>
#include <util/logging/logger.hpp>
#include <iterator>
#include <sstream>
#include <stdexcept>
#include <cassert>
namespace llarp
{
OptionDefinitionBase::OptionDefinitionBase(
std::string section_, std::string name_, bool required_)
: section(section_), name(name_), required(required_)
{
}
OptionDefinitionBase::OptionDefinitionBase(
std::string section_, std::string name_, bool required_, bool multiValued_)
: section(section_), name(name_), required(required_), multiValued(multiValued_)
{
}
template <>
bool
OptionDefinition<bool>::fromString(const std::string& input)
@ -32,17 +23,43 @@ namespace llarp
ConfigDefinition&
ConfigDefinition::defineOption(OptionDefinition_ptr def)
{
auto sectionItr = m_definitions.find(def->section);
if (sectionItr == m_definitions.end())
using namespace config;
// If explicitly deprecated or is a {client,relay} option in a {relay,client} config then add a
// dummy, warning option instead of this one.
if (def->deprecated || (relay ? def->clientOnly : def->relayOnly))
{
return defineOption<std::string>(
def->section,
def->name,
MultiValue,
Hidden,
[deprecated = def->deprecated,
relay = relay,
opt = "[" + def->section + "]:" + def->name](std::string_view) {
LogWarn(
"*** WARNING: The config option ",
opt,
(deprecated ? " is deprecated"
: relay ? " is not valid in service node configuration files"
: " is not valid in client configuration files"),
" and has been ignored.");
});
}
auto [sectionItr, newSect] = m_definitions.try_emplace(def->section);
if (newSect)
m_sectionOrdering.push_back(def->section);
auto& section = sectionItr->first;
auto& sectionDefinitions = m_definitions[def->section];
if (sectionDefinitions.find(def->name) != sectionDefinitions.end())
auto [it, added] = m_definitions[section].try_emplace(std::string{def->name}, std::move(def));
if (!added)
throw std::invalid_argument(
stringify("definition for [", def->section, "]:", def->name, " already exists"));
m_definitionOrdering[def->section].push_back(def->name);
sectionDefinitions[def->name] = std::move(def);
m_definitionOrdering[section].push_back(it->first);
if (!it->second->comments.empty())
addOptionComments(section, it->first, std::move(it->second->comments));
return *this;
}
@ -153,10 +170,13 @@ namespace llarp
const std::string& section, const std::string& name, std::vector<std::string> comments)
{
auto& defComments = m_definitionComments[section][name];
for (size_t i = 0; i < comments.size(); ++i)
{
defComments.emplace_back(std::move(comments[i]));
}
if (defComments.empty())
defComments = std::move(comments);
else
defComments.insert(
defComments.end(),
std::make_move_iterator(comments.begin()),
std::make_move_iterator(comments.end()));
}
std::string
@ -167,41 +187,49 @@ namespace llarp
int sectionsVisited = 0;
visitSections([&](const std::string& section, const DefinitionMap&) {
if (sectionsVisited > 0)
oss << "\n\n";
// TODO: this will create empty objects as a side effect of map's operator[]
// TODO: this also won't handle sections which have no definition
for (const std::string& comment : m_sectionComments[section])
{
oss << "# " << comment << "\n";
}
oss << "[" << section << "]\n";
std::ostringstream sect_out;
visitDefinitions(section, [&](const std::string& name, const OptionDefinition_ptr& def) {
oss << "\n";
bool has_comment = false;
// TODO: as above, this will create empty objects
// TODO: as above (but more important): this won't handle definitions with no entries
// (i.e. those handled by UndeclaredValueHandler's)
for (const std::string& comment : m_definitionComments[section][name])
{
oss << "# " << comment << "\n";
sect_out << "\n# " << comment;
has_comment = true;
}
if (useValues and def->getNumberFound() > 0)
{
oss << name << "=" << def->valueAsString(false) << "\n";
sect_out << "\n" << name << "=" << def->valueAsString(false) << "\n";
}
else
else if (not(def->hidden and not has_comment))
{
sect_out << "\n";
if (not def->required)
oss << "#";
oss << name << "=" << def->defaultValueAsString() << "\n";
sect_out << "#";
sect_out << name << "=" << def->defaultValueAsString() << "\n";
}
});
auto sect_str = sect_out.str();
if (sect_str.empty())
return; // Skip sections with no options
if (sectionsVisited > 0)
oss << "\n\n";
oss << "[" << section << "]\n";
// TODO: this will create empty objects as a side effect of map's operator[]
// TODO: this also won't handle sections which have no definition
for (const std::string& comment : m_sectionComments[section])
{
oss << "# " << comment << "\n";
}
oss << "\n" << sect_str;
sectionsVisited++;
});

@ -1,6 +1,9 @@
#pragma once
#include <initializer_list>
#include <type_traits>
#include <util/str.hpp>
#include <util/fs.hpp>
#include <iostream>
#include <memory>
@ -15,19 +18,111 @@
namespace llarp
{
namespace config
{
// Base class for the following option flag types
struct option_flag
{};
struct Required_t : option_flag
{};
struct Hidden_t : option_flag
{};
struct MultiValue_t : option_flag
{};
struct RelayOnly_t : option_flag
{};
struct ClientOnly_t : option_flag
{};
struct Deprecated_t : option_flag
{};
/// Value to pass for an OptionDefinition to indicate that the option is required
inline constexpr Required_t Required{};
/// Value to pass for an OptionDefinition to indicate that the option should be hidden from the
/// generate config file if it is unset (and has no comment). Typically for deprecated, renamed
/// options that still do something, and for internal dev options that aren't usefully exposed.
/// (For do-nothing deprecated options use Deprecated instead).
inline constexpr Hidden_t Hidden{};
/// Value to pass for an OptionDefinition to indicate that the option takes multiple values
inline constexpr MultiValue_t MultiValue{};
/// Value to pass for an option that should only be set for relay configs. If found in a client
/// config it be ignored (but will produce a warning).
inline constexpr RelayOnly_t RelayOnly{};
/// Value to pass for an option that should only be set for client configs. If found in a relay
/// config it will be ignored (but will produce a warning).
inline constexpr ClientOnly_t ClientOnly{};
/// Value to pass for an option that is deprecated and does nothing and should be ignored (with
/// a deprecation warning) if specified. Note that Deprecated implies Hidden, and that
/// {client,relay}-only options in a {relay,client} config are also considered Deprecated.
inline constexpr Deprecated_t Deprecated{};
/// Wrapper to specify a default value to an OptionDefinition
template <typename T>
struct Default
{
T val;
constexpr explicit Default(T val) : val{std::move(val)}
{}
};
/// Adds one or more comment lines to the option definition.
struct Comment
{
std::vector<std::string> comments;
explicit Comment(std::initializer_list<std::string> comments) : comments{std::move(comments)}
{}
};
/// A convenience function that returns an acceptor which assigns to a reference.
///
/// Note that this holds on to the reference; it must only be used when this is safe to do. In
/// particular, a reference to a local variable may be problematic.
template <typename T>
auto
AssignmentAcceptor(T& ref)
{
return [&ref](T arg) { ref = std::move(arg); };
}
// C++20 backport:
template <typename T>
using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
template <typename T>
constexpr bool is_default = false;
template <typename T>
constexpr bool is_default<Default<T>> = true;
template <typename U>
constexpr bool is_default<U&> = is_default<remove_cvref_t<U>>;
template <typename T, typename Option>
constexpr bool is_option =
std::is_base_of_v<
option_flag,
remove_cvref_t<
Option>> or std::is_same_v<Comment, Option> or is_default<Option> or std::is_invocable_v<remove_cvref_t<Option>, T>;
} // namespace config
/// A base class for specifying config options and their constraints. The basic to/from string
/// type functions are provided pure-virtual. The type-aware implementations which implement these
/// functions are templated classes. One reason for providing a non-templated base class is so
/// that they can all be mixed into the same containers (albiet as pointers).
struct OptionDefinitionBase
{
OptionDefinitionBase(std::string section_, std::string name_, bool required_);
OptionDefinitionBase(
std::string section_, std::string name_, bool required_, bool multiValued_);
virtual ~OptionDefinitionBase()
{
}
template <typename... T>
OptionDefinitionBase(std::string section_, std::string name_, const T&...)
: section(std::move(section_))
, name(std::move(name_))
, required{(std::is_same_v<T, config::Required_t> || ...)}
, multiValued{(std::is_same_v<T, config::MultiValue_t> || ...)}
, deprecated{(std::is_same_v<T, config::Deprecated_t> || ...)}
, hidden{deprecated || (std::is_same_v<T, config::Hidden_t> || ...)}
, relayOnly{(std::is_same_v<T, config::RelayOnly_t> || ...)}
, clientOnly{(std::is_same_v<T, config::ClientOnly_t> || ...)}
{}
virtual ~OptionDefinitionBase() = default;
/// Subclasses should provide their default value as a string
///
@ -65,6 +160,13 @@ namespace llarp
std::string name;
bool required = false;
bool multiValued = false;
bool deprecated = false;
bool hidden = false;
bool relayOnly = false;
bool clientOnly = false;
// Temporarily holds comments given during construction until the option is actually added to
// the owning ConfigDefinition.
std::vector<std::string> comments;
};
/// The primary type-aware implementation of OptionDefinitionBase, this templated class allows
@ -84,33 +186,53 @@ namespace llarp
/// 2) as the output in defaultValueAsString(), used to generate config files
/// 3) as the output in valueAsString(), used to generate config files
///
/// @param acceptor_ is an optional function whose purpose is to both validate the parsed
/// input and internalize it (e.g. copy it for runtime use). The acceptor should throw
/// an exception with a useful message if it is not acceptable.
OptionDefinition(
std::string section_,
std::string name_,
bool required_,
std::optional<T> defaultValue_,
std::function<void(T)> acceptor_ = nullptr)
: OptionDefinitionBase(section_, name_, required_)
, defaultValue(defaultValue_)
, acceptor(acceptor_)
/// @param opts - 0 or more of config::Required, config::Hidden, config::Default{...}, etc.
/// tagged options or an invocable acceptor validate and internalize input (e.g. copy it for
/// runtime use). The acceptor should throw an exception with a useful message if it is not
/// acceptable. Parameters may be passed in any order.
template <
typename... Options,
std::enable_if_t<(config::is_option<T, Options> && ...), int> = 0>
OptionDefinition(std::string section_, std::string name_, Options&&... opts)
: OptionDefinitionBase(section_, name_, opts...)
{
(extractDefault(std::forward<Options>(opts)), ...);
(extractAcceptor(std::forward<Options>(opts)), ...);
(extractComments(std::forward<Options>(opts)), ...);
}
/// Extracts a default value from an config::Default<U>; ignores anything that isn't an
/// config::Default<U>.
template <typename U>
void
extractDefault(U&& defaultValue_)
{
if constexpr (config::is_default<U>)
{
static_assert(
std::is_convertible_v<decltype(std::forward<U>(defaultValue_).val), T>,
"Cannot convert given llarp::config::Default to the required value type");
defaultValue = std::forward<U>(defaultValue_).val;
}
}
/// Extracts an acceptor (i.e. something callable with a `T`) from options; ignores anything
/// that isn't callable.
template <typename U>
void
extractAcceptor(U&& acceptor_)
{
if constexpr (std::is_invocable_v<U, T>)
acceptor = std::forward<U>(acceptor_);
}
/// As above, but also takes a bool value for multiValued.
OptionDefinition(
std::string section_,
std::string name_,
bool required_,
bool multiValued_,
std::optional<T> defaultValue_,
std::function<void(T)> acceptor_ = nullptr)
: OptionDefinitionBase(section_, name_, required_, multiValued_)
, defaultValue(defaultValue_)
, acceptor(acceptor_)
/// Extracts option Comments and forwards them addOptionComments.
template <typename U>
void
extractComments(U&& comment)
{
if constexpr (std::is_same_v<config::remove_cvref_t<U>, config::Comment>)
comments = std::forward<U>(comment).comments;
}
/// Returns the first parsed value, if available. Otherwise, provides the default value if the
@ -155,10 +277,14 @@ namespace llarp
std::string
defaultValueAsString() override
{
std::ostringstream oss;
if (defaultValue)
oss << *defaultValue;
if (!defaultValue)
return "";
if constexpr (std::is_same_v<fs::path, T>)
return defaultValue->string();
std::ostringstream oss;
oss << *defaultValue;
return oss.str();
}
@ -224,7 +350,7 @@ namespace llarp
}
// don't use default value if we are multi-valued and have no value
if (multiValued && parsedValues.size() == 0)
if (multiValued and parsedValues.size() == 0)
return;
if (acceptor)
@ -289,11 +415,14 @@ namespace llarp
/// calls to addConfigValue()).
struct ConfigDefinition
{
/// Spefify the parameters and type of a configuration option. The parameters are members of
explicit ConfigDefinition(bool relay) : relay{relay}
{}
/// Specify the parameters and type of a configuration option. The parameters are members of
/// OptionDefinitionBase; the type is inferred from OptionDefinition's template parameter T.
///
/// This function should be called for every option that this Configuration supports, and should
/// be done before any other interractions involving that option.
/// be done before any other interactions involving that option.
///
/// @param def should be a unique_ptr to a valid subclass of OptionDefinitionBase
/// @return `*this` for chaining calls
@ -307,7 +436,7 @@ namespace llarp
ConfigDefinition&
defineOption(Params&&... args)
{
return defineOption(std::make_unique<OptionDefinition<T>>(args...));
return defineOption(std::make_unique<OptionDefinition<T>>(std::forward<Params>(args)...));
}
/// Specify a config value for the given section and name. The value should be a valid string
@ -416,6 +545,9 @@ namespace llarp
generateINIConfig(bool useValues = false);
private:
// If true skip client-only options; if false skip relay-only options.
bool relay;
OptionDefinition_ptr&
lookupDefinitionOrThrow(std::string_view section, std::string_view name);
const OptionDefinition_ptr&
@ -444,15 +576,4 @@ namespace llarp
std::unordered_map<std::string, CommentsMap> m_definitionComments;
};
/// A convenience acceptor which takes a reference and later assigns it in its acceptor call.
///
/// Note that this holds on to a reference; it must only be used when this is safe to do. In
/// particular, a reference to a local variable may be problematic.
template <typename T>
std::function<void(T)>
AssignmentAcceptor(T& ref)
{
return [&](T arg) mutable { ref = std::move(arg); };
}
} // namespace llarp

@ -72,62 +72,44 @@ namespace llarp
std::string_view sectName;
size_t lineno = 0;
for (const auto& line : lines)
for (auto line : lines)
{
lineno++;
std::string_view realLine;
auto comment = line.find_first_of(';');
if (comment == std::string_view::npos)
comment = line.find_first_of('#');
if (comment == std::string_view::npos)
realLine = line;
else
realLine = line.substr(0, comment);
// blank or commented line?
if (realLine.size() == 0)
// Trim whitespace
while (!line.empty() && whitespace(line.front()))
line.remove_prefix(1);
while (!line.empty() && whitespace(line.back()))
line.remove_suffix(1);
// Skip blank lines and comments
if (line.empty() or line.front() == ';' or line.front() == '#')
continue;
// find delimiters
auto sectOpenPos = realLine.find_first_of('[');
auto sectClosPos = realLine.find_first_of(']');
auto kvDelim = realLine.find_first_of('=');
if (sectOpenPos != std::string_view::npos && sectClosPos != std::string_view::npos
&& kvDelim == std::string_view::npos)
if (line.front() == '[' && line.back() == ']')
{
// section header
// clamp whitespaces
++sectOpenPos;
while (whitespace(realLine[sectOpenPos]) && sectOpenPos != sectClosPos)
++sectOpenPos;
--sectClosPos;
while (whitespace(realLine[sectClosPos]) && sectClosPos != sectOpenPos)
--sectClosPos;
// set section name
sectName = realLine.substr(sectOpenPos, sectClosPos);
line.remove_prefix(1);
line.remove_suffix(1);
sectName = line;
}
else if (kvDelim != std::string_view::npos)
else if (auto kvDelim = line.find('='); kvDelim != std::string_view::npos)
{
// key value pair
std::string_view k = realLine.substr(0, kvDelim);
std::string_view v = realLine.substr(kvDelim + 1);
// clamp whitespaces
for (auto* x : {&k, &v})
{
while (!x->empty() && whitespace(x->front()))
x->remove_prefix(1);
while (!x->empty() && whitespace(x->back()))
x->remove_suffix(1);
}
if (k.size() == 0)
std::string_view k = line.substr(0, kvDelim);
std::string_view v = line.substr(kvDelim + 1);
// Trim inner whitespace
while (!k.empty() && whitespace(k.back()))
k.remove_suffix(1);
while (!v.empty() && whitespace(v.front()))
v.remove_prefix(1);
if (k.empty())
{
LogError(m_FileName, " invalid line (", lineno, "): '", line, "'");
return false;
}
SectionValues_t& sect = m_Config[std::string{sectName}];
LogDebug(m_FileName, ": ", sectName, ".", k, "=", v);
sect.emplace(k, v);
LogDebug(m_FileName, ": [", sectName, "]:", k, "=", v);
m_Config[std::string{sectName}].emplace(k, v);
}
else // malformed?
{

@ -9,8 +9,7 @@
namespace llarp
{
KeyManager::KeyManager() : m_initialized(false), m_needBackup(false)
{
}
{}
bool
KeyManager::initialize(const llarp::Config& config, bool genIfAbsent, bool isRouter)

@ -167,8 +167,7 @@ namespace llarp
void
Context::Reload()
{
}
{}
void
Context::SigINT()

@ -56,8 +56,7 @@ namespace llarp
}
Encrypted(size_t sz) : Encrypted(nullptr, sz)
{
}
{}
bool
BEncode(llarp_buffer_t* buf) const

@ -16,14 +16,12 @@ namespace llarp
struct EncryptedFrame : public Encrypted<EncryptedFrameSize>
{
EncryptedFrame() : EncryptedFrame(EncryptedFrameBodySize)
{
}
{}
EncryptedFrame(size_t sz)
: Encrypted<EncryptedFrameSize>(
std::min(sz, EncryptedFrameBodySize) + EncryptedFrameOverheadSize)
{
}
{}
void
Resize(size_t sz)
@ -70,8 +68,7 @@ namespace llarp
AsyncFrameDecrypter(const SecretKey& secretkey, DecryptHandler h)
: result(std::move(h)), seckey(secretkey)
{
}
{}
DecryptHandler result;
const SecretKey& seckey;

@ -20,16 +20,13 @@ namespace llarp
PubKey() = default;
explicit PubKey(const byte_t* ptr) : AlignedBuffer<SIZE>(ptr)
{
}
{}
explicit PubKey(const Data& data) : AlignedBuffer<SIZE>(data)
{
}
{}
explicit PubKey(const AlignedBuffer<SIZE>& other) : AlignedBuffer<SIZE>(other)
{
}
{}
std::string
ToString() const;
@ -84,13 +81,11 @@ namespace llarp
SecretKey() = default;
explicit SecretKey(const byte_t* ptr) : AlignedBuffer<SECKEYSIZE>(ptr)
{
}
{}
// The full data
explicit SecretKey(const AlignedBuffer<SECKEYSIZE>& seed) : AlignedBuffer<SECKEYSIZE>(seed)
{
}
{}
// Just the seed, we recalculate the pubkey
explicit SecretKey(const AlignedBuffer<32>& seed)
@ -147,12 +142,10 @@ namespace llarp
PrivateKey() = default;
explicit PrivateKey(const byte_t* ptr) : AlignedBuffer<64>(ptr)
{
}
{}
explicit PrivateKey(const AlignedBuffer<64>& key_and_hash) : AlignedBuffer<64>(key_and_hash)
{
}
{}
/// Returns a pointer to the beginning of the 32-byte hash which is used for
/// pseudorandomness when signing with this private key.
@ -195,8 +188,7 @@ namespace llarp
struct IdentitySecret final : public AlignedBuffer<32>
{
IdentitySecret() : AlignedBuffer<32>()
{
}
{}
/// no copy constructor
explicit IdentitySecret(const IdentitySecret&) = delete;

@ -20,8 +20,7 @@ namespace llarp
using Random_t = std::function<uint64_t()>;
Bucket(const Key_t& us, Random_t r) : nodes(XorMetric(us)), random(std::move(r))
{
}
{}
util::StatusObject
ExtractStatus() const

@ -12,8 +12,7 @@ namespace llarp
{
ExploreNetworkJob(const RouterID& peer, AbstractContext* ctx)
: TX<RouterID, RouterID>(TXOwner{}, peer, ctx)
{
}
{}
bool
Validate(const RouterID&) const override

@ -13,8 +13,7 @@ namespace llarp
const Key_t us;
XorMetric(const Key_t& ourKey) : us(ourKey)
{
}
{}
bool
operator()(const Key_t& left, const Key_t& right) const

@ -13,20 +13,16 @@ namespace llarp
struct Key_t : public AlignedBuffer<32>
{
explicit Key_t(const byte_t* buf) : AlignedBuffer<SIZE>(buf)
{
}
{}
explicit Key_t(const Data& data) : AlignedBuffer<SIZE>(data)
{
}
{}
explicit Key_t(const AlignedBuffer<SIZE>& data) : AlignedBuffer<SIZE>(data)
{
}
{}
Key_t() : AlignedBuffer<SIZE>()
{
}
{}
/// get snode address string
std::string

@ -16,8 +16,7 @@ namespace llarp
const PathID_t& path, uint64_t txid, const RouterID& _target, AbstractContext* ctx)
: RecursiveRouterLookup(TXOwner{ctx->OurKey(), txid}, _target, ctx, nullptr)
, localPath(path)
{
}
{}
void
LocalRouterLookup::SendReply()

@ -20,8 +20,7 @@ namespace llarp
__attribute__((unused)) const Key_t& askpeer)
: ServiceAddressLookup(TXOwner{ctx->OurKey(), txid}, addr, ctx, relayOrder, nullptr)
, localPath(pathid)
{
}
{}
void
LocalServiceAddressLookup::SendReply()

@ -13,8 +13,7 @@ namespace llarp
LocalTagLookup::LocalTagLookup(
const PathID_t& path, uint64_t txid, const service::Tag& _target, AbstractContext* ctx)
: TagLookup(TXOwner{ctx->OurKey(), txid}, _target, ctx, 0), localPath(path)
{
}
{}
void
LocalTagLookup::SendReply()

@ -22,8 +22,7 @@ namespace llarp
bool relayed = false;
MessageDecoder(const Key_t& from, bool wasRelayed) : From(from), relayed(wasRelayed)
{
}
{}
bool
operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
@ -105,8 +104,7 @@ namespace llarp
{
ListDecoder(bool hasRelayed, const Key_t& from, std::vector<IMessage::Ptr_t>& list)
: relayed(hasRelayed), From(from), l(list)
{
}
{}
bool relayed;
const Key_t& From;

@ -20,8 +20,7 @@ namespace llarp
/// construct
IMessage(const Key_t& from) : From(from)
{
}
{}
using Ptr_t = std::unique_ptr<IMessage>;

@ -26,8 +26,7 @@ namespace llarp
FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid)
: IMessage({}), tagName(tag), txID(txid)
{
}
{}
explicit FindIntroMessage(uint64_t txid, const Key_t& addr, uint64_t order)
: IMessage({}), location(addr), txID(txid), relayOrder(order)

@ -11,8 +11,7 @@ namespace llarp::dht
{
FindNameMessage::FindNameMessage(const Key_t& from, Key_t namehash, uint64_t txid)
: IMessage(from), NameHash(std::move(namehash)), TxID(txid)
{
}
{}
bool
FindNameMessage::BEncode(llarp_buffer_t* buf) const

@ -10,14 +10,12 @@ namespace llarp
{
// inbound parsing
FindRouterMessage(const Key_t& from) : IMessage(from)
{
}
{}
// find by routerid
FindRouterMessage(uint64_t id, const RouterID& target)
: IMessage({}), targetKey(target), txid(id)
{
}
{}
// exploritory
FindRouterMessage(uint64_t id) : IMessage({}), exploritory(true), txid(id)
@ -48,8 +46,7 @@ namespace llarp
struct RelayedFindRouterMessage final : public FindRouterMessage
{
RelayedFindRouterMessage(const Key_t& from) : FindRouterMessage(from)
{
}
{}
/// handle a relayed FindRouterMessage, do a lookup on the dht and inform
/// the path of the result

@ -15,8 +15,7 @@ namespace llarp
{
GotIntroMessage::GotIntroMessage(std::vector<service::EncryptedIntroSet> results, uint64_t tx)
: IMessage({}), found(std::move(results)), txid(tx)
{
}
{}
bool
GotIntroMessage::HandleMessage(

@ -23,8 +23,7 @@ namespace llarp
std::optional<Key_t> closer;
GotIntroMessage(const Key_t& from) : IMessage(from)
{
}
{}
GotIntroMessage(const GotIntroMessage& other)
: IMessage(other.From), found(other.found), txid(other.txid), closer(other.closer)
@ -35,8 +34,7 @@ namespace llarp
/// for iterative reply
GotIntroMessage(const Key_t& from, const Key_t& _closer, uint64_t _txid)
: IMessage(from), txid(_txid), closer(_closer)
{
}
{}
/// for recursive reply
GotIntroMessage(std::vector<service::EncryptedIntroSet> results, uint64_t txid);
@ -56,8 +54,7 @@ namespace llarp
struct RelayedGotIntroMessage final : public GotIntroMessage
{
RelayedGotIntroMessage() : GotIntroMessage({})
{
}
{}
bool
HandleMessage(llarp_dht_context* ctx, std::vector<IMessage::Ptr_t>& replies) const override;

@ -14,23 +14,19 @@ namespace llarp
struct GotRouterMessage final : public IMessage
{
GotRouterMessage(const Key_t& from, bool tunneled) : IMessage(from), relayed(tunneled)
{
}
{}
GotRouterMessage(
const Key_t& from, uint64_t id, const std::vector<RouterContact>& results, bool tunneled)
: IMessage(from), foundRCs(results), txid(id), relayed(tunneled)
{
}
{}
GotRouterMessage(const Key_t& from, const Key_t& closer, uint64_t id, bool tunneled)
: IMessage(from), closerTarget(new Key_t(closer)), txid(id), relayed(tunneled)
{
}
{}
GotRouterMessage(uint64_t id, std::vector<RouterID> _near, bool tunneled)
: IMessage({}), nearKeys(std::move(_near)), txid(id), relayed(tunneled)
{
}
{}
/// gossip message
GotRouterMessage(const RouterContact rc) : IMessage({}), foundRCs({rc}), txid(0)

@ -18,8 +18,7 @@ namespace llarp
uint64_t relayOrder = 0;
uint64_t txID = 0;
PublishIntroMessage(const Key_t& from, bool relayed_) : IMessage(from), relayed(relayed_)
{
}
{}
PublishIntroMessage(
const llarp::service::EncryptedIntroSet& introset_,
@ -27,8 +26,7 @@ namespace llarp
bool relayed_,
uint64_t relayOrder_)
: IMessage({}), introset(introset_), relayed(relayed_), relayOrder(relayOrder_), txID(tx)
{
}
{}
~PublishIntroMessage() override;

@ -21,8 +21,7 @@ namespace llarp
}
RCNode(const RouterContact& other) : rc(other), ID(other.pubkey)
{
}
{}
util::StatusObject
ExtractStatus() const

@ -20,8 +20,7 @@ namespace llarp
: TX<TXOwner, service::EncryptedIntroSet>(asker, asker, ctx)
, relayOrder(relayOrder_)
, introset(introset_)
{
}
{}
bool
PublishServiceJob::Validate(const service::EncryptedIntroSet& value) const
@ -56,8 +55,7 @@ namespace llarp
AbstractContext* ctx,
uint64_t relayOrder)
: PublishServiceJob(peer, introset, ctx, relayOrder), localPath(fromID), txid(_txid)
{
}
{}
void
LocalPublishServiceJob::SendReply()

@ -15,8 +15,7 @@ namespace llarp
TagLookup(
const TXOwner& asker, const service::Tag& tag, AbstractContext* ctx, uint64_t recursion)
: TX<service::Tag, service::EncryptedIntroSet>(asker, tag, ctx), recursionDepth(recursion)
{
}
{}
bool
Validate(const service::EncryptedIntroSet& introset) const override;

@ -26,8 +26,7 @@ namespace llarp
TX(const TXOwner& asker, const K& k, AbstractContext* p)
: target(k), parent(p), whoasked(asker)
{
}
{}
virtual ~TX() = default;

@ -22,8 +22,7 @@ namespace llarp
operator=(const TXOwner&) = default;
TXOwner(const Key_t& k, uint64_t id) : node(k), txid(id)
{
}
{}
util::StatusObject
ExtractStatus() const

@ -55,8 +55,7 @@ namespace llarp
, answers(std::move(other.answers))
, authorities(std::move(other.authorities))
, additional(std::move(other.additional))
{
}
{}
Message::Message(const Message& other)
: hdr_id(other.hdr_id)
@ -65,8 +64,7 @@ namespace llarp
, answers(other.answers)
, authorities(other.authorities)
, additional(other.additional)
{
}
{}
Message::Message(const MessageHeader& hdr) : hdr_id(hdr.id), hdr_fields(hdr.fields)
{

@ -12,12 +12,10 @@ namespace llarp
: qname(std::move(other.qname))
, qtype(std::move(other.qtype))
, qclass(std::move(other.qclass))
{
}
{}
Question::Question(const Question& other)
: qname(other.qname), qtype(other.qtype), qclass(other.qclass)
{
}
{}
bool
Question::Encode(llarp_buffer_t* buf) const

@ -14,8 +14,7 @@ namespace llarp
, rr_class(other.rr_class)
, ttl(other.ttl)
, rData(other.rData)
{
}
{}
ResourceRecord::ResourceRecord(ResourceRecord&& other)
: rr_name(std::move(other.rr_name))
@ -23,8 +22,7 @@ namespace llarp
, rr_class(std::move(other.rr_class))
, ttl(std::move(other.ttl))
, rData(std::move(other.rData))
{
}
{}
bool
ResourceRecord::Encode(llarp_buffer_t* buf) const

@ -31,8 +31,7 @@ namespace llarp
void
Proxy::Stop()
{
}
{}
bool
Proxy::Start(const IpAddress& addr, const std::vector<IpAddress>& resolvers)
@ -137,8 +136,7 @@ namespace llarp
void
Proxy::HandleTick(llarp_udp_io*)
{
}
{}
void
Proxy::SendServerMessageBufferTo(const SockAddr& to, const llarp_buffer_t& buf)

@ -66,8 +66,7 @@ namespace llarp::dns
, replyFunc(reply)
, failFunc(fail)
#endif
{
}
{}
// static callback
void

@ -101,8 +101,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
GetNow(llarp_ev_loop_ptr l) : loop(l)
{
}
{}
llarp_time_t
operator()() const
@ -115,8 +114,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
PutTime(llarp_ev_loop_ptr l) : loop(l)
{
}
{}
void
operator()(WriteBuffer& buf)
{
@ -143,8 +141,7 @@ namespace llarp
/// for tcp
win32_ev_io(intptr_t f, LosslessWriteQueue_t* q) : fd(f), m_BlockingWriteQueue(q)
{
}
{}
virtual void
error()
@ -304,8 +301,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
GetNow(llarp_ev_loop_ptr l) : loop(std::move(l))
{
}
{}
llarp_time_t
operator()() const
@ -318,8 +314,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
PutTime(llarp_ev_loop_ptr l) : loop(std::move(l))
{
}
{}
void
operator()(WriteBuffer& writebuf)
{
@ -355,18 +350,15 @@ namespace llarp
#endif
posix_ev_io(int f) : fd(f)
{
}
{}
/// for tun
posix_ev_io(int f, LossyWriteQueue_t* q) : fd(f), m_LossyWriteQueue(q)
{
}
{}
/// for tcp
posix_ev_io(int f, LosslessWriteQueue_t* q) : fd(f), m_BlockingWriteQueue(q)
{
}
{}
virtual void
error()
@ -425,8 +417,7 @@ namespace llarp
virtual void
before_flush_write()
{
}
{}
/// called in event loop when fd is ready for writing
/// requeues anything not written
@ -659,8 +650,7 @@ namespace llarp
struct llarp_fd_promise
{
void Set(std::pair<int, int>)
{
}
{}
int
Get()
@ -673,8 +663,7 @@ struct llarp_fd_promise
{
using promise_val_t = std::pair<int, int>;
llarp_fd_promise(std::promise<promise_val_t>* p) : _impl(p)
{
}
{}
std::promise<promise_val_t>* _impl;
void
@ -710,8 +699,7 @@ struct llarp_ev_loop
virtual void
update_time()
{
}
{}
virtual llarp_time_t
time_now() const

@ -762,8 +762,7 @@ namespace libuv
Loop::Loop(size_t queue_size)
: llarp_ev_loop(), m_LogicCalls(queue_size), m_timerQueue(20), m_timerCancelQueue(20)
{
}
{}
bool
Loop::init()

@ -40,8 +40,7 @@ namespace llarp
udp_listener(int fd, llarp_udp_io* u) : ev_io(fd), udp(u){};
~udp_listener()
{
}
{}
bool
tick();

@ -8,8 +8,7 @@
llarp_ev_pkt_pipe::llarp_ev_pkt_pipe(llarp_ev_loop_ptr loop)
: llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(std::move(loop))
{
}
{}
bool
llarp_ev_pkt_pipe::StartPipe()

@ -18,18 +18,15 @@ struct llarp_vpn_pkt_queue
};
struct llarp_vpn_pkt_writer : public llarp_vpn_pkt_queue
{
};
{};
struct llarp_vpn_pkt_reader : public llarp_vpn_pkt_queue
{
};
{};
struct llarp_vpn_io_impl
{
llarp_vpn_io_impl(llarp::Context* c, llarp_vpn_io* io) : ctx(c), parent(io)
{
}
{}
~llarp_vpn_io_impl() = default;
llarp::Context* ctx;

@ -7,8 +7,7 @@ namespace llarp
namespace exit
{
Context::Context(AbstractRouter* r) : m_Router(r)
{
}
{}
Context::~Context() = default;
void

@ -124,8 +124,7 @@ namespace llarp
struct UpstreamBuffer
{
UpstreamBuffer(const llarp::net::IPPacket& p, uint64_t c) : pkt(p), counter(c)
{
}
{}
llarp::net::IPPacket pkt;
uint64_t counter;

@ -22,8 +22,7 @@ namespace llarp
llarp::Signature Z;
ObtainExitMessage() : IMessage()
{
}
{}
~ObtainExitMessage() override = default;

@ -179,8 +179,7 @@ namespace llarp
size_t hoplen,
bool bundleRC)
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen, bundleRC)
{
}
{}
~ExitSession() override = default;

@ -12,8 +12,7 @@ namespace llarp
{
NullEndpoint(AbstractRouter* r, llarp::service::Context* parent)
: llarp::service::Endpoint(r, parent)
{
}
{}
virtual bool
HandleInboundPacket(

@ -24,8 +24,7 @@ namespace llarp
: ILinkLayer(
keyManager, getrc, h, sign, before, est, reneg, timeout, closed, pumpDone, worker)
, permitInbound{allowInbound}
{
}
{}
LinkLayer::~LinkLayer() = default;

@ -115,8 +115,7 @@ namespace llarp
InboundMessage::InboundMessage(uint64_t msgid, uint16_t sz, ShortHash h, llarp_time_t now)
: m_Data(size_t{sz}), m_Digset{std::move(h)}, m_MsgID(msgid), m_LastActiveAt{now}
{
}
{}
void
InboundMessage::HandleData(uint16_t idx, const llarp_buffer_t& buf, llarp_time_t now)

@ -37,8 +37,7 @@ namespace llarp
, QueueWork(std::move(work))
, m_RouterEncSecret(keyManager->encryptionKey)
, m_SecretKey(keyManager->transportKey)
{
}
{}
ILinkLayer::~ILinkLayer() = default;

@ -11,8 +11,7 @@ namespace llarp
struct DiscardMessage final : public ILinkMessage
{
DiscardMessage() : ILinkMessage()
{
}
{}
bool
BEncode(llarp_buffer_t* buf) const override

@ -14,8 +14,7 @@ namespace llarp
static constexpr size_t MaxSize = MAX_RC_SIZE + 256;
LinkIntroMessage() : ILinkMessage()
{
}
{}
RouterContact rc;
KeyExchangeNonce N;

@ -30,8 +30,7 @@ namespace llarp
LinkMessageParser::LinkMessageParser(AbstractRouter* _router)
: router(_router), from(nullptr), msg(nullptr), holder(std::make_unique<msg_holder_t>())
{
}
{}
LinkMessageParser::~LinkMessageParser() = default;

@ -52,8 +52,7 @@ namespace llarp
LR_CommitMessage(std::array<EncryptedFrame, 8> _frames)
: ILinkMessage(), frames(std::move(_frames))
{
}
{}
LR_CommitMessage() = default;

@ -38,8 +38,7 @@ namespace llarp
, path(std::move(_path))
, router(_router)
, pathid(pathid)
{
}
{}
~LRSM_AsyncHandler() = default;

@ -60,8 +60,7 @@ namespace llarp
LR_StatusMessage(std::array<EncryptedFrame, 8> _frames)
: ILinkMessage(), frames(std::move(_frames))
{
}
{}
LR_StatusMessage() = default;

@ -26,8 +26,7 @@ namespace llarp
ExitInfo() = default;
ExitInfo(const PubKey& pk, const IpAddress& address) : ipAddress(address), pubkey(pk)
{
}
{}
bool
BEncode(llarp_buffer_t* buf) const;

@ -11,8 +11,7 @@ namespace llarp
IpAddress::IpAddress(const IpAddress& other)
: m_empty(other.m_empty), m_ipAddress(other.m_ipAddress), m_port(other.m_port)
{
}
{}
IpAddress::IpAddress(std::string_view str, std::optional<uint16_t> port)
{

@ -84,7 +84,8 @@ struct ipv6_header_preamble
struct ipv6_header
{
union {
union
{
ipv6_header_preamble preamble;
uint32_t flowlabel;
} preamble;
@ -144,8 +145,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
PutTime(llarp_ev_loop_ptr evloop) : loop(std::move(evloop))
{
}
{}
void
operator()(IPPacket& pkt) const
{
@ -157,8 +157,7 @@ namespace llarp
{
llarp_ev_loop_ptr loop;
GetNow(llarp_ev_loop_ptr evloop) : loop(std::move(evloop))
{
}
{}
llarp_time_t
operator()() const
{

@ -24,13 +24,11 @@ namespace llarp
// Initializes with 0s
constexpr uint128_t() : uint128_t{0, 0}
{
}
{}
// Initializes with least-significant value
constexpr uint128_t(uint64_t lower) : uint128_t{0, lower}
{
}
{}
// Initializes with upper and lower values
constexpr uint128_t(uint64_t upper, uint64_t lower)
@ -41,8 +39,7 @@ namespace llarp
: lower{lower}, upper{upper}
#endif
// clang-format on
{
}
{}
constexpr uint128_t(const uint128_t&) = default;
constexpr uint128_t(uint128_t&&) = default;

@ -21,8 +21,7 @@ static const std::string RC_FILE_EXT = ".signed";
llarp_nodedb::NetDBEntry::NetDBEntry(llarp::RouterContact value)
: rc(std::move(value)), inserted(llarp::time_now_ms())
{
}
{}
bool
llarp_nodedb::Remove(const llarp::RouterID& pk)

@ -32,8 +32,7 @@ struct llarp_nodedb
explicit llarp_nodedb(const std::string rootdir, DiskCaller_t diskCaller)
: disk(std::move(diskCaller)), nodePath(rootdir)
{
}
{}
~llarp_nodedb()
{

@ -13,8 +13,7 @@ namespace llarp
PathContext::PathContext(AbstractRouter* router)
: m_Router(router), m_AllowTransit(false), m_PathLimits(DefaultPathBuildLimit)
{
}
{}
void
PathContext::AllowTransit()
@ -358,7 +357,6 @@ namespace llarp
}
void PathContext::RemovePathSet(PathSet_ptr)
{
}
{}
} // namespace path
} // namespace llarp

@ -12,8 +12,7 @@ namespace llarp
namespace path
{
PathSet::PathSet(size_t num) : numPaths(num)
{
}
{}
bool
PathSet::ShouldBuildMore(llarp_time_t now) const

@ -85,8 +85,7 @@ namespace llarp
TransitHopInfo::TransitHopInfo(const RouterID& down, const LR_CommitRecord& record)
: txID(record.txid), rxID(record.rxid), upstream(record.nextHop), downstream(down)
{
}
{}
bool
TransitHop::SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r)

@ -44,8 +44,7 @@ namespace sqlite_orm
/// llarp_time_t serialization
template <>
struct type_printer<llarp_time_t> : public integer_printer
{
};
{};
template <>
struct statement_binder<llarp_time_t>
@ -90,8 +89,7 @@ namespace sqlite_orm
/// RouterID serialization
template <>
struct type_printer<llarp::RouterID> : public text_printer
{
};
{};
template <>
struct statement_binder<llarp::RouterID>

@ -259,9 +259,6 @@ namespace llarp
void
PeerDb::configure(const RouterConfig& routerConfig)
{
if (not routerConfig.m_enablePeerStats)
throw std::runtime_error("[router]:enable-peer-stats is not enabled");
fs::path dbPath = routerConfig.m_dataDir / "peerstats.sqlite";
loadDatabase(dbPath);

@ -26,8 +26,7 @@ namespace llarp
PeerStats::PeerStats() = default;
PeerStats::PeerStats(const RouterID& routerId_) : routerId(routerId_)
{
}
{}
PeerStats&
PeerStats::operator+=(const PeerStats& other)

@ -96,8 +96,7 @@ namespace llarp
}
Profiling::Profiling() : m_DisableProfiling(false)
{
}
{}
void
Profiling::Disable()

@ -16,8 +16,7 @@ namespace llarp
OutboundMessageHandler::OutboundMessageHandler(size_t maxQueueSize)
: outboundQueue(maxQueueSize), removedPaths(20), removedSomePaths(false)
{
}
{}
bool
OutboundMessageHandler::QueueMessage(

@ -27,8 +27,7 @@ namespace llarp
PendingSession(RouterContact _rc, LinkLayer_ptr _link)
: rc(std::move(_rc)), link(std::move(_link))
{
}
{}
};
bool

@ -14,8 +14,7 @@ namespace llarp
RCGossiper::RCGossiper()
: I_RCGossiper(), m_Filter(std::chrono::duration_cast<Time_t>(RCGossipFilterDecayInterval))
{
}
{}
void
RCGossiper::Init(ILinkManager* l, const RouterID& ourID, AbstractRouter* router)

@ -279,6 +279,9 @@ namespace llarp
if (not StartRpcServer())
throw std::runtime_error("Failed to start rpc server");
if (conf.router.m_workerThreads > 0)
m_lmq->set_general_threads(conf.router.m_workerThreads);
m_lmq->start();
_nodedb = nodedb;
@ -450,12 +453,10 @@ namespace llarp
RouterContact::BlockBogons = conf.router.m_blockBogons;
// Lokid Config
usingSNSeed = conf.lokid.usingSNSeed;
whitelistRouters = conf.lokid.whitelistRouters;
lokidRPCAddr = lokimq::address(conf.lokid.lokidRPCAddr);
if (usingSNSeed)
ident_keyfile = conf.lokid.ident_keyfile;
m_isServiceNode = conf.router.m_isRelay;
networkConfig = conf.network;
@ -609,17 +610,15 @@ namespace llarp
}
// Network config
if (conf.network.m_enableProfiling.has_value() and not*conf.network.m_enableProfiling)
if (conf.network.m_enableProfiling.value_or(false))
{
routerProfiling().Disable();
LogWarn("router profiling explicitly disabled");
LogInfo("router profiling enabled; loading from ", routerProfilesFile);
routerProfiling().Load(routerProfilesFile.c_str());
}
if (!conf.network.m_routerProfilesFile.empty())
else
{
routerProfilesFile = conf.network.m_routerProfilesFile;
routerProfiling().Load(routerProfilesFile.c_str());
llarp::LogInfo("setting profiles to ", routerProfilesFile);
routerProfiling().Disable();
LogInfo("router profiling disabled");
}
// API config
@ -629,16 +628,12 @@ namespace llarp
}
// peer stats
if (conf.router.m_enablePeerStats)
if (IsServiceNode())
{
LogInfo("Initializing peerdb...");
m_peerDb = std::make_shared<PeerDb>();
m_peerDb->configure(conf.router);
}
else if (IsServiceNode())
{
throw std::runtime_error("peer stats must be enabled when running as relay");
}
// Logging config
LogContext::Instance().Initialize(

@ -71,9 +71,6 @@ namespace llarp
// our router contact
RouterContact _rc;
/// are we using the lokid service node seed ?
bool usingSNSeed = false;
/// should we obey the service node whitelist?
bool whitelistRouters = false;

@ -45,8 +45,7 @@ namespace llarp
}
NetID::NetID() : NetID(DefaultValue().data())
{
}
{}
bool
NetID::operator==(const NetID& other) const

@ -13,16 +13,13 @@ namespace llarp
using Data = std::array<byte_t, SIZE>;
RouterID()
{
}
{}
RouterID(const byte_t* buf) : AlignedBuffer<SIZE>(buf)
{
}
{}
RouterID(const Data& data) : AlignedBuffer<SIZE>(data)
{
}
{}
util::StatusObject
ExtractStatus() const;

@ -9,8 +9,7 @@ namespace llarp
{
RouterVersion::RouterVersion(const Version_t& router, uint64_t proto)
: m_Version(router), m_ProtoVersion(proto)
{
}
{}
bool
RouterVersion::IsCompatableWith(const RouterVersion& other) const

@ -31,8 +31,7 @@ namespace llarp
};
InboundMessageParser::InboundMessageParser() : m_Holder(std::make_unique<MessageHolder>())
{
}
{}
InboundMessageParser::~InboundMessageParser() = default;

@ -10,8 +10,7 @@ namespace llarp
{
PathConfirmMessage::PathConfirmMessage(llarp_time_t lifetime)
: pathLifetime(lifetime), pathCreated(time_now_ms())
{
}
{}
bool
PathConfirmMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)

@ -14,8 +14,7 @@ namespace llarp::rpc
, m_AuthWhitelist(std::move(whitelist))
, m_LMQ(std::move(lmq))
, m_Endpoint(std::move(endpoint))
{
}
{}
void
EndpointAuthRPC::Start()

@ -11,8 +11,7 @@
namespace llarp::rpc
{
RpcServer::RpcServer(LMQ_ptr lmq, AbstractRouter* r) : m_LMQ(std::move(lmq)), m_Router(r)
{
}
{}
/// maybe parse json from message paramter at index
std::optional<nlohmann::json>

@ -37,8 +37,7 @@ namespace llarp
FromString(std::string_view str, const char* tld = ".loki");
Address() : AlignedBuffer<32>()
{
}
{}
explicit Address(const std::string& str) : AlignedBuffer<32>()
{
@ -47,17 +46,14 @@ namespace llarp
}
explicit Address(const Data& buf) : AlignedBuffer<32>(buf)
{
}
{}
Address(const Address& other)
: AlignedBuffer<32>(other.as_array()), subdomain(other.subdomain)
{
}
{}
explicit Address(const AlignedBuffer<32>& other) : AlignedBuffer<32>(other)
{
}
{}
bool
operator<(const Address& other) const

@ -36,8 +36,7 @@ namespace llarp
} // namespace
Context::Context(AbstractRouter* r) : m_Router(r)
{
}
{}
Context::~Context() = default;

@ -505,8 +505,7 @@ namespace llarp
, m_IntroSet(std::move(introset))
, m_Endpoint(parent)
, m_relayOrder(relayOrder)
{
}
{}
std::shared_ptr<routing::IMessage>
BuildRequestMessage() override

@ -20,8 +20,7 @@ namespace llarp
, relayOrder(order)
, location(l)
, handle(std::move(h))
{
}
{}
bool
HiddenServiceAddressLookup::HandleIntrosetResponse(const std::set<EncryptedIntroSet>& results)

@ -19,8 +19,7 @@ namespace llarp
}
ProtocolMessage::ProtocolMessage(const ConvoTag& t) : tag(t)
{
}
{}
ProtocolMessage::~ProtocolMessage() = default;
@ -292,8 +291,7 @@ namespace llarp
, handler(h)
, frame(f)
, fromIntro(recvIntro)
{
}
{}
static void
Work(std::shared_ptr<AsyncFrameDecrypt> self)

@ -9,8 +9,7 @@ namespace llarp
{
RouterLookupJob::RouterLookupJob(Endpoint* p, RouterLookupHandler h)
: handler(std::move(h)), txid(p->GenTXID()), started(p->Now())
{
}
{}
} // namespace service
} // namespace llarp

@ -22,8 +22,7 @@ namespace llarp
, m_Endpoint(ep)
, createdAt(ep->Now())
, m_SendQueue(SendContextQueueSize)
{
}
{}
bool
SendContext::Send(std::shared_ptr<ProtocolFrame> msg, path::Path_ptr path)

@ -18,12 +18,10 @@ namespace llarp
struct Tag : public AlignedBuffer<16>
{
Tag() : AlignedBuffer<SIZE>()
{
}
{}
Tag(const byte_t* d) : AlignedBuffer<SIZE>(d)
{
}
{}
Tag(const std::string& str) : Tag()
{

@ -6,13 +6,11 @@ namespace llarp
namespace simulate
{
Simulation::Simulation() : m_CryptoManager(new sodium::CryptoLibSodium())
{
}
{}
void
Simulation::NodeUp(llarp::Context*)
{
}
{}
Node_ptr
Simulation::AddNode(const std::string& name)

@ -22,8 +22,7 @@ namespace tooling
, introsetPubkey(introsetPubkey_)
, relay(relay_)
, relayIndex(relayIndex_)
{
}
{}
std::string
ToString() const
@ -51,8 +50,7 @@ namespace tooling
, location(location_)
, txid(txid_)
, relayOrder(relayOrder_)
{
}
{}
std::string
ToString() const override
@ -79,8 +77,7 @@ namespace tooling
, From(from_)
, Introset(introset_)
, TxID(txid_)
{
}
{}
std::string
ToString() const override
@ -108,8 +105,7 @@ namespace tooling
, exploritory(msg.exploritory)
, txid(msg.txid)
, version(msg.version)
{
}
{}
std::string
ToString() const override

@ -5,8 +5,7 @@
namespace tooling
{
HiveContext::HiveContext(RouterHive* hive) : m_hive(hive)
{
}
{}
std::unique_ptr<llarp::AbstractRouter>
HiveContext::makeRouter(llarp_ev_loop_ptr netloop, std::shared_ptr<llarp::Logic> logic)

@ -7,8 +7,7 @@ namespace tooling
HiveRouter::HiveRouter(
llarp_ev_loop_ptr netloop, std::shared_ptr<llarp::Logic> logic, RouterHive* hive)
: Router(netloop, logic), m_hive(hive)
{
}
{}
bool
HiveRouter::disableGossipingRC_TestingOnly()

@ -15,8 +15,7 @@ namespace tooling
: RouterEvent("PathAttemptEvent", routerID, false)
, hops(path->hops)
, pathid(path->hops[0].rxID)
{
}
{}
std::string
ToString() const
@ -58,8 +57,7 @@ namespace tooling
, txid(hop->info.txID)
, rxid(hop->info.rxID)
, isEndpoint(routerID == nextHop ? true : false)
{
}
{}
std::string
ToString() const
@ -93,8 +91,7 @@ namespace tooling
PathStatusReceivedEvent(
const llarp::RouterID& routerID, const llarp::PathID_t rxid_, uint64_t status_)
: RouterEvent("PathStatusReceivedEvent", routerID, true), rxid(rxid_), status(status_)
{
}
{}
std::string
ToString() const
@ -119,8 +116,7 @@ namespace tooling
: RouterEvent("PathBuildRejectedEvent", routerID, false)
, rxid(rxid_)
, rejectedBy(rejectedBy_)
{
}
{}
std::string
ToString() const

@ -14,8 +14,7 @@ namespace tooling
: RouterEvent("Link: LinkSessionEstablishedEvent", ourRouterId, false)
, remoteId(remoteId_)
, inbound(inbound_)
{
}
{}
std::string
ToString() const
@ -31,8 +30,7 @@ namespace tooling
ConnectionAttemptEvent(const llarp::RouterID& ourRouterId, const llarp::RouterID& remoteId_)
: RouterEvent("Link: ConnectionAttemptEvent", ourRouterId, false), remoteId(remoteId_)
{
}
{}
std::string
ToString() const

@ -10,8 +10,7 @@ namespace tooling
{
RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc_)
: RouterEvent("RCGossipReceivedEvent", routerID, true), rc(rc_)
{
}
{}
std::string
ToString() const override
@ -33,8 +32,7 @@ namespace tooling
{
RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc_)
: RouterEvent("RCGossipSentEvent", routerID, true), rc(rc_)
{
}
{}
std::string
ToString() const override

@ -29,8 +29,7 @@ namespace tooling
{
RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered)
: eventType(eventType), routerID(routerID), triggered(triggered)
{
}
{}
virtual ~RouterEvent() = default;

@ -78,22 +78,19 @@ struct llarp_buffer_t
llarp_buffer_t() = default;
llarp_buffer_t(byte_t* b, byte_t* c, size_t s) : base(b), cur(c), sz(s)
{
}
{}
llarp_buffer_t(const ManagedBuffer&) = delete;
llarp_buffer_t(ManagedBuffer&&) = delete;
template <typename T>
llarp_buffer_t(T* buf, size_t _sz) : base(reinterpret_cast<byte_t*>(buf)), cur(base), sz(_sz)
{
}
{}
template <typename T>
llarp_buffer_t(const T* buf, size_t _sz)
: base(reinterpret_cast<byte_t*>(const_cast<T*>(buf))), cur(base), sz(_sz)
{
}
{}
/** initialize llarp_buffer_t from container */
template <typename T>
@ -106,8 +103,7 @@ struct llarp_buffer_t
template <typename T>
llarp_buffer_t(const T& t) : llarp_buffer_t(t.data(), t.size())
{
}
{}
// clang-format off
byte_t * begin() { return base; }
@ -204,8 +200,7 @@ struct ManagedBuffer
ManagedBuffer() = delete;
explicit ManagedBuffer(const llarp_buffer_t& b) : underlying(b)
{
}
{}
ManagedBuffer(ManagedBuffer&&) = default;
ManagedBuffer(const ManagedBuffer&) = default;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save