Skip to content
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

cleanup: address some unused return values #1759

Merged
merged 1 commit into from
Dec 11, 2021
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
1 change: 1 addition & 0 deletions toxcore/TCP_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static int connect_sock_to(Socket sock, IP_Port ip_port, const TCP_Proxy_Info *p

/* nonblocking socket, connect will never return success */
net_connect(sock, ip_port);

return 1;
}

Expand Down
15 changes: 12 additions & 3 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,21 @@ Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from,
/* Functions to increase the size of the send and receive UDP buffers.
*/
int n = 1024 * 1024 * 2;
setsockopt(temp->sock.socket, SOL_SOCKET, SO_RCVBUF, (const char *)&n, sizeof(n));
setsockopt(temp->sock.socket, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof(n));

if (setsockopt(temp->sock.socket, SOL_SOCKET, SO_RCVBUF, (const char *)&n, sizeof(n)) != 0) {
LOGGER_WARNING(log, "Failed to set socket option %d", SO_RCVBUF);
}

if (setsockopt(temp->sock.socket, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof(n)) != 0) {
LOGGER_WARNING(log, "Failed to set socket option %d", SO_SNDBUF);
}

/* Enable broadcast on socket */
int broadcast = 1;
setsockopt(temp->sock.socket, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast));

if (setsockopt(temp->sock.socket, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast)) != 0) {
LOGGER_WARNING(log, "Failed to set socket option %d", SO_BROADCAST);
}

/* iOS UDP sockets are weird and apparently can SIGPIPE */
if (!set_socket_nosigpipe(temp->sock)) {
Expand Down
6 changes: 5 additions & 1 deletion toxcore/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
/* Call this several times a second. */
void networking_poll(Networking_Core *net, void *userdata);

/* Connect a socket to the address specified by the ip_port. */
/* Connect a socket to the address specified by the ip_port.
*
* Return 0 on success.
* Return -1 on failure.
*/
int net_connect(Socket sock, IP_Port ip_port);

/* High-level getaddrinfo implementation.
Expand Down
11 changes: 6 additions & 5 deletions toxcore/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ struct Ping {
#define DHT_PING_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + PING_PLAIN_SIZE + CRYPTO_MAC_SIZE)
#define PING_DATA_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port))

int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
void ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
{
uint8_t pk[DHT_PING_SIZE];
int rc;
uint64_t ping_id;

if (id_equal(public_key, dht_get_self_public_key(ping->dht))) {
return 1;
return;
}

uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
Expand All @@ -67,7 +67,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)

if (ping_id == 0) {
crypto_memzero(shared_key, sizeof(shared_key));
return 1;
return;
}

uint8_t ping_plain[PING_PLAIN_SIZE];
Expand All @@ -87,10 +87,11 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
crypto_memzero(shared_key, sizeof(shared_key));

if (rc != PING_PLAIN_SIZE + CRYPTO_MAC_SIZE) {
return 1;
return;
}

return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
// We never check this return value and failures in sendpacket are already logged
sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
}

static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id,
Expand Down
2 changes: 1 addition & 1 deletion toxcore/ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, struct IP_Port ip_port);

void ping_iterate(Ping *ping);

int32_t ping_send_request(Ping *ping, struct IP_Port ipp, const uint8_t *public_key);
void ping_send_request(Ping *ping, struct IP_Port ipp, const uint8_t *public_key);

#endif // C_TOXCORE_TOXCORE_PING_H