Skip to content
Merged
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
2 changes: 2 additions & 0 deletions olp-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ set(OLP_SDK_GENERATED_HEADERS
)

set(OLP_SDK_HTTP_HEADERS
./include/olp/core/http/CertificateSettings.h
./include/olp/core/http/HttpStatusCode.h
./include/olp/core/http/Network.h
./include/olp/core/http/HttpStatusCode.h
./include/olp/core/http/NetworkConstants.h
./include/olp/core/http/NetworkInitializationSettings.h
./include/olp/core/http/NetworkProxySettings.h
./include/olp/core/http/NetworkRequest.h
./include/olp/core/http/NetworkResponse.h
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,15 @@
#pragma once

#include <memory>
#include <string>

#include <olp/core/CoreApi.h>
#include <olp/core/http/Network.h>
#include <olp/core/thread/TaskScheduler.h>
#include <boost/optional.hpp>

#include "olp/core/CoreApi.h"
#include "olp/core/http/Network.h"
#include "olp/core/http/NetworkInitializationSettings.h"
#include "olp/core/thread/TaskScheduler.h"

namespace olp {
namespace cache {
class KeyValueCache;
Expand Down Expand Up @@ -74,6 +77,29 @@ class CORE_API OlpClientSettingsFactory final {
static std::shared_ptr<http::Network> CreateDefaultNetworkRequestHandler(
size_t max_requests_count = 30u);

/**
* @brief Creates the `Network` instance used for all the non-local requests.
*
* Defaulted to platform-specific implementation.
*
* On UNIX platforms, the default network request handler is libcurl-based and
* has the known issue of static initialization and cleanup that needs special
* care. Therefore, we recommend initializing this network request handler at
* a very early stage, preferably as global static or from the main thread,
* and pass it on to every created client. For this matter, it is also not
* recommended to create multiple network request handlers.
*
* @see [cURL documentation]
* (Lhttps://curl.haxx.se/libcurl/c/curl_global_init.html) for more
* information.
*
* @param[in] settings The `NetworkInitializationSettings` instance.
*
* @return The `Network` instance.
*/
static std::shared_ptr<http::Network> CreateDefaultNetworkRequestHandler(
http::NetworkInitializationSettings settings);

/**
* @brief Creates the `KeyValueCache` instance that includes both a small
* memory LRU cache and a larger persistent database cache.
Expand Down
50 changes: 50 additions & 0 deletions olp-cpp-sdk-core/include/olp/core/http/CertificateSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

#pragma once

#include <string>

#include "olp/core/CoreApi.h"

namespace olp {
namespace http {

/**
* @brief Settings for custom network certificate.
*/
struct CORE_API CertificateSettings {
/**
* @brief The client certificate file as blob.
*/
std::string client_cert_file_blob;

/**
* @brief The client key file as blob.
*/
std::string client_key_file_blob;

/**
* @brief The CA file as blob.
*/
std::string cert_file_blob;
};

} // namespace http
} // namespace olp
18 changes: 13 additions & 5 deletions olp-cpp-sdk-core/include/olp/core/http/Network.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 HERE Europe B.V.
* Copyright (C) 2019-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,10 +24,11 @@
#include <memory>
#include <string>

#include <olp/core/CoreApi.h>
#include <olp/core/http/NetworkRequest.h>
#include <olp/core/http/NetworkResponse.h>
#include <olp/core/http/NetworkTypes.h>
#include "olp/core/CoreApi.h"
#include "olp/core/http/NetworkInitializationSettings.h"
#include "olp/core/http/NetworkRequest.h"
#include "olp/core/http/NetworkResponse.h"
#include "olp/core/http/NetworkTypes.h"

namespace olp {
/// Provides a platform specific network abstraction layer.
Expand Down Expand Up @@ -147,8 +148,15 @@ class CORE_API Network {
};

/// Creates a default `Network` implementation.
OLP_SDK_DEPRECATED(
"Will be removed by 05.2024, use "
"CreateDefaultNetwork(NetworkInitializationSettings) instead")
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
size_t max_requests_count);

/// Creates a default `Network` implementation.
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
NetworkInitializationSettings settings);

} // namespace http
} // namespace olp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

