Skip to content

Commit 5ec1bda

Browse files
authored
RCPP-6 Improve networking (#216)
1 parent 359569d commit 5ec1bda

34 files changed

+1870
-531
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ NEXT-RELEASE Release notes (YYYY-MM-DD)
1111
Supported operators are `==`, `!=`, `>`, `<`, `>=`, `<=` and `contains(const std::string&)`.
1212
* Add `managed<std::map<std::string, T>>::contains_key` for conveniently checking if a managed map
1313
contains a given key. Use this method in the Type Safe Query API instead of `managed<std::map<std::string, T>>::find`.
14+
* Add `realm::networking` namespace which contains interfaces for providing your own custom network transport
15+
implementations. The following interfaces are exposed:
16+
* `websocket_interface`
17+
* `websocket_observer`
18+
* `sync_socket_provider`
19+
* `sync_socket_provider::timer`
20+
* `http_transport_client`
21+
* Add `default_http_transport` for built-in HTTP transport.
22+
* Add `default_socket_provider` a built-in class for providing the components necessary for transport via WebSocket.
23+
* A custom WebSocket & HTTP transport implementation can be used by passing
24+
the instance via `realm::app::App::configuration.http_transport_client` & `realm::app::App::configuration.sync_socket_provider`.
25+
* Network configuration for the built-in http transport must be supplied via it's constructor using the
26+
`realm::networking::default_http_transport::configuration` struct.
27+
* Network configuration for the built-in websocket provider must be supplied via it's constructor using the
28+
`realm::networking::default_socket_provider::configuration` struct.
29+
30+
### Deprecations
31+
* Proxy and custom http headers should no longer be set via `realm::app::App::configuration`.
1432

1533
### Compatibility
1634
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10.
1735

1836
### Internals
19-
* None
37+
* Upgraded to Core v14.10.4
2038

2139
2.1.0 Release notes (2024-06-27)
2240
=============================================================

CMakeLists.txt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"
122122
target_compile_options(cpprealm PRIVATE -Wall -Wextra -pedantic -Werror)
123123
endif()
124124

125-
if(APPLE OR MSVC)
126-
target_sources(cpprealm PRIVATE src/cpprealm/internal/network/network_transport.cpp)
127-
elseif(ANDROID)
128-
set(REALM_ANDROID)
129-
target_sources(cpprealm PRIVATE src/cpprealm/internal/network/network_transport.cpp)
130-
else()
131-
find_package(CURL)
132-
if(NOT CURL_FOUND)
133-
message(WARNING "CURL not found. Realm C++ will use internal networking components instead.")
134-
target_sources(cpprealm PRIVATE src/cpprealm/internal/network/network_transport.cpp)
135-
else()
136-
target_link_libraries(cpprealm PUBLIC CURL::libcurl)
137-
target_sources(cpprealm PRIVATE src/cpprealm/internal/curl/network_transport.cpp)
138-
endif()
139-
140-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
141-
target_link_libraries(cpprealm PRIVATE stdc++fs)
142-
endif()
125+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
126+
target_link_libraries(cpprealm PRIVATE stdc++fs)
143127
endif()
144128

145129
if(MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)

Package.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import PackageDescription
44

55
let sdkVersion = Version("2.1.0")
6-
let coreVersion = Version("14.9.0")
6+
let coreVersion = Version("14.10.4")
77

88
var cxxSettings: [CXXSetting] = [
99
.define("REALM_ENABLE_SYNC", to: "1"),
@@ -41,8 +41,6 @@ let cppSdkTarget: Target = .target(
4141
],
4242
path: ".",
4343
exclude: [
44-
"src/cpprealm/internal/curl",
45-
"src/cpprealm/internal/network",
4644
"src/cpprealm/util/config.in.h",
4745
"realm-core"
4846
],

include/cpprealm/app.hpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
#include <cpprealm/internal/bridge/sync_manager.hpp>
2828
#include <cpprealm/internal/bridge/sync_session.hpp>
2929
#include <cpprealm/internal/bridge/utils.hpp>
30+
#include <cpprealm/networking/http.hpp>
31+
#include <cpprealm/networking/websocket.hpp>
3032

3133
#include <future>
3234
#include <utility>
3335

3436
namespace realm {
37+
3538
using proxy_config = sync_config::proxy_config;
3639
using sync_session = internal::bridge::sync_session;
3740

@@ -222,20 +225,43 @@ namespace app {
222225

223226
class App {
224227
public:
228+
/**
229+
* Properties representing the configuration of a client
230+
* that communicate with a particular Realm application.
231+
*
232+
* `App::configuration` options cannot be modified once the `App` using it
233+
* is created. App's configuration values are cached when the App is created so any modifications after it
234+
* will not have any effect.
235+
*/
225236
struct configuration {
237+
/// The App ID for your Atlas Device Sync Application.
226238
std::string app_id;
239+
/// A custom base URL to request against. If not set or set to nil, the default base url for app services will be returned.
227240
std::optional<std::string> base_url;
241+
/// Custom location for Realm files.
228242
std::optional<std::string> path;
243+
[[deprecated("Network options must be supplied via custom network implementations.")]]
229244
std::optional<std::map<std::string, std::string>> custom_http_headers;
245+
/// Custom encryption key for the metadata Realm.
230246
std::optional<std::array<char, 64>> metadata_encryption_key;
247+
/// Caches an App and its configuration for a given App ID. On by default.
248+
bool enable_caching = true;
249+
[[deprecated("Network options must be supplied via custom network implementations.")]]
231250
std::optional<sync_config::proxy_config> proxy_configuration;
251+
/**
252+
* Optionally provide a custom HTTP transport for network calls to the server.
253+
*
254+
* Alternatively use `realm::networking::set_http_client_factory` to globally set
255+
* the default HTTP transport client.
256+
*/
257+
std::shared_ptr<networking::http_transport_client> http_transport_client;
258+
/**
259+
* Optionally provide a custom WebSocket interface for sync.
260+
*/
261+
std::shared_ptr<networking::sync_socket_provider> sync_socket_provider;
262+
232263
};
233264

234-
[[deprecated("Use App(const configuration&) instead.")]]
235-
explicit App(const std::string& app_id,
236-
const std::optional<std::string>& base_url = {},
237-
const std::optional<std::string>& path = {},
238-
const std::optional<std::map<std::string, std::string>>& custom_http_headers = {});
239265

240266
App(const configuration&);
241267

include/cpprealm/db.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020
#define CPPREALM_DB_HPP
2121

2222
#include <cpprealm/accessors.hpp>
23-
23+
#include <cpprealm/macros.hpp>
24+
#include <cpprealm/results.hpp>
25+
#include <cpprealm/scheduler.hpp>
2426
#include <cpprealm/schema.hpp>
27+
#include <cpprealm/types.hpp>
2528

2629
#include <cpprealm/internal/bridge/sync_session.hpp>
2730
#include <cpprealm/internal/bridge/thread_safe_reference.hpp>
2831
#include <cpprealm/internal/bridge/sync_session.hpp>
2932

30-
#include <cpprealm/scheduler.hpp>
31-
32-
#include <cpprealm/macros.hpp>
33-
#include <cpprealm/results.hpp>
34-
#include <cpprealm/types.hpp>
35-
3633
#include <filesystem>
3734
#include <optional>
3835
#include <string>

include/cpprealm/internal/bridge/status.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace realm::internal::bridge {
6161
};
6262

6363
struct status {
64-
64+
static status ok();
6565
status(const ::realm::Status&);
6666
status(::realm::Status&&);
6767
status(const status&);
@@ -73,7 +73,7 @@ namespace realm::internal::bridge {
7373
bool is_ok() const noexcept;
7474
const std::string& reason() const noexcept;
7575
std::string_view code_string() const noexcept;
76-
76+
operator ::realm::Status() const noexcept;
7777
private:
7878
#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
7979
storage::Status m_status[1];

include/cpprealm/internal/generic_network_transport.hpp

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright 2024 Realm Inc.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
////////////////////////////////////////////////////////////////////////////
18+
19+
#ifndef CPPREALM_SHIMS_HPP
20+
#define CPPREALM_SHIMS_HPP
21+
22+
#include <cpprealm/networking/http.hpp>
23+
#include <cpprealm/networking/websocket.hpp>
24+
25+
namespace realm {
26+
namespace sync {
27+
class SyncSocketProvider;
28+
}
29+
namespace app {
30+
struct GenericNetworkTransport;
31+
}
32+
}
33+
34+
namespace realm::internal::networking {
35+
std::shared_ptr<app::GenericNetworkTransport> create_http_client_shim(const std::shared_ptr<::realm::networking::http_transport_client>&);
36+
std::unique_ptr<::realm::sync::SyncSocketProvider> create_sync_socket_provider_shim(const std::shared_ptr<::realm::networking::sync_socket_provider>& provider);
37+
}
38+
39+
#endif //CPPREALM_SHIMS_HPP
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright 2024 Realm Inc.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
////////////////////////////////////////////////////////////////////////////
18+
19+
#ifndef CPPREALM_NETWORKING_UTILS_HPP
20+
#define CPPREALM_NETWORKING_UTILS_HPP
21+
22+
#include <cpprealm/networking/websocket.hpp>
23+
24+
#include <optional>
25+
26+
namespace realm {
27+
namespace app {
28+
struct Request;
29+
struct Response;
30+
}
31+
namespace sync {
32+
struct WebSocketEndpoint;
33+
}
34+
35+
namespace networking {
36+
struct request;
37+
struct response;
38+
}
39+
}
40+
41+
namespace realm::internal::networking {
42+
::realm::networking::request to_request(const ::realm::app::Request&);
43+
::realm::app::Response to_core_response(const ::realm::networking::response&);
44+
45+
::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::websocket_endpoint& ep,
46+
const std::optional<::realm::networking::default_socket_provider::configuration>& config);
47+
::realm::networking::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& ep);
48+
} //namespace realm::internal::networking
49+
50+
#endif //CPPREALM_NETWORKING_UTILS_HPP

0 commit comments

Comments
 (0)