Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Checks:
- core*
- cppcoreguidelines-*
- modernize*
- bugprone-*
- performance-*
- readability-*
- portability-*
- clang-diagnostic-*
- misc-*
- google-build-namespaces
- google-build-using-namespace
- google-default-arguments
- google-explicit-constructor
- google-readability-casting
- -modernize-use-trailing-return-type
- -modernize-use-nodiscard
- -modernize-concat-nested-namespaces
- -modernize-use-default-member-init
- -modernize-use-ranges
- -modernize-use-designated-initializers
- -misc-non-private-member-variables-in-classes
- -misc-use-internal-linkage
- -misc-use-anonymous-namespace
- -cppcoreguidelines-pro-type-vararg
- -cppcoreguidelines-non-private-member-variables-in-classes
- -cppcoreguidelines-special-member-functions
- -cppcoreguidelines-pro-type-reinterpret-cast
- -cppcoreguidelines-pro-type-union-access
- -cppcoreguidelines-pro-bounds-pointer-arithmetic
- -cppcoreguidelines-pro-type-member-init
- -cppcoreguidelines-owning-memory
- -cppcoreguidelines-avoid-const-or-ref-data-members
- -cppcoreguidelines-macro-usage
- -cppcoreguidelines-pro-bounds-constant-array-index
- -cppcoreguidelines-pro-bounds-array-to-pointer-decay
- -cppcoreguidelines-pro-type-static-cast-downcast
- -bugprone-easily-swappable-parameters
- -readability-named-parameter
- -readability-identifier-length

CheckOptions:
bugprone-assert-side-effect.CheckFunctionCalls: true
performance-move-const-arg.CheckTriviallyCopyableMove: false
cppcoreguidelines-avoid-do-while.IgnoreMacros: true
13 changes: 7 additions & 6 deletions aether/aether_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
#include "aether/aether_app.h"

// IWYU pragma: begin_keeps
#include "aether/types/literal_array.h"
#include "aether/types/address_parser.h"
#include "aether/types/literal_array.h"

#include "aether/adapters/ethernet.h"
#include "aether/adapters/wifi_adapter.h"
#include "aether/crypto.h"
#include "aether/crypto/key.h"
#include "aether/global_ids.h"
#include "aether/adapters/ethernet.h"
#include "aether/registration_cloud.h"
#include "aether/adapters/wifi_adapter.h"
#include "aether/poller/win_poller.h"
#include "aether/poller/epoll_poller.h"
#include "aether/poller/kqueue_poller.h"
#include "aether/poller/freertos_poller.h"
#include "aether/poller/kqueue_poller.h"
#include "aether/poller/win_poller.h"
#include "aether/registration_cloud.h"

