]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/net/SocketConnection.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / crimson / net / SocketConnection.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2017 Red Hat, Inc
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#pragma once
16
11fdf7f2
TL
17#include <seastar/core/sharded.hh>
18
19#include "msg/Policy.h"
9f95a23c
TL
20#include "crimson/net/Connection.h"
21#include "crimson/net/Socket.h"
11fdf7f2
TL
22#include "crimson/thread/Throttle.h"
23
9f95a23c 24namespace crimson::net {
11fdf7f2 25
9f95a23c
TL
26class Dispatcher;
27class Protocol;
11fdf7f2
TL
28class SocketMessenger;
29class SocketConnection;
30using SocketConnectionRef = seastar::shared_ptr<SocketConnection>;
31
32class SocketConnection : public Connection {
33 SocketMessenger& messenger;
9f95a23c 34 std::unique_ptr<Protocol> protocol;
11fdf7f2 35
9f95a23c
TL
36 // if acceptor side, ephemeral_port is different from peer_addr.get_port();
37 // if connector side, ephemeral_port is different from my_addr.get_port().
11fdf7f2
TL
38 enum class side_t {
39 none,
40 acceptor,
41 connector
42 };
43 side_t side = side_t::none;
9f95a23c
TL
44 uint16_t ephemeral_port = 0;
45 void set_ephemeral_port(uint16_t port, side_t _side) {
46 ephemeral_port = port;
47 side = _side;
11fdf7f2
TL
48 }
49
9f95a23c
TL
50 ceph::net::Policy<crimson::thread::Throttle> policy;
51
11fdf7f2
TL
52 /// the seq num of the last transmitted message
53 seq_num_t out_seq = 0;
54 /// the seq num of the last received message
55 seq_num_t in_seq = 0;
56 /// update the seq num of last received message
57 /// @returns true if the @c seq is valid, and @c in_seq is updated,
58 /// false otherwise.
59 bool update_rx_seq(seq_num_t seq);
60
11fdf7f2 61 // messages to be resent after connection gets reset
9f95a23c
TL
62 std::deque<MessageRef> out_q;
63 std::deque<MessageRef> pending_q;
11fdf7f2 64 // messages sent, but not yet acked by peer
9f95a23c 65 std::deque<MessageRef> sent;
11fdf7f2 66
9f95a23c 67 seastar::shard_id shard_id() const;
11fdf7f2
TL
68
69 public:
70 SocketConnection(SocketMessenger& messenger,
9f95a23c
TL
71 Dispatcher& dispatcher,
72 bool is_msgr2);
73 ~SocketConnection() override;
11fdf7f2
TL
74
75 Messenger* get_messenger() const override;
76
9f95a23c 77 bool is_connected() const override;
11fdf7f2 78
9f95a23c
TL
79#ifdef UNIT_TESTS_BUILT
80 bool is_closed() const override;
81
82 bool peer_wins() const override;
83#else
84 bool peer_wins() const;
85#endif
11fdf7f2
TL
86
87 seastar::future<> send(MessageRef msg) override;
88
89 seastar::future<> keepalive() override;
90
91 seastar::future<> close() override;
92
11fdf7f2
TL
93 void print(ostream& out) const override;
94
11fdf7f2
TL
95 /// start a handshake from the client's perspective,
96 /// only call when SocketConnection first construct
97 void start_connect(const entity_addr_t& peer_addr,
98 const entity_type_t& peer_type);
99 /// start a handshake from the server's perspective,
100 /// only call when SocketConnection first construct
9f95a23c 101 void start_accept(SocketRef&& socket,
11fdf7f2
TL
102 const entity_addr_t& peer_addr);
103
11fdf7f2
TL
104 bool is_server_side() const {
105 return policy.server;
106 }
9f95a23c 107
11fdf7f2
TL
108 bool is_lossy() const {
109 return policy.lossy;
110 }
111
9f95a23c
TL
112 friend class Protocol;
113 friend class ProtocolV1;
114 friend class ProtocolV2;
11fdf7f2
TL
115};
116
9f95a23c 117} // namespace crimson::net