From 94da6f2a8d4b39c28d53509146e9e90dccab7f78 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Wed, 22 Jul 2020 19:38:19 +0300 Subject: [PATCH 1/2] Connection::ConnectionContext::init(). Add better error message. --- src/oatpp-libressl/Connection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/oatpp-libressl/Connection.cpp b/src/oatpp-libressl/Connection.cpp index 1cdbc97..a5c4175 100644 --- a/src/oatpp-libressl/Connection.cpp +++ b/src/oatpp-libressl/Connection.cpp @@ -23,6 +23,7 @@ ***************************************************************************/ #include "Connection.hpp" +#include namespace oatpp { namespace libressl { @@ -65,7 +66,7 @@ void Connection::ConnectionContext::init() { tlsObject->annul(); if (res != 0) { - OATPP_LOGD("[oatpp::libressl::Connection::ConnectionContext::init()]", "Error on call to 'tls_connect_cbs'. res=%d", res); + OATPP_LOGD("[oatpp::libressl::Connection::ConnectionContext::init()]", "Error on call to 'tls_connect_cbs'. %s", tls_error(m_connection->m_tlsHandle)); } } else { From 0e6a04d5dc64dd125bc08ccf682b102b39480821 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Tue, 29 Sep 2020 04:41:51 +0300 Subject: [PATCH 2/2] Upgrade to the latest oatpp API. --- CMakeLists.txt | 2 +- .../client/ConnectionProvider.cpp | 26 ++++++++++------- .../client/ConnectionProvider.hpp | 20 +++++++------ .../server/ConnectionProvider.cpp | 29 ++++++++++++------- .../server/ConnectionProvider.hpp | 22 ++++++++------ test/oatpp-libressl/FullAsyncClientTest.cpp | 14 ++++----- test/oatpp-libressl/FullAsyncClientTest.hpp | 4 +-- test/oatpp-libressl/FullAsyncTest.cpp | 14 ++++----- test/oatpp-libressl/FullAsyncTest.hpp | 4 +-- test/oatpp-libressl/FullTest.cpp | 14 ++++----- test/oatpp-libressl/FullTest.hpp | 4 +-- 11 files changed, 86 insertions(+), 67 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fc533a..d90ac5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) ## use these variables to configure module installation set(OATPP_THIS_MODULE_NAME oatpp-libressl) ## name of the module (also name of folders in installation dirs) -set(OATPP_THIS_MODULE_VERSION "1.1.0") ## version of the module (also sufix of folders in installation dirs) +set(OATPP_THIS_MODULE_VERSION "1.2.0") ## version of the module (also sufix of folders in installation dirs) set(OATPP_THIS_MODULE_LIBRARIES oatpp-libressl) ## list of libraries to find when find_package is called set(OATPP_THIS_MODULE_TARGETS oatpp-libressl) ## list of targets to install set(OATPP_THIS_MODULE_DIRECTORIES oatpp-libressl) ## list of directories to install diff --git a/src/oatpp-libressl/client/ConnectionProvider.cpp b/src/oatpp-libressl/client/ConnectionProvider.cpp index b81859e..a6491b1 100644 --- a/src/oatpp-libressl/client/ConnectionProvider.cpp +++ b/src/oatpp-libressl/client/ConnectionProvider.cpp @@ -26,7 +26,7 @@ #include "oatpp-libressl/Connection.hpp" -#include "oatpp/network/client/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/tcp/client/ConnectionProvider.hpp" #include @@ -53,16 +53,22 @@ ConnectionProvider::ConnectionProvider(const std::shared_ptr& config, } std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, - const std::shared_ptr& streamProvider) { + const std::shared_ptr& streamProvider) +{ return std::shared_ptr(new ConnectionProvider(config, streamProvider)); } -std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, const oatpp::String& host, v_uint16 port) { - return createShared(config, oatpp::network::client::SimpleTCPConnectionProvider::createShared(host, port)); +std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, + const network::Address& address) +{ + return createShared( + config, + network::tcp::client::ConnectionProvider::createShared(address) + ); } -std::shared_ptr ConnectionProvider::getConnection(){ +std::shared_ptr ConnectionProvider::get() { Connection::TLSHandle tlsHandle = tls_client(); tls_configure(tlsHandle, m_config->getTLSConfig()); @@ -74,7 +80,7 @@ std::shared_ptr ConnectionProvider::getConnection } auto tlsObject = std::make_shared(tlsHandle, TLSObject::Type::CLIENT, host); - auto connection = std::make_shared(tlsObject, m_streamProvider->getConnection()); + auto connection = std::make_shared(tlsObject, m_streamProvider->get()); connection->setOutputStreamIOMode(oatpp::data::stream::IOMode::BLOCKING); connection->setInputStreamIOMode(oatpp::data::stream::IOMode::BLOCKING); @@ -84,7 +90,7 @@ std::shared_ptr ConnectionProvider::getConnection } -oatpp::async::CoroutineStarterForResult&> ConnectionProvider::getConnectionAsync() { +oatpp::async::CoroutineStarterForResult&> ConnectionProvider::getAsync() { class ConnectCoroutine : public oatpp::async::CoroutineWithResult&> { @@ -103,7 +109,7 @@ oatpp::async::CoroutineStarterForResultgetConnectionAsync().callbackTo(&ConnectCoroutine::onConnected); + return m_streamProvider->getAsync().callbackTo(&ConnectCoroutine::onConnected); } Action onConnected(const std::shared_ptr& stream) { @@ -144,7 +150,7 @@ oatpp::async::CoroutineStarterForResult& connection) { +void ConnectionProvider::invalidate(const std::shared_ptr& connection) { auto c = std::static_pointer_cast(connection); @@ -160,7 +166,7 @@ void ConnectionProvider::invalidateConnection(const std::shared_ptr& c /* Invalidate underlying transport */ auto s = c->getTransportStream(); - m_streamProvider->invalidateConnection(s); + m_streamProvider->invalidate(s); } diff --git a/src/oatpp-libressl/client/ConnectionProvider.hpp b/src/oatpp-libressl/client/ConnectionProvider.hpp index 0ad80c0..c41f2f0 100644 --- a/src/oatpp-libressl/client/ConnectionProvider.hpp +++ b/src/oatpp-libressl/client/ConnectionProvider.hpp @@ -28,6 +28,7 @@ #include "oatpp-libressl/Config.hpp" #include "oatpp-libressl/TLSObject.hpp" +#include "oatpp/network/Address.hpp" #include "oatpp/network/ConnectionProvider.hpp" namespace oatpp { namespace libressl { namespace client { @@ -61,19 +62,20 @@ class ConnectionProvider : public base::Countable, public oatpp::network::Client const std::shared_ptr& streamProvider); /** - * Create shared ConnectionProvider using &id:oatpp::network::client::SimpleTCPConnectionProvider; - * as a provider of underlying transport stream. + * Create shared ConnectionProvider. * @param config - &id:oatpp::libressl::Config;. - * @param host - host. - * @param port - port. + * @param address - &id:oatpp::network::Address;. + * @param useExtendedConnections - set `true` to use &l:ConnectionProvider::ExtendedConnection;. + * `false` to use &id:oatpp::network::tcp::Connection;. * @return - `std::shared_ptr` to ConnectionProvider. */ - static std::shared_ptr createShared(const std::shared_ptr& config, const oatpp::String& host, v_uint16 port); + static std::shared_ptr createShared(const std::shared_ptr& config, + const network::Address& address); /** * Implements &id:oatpp::network::ConnectionProvider::close;. Here does nothing. */ - void close() override { + void stop() override { // DO NOTHING } @@ -81,19 +83,19 @@ class ConnectionProvider : public base::Countable, public oatpp::network::Client * Get connection. * @return - `std::shared_ptr` to &id:oatpp::data::stream::IOStream;. */ - std::shared_ptr getConnection() override; + std::shared_ptr get() override; /** * Get connection in asynchronous manner. * @return - &id:oatpp::async::CoroutineStarterForResult;. */ - oatpp::async::CoroutineStarterForResult&> getConnectionAsync() override; + oatpp::async::CoroutineStarterForResult&> getAsync() override; /** * Will call `invalidateConnection()` for the underlying transport stream. * @param connection - **MUST** be an instance of &id:oatpp::libressl::Connection;. */ - void invalidateConnection(const std::shared_ptr& connection) override; + void invalidate(const std::shared_ptr& connection) override; }; diff --git a/src/oatpp-libressl/server/ConnectionProvider.cpp b/src/oatpp-libressl/server/ConnectionProvider.cpp index 6b7ae6e..24fa070 100644 --- a/src/oatpp-libressl/server/ConnectionProvider.cpp +++ b/src/oatpp-libressl/server/ConnectionProvider.cpp @@ -26,7 +26,7 @@ #include "oatpp-libressl/Connection.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include "oatpp/core/utils/ConversionUtils.hpp" namespace oatpp { namespace libressl { namespace server { @@ -46,16 +46,23 @@ ConnectionProvider::ConnectionProvider(const std::shared_ptr& config, } std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, - const std::shared_ptr& streamProvider){ + const std::shared_ptr& streamProvider) +{ return std::shared_ptr(new ConnectionProvider(config, streamProvider)); } -std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, v_uint16 port) { - return createShared(config, oatpp::network::server::SimpleTCPConnectionProvider::createShared(port)); +std::shared_ptr ConnectionProvider::createShared(const std::shared_ptr& config, + const network::Address& address, + bool useExtendedConnections) +{ + return createShared( + config, + network::tcp::server::ConnectionProvider::createShared(address, useExtendedConnections) + ); } ConnectionProvider::~ConnectionProvider() { - close(); + stop(); } std::shared_ptr ConnectionProvider::instantiateTLSServer() { @@ -75,25 +82,25 @@ std::shared_ptr ConnectionProvider::instantiateTLSServer() { } -void ConnectionProvider::close() { +void ConnectionProvider::stop() { if(!m_closed) { m_closed = true; if(m_tlsObject) { m_tlsObject->close(); } - m_streamProvider->close(); + m_streamProvider->stop(); } } -std::shared_ptr ConnectionProvider::getConnection(){ - auto transportStream = m_streamProvider->getConnection(); +std::shared_ptr ConnectionProvider::get(){ + auto transportStream = m_streamProvider->get(); if(transportStream) { return std::make_shared(m_tlsObject, transportStream); } return nullptr; } -void ConnectionProvider::invalidateConnection(const std::shared_ptr& connection) { +void ConnectionProvider::invalidate(const std::shared_ptr& connection) { auto c = std::static_pointer_cast(connection); @@ -109,7 +116,7 @@ void ConnectionProvider::invalidateConnection(const std::shared_ptr& c /* Invalidate underlying transport */ auto s = c->getTransportStream(); - m_streamProvider->invalidateConnection(s); + m_streamProvider->invalidate(s); } diff --git a/src/oatpp-libressl/server/ConnectionProvider.hpp b/src/oatpp-libressl/server/ConnectionProvider.hpp index d2d4ed2..af8f2c9 100644 --- a/src/oatpp-libressl/server/ConnectionProvider.hpp +++ b/src/oatpp-libressl/server/ConnectionProvider.hpp @@ -28,7 +28,8 @@ #include "oatpp-libressl/Config.hpp" #include "oatpp-libressl/TLSObject.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/Address.hpp" +#include "oatpp/network/ConnectionProvider.hpp" namespace oatpp { namespace libressl { namespace server { @@ -64,13 +65,16 @@ class ConnectionProvider : public oatpp::base::Countable, public oatpp::network: const std::shared_ptr& streamProvider); /** - * Create shared ConnectionProvider using &id:oatpp::network::server::SimpleTCPConnectionProvider; - * as a provider of underlying transport stream. + * Create shared ConnectionProvider. * @param config - &id:oatpp::libressl::Config;. - * @param port - port to listen on. + * @param address - &id:oatpp::network::Address;. + * @param useExtendedConnections - set `true` to use &l:ConnectionProvider::ExtendedConnection;. + * `false` to use &id:oatpp::network::tcp::Connection;. * @return - `std::shared_ptr` to ConnectionProvider. */ - static std::shared_ptr createShared(const std::shared_ptr& config, v_uint16 port); + static std::shared_ptr createShared(const std::shared_ptr& config, + const network::Address& address, + bool useExtendedConnections = false); /** @@ -81,13 +85,13 @@ class ConnectionProvider : public oatpp::base::Countable, public oatpp::network: /** * Close all handles. */ - void close() override; + void stop() override; /** * Get incoming connection. * @return &id:oatpp::data::stream::IOStream;. */ - std::shared_ptr getConnection() override; + std::shared_ptr get() override; /** * No need to implement this.
@@ -97,7 +101,7 @@ class ConnectionProvider : public oatpp::base::Countable, public oatpp::network: *
* *It may be implemented later* */ - oatpp::async::CoroutineStarterForResult&> getConnectionAsync() override { + oatpp::async::CoroutineStarterForResult&> getAsync() override { /* * No need to implement this. * For Asynchronous IO in oatpp it is considered to be a good practice @@ -111,7 +115,7 @@ class ConnectionProvider : public oatpp::base::Countable, public oatpp::network: * Will call `invalidateConnection()` for the underlying transport stream. * @param connection - **MUST** be an instance of &id:oatpp::libressl::Connection;. */ - void invalidateConnection(const std::shared_ptr& connection) override; + void invalidate(const std::shared_ptr& connection) override; }; diff --git a/test/oatpp-libressl/FullAsyncClientTest.cpp b/test/oatpp-libressl/FullAsyncClientTest.cpp index 20fa45f..98c06ef 100644 --- a/test/oatpp-libressl/FullAsyncClientTest.cpp +++ b/test/oatpp-libressl/FullAsyncClientTest.cpp @@ -38,8 +38,8 @@ #include "oatpp/parser/json/mapping/ObjectMapper.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -#include "oatpp/network/client/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/tcp/server/ConnectionProvider.hpp" +#include "oatpp/network/tcp/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/server/ConnectionProvider.hpp" @@ -57,10 +57,10 @@ typedef oatpp::web::protocol::http::incoming::Response IncomingResponse; class TestComponent { private: - v_int32 m_port; + v_uint16 m_port; public: - TestComponent(v_int32 port) + TestComponent(v_uint16 port) : m_port(port) {} @@ -80,7 +80,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::server::SimpleTCPConnectionProvider::createShared(m_port); + streamProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", m_port}); } OATPP_LOGD("oatpp::libressl::Config", "pem='%s'", CERT_PEM_PATH); @@ -95,7 +95,7 @@ class TestComponent { return oatpp::web::server::HttpRouter::createShared(); }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { OATPP_COMPONENT(std::shared_ptr, router); OATPP_COMPONENT(std::shared_ptr, executor); return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router, executor); @@ -113,7 +113,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::client::SimpleTCPConnectionProvider::createShared("127.0.0.1", m_port); + streamProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({"localhost", m_port}); } auto config = oatpp::libressl::Config::createDefaultClientConfigShared(); diff --git a/test/oatpp-libressl/FullAsyncClientTest.hpp b/test/oatpp-libressl/FullAsyncClientTest.hpp index 1f8caae..e1a1d35 100644 --- a/test/oatpp-libressl/FullAsyncClientTest.hpp +++ b/test/oatpp-libressl/FullAsyncClientTest.hpp @@ -31,11 +31,11 @@ namespace oatpp { namespace test { namespace libressl { class FullAsyncClientTest : public UnitTest { private: - v_int32 m_port; + v_uint16 m_port; v_int32 m_connectionsPerEndpoint; public: - FullAsyncClientTest(v_int32 port, v_int32 connectionsPerEndpoint) + FullAsyncClientTest(v_uint16 port, v_int32 connectionsPerEndpoint) : UnitTest("TEST[web::FullAsyncClientTest]") , m_port(port) , m_connectionsPerEndpoint(connectionsPerEndpoint) diff --git a/test/oatpp-libressl/FullAsyncTest.cpp b/test/oatpp-libressl/FullAsyncTest.cpp index a6284c8..c4686c6 100644 --- a/test/oatpp-libressl/FullAsyncTest.cpp +++ b/test/oatpp-libressl/FullAsyncTest.cpp @@ -38,8 +38,8 @@ #include "oatpp/parser/json/mapping/ObjectMapper.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -#include "oatpp/network/client/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/tcp/server/ConnectionProvider.hpp" +#include "oatpp/network/tcp/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/server/ConnectionProvider.hpp" @@ -55,10 +55,10 @@ namespace { class TestComponent { private: - v_int32 m_port; + v_uint16 m_port; public: - TestComponent(v_int32 port) + TestComponent(v_uint16 port) : m_port(port) {} @@ -78,7 +78,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::server::SimpleTCPConnectionProvider::createShared(m_port); + streamProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", m_port}); } OATPP_LOGD("oatpp::libressl::Config", "pem='%s'", CERT_PEM_PATH); @@ -93,7 +93,7 @@ class TestComponent { return oatpp::web::server::HttpRouter::createShared(); }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { OATPP_COMPONENT(std::shared_ptr, router); OATPP_COMPONENT(std::shared_ptr, executor); return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router, executor); @@ -111,7 +111,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::client::SimpleTCPConnectionProvider::createShared("127.0.0.1", m_port); + streamProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({"localhost", m_port}); } auto config = oatpp::libressl::Config::createDefaultClientConfigShared(); diff --git a/test/oatpp-libressl/FullAsyncTest.hpp b/test/oatpp-libressl/FullAsyncTest.hpp index cdaca89..b6d7194 100644 --- a/test/oatpp-libressl/FullAsyncTest.hpp +++ b/test/oatpp-libressl/FullAsyncTest.hpp @@ -31,11 +31,11 @@ namespace oatpp { namespace test { namespace libressl { class FullAsyncTest : public UnitTest { private: - v_int32 m_port; + v_uint16 m_port; v_int32 m_iterationsPerStep; public: - FullAsyncTest(v_int32 port, v_int32 iterationsPerStep) + FullAsyncTest(v_uint16 port, v_int32 iterationsPerStep) : UnitTest("TEST[web::FullAsyncTest]") , m_port(port) , m_iterationsPerStep(iterationsPerStep) diff --git a/test/oatpp-libressl/FullTest.cpp b/test/oatpp-libressl/FullTest.cpp index a80e232..2b92f51 100644 --- a/test/oatpp-libressl/FullTest.cpp +++ b/test/oatpp-libressl/FullTest.cpp @@ -38,8 +38,8 @@ #include "oatpp/parser/json/mapping/ObjectMapper.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -#include "oatpp/network/client/SimpleTCPConnectionProvider.hpp" +#include "oatpp/network/tcp/server/ConnectionProvider.hpp" +#include "oatpp/network/tcp/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/client/ConnectionProvider.hpp" #include "oatpp/network/virtual_/server/ConnectionProvider.hpp" @@ -55,10 +55,10 @@ namespace { class TestComponent { private: - v_int32 m_port; + v_uint16 m_port; public: - TestComponent(v_int32 port) + TestComponent(v_uint16 port) : m_port(port) {} @@ -74,7 +74,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::server::SimpleTCPConnectionProvider::createShared(m_port); + streamProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", m_port}); } OATPP_LOGD("oatpp::libressl::Config", "pem='%s'", CERT_PEM_PATH); @@ -89,7 +89,7 @@ class TestComponent { return oatpp::web::server::HttpRouter::createShared(); }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { OATPP_COMPONENT(std::shared_ptr, router); return oatpp::web::server::HttpConnectionHandler::createShared(router); }()); @@ -106,7 +106,7 @@ class TestComponent { OATPP_COMPONENT(std::shared_ptr, interface); streamProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface); } else { - streamProvider = oatpp::network::client::SimpleTCPConnectionProvider::createShared("127.0.0.1", m_port); + streamProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({"localhost", m_port}); } auto config = oatpp::libressl::Config::createDefaultClientConfigShared(); diff --git a/test/oatpp-libressl/FullTest.hpp b/test/oatpp-libressl/FullTest.hpp index 7b7c6d5..51ea39e 100644 --- a/test/oatpp-libressl/FullTest.hpp +++ b/test/oatpp-libressl/FullTest.hpp @@ -31,11 +31,11 @@ namespace oatpp { namespace test { namespace libressl { class FullTest : public UnitTest { private: - v_int32 m_port; + v_uint16 m_port; v_int32 m_iterationsPerStep; public: - FullTest(v_int32 port, v_int32 iterationsPerStep) + FullTest(v_uint16 port, v_int32 iterationsPerStep) : UnitTest("TEST[web::FullTest]") , m_port(port) , m_iterationsPerStep(iterationsPerStep)