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 <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2020-07-24 11:17:42 +03:00
parent 41eee249d7
commit c28aeaee2e
6 changed files with 40 additions and 55 deletions

42
init.cc
View File

@@ -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<credentials_builder> creds;
if (mscfg.encrypt != encrypt_what::none) {
creds = std::make_shared<credentials_builder>();
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<gms::gossiper>& gossiper
, db::config& cfg
, sstring listen_address_in

13
init.hh
View File

@@ -24,10 +24,7 @@
#include <seastar/core/future.hh>
#include <seastar/core/distributed.hh>
#include <seastar/core/abort_source.hh>
#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<gms::gossiper>& gossiper
, db::config& cfg
, sstring listen_address

View File

@@ -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");

View File

@@ -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<credentials_builder> creds;
if (mscfg.encrypt != encrypt_what::none) {
creds = std::make_shared<credentials_builder>();
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

View File

@@ -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

View File

@@ -19,6 +19,7 @@
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#include <seastar/core/seastar.hh>
#include "init.hh"
#include "supervisor.hh"
#include "directories.hh"