Update ccapi to 7.9.3 (compatible w/ new boost)
This commit is contained in:
1 parent
bd7ccb5f44
commit
9fa7a9898e
117 files changed
+9016
-11255
No files matched your search
@@ -1,80 +1,15 @@
|
||||
#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_
|
||||
#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_
|
||||
#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
#include "websocketpp/client.hpp"
|
||||
#include "websocketpp/common/connection_hdl.hpp"
|
||||
#include "websocketpp/config/asio_client.hpp"
|
||||
#include "websocketpp/config/boost_config.hpp"
|
||||
namespace wspp = websocketpp;
|
||||
namespace ccapi {
|
||||
/**
|
||||
* Defines the service that the service depends on.
|
||||
*/
|
||||
class ServiceContext CCAPI_FINAL {
|
||||
public:
|
||||
typedef wspp::lib::asio::io_service IoContext;
|
||||
typedef wspp::lib::shared_ptr<wspp::lib::asio::io_service> IoContextPtr;
|
||||
struct CustomClientConfig : public wspp::config::asio_tls_client {
|
||||
#ifdef CCAPI_USE_SINGLE_THREAD
|
||||
typedef wspp::config::asio_tls_client base;
|
||||
static bool const enable_multithreading = false;
|
||||
struct transport_config : public base::transport_config {
|
||||
static bool const enable_multithreading = false;
|
||||
};
|
||||
#endif
|
||||
#ifdef CCAPI_WEBSOCKET_READ_BUFFER_SIZE
|
||||
static const size_t connection_read_buffer_size = CCAPI_WEBSOCKET_READ_BUFFER_SIZE;
|
||||
#endif
|
||||
static const wspp::log::level alog_level = wspp::log::alevel::none;
|
||||
static const wspp::log::level elog_level = wspp::log::elevel::none;
|
||||
};
|
||||
typedef wspp::client<CustomClientConfig> TlsClient;
|
||||
typedef wspp::lib::shared_ptr<wspp::client<CustomClientConfig> > TlsClientPtr;
|
||||
typedef wspp::lib::error_code ErrorCode;
|
||||
typedef wspp::lib::asio::ssl::context SslContext;
|
||||
typedef wspp::lib::shared_ptr<SslContext> SslContextPtr;
|
||||
ServiceContext() {
|
||||
this->tlsClientPtr->set_access_channels(websocketpp::log::alevel::none);
|
||||
this->tlsClientPtr->set_error_channels(websocketpp::log::elevel::none);
|
||||
ErrorCode ec;
|
||||
CCAPI_LOGGER_DEBUG("asio initialization start");
|
||||
this->tlsClientPtr->init_asio(this->ioContextPtr.get(), ec);
|
||||
if (ec) {
|
||||
CCAPI_LOGGER_FATAL("asio initialization error: " + ec.message());
|
||||
}
|
||||
CCAPI_LOGGER_DEBUG("asio initialization end");
|
||||
this->sslContextPtr->set_options(SslContext::default_workarounds | SslContext::no_sslv2 | SslContext::no_sslv3 | SslContext::single_dh_use);
|
||||
this->sslContextPtr->set_verify_mode(wspp::lib::asio::ssl::verify_none);
|
||||
// TODO(cryptochassis): verify ssl certificate to strengthen security
|
||||
// https://github.com/boostorg/asio/blob/develop/example/cpp03/ssl/client.cpp
|
||||
}
|
||||
ServiceContext(const ServiceContext&) = delete;
|
||||
ServiceContext& operator=(const ServiceContext&) = delete;
|
||||
void start() {
|
||||
CCAPI_LOGGER_INFO("about to start client asio io_service run loop");
|
||||
this->tlsClientPtr->start_perpetual();
|
||||
this->tlsClientPtr->run();
|
||||
CCAPI_LOGGER_INFO("just exited client asio io_service run loop");
|
||||
}
|
||||
void stop() {
|
||||
this->ioContextPtr->stop();
|
||||
this->tlsClientPtr->stop();
|
||||
this->tlsClientPtr->stop_perpetual();
|
||||
}
|
||||
IoContextPtr ioContextPtr{new IoContext()};
|
||||
TlsClientPtr tlsClientPtr{new TlsClient()};
|
||||
SslContextPtr sslContextPtr{new SslContext(SslContext::tls_client)};
|
||||
};
|
||||
|
||||
} /* namespace ccapi */
|
||||
#else
|
||||
#include "boost/asio/ssl.hpp"
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
|
||||
namespace ccapi {
|
||||
|
||||
/**
|
||||
* Defines the service that the service depends on.
|
||||
*/
|
||||
class ServiceContext CCAPI_FINAL {
|
||||
class ServiceContext {
|
||||
public:
|
||||
typedef boost::asio::io_context IoContext;
|
||||
typedef boost::asio::io_context* IoContextPtr;
|
||||
@@ -82,10 +17,13 @@ class ServiceContext CCAPI_FINAL {
|
||||
typedef ExecutorWorkGuard* ExecutorWorkGuardPtr;
|
||||
typedef boost::asio::ssl::context SslContext;
|
||||
typedef SslContext* SslContextPtr;
|
||||
|
||||
ServiceContext() {
|
||||
this->ioContextPtr = new boost::asio::io_context();
|
||||
this->useInternalIoContextPtr = true;
|
||||
this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor());
|
||||
this->sslContextPtr = new SslContext(SslContext::tls_client);
|
||||
this->useInternalSslContextPtr = true;
|
||||
// this->sslContextPtr->set_options(SslContext::default_workarounds | SslContext::no_sslv2 | SslContext::no_sslv3 | SslContext::single_dh_use);
|
||||
this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none);
|
||||
// TODO(cryptochassis): verify ssl certificate to strengthen security
|
||||
@@ -96,14 +34,18 @@ class ServiceContext CCAPI_FINAL {
|
||||
this->ioContextPtr = ioContextPtr;
|
||||
this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor());
|
||||
this->sslContextPtr = new SslContext(SslContext::tls_client);
|
||||
this->useInternalSslContextPtr = true;
|
||||
this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none);
|
||||
}
|
||||
|
||||
ServiceContext(SslContextPtr sslContextPtr) {
|
||||
this->ioContextPtr = new boost::asio::io_context();
|
||||
this->useInternalIoContextPtr = true;
|
||||
this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor());
|
||||
this->sslContextPtr = sslContextPtr;
|
||||
this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none);
|
||||
}
|
||||
|
||||
ServiceContext(IoContextPtr ioContextPtr, SslContextPtr sslContextPtr) {
|
||||
this->ioContextPtr = ioContextPtr;
|
||||
this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor());
|
||||
@@ -113,29 +55,44 @@ class ServiceContext CCAPI_FINAL {
|
||||
#endif
|
||||
ServiceContext(const ServiceContext&) = delete;
|
||||
ServiceContext& operator=(const ServiceContext&) = delete;
|
||||
|
||||
virtual ~ServiceContext() {
|
||||
delete this->executorWorkGuardPtr;
|
||||
delete this->ioContextPtr;
|
||||
delete this->sslContextPtr;
|
||||
if (this->useInternalIoContextPtr) {
|
||||
delete this->ioContextPtr;
|
||||
}
|
||||
if (this->useInternalSslContextPtr) {
|
||||
delete this->sslContextPtr;
|
||||
}
|
||||
}
|
||||
|
||||
void start() {
|
||||
CCAPI_LOGGER_INFO("about to start client asio io_context run loop");
|
||||
this->ioContextPtr->run();
|
||||
CCAPI_LOGGER_INFO("just exited client asio io_context run loop");
|
||||
if (this->useInternalIoContextPtr) {
|
||||
std::thread thread([this]() {
|
||||
CCAPI_LOGGER_INFO("about to start asio io_context run loop");
|
||||
this->ioContextPtr->run();
|
||||
CCAPI_LOGGER_INFO("just exited asio io_context run loop");
|
||||
});
|
||||
this->thread = std::move(thread);
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
this->executorWorkGuardPtr->reset();
|
||||
this->ioContextPtr->stop();
|
||||
if (this->useInternalIoContextPtr) {
|
||||
this->ioContextPtr->stop();
|
||||
this->thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
IoContextPtr ioContextPtr{nullptr};
|
||||
bool useInternalIoContextPtr{};
|
||||
ExecutorWorkGuardPtr executorWorkGuardPtr{nullptr};
|
||||
SslContextPtr sslContextPtr{nullptr};
|
||||
// IoContextPtr ioContextPtr{new IoContext()};
|
||||
// ExecutorWorkGuardPtr executorWorkGuardPtr{new ExecutorWorkGuard(ioContextPtr->get_executor())};
|
||||
// SslContextPtr sslContextPtr{new SslContext(SslContext::tls_client)};
|
||||
bool useInternalSslContextPtr{};
|
||||
std::thread thread;
|
||||
};
|
||||
|
||||
} /* namespace ccapi */
|
||||
|
||||
#endif
|
||||
#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_
|
||||
Reference in new issue
Block a user