1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2017 Red Hat, Inc
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.
18 #include "crimson/common/throttle.h"
19 #include "msg/Message.h"
20 #include "msg/Policy.h"
24 namespace crimson::auth
{
29 namespace crimson::net
{
31 #ifdef UNIT_TESTS_BUILT
35 using Throttle
= crimson::common::Throttle
;
36 using SocketPolicy
= ceph::net::Policy
<Throttle
>;
39 uint32_t crc_flags
= 0;
40 crimson::auth::AuthClient
* auth_client
= nullptr;
41 crimson::auth::AuthServer
* auth_server
= nullptr;
42 bool require_authorizer
= true;
45 entity_name_t my_name
;
46 entity_addrvec_t my_addrs
;
49 Messenger(const entity_name_t
& name
)
52 virtual ~Messenger() {}
54 #ifdef UNIT_TESTS_BUILT
55 Interceptor
*interceptor
= nullptr;
58 entity_type_t
get_mytype() const { return my_name
.type(); }
59 const entity_name_t
& get_myname() const { return my_name
; }
60 const entity_addrvec_t
& get_myaddrs() const { return my_addrs
; }
61 entity_addr_t
get_myaddr() const { return my_addrs
.front(); }
62 virtual seastar::future
<> set_myaddrs(const entity_addrvec_t
& addrs
) {
64 return seastar::now();
66 virtual bool set_addr_unknowns(const entity_addrvec_t
&addrs
) = 0;
68 using bind_ertr
= crimson::errorator
<
69 crimson::ct_error::address_in_use
, // The address (range) is already bound
70 crimson::ct_error::address_not_available
72 /// bind to the given address
73 virtual bind_ertr::future
<> bind(const entity_addrvec_t
& addr
) = 0;
75 /// start the messenger
76 virtual seastar::future
<> start(const dispatchers_t
&) = 0;
78 /// either return an existing connection to the peer,
79 /// or a new pending connection
81 connect(const entity_addr_t
& peer_addr
,
82 const entity_name_t
& peer_name
) = 0;
85 connect(const entity_addr_t
& peer_addr
,
86 const entity_type_t
& peer_type
) {
87 return connect(peer_addr
, entity_name_t(peer_type
, -1));
90 // wait for messenger shutdown
91 virtual seastar::future
<> wait() = 0;
93 // stop dispatching events and messages
94 virtual void stop() = 0;
96 virtual bool is_started() const = 0;
98 // free internal resources before destruction, must be called after stopped,
99 // and must be called if is bound.
100 virtual seastar::future
<> shutdown() = 0;
102 uint32_t get_crc_flags() const {
105 void set_crc_data() {
106 crc_flags
|= MSG_CRC_DATA
;
108 void set_crc_header() {
109 crc_flags
|= MSG_CRC_HEADER
;
112 crimson::auth::AuthClient
* get_auth_client() const { return auth_client
; }
113 void set_auth_client(crimson::auth::AuthClient
*ac
) {
116 crimson::auth::AuthServer
* get_auth_server() const { return auth_server
; }
117 void set_auth_server(crimson::auth::AuthServer
*as
) {
121 virtual void print(std::ostream
& out
) const = 0;
123 virtual SocketPolicy
get_policy(entity_type_t peer_type
) const = 0;
125 virtual SocketPolicy
get_default_policy() const = 0;
127 virtual void set_default_policy(const SocketPolicy
& p
) = 0;
129 virtual void set_policy(entity_type_t peer_type
, const SocketPolicy
& p
) = 0;
131 virtual void set_policy_throttler(entity_type_t peer_type
, Throttle
* throttle
) = 0;
133 // allow unauthenticated connections. This is needed for compatibility with
134 // pre-nautilus OSDs, which do not authenticate the heartbeat sessions.
135 bool get_require_authorizer() const {
136 return require_authorizer
;
138 void set_require_authorizer(bool r
) {
139 require_authorizer
= r
;
142 create(const entity_name_t
& name
,
143 const std::string
& lname
,
144 const uint64_t nonce
);
147 inline std::ostream
& operator<<(std::ostream
& out
, const Messenger
& msgr
) {
154 } // namespace crimson::net