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_SRC_CORE_HANDSHAKER_HANDSHAKER_FACTORY_H 20 #define GRPC_SRC_CORE_HANDSHAKER_HANDSHAKER_FACTORY_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include "src/core/lib/channel/channel_args.h" 25 #include "src/core/lib/iomgr/iomgr_fwd.h" 26 27 // A handshaker factory is used to create handshakers. 28 29 // TODO(ctiller): HandshakeManager is forward declared in this file. When 30 // EventEngine lands IO support we ought to be able to include 31 // handshake_manager.h here and eliminate the HandshakeManager dependency - we 32 // cannot right now because HandshakeManager names too many iomgr types. 33 34 namespace grpc_core { 35 36 class HandshakeManager; 37 38 class HandshakerFactory { 39 public: 40 // Enum representing the priority of the handshakers. 41 // The order of the handshakers is decided by the priority. 42 // For example kPreTCPConnect handshakers are called before kTCPConnect and so 43 // on. 44 enum class HandshakerPriority : int { 45 // Handshakers that should be called before a TCP connect. Applicable mainly 46 // for Client handshakers. 47 kPreTCPConnectHandshakers, 48 // Handshakers responsible for the actual TCP connect establishment. 49 // Applicable mainly for Client handshakers. 50 kTCPConnectHandshakers, 51 // Handshakers responsible for the actual HTTP connect established. 52 // Applicable mainly for Client handshakers. 53 kHTTPConnectHandshakers, 54 // Handshakers that should be called before security handshakes but after 55 // connect establishment. Applicable mainly for Server handshakers 56 // currently. 57 kReadAheadSecurityHandshakers, 58 // Handshakers that are responsible for post connect security handshakes. 59 // Applicable for both Client and Server handshakers. 60 kSecurityHandshakers, 61 // TEMPORARY HACK -- DO NOT USE 62 // Currently, handshakers that need to hijack the endpoint's fd and 63 // exit early (which generally run at priority kSecurityHandshakers) 64 // need to call grpc_tcp_destroy_and_release_fd(), which asserts 65 // that the endpoint is an iomgr endpoint. If another handshaker 66 // has wrapped the endpoint before then, this assertion fails. So 67 // for now, we introduce a new priority here for handshakers that 68 // need to wrap the endpoint, to make sure that they run after 69 // handshakers that hijack the fd and exit early. 70 // TODO(hork): As part of migrating to the EventEngine endpoint API, 71 // remove this priority. In the EE API, handshakers that want to 72 // hijack the fd will do so via the query interface, so we can just 73 // have any wrapper endpoints forward query interfaces to the wrapped 74 // endpoint, so that it's not a problem if the endpoint is wrapped 75 // before a handshaker needs to hijack the fd. 76 kTemporaryHackDoNotUseEndpointWrappingHandshakers, 77 }; 78 79 virtual void AddHandshakers(const ChannelArgs& args, 80 grpc_pollset_set* interested_parties, 81 HandshakeManager* handshake_mgr) = 0; 82 // Return the priority associated with the handshaker. 83 virtual HandshakerPriority Priority() = 0; 84 virtual ~HandshakerFactory() = default; 85 }; 86 87 } // namespace grpc_core 88 89 #endif // GRPC_SRC_CORE_HANDSHAKER_HANDSHAKER_FACTORY_H 90