proxygen
AcceptorHandshakeManager.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <chrono>
19 #include <folly/ExceptionWrapper.h>
20 #include <folly/Optional.h>
21 #include <folly/SocketAddress.h>
27 
28 namespace wangle {
29 
30 class Acceptor;
31 
33  public:
34  using UniquePtr = std::unique_ptr<
36 
37  class Callback {
38  public:
39  virtual ~Callback() = default;
40 
46  virtual void connectionReady(
48  std::string nextProtocol,
49  SecureTransportType secureTransportType,
51 
57  virtual void connectionError(
60  folly::Optional<SSLErrorEnum> sslErr) noexcept = 0;
61  };
62 
63  virtual void start(
66 
67  virtual void dropConnection(SSLErrorEnum reason = SSLErrorEnum::NO_ERROR) = 0;
68 };
69 
72  public:
74  Acceptor* acceptor,
75  const folly::SocketAddress& clientAddr,
76  std::chrono::steady_clock::time_point acceptTime,
77  TransportInfo tinfo) :
78  acceptor_(acceptor),
79  clientAddr_(clientAddr),
80  acceptTime_(acceptTime),
81  tinfo_(std::move(tinfo)) {}
82 
83  ~AcceptorHandshakeManager() override = default;
84 
86 
87  void timeoutExpired() noexcept override {
88  VLOG(4) << "SSL handshake timeout expired";
90  }
91 
92  void describe(std::ostream& os) const override {
93  os << "pending handshake on " << clientAddr_;
94  }
95 
96  bool isBusy() const override {
97  return true;
98  }
99 
100  void notifyPendingShutdown() override {}
101 
102  void closeWhenIdle() override {}
103 
104  void dropConnection() override {
106  }
107 
109  VLOG(10) << "Dropping in progress handshake for " << clientAddr_;
110  helper_->dropConnection(reason);
111  }
112 
113  void dumpConnectionState(uint8_t /* loglevel */) override {}
114 
115  protected:
116  void connectionReady(
118  std::string nextProtocol,
119  SecureTransportType secureTransportType,
121  details) noexcept override;
122 
123  void connectionError(
124  folly::AsyncTransportWrapper* transport,
127  details) noexcept override;
128 
129  std::chrono::milliseconds timeSinceAcceptMs() const;
130 
131  virtual void startHelper(folly::AsyncSSLSocket::UniquePtr sock) = 0;
132 
133  void startHandshakeTimeout();
134 
137  std::chrono::steady_clock::time_point acceptTime_;
140 };
141 
142 }
AcceptorHandshakeManager(Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo tinfo)
SSLErrorEnum
Definition: SSLUtil.h:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
void dropConnection(SSLErrorEnum reason)
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
FizzServerAcceptor * acceptor_
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
std::chrono::steady_clock::time_point acceptTime_
virtual void connectionReady(folly::AsyncTransportWrapper::UniquePtr transport, std::string nextProtocol, SecureTransportType secureTransportType, folly::Optional< SSLErrorEnum > sslErr) noexcept=0
virtual void dropConnection(SSLErrorEnum reason=SSLErrorEnum::NO_ERROR)=0
void describe(std::ostream &os) const override
virtual void connectionError(folly::AsyncTransportWrapper *transport, folly::exception_wrapper ex, folly::Optional< SSLErrorEnum > sslErr) noexcept=0
AcceptorHandshakeHelper::UniquePtr helper_
virtual void start(folly::AsyncSSLSocket::UniquePtr sock, AcceptorHandshakeHelper::Callback *callback) noexcept=0
const char * string
Definition: Conv.cpp:212
std::unique_ptr< AcceptorHandshakeHelper, folly::DelayedDestruction::Destructor > UniquePtr