Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS support for Windows client #81

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<img src="https://github.com/cpp-redis/cpp_redis/blob/master/assets/images/cpp_redis_logo.png"/>
</p>

# 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`.
Expand Down
15 changes: 12 additions & 3 deletions includes/cpp_redis/core/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = 0, bool use_encryption = false);

/**
* retrieve sentinel for current client
Expand Down Expand Up @@ -2321,6 +2325,11 @@ namespace cpp_redis {
std::uint32_t m_reconnect_interval_ms = 0;

/**
* use encryption
*
*/
bool m_use_encryption = false;
/**
* reconnection status
*
*/
Expand Down
4 changes: 3 additions & 1 deletion includes/cpp_redis/core/consumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ 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",
std::size_t port = 6379,
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);
Expand Down
33 changes: 27 additions & 6 deletions includes/cpp_redis/core/sentinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0, bool use_encryption = false);

/**
* clear all existing sentinels.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand All @@ -321,7 +337,12 @@ namespace cpp_redis {
*
*/
std::uint32_t m_timeout_ms;
};
/**
* use_encryption config
*
*/
bool m_use_encryption;
};

public:
/**
Expand Down
14 changes: 11 additions & 3 deletions includes/cpp_redis/core/subscriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -106,14 +108,16 @@ 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 &name,
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -467,6 +471,10 @@ namespace cpp_redis {
*
*/
std::uint32_t m_reconnect_interval_ms = 0;
/**
* use encryption
*/
bool m_use_encryption = false;

/**
* reconnection status
Expand Down
4 changes: 3 additions & 1 deletion includes/cpp_redis/network/redis_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ 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(
const std::string &host = "127.0.0.1",
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
Expand Down
3 changes: 2 additions & 1 deletion includes/cpp_redis/network/tcp_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions includes/cpp_redis/network/tcp_client_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0, bool use_encryption = false) = 0;

/**
* stop the tcp client
Expand Down
41 changes: 41 additions & 0 deletions msvc19/cpp_redis.sln
Original file line number Diff line number Diff line change
@@ -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
Loading