Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Jul 16, 2024
1 parent 8ec6316 commit 97ea134
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 157 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ NEXT-RELEASE Release notes (YYYY-MM-DD)
* Add `default_socket_provider` a built-in class for providing the components necessary for transport via WebSocket.
* A custom WebSocket & HTTP transport implementation can be used by passing
the instance via `realm::app::App::configuration.http_transport_client` & `realm::app::App::configuration.sync_socket_provider`.
* Proxy and custom header configuration for built-in transport must be supplied via the constructor on
`realm::networking::default_http_transport` & `realm::networking::default_socket_provider` using the
`realm::networking::default_transport_configuration` struct.
* Network configuration for the built-in http transport must be supplied via it's constructor using the
`realm::networking::default_http_transport::configuration` struct.
* Network configuration for the built-in websocket provider must be supplied via it's constructor using the
`realm::networking::default_socket_provider::configuration` struct.

### Deprecations
* Proxy and custom http headers should no longer be set via `realm::app::App::configuration`.

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

### Internals
* None
* Upgraded to Core v14.10.4

2.1.0 Release notes (2024-06-27)
=============================================================
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PackageDescription

let sdkVersion = Version("2.1.0")
let coreVersion = Version("14.9.0")
let coreVersion = Version("14.10.4")

var cxxSettings: [CXXSetting] = [
.define("REALM_ENABLE_SYNC", to: "1"),
Expand Down
1 change: 0 additions & 1 deletion include/cpprealm/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <cpprealm/internal/bridge/sync_session.hpp>
#include <cpprealm/internal/bridge/utils.hpp>
#include <cpprealm/networking/http.hpp>
#include <cpprealm/networking/networking.hpp>
#include <cpprealm/networking/websocket.hpp>

#include <future>
Expand Down
4 changes: 2 additions & 2 deletions include/cpprealm/internal/networking/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace realm::internal::networking {
::realm::networking::request to_request(const ::realm::app::Request&);
::realm::app::Response to_core_response(const ::realm::networking::response&);

::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::sync_socket_provider::websocket_endpoint& ep,
::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::websocket_endpoint& ep,
const std::optional<::realm::networking::default_socket_provider::configuration>& config);
::realm::networking::sync_socket_provider::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& ep);
::realm::networking::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& ep);
} //namespace realm::internal::networking

#endif //CPPREALM_NETWORKING_UTILS_HPP
74 changes: 73 additions & 1 deletion include/cpprealm/networking/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,89 @@
#ifndef CPPREALM_NETWORKING_HTTP_HPP
#define CPPREALM_NETWORKING_HTTP_HPP

#include <cpprealm/networking/networking.hpp>
#include <cpprealm/internal/bridge/realm.hpp>

#ifndef REALMCXX_VERSION_MAJOR
#include <cpprealm/version_numbers.hpp>
#endif

#include <optional>
#include <map>
#include <string>

