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 AlwaysBreakAfterReturnType: All
AlwaysBreakTemplateDeclarations: 'true' AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBinaryOperators: NonAssignment 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' BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'true' BreakConstructorInitializersBeforeComma: 'true'
Cpp11BracedListStyle: '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::LogInfo("Using config file: ", confFile);
llarp::Config conf; 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 = std::make_shared<llarp::Context>();
ctx->Configure(conf); ctx->Configure(conf);

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

File diff suppressed because it is too large Load Diff

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

@ -1,22 +1,13 @@
#include <config/definition.hpp> #include <config/definition.hpp>
#include <util/logging/logger.hpp>
#include <iterator>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <cassert> #include <cassert>
namespace llarp 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 <> template <>
bool bool
OptionDefinition<bool>::fromString(const std::string& input) OptionDefinition<bool>::fromString(const std::string& input)
@ -32,17 +23,43 @@ namespace llarp
ConfigDefinition& ConfigDefinition&
ConfigDefinition::defineOption(OptionDefinition_ptr def) ConfigDefinition::defineOption(OptionDefinition_ptr def)
{ {
auto sectionItr = m_definitions.find(def->section); using namespace config;
if (sectionItr == m_definitions.end()) // 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); m_sectionOrdering.push_back(def->section);
auto& section = sectionItr->first;
auto& sectionDefinitions = m_definitions[def->section]; auto [it, added] = m_definitions[section].try_emplace(std::string{def->name}, std::move(def));
if (sectionDefinitions.find(def->name) != sectionDefinitions.end()) if (!added)
throw std::invalid_argument( throw std::invalid_argument(
stringify("definition for [", def->section, "]:", def->name, " already exists")); stringify("definition for [", def->section, "]:", def->name, " already exists"));
m_definitionOrdering[def->section].push_back(def->name); m_definitionOrdering[section].push_back(it->first);
sectionDefinitions[def->name] = std::move(def);
if (!it->second->comments.empty())
addOptionComments(section, it->first, std::move(it->second->comments));
return *this; return *this;
} }
@ -153,10 +170,13 @@ namespace llarp
const std::string& section, const std::string& name, std::vector<std::string> comments) const std::string& section, const std::string& name, std::vector<std::string> comments)
{ {
auto& defComments = m_definitionComments[section][name]; auto& defComments = m_definitionComments[section][name];
for (size_t i = 0; i < comments.size(); ++i) if (defComments.empty())
{ defComments = std::move(comments);
defComments.emplace_back(std::move(comments[i])); else
} defComments.insert(
defComments.end(),
std::make_move_iterator(comments.begin()),
std::make_move_iterator(comments.end()));
} }
std::string std::string
@ -167,41 +187,49 @@ namespace llarp
int sectionsVisited = 0; int sectionsVisited = 0;
visitSections([&](const std::string& section, const DefinitionMap&) { visitSections([&](const std::string& section, const DefinitionMap&) {
if (sectionsVisited > 0) std::ostringstream sect_out;
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";
visitDefinitions(section, [&](const std::string& name, const OptionDefinition_ptr& def) { 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, this will create empty objects
// TODO: as above (but more important): this won't handle definitions with no entries // TODO: as above (but more important): this won't handle definitions with no entries
// (i.e. those handled by UndeclaredValueHandler's) // (i.e. those handled by UndeclaredValueHandler's)
for (const std::string& comment : m_definitionComments[section][name]) 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) 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) if (not def->required)
oss << "#"; sect_out << "#";
oss << name << "=" << def->defaultValueAsString() << "\n"; 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++; sectionsVisited++;
}); });