#pragma once

#include "olp/core/CoreApi.h"
#include "olp/core/http/CertificateSettings.h"

namespace olp {
namespace http {

/**
* @brief Settings for network initialization.
*/
struct CORE_API NetworkInitializationSettings {
/**
* @brief The maximum number of requests that can be sent simultaneously.
*/
size_t max_requests_count = 30u;

/**
* @brief The custom certificate settings.
*/
CertificateSettings certificate_settings;
};

} // namespace http
} // namespace olp
11 changes: 10 additions & 1 deletion olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "olp/core/cache/DefaultCache.h"
#include "olp/core/client/OlpClientSettings.h"
#include "olp/core/http/NetworkConstants.h"
#include "olp/core/http/NetworkInitializationSettings.h"
#include "olp/core/logging/Log.h"
#include "olp/core/porting/make_unique.h"
#include "olp/core/thread/ThreadPoolTaskScheduler.h"
Expand All @@ -43,7 +44,15 @@ OlpClientSettingsFactory::CreateDefaultTaskScheduler(size_t thread_count) {
std::shared_ptr<http::Network>
OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
size_t max_requests_count) {
return http::CreateDefaultNetwork(max_requests_count);
http::NetworkInitializationSettings settings;
settings.max_requests_count = max_requests_count;
return CreateDefaultNetworkRequestHandler(std::move(settings));
}

std::shared_ptr<http::Network>
OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
http::NetworkInitializationSettings settings) {
return http::CreateDefaultNetwork(std::move(settings));
}

std::unique_ptr<cache::KeyValueCache>
Expand Down
24 changes: 16 additions & 8 deletions olp-cpp-sdk-core/src/http/Network.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 HERE Europe B.V.
* Copyright (C) 2019-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,16 +36,17 @@ namespace olp {
namespace http {

namespace {
std::shared_ptr<Network> CreateDefaultNetworkImpl(size_t max_requests_count) {
OLP_SDK_CORE_UNUSED(max_requests_count);
std::shared_ptr<Network> CreateDefaultNetworkImpl(
NetworkInitializationSettings settings) {
OLP_SDK_CORE_UNUSED(settings);
#ifdef OLP_SDK_NETWORK_HAS_CURL
return std::make_shared<NetworkCurl>(max_requests_count);
return std::make_shared<NetworkCurl>(settings);
#elif OLP_SDK_NETWORK_HAS_ANDROID
return std::make_shared<NetworkAndroid>(max_requests_count);
return std::make_shared<NetworkAndroid>(settings.max_requests_count);
#elif OLP_SDK_NETWORK_HAS_IOS
return std::make_shared<OLPNetworkIOS>(max_requests_count);
return std::make_shared<OLPNetworkIOS>(settings.max_requests_count);
#elif OLP_SDK_NETWORK_HAS_WINHTTP
return std::make_shared<NetworkWinHttp>(max_requests_count);
return std::make_shared<NetworkWinHttp>(settings.max_requests_count);
#else
static_assert(false, "No default network implementation provided");
#endif
Expand All @@ -61,7 +62,14 @@ Network::Statistics Network::GetStatistics(uint8_t /*bucket_id*/) {
}

std::shared_ptr<Network> CreateDefaultNetwork(size_t max_requests_count) {
auto network = CreateDefaultNetworkImpl(max_requests_count);
NetworkInitializationSettings settings;
settings.max_requests_count = max_requests_count;
return CreateDefaultNetwork(std::move(settings));
}

std::shared_ptr<Network> CreateDefaultNetwork(
NetworkInitializationSettings settings) {
auto network = CreateDefaultNetworkImpl(std::move(settings));
if (network) {
return std::make_shared<DefaultNetwork>(network);
}
Expand Down
Loading