Skip to content

Commit 33e92df

Browse files
authored
feat: replace Encrypted/Plain clients with foxy library (#39)
* add foxy library * use foxy in both the AsioRequester and Eventsource libraries
1 parent c330bb8 commit 33e92df

File tree

24 files changed

+369
-541
lines changed

24 files changed

+369
-541
lines changed

CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ project(
1111
LANGUAGES CXX C
1212
)
1313

14-
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
15-
# Affects robustness of timestamp checking on FetchContent dependencies.
16-
cmake_policy(SET CMP0135 NEW)
17-
endif ()
18-
1914
# All projects in this repo should share the same version of 3rd party depends.
2015
# It's the only way to remain sane.
2116
set(CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -36,6 +31,10 @@ if (BUILD_TESTING)
3631
endif ()
3732
endif ()
3833
include(FetchContent)
34+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
35+
# Affects robustness of timestamp checking on FetchContent dependencies.
36+
cmake_policy(SET CMP0135 NEW)
37+
endif ()
3938
FetchContent_Declare(
4039
googletest
4140
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip

apps/hello-cpp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main() {
6060

6161
client.WaitForReadySync(std::chrono::seconds(30));
6262

63-
auto value = client.BoolVariationDetail("my-bool-flag", false);
63+
auto value = client.BoolVariationDetail("my-boolean-flag", false);
6464
LD_LOG(logger, LogLevel::kInfo) << "Value was: " << *value;
6565
if (auto reason = value.Reason()) {
6666
LD_LOG(logger, LogLevel::kInfo) << "Reason was: " << *reason;

apps/sse-contract-tests/src/entity_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bool EntityManager::destroy(std::string const& id) {
6565
return false;
6666
}
6767

68+
it->second.first->close();
6869
it->second.second->stop();
6970

7071
entities_.erase(it);

cmake/certify.cmake

Lines changed: 0 additions & 10 deletions
This file was deleted.

cmake/expected.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.11)
22

33
include(FetchContent)
44

5+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
6+
# Affects robustness of timestamp checking on FetchContent dependencies.
7+
cmake_policy(SET CMP0135 NEW)
8+
endif ()
9+
510
FetchContent_Declare(tl-expected
611
GIT_REPOSITORY https://github.com/TartanLlama/expected.git
712
GIT_TAG 292eff8bd8ee230a7df1d6a1c00c4ea0eb2f0362

cmake/foxy.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
3+
include(FetchContent)
4+
5+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
6+
# Affects robustness of timestamp checking on FetchContent dependencies.
7+
cmake_policy(SET CMP0135 NEW)
8+
endif ()
9+
10+
11+
FetchContent_Declare(foxy
12+
GIT_REPOSITORY https://github.com/launchdarkly/foxy.git
13+
GIT_TAG 7f4ac0495ad2ed9cd0eca5994743d677ac1d2636
14+
)
15+
16+
17+
set(BUILD_TESTING OFF)
18+
FetchContent_MakeAvailable(foxy)
19+
set(BUILD_TESTING ON)

cmake/json.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ include(FetchContent)
44

55
set(JSON_ImplicitConversions OFF)
66

7+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
8+
# Affects robustness of timestamp checking on FetchContent dependencies.
9+
cmake_policy(SET CMP0135 NEW)
10+
endif ()
11+
712
FetchContent_Declare(json
8-
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
9-
)
13+
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
14+
)
1015

1116
FetchContent_MakeAvailable(json)

libs/client-sdk/src/data_sources/streaming_data_source.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ StreamingDataSource::StreamingDataSource(
9090

9191
auto& http_properties = config.HttpProperties();
9292

93+
// TODO: can the read timeout be shared with *all* http requests? Or should
94+
// it have a default in defaults.hpp? This must be greater than the
95+
// heartbeat interval of the streaming service.
96+
client_builder.read_timeout(std::chrono::minutes(5));
97+
98+
client_builder.write_timeout(http_properties.WriteTimeout());
99+
100+
client_builder.connect_timeout(http_properties.ConnectTimeout());
101+
93102
client_builder.header("authorization", config.SdkKey());
94103
for (auto const& header : http_properties.BaseHeaders()) {
95104
client_builder.header(header.first, header.second);

libs/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}")
3737

3838

3939
include(${CMAKE_FILES}/expected.cmake)
40-
include(${CMAKE_FILES}/certify.cmake)
40+
include(${CMAKE_FILES}/foxy.cmake)
4141

4242
# Add main SDK sources.
4343
add_subdirectory(src)

libs/common/include/config/detail/builders/http_properties_builder.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ class HttpPropertiesBuilder {
5858
*/
5959
HttpPropertiesBuilder& ReadTimeout(std::chrono::milliseconds read_timeout);
6060

61+
/**
62+
* Set a write timeout. This is how long it takes to perform a write
63+
* operation.
64+
*
65+
* @param read_timeout The write timeout.
66+
* @return A reference to this builder.
67+
*/
68+
HttpPropertiesBuilder& WriteTimeout(
69+
std::chrono::milliseconds write_timeout);
70+
6171
/**
6272
* The time for the first byte to be received during a read. If a byte
6373
* is not received within this time, then the request will be cancelled.
@@ -115,6 +125,7 @@ class HttpPropertiesBuilder {
115125
private:
116126
std::chrono::milliseconds connect_timeout_;
117127
std::chrono::milliseconds read_timeout_;
128+
std::chrono::milliseconds write_timeout_;
118129
std::chrono::milliseconds response_timeout_;
119130
std::string wrapper_name_;
120131
std::string wrapper_version_;

libs/common/include/config/detail/built/http_properties.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ class HttpProperties final {
1111
public:
1212
HttpProperties(std::chrono::milliseconds connect_timeout,
1313
std::chrono::milliseconds read_timeout,
14+
std::chrono::milliseconds write_timeout,
1415
std::chrono::milliseconds response_timeout,
1516
std::string user_agent,
1617
std::map<std::string, std::string> base_headers);
1718

1819
[[nodiscard]] std::chrono::milliseconds ConnectTimeout() const;
1920
[[nodiscard]] std::chrono::milliseconds ReadTimeout() const;
21+
[[nodiscard]] std::chrono::milliseconds WriteTimeout() const;
22+
2023
[[nodiscard]] std::chrono::milliseconds ResponseTimeout() const;
2124
[[nodiscard]] std::string const& UserAgent() const;
2225
[[nodiscard]] std::map<std::string, std::string> const& BaseHeaders() const;
2326

2427
private:
2528
std::chrono::milliseconds connect_timeout_;
2629
std::chrono::milliseconds read_timeout_;
30+
std::chrono::milliseconds write_timeout_;
2731
std::chrono::milliseconds response_timeout_;
2832
std::string user_agent_;
2933
std::map<std::string, std::string> base_headers_;

libs/common/include/config/detail/defaults.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ struct Defaults<ClientSDK> {
4646
}
4747

4848
static auto HttpProperties() -> built::HttpProperties {
49-
return {
50-
std::chrono::milliseconds{10000}, std::chrono::milliseconds{10000},
51-
std::chrono::milliseconds{10000}, SdkName() + "/" + SdkVersion(),
52-
std::map<std::string, std::string>()};
49+
return {std::chrono::seconds{10},
50+
std::chrono::seconds{10},
51+
std::chrono::seconds{10},
52+
std::chrono::seconds{10},
53+
SdkName() + "/" + SdkVersion(),
54+
std::map<std::string, std::string>()};
5355
}
5456

5557
static auto StreamingConfig() -> built::StreamingConfig<ClientSDK> {
56-
return {std::chrono::milliseconds{1000}, "/meval"};
58+
return {std::chrono::seconds{1}, "/meval"};
5759
}
5860

5961
static auto DataSourceConfig() -> built::DataSourceConfig<ClientSDK> {
@@ -91,14 +93,16 @@ struct Defaults<ServerSDK> {
9193
}
9294

9395
static auto HttpProperties() -> built::HttpProperties {
94-
return {
95-
std::chrono::milliseconds{2000}, std::chrono::milliseconds{10000},
96-
std::chrono::milliseconds{10000}, SdkName() + "/" + SdkVersion(),
97-
std::map<std::string, std::string>()};
96+
return {std::chrono::seconds{2},
97+
std::chrono::seconds{10},
98+
std::chrono::seconds{10},
99+
std::chrono::seconds{10},
100+
SdkName() + "/" + SdkVersion(),
101+
std::map<std::string, std::string>()};
98102
}
99103

100104
static auto StreamingConfig() -> built::StreamingConfig<ServerSDK> {
101-
return {std::chrono::milliseconds{1000}};
105+
return {std::chrono::seconds{1}};
102106
}
103107

104108
static auto DataSourceConfig() -> built::DataSourceConfig<ServerSDK> {

0 commit comments

Comments
 (0)