Skip to content

Commit

Permalink
chore(server): Usability improvements
Browse files Browse the repository at this point in the history
1. Relax processor requirements for Dragonfly. Fixes dragonflydb#124.
2. Introduce cmake option DF_USE_SSL to allow building DF without SSL support. Fixes dragonflydb#128.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange committed Jun 15, 2022
1 parent 4ec2538 commit a1c3d8e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(CMAKE_CXX_STANDARD 17)
# they just disappear.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/helio/cmake" ${CMAKE_MODULE_PATH})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DF_USE_SSL "Provide support for SSL connections" ON)

include(third_party)
message(STATUS "after thirdpary")
Expand Down
2 changes: 1 addition & 1 deletion helio
2 changes: 1 addition & 1 deletion patches/lua-v5.4.4.patch
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ index d46e650c..e347e614 100644

+uname_m := $(shell uname -m)
+ifeq ($(uname_m),x86_64)
+OPTFLAGS= -march=broadwell
+OPTFLAGS= -march=sandybridge
+else ifeq ($(uname_m), aarch64)
+OPTFLAGS= -march=armv8.2-a+fp16+rcpc+dotprod+crypto
+else
Expand Down
10 changes: 7 additions & 3 deletions src/core/compact_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ void RobjWrapper::MakeInnerRoom(size_t current_cap, size_t desired, pmr::memory_
inner_obj_ = newp;
}

#pragma GCC push_options
#pragma GCC optimize("Ofast")
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC push_options
#pragma GCC optimize("Ofast")
#endif

// len must be at least 16
void ascii_pack(const char* ascii, size_t len, uint8_t* bin) {
Expand Down Expand Up @@ -460,7 +462,9 @@ bool compare_packed(const uint8_t* packed, const char* ascii, size_t ascii_len)
return true;
}

#pragma GCC pop_options
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC pop_options
#endif

} // namespace detail

Expand Down
8 changes: 7 additions & 1 deletion src/facade/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
add_library(dfly_facade dragonfly_listener.cc dragonfly_connection.cc facade.cc
memcache_parser.cc redis_parser.cc reply_builder.cc)

if (DF_USE_SSL)
set(TLS_LIB tls_lib)
target_compile_definitions(dfly_facade PRIVATE DFLY_USE_SSL)
endif()

cxx_link(dfly_facade base uring_fiber_lib fibers_ext strings_lib http_server_lib
tls_lib TRDP::mimalloc TRDP::dconv)
${TLS_LIB} TRDP::mimalloc TRDP::dconv)

add_library(facade_test facade_test.cc)
cxx_link(facade_test dfly_facade gtest_main_ext)
Expand Down
10 changes: 9 additions & 1 deletion src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include "facade/redis_parser.h"
#include "facade/service_interface.h"
#include "util/fiber_sched_algo.h"

#ifdef DFLY_USE_SSL
#include "util/tls/tls_socket.h"
#endif

#include "util/uring/uring_socket.h"

ABSL_FLAG(bool, tcp_nodelay, false,
Expand Down Expand Up @@ -181,6 +185,7 @@ void Connection::HandleRequests() {

auto remote_ep = lsb->RemoteEndpoint();

#ifdef DFLY_USE_SSL
unique_ptr<tls::TlsSocket> tls_sock;
if (ctx_) {
tls_sock.reset(new tls::TlsSocket(socket_.get()));
Expand All @@ -193,8 +198,11 @@ void Connection::HandleRequests() {
}
VLOG(1) << "TLS handshake succeeded";
}

FiberSocketBase* peer = tls_sock ? (FiberSocketBase*)tls_sock.get() : socket_.get();
#else
FiberSocketBase* peer = socket_.get();
#endif

io::Result<bool> http_res{false};
if (absl::GetFlag(FLAGS_http_admin_console))
http_res = CheckForHttpProto(peer);
Expand Down
11 changes: 11 additions & 0 deletions src/facade/dragonfly_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "facade/dragonfly_listener.h"

#ifdef DFLY_USE_SSL
#include <openssl/ssl.h>
#endif

#include "base/flags.h"
#include "base/logging.h"
Expand Down Expand Up @@ -47,6 +49,8 @@ using namespace util;
using absl::GetFlag;

namespace {

#ifdef DFLY_USE_SSL
// To connect: openssl s_client -cipher "ADH:@SECLEVEL=0" -state -crlf -connect 127.0.0.1:6380
static SSL_CTX* CreateSslCntx() {
SSL_CTX* ctx = SSL_CTX_new(TLS_server_method());
Expand Down Expand Up @@ -90,6 +94,7 @@ static SSL_CTX* CreateSslCntx() {

return ctx;
}
#endif

bool ConfigureKeepAlive(int fd, unsigned interval_sec) {
DCHECK_GT(interval_sec, 3u);
Expand Down Expand Up @@ -121,17 +126,23 @@ bool ConfigureKeepAlive(int fd, unsigned interval_sec) {
} // namespace

Listener::Listener(Protocol protocol, ServiceInterface* si) : service_(si), protocol_(protocol) {

#ifdef DFLY_USE_SSL
if (GetFlag(FLAGS_tls)) {
OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
ctx_ = CreateSslCntx();
}
#endif

http_base_.reset(new HttpListener<>);
http_base_->set_resource_prefix("https://romange.s3.eu-west-1.amazonaws.com/static");
si->ConfigureHttpHandlers(http_base_.get());
}

Listener::~Listener() {
#ifdef DFLY_USE_SSL
SSL_CTX_free(ctx_);
#endif
}

util::Connection* Listener::NewConnection(ProactorBase* proactor) {
Expand Down

0 comments on commit a1c3d8e

Please sign in to comment.