#include "aether/dns/dns_c_ares.h"
#include "aether/dns/esp32_dns_resolve.h"
Expand Down Expand Up @@ -299,6 +299,7 @@ void AetherAppContext::InitComponentContext() {
RcPtr<AetherApp> AetherApp::Construct(AetherAppContext context) {
// init all the components in context
context.InitComponentContext();

context.init_tele_(context);

auto app = MakeRcPtr<AetherApp>();
Expand Down
7 changes: 4 additions & 3 deletions aether/api_protocol/protocol_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "aether/api_protocol/protocol_context.h"

#include <cassert>
#include <cstdio>

#include "aether/api_protocol/api_protocol.h"

Expand Down Expand Up @@ -58,9 +59,9 @@ void ProtocolContext::SetSendErrorResponse(RequestId req_id,
send_error_events_.erase(it);
} else {
AE_TELED_DEBUG("No callback for error with request id {}", req_id);
std::cerr << "SendError: id " << req_id
<< " type: " << static_cast<int>(error_type)
<< " error code: " << error_code << std::endl;
fprintf(stderr, "SendError: id %zu, type: %d, error_code %zu\n",
static_cast<std::size_t>(req_id.id), static_cast<int>(error_type),
static_cast<std::size_t>(error_code));
parser()->Cancel();
}
send_result_events_.erase(req_id);
Expand Down
9 changes: 9 additions & 0 deletions aether/api_protocol/request_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstdint>

#include "aether-miscpp/format/format.h"
#include "aether-miscpp/reflect/reflect.h"

namespace ae {
Expand All @@ -40,6 +41,14 @@ struct RequestId {
AE_REFLECT_MEMBERS(id)
std::uint32_t id{};
};

template <>
struct Formatter<RequestId> {
template <typename Writer>
void Format(RequestId const& value, FormatContext<Writer>& ctx) const {
Formatter<std::uint32_t>{}.Format(value.id, ctx);
}
};
} // namespace ae

#endif // AETHER_API_PROTOCOL_REQUEST_ID_H_
11 changes: 7 additions & 4 deletions aether/client_messages/p2p_message_stream_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <utility>

#include "aether/client.h"
#include "aether/work_cloud_api/client_api/client_api_safe.h"
#include "aether/client_messages/client_messages_tele.h"
#include "aether/work_cloud_api/client_api/client_api_safe.h"

namespace ae {

Expand Down Expand Up @@ -57,9 +57,12 @@ P2pMessageStreamManager::GetOrCreatePort(Uid const& destination) {
return {std::move(existing), false};
}
}
auto port =
std::make_shared<p2p_stream_internal::P2pReceivePort>(destination);
ports_[destination] = port;
// Do not use std::make_shared here. GCC 16/libstdc++ emits a false
// -Warray-bounds warning while destroying P2pReceivePort from
// _Sp_counted_ptr_inplace because P2pReceivePort owns Event/RcPtr storage.
auto port = std::shared_ptr<p2p_stream_internal::P2pReceivePort>{
std::make_unique<p2p_stream_internal::P2pReceivePort>(destination)};
ports_.emplace(destination, port);
return {port, true};
}

Expand Down
28 changes: 12 additions & 16 deletions aether/crypto/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
AE_SIGNATURE != AE_NONE

# include <array>
# include <string>
# include <span>
# include <cstdint>
# include <cassert>
# include <sstream>
# include <iomanip>

# if AE_CRYPTO_ASYNC == AE_SODIUM_BOX_SEAL
# include <sodium/crypto_box.h>
Expand All @@ -47,6 +45,7 @@
# endif

# include "aether-miscpp/reflect/reflect.h"
# include "aether-miscpp/format/format.h"
# include "aether/types/variant_type.h"

namespace ae {
Expand Down Expand Up @@ -176,19 +175,16 @@ class Key
static_cast<typename VariantType::variant const&>(*this));
}

static std::string text(Key const& v) {
std::stringstream ss;
ss << "[";
std::visit(
[&ss](auto const& k) {
for (auto s : k.key) {
ss << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<std::uint32_t>(s);
}
},
static_cast<typename VariantType::variant const&>(v));
ss << "]";
return ss.str();
};

template <>
struct Formatter<Key> {
template <typename TStream>
void Format(Key const& value, FormatContext<TStream>& ctx) const {
auto data = std::span<std::uint8_t const>{value.Data(), value.Size()};
ctx.out().write('[');
Formatter<decltype(data)>{}.Format(data, ctx);
ctx.out().write(']');
}
};

Expand Down
26 changes: 12 additions & 14 deletions aether/crypto/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# include <array>
# include <cassert>
# include <cstdint>
# include <sstream>
# include <string>
# include <span>

# if AE_SIGNATURE == AE_ED25519
# include <sodium/crypto_sign.h>
Expand All @@ -34,6 +33,7 @@
# endif

# include "aether-miscpp/reflect/reflect.h"
# include "aether-miscpp/format/format.h"
# include "aether/types/variant_type.h"

namespace ae {
Expand Down Expand Up @@ -86,18 +86,16 @@ struct Sign : public VariantType<SignatureMethod,
static_cast<VariantType::variant const&>(*this));
}

static std::string text(Sign const& v) {
std::stringstream ss;
ss << "[";
std::visit(
[&ss](auto const& k) {
for (auto s : k.signature) {
ss << std::hex << static_cast<std::uint32_t>(s);
}
},
static_cast<VariantType::variant const&>(v));
ss << "]";
return ss.str();
};

