From e20fd4e880b5632d08bdf1fc75bd1db464b43c9b Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Wed, 2 Mar 2022 17:13:40 -0800 Subject: [PATCH 1/6] removing binary dependcy from odbc project --- src/odbc/CMakeLists.txt | 4 ++-- src/odbc/include/ignite/odbc/meta/column_meta.h | 2 +- src/odbc/include/ignite/odbc/meta/primary_key_meta.h | 2 +- src/odbc/include/ignite/odbc/meta/table_meta.h | 2 +- src/odbc/src/query/type_info_query.cpp | 3 +-- src/odbc/src/streaming/streaming_batch.cpp | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/odbc/CMakeLists.txt b/src/odbc/CMakeLists.txt index 52a2ac936..22ede7f6b 100644 --- a/src/odbc/CMakeLists.txt +++ b/src/odbc/CMakeLists.txt @@ -154,7 +154,7 @@ if (WIN32) add_definitions(-DNOMINMAX) endif() - target_link_libraries(${TARGET} ignite-common-objlib ignite-binary-objlib ignite-network-objlib odbccp32 shlwapi) + target_link_libraries(${TARGET} ignite-common-objlib ignite-network-objlib odbccp32 shlwapi) remove_definitions(-DUNICODE=1) @@ -166,7 +166,7 @@ if (WIN32) set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME "ignite.odbc") else() - target_link_libraries(${TARGET} ignite-common ignite-binary ignite-network) + target_link_libraries(${TARGET} ignite-common ignite-network) endif() if (WIN32 AND ${WITH_ODBC_MSI}) diff --git a/src/odbc/include/ignite/odbc/meta/column_meta.h b/src/odbc/include/ignite/odbc/meta/column_meta.h index af548354e..99a494b0c 100644 --- a/src/odbc/include/ignite/odbc/meta/column_meta.h +++ b/src/odbc/include/ignite/odbc/meta/column_meta.h @@ -22,7 +22,7 @@ #include -#include "ignite/impl/binary/binary_reader_impl.h" +#include "ignite/odbc/impl/binary/binary_reader_impl.h" #include "ignite/odbc/common_types.h" #include "ignite/odbc/jni/result_set.h" #include "ignite/odbc/protocol_version.h" diff --git a/src/odbc/include/ignite/odbc/meta/primary_key_meta.h b/src/odbc/include/ignite/odbc/meta/primary_key_meta.h index 617a6faf3..dcceb01f3 100644 --- a/src/odbc/include/ignite/odbc/meta/primary_key_meta.h +++ b/src/odbc/include/ignite/odbc/meta/primary_key_meta.h @@ -22,7 +22,7 @@ #include -#include "ignite/impl/binary/binary_reader_impl.h" +#include "ignite/odbc/impl/binary/binary_reader_impl.h" #include "ignite/odbc/utility.h" namespace ignite { diff --git a/src/odbc/include/ignite/odbc/meta/table_meta.h b/src/odbc/include/ignite/odbc/meta/table_meta.h index a0b085699..7d3395f06 100644 --- a/src/odbc/include/ignite/odbc/meta/table_meta.h +++ b/src/odbc/include/ignite/odbc/meta/table_meta.h @@ -22,7 +22,7 @@ #include -#include "ignite/impl/binary/binary_reader_impl.h" +#include "ignite/odbc/impl/binary/binary_reader_impl.h" #include "ignite/odbc/jni/result_set.h" #include "ignite/odbc/utility.h" diff --git a/src/odbc/src/query/type_info_query.cpp b/src/odbc/src/query/type_info_query.cpp index 7a91a0191..ee2535656 100644 --- a/src/odbc/src/query/type_info_query.cpp +++ b/src/odbc/src/query/type_info_query.cpp @@ -120,7 +120,7 @@ TypeInfoQuery::TypeInfoQuery(diagnostic::DiagnosableAdapter& diag, fetched(false), types(), cursor(types.end()) { - using namespace ignite::impl::binary; + using namespace ignite::odbc::impl::binary; using namespace ignite::odbc::impl::binary; using namespace ignite::odbc::type_traits; @@ -245,7 +245,6 @@ SqlResult::Type TypeInfoQuery::FetchNextRow( SqlResult::Type TypeInfoQuery::GetColumn(uint16_t columnIdx, app::ApplicationDataBuffer& buffer) { - using namespace ignite::impl::binary; using namespace ignite::odbc::impl::binary; if (!executed) { diff --git a/src/odbc/src/streaming/streaming_batch.cpp b/src/odbc/src/streaming/streaming_batch.cpp index 06ae5b5ae..aeddf6543 100644 --- a/src/odbc/src/streaming/streaming_batch.cpp +++ b/src/odbc/src/streaming/streaming_batch.cpp @@ -17,8 +17,8 @@ #include "ignite/odbc/streaming/streaming_batch.h" -#include "ignite/impl/binary/binary_writer_impl.h" -#include "ignite/impl/interop/interop_output_stream.h" +#include "ignite/odbc/impl/binary/binary_writer_impl.h" +#include "ignite/odbc/impl/interop/interop_output_stream.h" #include "ignite/odbc/app/parameter_set.h" namespace ignite { From fa1b9c9f85f852e2442b0174e09f40fad50eedf5 Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Wed, 2 Mar 2022 17:36:01 -0800 Subject: [PATCH 2/6] removing extra warnings --- src/common/os/win/include/ignite/common/common.h | 6 +++--- src/odbc/include/ignite/odbc/config/connection_info.h | 2 +- src/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h | 2 +- .../ignite/odbc/diagnostic/diagnostic_record_storage.h | 2 +- src/odbc/src/entry_points.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/os/win/include/ignite/common/common.h b/src/common/os/win/include/ignite/common/common.h index e7cda4b52..3ef9574e3 100644 --- a/src/common/os/win/include/ignite/common/common.h +++ b/src/common/os/win/include/ignite/common/common.h @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef _IGNITE_COMMON_COMMON -#define _IGNITE_COMMON_COMMON +#ifndef _IGNITE_ODBC_COMMON_COMMON +#define _IGNITE_ODBC_COMMON_COMMON #define IGNITE_EXPORT __declspec(dllexport) #define IGNITE_IMPORT __declspec(dllimport) @@ -43,4 +43,4 @@ #define IGNITE_UNUSED(x) ((void) x) -#endif //_IGNITE_COMMON_COMMON \ No newline at end of file +#endif //_IGNITE_ODBC_COMMON_COMMON \ No newline at end of file diff --git a/src/odbc/include/ignite/odbc/config/connection_info.h b/src/odbc/include/ignite/odbc/config/connection_info.h index a7054cf92..870f2e108 100644 --- a/src/odbc/include/ignite/odbc/config/connection_info.h +++ b/src/odbc/include/ignite/odbc/config/connection_info.h @@ -18,7 +18,7 @@ #ifndef _IGNITE_ODBC_CONFIG_CONNECTION_INFO #define _IGNITE_ODBC_CONFIG_CONNECTION_INFO -#include +#include #include #include #include diff --git a/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h b/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h index db7b376c4..e8be3ed67 100644 --- a/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h +++ b/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h @@ -18,7 +18,7 @@ #ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD #define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD -#include +#include #include #include diff --git a/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h b/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h index 9b754e0ea..5bc352c58 100644 --- a/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h +++ b/src/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h @@ -18,7 +18,7 @@ #ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD_STORAGE #define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD_STORAGE -#include +#include #include #include diff --git a/src/odbc/src/entry_points.cpp b/src/odbc/src/entry_points.cpp index 6f7dcbf82..8aec05039 100644 --- a/src/odbc/src/entry_points.cpp +++ b/src/odbc/src/entry_points.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include +#include #include "ignite/odbc.h" #include "ignite/odbc/log.h" From 07ca8ea5e87162e8442e93a5fcb33b1368f52c19 Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Wed, 2 Mar 2022 18:13:28 -0800 Subject: [PATCH 3/6] removing build warning, removing network project --- src/CMakeLists.txt | 5 - src/common/include/ignite/ignite_error.h | 6 +- src/ignite/CMakeLists.txt | 32 - src/ignite/src/ignite.cpp | 224 ------ src/network/CMakeLists.txt | 99 --- .../include/ignite/network/end_point.h | 157 ---- src/network/include/ignite/network/network.h | 62 -- .../include/ignite/network/socket_client.h | 115 --- .../include/ignite/network/tcp_range.h | 171 ----- src/network/include/ignite/network/utils.h | 42 -- src/network/os/linux/src/network/sockets.cpp | 115 --- src/network/os/linux/src/network/sockets.h | 83 -- .../linux/src/network/tcp_socket_client.cpp | 227 ------ src/network/os/linux/src/network/utils.cpp | 103 --- src/network/os/win/src/network/sockets.cpp | 137 ---- src/network/os/win/src/network/sockets.h | 89 --- .../os/win/src/network/tcp_socket_client.cpp | 257 ------- src/network/os/win/src/network/utils.cpp | 100 --- src/network/src/network/network.cpp | 51 -- .../src/network/ssl/secure_socket_client.cpp | 402 ---------- .../src/network/ssl/secure_socket_client.h | 191 ----- src/network/src/network/ssl/ssl_gateway.cpp | 710 ------------------ src/network/src/network/ssl/ssl_gateway.h | 277 ------- src/network/src/network/tcp_socket_client.h | 135 ---- src/odbc-test/CMakeLists.txt | 1 - src/odbc-test/src/connection_test.cpp | 1 + src/odbc/CMakeLists.txt | 4 +- 27 files changed, 6 insertions(+), 3790 deletions(-) delete mode 100644 src/ignite/CMakeLists.txt delete mode 100644 src/ignite/src/ignite.cpp delete mode 100644 src/network/CMakeLists.txt delete mode 100644 src/network/include/ignite/network/end_point.h delete mode 100644 src/network/include/ignite/network/network.h delete mode 100644 src/network/include/ignite/network/socket_client.h delete mode 100644 src/network/include/ignite/network/tcp_range.h delete mode 100644 src/network/include/ignite/network/utils.h delete mode 100644 src/network/os/linux/src/network/sockets.cpp delete mode 100644 src/network/os/linux/src/network/sockets.h delete mode 100644 src/network/os/linux/src/network/tcp_socket_client.cpp delete mode 100644 src/network/os/linux/src/network/utils.cpp delete mode 100644 src/network/os/win/src/network/sockets.cpp delete mode 100644 src/network/os/win/src/network/sockets.h delete mode 100644 src/network/os/win/src/network/tcp_socket_client.cpp delete mode 100644 src/network/os/win/src/network/utils.cpp delete mode 100644 src/network/src/network/network.cpp delete mode 100644 src/network/src/network/ssl/secure_socket_client.cpp delete mode 100644 src/network/src/network/ssl/secure_socket_client.h delete mode 100644 src/network/src/network/ssl/ssl_gateway.cpp delete mode 100644 src/network/src/network/ssl/ssl_gateway.h delete mode 100644 src/network/src/network/tcp_socket_client.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64e99b195..7bfc8c74b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,7 +84,6 @@ add_subdirectory(binary) if (${WITH_CORE} OR ${WITH_TESTS}) add_subdirectory(core) - add_subdirectory(ignite) endif() if (${WITH_TESTS}) @@ -99,10 +98,6 @@ if (${WITH_TESTS}) endif() endif() -if (${WITH_ODBC}) - add_subdirectory(network) -endif() - if (${WITH_ODBC}) add_subdirectory(odbc) diff --git a/src/common/include/ignite/ignite_error.h b/src/common/include/ignite/ignite_error.h index 0c402d42b..d07a36a71 100644 --- a/src/common/include/ignite/ignite_error.h +++ b/src/common/include/ignite/ignite_error.h @@ -20,8 +20,8 @@ * Declares ignite::IgniteError class. */ -#ifndef _IGNITE_IGNITE_ERROR -#define _IGNITE_IGNITE_ERROR +#ifndef _IGNITE_ODBC_IGNITE_ERROR +#define _IGNITE_ODBC_IGNITE_ERROR #include @@ -310,4 +310,4 @@ namespace ignite # pragma warning(pop) #endif //_MSC_VER -#endif //_IGNITE_IGNITE_ERROR +#endif //_IGNITE_ODBC_IGNITE_ERROR diff --git a/src/ignite/CMakeLists.txt b/src/ignite/CMakeLists.txt deleted file mode 100644 index 27cf7df75..000000000 --- a/src/ignite/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# - -project(ignite-bin) - -set(TARGET ignite-bin) - -include_directories(SYSTEM ${JNI_INCLUDE_DIRS}) - -set(SOURCES src/ignite.cpp) - -add_executable(${TARGET} ${SOURCES}) - -target_link_libraries(${TARGET} ignite) - -set_target_properties(ignite-bin PROPERTIES OUTPUT_NAME ignite) - -install(TARGETS ${TARGET} RUNTIME DESTINATION bin) diff --git a/src/ignite/src/ignite.cpp b/src/ignite/src/ignite.cpp deleted file mode 100644 index 5823fcd57..000000000 --- a/src/ignite/src/ignite.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include -#include -#include -#include -#include - -#include "ignite/ignite_configuration.h" -#include "ignite/ignition.h" -#include "ignite/common/utils.h" - -typedef std::list StringList; -typedef std::set StringSet; - -namespace config -{ - using ignite::common::ToLower; - - /** Command line argument: Ignite home. */ - const std::string CmdIgniteHome = ToLower("-IgniteHome="); - - /** Command line argument: Spring config URL. */ - const std::string CmdSpringCfgUrl = ToLower("-SpringConfigUrl="); - - /** Command line argument: Path to JVM library. */ - const std::string CmdJvmLib = ToLower("-JvmLibPath="); - - /** Command line argument: JVM classpath. */ - const std::string CmdJvmClasspath = ToLower("-JvmClasspath="); - - /** Command line argument: JVM option prefix. */ - const std::string CmdJvmOpt = ToLower("-J"); - - /** Command line argument: JvmInitialMemoryMB. */ - const std::string CmdJvmMinMem = ToLower("-JvmInitialMemoryMB="); - - /** Command line argument: JvmMaxMemoryMB. */ - const std::string CmdJvmMaxMem = ToLower("-JvmMaxMemoryMB="); - - /** - * Convert configuration to arguments. - * - * @param cfg Input configuration. - * @param args Output arguments. - */ - void ToArgs(const ignite::IgniteConfiguration& cfg, StringList& args) - { - using ignite::common::LongToString; - - if (!cfg.igniteHome.empty()) - args.push_back(CmdIgniteHome + cfg.igniteHome); - - if (cfg.springCfgPath.empty()) - args.push_back(CmdSpringCfgUrl + cfg.springCfgPath); - - if (cfg.jvmLibPath.empty()) - args.push_back(CmdJvmLib + cfg.jvmLibPath); - - if (cfg.jvmClassPath.empty()) - args.push_back(CmdJvmClasspath + cfg.jvmClassPath); - - if (cfg.jvmOpts.empty()) - { - for (StringList::const_iterator i = cfg.jvmOpts.begin(); i != cfg.jvmOpts.end(); ++i) - args.push_back(CmdJvmOpt + *i); - } - - args.push_back(CmdJvmMinMem + LongToString(cfg.jvmInitMem)); - args.push_back(CmdJvmMaxMem + LongToString(cfg.jvmMaxMem)); - } - - /** - * Convert arguments to configuration. - * - * @param cfg Output configuration. - * @param src Input arguments. - */ - void Configure(ignite::IgniteConfiguration& cfg, const StringList& src) - { - using ignite::common::ParseInt; - - StringList jvmOpts; - - for (StringList::const_iterator i = src.begin(); i != src.end(); ++i) - { - const std::string& arg = *i; - - std::string argLow = ToLower(arg); - - if (argLow.find(CmdIgniteHome) == 0) - cfg.igniteHome = arg.substr(CmdIgniteHome.size()); - else if (argLow.find(CmdSpringCfgUrl) == 0) - cfg.springCfgPath = arg.substr(CmdSpringCfgUrl.size()); - else if (argLow.find(CmdJvmLib) == 0) - cfg.jvmLibPath = arg.substr(CmdJvmLib.size()); - else if (argLow.find(CmdJvmClasspath) == 0) - cfg.jvmClassPath = arg.substr(CmdJvmClasspath.size()); - else if (argLow.find(CmdJvmMinMem) == 0) - cfg.jvmInitMem = ParseInt(arg.substr(CmdJvmMinMem.size())); - else if (argLow.find(CmdJvmMaxMem) == 0) - cfg.jvmMaxMem = ParseInt(arg.substr(CmdJvmMaxMem.size())); - else if (argLow.find(CmdJvmOpt) == 0) - jvmOpts.push_back(arg.substr(CmdJvmOpt.size())); - else - { - std::cout << "WARNING: unknown argument \"" << arg << "\"." - << "Type --help for the list of supported arguments." << std::endl; - } - } - - if (!jvmOpts.empty()) - { - if (!cfg.jvmOpts.empty()) - cfg.jvmOpts.swap(jvmOpts); - else - std::copy(jvmOpts.begin(), jvmOpts.end(), std::back_insert_iterator(cfg.jvmOpts)); - } - } -} - - -/** - * Prints help to standard output. - */ -void PrintHelp() -{ - std::cout << "Usage: ignite [-options]" << std::endl; - std::cout << std::endl; - std::cout << "Options:" << std::endl; - std::cout << "\t-igniteHome path to Ignite installation directory (if not provided IGNITE_HOME environment variable is used)" << std::endl; - std::cout << "\t-springConfigUrl path to spring configuration file (if not provided \"config/default-config.xml\" is used)" << std::endl; - std::cout << "\t-jvmLibPath path to JVM library (if not provided JAVA_HOME environment variable is used)" << std::endl; - std::cout << "\t-jvmClasspath classpath passed to JVM (enlist additional jar files here)" << std::endl; - std::cout << "\t-J JVM options passed to created JVM" << std::endl; - std::cout << "\t-jvmInitialMemoryMB Initial Java heap size, in megabytes. Maps to -Xms Java parameter. Defaults to 512." << std::endl; - std::cout << "\t-jvmMaxMemoryMB Maximum Java heap size, in megabytes. Maps to -Xmx Java parameter. Defaults to 1024." << std::endl; - std::cout << std::endl; - std::cout << "Examples:" << std::endl; - std::cout << "\tignite -J-Xms1024m -J-Xmx1024m -springConfigUrl=C:/woer/gg-test/my-test-gg-confignative.xml" << std::endl; - std::cout << "\tignite -igniteHome=c:/apache-ignite -jvmClasspath=libs/myLib1.jar;libs/myLib2.jar" << std::endl; - std::cout << "\tignite -jvmInitialMemoryMB=1024 -jvmMaxMemoryMB=4096" << std::endl; - std::cout << std::endl; -} - -/** - * Application entry point. - */ -int main(int argc, const char* argv[]) -{ - // Help commands. - StringSet help; - help.insert("/help"); - help.insert("-help"); - help.insert("--help"); - - StringList args(argv + 1, argv + argc); - - try - { - // Check for special cases. - if (!args.empty()) - { - using ignite::common::ToLower; - - std::string first = ToLower(args.front()); - - if (help.find(first) != help.end()) - { - PrintHelp(); - - return 0; - } - } - - // Pick application configuration. - ignite::IgniteConfiguration cfg; - - // Pick command line arguments. - config::Configure(cfg, args); - - ignite::Ignite ignite = ignite::Ignition::Start(cfg); - - ignite::impl::IgniteImpl *igniteImpl = ignite::impl::IgniteImpl::GetFromProxy(ignite); - - if (igniteImpl) - { - ignite::jni::java::JniContext* context = igniteImpl->GetContext(); - - if (context) - context->DestroyJvm(); - } - } - catch (const ignite::IgniteError& e) - { - std::cout << "ERROR: " << e.GetText() << std::endl; - - return -1; - } - catch (const std::exception& e) - { - std::cout << "ERROR: " << e.what() << std::endl; - - return -2; - } - - return 0; -} - diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt deleted file mode 100644 index e50920ee7..000000000 --- a/src/network/CMakeLists.txt +++ /dev/null @@ -1,99 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# - -project(ignite-network) - -set(TARGET ${PROJECT_NAME}) - -# On macOS, search Homebrew for keg-only versions of OpenSSL -# equivalent of # -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/ -if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") - execute_process( - COMMAND brew --prefix OpenSSL - RESULT_VARIABLE BREW_OPENSSL - OUTPUT_VARIABLE BREW_OPENSSL_PREFIX - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if (BREW_OPENSSL EQUAL 0 AND EXISTS "${BREW_OPENSSL_PREFIX}") - message(STATUS "Found OpenSSL keg installed by Homebrew at ${BREW_OPENSSL_PREFIX}") - set(OPENSSL_ROOT_DIR "${BREW_OPENSSL_PREFIX}/") - set(OPENSSL_INCLUDE_DIR "${BREW_OPENSSL_PREFIX}/include") - set(OPENSSL_LIBRARIES "${BREW_OPENSSL_PREFIX}/lib") - set(OPENSSL_CRYPTO_LIBRARY "${BREW_OPENSSL_PREFIX}/lib/libcrypto.dylib") - endif() -endif() - -find_package(OpenSSL REQUIRED) - -include_directories(include src ${OPENSSL_INCLUDE_DIR}) - -set(SOURCES src/network/network.cpp - src/network/ssl/secure_socket_client.cpp - src/network/ssl/ssl_gateway.cpp) - -if (WIN32) - include_directories(os/win/src) - - list(APPEND SOURCES os/win/src/network/tcp_socket_client.cpp - os/win/src/network/sockets.cpp - os/win/src/network/utils.cpp) -else() - include_directories(os/linux/src) - - list(APPEND SOURCES os/linux/src/network/tcp_socket_client.cpp - os/linux/src/network/sockets.cpp - os/linux/src/network/utils.cpp) -endif() - -list(APPEND _target_libs ${TARGET}) -if (WIN32) - add_library(${TARGET}-objlib OBJECT ${SOURCES}) - - add_library(${TARGET} SHARED $) - - list(APPEND _target_libs ${TARGET}-objlib) - - set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME "ignite.network") -else() - add_library(${TARGET} SHARED ${SOURCES}) -endif() - -foreach(_target_lib IN LISTS _target_libs) - set_target_properties(${_target_lib} PROPERTIES VERSION ${CMAKE_PROJECT_VERSION}) - - if (${_target_lib} STREQUAL ${TARGET}-objlib) - set_target_properties(${_target_lib} PROPERTIES POSITION_INDEPENDENT_CODE 1) - - target_link_libraries(${_target_lib} ignite-common-objlib) - else() - target_link_libraries(${_target_lib} ignite-common) - endif() - - if (WIN32) - target_link_libraries(${_target_lib} wsock32 ws2_32 iphlpapi) - endif() - - target_include_directories(${_target_lib} INTERFACE include ${OS_INCLUDE}) -endforeach() -unset(_target_libs) - -install(TARGETS ${TARGET} - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib -) -install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include FILES_MATCHING PATTERN "*.h*") diff --git a/src/network/include/ignite/network/end_point.h b/src/network/include/ignite/network/end_point.h deleted file mode 100644 index 499cbebb6..000000000 --- a/src/network/include/ignite/network/end_point.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_END_POINT -#define _IGNITE_NETWORK_END_POINT - -#include -#include - -namespace ignite -{ - namespace network - { - /** - * Connection end point structure. - */ - struct EndPoint - { - /** - * Default constructor. - */ - EndPoint() : - port(0) - { - // No-op. - } - - /** - * Constructor. - * - * @param host Host. - * @param port Port. - */ - EndPoint(const std::string& host, uint16_t port) : - host(host), - port(port) - { - // No-op. - } - - /** - * Compare to another instance. - * - * @param other Another instance. - * @return Negative value if less, positive if larger and - * zero, if equals another instance. - */ - int Compare(const EndPoint& other) const - { - if (port < other.port) - return -1; - - if (port > other.port) - return 1; - - return host.compare(other.host); - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if equal. - */ - friend bool operator==(const EndPoint& val1, const EndPoint& val2) - { - return val1.port == val2.port && val1.host == val2.host; - } - - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if not equal. - */ - friend bool operator!=(const EndPoint& val1, const EndPoint& val2) - { - return !(val1 == val2); - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if less. - */ - friend bool operator<(const EndPoint& val1, const EndPoint& val2) - { - return val1.Compare(val2) < 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if less or equal. - */ - friend bool operator<=(const EndPoint& val1, const EndPoint& val2) - { - return val1.Compare(val2) <= 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if gretter. - */ - friend bool operator>(const EndPoint& val1, const EndPoint& val2) - { - return val1.Compare(val2) > 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if gretter or equal. - */ - friend bool operator>=(const EndPoint& val1, const EndPoint& val2) - { - return val1.Compare(val2) >= 0; - } - - /** Remote host. */ - std::string host; - - /** TCP port. */ - uint16_t port; - }; - - typedef std::vector EndPoints; - } -} - -#endif //_IGNITE_NETWORK_END_POINT \ No newline at end of file diff --git a/src/network/include/ignite/network/network.h b/src/network/include/ignite/network/network.h deleted file mode 100644 index 5e83cc1b8..000000000 --- a/src/network/include/ignite/network/network.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SSL_SSL_API -#define _IGNITE_NETWORK_SSL_SSL_API - -#include - -#include -#include - -namespace ignite -{ - namespace network - { - namespace ssl - { - /** - * Ensure that SSL library is loaded. - * - * Called implicitly when SecureSocket is created, so there is no - * need to call this function explicitly. - * - * @throw IgniteError if it is not possible to load SSL library. - */ - IGNITE_IMPORT_EXPORT void EnsureSslLoaded(); - - /** - * Make basic TCP socket. - */ - IGNITE_IMPORT_EXPORT SocketClient* MakeTcpSocketClient(); - - /** - * Make secure socket for SSL/TLS connection. - * - * @param certPath Certificate file path. - * @param keyPath Private key file path. - * @param caPath Certificate authority file path. - * - * @throw IgniteError if it is not possible to load SSL library. - */ - IGNITE_IMPORT_EXPORT SocketClient* MakeSecureSocketClient(const std::string& certPath, - const std::string& keyPath, const std::string& caPath); - } - } -} - -#endif //_IGNITE_NETWORK_SSL_SSL_API \ No newline at end of file diff --git a/src/network/include/ignite/network/socket_client.h b/src/network/include/ignite/network/socket_client.h deleted file mode 100644 index eb1d481a5..000000000 --- a/src/network/include/ignite/network/socket_client.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SOCKET_CLIENT -#define _IGNITE_NETWORK_SOCKET_CLIENT - -#include - -#include - -namespace ignite -{ - namespace network - { - /** - * Socket client implementation. - */ - class SocketClient - { - public: - /** - * Non-negative timeout operation result. - */ - struct WaitResult - { - enum T - { - /** Timeout. */ - TIMEOUT = 0, - - /** Success. */ - SUCCESS = 1 - }; - }; - - /** - * Destructor. - */ - virtual ~SocketClient() - { - // No-op. - } - - /** - * Establish connection with remote service. - * - * @param hostname Remote host name. - * @param port Service port. - * @param timeout Timeout. - * @return @c true on success and @c false on timeout. - */ - virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout) = 0; - - /** - * Close established connection. - */ - virtual void Close() = 0; - - /** - * Send data by established connection. - * - * @param data Pointer to data to be sent. - * @param size Size of the data in bytes. - * @param timeout Timeout. - * @return Number of bytes that have been sent on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Send(const int8_t* data, size_t size, int32_t timeout) = 0; - - /** - * Receive data from established connection. - * - * @param buffer Pointer to data buffer. - * @param size Size of the buffer in bytes. - * @param timeout Timeout. - * @return Number of bytes that have been received on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Receive(int8_t* buffer, size_t size, int32_t timeout) = 0; - - /** - * Check if the socket is blocking or not. - * @return @c true if the socket is blocking and false otherwise. - */ - virtual bool IsBlocking() const = 0; - - protected: - /** - * Throw connection error. - * - * @param err Error message. - */ - static void ThrowNetworkError(const std::string& err) - { - throw IgniteError(IgniteError::IGNITE_ERR_NETWORK_FAILURE, err.c_str()); - } - }; - } -} - -#endif //_IGNITE_NETWORK_SOCKET_CLIENT \ No newline at end of file diff --git a/src/network/include/ignite/network/tcp_range.h b/src/network/include/ignite/network/tcp_range.h deleted file mode 100644 index 8644d4624..000000000 --- a/src/network/include/ignite/network/tcp_range.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_TCP_RANGE -#define _IGNITE_NETWORK_TCP_RANGE - -#include -#include - -namespace ignite -{ - namespace network - { - /** - * TCP port range. - */ - struct TcpRange - { - /** - * Default constructor. - */ - TcpRange() : - port(0), - range(0) - { - // No-op. - } - - /** - * Constructor. - * - * @param host Host. - * @param port Port. - * @param range Number of ports after the @c port that - * should be tried if the previous are unavailable. - */ - TcpRange(const std::string& host, uint16_t port, uint16_t range = 0) : - host(host), - port(port), - range(range) - { - // No-op. - } - - /** - * Compare to another instance. - * - * @param other Another instance. - * @return Negative value if less, positive if larger and - * zero, if equals another instance. - */ - int Compare(const TcpRange& other) const - { - if (port < other.port) - return -1; - - if (port > other.port) - return 1; - - if (range < other.range) - return -1; - - if (range > other.range) - return 1; - - return host.compare(other.host); - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if equal. - */ - friend bool operator==(const TcpRange& val1, const TcpRange& val2) - { - return val1.port == val2.port && val1.range == val2.range && val1.host == val2.host; - } - - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if not equal. - */ - friend bool operator!=(const TcpRange& val1, const TcpRange& val2) - { - return !(val1 == val2); - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if less. - */ - friend bool operator<(const TcpRange& val1, const TcpRange& val2) - { - return val1.Compare(val2) < 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if less or equal. - */ - friend bool operator<=(const TcpRange& val1, const TcpRange& val2) - { - return val1.Compare(val2) <= 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if gretter. - */ - friend bool operator>(const TcpRange& val1, const TcpRange& val2) - { - return val1.Compare(val2) > 0; - } - - /** - * Comparison operator. - * - * @param val1 First value. - * @param val2 Second value. - * @return True if gretter or equal. - */ - friend bool operator>=(const TcpRange& val1, const TcpRange& val2) - { - return val1.Compare(val2) >= 0; - } - - /** Remote host. */ - std::string host; - - /** TCP port. */ - uint16_t port; - - /** - * Number of ports after the port that should be tried if - * the previous are unavailable. - */ - uint16_t range; - }; - } -} - -#endif //_IGNITE_NETWORK_TCP_RANGE \ No newline at end of file diff --git a/src/network/include/ignite/network/utils.h b/src/network/include/ignite/network/utils.h deleted file mode 100644 index e8f0851b6..000000000 --- a/src/network/include/ignite/network/utils.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_UTILS -#define _IGNITE_NETWORK_UTILS - -#include -#include - -#include - -namespace ignite -{ - namespace network - { - namespace utils - { - /** - * Get set of local addresses. - * - * @param addrs Addresses set. - */ - void IGNITE_IMPORT_EXPORT GetLocalAddresses(std::set& addrs); - } - } -} - -#endif //_IGNITE_NETWORK_UTILS \ No newline at end of file diff --git a/src/network/os/linux/src/network/sockets.cpp b/src/network/os/linux/src/network/sockets.cpp deleted file mode 100644 index 08e0b5eea..000000000 --- a/src/network/os/linux/src/network/sockets.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include -#include - -#include -#include - -#include - -#include "network/sockets.h" -#include - -namespace ignite -{ - namespace network - { - namespace sockets - { - int GetLastSocketError() - { - return errno; - } - - int GetLastSocketError(int handle) - { - int lastError = 0; - socklen_t size = sizeof(lastError); - int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast(&lastError), &size); - - return res == SOCKET_ERROR ? 0 : lastError; - } - - std::string GetSocketErrorMessage(int error) - { - std::stringstream res; - - res << "error_code=" << error; - - if (error == 0) - return res.str(); - - char buffer[1024] = ""; - - if (!strerror_r(error, buffer, sizeof(buffer))) - res << ", msg=" << buffer; - - return res.str(); - } - - std::string GetLastSocketErrorMessage() - { - int lastError = errno; - - return GetSocketErrorMessage(lastError); - } - - int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd) - { - int32_t timeout0 = timeout == 0 ? -1 : timeout; - - int lastError = 0; - int ret; - - do - { - struct pollfd fds[1]; - - fds[0].fd = socket; - fds[0].events = rd ? POLLIN : POLLOUT; - - ret = poll(fds, 1, timeout0 * 1000); - - if (ret == SOCKET_ERROR) - lastError = GetLastSocketError(); - - } while (ret == SOCKET_ERROR && IsSocketOperationInterrupted(lastError)); - - if (ret == SOCKET_ERROR) - return -lastError; - - socklen_t size = sizeof(lastError); - int res = getsockopt(socket, SOL_SOCKET, SO_ERROR, reinterpret_cast(&lastError), &size); - - if (res != SOCKET_ERROR && lastError != 0) - return -lastError; - - if (ret == 0) - return SocketClient::WaitResult::TIMEOUT; - - return SocketClient::WaitResult::SUCCESS; - } - - bool IsSocketOperationInterrupted(int errorCode) - { - return errorCode == EINTR; - } - } - } -} diff --git a/src/network/os/linux/src/network/sockets.h b/src/network/os/linux/src/network/sockets.h deleted file mode 100644 index aad7bb283..000000000 --- a/src/network/os/linux/src/network/sockets.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SOCKETS -#define _IGNITE_NETWORK_SOCKETS - -#include -#include - -#define SOCKET_ERROR (-1) - -namespace ignite -{ - namespace network - { - namespace sockets - { - /** Socket handle type. */ - typedef int SocketHandle; - - /** - * Get socket error. - * @return Last socket error. - */ - int GetLastSocketError(); - - /** - * Get socket error. - * @param handle Socket handle. - * @return Last socket error. - */ - int GetLastSocketError(int handle); - - /** - * Get socket error message for the error code. - * @param error Error code. - * @return Socket error message string. - */ - std::string GetSocketErrorMessage(int error); - - /** - * Get last socket error message. - * @return Last socket error message string. - */ - std::string GetLastSocketErrorMessage(); - - /** - * Check whether socket operation was interupted. - * @return @c true if the socket operation was interupted. - */ - bool IsSocketOperationInterrupted(int errorCode); - - /** - * Wait on the socket for any event for specified time. - * This function uses poll to achive timeout functionality - * for every separate socket operation. - * - * @param socket Socket handle. - * @param timeout Timeout. - * @param rd Wait for read if @c true, or for write if @c false. - * @return -errno on error, WaitResult::TIMEOUT on timeout and - * WaitResult::SUCCESS on success. - */ - int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd); - } - } -} - -#endif //_IGNITE_NETWORK_SOCKETS \ No newline at end of file diff --git a/src/network/os/linux/src/network/tcp_socket_client.cpp b/src/network/os/linux/src/network/tcp_socket_client.cpp deleted file mode 100644 index da5a6b07d..000000000 --- a/src/network/os/linux/src/network/tcp_socket_client.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include -#include "network/tcp_socket_client.h" - -namespace ignite -{ - namespace network - { - TcpSocketClient::TcpSocketClient() : - socketHandle(SOCKET_ERROR), - blocking(true) - { - // No-op. - } - - TcpSocketClient::~TcpSocketClient() - { - InternalClose(); - } - - bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout) - { - addrinfo hints; - - std::memset(&hints, 0, sizeof(hints)); - - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - std::stringstream converter; - converter << port; - std::string strPort = converter.str(); - - // Resolve the server address and port - addrinfo *result = NULL; - int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result); - - if (res != 0) - ThrowNetworkError("Can not resolve host: " + std::string(hostname) + ":" + strPort); - - std::string lastErrorMsg = "Failed to resolve host"; - bool isTimeout = false; - - // Attempt to connect to an address until one succeeds - for (addrinfo *it = result; it != NULL; it = it->ai_next) - { - lastErrorMsg = "Failed to establish connection with the host"; - isTimeout = false; - - // Create a SOCKET for connecting to server - socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol); - - if (socketHandle == SOCKET_ERROR) - { - std::string err = "Socket creation failed: " + sockets::GetLastSocketErrorMessage(); - - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, err.c_str()); - } - - TrySetOptions(); - - // Connect to server. - res = connect(socketHandle, it->ai_addr, static_cast(it->ai_addrlen)); - if (SOCKET_ERROR == res) - { - int lastError = errno; - - if (lastError != EWOULDBLOCK && lastError != EINPROGRESS) - { - lastErrorMsg.append(": ").append(sockets::GetSocketErrorMessage(lastError)); - - Close(); - - continue; - } - - res = WaitOnSocket(timeout, false); - - if (res < 0 || res == WaitResult::TIMEOUT) - { - isTimeout = true; - - Close(); - - continue; - } - } - - break; - } - - freeaddrinfo(result); - - if (socketHandle == SOCKET_ERROR) - { - if (isTimeout) - return false; - - ThrowNetworkError(lastErrorMsg); - } - - return true; - } - - void TcpSocketClient::Close() - { - InternalClose(); - } - - void TcpSocketClient::InternalClose() - { - if (socketHandle != SOCKET_ERROR) - { - close(socketHandle); - - socketHandle = SOCKET_ERROR; - } - } - - int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout) - { - if (!blocking) - { - int res = WaitOnSocket(timeout, false); - - if (res < 0 || res == WaitResult::TIMEOUT) - return res; - } - - return send(socketHandle, reinterpret_cast(data), static_cast(size), 0); - } - - int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout) - { - if (!blocking) - { - int res = WaitOnSocket(timeout, true); - - if (res < 0 || res == WaitResult::TIMEOUT) - return res; - } - - return recv(socketHandle, reinterpret_cast(buffer), static_cast(size), 0); - } - - bool TcpSocketClient::IsBlocking() const - { - return blocking; - } - - void TcpSocketClient::TrySetOptions() - { - int trueOpt = 1; - - int idleOpt = KEEP_ALIVE_IDLE_TIME; - int idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD; - int bufSizeOpt = BUFFER_SIZE; - - setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&bufSizeOpt), sizeof(bufSizeOpt)); - - setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast(&bufSizeOpt), sizeof(bufSizeOpt)); - - setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE, reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - blocking = false; - - int flags; - blocking = ((flags = fcntl(socketHandle, F_GETFL, 0)) < 0) || - (fcntl(socketHandle, F_SETFL, flags | O_NONBLOCK) < 0); - - int res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE, - reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - if (SOCKET_ERROR == res) - { - // There is no sense in configuring keep alive params if we faileed to set up keep alive mode. - return; - } -#ifdef __APPLE__ - setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPALIVE, reinterpret_cast(&idleOpt), sizeof(idleOpt)); -#else - setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast(&idleOpt), sizeof(idleOpt)); -#endif - - setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL, - reinterpret_cast(&idleRetryOpt), sizeof(idleRetryOpt)); - } - - int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd) - { - return sockets::WaitOnSocket(socketHandle, timeout, rd); - } - } -} - diff --git a/src/network/os/linux/src/network/utils.cpp b/src/network/os/linux/src/network/utils.cpp deleted file mode 100644 index c719f8593..000000000 --- a/src/network/os/linux/src/network/utils.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace ignite -{ - namespace network - { - namespace utils - { - void GetLocalAddresses(std::set& addrs) - { - struct ifaddrs *outAddrs; - if(getifaddrs(&outAddrs) != 0) - { - freeifaddrs(outAddrs); - - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list"); - } - - for (struct ifaddrs *outAddr = outAddrs; outAddr != NULL; outAddr = outAddr->ifa_next) - { - if (outAddr->ifa_addr == NULL) - continue; - - if (outAddr->ifa_flags & IFF_LOOPBACK) - continue; - - if (!(outAddr->ifa_flags & IFF_UP)) - continue; - - void *inAddr; - - char strBuffer[INET6_ADDRSTRLEN]; - - int saFamily = outAddr->ifa_addr->sa_family; - - switch (saFamily) - { - case AF_INET: - { - sockaddr_in *s4 = reinterpret_cast(outAddr->ifa_addr); - inAddr = &s4->sin_addr; - break; - } - - case AF_INET6: - { - sockaddr_in6 *s6 = reinterpret_cast(outAddr->ifa_addr); - inAddr = &s6->sin6_addr; - break; - } - - default: - continue; - } - - inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer)); - - std::string strAddr(strBuffer); - - if (!strAddr.empty()) - addrs.insert(strAddr); - } - - freeifaddrs(outAddrs); - } - } - } -} - diff --git a/src/network/os/win/src/network/sockets.cpp b/src/network/os/win/src/network/sockets.cpp deleted file mode 100644 index a6b6bb102..000000000 --- a/src/network/os/win/src/network/sockets.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include "network/sockets.h" - -#include - -#include - -namespace ignite -{ - namespace network - { - namespace sockets - { - int GetLastSocketError() - { - return WSAGetLastError(); - } - - int GetLastSocketError(int handle) - { - int lastError = 0; - socklen_t size = sizeof(lastError); - int res = getsockopt(handle, SOL_SOCKET, SO_ERROR, reinterpret_cast(&lastError), &size); - - return res == SOCKET_ERROR ? 0 : lastError; - } - - std::string GetSocketErrorMessage(HRESULT error) - { - std::stringstream res; - - res << "error_code=" << error; - - if (error == 0) - return res.str(); - - LPTSTR errorText = NULL; - - DWORD len = FormatMessage( - // use system message tables to retrieve error text - FORMAT_MESSAGE_FROM_SYSTEM - // allocate buffer on local heap for error text - | FORMAT_MESSAGE_ALLOCATE_BUFFER - // We're not passing insertion parameters - | FORMAT_MESSAGE_IGNORE_INSERTS, - // unused with FORMAT_MESSAGE_FROM_SYSTEM - NULL, - error, - MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), - // output - reinterpret_cast(&errorText), - // minimum size for output buffer - 0, - // arguments - see note - NULL); - - if (NULL != errorText && len > 0) - { - std::string msg(reinterpret_cast(errorText), static_cast(len)); - - if (len != 0) - res << ", msg=" << msg; - - LocalFree(errorText); - } - - return res.str(); - } - - std::string GetLastSocketErrorMessage() - { - HRESULT lastError = WSAGetLastError(); - - return GetSocketErrorMessage(lastError); - } - - int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd) - { - int ready = 0; - int lastError = 0; - - fd_set fds; - - do { - struct timeval tv = { 0 }; - tv.tv_sec = timeout; - - FD_ZERO(&fds); - FD_SET(socket, &fds); - - fd_set* readFds = 0; - fd_set* writeFds = 0; - - if (rd) - readFds = &fds; - else - writeFds = &fds; - - ready = select(static_cast(socket) + 1, readFds, writeFds, NULL, timeout == 0 ? NULL : &tv); - - if (ready == SOCKET_ERROR) - lastError = GetLastSocketError(); - - } while (ready == SOCKET_ERROR && IsSocketOperationInterrupted(lastError)); - - if (ready == SOCKET_ERROR) - return -lastError; - - if (ready == 0) - return SocketClient::WaitResult::TIMEOUT; - - return SocketClient::WaitResult::SUCCESS; - } - - bool IsSocketOperationInterrupted(int errorCode) - { - return errorCode == WSAEINTR; - } - } - } -} diff --git a/src/network/os/win/src/network/sockets.h b/src/network/os/win/src/network/sockets.h deleted file mode 100644 index 8da1fc0b8..000000000 --- a/src/network/os/win/src/network/sockets.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SOCKETS -#define _IGNITE_NETWORK_SOCKETS - -#define WIN32_LEAN_AND_MEAN -#define _WINSOCKAPI_ - -#include -#include -#include -#include - -#include -#include - -namespace ignite -{ - namespace network - { - namespace sockets - { - /** Socket handle type. */ - typedef SOCKET SocketHandle; - - /** - * Get socket error. - * @return Last socket error. - */ - int GetLastSocketError(); - - /** - * Get socket error. - * @param handle Socket handle. - * @return Last socket error. - */ - int GetLastSocketError(int handle); - - /** - * Get socket error message for the error code. - * @param error Error code. - * @return Socket error message string. - */ - std::string GetSocketErrorMessage(HRESULT error); - - /** - * Get last socket error message. - * @return Last socket error message string. - */ - std::string GetLastSocketErrorMessage(); - - /** - * Check whether socket operation was interupted. - * @return @c true if the socket operation was interupted. - */ - bool IsSocketOperationInterrupted(int errorCode); - - /** - * Wait on the socket for any event for specified time. - * This function uses poll to achive timeout functionality - * for every separate socket operation. - * - * @param socket Socket handle. - * @param timeout Timeout. - * @param rd Wait for read if @c true, or for write if @c false. - * @return -errno on error, WaitResult::TIMEOUT on timeout and - * WaitResult::SUCCESS on success. - */ - int WaitOnSocket(SocketHandle socket, int32_t timeout, bool rd); - } - } -} - -#endif //_IGNITE_NETWORK_SOCKETS \ No newline at end of file diff --git a/src/network/os/win/src/network/tcp_socket_client.cpp b/src/network/os/win/src/network/tcp_socket_client.cpp deleted file mode 100644 index 6c3c9a17a..000000000 --- a/src/network/os/win/src/network/tcp_socket_client.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include "network/sockets.h" - -#include - -#include - -#include - -#include "network/tcp_socket_client.h" - -namespace ignite -{ - namespace network - { - TcpSocketClient::TcpSocketClient() : - socketHandle(INVALID_SOCKET), - blocking(true) - { - // No-op. - } - - TcpSocketClient::~TcpSocketClient() - { - InternalClose(); - } - - bool TcpSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout) - { - static common::concurrent::CriticalSection initCs; - static bool networkInited = false; - - // Initing networking if is not inited. - if (!networkInited) - { - common::concurrent::CsLockGuard lock(initCs); - if (!networkInited) - { - WSADATA wsaData; - - networkInited = WSAStartup(MAKEWORD(2, 2), &wsaData) == 0; - - if (!networkInited) - ThrowNetworkError("Networking initialisation failed: " + sockets::GetLastSocketErrorMessage()); - } - } - - InternalClose(); - - addrinfo hints = { 0 }; - - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - std::stringstream converter; - converter << port; - std::string strPort = converter.str(); - - // Resolve the server address and port - addrinfo *result = NULL; - int res = getaddrinfo(hostname, strPort.c_str(), &hints, &result); - - if (res != 0) - ThrowNetworkError("Can not resolve host: " + std::string(hostname) + ":" + strPort); - - std::string lastErrorMsg = "Failed to resolve host"; - bool isTimeout = false; - - // Attempt to connect to an address until one succeeds - for (addrinfo *it = result; it != NULL; it = it->ai_next) - { - lastErrorMsg = "Failed to establish connection with the host"; - isTimeout = false; - - // Create a SOCKET for connecting to server - socketHandle = socket(it->ai_family, it->ai_socktype, it->ai_protocol); - - if (socketHandle == INVALID_SOCKET) - ThrowNetworkError("Socket creation failed: " + sockets::GetLastSocketErrorMessage()); - - TrySetOptions(); - - // Connect to server. - res = connect(socketHandle, it->ai_addr, static_cast(it->ai_addrlen)); - if (SOCKET_ERROR == res) - { - int lastError = WSAGetLastError(); - - if (lastError != WSAEWOULDBLOCK) - { - lastErrorMsg.append(": ").append(sockets::GetSocketErrorMessage(lastError)); - - Close(); - - continue; - } - - res = WaitOnSocket(timeout, false); - - if (res < 0 || res == WaitResult::TIMEOUT) - { - isTimeout = true; - - Close(); - - continue; - } - } - - break; - } - - freeaddrinfo(result); - - if (socketHandle == INVALID_SOCKET) - { - if (isTimeout) - return false; - - ThrowNetworkError(lastErrorMsg); - } - - return true; - } - - void TcpSocketClient::Close() - { - InternalClose(); - } - - void TcpSocketClient::InternalClose() - { - if (socketHandle != INVALID_SOCKET) - { - closesocket(socketHandle); - - socketHandle = INVALID_SOCKET; - } - } - - int TcpSocketClient::Send(const int8_t* data, size_t size, int32_t timeout) - { - if (!blocking) - { - int res = WaitOnSocket(timeout, false); - - if (res < 0 || res == WaitResult::TIMEOUT) - return res; - } - - return send(socketHandle, reinterpret_cast(data), static_cast(size), 0); - } - - int TcpSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout) - { - if (!blocking) - { - int res = WaitOnSocket(timeout, true); - - if (res < 0 || res == WaitResult::TIMEOUT) - return res; - } - - return recv(socketHandle, reinterpret_cast(buffer), static_cast(size), 0); - } - - bool TcpSocketClient::IsBlocking() const - { - return blocking; - } - - void TcpSocketClient::TrySetOptions() - { - BOOL trueOpt = TRUE; - ULONG uTrueOpt = TRUE; - int bufSizeOpt = BUFFER_SIZE; - - setsockopt(socketHandle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&bufSizeOpt), sizeof(bufSizeOpt)); - - setsockopt(socketHandle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast(&bufSizeOpt), sizeof(bufSizeOpt)); - - setsockopt(socketHandle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - setsockopt(socketHandle, SOL_SOCKET, SO_OOBINLINE, reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - blocking = ioctlsocket(socketHandle, FIONBIO, &uTrueOpt) == SOCKET_ERROR; - - int res = setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE, - reinterpret_cast(&trueOpt), sizeof(trueOpt)); - - if (SOCKET_ERROR == res) - { - // There is no sense in configuring keep alive params if we faileed to set up keep alive mode. - return; - } - - // This option is available starting with Windows 10, version 1709. -#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) - DWORD idleOpt = KEEP_ALIVE_IDLE_TIME; - DWORD idleRetryOpt = KEEP_ALIVE_PROBES_PERIOD; - - setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast(&idleOpt), sizeof(idleOpt)); - - setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL, - reinterpret_cast(&idleRetryOpt), sizeof(idleRetryOpt)); -#else // use old hardcore WSAIoctl - - // WinSock structure for KeepAlive timing settings - struct tcp_keepalive settings = { 0 }; - settings.onoff = 1; - settings.keepalivetime = KEEP_ALIVE_IDLE_TIME * 1000; - settings.keepaliveinterval = KEEP_ALIVE_PROBES_PERIOD * 1000; - - // pointers for WinSock call - DWORD bytesReturned; - WSAOVERLAPPED overlapped; - overlapped.hEvent = NULL; - - // Set KeepAlive settings - WSAIoctl( - socketHandle, - SIO_KEEPALIVE_VALS, - &settings, - sizeof(struct tcp_keepalive), - NULL, - 0, - &bytesReturned, - &overlapped, - NULL - ); -#endif - } - - int TcpSocketClient::WaitOnSocket(int32_t timeout, bool rd) - { - return sockets::WaitOnSocket(socketHandle, timeout, rd); - } - } -} - diff --git a/src/network/os/win/src/network/utils.cpp b/src/network/os/win/src/network/utils.cpp deleted file mode 100644 index 5fde3bffe..000000000 --- a/src/network/os/win/src/network/utils.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include - -namespace ignite -{ - namespace network - { - namespace utils - { - IGNITE_IMPORT_EXPORT void GetLocalAddresses(std::set& addrs) - { - IP_ADAPTER_ADDRESSES outAddrs[64]; - - DWORD outAddrsSize = sizeof(outAddrs); - - DWORD error = ::GetAdaptersAddresses(AF_UNSPEC, 0, NULL, &outAddrs[0], &outAddrsSize); - - if (ERROR_SUCCESS != error) - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list"); - - for (IP_ADAPTER_ADDRESSES* outAddr = &outAddrs[0]; NULL != outAddr; outAddr = outAddr->Next) - { - if (IF_TYPE_SOFTWARE_LOOPBACK == outAddr->IfType) - continue; - - for (IP_ADAPTER_UNICAST_ADDRESS* addr = outAddr->FirstUnicastAddress; - NULL != addr; - addr = addr->Next) - { - void *inAddr = 0; - - char strBuffer[INET6_ADDRSTRLEN] = { 0 }; - - int saFamily = addr->Address.lpSockaddr->sa_family; - - switch (saFamily) - { - case AF_INET: - { - SOCKADDR_IN* ipv4 = reinterpret_cast(addr->Address.lpSockaddr); - inAddr = &ipv4->sin_addr; - - break; - } - - case AF_INET6: - { - SOCKADDR_IN6* ipv6 = reinterpret_cast(addr->Address.lpSockaddr); - inAddr = &ipv6->sin6_addr; - - break; - } - - default: - continue; - } - - inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer)); - - std::string strAddr(strBuffer); - - if (!strAddr.empty()) - addrs.insert(strAddr); - } - } - } - } - } -} - diff --git a/src/network/src/network/network.cpp b/src/network/src/network/network.cpp deleted file mode 100644 index ab1b295d0..000000000 --- a/src/network/src/network/network.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include "network/sockets.h" - -#include - -#include "network/ssl/ssl_gateway.h" -#include "network/ssl/secure_socket_client.h" -#include "network/tcp_socket_client.h" - -namespace ignite -{ - namespace network - { - namespace ssl - { - IGNITE_IMPORT_EXPORT void EnsureSslLoaded() - { - SslGateway::GetInstance().LoadAll(); - } - - IGNITE_IMPORT_EXPORT SocketClient* MakeTcpSocketClient() - { - return new TcpSocketClient; - } - - IGNITE_IMPORT_EXPORT SocketClient* MakeSecureSocketClient(const std::string& certPath, - const std::string& keyPath, const std::string& caPath) - { - EnsureSslLoaded(); - - return new SecureSocketClient(certPath, keyPath, caPath); - } - } - } -} diff --git a/src/network/src/network/ssl/secure_socket_client.cpp b/src/network/src/network/ssl/secure_socket_client.cpp deleted file mode 100644 index 9e4143d61..000000000 --- a/src/network/src/network/ssl/secure_socket_client.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include "network/sockets.h" - -#include -#include - -#include -#include -#include - -#include "network/ssl/secure_socket_client.h" -#include "network/ssl/ssl_gateway.h" - -enum { OPERATION_SUCCESS = 1 }; - -void FreeContext(SSL_CTX* ctx) -{ - using namespace ignite::network::ssl; - - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - sslGateway.SSL_CTX_free_(ctx); -} - -void FreeBio(BIO* bio) -{ - using namespace ignite::network::ssl; - - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - sslGateway.BIO_free_all_(bio); -} - -namespace ignite -{ - namespace network - { - namespace ssl - { - SecureSocketClient::SecureSocketClient(const std::string& certPath, const std::string& keyPath, - const std::string& caPath): - certPath(certPath), - keyPath(keyPath), - caPath(caPath), - context(0), - ssl(0), - blocking(true) - { - // No-op. - } - - SecureSocketClient::~SecureSocketClient() - { - CloseInternal(); - - if (context) - SslGateway::GetInstance().SSL_CTX_free_(reinterpret_cast(context)); - } - - bool SecureSocketClient::Connect(const char* hostname, uint16_t port, int32_t timeout) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - CloseInternal(); - - if (!context) - { - context = MakeContext(certPath, keyPath, caPath); - - if (!context) - ThrowSecureError("Can not create SSL context. Aborting connect"); - } - - ssl = MakeSsl(context, hostname, port, blocking); - - assert(ssl != 0); - - common::MethodGuard guard(this, &SecureSocketClient::CloseInternal); - - SSL* ssl0 = reinterpret_cast(ssl); - - int res = sslGateway.SSL_set_tlsext_host_name_(ssl0, hostname); - - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set host name for secure connection: " + GetSslError(ssl0, res)); - - sslGateway.SSL_set_connect_state_(ssl0); - - bool connected = CompleteConnectInternal(ssl0, timeout); - - if (!connected) - return false; - - // Verify a server certificate was presented during the negotiation - X509* cert = sslGateway.SSL_get_peer_certificate_(ssl0); - if (cert) - sslGateway.X509_free_(cert); - else - ThrowSecureError("Remote host did not provide certificate: " + GetSslError(ssl0, res)); - - // Verify the result of chain verification - // Verification performed according to RFC 4158 - res = sslGateway.SSL_get_verify_result_(ssl0); - if (X509_V_OK != res) - ThrowSecureError("Certificate chain verification failed: " + GetSslError(ssl0, res)); - - guard.Release(); - - return true; - } - - void SecureSocketClient::Close() - { - CloseInternal(); - } - - int SecureSocketClient::Send(const int8_t* data, size_t size, int32_t) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - if (!ssl) - ThrowNetworkError("Trying to send data using closed connection"); - - SSL* ssl0 = reinterpret_cast(ssl); - - return sslGateway.SSL_write_(ssl0, data, static_cast(size)); - } - - int SecureSocketClient::Receive(int8_t* buffer, size_t size, int32_t timeout) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - if (!ssl) - ThrowNetworkError("Trying to receive data using closed connection"); - - SSL* ssl0 = reinterpret_cast(ssl); - - int res = 0; - - if (!blocking && sslGateway.SSL_pending_(ssl0) == 0) - { - res = WaitOnSocket(ssl, timeout, true); - - if (res < 0 || res == WaitResult::TIMEOUT) - return res; - } - - do { - res = sslGateway.SSL_read_(ssl0, buffer, static_cast(size)); - - if (res <= 0) - { - int err = sslGateway.SSL_get_error_(ssl0, res); - if (IsActualError(err)) - return -err; - - int want = sslGateway.SSL_want_(ssl0); - - int waitRes = WaitOnSocket(ssl, timeout, want == SSL_READING); - - if (waitRes < 0 || waitRes == WaitResult::TIMEOUT) - return waitRes; - } - } while (res <= 0); - - return res; - } - - bool SecureSocketClient::IsBlocking() const - { - return blocking; - } - - void* SecureSocketClient::MakeContext(const std::string& certPath, const std::string& keyPath, - const std::string& caPath) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - const SSL_METHOD* method = sslGateway.SSLv23_client_method_(); - if (!method) - ThrowSecureError("Can not get SSL method"); - - SSL_CTX* ctx = sslGateway.SSL_CTX_new_(method); - if (!ctx) - ThrowSecureError("Can not create new SSL context"); - - common::DeinitGuard guard(ctx, &FreeContext); - - sslGateway.SSL_CTX_set_verify_(ctx, SSL_VERIFY_PEER, 0); - - sslGateway.SSL_CTX_set_verify_depth_(ctx, 8); - - sslGateway.SSL_CTX_set_options_(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION); - - const char* cCaPath = caPath.empty() ? 0 : caPath.c_str(); - - long res = sslGateway.SSL_CTX_load_verify_locations_(ctx, cCaPath, 0); - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set Certificate Authority path for secure connection"); - - res = sslGateway.SSL_CTX_use_certificate_chain_file_(ctx, certPath.c_str()); - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set client certificate file for secure connection"); - - res = sslGateway.SSL_CTX_use_RSAPrivateKey_file_(ctx, keyPath.c_str(), SSL_FILETYPE_PEM); - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set private key file for secure connection"); - - const char* const PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4"; - res = sslGateway.SSL_CTX_set_cipher_list_(ctx, PREFERRED_CIPHERS); - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set ciphers list for secure connection"); - - guard.Release(); - - return ctx; - } - - void* SecureSocketClient::MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - BIO* bio = sslGateway.BIO_new_ssl_connect_(reinterpret_cast(context)); - if (!bio) - ThrowSecureError("Can not create SSL connection"); - - common::DeinitGuard guard(bio, &FreeBio); - - blocking = sslGateway.BIO_set_nbio_(bio, 1) != OPERATION_SUCCESS; - - std::stringstream stream; - stream << hostname << ":" << port; - - std::string address = stream.str(); - - long res = sslGateway.BIO_set_conn_hostname_(bio, address.c_str()); - if (res != OPERATION_SUCCESS) - ThrowSecureError("Can not set SSL connection hostname"); - - SSL* ssl = 0; - sslGateway.BIO_get_ssl_(bio, &ssl); - if (!ssl) - ThrowSecureError("Can not get SSL instance from BIO"); - - guard.Release(); - - return ssl; - } - - bool SecureSocketClient::CompleteConnectInternal(void* ssl, int timeout) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - SSL* ssl0 = reinterpret_cast(ssl); - - while (true) - { - int res = sslGateway.SSL_connect_(ssl0); - - if (res == OPERATION_SUCCESS) - return true; - - int sslError = sslGateway.SSL_get_error_(ssl0, res); - - if (IsActualError(sslError)) - ThrowSecureError("Can not establish secure connection: " + GetSslError(ssl0, res)); - - int want = sslGateway.SSL_want_(ssl0); - - res = WaitOnSocket(ssl, timeout, want == SSL_READING); - - if (res == WaitResult::TIMEOUT) - return false; - - if (res != WaitResult::SUCCESS) - ThrowSecureError("Error while establishing secure connection: " + GetSslError(ssl0, res)); - } - } - - std::string SecureSocketClient::GetSslError(void* ssl, int ret) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - SSL* ssl0 = reinterpret_cast(ssl); - - int sslError = sslGateway.SSL_get_error_(ssl0, ret); - - switch (sslError) - { - case SSL_ERROR_NONE: - break; - - case SSL_ERROR_WANT_WRITE: - return std::string("SSL_connect wants write"); - - case SSL_ERROR_WANT_READ: - return std::string("SSL_connect wants read"); - - default: - return std::string("SSL error: ") + common::LexicalCast(sslError); - } - - long error = sslGateway.ERR_get_error_(); - - char errBuf[1024] = { 0 }; - - sslGateway.ERR_error_string_n_(error, errBuf, sizeof(errBuf)); - - return std::string(errBuf); - } - - bool SecureSocketClient::IsActualError(int err) - { - switch (err) - { - case SSL_ERROR_NONE: - case SSL_ERROR_WANT_WRITE: - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_CONNECT: - case SSL_ERROR_WANT_ACCEPT: - case SSL_ERROR_WANT_X509_LOOKUP: - return false; - - default: - return true; - } - } - - void SecureSocketClient::CloseInternal() - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - if (sslGateway.Loaded() && ssl) - { - sslGateway.SSL_free_(reinterpret_cast(ssl)); - - ssl = 0; - } - } - - void SecureSocketClient::ThrowSecureError(const std::string& err) - { - throw IgniteError(IgniteError::IGNITE_ERR_SECURE_CONNECTION_FAILURE, err.c_str()); - } - - int SecureSocketClient::WaitOnSocket(void* ssl, int32_t timeout, bool rd) - { - SslGateway &sslGateway = SslGateway::GetInstance(); - - assert(sslGateway.Loaded()); - - SSL* ssl0 = reinterpret_cast(ssl); - int fd = sslGateway.SSL_get_fd_(ssl0); - - if (fd < 0) - { - std::stringstream ss; - - ss << "Can not get file descriptor from the SSL socket: " << fd << ", " << GetSslError(ssl, fd); - - ThrowNetworkError(ss.str()); - } - - return sockets::WaitOnSocket(fd, timeout, rd); - } - } - } -} diff --git a/src/network/src/network/ssl/secure_socket_client.h b/src/network/src/network/ssl/secure_socket_client.h deleted file mode 100644 index 76d0392d0..000000000 --- a/src/network/src/network/ssl/secure_socket_client.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT -#define _IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT - -#include -#include - -#include - -namespace ignite -{ - namespace network - { - namespace ssl - { - /** - * Secure socket client. - */ - class SecureSocketClient : public SocketClient - { - public: - /** - * Constructor. - * - * @param certPath Certificate file path. - * @param keyPath Private key file path. - * @param caPath Certificate authority file path. - */ - SecureSocketClient(const std::string& certPath, const std::string& keyPath, const std::string& caPath); - - /** - * Destructor. - */ - virtual ~SecureSocketClient(); - - /** - * Establish connection with the host. - * - * @param hostname Host name or address. - * @param port TCP port. - * @param timeout Timeout in seconds. - * @return @c true on success and @c false on timeout. - */ - virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout); - - /** - * Close the connection. - */ - virtual void Close(); - - /** - * Send data using connection. - * @param data Data to send. - * @param size Number of bytes to send. - * @param timeout Timeout in seconds. - * @return Number of bytes that have been sent on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Send(const int8_t* data, size_t size, int32_t timeout); - - /** - * Receive data from established connection. - * - * @param buffer Pointer to data buffer. - * @param size Size of the buffer in bytes. - * @param timeout Timeout in seconds. - * @return Number of bytes that have been received on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Receive(int8_t* buffer, size_t size, int32_t timeout); - - /** - * Check if the socket is blocking or not. - * @return @c true if the socket is blocking and false otherwise. - */ - virtual bool IsBlocking() const; - - private: - /** - * Close the connection. - * Internal call. - */ - void CloseInternal(); - - /** - * Throw SSL-related error. - * - * @param err Error message. - */ - static void ThrowSecureError(const std::string& err); - - /** - * Wait on the socket for any event for specified time. - * This function uses poll to achive timeout functionality - * for every separate socket operation. - * - * @param ssl SSL instance. - * @param timeout Timeout in seconds. - * @param rd Wait for read if @c true, or for write if @c false. - * @return -errno on error, WaitResult::TIMEOUT on timeout and - * WaitResult::SUCCESS on success. - */ - static int WaitOnSocket(void* ssl, int32_t timeout, bool rd); - - /** - * Make new context instance. - * - * @param certPath Certificate file path. - * @param keyPath Private key file path. - * @param caPath Certificate authority file path. - * @return New context instance on success and null-pointer on fail. - */ - static void* MakeContext(const std::string& certPath, const std::string& keyPath, - const std::string& caPath); - - /** - * Make new SSL instance. - * - * @param context SSL context. - * @param hostname Host name or address. - * @param port TCP port. - * @param blocking Indicates if the resulted SSL is blocking or not. - * @return New SSL instance on success and null-pointer on fail. - */ - static void* MakeSsl(void* context, const char* hostname, uint16_t port, bool& blocking); - - /** - * Complete async connect. - * - * @param ssl SSL instance. - * @param timeout Timeout in seconds. - * @return @c true on success and @c false on timeout. - */ - static bool CompleteConnectInternal(void* ssl, int timeout); - - /** - * Get SSL error. - * - * @param ssl SSL instance. - * @param ret Return value of the pervious operation. - * @return Error string. - */ - static std::string GetSslError(void* ssl, int ret); - - /** - * Check if a actual error occured. - * - * @param err SSL error code. - * @return @true if a actual error occured - */ - static bool IsActualError(int err); - - /** Certificate file path. */ - std::string certPath; - - /** Private key file path. */ - std::string keyPath; - - /** Certificate authority file path. */ - std::string caPath; - - /** SSL context. */ - void* context; - - /** OpenSSL instance */ - void* ssl; - - /** Blocking flag. */ - bool blocking; - }; - } - } -} - -#endif //_IGNITE_NETWORK_SSL_SECURE_SOCKET_CLIENT diff --git a/src/network/src/network/ssl/ssl_gateway.cpp b/src/network/src/network/ssl/ssl_gateway.cpp deleted file mode 100644 index b2afb0fea..000000000 --- a/src/network/src/network/ssl/ssl_gateway.cpp +++ /dev/null @@ -1,710 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#include - -#include -#include - -#include "network/ssl/ssl_gateway.h" - -#ifndef ADDITIONAL_OPENSSL_HOME_ENV -# define ADDITIONAL_OPENSSL_HOME_ENV "OPEN_SSL_HOME" -#endif // ADDITIONAL_OPENSSL_HOME_ENV - -#ifndef SSL_CTRL_OPTIONS -# define SSL_CTRL_OPTIONS 32 -#endif // SSL_CTRL_OPTIONS - -#ifndef OPENSSL_INIT_LOAD_SSL_STRINGS -# define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L -#endif // OPENSSL_INIT_LOAD_SSL_STRINGS - -#ifndef OPENSSL_INIT_LOAD_CRYPTO_STRINGS -# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L -#endif // OPENSSL_INIT_LOAD_CRYPTO_STRINGS - -namespace ignite -{ - namespace network - { - namespace ssl - { - SslGateway::SslGateway() : - inited(false), - functions() - { - memset(&functions, 0, sizeof(functions)); - } - - SslGateway::~SslGateway() - { - // No-op. - } - - void SslGateway::UnloadAll() - { - libeay32.Unload(); - ssleay32.Unload(); - libssl.Unload(); - libcrypto.Unload(); - - memset(&functions, 0, sizeof(functions)); - } - - common::dynamic::Module SslGateway::LoadSslLibrary(const char* name) - { - using namespace common; - using namespace dynamic; - - std::string home = GetEnv(ADDITIONAL_OPENSSL_HOME_ENV); - - if (home.empty()) - home = GetEnv("OPENSSL_HOME"); - - std::string fullName = GetDynamicLibraryName(name); - - if (!home.empty()) - { - const char* paths[] = {"bin", "lib"}; - - for (size_t i = 0; i < 2; i++) { - std::stringstream constructor; - - constructor << home << Fs << paths[i] << Fs << fullName; - - std::string fullPath = constructor.str(); - - Module mod = LoadModule(fullPath); - - if (mod.IsLoaded()) - return mod; - } - } - - return LoadModule(fullName); - } - - void SslGateway::LoadSslLibraries() - { - libssl = LoadSslLibrary("libssl"); - - if (!libssl.IsLoaded()) - { - libcrypto = LoadSslLibrary("libcrypto-1_1-x64"); - libssl = LoadSslLibrary("libssl-1_1-x64"); - } - - if (!libssl.IsLoaded()) - { - libeay32 = LoadSslLibrary("libeay32"); - ssleay32 = LoadSslLibrary("ssleay32"); - } - - if (!libssl.IsLoaded() && (!libeay32.IsLoaded() || !ssleay32.IsLoaded())) - { - if (!libssl.IsLoaded()) - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, - "Can not load neccessary OpenSSL library: libssl"); - - std::stringstream ss; - - ss << "Can not load neccessary OpenSSL libraries:"; - - if (!libeay32.IsLoaded()) - ss << " libeay32"; - - if (!ssleay32.IsLoaded()) - ss << " ssleay32"; - - std::string res = ss.str(); - - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str()); - } - } - - void SslGateway::LoadMandatoryMethods() - { - functions.fpSSLeay_version = TryLoadSslMethod("SSLeay_version"); - - if (!functions.fpSSLeay_version) - functions.fpOpenSSL_version = LoadSslMethod("OpenSSL_version"); - - functions.fpSSL_library_init = TryLoadSslMethod("SSL_library_init"); - functions.fpSSL_load_error_strings = TryLoadSslMethod("SSL_load_error_strings"); - - if (!functions.fpSSL_library_init || !functions.fpSSL_load_error_strings) - functions.fpOPENSSL_init_ssl = LoadSslMethod("OPENSSL_init_ssl"); - - functions.fpSSLv23_client_method = TryLoadSslMethod("SSLv23_client_method"); - - if (!functions.fpSSLv23_client_method) - functions.fpTLS_client_method = LoadSslMethod("TLS_client_method"); - - functions.fpSSL_CTX_new = LoadSslMethod("SSL_CTX_new"); - functions.fpSSL_CTX_free = LoadSslMethod("SSL_CTX_free"); - functions.fpSSL_CTX_set_verify = LoadSslMethod("SSL_CTX_set_verify"); - functions.fpSSL_CTX_set_verify_depth = LoadSslMethod("SSL_CTX_set_verify_depth"); - functions.fpSSL_CTX_load_verify_locations = LoadSslMethod("SSL_CTX_load_verify_locations"); - functions.fpSSL_CTX_use_certificate_chain_file = LoadSslMethod("SSL_CTX_use_certificate_chain_file"); - functions.fpSSL_CTX_use_RSAPrivateKey_file = LoadSslMethod("SSL_CTX_use_RSAPrivateKey_file"); - functions.fpSSL_CTX_set_cipher_list = LoadSslMethod("SSL_CTX_set_cipher_list"); - - functions.fpSSL_get_verify_result = LoadSslMethod("SSL_get_verify_result"); - - functions.fpSSL_get_peer_certificate = LoadSslMethod("SSL_get_peer_certificate"); - functions.fpSSL_ctrl = LoadSslMethod("SSL_ctrl"); - functions.fpSSL_CTX_ctrl = LoadSslMethod("SSL_CTX_ctrl"); - - functions.fpSSL_set_connect_state = LoadSslMethod("SSL_set_connect_state"); - functions.fpSSL_connect = LoadSslMethod("SSL_connect"); - functions.fpSSL_get_error = LoadSslMethod("SSL_get_error"); - functions.fpSSL_want = LoadSslMethod("SSL_want"); - functions.fpSSL_write = LoadSslMethod("SSL_write"); - functions.fpSSL_read = LoadSslMethod("SSL_read"); - functions.fpSSL_pending = LoadSslMethod("SSL_pending"); - functions.fpSSL_get_fd = LoadSslMethod("SSL_get_fd"); - functions.fpSSL_free = LoadSslMethod("SSL_free"); - functions.fpBIO_new_ssl_connect = LoadSslMethod("BIO_new_ssl_connect"); - - functions.fpOPENSSL_config = LoadSslMethod("OPENSSL_config"); - functions.fpX509_free = LoadSslMethod("X509_free"); - - functions.fpBIO_free_all = LoadSslMethod("BIO_free_all"); - functions.fpBIO_ctrl = LoadSslMethod("BIO_ctrl"); - - functions.fpERR_get_error = LoadSslMethod("ERR_get_error"); - functions.fpERR_error_string_n = LoadSslMethod("ERR_error_string_n"); - } - - SslGateway& SslGateway::GetInstance() - { - static SslGateway self; - - return self; - } - - void SslGateway::LoadAll() - { - using namespace common::dynamic; - - if (inited) - return; - - common::concurrent::CsLockGuard lock(initCs); - - if (inited) - return; - - common::MethodGuard guard(this, &SslGateway::UnloadAll); - - LoadSslLibraries(); - - LoadMandatoryMethods(); - - functions.fpSSL_CTX_set_options = TryLoadSslMethod("SSL_CTX_set_options"); - functions.fpERR_print_errors_fp = TryLoadSslMethod("ERR_print_errors_fp"); - - IGNITE_UNUSED(SSL_library_init_()); - - SSL_load_error_strings_(); - - OPENSSL_config_(0); - - guard.Release(); - - inited = true; - } - - void* SslGateway::TryLoadSslMethod(const char* name) - { - void* fp = libeay32.FindSymbol(name); - - if (!fp) - fp = ssleay32.FindSymbol(name); - - if (!fp) - fp = libcrypto.FindSymbol(name); - - if (!fp) - fp = libssl.FindSymbol(name); - - return fp; - } - - void* SslGateway::LoadSslMethod(const char* name) - { - void* fp = TryLoadSslMethod(name); - - if (!fp) - { - std::stringstream ss; - - ss << "Can not load function " << name; - - std::string res = ss.str(); - - throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, res.c_str()); - } - - return fp; - } - - char* SslGateway::SSLeay_version_(int type) - { - typedef char* (FuncType)(int); - - FuncType* fp = 0; - - if (functions.fpSSLeay_version) - fp = reinterpret_cast(functions.fpSSLeay_version); - else - fp = reinterpret_cast(functions.fpOpenSSL_version); - - assert(fp != 0); - - return fp(type); - } - - int SslGateway::OPENSSL_init_ssl_(uint64_t opts, const void* settings) - { - assert(functions.fpOPENSSL_init_ssl != 0); - - typedef int (FuncType)(uint64_t, const void*); - - FuncType* fp = reinterpret_cast(functions.fpOPENSSL_init_ssl); - - return fp(opts, settings); - } - - long SslGateway::SSL_CTX_set_options_(SSL_CTX* ctx, long options) - { - if (functions.fpSSL_CTX_set_options) - { - typedef long (FuncType)(SSL_CTX*, long); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_set_options); - - return fp(ctx, options); - } - - return SSL_CTX_ctrl_(ctx, SSL_CTRL_OPTIONS, options, NULL); - } - - long SslGateway::SSL_CTX_ctrl_(SSL_CTX* ctx, int cmd, long larg, void* parg) - { - assert(functions.fpSSL_CTX_ctrl != 0); - - typedef long (FuncType)(SSL_CTX*, int, long, void*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_ctrl); - - return fp(ctx, cmd, larg, parg); - } - - SSL_CTX* SslGateway::SSL_CTX_new_(const SSL_METHOD* meth) - { - assert(functions.fpSSL_CTX_new != 0); - - typedef SSL_CTX*(FuncType)(const SSL_METHOD*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_new); - - return fp(meth); - } - - void SslGateway::SSL_CTX_free_(SSL_CTX* ctx) - { - assert(functions.fpSSL_CTX_free != 0); - - typedef void (FuncType)(SSL_CTX*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_free); - - fp(ctx); - } - - void SslGateway::SSL_CTX_set_verify_(SSL_CTX* ctx, int mode, int (* callback)(int, X509_STORE_CTX*)) - { - assert(functions.fpSSL_CTX_set_verify != 0); - - typedef void (FuncType)(SSL_CTX*, int, int (*)(int, X509_STORE_CTX*)); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_set_verify); - - fp(ctx, mode, callback); - } - - void SslGateway::SSL_CTX_set_verify_depth_(SSL_CTX* ctx, int depth) - { - assert(functions.fpSSL_CTX_set_verify_depth != 0); - - typedef void (FuncType)(SSL_CTX*, int); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_set_verify_depth); - - fp(ctx, depth); - } - - int SslGateway::SSL_CTX_load_verify_locations_(SSL_CTX* ctx, const char* cAfile, const char* cApath) - { - assert(functions.fpSSL_CTX_load_verify_locations != 0); - - typedef int (FuncType)(SSL_CTX*, const char*, const char*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_load_verify_locations); - - return fp(ctx, cAfile, cApath); - } - - int SslGateway::SSL_CTX_use_certificate_chain_file_(SSL_CTX* ctx, const char* file) - { - assert(functions.fpSSL_CTX_use_certificate_chain_file != 0); - - typedef int (FuncType)(SSL_CTX*, const char*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_use_certificate_chain_file); - - return fp(ctx, file); - } - - int SslGateway::SSL_CTX_use_RSAPrivateKey_file_(SSL_CTX* ctx, const char* file, int type) - { - assert(functions.fpSSL_CTX_use_RSAPrivateKey_file != 0); - - typedef int (FuncType)(SSL_CTX*, const char*, int); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_use_RSAPrivateKey_file); - - return fp(ctx, file, type); - } - - int SslGateway::SSL_CTX_set_cipher_list_(SSL_CTX* ctx, const char* str) - { - assert(functions.fpSSL_CTX_set_cipher_list != 0); - - typedef int (FuncType)(SSL_CTX*, const char*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_CTX_set_cipher_list); - - return fp(ctx, str); - } - - long SslGateway::SSL_get_verify_result_(const SSL* s) - { - assert(functions.fpSSL_get_verify_result != 0); - - typedef long (FuncType)(const SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_get_verify_result); - - return fp(s); - } - - int SslGateway::SSL_library_init_() - { - typedef int (FuncType)(); - - if (functions.fpSSL_library_init) - { - FuncType* fp = reinterpret_cast(functions.fpSSL_library_init); - - return fp(); - } - - return OPENSSL_init_ssl_(0, NULL); - } - - void SslGateway::SSL_load_error_strings_() - { - typedef void (FuncType)(); - - if (functions.fpSSL_load_error_strings) - { - FuncType* fp = reinterpret_cast(functions.fpSSL_load_error_strings); - - fp(); - - return; - } - - OPENSSL_init_ssl_(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); - } - - X509* SslGateway::SSL_get_peer_certificate_(const SSL* s) - { - assert(functions.fpSSL_get_peer_certificate != 0); - - typedef X509*(FuncType)(const SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_get_peer_certificate); - - return fp(s); - } - - long SslGateway::SSL_ctrl_(SSL* s, int cmd, long larg, void* parg) - { - assert(functions.fpSSL_ctrl != 0); - - typedef long (FuncType)(SSL*, int, long, void*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_ctrl); - - return fp(s, cmd, larg, parg); - } - - long SslGateway::SSL_set_tlsext_host_name_(SSL* s, const char* name) - { - return SSL_ctrl_(s, SSL_CTRL_SET_TLSEXT_HOSTNAME, - TLSEXT_NAMETYPE_host_name, const_cast(name)); - } - - void SslGateway::SSL_set_connect_state_(SSL* s) - { - assert(functions.fpSSL_set_connect_state != 0); - - typedef void (FuncType)(SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_set_connect_state); - - return fp(s); - } - - int SslGateway::SSL_connect_(SSL* s) - { - assert(functions.fpSSL_connect != 0); - - typedef int (FuncType)(SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_connect); - - return fp(s); - } - - int SslGateway::SSL_get_error_(const SSL* s, int ret) - { - assert(functions.fpSSL_get_error != 0); - - typedef int (FuncType)(const SSL*, int); - - FuncType* fp = reinterpret_cast(functions.fpSSL_get_error); - - return fp(s, ret); - } - - int SslGateway::SSL_want_(const SSL* s) - { - assert(functions.fpSSL_want != 0); - - typedef int (FuncType)(const SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_want); - - return fp(s); - } - - int SslGateway::SSL_write_(SSL* s, const void* buf, int num) - { - assert(functions.fpSSL_write != 0); - - typedef int (FuncType)(SSL*, const void*, int); - - FuncType* fp = reinterpret_cast(functions.fpSSL_write); - - return fp(s, buf, num); - } - - int SslGateway::SSL_read_(SSL* s, void* buf, int num) - { - assert(functions.fpSSL_read != 0); - - typedef int (FuncType)(SSL*, void*, int); - - FuncType* fp = reinterpret_cast(functions.fpSSL_read); - - return fp(s, buf, num); - } - - int SslGateway::SSL_pending_(const SSL* ssl) - { - assert(functions.fpSSL_pending != 0); - - typedef int (FuncType)(const SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_pending); - - return fp(ssl); - } - - int SslGateway::SSL_get_fd_(const SSL* ssl) - { - assert(functions.fpSSL_get_fd != 0); - - typedef int (FuncType)(const SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_get_fd); - - return fp(ssl); - } - - void SslGateway::SSL_free_(SSL* ssl) - { - assert(functions.fpSSL_free != 0); - - typedef void (FuncType)(SSL*); - - FuncType* fp = reinterpret_cast(functions.fpSSL_free); - - fp(ssl); - } - - const SSL_METHOD* SslGateway::SSLv23_client_method_() - { - if (functions.fpSSLv23_client_method) - { - typedef const SSL_METHOD*(FuncType)(); - - FuncType* fp = reinterpret_cast(functions.fpSSLv23_client_method); - - return fp(); - } - - return TLS_client_method_(); - } - - const SSL_METHOD* SslGateway::TLS_client_method_() - { - assert(functions.fpTLS_client_method != 0); - - typedef const SSL_METHOD*(FuncType)(); - - FuncType* fp = reinterpret_cast(functions.fpTLS_client_method); - - return fp(); - } - - void SslGateway::OPENSSL_config_(const char* configName) - { - assert(functions.fpOPENSSL_config != 0); - - typedef void (FuncType)(const char*); - - FuncType* fp = reinterpret_cast(functions.fpOPENSSL_config); - - fp(configName); - } - - void SslGateway::X509_free_(X509* a) - { - assert(functions.fpX509_free != 0); - - typedef void (FuncType)(X509*); - - FuncType* fp = reinterpret_cast(functions.fpX509_free); - - fp(a); - } - - BIO* SslGateway::BIO_new_ssl_connect_(SSL_CTX* ctx) - { - assert(functions.fpBIO_new_ssl_connect != 0); - - typedef BIO*(FuncType)(SSL_CTX*); - - FuncType* fp = reinterpret_cast(functions.fpBIO_new_ssl_connect); - - return fp(ctx); - } - - void SslGateway::BIO_free_all_(BIO* a) - { - assert(functions.fpBIO_free_all != 0); - - typedef void (FuncType)(BIO*); - - FuncType* fp = reinterpret_cast(functions.fpBIO_free_all); - - fp(a); - } - - long SslGateway::BIO_ctrl_(BIO* bp, int cmd, long larg, void* parg) - { - assert(functions.fpBIO_ctrl != 0); - - typedef long (FuncType)(BIO*, int, long, void*); - - FuncType* fp = reinterpret_cast(functions.fpBIO_ctrl); - - return fp(bp, cmd, larg, parg); - } - - long SslGateway::BIO_get_fd_(BIO* bp, int* fd) - { - return BIO_ctrl_(bp, BIO_C_GET_FD, 0, reinterpret_cast(fd)); - } - - long SslGateway::BIO_get_ssl_(BIO* bp, SSL** ssl) - { - return BIO_ctrl_(bp, BIO_C_GET_SSL, 0, reinterpret_cast(ssl)); - } - - long SslGateway::BIO_set_nbio_(BIO* bp, long n) - { - return BIO_ctrl_(bp, BIO_C_SET_NBIO, n, NULL); - } - - long SslGateway::BIO_set_conn_hostname_(BIO* bp, const char* name) - { - return BIO_ctrl_(bp, BIO_C_SET_CONNECT, 0, const_cast(name)); - } - - unsigned long SslGateway::ERR_get_error_() - { - assert(functions.fpERR_get_error != 0); - - typedef unsigned long (FuncType)(); - - FuncType* fp = reinterpret_cast(functions.fpERR_get_error); - - return fp(); - } - - void SslGateway::ERR_error_string_n_(unsigned long e, char* buf, size_t len) - { - assert(functions.fpERR_error_string_n != 0); - - typedef void (FuncType)(unsigned long, char*, size_t); - - FuncType* fp = reinterpret_cast(functions.fpERR_error_string_n); - - fp(e, buf, len); - } - - void SslGateway::ERR_print_errors_fp_(FILE* fd) - { - if (!functions.fpERR_print_errors_fp) - return; - - typedef void (FuncType)(FILE*); - - FuncType* fp = reinterpret_cast(functions.fpERR_print_errors_fp); - - fp(fd); - } - } - } -} diff --git a/src/network/src/network/ssl/ssl_gateway.h b/src/network/src/network/ssl/ssl_gateway.h deleted file mode 100644 index 30134f3c3..000000000 --- a/src/network/src/network/ssl/ssl_gateway.h +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_SSL_SSL_GATEWAY -#define _IGNITE_NETWORK_SSL_SSL_GATEWAY - -#include -#include -#include - -#include -#include - - -namespace ignite -{ - namespace network - { - namespace ssl - { - /** - * Functions collection. - */ - struct SslFunctions - { - void *fpSSLeay_version; - void *fpSSL_CTX_new; - void *fpSSL_CTX_free; - void *fpSSL_CTX_set_verify; - void *fpSSL_CTX_set_verify_depth; - void *fpSSL_CTX_load_verify_locations; - void *fpSSL_CTX_use_certificate_chain_file; - void *fpSSL_CTX_use_RSAPrivateKey_file; - void *fpSSL_CTX_set_cipher_list; - void *fpSSL_CTX_ctrl; - void *fpSSL_get_verify_result; - void *fpSSL_library_init; - void *fpSSL_load_error_strings; - void *fpSSL_get_peer_certificate; - void *fpSSL_ctrl; - void *fpSSLv23_client_method; - void *fpSSL_set_connect_state; - void *fpSSL_connect; - void *fpSSL_get_error; - void *fpSSL_want; - void *fpSSL_write; - void *fpSSL_read; - void *fpSSL_pending; - void *fpSSL_get_fd; - void *fpSSL_free; - void *fpOPENSSL_config; - void *fpX509_free; - void *fpBIO_new_ssl_connect; - void *fpBIO_free_all; - void *fpBIO_ctrl; - void *fpERR_get_error; - void *fpERR_error_string_n; - void *fpERR_print_errors_fp; - - void *fpOpenSSL_version; - void *fpSSL_CTX_set_options; - void *fpOPENSSL_init_ssl; - void *fpTLS_client_method; - }; - - /** - * SSL Gateway abstraction. - * Used as a factory for secure sockets. Needed for dynamic loading - * of the SSL libraries. - */ - class SslGateway - { - public: - /** - * Get class instance. - * @return SslLibrary instance. - */ - static SslGateway& GetInstance(); - - /** - * Try loading SSL library. - */ - void LoadAll(); - - /** - * Get functions. - * @return Functions structure. - */ - SslFunctions& GetFunctions() - { - return functions; - } - - /** - * Check whether the libraries are loaded. - * @return @c true if loaded. - */ - bool Loaded() const - { - return inited; - } - - char* SSLeay_version_(int type); - - int OPENSSL_init_ssl_(uint64_t opts, const void* settings); - - long SSL_CTX_set_options_(SSL_CTX* ctx, long options); - - long SSL_CTX_ctrl_(SSL_CTX* ctx, int cmd, long larg, void* parg); - - SSL_CTX* SSL_CTX_new_(const SSL_METHOD* meth); - - void SSL_CTX_free_(SSL_CTX* ctx); - - void SSL_CTX_set_verify_(SSL_CTX* ctx, int mode, int (*callback)(int, X509_STORE_CTX*)); - - void SSL_CTX_set_verify_depth_(SSL_CTX* ctx, int depth); - - int SSL_CTX_load_verify_locations_(SSL_CTX* ctx, const char* cAfile, const char* cApath); - - int SSL_CTX_use_certificate_chain_file_(SSL_CTX* ctx, const char* file); - - int SSL_CTX_use_RSAPrivateKey_file_(SSL_CTX* ctx, const char* file, int type); - - int SSL_CTX_set_cipher_list_(SSL_CTX* ctx, const char* str); - - long SSL_get_verify_result_(const SSL* s); - - int SSL_library_init_(); - - void SSL_load_error_strings_(); - - X509* SSL_get_peer_certificate_(const SSL* s); - - long SSL_ctrl_(SSL* s, int cmd, long larg, void* parg); - - long SSL_set_tlsext_host_name_(SSL* s, const char* name); - - void SSL_set_connect_state_(SSL* s); - - int SSL_connect_(SSL* s); - - int SSL_get_error_(const SSL* s, int ret); - - int SSL_want_(const SSL* s); - - int SSL_write_(SSL* s, const void* buf, int num); - - int SSL_read_(SSL* s, void* buf, int num); - - int SSL_pending_(const SSL* ssl); - - int SSL_get_fd_(const SSL* ssl); - - void SSL_free_(SSL* ssl); - - const SSL_METHOD* SSLv23_client_method_(); - - const SSL_METHOD* TLS_client_method_(); - - void OPENSSL_config_(const char* configName); - - void X509_free_(X509* a); - - BIO* BIO_new_ssl_connect_(SSL_CTX* ctx); - - void BIO_free_all_(BIO* a); - - long BIO_ctrl_(BIO* bp, int cmd, long larg, void* parg); - - long BIO_get_fd_(BIO* bp, int* fd); - - long BIO_get_ssl_(BIO* bp, SSL** ssl); - - long BIO_set_nbio_(BIO* bp, long n); - - long BIO_set_conn_hostname_(BIO* bp, const char* name); - - unsigned long ERR_get_error_(); - - void ERR_error_string_n_(unsigned long e, char* buf, size_t len); - - void ERR_print_errors_fp_(FILE *fd); - - private: - /** - * Constructor. - */ - SslGateway(); - - /** - * Destructor. - */ - ~SslGateway(); - - /** - * Unload all SSL symbols. - */ - void UnloadAll(); - - /** - * Load SSL library. - * @param name Name. - * @return Module. - */ - common::dynamic::Module LoadSslLibrary(const char* name); - - /** - * Load all SSL libraries. - */ - void LoadSslLibraries(); - - /** - * Load mandatory SSL methods. - * - * @throw IgniteError if can not load one of the functions. - */ - void LoadMandatoryMethods(); - - /** - * Try load SSL method. - * - * @param name Name. - * @return Method pointer. - */ - void* TryLoadSslMethod(const char* name); - - /** - * Load SSL method. - * - * @param name Name. - * @return Method pointer. - * - * @throw IgniteError if the method is not present. - */ - void* LoadSslMethod(const char* name); - - /** Indicates whether the library was inited. */ - bool inited; - - /** Critical section to prevent multiple instance creation. */ - common::concurrent::CriticalSection initCs; - - /** libeay32 module. */ - common::dynamic::Module libeay32; - - /** ssleay32 module. */ - common::dynamic::Module ssleay32; - - /** libcrypto module. */ - common::dynamic::Module libcrypto; - - /** libssl module. */ - common::dynamic::Module libssl; - - /** Functions. */ - SslFunctions functions; - }; - } - } -} - -#endif //_IGNITE_NETWORK_SSL_SSL_GATEWAY \ No newline at end of file diff --git a/src/network/src/network/tcp_socket_client.h b/src/network/src/network/tcp_socket_client.h deleted file mode 100644 index 8627d99ee..000000000 --- a/src/network/src/network/tcp_socket_client.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#ifndef _IGNITE_NETWORK_TCP_SOCKET_CLIENT -#define _IGNITE_NETWORK_TCP_SOCKET_CLIENT - -#include "network/sockets.h" - -#include - -#include - -#include - -namespace ignite -{ - namespace network - { - /** - * Socket client implementation. - */ - class TcpSocketClient : public SocketClient - { - public: - /** Buffers size */ - enum { BUFFER_SIZE = 0x10000 }; - - /** The time in seconds the connection needs to remain idle before starts sending keepalive probes. */ - enum { KEEP_ALIVE_IDLE_TIME = 60 }; - - /** The time in seconds between individual keepalive probes. */ - enum { KEEP_ALIVE_PROBES_PERIOD = 1 }; - - /** - * Constructor. - */ - TcpSocketClient(); - - /** - * Destructor. - */ - virtual ~TcpSocketClient(); - - /** - * Establish connection with remote TCP service. - * - * @param hostname Remote host name. - * @param port TCP service port. - * @param timeout Timeout. - * @return True on success. - */ - virtual bool Connect(const char* hostname, uint16_t port, int32_t timeout); - - /** - * Close established connection. - */ - virtual void Close(); - - /** - * Send data by established connection. - * - * @param data Pointer to data to be sent. - * @param size Size of the data in bytes. - * @param timeout Timeout. - * @return Number of bytes that have been sent on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Send(const int8_t* data, size_t size, int32_t timeout); - - /** - * Receive data from established connection. - * - * @param buffer Pointer to data buffer. - * @param size Size of the buffer in bytes. - * @param timeout Timeout. - * @return Number of bytes that have been received on success, - * WaitResult::TIMEOUT on timeout and -errno on failure. - */ - virtual int Receive(int8_t* buffer, size_t size, int32_t timeout); - - /** - * Check if the socket is blocking or not. - * @return @c true if the socket is blocking and false otherwise. - */ - virtual bool IsBlocking() const; - - private: - /** - * Close established connection. - */ - void InternalClose(); - - /** - * Tries set socket options. - */ - void TrySetOptions(); - - /** - * Wait on the socket for any event for specified time. - * This function uses poll to achive timeout functionality - * for every separate socket operation. - * - * @param timeout Timeout. - * @param rd Wait for read if @c true, or for write if @c false. - * @return -errno on error, WaitResult::TIMEOUT on timeout and - * WaitResult::SUCCESS on success. - */ - int WaitOnSocket(int32_t timeout, bool rd); - - /** Handle. */ - sockets::SocketHandle socketHandle; - - /** Blocking flag. */ - bool blocking; - - IGNITE_NO_COPY_ASSIGNMENT(TcpSocketClient); - }; - } -} - -#endif //_IGNITE_NETWORK_TCP_SOCKET_CLIENT diff --git a/src/odbc-test/CMakeLists.txt b/src/odbc-test/CMakeLists.txt index afea141d6..5616e9c09 100644 --- a/src/odbc-test/CMakeLists.txt +++ b/src/odbc-test/CMakeLists.txt @@ -46,7 +46,6 @@ set(SOURCES src/meta_queries_test.cpp src/odbc_test_suite.cpp src/test_utils.cpp - src/dummy_test.cpp ../odbc/src/app/application_data_buffer.cpp ../odbc/src/binary/binary_containers.cpp ../odbc/src/binary/binary_raw_writer.cpp diff --git a/src/odbc-test/src/connection_test.cpp b/src/odbc-test/src/connection_test.cpp index 3da373031..6a3d4c07f 100644 --- a/src/odbc-test/src/connection_test.cpp +++ b/src/odbc-test/src/connection_test.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#define BOOST_TEST_MODULE DocumentDBTest #ifdef _WIN32 #include #endif diff --git a/src/odbc/CMakeLists.txt b/src/odbc/CMakeLists.txt index 22ede7f6b..b031d6095 100644 --- a/src/odbc/CMakeLists.txt +++ b/src/odbc/CMakeLists.txt @@ -154,7 +154,7 @@ if (WIN32) add_definitions(-DNOMINMAX) endif() - target_link_libraries(${TARGET} ignite-common-objlib ignite-network-objlib odbccp32 shlwapi) + target_link_libraries(${TARGET} ignite-common-objlib odbccp32 shlwapi) remove_definitions(-DUNICODE=1) @@ -166,7 +166,7 @@ if (WIN32) set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME "ignite.odbc") else() - target_link_libraries(${TARGET} ignite-common ignite-network) + target_link_libraries(${TARGET} ignite-common) endif() if (WIN32 AND ${WITH_ODBC_MSI}) From 97845850bba8b76feedc08896caf909ffba937b8 Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Wed, 2 Mar 2022 18:14:48 -0800 Subject: [PATCH 4/6] removing dummy test --- src/odbc-test/src/dummy_test.cpp | 44 -------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 src/odbc-test/src/dummy_test.cpp diff --git a/src/odbc-test/src/dummy_test.cpp b/src/odbc-test/src/dummy_test.cpp deleted file mode 100644 index 8f141d2ba..000000000 --- a/src/odbc-test/src/dummy_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -#define BOOST_TEST_MODULE MyTest -#include - -int add(int i, int j) { - return i + j; -} - -BOOST_AUTO_TEST_CASE(my_test) { - // seven ways to detect and report the same error: - BOOST_CHECK(add(2, 2) == 4); // #1 continues on error - - BOOST_REQUIRE(add(2, 2) == 4); // #2 throws on error - - if (add(2, 2) != 4) - BOOST_ERROR("Ouch..."); // #3 continues on error - - if (add(2, 2) != 4) - BOOST_FAIL("Ouch..."); // #4 throws on error - - if (add(2, 2) != 4) - throw "Ouch..."; // #5 throws on error - - BOOST_CHECK_MESSAGE(add(2, 2) == 4, // #6 continues on error - "add(..) result: " << add(2, 2)); - - BOOST_CHECK_EQUAL(add(2, 2), 4); // #7 continues on error -} From 4a4ed76c4c00a26717197f78ce81152b73982e50 Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Thu, 3 Mar 2022 18:44:28 -0800 Subject: [PATCH 5/6] creating new define to handle ignite_error_macros --- src/common/include/ignite/ignite_error.h | 12 +++++++++--- src/common/os/win/include/ignite/common/common.h | 2 +- src/odbc/include/ignite/odbc/ignite_error.h | 6 ++++++ src/odbc/src/query/type_info_query.cpp | 1 - 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/include/ignite/ignite_error.h b/src/common/include/ignite/ignite_error.h index d07a36a71..a47290480 100644 --- a/src/common/include/ignite/ignite_error.h +++ b/src/common/include/ignite/ignite_error.h @@ -20,8 +20,8 @@ * Declares ignite::IgniteError class. */ -#ifndef _IGNITE_ODBC_IGNITE_ERROR -#define _IGNITE_ODBC_IGNITE_ERROR +#ifndef _IGNITE_IGNITE_ERROR +#define _IGNITE_IGNITE_ERROR #include @@ -30,6 +30,10 @@ #include +//Define can be removed once the duplicated code was removed +#ifndef _IGNITE_ERROR_MACRO +#define _IGNITE_ERROR_MACRO + #define IGNITE_ERROR_1(code, part1) { \ std::stringstream stream; \ stream << (part1); \ @@ -72,6 +76,8 @@ throw ignite::IgniteError(code, stream.str().c_str()); \ } +#endif //_IGNITE_ERROR_MACRO + #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable : 4275) @@ -310,4 +316,4 @@ namespace ignite # pragma warning(pop) #endif //_MSC_VER -#endif //_IGNITE_ODBC_IGNITE_ERROR +#endif //_IGNITE_IGNITE_ERROR diff --git a/src/common/os/win/include/ignite/common/common.h b/src/common/os/win/include/ignite/common/common.h index 3ef9574e3..fc1f6004e 100644 --- a/src/common/os/win/include/ignite/common/common.h +++ b/src/common/os/win/include/ignite/common/common.h @@ -43,4 +43,4 @@ #define IGNITE_UNUSED(x) ((void) x) -#endif //_IGNITE_ODBC_COMMON_COMMON \ No newline at end of file +#endif //_IGNITE_ODBC_COMMON_COMMON diff --git a/src/odbc/include/ignite/odbc/ignite_error.h b/src/odbc/include/ignite/odbc/ignite_error.h index 3ef2e91fb..e77a711a2 100644 --- a/src/odbc/include/ignite/odbc/ignite_error.h +++ b/src/odbc/include/ignite/odbc/ignite_error.h @@ -29,6 +29,10 @@ #include #include +//Define can be removed once the duplicated code was removed +#ifndef _IGNITE_ERROR_MACRO +#define _IGNITE_ERROR_MACRO + #define IGNITE_ERROR_1(code, part1) \ { \ std::stringstream stream; \ @@ -84,6 +88,8 @@ throw IgniteError(code, stream.str().c_str()); \ } +#endif //_IGNITE_ERROR_MACRO + #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4275) diff --git a/src/odbc/src/query/type_info_query.cpp b/src/odbc/src/query/type_info_query.cpp index ee2535656..30ee06785 100644 --- a/src/odbc/src/query/type_info_query.cpp +++ b/src/odbc/src/query/type_info_query.cpp @@ -121,7 +121,6 @@ TypeInfoQuery::TypeInfoQuery(diagnostic::DiagnosableAdapter& diag, types(), cursor(types.end()) { using namespace ignite::odbc::impl::binary; - using namespace ignite::odbc::impl::binary; using namespace ignite::odbc::type_traits; using meta::ColumnMeta; From 390560a9239bb6f4bb41483f0aa01f2f92c64af1 Mon Sep 17 00:00:00 2001 From: Affonso Vieira Date: Thu, 3 Mar 2022 23:12:21 -0800 Subject: [PATCH 6/6] removing warnings --- src/binary/include/ignite/binary/binary_type.h | 5 ++++- src/odbc/include/ignite/odbc/binary/binary_type.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/binary/include/ignite/binary/binary_type.h b/src/binary/include/ignite/binary/binary_type.h index 492de0364..1c541103d 100644 --- a/src/binary/include/ignite/binary/binary_type.h +++ b/src/binary/include/ignite/binary/binary_type.h @@ -30,6 +30,9 @@ #include + +#ifndef _IGNITE_BINARY_TYPE_MACRO +#define _IGNITE_BINARY_TYPE_MACRO /** * @def IGNITE_BINARY_TYPE_START(T) * Start binary type definition. @@ -126,7 +129,7 @@ static void GetNull(T& dst) \ dst = 0; \ } - +#endif // _IGNITE_BINARY_TYPE_MACRO namespace ignite { namespace binary diff --git a/src/odbc/include/ignite/odbc/binary/binary_type.h b/src/odbc/include/ignite/odbc/binary/binary_type.h index c0dff5abe..ecdde0f0d 100644 --- a/src/odbc/include/ignite/odbc/binary/binary_type.h +++ b/src/odbc/include/ignite/odbc/binary/binary_type.h @@ -28,6 +28,8 @@ #include #include +#ifndef _IGNITE_BINARY_TYPE_MACRO +#define _IGNITE_BINARY_TYPE_MACRO /** * @def IGNITE_BINARY_TYPE_START(T) * Start binary type definition. @@ -118,6 +120,8 @@ dst = 0; \ } +#endif // _IGNITE_BINARY_TYPE_MACRO + namespace ignite { namespace odbc { namespace binary {