From c28aeaee2e7e828b4fe00da20103d35e2e9fca22 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 24 Jul 2020 11:17:42 +0300 Subject: [PATCH] messaging_service: Move initialization to messaging/ Now the init_messaging_service() only deals with messaing service and related internal stuff, so it can sit in its own module. Signed-off-by: Pavel Emelyanov --- init.cc | 42 ------------------------------------ init.hh | 13 +---------- main.cc | 2 +- message/messaging_service.cc | 34 +++++++++++++++++++++++++++++ message/messaging_service.hh | 3 +++ utils/directories.cc | 1 + 6 files changed, 40 insertions(+), 55 deletions(-) diff --git a/init.cc b/init.cc index d9ec55a619..ce822efcb5 100644 --- a/init.cc +++ b/init.cc @@ -20,57 +20,15 @@ */ #include "init.hh" -#include "message/messaging_service.hh" #include "gms/failure_detector.hh" #include "gms/gossiper.hh" -#include "service/storage_service.hh" #include "to_string.hh" #include "gms/inet_address.hh" -#include "gms/feature_service.hh" #include "seastarx.hh" #include "db/config.hh" logging::logger startlog("init"); -void init_messaging_service(netw::messaging_service::config mscfg - , sstring ms_trust_store - , sstring ms_cert - , sstring ms_key - , sstring ms_tls_prio - , bool ms_client_auth - , netw::messaging_service::scheduling_config scfg) { - - using encrypt_what = netw::messaging_service::encrypt_what; - using namespace seastar::tls; - - std::shared_ptr creds; - - if (mscfg.encrypt != encrypt_what::none) { - creds = std::make_shared(); - creds->set_dh_level(dh_params::level::MEDIUM); - - creds->set_x509_key_file(ms_cert, ms_key, x509_crt_format::PEM).get(); - if (ms_trust_store.empty()) { - creds->set_system_trust().get(); - } else { - creds->set_x509_trust_file(ms_trust_store, x509_crt_format::PEM).get(); - } - - creds->set_priority_string(db::config::default_tls_priority); - - if (!ms_tls_prio.empty()) { - creds->set_priority_string(ms_tls_prio); - } - if (ms_client_auth) { - creds->set_client_auth(seastar::tls::client_auth::REQUIRE); - } - } - - // Init messaging_service - // Delay listening messaging_service until gossip message handlers are registered - netw::get_messaging_service().start(mscfg, scfg, creds).get(); -} - void init_gossiper(sharded& gossiper , db::config& cfg , sstring listen_address_in diff --git a/init.hh b/init.hh index ceb6a65c94..b53750bb37 100644 --- a/init.hh +++ b/init.hh @@ -24,10 +24,7 @@ #include #include #include -#include "auth/service.hh" -#include "message/messaging_service.hh" -#include "db/system_distributed_keyspace.hh" -#include "database_fwd.hh" +#include "db/config.hh" #include "log.hh" #include "seastarx.hh" @@ -48,14 +45,6 @@ extern logging::logger startlog; class bad_configuration_error : public std::exception {}; -void init_messaging_service(netw::messaging_service::config cfg - , sstring ms_trust_store - , sstring ms_cert - , sstring ms_key - , sstring ms_tls_prio - , bool ms_client_auth - , netw::messaging_service::scheduling_config scheduling_config); - void init_gossiper(sharded& gossiper , db::config& cfg , sstring listen_address diff --git a/main.cc b/main.cc index 349aca46d1..37f70be139 100644 --- a/main.cc +++ b/main.cc @@ -840,7 +840,7 @@ int main(int ac, char** av) { scfg.streaming = dbcfg.streaming_scheduling_group; scfg.gossip = scheduling_group(); - init_messaging_service(std::move(mscfg), trust_store, cert, key, prio, clauth, std::move(scfg)); + netw::init_messaging_service(std::move(mscfg), std::move(scfg), trust_store, cert, key, prio, clauth); init_gossiper(gossiper, *cfg, listen_address, seed_provider, cluster_name); supervisor::notify("starting storage proxy"); diff --git a/message/messaging_service.cc b/message/messaging_service.cc index 1adc1742a4..c878ca6446 100644 --- a/message/messaging_service.cc +++ b/message/messaging_service.cc @@ -1401,4 +1401,38 @@ future<> messaging_service::send_hint_mutation(msg_addr id, clock_type::time_poi std::move(reply_to), shard, std::move(response_id), std::move(trace_info)); } +void init_messaging_service(messaging_service::config mscfg, netw::messaging_service::scheduling_config scfg, + sstring ms_trust_store, sstring ms_cert, sstring ms_key, sstring ms_tls_prio, bool ms_client_auth) { + using encrypt_what = messaging_service::encrypt_what; + using namespace seastar::tls; + + std::shared_ptr creds; + + if (mscfg.encrypt != encrypt_what::none) { + creds = std::make_shared(); + creds->set_dh_level(dh_params::level::MEDIUM); + + creds->set_x509_key_file(ms_cert, ms_key, x509_crt_format::PEM).get(); + if (ms_trust_store.empty()) { + creds->set_system_trust().get(); + } else { + creds->set_x509_trust_file(ms_trust_store, x509_crt_format::PEM).get(); + } + + creds->set_priority_string(db::config::default_tls_priority); + + if (!ms_tls_prio.empty()) { + creds->set_priority_string(ms_tls_prio); + } + if (ms_client_auth) { + creds->set_client_auth(seastar::tls::client_auth::REQUIRE); + } + } + + // Init messaging_service + // Delay listening messaging_service until gossip message handlers are registered + + get_messaging_service().start(mscfg, scfg, creds).get(); +} + } // namespace net diff --git a/message/messaging_service.hh b/message/messaging_service.hh index 11fc24d46d..dc79a566dd 100644 --- a/message/messaging_service.hh +++ b/message/messaging_service.hh @@ -570,4 +570,7 @@ inline messaging_service& get_local_messaging_service() { return _the_messaging_service.local(); } +void init_messaging_service(messaging_service::config cfg, messaging_service::scheduling_config scheduling_config, + sstring ms_trust_store, sstring ms_cert, sstring ms_key, sstring ms_tls_prio, bool ms_client_auth); + } // namespace netw diff --git a/utils/directories.cc b/utils/directories.cc index 0ee07a87cc..ab72128ca5 100644 --- a/utils/directories.cc +++ b/utils/directories.cc @@ -19,6 +19,7 @@ * along with Scylla. If not, see . */ +#include #include "init.hh" #include "supervisor.hh" #include "directories.hh"