diff --git a/arangod/Cluster/HeartbeatThread.h b/arangod/Cluster/HeartbeatThread.h index 7f0da581c9..ede66a4866 100644 --- a/arangod/Cluster/HeartbeatThread.h +++ b/arangod/Cluster/HeartbeatThread.h @@ -26,10 +26,9 @@ #include "Basics/Thread.h" -#include - #include "Basics/ConditionVariable.h" #include "Basics/Mutex.h" +#include "Basics/asio-helper.h" #include "Cluster/AgencyComm.h" #include "Cluster/DBServerAgencySync.h" #include "Logger/Logger.h" diff --git a/arangod/GeneralServer/GeneralServerFeature.h b/arangod/GeneralServer/GeneralServerFeature.h index 6dae90fc87..c2ecb281f6 100644 --- a/arangod/GeneralServer/GeneralServerFeature.h +++ b/arangod/GeneralServer/GeneralServerFeature.h @@ -28,6 +28,7 @@ #include #include +#include "Basics/asio-helper.h" #include "Actions/RestActionHandler.h" #include "VocBase/AuthInfo.h" diff --git a/arangod/Scheduler/JobQueue.h b/arangod/Scheduler/JobQueue.h index 906b1f070a..5f3cd06abf 100644 --- a/arangod/Scheduler/JobQueue.h +++ b/arangod/Scheduler/JobQueue.h @@ -25,9 +25,9 @@ #include "Basics/Common.h" -#include #include +#include "Basics/asio-helper.h" #include "Basics/ConditionVariable.h" #include "Basics/Thread.h" #include "Scheduler/Job.h" diff --git a/arangod/Scheduler/SocketTask.h b/arangod/Scheduler/SocketTask.h index 1c58c0fb34..feb859ddcd 100644 --- a/arangod/Scheduler/SocketTask.h +++ b/arangod/Scheduler/SocketTask.h @@ -29,6 +29,7 @@ #include +#include "Basics/asio-helper.h" #include "Basics/StringBuffer.h" #include "Scheduler/Socket.h" #include "Statistics/StatisticsAgent.h" diff --git a/lib/Basics/asio-helper.h b/lib/Basics/asio-helper.h new file mode 100644 index 0000000000..24e63d450d --- /dev/null +++ b/lib/Basics/asio-helper.h @@ -0,0 +1,68 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2016 ArangoDB GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler +//////////////////////////////////////////////////////////////////////////////// + +#include + +// these classes are only here in order to shutup compiler warning +// DO NOT USE THEM! + +#ifndef ARANGODB_BASICS_ASIO_HELPER_H_1 +#define ARANGODB_BASICS_ASIO_HELPER_H_1 1 +namespace { +class Unused1 { + protected: + const boost::system::error_category& unused1 + = boost::asio::error::system_category; + + const boost::system::error_category& unused2 + = boost::asio::error::netdb_category; + + const boost::system::error_category& unused3 + = boost::asio::error::addrinfo_category; + + const boost::system::error_category& unused4 + = boost::asio::error::misc_category; + + const boost::system::error_category& unused5 + = boost::system::posix_category; + + const boost::system::error_category& unused6 + = boost::system::errno_ecat; + + const boost::system::error_category& unused7 + = boost::system::native_ecat; +}; +} +#endif + +#ifdef BOOST_ASIO_SSL_HPP +#ifndef ARANGODB_BASICS_ASIO_HELPER_H_2 +#define ARANGODB_BASICS_ASIO_HELPER_H_2 1 +namespace { +class Unused2 { + protected: + const boost::system::error_category& unused1 + = boost::asio::error::ssl_category; +}; +} +#endif +#endif diff --git a/lib/Endpoint/Endpoint.h b/lib/Endpoint/Endpoint.h index 63d576b5a0..032a640216 100644 --- a/lib/Endpoint/Endpoint.h +++ b/lib/Endpoint/Endpoint.h @@ -26,8 +26,6 @@ #include "Basics/Common.h" -#include - #ifdef TRI_HAVE_WINSOCK2_H #include #include @@ -35,6 +33,7 @@ #include +#include "Basics/asio-helper.h" #include "Basics/socket-utils.h" namespace arangodb { diff --git a/lib/Ssl/SslFeature.cpp b/lib/Ssl/SslFeature.cpp index 2089930964..d649f002c0 100644 --- a/lib/Ssl/SslFeature.cpp +++ b/lib/Ssl/SslFeature.cpp @@ -42,96 +42,6 @@ using namespace arangodb; using namespace arangodb::basics; using namespace arangodb::options; -// OPEN SSL support -namespace { -long* opensslLockCount; -TRI_mutex_t* opensslLocks; - -#if OPENSSL_VERSION_NUMBER < 0x01000000L - -unsigned long opensslThreadId() { - return (unsigned long)Thread::currentThreadId(); -} - -#else - -// The compiler chooses the right one from the following two, -// according to the type of the return value of pthread_self(): - -#ifndef __sun -template -void setter(CRYPTO_THREADID* id, T p) { - CRYPTO_THREADID_set_pointer(id, p); -} -#else -template -void setter(CRYPTO_THREADID* id, T p) { - CRYPTO_THREADID_set_pointer(id, (void*)(intptr_t)p); -} -#endif - -#ifndef __APPLE__ -template <> -void setter(CRYPTO_THREADID* id, unsigned long val) { - CRYPTO_THREADID_set_numeric(id, val); -} -#endif - -static void arango_threadid_func(CRYPTO_THREADID* id) { - auto self = Thread::currentThreadId(); - - setter(id, self); -} - -#endif - -void opensslLockingCallback(int mode, int type, char const* /* file */, - int /* line */) { - if (mode & CRYPTO_LOCK) { - TRI_LockMutex(&(opensslLocks[type])); - opensslLockCount[type]++; - } else { - TRI_UnlockMutex(&(opensslLocks[type])); - } -} - -void opensslSetup() { - opensslLockCount = (long*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); - opensslLocks = - (TRI_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(TRI_mutex_t)); - - for (long i = 0; i < CRYPTO_num_locks(); ++i) { - opensslLockCount[i] = 0; - TRI_InitMutex(&(opensslLocks[i])); - } - -#if OPENSSL_VERSION_NUMBER < 0x01000000L - CRYPTO_set_id_callback(opensslThreadId); - CRYPTO_set_locking_callback(opensslLockingCallback); -#else - CRYPTO_THREADID_set_callback(arango_threadid_func); - CRYPTO_set_locking_callback(opensslLockingCallback); -#endif -} - -void opensslCleanup() { - CRYPTO_set_locking_callback(nullptr); - -#if OPENSSL_VERSION_NUMBER < 0x01000000L - CRYPTO_set_id_callback(nullptr); -#else - CRYPTO_THREADID_set_callback(nullptr); -#endif - - for (long i = 0; i < CRYPTO_num_locks(); ++i) { - TRI_DestroyMutex(&(opensslLocks[i])); - } - - OPENSSL_free(opensslLocks); - OPENSSL_free(opensslLockCount); -} -} - const boost::asio::ssl::detail::openssl_init SslFeature::sslBase{}; SslFeature::SslFeature(application_features::ApplicationServer* server) @@ -143,18 +53,7 @@ SslFeature::SslFeature(application_features::ApplicationServer* server) } void SslFeature::prepare() { - // SSL_library_init(); - // SSL_load_error_strings(); - // OpenSSL_add_all_algorithms(); - // ERR_load_crypto_strings(); - - // opensslSetup(); } void SslFeature::unprepare() { - // opensslCleanup(); - - // ERR_free_strings(); - // EVP_cleanup(); - // CRYPTO_cleanup_all_ex_data(); } diff --git a/lib/Ssl/SslFeature.h b/lib/Ssl/SslFeature.h index ac6458ae67..7e06ce3621 100644 --- a/lib/Ssl/SslFeature.h +++ b/lib/Ssl/SslFeature.h @@ -28,6 +28,8 @@ #include #include +#include "Basics/asio-helper.h" + namespace arangodb { class SslFeature final : public application_features::ApplicationFeature { public: diff --git a/lib/Ssl/SslServerFeature.h b/lib/Ssl/SslServerFeature.h index 1217010f2c..21f0f2cd55 100644 --- a/lib/Ssl/SslServerFeature.h +++ b/lib/Ssl/SslServerFeature.h @@ -28,6 +28,8 @@ #include #include +#include "Basics/asio-helper.h" + namespace arangodb { class SslServerFeature final : public application_features::ApplicationFeature { public: diff --git a/lib/Ssl/ssl-helper.h b/lib/Ssl/ssl-helper.h index 5527135e76..c8e311209a 100644 --- a/lib/Ssl/ssl-helper.h +++ b/lib/Ssl/ssl-helper.h @@ -31,12 +31,10 @@ #include #include +#include "Basics/asio-helper.h" + namespace arangodb { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief SSL protocol methods -//////////////////////////////////////////////////////////////////////////////// - +// SSL protocol methods enum protocol_e { SSL_UNKNOWN = 0, SSL_V2 = 1, @@ -48,33 +46,17 @@ enum protocol_e { SSL_LAST }; -//////////////////////////////////////////////////////////////////////////////// -/// @brief SSL_CONST -//////////////////////////////////////////////////////////////////////////////// - #if (OPENSSL_VERSION_NUMBER < 0x00999999L) #define SSL_CONST /* */ #else #define SSL_CONST const #endif -//////////////////////////////////////////////////////////////////////////////// -/// @brief creates an SSL context -//////////////////////////////////////////////////////////////////////////////// - boost::optional sslContext( protocol_e, std::string const& keyfile); -//////////////////////////////////////////////////////////////////////////////// -/// @brief get the name of an SSL protocol version -//////////////////////////////////////////////////////////////////////////////// - std::string protocolName(protocol_e protocol); -//////////////////////////////////////////////////////////////////////////////// -/// @brief get last SSL error -//////////////////////////////////////////////////////////////////////////////// - std::string lastSSLError(); }