handshaker.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_TRANSPORT_HANDSHAKER_H
20 #define GRPC_CORE_LIB_TRANSPORT_HANDSHAKER_H
21 
23 
24 #include <stddef.h>
25 
26 #include "absl/container/inlined_vector.h"
27 
29 #include <grpc/slice.h>
30 
40 
41 namespace grpc_core {
42 
49 
65  grpc_endpoint* endpoint = nullptr;
66  grpc_channel_args* args = nullptr;
68  // A handshaker may set this to true before invoking on_handshake_done
69  // to indicate that subsequent handshakers should be skipped.
70  bool exit_early = false;
71  // User data passed through the handshake manager. Not used by
72  // individual handshakers.
73  void* user_data = nullptr;
74  // Deadline associated with the handshake.
75  // TODO(anramach): Move this out of handshake args after event engine
76  // is the default.
78 };
79 
83 
84 class Handshaker : public RefCounted<Handshaker> {
85  public:
86  ~Handshaker() override = default;
87  virtual void Shutdown(grpc_error_handle why) = 0;
88  virtual void DoHandshake(grpc_tcp_server_acceptor* acceptor,
90  HandshakerArgs* args) = 0;
91  virtual const char* name() const = 0;
92 };
93 
94 //
95 // HandshakeManager
96 //
97 
98 class HandshakeManager : public RefCounted<HandshakeManager> {
99  public:
101  ~HandshakeManager() override;
102 
105  void Add(RefCountedPtr<Handshaker> handshaker);
106 
109  void Shutdown(grpc_error_handle why);
110 
123  void DoHandshake(grpc_endpoint* endpoint,
124  const grpc_channel_args* channel_args, Timestamp deadline,
125  grpc_tcp_server_acceptor* acceptor,
126  grpc_iomgr_cb_func on_handshake_done, void* user_data);
127 
128  private:
130 
131  // A function used as the handshaker-done callback when chaining
132  // handshakers together.
133  static void CallNextHandshakerFn(void* arg, grpc_error_handle error);
134 
135  // Callback invoked when deadline is exceeded.
136  static void OnTimeoutFn(void* arg, grpc_error_handle error);
137 
138  static const size_t HANDSHAKERS_INIT_SIZE = 2;
139 
141  bool is_shutdown_ = false;
142  // An array of handshakers added via grpc_handshake_manager_add().
145  // The index of the handshaker to invoke next and closure to invoke it.
146  size_t index_ = 0;
148  // The acceptor to call the handshakers with.
150  // Deadline timer across all handshakers.
153  // The final callback and user_data to invoke after the last handshaker.
155  // Handshaker args.
157 };
158 
159 } // namespace grpc_core
160 
161 // TODO(arjunroy): These are transitional to account for the new handshaker API
162 // and will eventually be removed entirely.
166  grpc_handshaker* handshaker);
167 
168 #endif /* GRPC_CORE_LIB_TRANSPORT_HANDSHAKER_H */
grpc_core::HandshakeManager::handshakers_
absl::InlinedVector< RefCountedPtr< Handshaker >, HANDSHAKERS_INIT_SIZE > handshakers_
Definition: handshaker.h:144
grpc_core::Handshaker::name
virtual const char * name() const =0
slice.h
grpc_core::HandshakerArgs::deadline
Timestamp deadline
Definition: handshaker.h:77
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::HandshakeManager::OnTimeoutFn
static void OnTimeoutFn(void *arg, grpc_error_handle error)
Definition: src/core/lib/transport/handshaker.cc:166
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::HandshakerArgs::args
grpc_channel_args * args
Definition: handshaker.h:66
closure.h
grpc_core::HandshakeManager::on_handshake_done_
grpc_closure on_handshake_done_
Definition: handshaker.h:154
grpc_core::Handshaker::~Handshaker
~Handshaker() override=default
grpc_timer
Definition: iomgr/timer.h:33
grpc_channel_args
Definition: grpc_types.h:132
grpc_handshake_manager
grpc_core::HandshakeManager grpc_handshake_manager
Definition: handshaker.h:163
grpc_core::HandshakeManager::is_shutdown_
bool is_shutdown_
Definition: handshaker.h:141
grpc_core::HandshakeManager::acceptor_
grpc_tcp_server_acceptor * acceptor_
Definition: handshaker.h:149
grpc_core::HandshakeManager::on_timeout_
grpc_closure on_timeout_
Definition: handshaker.h:152
grpc_core::Handshaker
Definition: handshaker.h:84
grpc_core::HandshakeManager::call_next_handshaker_
grpc_closure call_next_handshaker_
Definition: handshaker.h:147
grpc_types.h
grpc_core::HandshakeManager::mu_
Mutex mu_
Definition: handshaker.h:140
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::HandshakeManager::~HandshakeManager
~HandshakeManager() override
Definition: src/core/lib/transport/handshaker.cc:74
grpc_core::HandshakerArgs::exit_early
bool exit_early
Definition: handshaker.h:70
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::Handshaker::DoHandshake
virtual void DoHandshake(grpc_tcp_server_acceptor *acceptor, grpc_closure *on_handshake_done, HandshakerArgs *args)=0
grpc_handshaker
grpc_core::Handshaker grpc_handshaker
Definition: handshaker.h:164
grpc_core::HandshakeManager::index_
size_t index_
Definition: handshaker.h:146
grpc_core::HandshakeManager::HANDSHAKERS_INIT_SIZE
static const size_t HANDSHAKERS_INIT_SIZE
Definition: handshaker.h:138
arg
Definition: cmdline.cc:40
grpc_core::HandshakeManager::Add
void Add(RefCountedPtr< Handshaker > handshaker)
Definition: src/core/lib/transport/handshaker.cc:63
time.h
grpc_core::HandshakeManager::args_
HandshakerArgs args_
Definition: handshaker.h:156
error.h
grpc_core::Handshaker::Shutdown
virtual void Shutdown(grpc_error_handle why)=0
grpc_core::HandshakeManager::CallNextHandshakerFn
static void CallNextHandshakerFn(void *arg, grpc_error_handle error)
Definition: src/core/lib/transport/handshaker.cc:150
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::HandshakeManager::DoHandshake
void DoHandshake(grpc_endpoint *endpoint, const grpc_channel_args *channel_args, Timestamp deadline, grpc_tcp_server_acceptor *acceptor, grpc_iomgr_cb_func on_handshake_done, void *user_data)
Definition: src/core/lib/transport/handshaker.cc:174
grpc_core::HandshakerArgs::read_buffer
grpc_slice_buffer * read_buffer
Definition: handshaker.h:67
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_core::HandshakeManager::HandshakeManager
HandshakeManager()
Definition: src/core/lib/transport/handshaker.cc:61
grpc_core::HandshakerArgs::endpoint
grpc_endpoint * endpoint
Definition: handshaker.h:65
ref_counted.h
grpc_tcp_server_acceptor
Definition: tcp_server.h:36
grpc_iomgr_cb_func
void(* grpc_iomgr_cb_func)(void *arg, grpc_error_handle error)
Definition: closure.h:53
grpc_core::HandshakeManager::Shutdown
void Shutdown(grpc_error_handle why)
Definition: src/core/lib/transport/handshaker.cc:76
ref_counted_ptr.h
timer.h
grpc_core::HandshakerArgs
Definition: handshaker.h:64
grpc_slice_buffer
Definition: include/grpc/impl/codegen/slice.h:83
grpc_core::HandshakeManager
Definition: handshaker.h:98
absl::InlinedVector
Definition: abseil-cpp/absl/container/inlined_vector.h:69
endpoint.h
grpc_core::HandshakerArgs::user_data
void * user_data
Definition: handshaker.h:73
grpc_error
Definition: error_internal.h:42
tcp_server.h
grpc_core::HandshakeManager::CallNextHandshakerLocked
bool CallNextHandshakerLocked(grpc_error_handle error)
Definition: src/core/lib/transport/handshaker.cc:91
grpc_closure
Definition: closure.h:56
grpc_endpoint
Definition: endpoint.h:105
on_handshake_done
static void on_handshake_done(void *arg, grpc_error_handle error)
Definition: ssl_server_fuzzer.cc:45
grpc_handshake_manager_add
void grpc_handshake_manager_add(grpc_handshake_manager *mgr, grpc_handshaker *handshaker)
Definition: src/core/lib/transport/handshaker.cc:221
sync.h
grpc_core::HandshakeManager::deadline_timer_
grpc_timer deadline_timer_
Definition: handshaker.h:151
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:10