proxygen
BaseClientBootstrap.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 <folly/SocketAddress.h>
19 #include <folly/futures/Future.h>
23 #include <memory>
24 
25 namespace wangle {
26 
27 
29  public:
30  virtual ~SSLSessionEstablishedCallback() = default;
31  // notified when a non-reused SSL_SESSION is established.
32  virtual void onEstablished(SSL_SESSION* session) = 0;
33 };
34 
36  std::unique_ptr<SSLSessionEstablishedCallback>;
37 
38 /*
39  * A wrapper template around Pipeline and AsyncSocket or SPDY/HTTP/2 session to
40  * match ServerBootstrap so BroadcastPool can work with either option
41  */
42 template <typename P = DefaultPipeline>
44  public:
45  using Ptr = std::unique_ptr<BaseClientBootstrap>;
47 
48  virtual ~BaseClientBootstrap() = default;
49 
51  std::shared_ptr<PipelineFactory<P>> factory) noexcept {
52  pipelineFactory_ = factory;
53  return this;
54  }
55 
56  P* getPipeline() {
57  return pipeline_.get();
58  }
59 
60  virtual folly::Future<P*> connect(
61  const folly::SocketAddress& address,
62  std::chrono::milliseconds timeout =
63  std::chrono::milliseconds(0)) = 0;
64 
66  sslContext_ = sslContext;
67  return this;
68  }
69 
70  BaseClientBootstrap* sslSession(SSL_SESSION* sslSession) {
71  sslSession_ = sslSession;
72  return this;
73  }
74 
76  sni_ = sni;
77  return this;
78  }
79 
81  SSLSessionEstablishedCallbackUniquePtr sslSessionEstablishedCallback) {
82  sslSessionEstablishedCallback_ = std::move(sslSessionEstablishedCallback);
83  return this;
84  }
85 
86  BaseClientBootstrap* deferSecurityNegotiation(bool deferSecurityNegotiation) {
87  deferSecurityNegotiation_ = deferSecurityNegotiation;
88  return this;
89  }
90 
91  void setPipeline(const typename P::Ptr& pipeline) {
92  pipeline_ = pipeline;
93  }
94 
95  virtual void makePipeline(
96  std::shared_ptr<folly::AsyncTransportWrapper> socket) {
97  pipeline_ = pipelineFactory_->newPipeline(socket);
98  }
99 
100  protected:
101  std::shared_ptr<PipelineFactory<P>> pipelineFactory_;
102  typename P::Ptr pipeline_;
104  SSL_SESSION* sslSession_{nullptr};
106  bool deferSecurityNegotiation_{false};
108 };
109 
110 template <typename ClientBootstrap = BaseClientBootstrap<>>
112  public:
113  virtual typename ClientBootstrap::Ptr newClient() = 0;
114  virtual ~BaseClientBootstrapFactory() = default;
115 };
116 
117 } // namespace wangle
std::unique_ptr< SSLSessionEstablishedCallback > SSLSessionEstablishedCallbackUniquePtr
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
BaseClientBootstrap * sslSessionEstablishedCallback(SSLSessionEstablishedCallbackUniquePtr sslSessionEstablishedCallback)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void onEstablished(SSL_SESSION *session)=0
requires E e noexcept(noexcept(s.error(std::move(e))))
BaseClientBootstrap * deferSecurityNegotiation(bool deferSecurityNegotiation)
folly::SSLContextPtr sslContext_
BaseClientBootstrap * serverName(const std::string &sni)
Optional< std::string > sni_
std::shared_ptr< SSLContext > SSLContextPtr
Definition: SSLContext.h:628
BaseClientBootstrap * sslContext(folly::SSLContextPtr sslContext)
std::shared_ptr< PipelineFactory< P > > pipelineFactory_
BaseClientBootstrap< P > * pipelineFactory(std::shared_ptr< PipelineFactory< P >> factory) noexcept
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
StringPiece sni
BaseClientBootstrap * sslSession(SSL_SESSION *sslSession)
const char * string
Definition: Conv.cpp:212
virtual void makePipeline(std::shared_ptr< folly::AsyncTransportWrapper > socket)
virtual ~SSLSessionEstablishedCallback()=default
std::unique_ptr< BaseClientBootstrap > Ptr
SSLSessionEstablishedCallbackUniquePtr sslSessionEstablishedCallback_
void setPipeline(const typename P::Ptr &pipeline)