From a3bb44f2e87eddeb8d0811001f4964cbae9d1ae1 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:38:29 -0400 Subject: [PATCH] refactor: make immutable globals const and remove unused frame --- src/main.cpp | 4 +- src/network.cpp | 16 +++---- src/platform/macos/nv12_zero_device.cpp | 2 - src/platform/macos/nv12_zero_device.h | 2 +- tests/unit/test_network.cpp | 60 +++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fb5255488..19b167311 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,9 +73,9 @@ void on_signal(int sig, FN &&fn) { } /** - * @brief Cmd to func. + * @brief Immutable dispatch table for supported command-line subcommands. */ -std::map> cmd_to_func { +const std::map> cmd_to_func { {"creds"sv, [](const char *name, int argc, char **argv) { return args::creds(name, argc, argv); }}, diff --git a/src/network.cpp b/src/network.cpp index b04d6f888..a813a6010 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -18,15 +18,15 @@ namespace ip = boost::asio::ip; namespace net { /** - * @brief Pc ips v4. + * @brief Immutable IPv4 loopback ranges classified as local to this PC. */ - std::vector pc_ips_v4 { + const std::vector pc_ips_v4 { ip::make_network_v4("127.0.0.0/8"sv), }; /** - * @brief Lan ips v4. + * @brief Immutable IPv4 private, shared, and link-local ranges classified as LAN. */ - std::vector lan_ips_v4 { + const std::vector lan_ips_v4 { ip::make_network_v4("192.168.0.0/16"sv), ip::make_network_v4("172.16.0.0/12"sv), ip::make_network_v4("10.0.0.0/8"sv), @@ -35,15 +35,15 @@ namespace net { }; /** - * @brief Pc ips v6. + * @brief Immutable IPv6 loopback ranges classified as local to this PC. */ - std::vector pc_ips_v6 { + const std::vector pc_ips_v6 { ip::make_network_v6("::1/128"sv), }; /** - * @brief Lan ips v6. + * @brief Immutable IPv6 unique-local and link-local ranges classified as LAN. */ - std::vector lan_ips_v6 { + const std::vector lan_ips_v6 { ip::make_network_v6("fc00::/7"sv), ip::make_network_v6("fe80::/64"sv), }; diff --git a/src/platform/macos/nv12_zero_device.cpp b/src/platform/macos/nv12_zero_device.cpp index 977019879..68cf6c971 100644 --- a/src/platform/macos/nv12_zero_device.cpp +++ b/src/platform/macos/nv12_zero_device.cpp @@ -33,8 +33,6 @@ namespace platf { CVPixelBufferRelease((CVPixelBufferRef) data); } - util::safe_ptr av_frame; ///< AV frame. - int nv12_zero_device::convert(platf::img_t &img) { auto *av_img = (av_img_t *) &img; diff --git a/src/platform/macos/nv12_zero_device.h b/src/platform/macos/nv12_zero_device.h index bd92b025b..44acaa167 100644 --- a/src/platform/macos/nv12_zero_device.h +++ b/src/platform/macos/nv12_zero_device.h @@ -66,7 +66,7 @@ namespace platf { int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override; private: - util::safe_ptr av_frame; + util::safe_ptr av_frame; ///< Frame retained by this device for zero-copy encoding. }; } // namespace platf diff --git a/tests/unit/test_network.cpp b/tests/unit/test_network.cpp index f3a8987e1..3c07fd7e3 100644 --- a/tests/unit/test_network.cpp +++ b/tests/unit/test_network.cpp @@ -9,6 +9,66 @@ // local includes #include +/** + * @brief Address classifications supplied by the immutable IPv4 and IPv6 range tables. + */ +struct NetworkAddressTest: BaseTest, testing::WithParamInterface> {}; + +/** + * @brief Preserve loopback, LAN, and WAN classification across each configured range. + */ +TEST_P(NetworkAddressTest, ClassifiesAddress) { + const auto &[address, expected] = GetParam(); + EXPECT_EQ(net::from_address(address), expected); +} + +/** + * @brief Cover the first and last usable addresses and adjacent addresses for each range. + */ +INSTANTIATE_TEST_SUITE_P( + NetworkAddressTests, + NetworkAddressTest, + testing::Values( + std::make_tuple("127.0.0.1", net::PC), + std::make_tuple("127.255.255.254", net::PC), + std::make_tuple("126.255.255.254", net::WAN), + std::make_tuple("128.0.0.1", net::WAN), + std::make_tuple("192.168.0.1", net::LAN), + std::make_tuple("192.168.255.254", net::LAN), + std::make_tuple("192.167.255.254", net::WAN), + std::make_tuple("192.169.0.1", net::WAN), + std::make_tuple("172.16.0.1", net::LAN), + std::make_tuple("172.31.255.254", net::LAN), + std::make_tuple("172.15.255.254", net::WAN), + std::make_tuple("172.32.0.1", net::WAN), + std::make_tuple("10.0.0.1", net::LAN), + std::make_tuple("10.255.255.254", net::LAN), + std::make_tuple("9.255.255.254", net::WAN), + std::make_tuple("11.0.0.1", net::WAN), + std::make_tuple("100.64.0.1", net::LAN), + std::make_tuple("100.127.255.254", net::LAN), + std::make_tuple("100.63.255.254", net::WAN), + std::make_tuple("100.128.0.1", net::WAN), + std::make_tuple("169.254.0.1", net::LAN), + std::make_tuple("169.254.255.254", net::LAN), + std::make_tuple("169.253.255.254", net::WAN), + std::make_tuple("169.255.0.1", net::WAN), + std::make_tuple("::1", net::PC), + std::make_tuple("::2", net::WAN), + std::make_tuple("fc00::1", net::LAN), + std::make_tuple("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", net::LAN), + std::make_tuple("fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", net::WAN), + std::make_tuple("fe00::1", net::WAN), + std::make_tuple("fe80::1", net::LAN), + std::make_tuple("fe80::ffff:ffff:ffff:ffff", net::LAN), + std::make_tuple("fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ffff", net::WAN), + std::make_tuple("fe81::1", net::WAN), + std::make_tuple("::ffff:127.0.0.1", net::PC), + std::make_tuple("::ffff:192.168.1.1", net::LAN), + std::make_tuple("::ffff:198.51.100.1", net::WAN) + ) +); + struct MdnsInstanceNameTest: BaseTest, testing::WithParamInterface> {}; TEST_P(MdnsInstanceNameTest, Run) {