]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/net/ProtocolV1.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / crimson / net / ProtocolV1.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include "Protocol.h"
7
8 class AuthAuthorizer;
9 class AuthSessionHandler;
10
11 namespace crimson::net {
12
13 class ProtocolV1 final : public Protocol {
14 public:
15 ProtocolV1(ChainedDispatchers& dispatchers,
16 SocketConnection& conn,
17 SocketMessenger& messenger);
18 ~ProtocolV1() override;
19 void print(std::ostream&) const final;
20 private:
21 void on_closed() override;
22 bool is_connected() const override;
23
24 void start_connect(const entity_addr_t& peer_addr,
25 const entity_name_t& peer_name) override;
26
27 void start_accept(SocketRef&& socket,
28 const entity_addr_t& peer_addr) override;
29
30 void trigger_close() override;
31
32 ceph::bufferlist do_sweep_messages(
33 const std::deque<MessageRef>& msgs,
34 size_t num_msgs,
35 bool require_keepalive,
36 std::optional<utime_t> keepalive_ack,
37 bool require_ack) override;
38
39 private:
40 SocketMessenger &messenger;
41
42 enum class state_t {
43 none,
44 accepting,
45 connecting,
46 open,
47 standby,
48 wait,
49 closing
50 };
51 state_t state = state_t::none;
52
53 // state for handshake
54 struct Handshake {
55 ceph_msg_connect connect;
56 ceph_msg_connect_reply reply;
57 ceph::bufferlist auth_payload; // auth(orizer) payload read off the wire
58 ceph::bufferlist auth_more; // connect-side auth retry (we added challenge)
59 std::chrono::milliseconds backoff;
60 uint32_t connect_seq = 0;
61 uint32_t peer_global_seq = 0;
62 uint32_t global_seq;
63 } h;
64
65 std::unique_ptr<AuthSessionHandler> session_security;
66
67 // state for an incoming message
68 struct MessageReader {
69 ceph_msg_header header;
70 ceph_msg_footer footer;
71 bufferlist front;
72 bufferlist middle;
73 bufferlist data;
74 } m;
75
76 struct Keepalive {
77 struct {
78 const char tag = CEPH_MSGR_TAG_KEEPALIVE2;
79 ceph_timespec stamp;
80 } __attribute__((packed)) req;
81 struct {
82 const char tag = CEPH_MSGR_TAG_KEEPALIVE2_ACK;
83 ceph_timespec stamp;
84 } __attribute__((packed)) ack;
85 ceph_timespec ack_stamp;
86 } k;
87
88 private:
89 // connecting
90 void reset_session();
91 seastar::future<stop_t> handle_connect_reply(crimson::net::msgr_tag_t tag);
92 seastar::future<stop_t> repeat_connect();
93 ceph::bufferlist get_auth_payload();
94
95 // accepting
96 seastar::future<stop_t> send_connect_reply(
97 msgr_tag_t tag, bufferlist&& authorizer_reply = {});
98 seastar::future<stop_t> send_connect_reply_ready(
99 msgr_tag_t tag, bufferlist&& authorizer_reply);
100 seastar::future<stop_t> replace_existing(
101 SocketConnectionRef existing,
102 bufferlist&& authorizer_reply,
103 bool is_reset_from_peer = false);
104 seastar::future<stop_t> handle_connect_with_existing(
105 SocketConnectionRef existing, bufferlist&& authorizer_reply);
106 bool require_auth_feature() const;
107 bool require_cephx_v2_feature() const;
108 seastar::future<stop_t> repeat_handle_connect();
109
110 // open
111 seastar::future<> handle_keepalive2_ack();
112 seastar::future<> handle_keepalive2();
113 seastar::future<> handle_ack();
114 seastar::future<> maybe_throttle();
115 seastar::future<> read_message();
116 seastar::future<> handle_tags();
117
118 enum class open_t {
119 connected,
120 accepted
121 };
122 void execute_open(open_t type);
123
124 // replacing
125 // the number of connections initiated in this session, increment when a
126 // new connection is established
127 uint32_t connect_seq() const { return h.connect_seq; }
128 // the client side should connect us with a gseq. it will be reset with
129 // the one of exsting connection if it's greater.
130 uint32_t peer_global_seq() const { return h.peer_global_seq; }
131 // current state of ProtocolV1
132 state_t get_state() const { return state; }
133
134 seastar::future<> fault();
135 };
136
137 } // namespace crimson::net