]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/net/Messenger.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / net / Messenger.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 17#include "Fwd.h"
f67539c2 18#include "crimson/common/throttle.h"
9f95a23c 19#include "msg/Message.h"
11fdf7f2
TL
20#include "msg/Policy.h"
21
22class AuthAuthorizer;
23
9f95a23c
TL
24namespace crimson::auth {
25class AuthClient;
26class AuthServer;
27}
28
29namespace crimson::net {
30
31#ifdef UNIT_TESTS_BUILT
32class Interceptor;
33#endif
11fdf7f2 34
f67539c2 35using Throttle = crimson::common::Throttle;
11fdf7f2
TL
36using SocketPolicy = ceph::net::Policy<Throttle>;
37
38class Messenger {
9f95a23c 39public:
1e59de90
TL
40 Messenger() {}
41
11fdf7f2
TL
42 virtual ~Messenger() {}
43
1e59de90
TL
44 virtual const entity_name_t& get_myname() const = 0;
45
46 entity_type_t get_mytype() const { return get_myname().type(); }
47
48 virtual const entity_addrvec_t &get_myaddrs() const = 0;
49
50 entity_addr_t get_myaddr() const { return get_myaddrs().front(); }
51
52 virtual void set_myaddrs(const entity_addrvec_t& addrs) = 0;
9f95a23c 53
20effc67 54 virtual bool set_addr_unknowns(const entity_addrvec_t &addrs) = 0;
11fdf7f2 55
1e59de90
TL
56 virtual void set_auth_client(crimson::auth::AuthClient *) = 0;
57
58 virtual void set_auth_server(crimson::auth::AuthServer *) = 0;
59
f67539c2 60 using bind_ertr = crimson::errorator<
20effc67
TL
61 crimson::ct_error::address_in_use, // The address (range) is already bound
62 crimson::ct_error::address_not_available
f67539c2 63 >;
11fdf7f2 64 /// bind to the given address
f67539c2 65 virtual bind_ertr::future<> bind(const entity_addrvec_t& addr) = 0;
11fdf7f2 66
11fdf7f2 67 /// start the messenger
f67539c2 68 virtual seastar::future<> start(const dispatchers_t&) = 0;
11fdf7f2
TL
69
70 /// either return an existing connection to the peer,
71 /// or a new pending connection
9f95a23c 72 virtual ConnectionRef
11fdf7f2 73 connect(const entity_addr_t& peer_addr,
f67539c2
TL
74 const entity_name_t& peer_name) = 0;
75
76 ConnectionRef
77 connect(const entity_addr_t& peer_addr,
78 const entity_type_t& peer_type) {
79 return connect(peer_addr, entity_name_t(peer_type, -1));
80 }
11fdf7f2 81
1e59de90
TL
82 virtual bool owns_connection(Connection &) const = 0;
83
11fdf7f2
TL
84 // wait for messenger shutdown
85 virtual seastar::future<> wait() = 0;
86
f67539c2
TL
87 // stop dispatching events and messages
88 virtual void stop() = 0;
89
90 virtual bool is_started() const = 0;
91
92 // free internal resources before destruction, must be called after stopped,
93 // and must be called if is bound.
11fdf7f2
TL
94 virtual seastar::future<> shutdown() = 0;
95
20effc67 96 virtual void print(std::ostream& out) const = 0;
11fdf7f2 97
9f95a23c
TL
98 virtual SocketPolicy get_policy(entity_type_t peer_type) const = 0;
99
100 virtual SocketPolicy get_default_policy() const = 0;
101
11fdf7f2
TL
102 virtual void set_default_policy(const SocketPolicy& p) = 0;
103
104 virtual void set_policy(entity_type_t peer_type, const SocketPolicy& p) = 0;
105
106 virtual void set_policy_throttler(entity_type_t peer_type, Throttle* throttle) = 0;
107
9f95a23c 108 static MessengerRef
11fdf7f2
TL
109 create(const entity_name_t& name,
110 const std::string& lname,
9f95a23c 111 const uint64_t nonce);
1e59de90
TL
112
113#ifdef UNIT_TESTS_BUILT
114 virtual void set_interceptor(Interceptor *) = 0;
115#endif
11fdf7f2
TL
116};
117
20effc67 118inline std::ostream& operator<<(std::ostream& out, const Messenger& msgr) {
11fdf7f2
TL
119 out << "[";
120 msgr.print(out);
121 out << "]";
122 return out;
123}
124
9f95a23c 125} // namespace crimson::net
1e59de90
TL
126
127#if FMT_VERSION >= 90000
128template <> struct fmt::formatter<crimson::net::Messenger> : fmt::ostream_formatter {};
129#endif