namespace realm::networking {

/**
* A HTTP method type.
*/
enum class http_method { get, post, patch, put, del };
/**
* Request/Response headers type
*/
using http_headers = std::map<std::string, std::string>;

/**
* An HTTP request that can be made to an arbitrary server.
*/
struct request {
/**
* The HTTP method of this request.
*/
http_method method = http_method::get;

/**
* The URL to which this request will be made.
*/
std::string url;

/**
* The number of milliseconds that the underlying transport should spend on an HTTP round trip before failing with
* an error.
*/
uint64_t timeout_ms = 0;

/**
* The HTTP headers of this request - keys are case insensitive.
*/
http_headers headers;

/**
* The body of the request.
*/
std::string body;
};

/**
* The contents of an HTTP response.
*/
struct response {
/**
* The status code of the HTTP response.
*/
int http_status_code;

/**
* A custom status code provided by the language binding (SDK).
*/
int custom_status_code;

/**
* The headers of the HTTP response - keys are case insensitive.
*/
http_headers headers;

/**
* The body of the HTTP response.
*/
std::string body;

/**
* An error code used by the client to report http processing errors.
*/
std::optional<std::int32_t> client_error_code;

};

// Interface for providing http transport
struct http_transport_client {
virtual ~http_transport_client() = default;
Expand Down
100 changes: 0 additions & 100 deletions include/cpprealm/networking/networking.hpp

This file was deleted.

77 changes: 38 additions & 39 deletions include/cpprealm/networking/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef CPPREALM_NETWORKING_WEBSOCKET_HPP
#define CPPREALM_NETWORKING_WEBSOCKET_HPP

#include <cpprealm/networking/networking.hpp>
#include <cpprealm/internal/bridge/status.hpp>
#include <cpprealm/internal/bridge/realm.hpp>

Expand All @@ -44,6 +43,43 @@ namespace realm {

namespace realm::networking {

struct websocket_endpoint {
/// Array of one or more websocket protocols.
std::vector<std::string> protocols;
/// The websocket url to connect to.
std::string url;
};

enum class websocket_err_codes {
ok = 1000,
going_away = 1001,
protocol_error = 1002,
unsupported_data = 1003,
websocket_reserved = 1004,
no_status_received = 1005,
abnormal_closure = 1006,
invalid_payload_data = 1007,
policy_violation = 1008,
message_too_big = 1009,
invalid_extension = 1010,
invalid_server_error = 1011,
TLS_handshake_failed = 1015,

unauthorized = 4001,
forbidden = 4002,
moved_permanently = 4003,
client_too_old = 4004,
client_too_new = 4005,
protocol_mismatch = 4006,

resolve_failed = 4400,
connection_failed = 4401,
read_error = 4402,
write_error = 4403,
retry_error = 4404,
fata_error = 4405,
};

using status = ::realm::internal::bridge::status;
struct websocket_interface;
struct websocket_observer;
Expand Down Expand Up @@ -76,43 +112,6 @@ namespace realm::networking {
class sync_socket_provider {
public:

struct websocket_endpoint {
/// Array of one or more websocket protocols.
std::vector<std::string> protocols;
/// The websocket url to connect to.
std::string url;
};

enum websocket_err_codes {
RLM_ERR_WEBSOCKET_OK = 1000,
RLM_ERR_WEBSOCKET_GOINGAWAY = 1001,
RLM_ERR_WEBSOCKET_PROTOCOLERROR = 1002,
RLM_ERR_WEBSOCKET_UNSUPPORTEDDATA = 1003,
RLM_ERR_WEBSOCKET_RESERVED = 1004,
RLM_ERR_WEBSOCKET_NOSTATUSRECEIVED = 1005,
RLM_ERR_WEBSOCKET_ABNORMALCLOSURE = 1006,
RLM_ERR_WEBSOCKET_INVALIDPAYLOADDATA = 1007,
RLM_ERR_WEBSOCKET_POLICYVIOLATION = 1008,
RLM_ERR_WEBSOCKET_MESSAGETOOBIG = 1009,
RLM_ERR_WEBSOCKET_INAVALIDEXTENSION = 1010,
RLM_ERR_WEBSOCKET_INTERNALSERVERERROR = 1011,
RLM_ERR_WEBSOCKET_TLSHANDSHAKEFAILED = 1015,

RLM_ERR_WEBSOCKET_UNAUTHORIZED = 4001,
RLM_ERR_WEBSOCKET_FORBIDDEN = 4002,
RLM_ERR_WEBSOCKET_MOVEDPERMANENTLY = 4003,
RLM_ERR_WEBSOCKET_CLIENT_TOO_OLD = 4004,
RLM_ERR_WEBSOCKET_CLIENT_TOO_NEW = 4005,
RLM_ERR_WEBSOCKET_PROTOCOL_MISMATCH = 4006,

RLM_ERR_WEBSOCKET_RESOLVE_FAILED = 4400,
RLM_ERR_WEBSOCKET_CONNECTION_FAILED = 4401,
RLM_ERR_WEBSOCKET_READ_ERROR = 4402,
RLM_ERR_WEBSOCKET_WRITE_ERROR = 4403,
RLM_ERR_WEBSOCKET_RETRY_ERROR = 4404,
RLM_ERR_WEBSOCKET_FATAL_ERROR = 4405,
};

/// Function handler typedef
using FunctionHandler = std::function<void(status)>;

Expand Down Expand Up @@ -260,7 +259,7 @@ namespace realm::networking {
/// True to indicate the WebSocket object is no longer valid. If False
/// is returned, the WebSocket object will be destroyed at some point
/// in the future.
virtual bool websocket_closed_handler(bool was_clean, sync_socket_provider::websocket_err_codes error_code,
virtual bool websocket_closed_handler(bool was_clean, websocket_err_codes error_code,
std::string_view message) = 0;
};

Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ set(HEADERS
../include/cpprealm/internal/networking/utils.hpp
../include/cpprealm/internal/scheduler/realm_core_scheduler.hpp
../include/cpprealm/schedulers/default_scheduler.hpp
../include/cpprealm/networking/networking.hpp
../include/cpprealm/networking/http.hpp
../include/cpprealm/networking/websocket.hpp
../include/cpprealm/logger.hpp
Expand Down
1 change: 0 additions & 1 deletion src/cpprealm/internal/network/network_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#endif
#include <cpprealm/app.hpp>
#include <cpprealm/networking/http.hpp>
#include <cpprealm/networking/networking.hpp>

#include <realm/object-store/sync/generic_network_transport.hpp>
#include <realm/sync/network/http.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/cpprealm/internal/networking/shims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace realm::internal::networking {
return m_observer->websocket_binary_message_received(data);
}

bool websocket_closed_handler(bool was_clean, ::realm::networking::sync_socket_provider::websocket_err_codes error_code,
bool websocket_closed_handler(bool was_clean, ::realm::networking::websocket_err_codes error_code,
std::string_view message) override {
return m_observer->websocket_closed_handler(was_clean, static_cast<::realm::sync::websocket::WebSocketError>(error_code), message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpprealm/internal/networking/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace realm::internal::networking {
REALM_TERMINATE("Unrecognized websocket protocol");
}

::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::sync_socket_provider::websocket_endpoint& ep,
::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::websocket_endpoint& ep,
const std::optional<::realm::networking::default_socket_provider::configuration>& config) {
::realm::sync::WebSocketEndpoint core_ep;
auto uri = util::Uri(ep.url);
Expand Down Expand Up @@ -90,8 +90,8 @@ namespace realm::internal::networking {
return core_ep;
}

::realm::networking::sync_socket_provider::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& core_ep) {
::realm::networking::sync_socket_provider::websocket_endpoint ep;
::realm::networking::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& core_ep) {
::realm::networking::websocket_endpoint ep;
ep.protocols = core_ep.protocols;
const auto& port = core_ep.proxy ? core_ep.proxy->port : core_ep.port;
ep.url = util::format("%1://%2:%3%4", core_ep.is_ssl ? "wss" : "ws", core_ep.address, port, core_ep.path);
Expand Down
Loading

0 comments on commit 97ea134

Please sign in to comment.