OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThriftClientConnection Class Reference

#include <ThriftClient.h>

+ Collaboration diagram for ThriftClientConnection:

Public Member Functions

 ThriftClientConnection (const std::string &server_host, const int port, const ThriftConnectionType conn_type, bool skip_host_verify, const std::string &ca_cert_name, const std::string &trust_cert_file)
 
 ThriftClientConnection (const std::string &server_host, const int port, const ThriftConnectionType conn_type, bool skip_host_verify, std::shared_ptr< TSSLSocketFactory > factory)
 
 ThriftClientConnection ()
 
std::shared_ptr< TTransport > open_buffered_client_transport (const std::string &server_host, const int port, const std::string &ca_cert_name, const bool with_timeout=false, const bool with_keepalive=true, const unsigned connect_timeout=0, const unsigned recv_timeount=0, const unsigned send_timeout=0)
 
std::shared_ptr< TTransport > open_http_client_transport (const std::string &server_host, const int port, const std::string &trust_cert_file_, bool use_https, bool skip_verify)
 
std::shared_ptr< TProtocol > get_protocol ()
 
virtual ~ThriftClientConnection ()
 

Private Attributes

std::string server_host_
 
int port_
 
ThriftConnectionType conn_type_
 
bool skip_host_verify_
 
std::string ca_cert_name_
 
std::string trust_cert_file_
 
bool using_X509_store_ = false
 
std::shared_ptr
< TSSLSocketFactory > 
factory_
 

Detailed Description

Definition at line 31 of file ThriftClient.h.

Constructor & Destructor Documentation

ThriftClientConnection::ThriftClientConnection ( const std::string &  server_host,
const int  port,
const ThriftConnectionType  conn_type,
bool  skip_host_verify,
const std::string &  ca_cert_name,
const std::string &  trust_cert_file 
)
inline

Definition at line 33 of file ThriftClient.h.

39  : server_host_(server_host)
40  , port_(port)
41  , conn_type_(conn_type)
42  , skip_host_verify_(skip_host_verify)
43  , ca_cert_name_(ca_cert_name)
44  , trust_cert_file_(trust_cert_file){};
ThriftConnectionType conn_type_
Definition: ThriftClient.h:77
std::string ca_cert_name_
Definition: ThriftClient.h:79
std::string trust_cert_file_
Definition: ThriftClient.h:80
std::string server_host_
Definition: ThriftClient.h:75
ThriftClientConnection::ThriftClientConnection ( const std::string &  server_host,
const int  port,
const ThriftConnectionType  conn_type,
bool  skip_host_verify,
std::shared_ptr< TSSLSocketFactory >  factory 
)

Definition at line 171 of file ThriftClient.cpp.

References BINARY_SSL, conn_type_, factory_, HTTPS, skip_host_verify_, and using_X509_store_.

176  : server_host_(server_host)
177  , port_(port)
178  , conn_type_(conn_type)
179  , skip_host_verify_(skip_host_verify)
180  , trust_cert_file_("") {
181  if (factory && (conn_type_ == ThriftConnectionType::BINARY_SSL ||
183  using_X509_store_ = true;
184  factory_ = factory;
185  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
186  if (skip_host_verify_) {
187  factory_->access(
188  std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
189  }
190  }
191 }
ThriftConnectionType conn_type_
Definition: ThriftClient.h:77
std::string trust_cert_file_
Definition: ThriftClient.h:80
std::string server_host_
Definition: ThriftClient.h:75
std::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:82
ThriftClientConnection::ThriftClientConnection ( )
inline

Definition at line 52 of file ThriftClient.h.

52 {};
ThriftClientConnection::~ThriftClientConnection ( )
virtual

Definition at line 170 of file ThriftClient.cpp.

170 {}

Member Function Documentation

std::shared_ptr< TProtocol > ThriftClientConnection::get_protocol ( )

Definition at line 193 of file ThriftClient.cpp.

References ca_cert_name_, conn_type_, HTTP, HTTPS, open_buffered_client_transport(), open_http_client_transport(), port_, server_host_, skip_host_verify_, and to_string().

Referenced by RowToColumnLoader::createConnection().

193  {
194  std::shared_ptr<apache::thrift::transport::TTransport> mytransport;
198  port_,
202 
203  } else {
205  }
206 
207  try {
208  mytransport->open();
209  } catch (const apache::thrift::TException& e) {
210  throw apache::thrift::TException(std::string(e.what()) + ": host " + server_host_ +
211  ", port " + std::to_string(port_));
212  }
215  return std::shared_ptr<TProtocol>(new TJSONProtocol(mytransport));
216  } else {
217  return std::shared_ptr<TProtocol>(new TBinaryProtocol(mytransport));
218  }
219 }
ThriftConnectionType conn_type_
Definition: ThriftClient.h:77
std::shared_ptr< TTransport > open_http_client_transport(const std::string &server_host, const int port, const std::string &trust_cert_file_, bool use_https, bool skip_verify)
std::string to_string(char const *&&v)
std::shared_ptr< TTransport > open_buffered_client_transport(const std::string &server_host, const int port, const std::string &ca_cert_name, const bool with_timeout=false, const bool with_keepalive=true, const unsigned connect_timeout=0, const unsigned recv_timeount=0, const unsigned send_timeout=0)
std::string ca_cert_name_
Definition: ThriftClient.h:79
std::string server_host_
Definition: ThriftClient.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< TTransport > ThriftClientConnection::open_buffered_client_transport ( const std::string &  server_host,
const int  port,
const std::string &  ca_cert_name,
const bool  with_timeout = false,
const bool  with_keepalive = true,
const unsigned  connect_timeout = 0,
const unsigned  recv_timeount = 0,
const unsigned  send_timeout = 0 
)