template <>
struct Formatter<Sign> {
template <typename TStream>
void Format(Sign const& value, FormatContext<TStream>& ctx) const {
auto data = std::span<std::uint8_t const>{value.Data(), value.Size()};
ctx.out().write('[');
Formatter<decltype(data)>{}.Format(data, ctx);
ctx.out().write(']');
}
};
} // namespace ae
Expand Down
13 changes: 13 additions & 0 deletions aether/poller/poller_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ static constexpr auto kInvalidDescriptor =
static constexpr auto kInvalidDescriptor = -1;
#endif

template <>
struct Formatter<DescriptorType> {
template <typename TStream>
void Format(DescriptorType const& value, FormatContext<TStream>& ctx) const {
#ifdef _WIN32
Formatter<DescriptorType::Socket>{}.Format(
static_cast<DescriptorType::Socket>(value), ctx);
#else
Formatter<int>{}.Format(value.descriptor, ctx);
#endif
}
};

template <>
struct Formatter<EventType> {
template <typename TStream>
Expand Down
11 changes: 5 additions & 6 deletions aether/tasks/details/manual_task_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#ifndef AETHER_TASKS_DETAILS_MANUAL_TASK_SCHEDULER_H_
#define AETHER_TASKS_DETAILS_MANUAL_TASK_SCHEDULER_H_

#include <mutex>
#include <atomic>
#include <chrono>
#include <cassert>
#include <format> // IWYU pragma: keeps
#include <iostream> // IWYU pragma: keeps
#include <chrono>
#include <condition_variable>
#include <cstdio> // // IWYU pragma: keep
#include <mutex>

#include "aether/tasks/details/task_manager.h"

Expand Down Expand Up @@ -128,8 +127,8 @@ class ManualTaskScheduler {
void CheckOverflows() {
#ifndef NDEBUG
if (overflow_counter_ != 0) {
std::cerr << std::format("!!!!!> ManualTaskScheduler: got overflow: {}\n",
overflow_counter_);
fprintf(stderr, "!!!!!> ManualTaskScheduler: got overflow: %zu\n",
overflow_counter_);
overflow_counter_ = 0;
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions aether/tele/collectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
# error "Include tele.h instead"
#endif

#include <memory>
#include <chrono>
#include <cstdint>
#include <utility>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>

#include "aether/clock.h"
#include "aether-miscpp/format/format.h"
#include "aether/clock.h"

#include "aether/tele/tags.h"
#include "aether/tele/itrap.h"
#include "aether/tele/levels.h"
#include "aether/tele/modules.h"
#include "aether/tele/tags.h"

namespace ae::tele {
struct Timer {
Expand Down Expand Up @@ -145,7 +145,8 @@ struct TeleLogCollector<TSinkConfig,
}

template <typename... TArgs>
void Blob(std::string_view format, TArgs&&... args) {
void Blob([[maybe_unused]] FormatScheme const& format,
[[maybe_unused]] TArgs&&... args) {
if constexpr (TSinkConfig::kBlobLogs) {
if (trap_ == nullptr) {
return;
Expand Down
10 changes: 5 additions & 5 deletions aether/tele/env_collectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
#include <utility>

#include "aether/env.h"
#include "aether/tele/itrap.h"
#include "aether/tele/env/compiler.h"
#include "aether/tele/compile_option.h"
#include "aether/tele/env/platform_type.h"
#include "aether/tele/env/library_version.h"
#include "aether/tele/env/cpu_architecture.h"
#include "aether/tele/env/compilation_options.h"
#include "aether/tele/env/compiler.h"
#include "aether/tele/env/cpu_architecture.h"
#include "aether/tele/env/library_version.h"
#include "aether/tele/env/platform_type.h"
#include "aether/tele/itrap.h"

namespace ae::tele {
/**
Expand Down
4 changes: 0 additions & 4 deletions aether/tele/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

namespace ae::tele {
struct Module {
static std::string text(Module const& value) {
return std::string{value.name};
}

std::uint32_t id;
std::uint32_t index_start;
std::uint32_t index_end;
Expand Down
2 changes: 1 addition & 1 deletion aether/tele/tele_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "aether/tele/tele_init.h"

#include <utility>
#include <iostream>
#include <utility>

#include "aether/config.h"

Expand Down
Loading
Loading