// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- #pragma once #include #include #include #include #include #include "auth/KeyRing.h" #include "crimson/net/Dispatcher.h" #include "crimson/net/Fwd.h" #include "mon/MonMap.h" #include "mon/MonSub.h" template using Ref = boost::intrusive_ptr; namespace ceph::net { class Messenger; } class AuthMethodList; class MAuthReply; struct MMonMap; struct MMonSubscribeAck; struct MMonGetVersionReply; struct MMonCommandAck; struct MLogAck; struct MConfig; namespace ceph::mon { class Connection; class Client : public ceph::net::Dispatcher { EntityName entity_name; KeyRing keyring; std::unique_ptr auth_methods; const uint32_t want_keys; MonMap monmap; seastar::promise reply; std::unique_ptr active_con; std::vector pending_conns; seastar::timer timer; seastar::gate tick_gate; ceph::net::Messenger& msgr; // commands using get_version_t = seastar::future; ceph_tid_t last_version_req_id = 0; std::map version_reqs; ceph_tid_t last_mon_command_id = 0; using command_result_t = seastar::future; std::map mon_commands; MonSub sub; public: Client(ceph::net::Messenger& messenger); Client(Client&&); ~Client(); seastar::future<> start(); seastar::future<> stop(); const uuid_d& get_fsid() const { return monmap.fsid; } get_version_t get_version(const std::string& map); command_result_t run_command(const std::vector& cmd, const bufferlist& bl); seastar::future<> send_message(MessageRef); bool sub_want(const std::string& what, version_t start, unsigned flags); void sub_got(const std::string& what, version_t have); void sub_unwant(const std::string& what); bool sub_want_increment(const std::string& what, version_t start, unsigned flags); seastar::future<> renew_subs(); private: void tick(); seastar::future<> ms_dispatch(ceph::net::ConnectionRef conn, MessageRef m) override; seastar::future<> ms_handle_reset(ceph::net::ConnectionRef conn) override; seastar::future<> handle_monmap(ceph::net::ConnectionRef conn, Ref m); seastar::future<> handle_auth_reply(ceph::net::ConnectionRef conn, Ref m); seastar::future<> handle_subscribe_ack(Ref m); seastar::future<> handle_get_version_reply(Ref m); seastar::future<> handle_mon_command_ack(Ref m); seastar::future<> handle_log_ack(Ref m); seastar::future<> handle_config(Ref m); private: seastar::future<> load_keyring(); seastar::future<> authenticate(); bool is_hunting() const; seastar::future<> reopen_session(int rank); std::vector get_random_mons(unsigned n) const; seastar::future<> _add_conn(unsigned rank, uint64_t global_id); }; } // namespace ceph::mon