Skip to content

Commit

Permalink
Upgrade uvw to 3.X and fix/suppress some compiler warnings (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoparente authored Oct 17, 2023
1 parent d4f43a2 commit 167a0b1
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 162 deletions.
2 changes: 1 addition & 1 deletion 3rd/fstrm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ add_library(fstrm
libmy/my_queue_mutex.c
)
add_library(fstrm::fstrm ALIAS fstrm)
target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable)
target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable -Wno-unused-but-set-variable)

target_include_directories(fstrm
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion cmd/pktvisord/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ int main(int argc, char *argv[])
// if we are demonized, change to root directory now that (potentially) logs are open
if (options.daemon) {
#if __has_include(<unistd.h>)
chdir("/");
[[maybe_unused]] int result = chdir("/");
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[requires]
catch2/3.4.0
corrade/2020.06
cpp-httplib/0.14.0
cpp-httplib/0.14.1
docopt.cpp/0.6.3
fast-cpp-csv-parser/cci.20211104
json-schema-validator/2.2.0
libmaxminddb/1.7.1
nlohmann_json/3.11.2
openssl/1.1.1k
openssl/1.1.1w
opentelemetry-proto/1.0.0
pcapplusplus/22.11
protobuf/3.21.12
sigslot/1.2.2
spdlog/1.12.0
uvw/2.12.1
uvw/3.2.0
libpcap/1.10.4
yaml-cpp/0.8.0
robin-hood-hashing/3.11.5
Expand Down
1 change: 1 addition & 0 deletions src/IpPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <csv.h>
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#pragma once
#include <nlohmann/json.hpp>
#include <opentelemetry/proto/metrics/v1/metrics.pb.h>
#include <sstream>
#include <timer.hpp>
#ifdef __GNUC__
Expand All @@ -17,6 +16,7 @@
#include <cpc_sketch.hpp>
#include <frequent_items_sketch.hpp>
#include <kll_sketch.hpp>
#include <opentelemetry/proto/metrics/v1/metrics.pb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/dns/v1/DnsStreamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void DnsStreamHandler::start()
_f_rcodes.push_back(NoError);
} else if (config_exists("only_rcode")) {
std::vector<std::string> rcodes;
uint64_t want_code;
uint64_t want_code{0};
try {
want_code = config_get<uint64_t>("only_rcode");
} catch (const std::exception &e) {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/dns/v2/DnsStreamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void DnsStreamHandler::start()
_f_rcodes.push_back(NoError);
} else if (config_exists("only_rcode")) {
std::vector<std::string> rcodes;
uint64_t want_code;
uint64_t want_code{0};
try {
want_code = config_get<uint64_t>("only_rcode");
} catch (const std::exception &e) {
Expand Down
7 changes: 7 additions & 0 deletions src/inputs/dnstap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS pb/dnstap.proto)

if(NOT WIN32)
# Suppress the warning for the generated files
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS}
PROPERTIES COMPILE_FLAGS "-Wno-missing-declarations -Wno-unused-parameter"
)
endif()

corrade_add_static_plugin(VisorInputDnstap ${CMAKE_CURRENT_BINARY_DIR}
Dnstap.conf
DnstapInputModulePlugin.cpp
Expand Down
85 changes: 46 additions & 39 deletions src/inputs/dnstap/DnstapInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
#include "DnstapException.h"
#include "ThreadName.h"
#include <filesystem>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include <uvw/async.h>
#include <uvw/loop.h>
#include <uvw/pipe.h>
#include <uvw/stream.h>
#include <uvw/tcp.h>
#include <uvw/timer.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

namespace visor::input::dnstap {

Expand Down Expand Up @@ -129,16 +136,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
}

// main io loop, run in its own thread
_io_loop = uvw::Loop::create();
_io_loop = uvw::loop::create();
if (!_io_loop) {
throw DnstapException("unable to create io loop");
}
// AsyncHandle lets us stop the loop from its own thread
_async_h = _io_loop->resource<uvw::AsyncHandle>();
_async_h = _io_loop->resource<uvw::async_handle>();
if (!_async_h) {
throw DnstapException("unable to initialize AsyncHandle");
}
_async_h->once<uvw::AsyncEvent>([this](const auto &, auto &handle) {
_async_h->on<uvw::async_event>([this](const auto &, auto &handle) {
_timer->stop();
_timer->close();
_tcp_server_h->stop();
Expand All @@ -147,16 +154,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
_io_loop->close();
handle.close();
});
_async_h->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
_async_h->on<uvw::error_event>([this](const auto &err, auto &handle) {
_logger->error("[{}] AsyncEvent error: {}", _name, err.what());
handle.close();
});

_timer = _io_loop->resource<uvw::TimerHandle>();
_timer = _io_loop->resource<uvw::timer_handle>();
if (!_timer) {
throw DnstapException("unable to initialize TimerHandle");
}
_timer->on<uvw::TimerEvent>([this](const auto &, auto &) {
_timer->on<uvw::timer_event>([this](const auto &, auto &) {
timespec stamp;
// use now()
std::timespec_get(&stamp, TIME_UTC);
Expand All @@ -165,25 +172,25 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
static_cast<DnstapInputEventProxy *>(proxy.get())->heartbeat_cb(stamp);
}
});
_timer->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
_timer->on<uvw::error_event>([this](const auto &err, auto &handle) {
_logger->error("[{}] TimerEvent error: {}", _name, err.what());
handle.close();
});

// setup server socket
_tcp_server_h = _io_loop->resource<uvw::TCPHandle>();
_tcp_server_h = _io_loop->resource<uvw::tcp_handle>();
if (!_tcp_server_h) {
throw DnstapException("unable to initialize server PipeHandle");
throw DnstapException("unable to initialize server pipe_handle");
}

_tcp_server_h->on<uvw::ErrorEvent>([this](const auto &err, auto &) {
_tcp_server_h->on<uvw::error_event>([this](const auto &err, auto &) {
_logger->error("[{}] socket error: {}", _name, err.what());
throw DnstapException(err.what());
});

// ListenEvent happens on client connection
_tcp_server_h->on<uvw::ListenEvent>([this](const uvw::ListenEvent &, uvw::TCPHandle &) {
auto client = _io_loop->resource<uvw::TCPHandle>();
// listen_event happens on client connection
_tcp_server_h->on<uvw::listen_event>([this](const uvw::listen_event &, uvw::tcp_handle &) {
auto client = _io_loop->resource<uvw::tcp_handle>();
if (!client) {
throw DnstapException("unable to initialize connected client TCPHandle");
}
Expand All @@ -209,14 +216,14 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
}
};

client->on<uvw::ErrorEvent>([this](const uvw::ErrorEvent &err, uvw::TCPHandle &c_sock) {
client->on<uvw::error_event>([this](const uvw::error_event &err, uvw::tcp_handle &c_sock) {
_logger->error("[{}]: dnstap client socket error: {}", _name, err.what());
c_sock.stop();
c_sock.close();
});

// client sent data
client->on<uvw::DataEvent>([this](const uvw::DataEvent &data, uvw::TCPHandle &c_sock) {
client->on<uvw::data_event>([this](const uvw::data_event &data, uvw::tcp_handle &c_sock) {
assert(_tcp_sessions[c_sock.fd()]);
try {
_tcp_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast<uint8_t *>(data.data.get()), data.length);
Expand All @@ -227,20 +234,20 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()
}
});
// client was closed
client->on<uvw::CloseEvent>([this](const uvw::CloseEvent &, uvw::TCPHandle &c_sock) {
client->on<uvw::close_event>([this](const uvw::close_event &, uvw::tcp_handle &c_sock) {
_logger->info("[{}]: dnstap client disconnected", _name);
_tcp_sessions.erase(c_sock.fd());
});
// client read EOF
client->on<uvw::EndEvent>([this](const uvw::EndEvent &, uvw::TCPHandle &c_sock) {
client->on<uvw::end_event>([this](const uvw::end_event &, uvw::tcp_handle &c_sock) {
_logger->info("[{}]: dnstap client EOF {}", _name, c_sock.peer().ip);
c_sock.stop();
c_sock.close();
});

_tcp_server_h->accept(*client);
_logger->info("[{}]: dnstap client connected {}", _name, client->peer().ip);
_tcp_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::TCPHandle>>(client, CONTENT_TYPE, on_data_frame);
_tcp_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::tcp_handle>>(client, CONTENT_TYPE, on_data_frame);
client->read();
});

Expand All @@ -250,7 +257,7 @@ void DnstapInputStream::_create_frame_stream_tcp_socket()

// spawn the loop
_io_thread = std::make_unique<std::thread>([this] {
_timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000});
_timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000});
thread::change_self_name(schema_key(), name());
_io_loop->run();
});
Expand All @@ -260,16 +267,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
assert(config_exists("socket"));

// main io loop, run in its own thread
_io_loop = uvw::Loop::create();
_io_loop = uvw::loop::create();
if (!_io_loop) {
throw DnstapException("unable to create io loop");
}
// AsyncHandle lets us stop the loop from its own thread
_async_h = _io_loop->resource<uvw::AsyncHandle>();
_async_h = _io_loop->resource<uvw::async_handle>();
if (!_async_h) {
throw DnstapException("unable to initialize AsyncHandle");
}
_async_h->once<uvw::AsyncEvent>([this](const auto &, auto &handle) {
_async_h->on<uvw::async_event>([this](const auto &, auto &handle) {
_timer->stop();
_timer->close();
_unix_server_h->stop();
Expand All @@ -278,16 +285,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
_io_loop->close();
handle.close();
});
_async_h->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
_async_h->on<uvw::error_event>([this](const auto &err, auto &handle) {
_logger->error("[{}] AsyncEvent error: {}", _name, err.what());
handle.close();
});

_timer = _io_loop->resource<uvw::TimerHandle>();
_timer = _io_loop->resource<uvw::timer_handle>();
if (!_timer) {
throw DnstapException("unable to initialize TimerHandle");
}
_timer->on<uvw::TimerEvent>([this](const auto &, auto &) {
_timer->on<uvw::timer_event>([this](const auto &, auto &) {
timespec stamp;
// use now()
std::timespec_get(&stamp, TIME_UTC);
Expand All @@ -296,27 +303,27 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
static_cast<DnstapInputEventProxy *>(proxy.get())->heartbeat_cb(stamp);
}
});
_timer->on<uvw::ErrorEvent>([this](const auto &err, auto &handle) {
_timer->on<uvw::error_event>([this](const auto &err, auto &handle) {
_logger->error("[{}] TimerEvent error: {}", _name, err.what());
handle.close();
});

// setup server socket
_unix_server_h = _io_loop->resource<uvw::PipeHandle>();
_unix_server_h = _io_loop->resource<uvw::pipe_handle>();
if (!_unix_server_h) {
throw DnstapException("unable to initialize server PipeHandle");
throw DnstapException("unable to initialize server pipe_handle");
}

_unix_server_h->on<uvw::ErrorEvent>([this](const auto &err, auto &) {
_unix_server_h->on<uvw::error_event>([this](const auto &err, auto &) {
_logger->error("[{}] socket error: {}", _name, err.what());
throw DnstapException(err.what());
});

// ListenEvent happens on client connection
_unix_server_h->on<uvw::ListenEvent>([this](const uvw::ListenEvent &, uvw::PipeHandle &) {
auto client = _io_loop->resource<uvw::PipeHandle>();
// listen_event happens on client connection
_unix_server_h->on<uvw::listen_event>([this](const uvw::listen_event &, uvw::pipe_handle &) {
auto client = _io_loop->resource<uvw::pipe_handle>();
if (!client) {
throw DnstapException("unable to initialize connected client PipeHandle");
throw DnstapException("unable to initialize connected client pipe_handle");
}

auto on_data_frame = [this](const void *data, std::size_t len_data) {
Expand All @@ -339,14 +346,14 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
}
};

client->on<uvw::ErrorEvent>([this](const uvw::ErrorEvent &err, uvw::PipeHandle &c_sock) {
client->on<uvw::error_event>([this](const uvw::error_event &err, uvw::pipe_handle &c_sock) {
_logger->error("[{}]: dnstap client socket error: {}", _name, err.what());
c_sock.stop();
c_sock.close();
});

// client sent data
client->on<uvw::DataEvent>([this](const uvw::DataEvent &data, uvw::PipeHandle &c_sock) {
client->on<uvw::data_event>([this](const uvw::data_event &data, uvw::pipe_handle &c_sock) {
assert(_unix_sessions[c_sock.fd()]);
try {
_unix_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast<uint8_t *>(data.data.get()), data.length);
Expand All @@ -357,20 +364,20 @@ void DnstapInputStream::_create_frame_stream_unix_socket()
}
});
// client was closed
client->on<uvw::CloseEvent>([this](const uvw::CloseEvent &, uvw::PipeHandle &c_sock) {
client->on<uvw::close_event>([this](const uvw::close_event &, uvw::pipe_handle &c_sock) {
_logger->info("[{}]: dnstap client disconnected", _name);
_unix_sessions.erase(c_sock.fd());
});
// client read EOF
client->on<uvw::EndEvent>([this](const uvw::EndEvent &, uvw::PipeHandle &c_sock) {
client->on<uvw::end_event>([this](const uvw::end_event &, uvw::pipe_handle &c_sock) {
_logger->info("[{}]: dnstap client EOF {}", _name, c_sock.sock());
c_sock.stop();
c_sock.close();
});

_unix_server_h->accept(*client);
_logger->info("[{}]: dnstap client connected {}", _name, client->sock());
_unix_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::PipeHandle>>(client, CONTENT_TYPE, on_data_frame);
_unix_sessions[client->fd()] = std::make_unique<FrameSessionData<uvw::pipe_handle>>(client, CONTENT_TYPE, on_data_frame);
client->read();
});

Expand All @@ -383,7 +390,7 @@ void DnstapInputStream::_create_frame_stream_unix_socket()

// spawn the loop
_io_thread = std::make_unique<std::thread>([this] {
_timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000});
_timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000});
thread::change_self_name(schema_key(), name());
_io_loop->run();
});
Expand Down
Loading

0 comments on commit 167a0b1

Please sign in to comment.