From 2a7ef553db25ee0d681ef8fb3d6fe6481348b1c9 Mon Sep 17 00:00:00 2001 From: masmartin <86951372+masmartin@users.noreply.github.com> Date: Wed, 25 Aug 2021 16:33:39 +0200 Subject: [PATCH 1/5] Update tacopie --- tacopie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tacopie b/tacopie index 6b060c7..c025604 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit 6b060c7f7e158e60d634c14e412aa78d4041f237 +Subproject commit c025604137234b7116dddadc8492e1d8fcebc948 From 08ba1dbda6a04c5adb8079dd9821e285acebd846 Mon Sep 17 00:00:00 2001 From: masmartin <86951372+masmartin@users.noreply.github.com> Date: Thu, 26 Aug 2021 13:42:59 +0200 Subject: [PATCH 2/5] - Supports TLS encrypted connections (Windows client only) when using the referenced fork of the tacopie network module. - Visual Studio solution and project converted to VS2019 --- README.md | 4 +- includes/cpp_redis/core/client.hpp | 15 +- includes/cpp_redis/core/consumer.hpp | 4 +- includes/cpp_redis/core/sentinel.hpp | 33 +- includes/cpp_redis/core/subscriber.hpp | 14 +- .../cpp_redis/network/redis_connection.hpp | 4 +- includes/cpp_redis/network/tcp_client.hpp | 3 +- .../cpp_redis/network/tcp_client_iface.hpp | 4 +- msvc15/cpp_redis.vcxproj | 406 +++++++++--------- sources/core/client.cpp | 28 +- sources/core/consumer.cpp | 20 +- sources/core/reply.cpp | 2 +- sources/core/sentinel.cpp | 10 +- sources/core/subscriber.cpp | 19 +- sources/network/redis_connection.cpp | 4 +- sources/network/tcp_client.cpp | 4 +- tacopie | 2 +- 17 files changed, 312 insertions(+), 264 deletions(-) diff --git a/README.md b/README.md index 41b872d..cabed7a 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@

