OmniSciDB  a5dc49c757
 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 170 of file ThriftClient.cpp.

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

175  : server_host_(server_host)
176  , port_(port)
177  , conn_type_(conn_type)
178  , skip_host_verify_(skip_host_verify)
179  , trust_cert_file_("") {
180  if (factory && (conn_type_ == ThriftConnectionType::BINARY_SSL ||
182  using_X509_store_ = true;
183  factory_ = factory;
184  factory_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
185  if (skip_host_verify_) {
186  factory_->access(
187  std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
188  }
189  }
190 }
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 169 of file ThriftClient.cpp.

169 {}

Member Function Documentation

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

Definition at line 192 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().

192  {
193  std::shared_ptr<apache::thrift::transport::TTransport> mytransport;
197  port_,
201 
202  } else {
204  }
205 
206  try {
207  mytransport->open();
208  } catch (const apache::thrift::TException& e) {
209  throw apache::thrift::TException(std::string(e.what()) + ": host " + server_host_ +
210  ", port " + std::to_string(port_));
211  }
214  return std::shared_ptr<TProtocol>(new TJSONProtocol(mytransport));
215  } else {
216  return std::shared_ptr<TProtocol>(new TBinaryProtocol(mytransport));
217  }
218 }
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 220 of file ThriftClient.cpp.

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

Referenced by get_protocol().

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

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

Referenced by get_protocol().

288  {
289  trust_cert_file_ = trust_cert_fileX;
291 
292  if (!factory_) {
293  factory_ =
294  std::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory(SSLProtocol::SSLTLS));
295  }
296  std::shared_ptr<TTransport> transport;
297  std::shared_ptr<TTransport> socket;
298  if (use_https) {
299  if (skip_verify) {
300  factory_->authenticate(false);
301  factory_->access(
302  std::shared_ptr<InsecureAccessManager>(new InsecureAccessManager()));
303  }
304  if (!using_X509_store_) {
305  factory_->loadTrustedCertificates(trust_cert_file_.c_str());
306  }
307  socket = factory_->createSocket(server_host, port);
308  // transport = std::shared_ptr<TTransport>(new THttpClient(socket,
309  // server_host,
310  // "/"));
311  transport =
312  std::shared_ptr<TTransport>(new ProxyTHttpClient(socket, server_host, "/"));
313  } else {
314  transport = std::shared_ptr<TTransport>(new ProxyTHttpClient(server_host, port, "/"));
315  }
316  return transport;
317 }
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: