Skip to content

Commit

Permalink
sentry: --nodiscovery option (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Jun 29, 2023
1 parent 8ec57da commit d0f8da6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/common/sentry_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ void add_sentry_options(CLI::App& cli, silkworm::sentry::Settings& settings) {
static_peers_option->description("Peers enode URLs to connect to without discovery");
static_peers_option->type_size(1, INT_MAX);

cli.add_flag("--nodiscover", settings.no_discover)
->description("Disables automatic peer discovery");

cli.add_option("--maxpeers", settings.max_peers)
->description("Maximum number of P2P network peers")
->check(CLI::Range(0, 1000))
Expand Down
15 changes: 13 additions & 2 deletions silkworm/sentry/discovery/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DiscoveryImpl {
public:
explicit DiscoveryImpl(
std::vector<common::EnodeUrl> peer_urls,
bool with_dynamic_discovery,
std::function<common::EccKeyPair()> node_key,
uint16_t disc_v4_port);

Expand All @@ -48,19 +49,24 @@ class DiscoveryImpl {

private:
const std::vector<common::EnodeUrl> peer_urls_;
bool with_dynamic_discovery_;
disc_v4::Discovery disc_v4_discovery_;
};

DiscoveryImpl::DiscoveryImpl(
std::vector<common::EnodeUrl> peer_urls,
bool with_dynamic_discovery,
std::function<common::EccKeyPair()> node_key,
uint16_t disc_v4_port)
: peer_urls_(std::move(peer_urls)),
with_dynamic_discovery_(with_dynamic_discovery),
disc_v4_discovery_(disc_v4_port, node_key) {
}

Task<void> DiscoveryImpl::run() {
co_await disc_v4_discovery_.run();
if (with_dynamic_discovery_) {
co_await disc_v4_discovery_.run();
}
}

template <typename T>
Expand Down Expand Up @@ -92,9 +98,14 @@ bool DiscoveryImpl::is_static_peer_url(const common::EnodeUrl& peer_url) {

Discovery::Discovery(
std::vector<common::EnodeUrl> peer_urls,
bool with_dynamic_discovery,
std::function<common::EccKeyPair()> node_key,
uint16_t disc_v4_port)
: p_impl_(std::make_unique<DiscoveryImpl>(std::move(peer_urls), std::move(node_key), disc_v4_port)) {}
: p_impl_(std::make_unique<DiscoveryImpl>(
std::move(peer_urls),
with_dynamic_discovery,
std::move(node_key),
disc_v4_port)) {}

Discovery::~Discovery() {
log::Trace("sentry") << "silkworm::sentry::discovery::Discovery::~Discovery";
Expand Down
1 change: 1 addition & 0 deletions silkworm/sentry/discovery/discovery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Discovery {
public:
explicit Discovery(
std::vector<common::EnodeUrl> peer_urls,
bool with_dynamic_discovery,
std::function<common::EccKeyPair()> node_key,
uint16_t disc_v4_port);
~Discovery();
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sentry/sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ SentryImpl::SentryImpl(Settings settings, silkworm::rpc::ServerContextPool& cont
context_pool_(context_pool),
status_manager_(context_pool_.next_io_context()),
rlpx_server_(context_pool_.next_io_context(), settings_.port),
discovery_(settings_.static_peers, node_key_provider(), settings_.port),
discovery_(settings_.static_peers, !settings_.no_discover, node_key_provider(), settings_.port),
peer_manager_(context_pool_.next_io_context(), settings_.max_peers, context_pool_),
message_sender_(context_pool_.next_io_context()),
message_receiver_(std::make_shared<MessageReceiver>(context_pool_.next_io_context(), settings_.max_peers)),
Expand Down
2 changes: 2 additions & 0 deletions silkworm/sentry/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct Settings {

std::vector<common::EnodeUrl> static_peers;

bool no_discover{true};

size_t max_peers{100};
};

Expand Down

0 comments on commit d0f8da6

Please sign in to comment.