2020-03-16 23:26:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
#include <fmt/core.h>
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <type_traits>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/str.hpp>
|
|
|
|
#include <llarp/util/fs.hpp>
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-04-30 20:05:05 +00:00
|
|
|
#include <iostream>
|
2020-03-16 23:26:18 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <unordered_map>
|
2020-03-17 21:17:35 +00:00
|
|
|
#include <vector>
|
2020-05-01 19:51:15 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
|
|
|
#include <cassert>
|
2020-03-16 23:26:18 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
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>>;
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
template <typename T>
|
|
|
|
constexpr bool is_default_array = false;
|
|
|
|
template <typename T, size_t N>
|
|
|
|
constexpr bool is_default_array<std::array<Default<T>, N>> = true;
|
|
|
|
template <typename U>
|
|
|
|
constexpr bool is_default_array<U&> = is_default_array<remove_cvref_t<U>>;
|
|
|
|
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
template <typename T, typename Option>
|
|
|
|
constexpr bool is_option =
|
|
|
|
std::is_base_of_v<
|
|
|
|
option_flag,
|
|
|
|
remove_cvref_t<
|
2022-09-10 02:44:21 +00:00
|
|
|
Option>> or std::is_same_v<Comment, Option> or is_default<Option> or is_default_array<Option> or std::is_invocable_v<remove_cvref_t<Option>, T>;
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
} // namespace config
|
|
|
|
|
2020-03-17 23:28:04 +00:00
|
|
|
/// 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).
|
2020-04-07 20:41:11 +00:00
|
|
|
struct OptionDefinitionBase
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
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;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-17 23:28:04 +00:00
|
|
|
/// Subclasses should provide their default value as a string
|
|
|
|
///
|
|
|
|
/// @return the option's default value represented as a string
|
2022-09-10 02:44:21 +00:00
|
|
|
virtual std::vector<std::string>
|
|
|
|
defaultValuesAsString() = 0;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-17 23:28:04 +00:00
|
|
|
/// Subclasses should parse and store the provided input
|
|
|
|
///
|
|
|
|
/// @param input is the string input to interpret
|
2020-03-17 03:13:37 +00:00
|
|
|
virtual void
|
|
|
|
parseValue(const std::string& input) = 0;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-04-01 17:10:12 +00:00
|
|
|
/// Subclasses should provide the number of values found.
|
|
|
|
///
|
|
|
|
/// @return number of values found
|
|
|
|
virtual size_t
|
|
|
|
getNumberFound() const = 0;
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Subclasess should write their parsed values as strings.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
2022-09-10 02:44:21 +00:00
|
|
|
/// @return the option's value(s) as strings
|
|
|
|
virtual std::vector<std::string>
|
|
|
|
valuesAsString() = 0;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
/// Subclassess should call their acceptor, if present. See OptionDefinition for more details.
|
2020-03-18 15:14:52 +00:00
|
|
|
///
|
|
|
|
/// @throws if the acceptor throws or the option is required but missing
|
2020-04-07 20:41:11 +00:00
|
|
|
virtual void
|
|
|
|
tryAccept() const = 0;
|
2020-03-18 15:14:52 +00:00
|
|
|
|
2020-03-16 23:26:18 +00:00
|
|
|
std::string section;
|
|
|
|
std::string name;
|
|
|
|
bool required = false;
|
|
|
|
bool multiValued = false;
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
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;
|
2020-03-16 23:26:18 +00:00
|
|
|
};
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// The primary type-aware implementation of OptionDefinitionBase, this templated class allows for
|
|
|
|
/// implementations which can use fmt::format for conversion to string and std::istringstream for
|
|
|
|
/// input from string.
|
2020-04-07 20:41:11 +00:00
|
|
|
///
|
|
|
|
/// Note that types (T) used as template parameters here must be used verbatim when calling
|
|
|
|
/// ConfigDefinition::getConfigValue(). Similar types such as uint32_t and int32_t cannot be
|
|
|
|
/// mixed.
|
|
|
|
template <typename T>
|
2020-03-31 17:33:36 +00:00
|
|
|
struct OptionDefinition : public OptionDefinitionBase
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2020-03-31 17:33:36 +00:00
|
|
|
/// Constructor. Arguments are passed directly to OptionDefinitionBase.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
2020-03-18 15:14:52 +00:00
|
|
|
/// @param defaultValue_ is used in the following situations:
|
2020-03-17 23:28:04 +00:00
|
|
|
/// 1) as the return value for getValue() if there is no parsed value and required==false
|
2022-09-10 02:44:21 +00:00
|
|
|
/// 2) as the output in defaultValuesAsString(), used to generate config files
|
2020-03-17 23:28:04 +00:00
|
|
|
/// 3) as the output in valueAsString(), used to generate config files
|
2020-03-18 15:14:52 +00:00
|
|
|
///
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
/// @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)), ...);
|
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Extracts a default value from an config::Default<U> or an array of defaults (for
|
|
|
|
/// multi-valued options with multi-value default); ignores anything else.
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
template <typename U>
|
|
|
|
void
|
|
|
|
extractDefault(U&& defaultValue_)
|
|
|
|
{
|
2022-09-10 02:44:21 +00:00
|
|
|
if constexpr (config::is_default_array<U>)
|
|
|
|
{
|
|
|
|
if (!multiValued)
|
|
|
|
throw std::logic_error{"Array config defaults require multiValue mode"};
|
|
|
|
|
|
|
|
defaultValues.clear();
|
|
|
|
defaultValues.reserve(defaultValue_.size());
|
|
|
|
for (const auto& def : defaultValue_)
|
|
|
|
defaultValues.push_back(def.val);
|
|
|
|
}
|
|
|
|
else if constexpr (config::is_default<U>)
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
{
|
|
|
|
static_assert(
|
|
|
|
std::is_convertible_v<decltype(std::forward<U>(defaultValue_).val), T>,
|
|
|
|
"Cannot convert given llarp::config::Default to the required value type");
|
2022-09-10 02:44:21 +00:00
|
|
|
defaultValues = {std::forward<U>(defaultValue_).val};
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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_)
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
if constexpr (std::is_invocable_v<U, T>)
|
|
|
|
acceptor = std::forward<U>(acceptor_);
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
/// Extracts option Comments and forwards them addOptionComments.
|
|
|
|
template <typename U>
|
|
|
|
void
|
|
|
|
extractComments(U&& comment)
|
2020-03-31 21:26:55 +00:00
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
if constexpr (std::is_same_v<config::remove_cvref_t<U>, config::Comment>)
|
|
|
|
comments = std::forward<U>(comment).comments;
|
2020-03-31 21:26:55 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Returns the first parsed value, if available. Otherwise, provides the (first) default value
|
|
|
|
/// if the option is not required. Otherwise, returns an empty optional.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
2022-09-10 02:44:21 +00:00
|
|
|
/// @return an optional with the parsed value, the (first) default value, or no value.
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional<T>
|
2020-03-17 03:13:37 +00:00
|
|
|
getValue() const
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
if (parsedValues.empty())
|
2022-09-10 02:44:21 +00:00
|
|
|
{
|
|
|
|
if (required || defaultValues.empty())
|
|
|
|
return std::nullopt;
|
|
|
|
return defaultValues.front();
|
|
|
|
}
|
2022-07-09 15:05:52 +00:00
|
|
|
return parsedValues.front();
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 17:10:12 +00:00
|
|
|
/// Returns the number of values found.
|
|
|
|
///
|
|
|
|
/// @return number of values found
|
|
|
|
size_t
|
|
|
|
getNumberFound() const override
|
|
|
|
{
|
|
|
|
return parsedValues.size();
|
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
std::vector<std::string>
|
|
|
|
defaultValuesAsString() override
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2022-09-10 02:44:21 +00:00
|
|
|
if (defaultValues.empty())
|
|
|
|
return {};
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
if constexpr (std::is_same_v<fs::path, T>)
|
2022-09-10 02:44:21 +00:00
|
|
|
return {{defaultValues.front().u8string()}};
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> def_strs;
|
|
|
|
def_strs.reserve(defaultValues.size());
|
|
|
|
for (const auto& v : defaultValues)
|
|
|
|
def_strs.push_back(fmt::format("{}", v));
|
|
|
|
return def_strs;
|
|
|
|
}
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 03:13:37 +00:00
|
|
|
void
|
2020-03-17 23:28:04 +00:00
|
|
|
parseValue(const std::string& input) override
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2020-04-01 17:10:12 +00:00
|
|
|
if (not multiValued and parsedValues.size() > 0)
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2022-07-16 00:41:14 +00:00
|
|
|
throw std::invalid_argument{
|
|
|
|
fmt::format("duplicate value for {}, previous value: {}", name, parsedValues[0])};
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
2020-04-07 20:41:11 +00:00
|
|
|
|
2020-04-29 18:32:07 +00:00
|
|
|
parsedValues.emplace_back(fromString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
T
|
|
|
|
fromString(const std::string& input)
|
|
|
|
{
|
2020-08-31 20:07:17 +00:00
|
|
|
if constexpr (std::is_same_v<T, std::string>)
|
|
|
|
{
|
|
|
|
return input;
|
|
|
|
}
|
2020-03-16 23:26:18 +00:00
|
|
|
else
|
2020-08-31 20:07:17 +00:00
|
|
|
{
|
|
|
|
std::istringstream iss(input);
|
|
|
|
T t;
|
|
|
|
iss >> t;
|
|
|
|
if (iss.fail())
|
2022-07-16 00:41:14 +00:00
|
|
|
throw std::invalid_argument{fmt::format("{} is not a valid {}", input, typeid(T).name())};
|
2020-08-31 20:07:17 +00:00
|
|
|
else
|
|
|
|
return t;
|
|
|
|
}
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
std::vector<std::string>
|
|
|
|
valuesAsString() override
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2022-09-10 02:44:21 +00:00
|
|
|
if (parsedValues.empty())
|
|
|
|
return {};
|
|
|
|
std::vector<std::string> result;
|
|
|
|
result.reserve(parsedValues.size());
|
|
|
|
for (const auto& v : parsedValues)
|
|
|
|
result.push_back(fmt::format("{}", v));
|
|
|
|
return result;
|
2020-03-16 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Attempts to call the acceptor function, if present. This function may throw if the value
|
|
|
|
/// is not acceptable. Additionally, tryAccept should not be called if the option is required
|
|
|
|
/// and no value has been provided.
|
2020-03-18 15:14:52 +00:00
|
|
|
///
|
|
|
|
/// @throws if required and no value present or if the acceptor throws
|
|
|
|
void
|
|
|
|
tryAccept() const override
|
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
if (required and parsedValues.empty())
|
2020-03-18 15:14:52 +00:00
|
|
|
{
|
2022-07-16 00:41:14 +00:00
|
|
|
throw std::runtime_error{fmt::format(
|
|
|
|
"cannot call tryAccept() on [{}]:{} when required but no value available",
|
2020-04-07 20:41:11 +00:00
|
|
|
section,
|
2022-07-16 00:41:14 +00:00
|
|
|
name)};
|
2020-03-18 15:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (acceptor)
|
|
|
|
{
|
2020-04-01 17:10:12 +00:00
|
|
|
if (multiValued)
|
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
// add default value in multi value mode
|
2022-09-10 02:44:21 +00:00
|
|
|
if (parsedValues.empty() and not defaultValues.empty())
|
|
|
|
for (const auto& v : defaultValues)
|
|
|
|
acceptor(v);
|
2022-07-09 15:05:52 +00:00
|
|
|
|
2020-09-19 13:29:36 +00:00
|
|
|
for (auto value : parsedValues)
|
2020-04-01 17:10:12 +00:00
|
|
|
{
|
|
|
|
acceptor(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto maybe = getValue();
|
2020-05-20 19:46:08 +00:00
|
|
|
if (maybe)
|
|
|
|
acceptor(*maybe);
|
2020-04-01 17:10:12 +00:00
|
|
|
}
|
2020-03-18 15:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
std::vector<T> defaultValues;
|
2020-04-01 17:10:12 +00:00
|
|
|
std::vector<T> parsedValues;
|
2020-03-18 15:14:52 +00:00
|
|
|
std::function<void(T)> acceptor;
|
2020-03-16 23:26:18 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 18:32:07 +00:00
|
|
|
/// Specialization for bool types. We don't want to use stringstream parsing in this
|
|
|
|
/// case because we want to accept "truthy" and "falsy" string values (e.g. "off" == false)
|
|
|
|
template <>
|
|
|
|
bool
|
|
|
|
OptionDefinition<bool>::fromString(const std::string& input);
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
using UndeclaredValueHandler =
|
2020-05-01 19:51:15 +00:00
|
|
|
std::function<void(std::string_view section, std::string_view name, std::string_view value)>;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
using OptionDefinition_ptr = std::unique_ptr<OptionDefinitionBase>;
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-17 20:21:38 +00:00
|
|
|
// map of k:v pairs
|
2020-03-31 17:33:36 +00:00
|
|
|
using DefinitionMap = std::unordered_map<std::string, OptionDefinition_ptr>;
|
2020-03-17 20:21:38 +00:00
|
|
|
|
|
|
|
// map of section-name to map-of-definitions
|
|
|
|
using SectionMap = std::unordered_map<std::string, DefinitionMap>;
|
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// A ConfigDefinition holds an ordered set of OptionDefinitions defining the allowable values
|
|
|
|
/// and their constraints (specified through calls to defineOption()).
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
|
|
|
/// The layout and grouping of the config options are modelled after the INI file format; each
|
|
|
|
/// option has a name and is grouped under a section. Duplicate option names are allowed only if
|
2020-04-07 20:41:11 +00:00
|
|
|
/// they exist in a different section. The ConfigDefinition can be serialized in the INI file
|
|
|
|
/// format using the generateINIConfig() function.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
|
|
|
/// Configured values (e.g. those encountered when parsing a file) can be provided through calls
|
|
|
|
/// to addConfigValue(). These take a std::string as a value, which is automatically parsed.
|
2020-04-07 20:41:11 +00:00
|
|
|
///
|
2022-09-10 02:44:21 +00:00
|
|
|
/// The ConfigDefinition can be used to print out a full config string (or file), including
|
|
|
|
/// fields with defaults and optionally fields which have a specified value (values provided
|
|
|
|
/// through calls to addConfigValue()).
|
2020-04-07 20:41:11 +00:00
|
|
|
struct ConfigDefinition
|
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
explicit ConfigDefinition(bool relay) : relay{relay}
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// Specify the parameters and type of a configuration option. The parameters are members of
|
2020-03-31 17:33:36 +00:00
|
|
|
/// OptionDefinitionBase; the type is inferred from OptionDefinition's template parameter T.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
2022-09-10 02:44:21 +00:00
|
|
|
/// This function should be called for every option that this Configuration supports, and
|
|
|
|
/// should be done before any other interactions involving that option.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
2020-03-31 17:33:36 +00:00
|
|
|
/// @param def should be a unique_ptr to a valid subclass of OptionDefinitionBase
|
2020-03-17 23:28:04 +00:00
|
|
|
/// @return `*this` for chaining calls
|
|
|
|
/// @throws std::invalid_argument if the option already exists
|
2020-03-31 17:33:36 +00:00
|
|
|
ConfigDefinition&
|
|
|
|
defineOption(OptionDefinition_ptr def);
|
2020-03-18 15:45:30 +00:00
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Convenience function which calls defineOption with a OptionDefinition of the specified
|
|
|
|
/// type and with parameters passed through to OptionDefinition's constructor.
|
2020-04-07 20:41:11 +00:00
|
|
|
template <typename T, typename... Params>
|
2020-03-31 17:33:36 +00:00
|
|
|
ConfigDefinition&
|
2020-03-18 15:45:30 +00:00
|
|
|
defineOption(Params&&... args)
|
|
|
|
{
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
return defineOption(std::make_unique<OptionDefinition<T>>(std::forward<Params>(args)...));
|
2020-03-18 15:45:30 +00:00
|
|
|
}
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-17 23:28:04 +00:00
|
|
|
/// Specify a config value for the given section and name. The value should be a valid string
|
2020-03-18 15:45:30 +00:00
|
|
|
/// representing the type used by the option (e.g. the type provided when defineOption() was
|
2020-03-17 23:28:04 +00:00
|
|
|
/// called).
|
|
|
|
///
|
2022-09-10 02:44:21 +00:00
|
|
|
/// If the specified option doesn't exist, an exception will be thrown. Otherwise, the
|
|
|
|
/// option's parseValue() will be invoked, and should throw an exception if the string can't
|
|
|
|
/// be parsed.
|
2020-03-17 23:28:04 +00:00
|
|
|
///
|
|
|
|
/// @param section is the section this value resides in
|
|
|
|
/// @param name is the name of the value
|
|
|
|
/// @return `*this` for chaining calls
|
|
|
|
/// @throws if the option doesn't exist or the provided string isn't parseable
|
2020-03-31 17:33:36 +00:00
|
|
|
ConfigDefinition&
|
2020-05-01 19:51:15 +00:00
|
|
|
addConfigValue(std::string_view section, std::string_view name, std::string_view value);
|
2020-03-17 22:24:59 +00:00
|
|
|
|
|
|
|
/// Get a config value. If the value hasn't been provided but a default has, the default will
|
|
|
|
/// be returned. If no value and no default is provided, an empty optional will be returned.
|
|
|
|
///
|
|
|
|
/// The type T should exactly match that provided by the definition; it is not sufficient for
|
|
|
|
/// one type to be a valid substitution for the other.
|
|
|
|
///
|
|
|
|
/// @param section is the section this value resides in
|
|
|
|
/// @param name is the name of the value
|
|
|
|
/// @return an optional providing the configured value, the default, or empty
|
|
|
|
/// @throws std::invalid_argument if there is no such config option or the wrong type T was
|
|
|
|
// provided
|
2020-04-07 20:41:11 +00:00
|
|
|
template <typename T>
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional<T>
|
|
|
|
getConfigValue(std::string_view section, std::string_view name)
|
2020-03-16 23:26:18 +00:00
|
|
|
{
|
2020-03-31 17:33:36 +00:00
|
|
|
OptionDefinition_ptr& definition = lookupDefinitionOrThrow(section, name);
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
auto derived = dynamic_cast<const OptionDefinition<T>*>(definition.get());
|
2020-03-16 23:26:18 +00:00
|
|
|
if (not derived)
|
2022-07-16 00:41:14 +00:00
|
|
|
throw std::invalid_argument{
|
|
|
|
fmt::format("{} is the incorrect type for [{}]:{}", typeid(T).name(), section, name)};
|
2020-03-16 23:26:18 +00:00
|
|
|
|
|
|
|
return derived->getValue();
|
|
|
|
}
|
|
|
|
|
2020-03-20 05:24:45 +00:00
|
|
|
/// Add an "undeclared" handler for the given section. This is a handler that will be called
|
|
|
|
/// whenever a k:v pair is found that doesn't match a provided definition.
|
|
|
|
///
|
|
|
|
/// Any exception thrown by the handler will progagate back through the call to
|
|
|
|
/// addConfigValue().
|
|
|
|
///
|
|
|
|
/// @param section is the section for which any undeclared values will invoke the provided
|
|
|
|
/// handler
|
2020-04-07 20:41:11 +00:00
|
|
|
/// @param handler
|
2020-03-20 05:24:45 +00:00
|
|
|
/// @throws if there is already a handler for this section
|
|
|
|
void
|
|
|
|
addUndeclaredHandler(const std::string& section, UndeclaredValueHandler handler);
|
|
|
|
|
|
|
|
/// Removes an "undeclared" handler for the given section.
|
|
|
|
///
|
|
|
|
/// @param section is the section which we want to remove the handler for
|
|
|
|
void
|
|
|
|
removeUndeclaredHandler(const std::string& section);
|
|
|
|
|
2020-03-18 13:39:18 +00:00
|
|
|
/// Validate that all required fields are present.
|
2020-03-16 23:26:18 +00:00
|
|
|
///
|
|
|
|
/// @throws std::invalid_argument if configuration constraints are not met
|
2020-03-17 03:13:37 +00:00
|
|
|
void
|
2020-03-18 13:39:18 +00:00
|
|
|
validateRequiredFields();
|
2020-03-16 23:26:18 +00:00
|
|
|
|
2022-09-10 02:44:21 +00:00
|
|
|
/// Accept all options. This will call the acceptor (if present) on each option. Note that
|
|
|
|
/// this should only be called if all required fields are present (that is,
|
|
|
|
/// validateRequiredFields() has been or could be called without throwing).
|
2020-03-18 15:14:52 +00:00
|
|
|
///
|
|
|
|
/// @throws if any option's acceptor throws
|
|
|
|
void
|
|
|
|
acceptAllOptions();
|
|
|
|
|
2022-07-09 15:05:52 +00:00
|
|
|
/// validates and accept all parsed options
|
|
|
|
inline void
|
|
|
|
process()
|
|
|
|
{
|
|
|
|
validateRequiredFields();
|
|
|
|
acceptAllOptions();
|
|
|
|
}
|
|
|
|
|
2020-03-25 03:34:23 +00:00
|
|
|
/// Add comments for a given section. Comments are replayed in-order during config file
|
|
|
|
/// generation. A proper comment prefix will automatically be applied, and the entire comment
|
|
|
|
/// will otherwise be used verbatim (no automatic line separation, etc.).
|
|
|
|
///
|
|
|
|
/// @param section
|
|
|
|
/// @param comment
|
|
|
|
void
|
2020-03-31 20:12:06 +00:00
|
|
|
addSectionComments(const std::string& section, std::vector<std::string> comments);
|
2020-03-25 03:34:23 +00:00
|
|
|
|
|
|
|
/// Add comments for a given option. Similar to addSectionComment, but applies to a specific
|
|
|
|
/// [section]:name pair.
|
|
|
|
///
|
|
|
|
/// @param section
|
|
|
|
/// @param name
|
|
|
|
/// @param comment
|
|
|
|
void
|
2020-04-07 20:41:11 +00:00
|
|
|
addOptionComments(
|
|
|
|
const std::string& section, const std::string& name, std::vector<std::string> comments);
|
2020-03-25 03:34:23 +00:00
|
|
|
|
2020-03-17 22:15:30 +00:00
|
|
|
/// Generate a config string from the current config definition, optionally using overridden
|
|
|
|
/// values. The generated config will preserve insertion order of both sections and their
|
|
|
|
/// definitions.
|
|
|
|
///
|
|
|
|
/// Definitions which are required or have an overriden value (and useValues == true) will be
|
|
|
|
/// written normally. Otherwise, they will be written commented-out in order to provide a
|
|
|
|
/// complete documentation of the configuration file.
|
|
|
|
///
|
|
|
|
/// @param useValues specifies whether we use specified values (e.g. those from calls to
|
|
|
|
/// addConfigValue()) or only definitions
|
|
|
|
/// @return a string containing the config in INI format
|
2020-03-16 23:26:18 +00:00
|
|
|
std::string
|
2020-03-17 22:15:30 +00:00
|
|
|
generateINIConfig(bool useValues = false);
|
2020-03-16 23:26:18 +00:00
|
|
|
|
|
|
|
private:
|
Config file improvements (#1397)
* Config file API/comment improvements
API improvements:
=================
Make the config API use position-independent tag parameters (Required,
Default{123}, MultiValue) rather than a sequence of bools with
overloads. For example, instead of:
conf.defineOption<int>("a", "b", false, true, 123, [] { ... });
you now write:
conf.defineOption<int>("a", "b", MultiValue, Default{123}, [] { ... });
The tags are:
- Required
- MultiValue
- Default{value}
plus new abilities (see below):
- Hidden
- RelayOnly
- ClientOnly
- Comment{"line1", "line2", "line3"}
Made option definition more powerful:
=====================================
- `Hidden` allows you to define an option that won't show up in the
generated config file if it isn't set.
- `RelayOnly`/`ClientOnly` sets up an option that is only accepted and
only shows up for relay or client configs. (If neither is specified
the option shows up in both modes).
- `Comment{...}` lets the option comments be specified as part of the
defineOption.
Comment improvements
====================
- Rewrote comments for various options to expand on details.
- Inlined all the comments with the option definitions.
- Several options that were missing comments got comments added.
- Made various options for deprecated and or internal options hidden by
default so that they don't show up in a default config file.
- show the section comment (but not option comments) *after* the
[section] tag instead of before it as it makes more sense that way
(particularly for the [bind] section which has a new long comment to
describe how it works).
Disable profiling by default
============================
We had this weird state where we use and store profiling by default but
never *load* it when starting up. This commit makes us just not use
profiling at all unless explicitly enabled.
Other misc changes:
===================
- change default worker threads to 0 (= num cpus) instead of 1, and fix
it to allow 0.
- Actually apply worker-threads option
- fixed default data-dir value erroneously having quotes around it
- reordered ifname/ifaddr/mapaddr (was previously mapaddr/ifaddr/ifname)
as mapaddr is a sort of specialization of ifaddr and so makes more
sense to come after it (particularly because it now references ifaddr
in its help message).
- removed peer-stats option (since we always require it for relays and
never use it for clients)
- removed router profiles filename option (this doesn't need to be
configurable)
- removed defunct `service-node-seed` option
- Change default logging output file to "" (which means stdout), and
also made "-" work for stdout.
* Router hive compilation fixes
* Comments for SNApp SRV settings in ini file
* Add extra blank line after section comments
* Better deprecated option handling
Allow {client,relay}-only options in {relay,client} configs to be
specified as implicitly deprecated options: they warn, and don't set
anything.
Add an explicit `Deprecated` tag and move deprecated option handling
into definition.cpp.
* Move backwards compat options into section definitions
Keep the "addBackwardsCompatibleConfigOptions" only for options in
sections that no longer exist.
* Fix INI parsing issues & C++17-ify
- don't allow inline comments because it seems they aren't allowed in
ini formats in general, and is going to cause problems if there is a
comment character in a value (e.g. an exit auth string). Additionally
it was breaking on a line such as:
# some comment; see?
because it was treating only `; see?` as the comment and then producing
an error message about the rest of the line being invalid.
- make section parsing stricter: the `[` and `]` have to be at the
beginning at end of the line now (after stripping whitespace).
- Move whitespace stripping to the top since everything in here does it.
- chop off string_view suffix/prefix rather than maintaining position
values
- fix potential infinite loop/segfault when given a line such as `]foo[`
* Make config parsing failure fatal
Load() LogError's and returns false on failure, so we weren't aborting
on config file errors.
* Formatting: allow `{}` for empty functions/structs
Instead of using two lines when empty:
{
}
* Make default dns bind 127.0.0.1 on non-Linux
* Don't show empty section; fix tests
We can conceivably have sections that only make sense for clients or
relays, and so want to completely omit that section if we have no
options for the type of config being generated.
Also fixes missing empty lines between tests.
Co-authored-by: Thomas Winget <tewinget@gmail.com>
2020-10-07 22:22:58 +00:00
|
|
|
// If true skip client-only options; if false skip relay-only options.
|
|
|
|
bool relay;
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
OptionDefinition_ptr&
|
2020-05-01 19:51:15 +00:00
|
|
|
lookupDefinitionOrThrow(std::string_view section, std::string_view name);
|
2020-04-07 20:41:11 +00:00
|
|
|
const OptionDefinition_ptr&
|
2020-05-01 19:51:15 +00:00
|
|
|
lookupDefinitionOrThrow(std::string_view section, std::string_view name) const;
|
2020-03-17 21:17:35 +00:00
|
|
|
|
|
|
|
using SectionVisitor = std::function<void(const std::string&, const DefinitionMap&)>;
|
2020-04-07 20:41:11 +00:00
|
|
|
void
|
|
|
|
visitSections(SectionVisitor visitor) const;
|
2020-03-17 21:17:35 +00:00
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
using DefVisitor = std::function<void(const std::string&, const OptionDefinition_ptr&)>;
|
2020-04-07 20:41:11 +00:00
|
|
|
void
|
|
|
|
visitDefinitions(const std::string& section, DefVisitor visitor) const;
|
2020-03-17 21:17:35 +00:00
|
|
|
|
2020-03-20 05:24:45 +00:00
|
|
|
SectionMap m_definitions;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, UndeclaredValueHandler> m_undeclaredHandlers;
|
|
|
|
|
2020-03-31 20:12:06 +00:00
|
|
|
// track insertion order. the vector<string>s are ordered list of section/option names.
|
2020-03-17 21:17:35 +00:00
|
|
|
std::vector<std::string> m_sectionOrdering;
|
|
|
|
std::unordered_map<std::string, std::vector<std::string>> m_definitionOrdering;
|
2020-03-25 03:34:23 +00:00
|
|
|
|
|
|
|
// comments for config file generation
|
|
|
|
using CommentList = std::vector<std::string>;
|
|
|
|
using CommentsMap = std::unordered_map<std::string, CommentList>;
|
|
|
|
CommentsMap m_sectionComments;
|
|
|
|
std::unordered_map<std::string, CommentsMap> m_definitionComments;
|
2020-03-16 23:26:18 +00:00
|
|
|
};
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
} // namespace llarp
|