Skip to content

Commit

Permalink
Merge pull request #434 from beef9999/beef9999/br-06
Browse files Browse the repository at this point in the history
openssl not use locking after 1.1.0
  • Loading branch information
lihuiba authored Aug 1, 2024
2 parents 1fd201d + c1f3e59 commit 1081f1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ option(PHOTON_BUILD_TESTING "enable build testing" OFF)
option(PHOTON_BUILD_WITH_ASAN "build with asan" OFF)
option(PHOTON_ENABLE_URING "enable io_uring function" OFF)
option(PHOTON_ENABLE_FUSE "enable fuse function" OFF)
option(PHOTON_GLOBAL_INIT_OPENSSL "Turn this off if any of your third-party libs inits old-version OpenSSL as well,
because Photon will register coroutine locks for crypto. But don't bother if you have latest OpenSSL >= 1.1.0" ON)
option(PHOTON_ENABLE_SASL "enable sasl" OFF)
option(PHOTON_ENABLE_MIMIC_VDSO "enable mimic vdso" OFF)
option(PHOTON_ENABLE_FSTACK_DPDK "Use f-stack + DPDK as the event engine" OFF)
Expand Down Expand Up @@ -228,6 +230,9 @@ target_include_directories(photon_obj PRIVATE include ${OPENSSL_INCLUDE_DIRS} ${
)

target_compile_definitions(photon_obj PRIVATE _FILE_OFFSET_BITS=64 FUSE_USE_VERSION=29)
if (PHOTON_GLOBAL_INIT_OPENSSL)
target_compile_definitions(photon_obj PRIVATE PHOTON_GLOBAL_INIT_OPENSSL)
endif ()
if (PHOTON_ENABLE_URING)
target_include_directories(photon_obj PRIVATE ${URING_INCLUDE_DIRS})
target_compile_definitions(photon_obj PRIVATE PHOTON_URING=on)
Expand Down
4 changes: 2 additions & 2 deletions fs/httpfs/httpfs_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ IFileSystem* new_httpfs_v2(bool default_https, uint64_t conn_timeout,
client, client_ownership);
}

IFile* new_httpfile_v2(const char* url, HttpFs_v2* httpfs, uint64_t conn_timeout,
IFile* new_httpfile_v2(const char* url, IFileSystem* httpfs, uint64_t conn_timeout,
uint64_t stat_timeout) {
return new HttpFile_v2(url, httpfs, conn_timeout, stat_timeout);
return new HttpFile_v2(url, (HttpFs_v2*) httpfs, conn_timeout, stat_timeout);
}
} // namespace fs
}
12 changes: 10 additions & 2 deletions net/security-context/tls-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,21 @@ class GlobalSSLContext : public Singleton<GlobalSSLContext> {
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
OpenSSL_add_all_algorithms();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
mtx.clear();
for (int i = 0; i < CRYPTO_num_locks(); i++) {
mtx.emplace_back(std::make_unique<photon::mutex>());
}
CRYPTO_set_id_callback(&GlobalSSLContext ::threadid_callback);
CRYPTO_set_id_callback(&GlobalSSLContext::threadid_callback);
CRYPTO_set_locking_callback(&GlobalSSLContext::lock_callback);
#endif
}

~GlobalSSLContext() {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
#endif
}
};

Expand Down Expand Up @@ -172,7 +176,11 @@ class TLSContextImpl : public TLSContext {
}
};

void __OpenSSLGlobalInit() { (void)GlobalSSLContext::getInstance(); }
void __OpenSSLGlobalInit() {
#ifdef PHOTON_GLOBAL_INIT_OPENSSL
(void)GlobalSSLContext::getInstance();
#endif
}

TLSContext* new_tls_context(const char* cert_str, const char* key_str,
const char* passphrase, TLSVersion version) {
Expand Down

0 comments on commit 1081f1a

Please sign in to comment.