style: adjust clang-format rules (#2186)

Co-authored-by: Vithorio Polten <reach@vithor.io>
This commit is contained in:
ReenigneArcher
2025-01-19 22:34:47 -05:00
committed by GitHub
parent f57aee9025
commit c2420427b1
158 changed files with 8754 additions and 9994 deletions

View File

@@ -2,13 +2,16 @@
* @file src/network.cpp
* @brief Definitions for networking related functions.
*/
#include "network.h"
#include "config.h"
#include "logging.h"
#include "utility.h"
// standard includes
#include <algorithm>
#include <sstream>
// local includes
#include "config.h"
#include "logging.h"
#include "network.h"
#include "utility.h"
using namespace std::literals;
namespace ip = boost::asio::ip;
@@ -33,8 +36,7 @@ namespace net {
ip::make_network_v6("fe80::/64"sv),
};
net_e
from_enum_string(const std::string_view &view) {
net_e from_enum_string(const std::string_view &view) {
if (view == "wan") {
return WAN;
}
@@ -45,8 +47,7 @@ namespace net {
return PC;
}
net_e
from_address(const std::string_view &view) {
net_e from_address(const std::string_view &view) {
auto addr = normalize_address(ip::make_address(view));
if (addr.is_v6()) {
@@ -61,8 +62,7 @@ namespace net {
return LAN;
}
}
}
else {
} else {
for (auto &range : pc_ips_v4) {
if (range.hosts().find(addr.to_v4()) != range.hosts().end()) {
return PC;
@@ -79,8 +79,7 @@ namespace net {
return WAN;
}
std::string_view
to_enum_string(net_e net) {
std::string_view to_enum_string(net_e net) {
switch (net) {
case PC:
return "pc"sv;
@@ -94,8 +93,7 @@ namespace net {
return "wan"sv;
}
af_e
af_from_enum_string(const std::string_view &view) {
af_e af_from_enum_string(const std::string_view &view) {
if (view == "ipv4") {
return IPV4;
}
@@ -107,8 +105,7 @@ namespace net {
return BOTH;
}
std::string_view
af_to_any_address_string(af_e af) {
std::string_view af_to_any_address_string(af_e af) {
switch (af) {
case IPV4:
return "0.0.0.0"sv;
@@ -120,8 +117,7 @@ namespace net {
return "::"sv;
}
boost::asio::ip::address
normalize_address(boost::asio::ip::address address) {
boost::asio::ip::address normalize_address(boost::asio::ip::address address) {
// Convert IPv6-mapped IPv4 addresses into regular IPv4 addresses
if (address.is_v6()) {
auto v6 = address.to_v6();
@@ -133,37 +129,31 @@ namespace net {
return address;
}
std::string
addr_to_normalized_string(boost::asio::ip::address address) {
std::string addr_to_normalized_string(boost::asio::ip::address address) {
return normalize_address(address).to_string();
}
std::string
addr_to_url_escaped_string(boost::asio::ip::address address) {
std::string addr_to_url_escaped_string(boost::asio::ip::address address) {
address = normalize_address(address);
if (address.is_v6()) {
std::stringstream ss;
ss << '[' << address.to_string() << ']';
return ss.str();
}
else {
} else {
return address.to_string();
}
}
int
encryption_mode_for_address(boost::asio::ip::address address) {
int encryption_mode_for_address(boost::asio::ip::address address) {
auto nettype = net::from_address(address.to_string());
if (nettype == net::net_e::PC || nettype == net::net_e::LAN) {
return config::stream.lan_encryption_mode;
}
else {
} else {
return config::stream.wan_encryption_mode;
}
}
host_t
host_create(af_e af, ENetAddress &addr, std::uint16_t port) {
host_t host_create(af_e af, ENetAddress &addr, std::uint16_t port) {
static std::once_flag enet_init_flag;
std::call_once(enet_init_flag, []() {
enet_initialize();
@@ -174,7 +164,7 @@ namespace net {
enet_address_set_port(&addr, port);
// Maximum of 128 clients, which should be enough for anyone
auto host = host_t { enet_host_create(af == IPV4 ? AF_INET : AF_INET6, &addr, 128, 0, 0, 0) };
auto host = host_t {enet_host_create(af == IPV4 ? AF_INET : AF_INET6, &addr, 128, 0, 0, 0)};
// Enable opportunistic QoS tagging (automatically disables if the network appears to drop tagged packets)
enet_socket_set_option(host->socket, ENET_SOCKOPT_QOS, 1);
@@ -182,8 +172,7 @@ namespace net {
return host;
}
void
free_host(ENetHost *host) {
void free_host(ENetHost *host) {
std::for_each(host->peers, host->peers + host->peerCount, [](ENetPeer &peer_ref) {
ENetPeer *peer = &peer_ref;
@@ -195,8 +184,7 @@ namespace net {
enet_host_destroy(host);
}
std::uint16_t
map_port(int port) {
std::uint16_t map_port(int port) {
// calculate the port from the config port
auto mapped_port = (std::uint16_t)((int) config::sunshine.port + port);
@@ -213,10 +201,9 @@ namespace net {
* @param hostname The hostname to use for instance name generation.
* @return Hostname-based instance name or "Sunshine" if hostname is invalid.
*/
std::string
mdns_instance_name(const std::string_view &hostname) {
std::string mdns_instance_name(const std::string_view &hostname) {
// Start with the unmodified hostname
std::string instancename { hostname.data(), hostname.size() };
std::string instancename {hostname.data(), hostname.size()};
// Truncate to 63 characters per RFC 6763 section 7.2.
if (instancename.size() > 63) {
@@ -227,8 +214,7 @@ namespace net {
// Replace any spaces with dashes
if (instancename[i] == ' ') {
instancename[i] = '-';
}
else if (!std::isalnum(instancename[i]) && instancename[i] != '-') {
} else if (!std::isalnum(instancename[i]) && instancename[i] != '-') {
// Stop at the first invalid character
instancename.resize(i);
break;