@ -1,6 +1,9 @@
#pragma once #pragma once
#include <initializer_list>
#include <type_traits>
#include <util/str.hpp> #include <util/str.hpp>
#include <util/fs.hpp>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
@ -15,19 +18,111 @@
namespace llarp 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 /// 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 /// 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 /// 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). /// that they can all be mixed into the same containers (albiet as pointers).
struct OptionDefinitionBase struct OptionDefinitionBase
{ {
OptionDefinitionBase(std::string section_, std::string name_, bool required_); template <typename... T>
OptionDefinitionBase( OptionDefinitionBase(std::string section_, std::string name_, const T&...)
std::string section_, std::string name_, bool required_, bool multiValued_); : section(std::move(section_))
, name(std::move(name_))
virtual ~OptionDefinitionBase() , 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 /// Subclasses should provide their default value as a string
/// ///
@ -65,6 +160,13 @@ namespace llarp
std::string name; std::string name;
bool required = false; bool required = false;
bool multiValued = 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 /// 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 /// 2) as the output in defaultValueAsString(), used to generate config files
/// 3) as the output in valueAsString(), 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 /// @param opts - 0 or more of config::Required, config::Hidden, config::Default{...}, etc.
/// input and internalize it (e.g. copy it for runtime use). The acceptor should throw /// tagged options or an invocable acceptor validate and internalize input (e.g. copy it for
/// an exception with a useful message if it is not acceptable. /// runtime use). The acceptor should throw an exception with a useful message if it is not
OptionDefinition( /// acceptable. Parameters may be passed in any order.
std::string section_, template <
std::string name_, typename... Options,
bool required_, std::enable_if_t<(config::is_option<T, Options> && ...), int> = 0>
std::optional<T> defaultValue_, OptionDefinition(std::string section_, std::string name_, Options&&... opts)
std::function<void(T)> acceptor_ = nullptr) : OptionDefinitionBase(section_, name_, opts...)
: OptionDefinitionBase(section_, name_, required_) {
, defaultValue(defaultValue_) (extractDefault(std::forward<Options>(opts)), ...);
, acceptor(acceptor_) (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. /// Extracts option Comments and forwards them addOptionComments.
OptionDefinition( template <typename U>
std::string section_, void
std::string name_, extractComments(U&& comment)
bool required_,
bool multiValued_,
std::optional<T> defaultValue_,
std::function<void(T)> acceptor_ = nullptr)
: OptionDefinitionBase(section_, name_, required_, multiValued_)
, defaultValue(defaultValue_)
, acceptor(acceptor_)
{ {
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 /// Returns the first parsed value, if available. Otherwise, provides the default value if the
@ -155,10 +277,14 @@ namespace llarp
std::string std::string
defaultValueAsString() override defaultValueAsString() override
{ {
std::ostringstream oss; if (!defaultValue)
if (defaultValue) return "";
oss << *defaultValue;
if constexpr (std::is_same_v<fs::path, T>)
return defaultValue->string();
std::ostringstream oss;
oss << *defaultValue;
return oss.str(); return oss.str();
} }
@ -224,7 +350,7 @@ namespace llarp
} }
// don't use default value if we are multi-valued and have no value // 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; return;
if (acceptor) if (acceptor)
@ -289,11 +415,14 @@ namespace llarp
/// calls to addConfigValue()). /// calls to addConfigValue()).
struct ConfigDefinition 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. /// 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 /// 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 /// @param def should be a unique_ptr to a valid subclass of OptionDefinitionBase
/// @return `*this` for chaining calls /// @return `*this` for chaining calls
@ -307,7 +436,7 @@ namespace llarp
ConfigDefinition& ConfigDefinition&
defineOption(Params&&... args) 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 /// 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); generateINIConfig(bool useValues = false);
private: private:
// If true skip client-only options; if false skip relay-only options.
bool relay;
OptionDefinition_ptr& OptionDefinition_ptr&
lookupDefinitionOrThrow(std::string_view section, std::string_view name); lookupDefinitionOrThrow(std::string_view section, std::string_view name);
const OptionDefinition_ptr& const OptionDefinition_ptr&
@ -444,15 +576,4 @@ namespace llarp
std::unordered_map<std::string, CommentsMap> m_definitionComments; 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 } // namespace llarp

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -26,8 +26,7 @@ namespace llarp
FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid) FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid)
: IMessage({}), tagName(tag), txID(txid) : IMessage({}), tagName(tag), txID(txid)
{ {}
}
explicit FindIntroMessage(uint64_t txid, const Key_t& addr, uint64_t order) explicit FindIntroMessage(uint64_t txid, const Key_t& addr, uint64_t order)
: IMessage({}), location(addr), txID(txid), relayOrder(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) FindNameMessage::FindNameMessage(const Key_t& from, Key_t namehash, uint64_t txid)
: IMessage(from), NameHash(std::move(namehash)), TxID(txid) : IMessage(from), NameHash(std::move(namehash)), TxID(txid)
{ {}
}
bool bool
FindNameMessage::BEncode(llarp_buffer_t* buf) const FindNameMessage::BEncode(llarp_buffer_t* buf) const

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -8,8 +8,7 @@
llarp_ev_pkt_pipe::llarp_ev_pkt_pipe(llarp_ev_loop_ptr loop) 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)) : llarp::ev_io(-1, new LosslessWriteQueue_t()), m_Loop(std::move(loop))
{ {}
}
bool bool
llarp_ev_pkt_pipe::StartPipe() 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_writer : public llarp_vpn_pkt_queue
{ {};
};
struct llarp_vpn_pkt_reader : public llarp_vpn_pkt_queue struct llarp_vpn_pkt_reader : public llarp_vpn_pkt_queue
{ {};
};
struct llarp_vpn_io_impl struct llarp_vpn_io_impl
{ {
llarp_vpn_io_impl(llarp::Context* c, llarp_vpn_io* io) : ctx(c), parent(io) llarp_vpn_io_impl(llarp::Context* c, llarp_vpn_io* io) : ctx(c), parent(io)
{ {}
}
~llarp_vpn_io_impl() = default; ~llarp_vpn_io_impl() = default;
llarp::Context* ctx; llarp::Context* ctx;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -24,13 +24,11 @@ namespace llarp
// Initializes with 0s // Initializes with 0s
constexpr uint128_t() : uint128_t{0, 0} constexpr uint128_t() : uint128_t{0, 0}
{ {}
}
// Initializes with least-significant value // Initializes with least-significant value
constexpr uint128_t(uint64_t lower) : uint128_t{0, lower} constexpr uint128_t(uint64_t lower) : uint128_t{0, lower}
{ {}
}
// Initializes with upper and lower values // Initializes with upper and lower values
constexpr uint128_t(uint64_t upper, uint64_t lower) constexpr uint128_t(uint64_t upper, uint64_t lower)
@ -41,8 +39,7 @@ namespace llarp
: lower{lower}, upper{upper} : lower{lower}, upper{upper}
#endif #endif
// clang-format on // clang-format on
{ {}
}
constexpr uint128_t(const uint128_t&) = default; constexpr uint128_t(const uint128_t&) = default;
constexpr uint128_t(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) llarp_nodedb::NetDBEntry::NetDBEntry(llarp::RouterContact value)
: rc(std::move(value)), inserted(llarp::time_now_ms()) : rc(std::move(value)), inserted(llarp::time_now_ms())
{ {}
}
bool bool
llarp_nodedb::Remove(const llarp::RouterID& pk) llarp_nodedb::Remove(const llarp::RouterID& pk)

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

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

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

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

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

@ -259,9 +259,6 @@ namespace llarp
void void
PeerDb::configure(const RouterConfig& routerConfig) 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"; fs::path dbPath = routerConfig.m_dataDir / "peerstats.sqlite";
loadDatabase(dbPath); loadDatabase(dbPath);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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