1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Improve some protocol code log messages

also get rid of the very noisy socket debug message that are
useless in a world where Wireshark exists.
This commit is contained in:
sfan5 2024-08-31 17:16:48 +02:00 committed by SmallJoker
parent 7556bf43a6
commit 96fbc52071
5 changed files with 26 additions and 86 deletions

View file

@ -50,9 +50,6 @@ typedef int socklen_t;
#define SOCKET_ERR_STR(e) strerror(e)
#endif
// Set to true to enable verbose debug output
bool socket_enable_debug_output = false; // yuck
static bool g_sockets_initialized = false;
// Initialize sockets
@ -104,12 +101,6 @@ bool UDPSocket::init(bool ipv6, bool noExceptions)
m_addr_family = ipv6 ? AF_INET6 : AF_INET;
m_handle = socket(m_addr_family, SOCK_DGRAM, IPPROTO_UDP);
if (socket_enable_debug_output) {
tracestream << "UDPSocket(" << (int)m_handle
<< ")::UDPSocket(): ipv6 = " << (ipv6 ? "true" : "false")
<< std::endl;
}
if (m_handle < 0) {
if (noExceptions) {
return false;
@ -135,11 +126,6 @@ bool UDPSocket::init(bool ipv6, bool noExceptions)
UDPSocket::~UDPSocket()
{
if (socket_enable_debug_output) {
tracestream << "UDPSocket( " << (int)m_handle << ")::~UDPSocket()"
<< std::endl;
}
if (m_handle >= 0) {
#ifdef _WIN32
closesocket(m_handle);
@ -151,12 +137,6 @@ UDPSocket::~UDPSocket()
void UDPSocket::Bind(Address addr)
{
if (socket_enable_debug_output) {
tracestream << "UDPSocket(" << (int)m_handle
<< ")::Bind(): " << addr.serializeString() << ":"
<< addr.getPort() << std::endl;
}
if (addr.getFamily() != m_addr_family) {
const char *errmsg =
"Socket and bind address families do not match";
@ -202,30 +182,6 @@ void UDPSocket::Send(const Address &destination, const void *data, int size)
if (INTERNET_SIMULATOR)
dumping_packet = myrand() % INTERNET_SIMULATOR_PACKET_LOSS == 0;
if (socket_enable_debug_output) {
// Print packet destination and size
tracestream << (int)m_handle << " -> ";
destination.print(tracestream);
tracestream << ", size=" << size;
// Print packet contents
tracestream << ", data=";
for (int i = 0; i < size && i < 20; i++) {
if (i % 2 == 0)
tracestream << " ";
unsigned int a = ((const unsigned char *)data)[i];
tracestream << std::hex << std::setw(2) << std::setfill('0') << a;
}
if (size > 20)
tracestream << "...";
if (dumping_packet)
tracestream << " (DUMPED BY INTERNET_SIMULATOR)";
tracestream << std::endl;
}
if (dumping_packet) {
// Lol let's forget it
tracestream << "UDPSocket::Send(): INTERNET_SIMULATOR: dumping packet."
@ -302,26 +258,6 @@ int UDPSocket::Receive(Address &sender, void *data, int size)
sender = Address(address_ip, address_port);
}
if (socket_enable_debug_output) {
// Print packet sender and size
tracestream << (int)m_handle << " <- ";
sender.print(tracestream);
tracestream << ", size=" << received;
// Print packet contents
tracestream << ", data=";
for (int i = 0; i < received && i < 20; i++) {
if (i % 2 == 0)
tracestream << " ";
unsigned int a = ((const unsigned char *)data)[i];
tracestream << std::hex << std::setw(2) << std::setfill('0') << a;
}
if (received > 20)
tracestream << "...";
tracestream << std::endl;
}
return received;
}