8000 cleanup: Make `Networking_Core` pointer-to-const where possible. by iphydf · Pull Request #1899 · TokTok/c-toxcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cleanup: Make Networking_Core pointer-to-const where possible. #1899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/scripts/cmake-linux
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions .github/scripts/cmake-osx
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
058c26e86ce3fcdd5d32850f46434e618bec6b122288fbdbc7cf9a9d23ee1d9c /usr/local/bin/tox-bootstrapd
78791fce8556684ee8210d6b79b11c5fd7a2c35c96589aec4b8641a62b0414a3 /usr/local/bin/tox-bootstrapd
22 changes: 12 additions & 10 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#endif

#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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];

Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -600,24 +601,25 @@ 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;
}

/**
* 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)
{
const Packet packet = {data, length};
return send_packet(net, ip_port, packet);
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions toxcore/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
0