From: Kefu Chai Date: Thu, 11 Apr 2019 05:01:36 +0000 (+0800) Subject: crimson/mon: refactor Connection::create_auth() so it can be reused X-Git-Tag: v15.1.0~2915^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=15b8258efb1dad4fb72d77ae714cc323e0569a4d;p=ceph.git crimson/mon: refactor Connection::create_auth() so it can be reused Connection::create_auth() will be shared by v1 and v2 msgrs, so we need to decouple it from v1 implementation. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 7ed927b3a4c3..ce57847b3756 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -12,6 +12,7 @@ #include "common/hostname.h" +#include "crimson/auth/AuthClient.h" #include "crimson/auth/KeyRing.h" #include "crimson/common/config_proxy.h" #include "crimson/common/log.h" @@ -67,9 +68,10 @@ private: seastar::future<> setup_session(epoch_t epoch, const AuthMethodList& auth_methods, const EntityName& name); - std::unique_ptr create_auth(Ref m, - const EntityName& name, - uint32_t want_keys); + std::unique_ptr create_auth(ceph::auth::method_t, + uint64_t global_id, + const EntityName& name, + uint32_t want_keys); seastar::future do_auth(); private: @@ -120,29 +122,24 @@ KeyStore& Connection::get_keys() { } std::unique_ptr -Connection::create_auth(Ref m, +Connection::create_auth(ceph::auth::method_t protocol, + uint64_t global_id, const EntityName& name, uint32_t want_keys) { static CephContext cct; std::unique_ptr auth; auth.reset(AuthClientHandler::create(&cct, - m->protocol, + protocol, &rotating_keyring)); if (!auth) { - logger().error("no handler for protocol {}", m->protocol); + logger().error("no handler for protocol {}", protocol); throw std::system_error(make_error_code( ceph::net::error::negotiation_failure)); } auth->init(name); auth->set_want_keys(want_keys); auth->set_global_id(global_id); - - if (m->global_id != global_id) { - // it's a new session - auth->set_global_id(global_id); - auth->reset(); - } return auth; } @@ -206,7 +203,13 @@ Connection::authenticate(epoch_t epoch, return reply.get_future(); }).then([name, want_keys, this](Ref m) { reply = decltype(reply){}; - auth = create_auth(m, name, want_keys); + if (m->global_id != global_id) { + // it's a new session + global_id = m->global_id; + auth->set_global_id(global_id); + auth->reset(); + } + auth = create_auth(m->protocol, m->global_id, name, want_keys); global_id = m->global_id; switch (auto p = m->result_bl.cbegin(); auth->handle_response(m->result, p,