From 0be7365f59106887fad99170ff86e4ffcd826e01 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Mon, 31 Oct 2022 17:32:53 +0800 Subject: [PATCH] crimson/net: proper group SocketConnection interfaces Signed-off-by: Yingxin Cheng --- src/crimson/net/ProtocolV2.cc | 19 ++++++---- src/crimson/net/SocketConnection.h | 59 ++++++++++++++---------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/crimson/net/ProtocolV2.cc b/src/crimson/net/ProtocolV2.cc index caa19da1e5f..11fdbbcd5c5 100644 --- a/src/crimson/net/ProtocolV2.cc +++ b/src/crimson/net/ProtocolV2.cc @@ -111,20 +111,25 @@ template auto ptr(const ::seastar::shared_ptr& p) -> const void* namespace crimson::net { #ifdef UNIT_TESTS_BUILT -void intercept(Breakpoint bp, bp_type_t type, - SocketConnection& conn, SocketRef& socket) { - if (conn.interceptor) { - auto action = conn.interceptor->intercept(conn, Breakpoint(bp)); - socket->set_trap(type, action, &conn.interceptor->blocker); +void intercept(Breakpoint bp, + bp_type_t type, + Connection& conn, + Interceptor *interceptor, + SocketRef& socket) { + if (interceptor) { + auto action = interceptor->intercept(conn, Breakpoint(bp)); + socket->set_trap(type, action, &interceptor->blocker); } } #define INTERCEPT_CUSTOM(bp, type) \ -intercept({bp}, type, conn, conn.socket) +intercept({bp}, type, conn, \ + conn.interceptor, conn.socket) #define INTERCEPT_FRAME(tag, type) \ intercept({static_cast(tag), type}, \ - type, conn, conn.socket) + type, conn, \ + conn.interceptor, conn.socket) #define INTERCEPT_N_RW(bp) \ if (conn.interceptor) { \ diff --git a/src/crimson/net/SocketConnection.h b/src/crimson/net/SocketConnection.h index d4cbca463d3..5a698919f28 100644 --- a/src/crimson/net/SocketConnection.h +++ b/src/crimson/net/SocketConnection.h @@ -59,10 +59,6 @@ class SocketConnection : public Connection { seq_num_t out_seq = 0; /// the seq num of the last received message seq_num_t in_seq = 0; - /// update the seq num of last received message - /// @returns true if the @c seq is valid, and @c in_seq is updated, - /// false otherwise. - bool update_rx_seq(seq_num_t seq); // messages to be resent after connection gets reset std::deque out_q; @@ -73,8 +69,7 @@ class SocketConnection : public Connection { std::unique_ptr user_private; - seastar::shard_id shard_id() const; - + // Connection interfaces, public to users public: SocketConnection(SocketMessenger& messenger, ChainedDispatchers& dispatchers); @@ -133,7 +128,34 @@ class SocketConnection : public Connection { void print(std::ostream& out) const override; + // public to SocketMessenger public: + /// start a handshake from the client's perspective, + /// only call when SocketConnection first construct + void start_connect(const entity_addr_t& peer_addr, + const entity_name_t& peer_name); + + /// start a handshake from the server's perspective, + /// only call when SocketConnection first construct + void start_accept(SocketRef&& socket, + const entity_addr_t& peer_addr); + + seastar::future<> close_clean(bool dispatch_reset); + + seastar::socket_address get_local_address() const; + + SocketMessenger &get_messenger() const { + return messenger; + } + +private: + seastar::shard_id shard_id() const; + + /// update the seq num of last received message + /// @returns true if the @c seq is valid, and @c in_seq is updated, + /// false otherwise. + bool update_rx_seq(seq_num_t seq); + void set_peer_type(entity_type_t peer_type) { // it is not allowed to assign an unknown value when the current // value is known @@ -173,31 +195,6 @@ class SocketConnection : public Connection { features = f; } - /// start a handshake from the client's perspective, - /// only call when SocketConnection first construct - void start_connect(const entity_addr_t& peer_addr, - const entity_name_t& peer_name); - /// start a handshake from the server's perspective, - /// only call when SocketConnection first construct - void start_accept(SocketRef&& socket, - const entity_addr_t& peer_addr); - - seastar::future<> close_clean(bool dispatch_reset); - - bool is_server_side() const { - return policy.server; - } - - bool is_lossy() const { - return policy.lossy; - } - - seastar::socket_address get_local_address() const; - - SocketMessenger &get_messenger() const { - return messenger; - } - #ifdef UNIT_TESTS_BUILT bool is_closed_clean() const override; -- 2.39.5