From 09bb9b8a234ef877bcfe4e7db51dcc5a4e993bf4 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 16 Jan 2022 00:39:51 +0000 Subject: [PATCH] cleanup: Make Networking_Core pointer-to-const where possible. --- .github/scripts/cmake-linux | 3 +-- .github/scripts/cmake-osx | 3 +-- .../docker/tox-bootstrapd.sha256 | 2 +- toxcore/network.c | 22 ++++++++++--------- toxcore/network.h | 6 ++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/scripts/cmake-linux b/.github/scripts/cmake-linux index d4ea33f1..cee6b491 100755 --- a/.github/scripts/cmake-linux +++ b/.github/scripts/cmake-linux @@ -33,6 +33,5 @@ cmake -B_build -H. -GNinja \ cmake --build _build --parallel "$NPROC" --target install -- -k 0 cd _build # pushd -ctest -j50 --output-on-failure || - ctest -j50 --output-on-failure --rerun-failed +ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 cd - # popd diff --git a/.github/scripts/cmake-osx b/.github/scripts/cmake-osx index 5ef5ee72..a13a1811 100755 --- a/.github/scripts/cmake-osx +++ b/.github/scripts/cmake-osx @@ -31,6 +31,5 @@ cmake -B_build -H. \ cd _build # pushd make "-j$NPROC" -k install -make "-j$NPROC" test ARGS="-j50" || - make "-j$NPROC" test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 +ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 cd - # popd diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 0e7b640b..49660930 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -058c26e86ce3fcdd5d32850f46434e618bec6b122288fbdbc7cf9a9d23ee1d9c /usr/local/bin/tox-bootstrapd +78791fce8556684ee8210d6b79b11c5fd7a2c35c96589aec4b8641a62b0414a3 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/network.c b/toxcore/network.c index 096edfef..add265c3 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -82,6 +82,7 @@ #endif #include +#include #include #include #include @@ -485,7 +486,7 @@ static uint32_t data_1(uint16_t buflen, const uint8_t *buffer) } static void loglogdata(const Logger *log, const char *message, const uint8_t *buffer, - uint16_t buflen, IP_Port ip_port, int res) + uint16_t buflen, IP_Port ip_port, long res) { char ip_str[IP_NTOA_LEN]; @@ -503,7 +504,7 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", data_0(buflen, buffer), data_1(buflen, buffer)); } else { /* empty or overwrite */ - LOGGER_TRACE(log, "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x", + LOGGER_TRACE(log, "[%2u] %s %lu%c%u %s:%u (%u: %s) | %04x%04x", buffer[0], message, res, !res ? '!' : '>', buflen, ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", data_0(buflen, buffer), data_1(buflen, buffer)); @@ -538,7 +539,7 @@ uint16_t net_port(const Networking_Core *net) /* Basic network functions: */ -int send_packet(Networking_Core *net, IP_Port ip_port, Packet packet) +int send_packet(const Networking_Core *net, IP_Port ip_port, Packet packet) { if (net_family_is_unspec(net->family)) { /* Socket not initialized */ // TODO(iphydf): Make this an error. Currently, the onion client calls @@ -600,16 +601,17 @@ int send_packet(Networking_Core *net, IP_Port ip_port, Packet packet) } #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - const int res = fuzz_sendto(net->sock.socket, (const char *)packet.data, packet.length, 0, - (struct sockaddr *)&addr, addrsize); + const long res = fuzz_sendto(net->sock.socket, (const char *)packet.data, packet.length, 0, + (struct sockaddr *)&addr, addrsize); #else - const int res = sendto(net->sock.socket, (const char *)packet.data, packet.length, 0, - (struct sockaddr *)&addr, addrsize); + const long res = sendto(net->sock.socket, (const char *)packet.data, packet.length, 0, + (struct sockaddr *)&addr, addrsize); #endif loglogdata(net->log, "O=>", packet.data, packet.length, ip_port, res); - return res; + assert(res <= INT_MAX); + return (int)res; } /** @@ -617,7 +619,7 @@ int send_packet(Networking_Core *net, IP_Port ip_port, Packet packet) * * @deprecated Use send_packet instead. */ -int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint16_t length) +int sendpacket(const Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint16_t length) { const Packet packet = {data, length}; return send_packet(net, ip_port, packet); @@ -704,7 +706,7 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl net->packethandlers[byte].object = object; } -void networking_poll(Networking_Core *net, void *userdata) +void networking_poll(const Networking_Core *net, void *userdata) { if (net_family_is_unspec(net->family)) { /* Socket not initialized */ diff --git a/toxcore/network.h b/toxcore/network.h index 78014b9c..aa6e6c5a 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -383,20 +383,20 @@ typedef struct Packet { /** * Function to send a network packet to a given IP/port. */ -int send_packet(Networking_Core *net, IP_Port ip_port, Packet packet); +int send_packet(const Networking_Core *net, IP_Port ip_port, Packet packet); /** * Function to send packet(data) of length length to ip_port. * * @deprecated Use send_packet instead. */ -int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint16_t length); +int sendpacket(const Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint16_t length); /** Function to call when packet beginning with byte is received. */ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_cb *cb, void *object); /** Call this several times a second. */ -void networking_poll(Networking_Core *net, void *userdata); +void networking_poll(const Networking_Core *net, void *userdata); /** Connect a socket to the address specified by the ip_port. *