-# cpp_redis [![Build Status](https://travis-ci.org/Cylix/cpp_redis.svg?branch=master)](https://travis-ci.org/Cylix/cpp_redis) [![Build status](https://ci.appveyor.com/api/projects/status/d45yqju539t97s4m?svg=true)](https://ci.appveyor.com/project/Cylix/cpp-redis) +# cpp_redis `cpp_redis` is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations, pipelining, sentinels and high availability. +This fork supports TLS encrypted connections (Windows client only) when using the referenced fork of the tacopie network module. + ## Requirement `cpp_redis` has **no dependency**. Its only requirement is `C++11`. diff --git a/includes/cpp_redis/core/client.hpp b/includes/cpp_redis/core/client.hpp index e3ac14e..9df70e3 100644 --- a/includes/cpp_redis/core/client.hpp +++ b/includes/cpp_redis/core/client.hpp @@ -111,6 +111,7 @@ namespace cpp_redis { * @param timeout_ms maximum time to connect * @param max_reconnects maximum attempts of reconnection if connection dropped * @param reconnect_interval_ms time between two attempts of reconnection + * @param use_encryption enables TLS when set to true * */ void connect( @@ -119,7 +120,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback = nullptr, std::uint32_t timeout_ms = 0, std::int32_t max_reconnects = 0, - std::uint32_t reconnect_interval_ms = 0); + std::uint32_t reconnect_interval_ms = 0, + bool use_encryption = false); /** * Connect to redis server @@ -136,7 +138,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback = nullptr, std::uint32_t timeout_ms = 0, std::int32_t max_reconnects = 0, - std::uint32_t reconnect_interval_ms = 0); + std::uint32_t reconnect_interval_ms = 0, + bool use_encryption = false); /** * @return whether we are connected to the redis server @@ -321,9 +324,10 @@ namespace cpp_redis { * @param host sentinel host * @param port sentinel port * @param timeout_ms maximum time to connect + * @param use_encryption enables TLS when set to true * */ - void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0); + void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption); /** * retrieve sentinel for current client @@ -2321,6 +2325,11 @@ namespace cpp_redis { std::uint32_t m_reconnect_interval_ms = 0; /** + * use encryption + * + */ + bool m_use_encryption = false; + /** * reconnection status * */ diff --git a/includes/cpp_redis/core/consumer.hpp b/includes/cpp_redis/core/consumer.hpp index e6c7102..e57e2b8 100644 --- a/includes/cpp_redis/core/consumer.hpp +++ b/includes/cpp_redis/core/consumer.hpp @@ -82,6 +82,7 @@ namespace cpp_redis { * @param timeout_ms maximum time to connect * @param max_reconnects maximum attempts of reconnection if connection dropped * @param reconnect_interval_ms time between two attempts of reconnection + * @param use_encryption enables TLS when set to true */ void connect( const std::string &host = "127.0.0.1", @@ -89,7 +90,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback = nullptr, std::uint32_t timeout_ms = 0, std::int32_t max_reconnects = 0, - std::uint32_t reconnect_interval_ms = 0); + std::uint32_t reconnect_interval_ms = 0, + bool use_encryption = false); void auth(const std::string &password, const reply_callback_t &reply_callback = nullptr); diff --git a/includes/cpp_redis/core/sentinel.hpp b/includes/cpp_redis/core/sentinel.hpp index 21d9190..1b00f1a 100644 --- a/includes/cpp_redis/core/sentinel.hpp +++ b/includes/cpp_redis/core/sentinel.hpp @@ -152,7 +152,7 @@ namespace cpp_redis { * @return current instance * */ - sentinel &add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0); + sentinel &add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption); /** * clear all existing sentinels. @@ -198,13 +198,14 @@ namespace cpp_redis { * @param port port to be connected to * @param timeout_ms maximum time to connect * @param disconnect_handler handler to be called whenever disconnection occurs + * @param use_encryption enables TLS when set to true * */ void connect( const std::string &host, std::size_t port, const sentinel_disconnect_handler_t &disconnect_handler = nullptr, - std::uint32_t timeout_ms = 0); + std::uint32_t timeout_ms = 0, bool use_encryption = false); /** * Used to find the current redis master by asking one or more sentinels. Use high availability. @@ -264,8 +265,8 @@ namespace cpp_redis { * ctor * */ - sentinel_def(std::string host, std::size_t port, std::uint32_t timeout_ms) - : m_host(std::move(host)), m_port(port), m_timeout_ms(timeout_ms) {} + sentinel_def(std::string host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption) + : m_host(std::move(host)), m_port(port), m_timeout_ms(timeout_ms), m_use_encryption(use_encryption) {} /** * dtor @@ -303,7 +304,22 @@ namespace cpp_redis { void set_timeout_ms(std::uint32_t timeout_ms) { m_timeout_ms = timeout_ms; } - private: + /** + * @return use_encryption for sentinel + * + */ + bool + get_use_encryption() const { return m_use_encryption; } + + /** + * set use_encryption for sentinel + * @param use_encryption new value + * + */ + void + set_use_encryption(bool use_encryption) { m_use_encryption = use_encryption; } + + private: /** * sentinel host * @@ -321,7 +337,12 @@ namespace cpp_redis { * */ std::uint32_t m_timeout_ms; - }; + /** + * use_encryption config + * + */ + bool m_use_encryption; + }; public: /** diff --git a/includes/cpp_redis/core/subscriber.hpp b/includes/cpp_redis/core/subscriber.hpp index 6b46e1a..82bddc2 100644 --- a/includes/cpp_redis/core/subscriber.hpp +++ b/includes/cpp_redis/core/subscriber.hpp @@ -89,6 +89,7 @@ namespace cpp_redis { * @param timeout_ms maximum time to connect * @param max_reconnects maximum attempts of reconnection if connection dropped * @param reconnect_interval_ms time between two attempts of reconnection + * @param use_encryption enables TLS when set to true * */ void connect( @@ -97,7 +98,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback = nullptr, std::uint32_t timeout_ms = 0, std::int32_t max_reconnects = 0, - std::uint32_t reconnect_interval_ms = 0); + std::uint32_t reconnect_interval_ms = 0, + bool use_encryption = false); /** * @brief Connect to redis server @@ -106,6 +108,7 @@ namespace cpp_redis { * @param timeout_ms maximum time to connect * @param max_reconnects maximum attempts of reconnection if connection dropped * @param reconnect_interval_ms time between two attempts of reconnection + * @param use_encryption enables TLS when set to true * */ void connect( @@ -113,7 +116,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback = nullptr, std::uint32_t timeout_ms = 0, std::int32_t max_reconnects = 0, - std::uint32_t reconnect_interval_ms = 0); + std::uint32_t reconnect_interval_ms = 0, + bool use_encryption = false); /** * @brief determines client connectivity @@ -245,7 +249,7 @@ namespace cpp_redis { * @param timeout_ms maximum time to connect * */ - void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0); + void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption); /** * retrieve sentinel for current client @@ -467,6 +471,10 @@ namespace cpp_redis { * */ std::uint32_t m_reconnect_interval_ms = 0; + /** + * use encryption + */ + bool m_use_encryption = false; /** * reconnection status diff --git a/includes/cpp_redis/network/redis_connection.hpp b/includes/cpp_redis/network/redis_connection.hpp index 9714aec..a6d58a8 100644 --- a/includes/cpp_redis/network/redis_connection.hpp +++ b/includes/cpp_redis/network/redis_connection.hpp @@ -102,6 +102,8 @@ namespace cpp_redis { * @param disconnection_handler handler to be called in case of disconnection * @param reply_callback handler to be called once a reply is ready * @param timeout_ms max time to connect (in ms) + * @param use_encryption enables TLS when set to true + * * */ void connect( @@ -109,7 +111,7 @@ namespace cpp_redis { std::size_t port = 6379, const disconnection_handler_t &disconnection_handler = nullptr, const reply_callback_t &reply_callback = nullptr, - std::uint32_t timeout_ms = 0); + std::uint32_t timeout_ms = 0, bool use_encryption = false); /** * disconnect from redis server diff --git a/includes/cpp_redis/network/tcp_client.hpp b/includes/cpp_redis/network/tcp_client.hpp index ad5fcc9..597e45d 100644 --- a/includes/cpp_redis/network/tcp_client.hpp +++ b/includes/cpp_redis/network/tcp_client.hpp @@ -55,9 +55,10 @@ class tcp_client : public tcp_client_iface { * @param addr host to be connected to * @param port port to be connected to * @param timeout_ms max time to connect in ms + * @param use_encryption enables TLS when set to true * */ - void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms) override; + void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms, bool use_encryption) override; /** * stop the tcp client diff --git a/includes/cpp_redis/network/tcp_client_iface.hpp b/includes/cpp_redis/network/tcp_client_iface.hpp index 332f257..48aa818 100644 --- a/includes/cpp_redis/network/tcp_client_iface.hpp +++ b/includes/cpp_redis/network/tcp_client_iface.hpp @@ -55,9 +55,9 @@ class tcp_client_iface { * @param addr host to be connected to * @param port port to be connected to * @param timeout_ms max time to connect in ms - * + * @param use_encryption enables TLS when set to true */ - virtual void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms = 0) = 0; + virtual void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms, bool use_encryption) = 0; /** * stop the tcp client diff --git a/msvc15/cpp_redis.vcxproj b/msvc15/cpp_redis.vcxproj index a6646e7..2903ab2 100644 --- a/msvc15/cpp_redis.vcxproj +++ b/msvc15/cpp_redis.vcxproj @@ -1,4 +1,4 @@ - + - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 15.0 - {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01} - Win32Proj - cpp_redis - 8.1 - - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;_WIN32;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - - - true - - - - - - - Level3 - Disabled - _DEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - /bigobj %(AdditionalOptions) - true - - - Windows - - - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;_WIN32;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - true - true - - - true - - - - - Level3 - - - MaxSpeed - true - true - NDEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - true - true - - - true - - - - - - +--> + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01} + Win32Proj + cpp_redis + 10.0.19041.0 + + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions);LOGGING_ENABLED + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + + + true + + + + + + + Level3 + Disabled + _DEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions);__CPP_REDIS_LOGGING_ENABLED + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) + true + + + Windows + + + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + + \ No newline at end of file diff --git a/sources/core/client.cpp b/sources/core/client.cpp index 659c049..4220108 100644 --- a/sources/core/client.cpp +++ b/sources/core/client.cpp @@ -71,8 +71,9 @@ namespace cpp_redis { const connect_callback_t &connect_callback, std::uint32_t timeout_ms, std::int32_t max_reconnects, - std::uint32_t reconnect_interval_ms) { -/** + std::uint32_t reconnect_interval_ms, + bool use_encryption) { + /** * Save for auto reconnects */ m_master_name = name; @@ -94,7 +95,8 @@ namespace cpp_redis { const connect_callback_t &connect_callback, std::uint32_t timeout_ms, std::int32_t max_reconnects, - std::uint32_t reconnect_interval_ms) { + std::uint32_t reconnect_interval_ms, + bool use_encryption) { __CPP_REDIS_LOG(debug, "cpp_redis::client attempts to connect"); /** @@ -105,6 +107,7 @@ namespace cpp_redis { m_connect_callback = connect_callback; m_max_reconnects = max_reconnects; m_reconnect_interval_ms = reconnect_interval_ms; + m_use_encryption = use_encryption; /** * notify start @@ -114,9 +117,8 @@ namespace cpp_redis { } auto disconnection_handler = std::bind(&client::connection_disconnection_handler, this, std::placeholders::_1); - auto receive_handler = std::bind(&client::connection_receive_handler, this, std::placeholders::_1, - std::placeholders::_2); - m_client.connect(host, port, disconnection_handler, receive_handler, timeout_ms); + auto receive_handler = std::bind(&client::connection_receive_handler, this, std::placeholders::_1, std::placeholders::_2); + m_client.connect(host, port, disconnection_handler, receive_handler, timeout_ms, use_encryption); __CPP_REDIS_LOG(info, "cpp_redis::client connected"); @@ -161,8 +163,8 @@ namespace cpp_redis { } void - client::add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms) { - m_sentinel.add_sentinel(host, port, timeout_ms); + client::add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption) { + m_sentinel.add_sentinel(host, port, timeout_ms, use_encryption); } const sentinel & @@ -442,7 +444,7 @@ namespace cpp_redis { * We rely on the sentinel to tell us which redis server is currently the master. */ if (!m_master_name.empty() && - !m_sentinel.get_master_addr_by_name(m_master_name, m_redis_server, m_redis_port, true)) { + !m_sentinel.get_master_addr_by_name(m_master_name, m_redis_server, m_redis_port, true)) { if (m_connect_callback) { m_connect_callback(m_redis_server, m_redis_port, connect_state::lookup_failed); } @@ -454,7 +456,7 @@ namespace cpp_redis { */ try { connect(m_redis_server, m_redis_port, m_connect_callback, m_connect_timeout_ms, m_max_reconnects, - m_reconnect_interval_ms); + m_reconnect_interval_ms, m_use_encryption); } catch (...) { } @@ -612,7 +614,7 @@ namespace cpp_redis { client & client::bitfield(const std::string &key, const std::vector &operations, - const reply_callback_t &reply_callback) { + const reply_callback_t &reply_callback) { std::vector cmd = {"BITFIELD", key}; for (const auto &operation : operations) { @@ -621,7 +623,7 @@ namespace cpp_redis { cmd.push_back(std::to_string(operation.offset)); if (operation.operation_type == bitfield_operation_type::set || - operation.operation_type == bitfield_operation_type::incrby) { + operation.operation_type == bitfield_operation_type::incrby) { cmd.push_back(std::to_string(operation.value)); } @@ -637,7 +639,7 @@ namespace cpp_redis { client & client::bitop(const std::string &operation, const std::string &destkey, const std::vector &keys, - const reply_callback_t &reply_callback) { + const reply_callback_t &reply_callback) { std::vector cmd = {"BITOP", operation, destkey}; cmd.insert(cmd.end(), keys.begin(), keys.end()); send(cmd, reply_callback); diff --git a/sources/core/consumer.cpp b/sources/core/consumer.cpp index e0d3507..12c974a 100644 --- a/sources/core/consumer.cpp +++ b/sources/core/consumer.cpp @@ -69,9 +69,9 @@ namespace cpp_redis { } void consumer::connect(const std::string &host, size_t port, const connect_callback_t &connect_callback, - uint32_t timeout_ms, int32_t max_reconnects, uint32_t reconnect_interval_ms) { - m_client->ack_client.connect(host, port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms); - m_client->poll_client.connect(host, port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms); + uint32_t timeout_ms, int32_t max_reconnects, uint32_t reconnect_interval_ms, bool use_encryption) { + m_client->ack_client.connect(host, port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms, use_encryption); + m_client->poll_client.connect(host, port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms, use_encryption); } void consumer::auth(const std::string &password, @@ -82,14 +82,12 @@ namespace cpp_redis { consumer &consumer::commit() { while (!is_ready) { - if (!is_ready) { - std::unique_lock dispatch_lock(dispatch_queue_changed_mutex); - dispatch_queue_changed.wait(dispatch_lock, [&]() { - return !dispatch_queue_full.load(); - }); - m_read_count = static_cast(m_max_concurrency - m_dispatch_queue->size()); - poll(); - } + std::unique_lock dispatch_lock(dispatch_queue_changed_mutex); + dispatch_queue_changed.wait(dispatch_lock, [&]() { + return !dispatch_queue_full.load(); + }); + m_read_count = static_cast(m_max_concurrency - m_dispatch_queue->size()); + poll(); } return *this; } diff --git a/sources/core/reply.cpp b/sources/core/reply.cpp index 19c8c98..b640b27 100644 --- a/sources/core/reply.cpp +++ b/sources/core/reply.cpp @@ -50,7 +50,7 @@ namespace cpp_redis { if (is_integer()) return optional_t(m_int_val); - __CPP_REDIS_LOG(1, "Reply is not an integer"); + __CPP_REDIS_LOG(error, "Reply is not an integer"); return {0}; } diff --git a/sources/core/sentinel.cpp b/sources/core/sentinel.cpp index bd67d6f..b266cc1 100644 --- a/sources/core/sentinel.cpp +++ b/sources/core/sentinel.cpp @@ -48,8 +48,8 @@ sentinel::~sentinel(void) { } sentinel& -sentinel::add_sentinel(const std::string& host, std::size_t port, std::uint32_t timeout_ms) { - m_sentinels.push_back({host, port, timeout_ms}); +sentinel::add_sentinel(const std::string& host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption) { + m_sentinels.push_back({host, port, timeout_ms, use_encryption}); return *this; } @@ -124,7 +124,7 @@ sentinel::connect_sentinel(const sentinel_disconnect_handler_t& sentinel_disconn while (not_connected && it != m_sentinels.end()) { try { __CPP_REDIS_LOG(debug, std::string("cpp_redis::sentinel attempting to connect to host ") + it->get_host()); - m_client.connect(it->get_host(), it->get_port(), disconnect_handler, receive_handler, it->get_timeout_ms()); + m_client.connect(it->get_host(), it->get_port(), disconnect_handler, receive_handler, it->get_timeout_ms(), it->get_use_encryption()); } catch (const redis_error&) { __CPP_REDIS_LOG(info, std::string("cpp_redis::sentinel unable to connect to sentinel host ") + it->get_host()); @@ -152,13 +152,13 @@ sentinel::connect_sentinel(const sentinel_disconnect_handler_t& sentinel_disconn void sentinel::connect(const std::string& host, std::size_t port, const sentinel_disconnect_handler_t& sentinel_disconnect_handler, - std::uint32_t timeout_ms) { + std::uint32_t timeout_ms, bool use_encryption) { __CPP_REDIS_LOG(debug, "cpp_redis::sentinel attempts to connect"); auto disconnect_handler = std::bind(&sentinel::connection_disconnect_handler, this, std::placeholders::_1); auto receive_handler = std::bind(&sentinel::connection_receive_handler, this, std::placeholders::_1, std::placeholders::_2); - m_client.connect(host, port, disconnect_handler, receive_handler, timeout_ms); + m_client.connect(host, port, disconnect_handler, receive_handler, timeout_ms, use_encryption); __CPP_REDIS_LOG(info, "cpp_redis::sentinel connected"); diff --git a/sources/core/subscriber.cpp b/sources/core/subscriber.cpp index 02678d4..9469056 100644 --- a/sources/core/subscriber.cpp +++ b/sources/core/subscriber.cpp @@ -73,13 +73,14 @@ subscriber::connect( const connect_callback_t& connect_callback, std::uint32_t timeout_ms, std::int32_t max_reconnects, - std::uint32_t reconnect_interval_ms) { + std::uint32_t reconnect_interval_ms, + bool use_encryption) { //! Save for auto reconnects m_master_name = name; //! We rely on the sentinel to tell us which redis server is currently the master. if (m_sentinel.get_master_addr_by_name(name, m_redis_server, m_redis_port, true)) { - connect(m_redis_server, m_redis_port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms); + connect(m_redis_server, m_redis_port, connect_callback, timeout_ms, max_reconnects, reconnect_interval_ms, use_encryption); } else { throw redis_error("cpp_redis::subscriber::connect() could not find master for m_name " + name); @@ -93,7 +94,8 @@ subscriber::connect( const connect_callback_t& connect_callback, std::uint32_t timeout_ms, std::int32_t max_reconnects, - std::uint32_t reconnect_interval_ms) { + std::uint32_t reconnect_interval_ms, + bool use_encryption) { __CPP_REDIS_LOG(debug, "cpp_redis::subscriber attempts to connect"); //! Save for auto reconnects @@ -101,7 +103,8 @@ subscriber::connect( m_redis_port = port; m_connect_callback = connect_callback; m_max_reconnects = max_reconnects; - m_reconnect_interval_ms = reconnect_interval_ms; + m_reconnect_interval_ms = reconnect_interval_ms; + m_use_encryption = use_encryption; //! notify start if (m_connect_callback) { @@ -110,7 +113,7 @@ subscriber::connect( auto disconnection_handler = std::bind(&subscriber::connection_disconnection_handler, this, std::placeholders::_1); auto receive_handler = std::bind(&subscriber::connection_receive_handler, this, std::placeholders::_1, std::placeholders::_2); - m_client.connect(host, port, disconnection_handler, receive_handler, timeout_ms); + m_client.connect(host, port, disconnection_handler, receive_handler, timeout_ms, use_encryption); //! notify end if (m_connect_callback) { @@ -121,8 +124,8 @@ subscriber::connect( } void -subscriber::add_sentinel(const std::string& host, std::size_t port, std::uint32_t timeout_ms) { - m_sentinel.add_sentinel(host, port, timeout_ms); +subscriber::add_sentinel(const std::string& host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption) { + m_sentinel.add_sentinel(host, port, timeout_ms, use_encryption); } const sentinel& @@ -485,7 +488,7 @@ subscriber::reconnect() { //! Try catch block because the redis subscriber throws an error if connection cannot be made. try { - connect(m_redis_server, m_redis_port, m_connect_callback, m_connect_timeout_ms, m_max_reconnects, m_reconnect_interval_ms); + connect(m_redis_server, m_redis_port, m_connect_callback, m_connect_timeout_ms, m_max_reconnects, m_reconnect_interval_ms, m_use_encryption); } catch (...) { } diff --git a/sources/network/redis_connection.cpp b/sources/network/redis_connection.cpp index 20ac630..1294249 100644 --- a/sources/network/redis_connection.cpp +++ b/sources/network/redis_connection.cpp @@ -56,14 +56,14 @@ namespace cpp_redis { redis_connection::connect(const std::string &host, std::size_t port, const disconnection_handler_t &client_disconnection_handler, const reply_callback_t &client_reply_callback, - std::uint32_t timeout_ms) { + std::uint32_t timeout_ms, bool use_encryption) { try { __CPP_REDIS_LOG(debug, "cpp_redis::network::redis_connection attempts to connect"); /** * connect client */ - m_client->connect(host, (uint32_t) port, timeout_ms); + m_client->connect(host, (uint32_t) port, timeout_ms, use_encryption); m_client->set_on_disconnection_handler(std::bind(&redis_connection::tcp_client_disconnection_handler, this)); /** diff --git a/sources/network/tcp_client.cpp b/sources/network/tcp_client.cpp index 28891ea..a341bf9 100644 --- a/sources/network/tcp_client.cpp +++ b/sources/network/tcp_client.cpp @@ -28,8 +28,8 @@ namespace cpp_redis { namespace network { void -tcp_client::connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms) { - m_client.connect(addr, port, timeout_ms); +tcp_client::connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms, bool use_encryption) { + m_client.connect(addr, port, timeout_ms, use_encryption); } diff --git a/tacopie b/tacopie index c025604..e124a48 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit c025604137234b7116dddadc8492e1d8fcebc948 +Subproject commit e124a482161a6fa41d54b27449bc5611f4b5a979 From 7d18777c5f1c90997168f3066a89a8eab6cc48fb Mon Sep 17 00:00:00 2001 From: masmartin <86951372+masmartin@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:20:11 +0200 Subject: [PATCH 3/5] - added VS2019 project - restored VS2015 project - updated to current tacopie with tls and VS2019 --- msvc19/cpp_redis.sln | 41 +++++++ msvc19/cpp_redis.vcxproj | 230 +++++++++++++++++++++++++++++++++++++++ tacopie | 2 +- 3 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 msvc19/cpp_redis.sln create mode 100644 msvc19/cpp_redis.vcxproj diff --git a/msvc19/cpp_redis.sln b/msvc19/cpp_redis.sln new file mode 100644 index 0000000..9edf9b8 --- /dev/null +++ b/msvc19/cpp_redis.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp_redis", "cpp_redis.vcxproj", "{8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tacopie", "..\tacopie\msvc19\tacopie.vcxproj", "{5DC28D31-04A5-4509-8EE3-CF16DE77475B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Debug|x64.ActiveCfg = Debug|x64 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Debug|x64.Build.0 = Debug|x64 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Debug|x86.ActiveCfg = Debug|Win32 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Debug|x86.Build.0 = Debug|Win32 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Release|x64.ActiveCfg = Release|x64 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Release|x64.Build.0 = Release|x64 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Release|x86.ActiveCfg = Release|Win32 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01}.Release|x86.Build.0 = Release|Win32 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Debug|x64.ActiveCfg = Debug|x64 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Debug|x64.Build.0 = Debug|x64 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Debug|x86.ActiveCfg = Debug|Win32 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Debug|x86.Build.0 = Debug|Win32 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Release|x64.ActiveCfg = Release|x64 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Release|x64.Build.0 = Release|x64 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Release|x86.ActiveCfg = Release|Win32 + {5DC28D31-04A5-4509-8EE3-CF16DE77475B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2E89D461-07FD-4A05-826C-3138C5E2AF44} + EndGlobalSection +EndGlobal diff --git a/msvc19/cpp_redis.vcxproj b/msvc19/cpp_redis.vcxproj new file mode 100644 index 0000000..197f9d2 --- /dev/null +++ b/msvc19/cpp_redis.vcxproj @@ -0,0 +1,230 @@ + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {5dc28d31-04a5-4509-8ee3-cf16de77475b} + false + + + + 15.0 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01} + Win32Proj + cpp_redis + 10.0.19041.0 + + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions);LOGGING_ENABLED + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + + + true + + + + + + + Level3 + Disabled + _DEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions);__CPP_REDIS_LOGGING_ENABLED + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) + true + + + Windows + + + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + + \ No newline at end of file diff --git a/tacopie b/tacopie index e124a48..c025604 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit e124a482161a6fa41d54b27449bc5611f4b5a979 +Subproject commit c025604137234b7116dddadc8492e1d8fcebc948 From b432bbbe6240a758c1d98ba22f7be6bec334c044 Mon Sep 17 00:00:00 2001 From: masmartin <86951372+masmartin@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:47:15 +0200 Subject: [PATCH 4/5] - restored default parameters for connect function to retain backwards compatibility - restore msvc15 project --- includes/cpp_redis/core/client.hpp | 2 +- includes/cpp_redis/core/sentinel.hpp | 2 +- .../cpp_redis/network/tcp_client_iface.hpp | 2 +- msvc15/cpp_redis.vcxproj | 406 +++++++++--------- 4 files changed, 206 insertions(+), 206 deletions(-) diff --git a/includes/cpp_redis/core/client.hpp b/includes/cpp_redis/core/client.hpp index 9df70e3..6e46d0b 100644 --- a/includes/cpp_redis/core/client.hpp +++ b/includes/cpp_redis/core/client.hpp @@ -327,7 +327,7 @@ namespace cpp_redis { * @param use_encryption enables TLS when set to true * */ - void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption); + void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0, bool use_encryption = false); /** * retrieve sentinel for current client diff --git a/includes/cpp_redis/core/sentinel.hpp b/includes/cpp_redis/core/sentinel.hpp index 1b00f1a..4c4c012 100644 --- a/includes/cpp_redis/core/sentinel.hpp +++ b/includes/cpp_redis/core/sentinel.hpp @@ -152,7 +152,7 @@ namespace cpp_redis { * @return current instance * */ - sentinel &add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms, bool use_encryption); + sentinel &add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0, bool use_encryption = false); /** * clear all existing sentinels. diff --git a/includes/cpp_redis/network/tcp_client_iface.hpp b/includes/cpp_redis/network/tcp_client_iface.hpp index 48aa818..549014b 100644 --- a/includes/cpp_redis/network/tcp_client_iface.hpp +++ b/includes/cpp_redis/network/tcp_client_iface.hpp @@ -57,7 +57,7 @@ class tcp_client_iface { * @param timeout_ms max time to connect in ms * @param use_encryption enables TLS when set to true */ - virtual void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms, bool use_encryption) = 0; + virtual void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_ms = 0, bool use_encryption = false) = 0; /** * stop the tcp client diff --git a/msvc15/cpp_redis.vcxproj b/msvc15/cpp_redis.vcxproj index 2903ab2..a6646e7 100644 --- a/msvc15/cpp_redis.vcxproj +++ b/msvc15/cpp_redis.vcxproj @@ -1,4 +1,4 @@ - + - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 15.0 - {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01} - Win32Proj - cpp_redis - 10.0.19041.0 - - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - StaticLibrary - true - v142 - Unicode - - - StaticLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions);LOGGING_ENABLED - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - - - true - - - - - - - Level3 - Disabled - _DEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions);__CPP_REDIS_LOGGING_ENABLED - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - /bigobj %(AdditionalOptions) - true - - - Windows - - - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;_WIN32;SECURITY_WIN32;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - true - true - - - true - - - - - Level3 - - - MaxSpeed - true - true - NDEBUG;_LIB;_WIN32;_WIN64;SECURITY_WIN32;%(PreprocessorDefinitions) - ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) - true - - - Windows - true - true - - - true - - - - - - \ No newline at end of file +--> + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {8D6B2E0B-45B0-40CB-AF6B-B917F136EB01} + Win32Proj + cpp_redis + 8.1 + + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + + + true + + + + + + + Level3 + Disabled + _DEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) + true + + + Windows + + + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;_WIN32;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions) + ..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories) + true + + + Windows + true + true + + + true + + + + + + From 4dca85a973d7c4d3caad578f321455fbb7abe7b0 Mon Sep 17 00:00:00 2001 From: masmartin <86951372+masmartin@users.noreply.github.com> Date: Mon, 30 Aug 2021 12:11:40 +0200 Subject: [PATCH 5/5] - updated tacopie reference --- tacopie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tacopie b/tacopie index c025604..ef58851 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit c025604137234b7116dddadc8492e1d8fcebc948 +Subproject commit ef5885162b7463290d961384e23dd82530eb13c0