Definition at line 221 of file ThriftClient.cpp.

References shared::default_tconfig(), factory_, and using_X509_store_.

Referenced by get_protocol().

229  {
230  std::shared_ptr<TTransport> transport;
231 
232  if (!factory_ && !ca_cert_name.empty()) {
233  // need to build a factory once for ssl conection
234  factory_ =
235  std::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
236  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
237  factory_->loadTrustedCertificates(ca_cert_name.c_str());
238  factory_->authenticate(false);
239  factory_->access(std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
240  }
241  if (!using_X509_store_ && ca_cert_name.empty()) {
242 #ifdef HAVE_THRIFT_MESSAGE_LIMIT
243  const auto socket =
244  std::make_shared<TSocket>(server_host, port, shared::default_tconfig());
245 #else
246  const auto socket = std::make_shared<TSocket>(server_host, port);
247 #endif
248  if (with_timeout) {
249  socket->setKeepAlive(with_keepalive);
250  socket->setConnTimeout(connect_timeout);
251  socket->setRecvTimeout(recv_timeout);
252  socket->setSendTimeout(send_timeout);
253 #ifdef __APPLE__
254  socket->setLinger(false, 0);
255 #endif
256  }
257 #ifdef HAVE_THRIFT_MESSAGE_LIMIT
258  transport = std::make_shared<TBufferedTransport>(socket, shared::default_tconfig());
259 #else
260  transport = std::make_shared<TBufferedTransport>(socket);
261 #endif
262  } else {
263  std::shared_ptr<TSocket> secure_socket = factory_->createSocket(server_host, port);
264  if (with_timeout) {
265  secure_socket->setKeepAlive(with_keepalive);
266  secure_socket->setConnTimeout(connect_timeout);
267  secure_socket->setRecvTimeout(recv_timeout);
268  secure_socket->setSendTimeout(send_timeout);
269 #ifdef __APPLE__
270  secure_socket->setLinger(false, 0);
271 #endif
272  }
273 #ifdef HAVE_THRIFT_MESSAGE_LIMIT
274  transport = std::shared_ptr<TTransport>(
275  new TBufferedTransport(secure_socket, shared::default_tconfig()));
276 #else
277  transport = std::shared_ptr<TTransport>(new TBufferedTransport(secure_socket));
278 #endif
279  }
280 
281  return transport;
282 }
unsigned connect_timeout
unsigned send_timeout
std::shared_ptr< apache::thrift::TConfiguration > default_tconfig()
Definition: ThriftConfig.h:26
bool with_keepalive
unsigned recv_timeout
std::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:82

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< TTransport > ThriftClientConnection::open_http_client_transport ( const std::string &  server_host,
const int  port,
const std::string &  trust_cert_file_,
bool  use_https,
bool  skip_verify 
)

Definition at line 284 of file ThriftClient.cpp.

References check_standard_ca(), factory_, trust_cert_file_, and using_X509_store_.

Referenced by get_protocol().

289  {
290  trust_cert_file_ = trust_cert_fileX;
292 
293  if (!factory_) {
294  factory_ =
295  std::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
296  }
297  std::shared_ptr<TTransport> transport;
298  std::shared_ptr<TTransport> socket;
299  if (use_https) {
300  if (skip_verify) {
301  factory_->authenticate(false);
302  factory_->access(
303  std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
304  }
305  if (!using_X509_store_) {
306  factory_->loadTrustedCertificates(trust_cert_file_.c_str());
307  }
308  socket = factory_->createSocket(server_host, port);
309  // transport = std::shared_ptr<TTransport>(new THttpClient(socket,
310  // server_host,
311  // "/"));
312  transport =
313  std::shared_ptr<TTransport>(new ProxyTHttpClient(socket, server_host, "/"));
314  } else {
315  transport = std::shared_ptr<TTransport>(new ProxyTHttpClient(server_host, port, "/"));
316  }
317  return transport;
318 }
void check_standard_ca(std::string &ca_cert_file)
std::string trust_cert_file_
Definition: ThriftClient.h:80
std::shared_ptr< TSSLSocketFactory > factory_
Definition: ThriftClient.h:82

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::string ThriftClientConnection::ca_cert_name_
private

Definition at line 79 of file ThriftClient.h.

Referenced by get_protocol().

ThriftConnectionType ThriftClientConnection::conn_type_
private

Definition at line 77 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

std::shared_ptr<TSSLSocketFactory> ThriftClientConnection::factory_
private
int ThriftClientConnection::port_
private

Definition at line 76 of file ThriftClient.h.

Referenced by get_protocol().

std::string ThriftClientConnection::server_host_
private

Definition at line 75 of file ThriftClient.h.

Referenced by get_protocol().

bool ThriftClientConnection::skip_host_verify_
private

Definition at line 78 of file ThriftClient.h.

Referenced by get_protocol(), and ThriftClientConnection().

std::string ThriftClientConnection::trust_cert_file_
private

Definition at line 80 of file ThriftClient.h.

Referenced by open_http_client_transport().

bool ThriftClientConnection::using_X509_store_ = false
private

The documentation for this class was generated from the following files: