Skip to content

Commit 22b453e

Browse files
fix: resolve Clang-Tidy and MSVC CI failures in nuclearnet
Add missing includes and NOLINTs for Log.cpp, fix Fragmentation ctor casts for MSVC, and move default multicast address to wire_protocol constant. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2441bdf commit 22b453e

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/nuclearnet/Log.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@
2222

2323
#include "Log.hpp"
2424

25+
#include "../util/network/sock_t.hpp"
26+
#include "Discovery.hpp"
27+
28+
#include <array>
29+
#include <atomic>
30+
#include <cstdint>
2531
#include <cstdio>
2632
#include <iostream>
33+
#include <string>
2734

2835
namespace NUClear {
2936
namespace network {
3037

3138
namespace {
3239

40+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
3341
std::atomic<std::uint8_t> g_log_level{static_cast<std::uint8_t>(LogLevel::Off)};
3442

3543
const char* level_name(LogLevel level) {
@@ -61,9 +69,12 @@ namespace {
6169
}
6270

6371
std::string hash_hex(uint64_t hash) {
64-
char buf[19];
65-
std::snprintf(buf, sizeof(buf), "0x%016llx", static_cast<unsigned long long>(hash));
66-
return buf;
72+
std::array<char, 19> buf{};
73+
const int n = std::snprintf(buf.data(), buf.size(), "0x%016llx", static_cast<unsigned long long>(hash));
74+
if (n < 0) {
75+
return "0x?";
76+
}
77+
return std::string(buf.data(), static_cast<std::size_t>(n));
6778
}
6879

6980
std::string sock_str(const util::network::sock_t& address) {

src/nuclearnet/NUClearNet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424

2525
#include <algorithm>
2626
#include <array>
27+
#include <cerrno>
2728
#include <chrono>
2829
#include <cstdint>
2930
#include <cstring>
3031
#include <memory>
3132
#include <set>
33+
#include <string>
3234
#include <system_error>
3335
#include <utility>
3436
#include <vector>
@@ -86,7 +88,9 @@ namespace {
8688

8789
NUClearNet::NUClearNet()
8890
: discovery(std::make_unique<Discovery>(std::chrono::seconds(2)))
89-
, fragmentation(std::make_unique<Fragmentation>(1452, 64 * 1024 * 1024, std::chrono::seconds(2)))
91+
, fragmentation(std::make_unique<Fragmentation>(static_cast<uint16_t>(1452),
92+
static_cast<std::size_t>(64) * 1024 * 1024,
93+
std::chrono::seconds(2)))
9094
, reliability(std::make_unique<Reliability>()) {
9195
wire_discovery_callbacks();
9296
}
@@ -311,7 +315,7 @@ namespace {
311315
open_sockets();
312316
needs_rebind = false;
313317
}
314-
catch (...) {
318+
catch (...) { // NOLINT(bugprone-empty-catch)
315319
// Network not available yet; will retry on the next process() call
316320
}
317321

src/nuclearnet/NUClearNet.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "PacketDeduplicator.hpp"
4242
#include "Reliability.hpp"
4343
#include "Routing.hpp"
44+
#include "wire_protocol.hpp"
4445

4546
namespace NUClear {
4647
namespace network {
@@ -51,8 +52,8 @@ namespace network {
5152
struct NetworkConfig {
5253
/// This node's name on the network
5354
std::string name;
54-
/// The multicast/broadcast/unicast address to announce on (organization-local multicast default)
55-
std::string announce_address = "239.226.152.162"; // NOSONAR
55+
/// The multicast/broadcast/unicast address to announce on
56+
std::string announce_address = DEFAULT_ANNOUNCE_ADDRESS;
5657
/// The port to use for announce discovery
5758
in_port_t announce_port = 7447;
5859
/// Address to bind to (empty = all interfaces)

src/nuclearnet/wire_protocol.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ namespace network {
4141
/// Protocol version for NUClearNet v2
4242
constexpr uint8_t PROTOCOL_VERSION = 0x03;
4343

44+
/// Default organization-local multicast address for peer discovery (RFC 2365)
45+
constexpr const char DEFAULT_ANNOUNCE_ADDRESS[] = "239.226.152.162"; // NOSONAR
46+
4447
/// Packet type identifiers
4548
enum PacketType : uint8_t {
4649
ANNOUNCE = 1,

0 commit comments

Comments
 (0)