Skip to content

Commit

Permalink
cleanup: Make parameters pointers-to-const where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 16, 2022
1 parent 09bb9b8 commit 08bc0ac
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 86 deletions.
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 @@
78791fce8556684ee8210d6b79b11c5fd7a2c35c96589aec4b8641a62b0414a3 /usr/local/bin/tox-bootstrapd
7be4fcdc11f74036b97de9569eb06f82296f193db3e18e671171f3bc059f95a6 /usr/local/bin/tox-bootstrapd
13 changes: 7 additions & 6 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
}

static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet)
const uint8_t *shared_key, const uint8_t type,
const uint8_t *plain, size_t plain_length, uint8_t *packet)
{
VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE);
uint8_t nonce[CRYPTO_NONCE_SIZE];
Expand Down Expand Up @@ -1066,7 +1067,7 @@ static bool is_pk_in_client_list(const Client_data *list, unsigned int client_li
return !assoc_timeout(cur_time, assoc);
}

static bool is_pk_in_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_port)
static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, IP_Port ip_port)
{
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);

Expand Down Expand Up @@ -2124,7 +2125,7 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu
*
* return ip of 0 if failure.
*/
static IP nat_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
{
IP zero;
ip_reset(&zero);
Expand Down Expand Up @@ -2156,7 +2157,7 @@ static IP nat_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
*
* return number of ports and puts the list of ports in portlist.
*/
static uint16_t nat_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip)
static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uint16_t len, IP ip)
{
uint16_t num = 0;

Expand Down Expand Up @@ -2279,8 +2280,8 @@ static void do_NAT(DHT *dht)
*
* return the number of nodes.
*/
static uint16_t list_nodes(Client_data *list, size_t length, uint64_t cur_time, Node_format *nodes,
uint16_t max_num)
static uint16_t list_nodes(const Client_data *list, size_t length, uint64_t cur_time,
Node_format *nodes, uint16_t max_num)
{
if (max_num == 0) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
}


int lan_discovery_send(uint16_t port, DHT *dht)
int lan_discovery_send(uint16_t port, const DHT *dht)
{
uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
data[0] = NET_PACKET_LAN_DISCOVERY;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/LAN_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Send a LAN discovery pcaket to the broadcast address with port port.
*/
int32_t lan_discovery_send(uint16_t port, DHT *dht);
int32_t lan_discovery_send(uint16_t port, const DHT *dht);

/**
* Sets up packet handlers.
Expand Down
2 changes: 1 addition & 1 deletion toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
}

static int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber,
uint8_t control_type, uint8_t *data, uint16_t data_length)
uint8_t control_type, const uint8_t *data, uint16_t data_length)
{
if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
return -1;
Expand Down
12 changes: 6 additions & 6 deletions toxcore/TCP_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
static int proxy_http_read_connection_response(const Logger *logger, TCP_Client_Connection *tcp_conn)
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{
char success[] = "200";
uint8_t data[16]; // draining works the best if the length is a power of 2
Expand Down Expand Up @@ -190,7 +190,7 @@ static void proxy_socks5_generate_handshake(TCP_Client_Connection *tcp_conn)
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
static int socks5_read_handshake_response(const Logger *logger, TCP_Client_Connection *tcp_conn)
static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{
uint8_t data[2];
int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data));
Expand Down Expand Up @@ -236,7 +236,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
static int proxy_socks5_read_connection_response(const Logger *logger, TCP_Client_Connection *tcp_conn)
static int proxy_socks5_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{
if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)];
Expand Down Expand Up @@ -470,7 +470,7 @@ static int write_packet_TCP_client_secure_connection(TCP_Client_Connection *con,
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key)
int send_routing_request(TCP_Client_Connection *con, const uint8_t *public_key)
{
uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE];
packet[0] = TCP_PACKET_ROUTING_REQUEST;
Expand Down Expand Up @@ -957,8 +957,8 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c

/** Run the TCP connection
*/
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection,
void *userdata)
void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata)
{
if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) {
return;
Expand Down
6 changes: 3 additions & 3 deletions toxcore/TCP_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip

/** Run the TCP connection
*/
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection,
void *userdata);
void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata);

/** Kill the TCP connection
*/
Expand All @@ -77,7 +77,7 @@ typedef int tcp_routing_status_cb(void *object, uint32_t number, uint8_t connect
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key);
int send_routing_request(TCP_Client_Connection *con, const uint8_t *public_key);
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object);
void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);

Expand Down
30 changes: 15 additions & 15 deletions toxcore/TCP_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c)
* return -1 on failure.
* return 0 on success.
*/
int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length)
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length)
{
TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

Expand Down Expand Up @@ -372,7 +372,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
* return TCP connection number on success.
* return -1 on failure.
*/
int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c)
int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c)
{
const uint32_t r = random_u32();

Expand Down Expand Up @@ -415,8 +415,8 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_numb
* return 0 on success.
* return -1 on failure.
*/
int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
const uint8_t *packet, uint16_t length)
int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connections_number,
const uint8_t *public_key, const uint8_t *packet, uint16_t length)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);

Expand All @@ -437,14 +437,14 @@ int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_num
return -1;
}

static int find_tcp_connection_relay(TCP_Connections *tcp_c, const uint8_t *relay_pk);
static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk);

/** Send an oob packet via the TCP relay corresponding to relay_pk.
*
* return 0 on success.
* return -1 on failure.
*/
int tcp_send_oob_packet_using_relay(TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
const uint8_t *packet, uint16_t length)
{
int tcp_con_number = find_tcp_connection_relay(tcp_c, relay_pk);
Expand Down Expand Up @@ -485,7 +485,7 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_
* return connections_number on success.
* return -1 on failure.
*/
static int find_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key)
static int find_tcp_connection_to(const TCP_Connections *tcp_c, const uint8_t *public_key)
{
for (unsigned int i = 0; i < tcp_c->connections_length; ++i) {
TCP_Connection_to *con_to = get_connection(tcp_c, i);
Expand All @@ -505,7 +505,7 @@ static int find_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_
* return connections_number on success.
* return -1 on failure.
*/
static int find_tcp_connection_relay(TCP_Connections *tcp_c, const uint8_t *relay_pk)
static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
Expand Down Expand Up @@ -603,7 +603,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number)
* return 0 on success.
* return -1 on failure.
*/
int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, bool status)
int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status)
{
TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

Expand Down Expand Up @@ -660,7 +660,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number,
return 0;
}

static bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{
for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
Expand Down Expand Up @@ -712,7 +712,7 @@ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int t
/** return number of online connections on success.
* return -1 on failure.
*/
static unsigned int online_tcp_connection_from_conn(TCP_Connection_to *con_to)
static unsigned int online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
{
unsigned int count = 0;

Expand Down Expand Up @@ -903,7 +903,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
* return 0 on success.
* return -1 on failure.
*/
static int send_tcp_relay_routing_request(TCP_Connections *tcp_c, int tcp_connections_number, uint8_t *public_key)
static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_connections_number, uint8_t *public_key)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);

Expand Down Expand Up @@ -1266,7 +1266,7 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
/** return number of online tcp relays tied to the connection on success.
* return 0 on failure.
*/
unsigned int tcp_connection_to_online_tcp_relays(TCP_Connections *tcp_c, int connections_number)
unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number)
{
TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

Expand All @@ -1283,7 +1283,7 @@ unsigned int tcp_connection_to_online_tcp_relays(TCP_Connections *tcp_c, int con
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
{
const uint32_t r = random_u32();
uint32_t copied = 0;
Expand Down Expand Up @@ -1387,7 +1387,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
*
* Returns NULL on failure.
*/
TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, TCP_Proxy_Info *proxy_info)
TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, const TCP_Proxy_Info *proxy_info)
{
if (secret_key == nullptr) {
return nullptr;
Expand Down
16 changes: 8 additions & 8 deletions toxcore/TCP_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
* return -1 on failure.
* return 0 on success.
*/
int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length);
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length);

/** Return a random TCP connection number for use in send_tcp_onion_request.
*
Expand All @@ -90,7 +90,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
* return TCP connection number on success.
* return -1 on failure.
*/
int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c);
int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);

/** Send an onion packet via the TCP relay corresponding to tcp_connections_number.
*
Expand All @@ -114,12 +114,12 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
* return 0 on success.
* return -1 on failure.
*/
int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);

typedef int tcp_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);

int tcp_send_oob_packet_using_relay(TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);

/** Set the callback for TCP data packets.
Expand Down Expand Up @@ -165,12 +165,12 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success.
* return -1 on failure.
*/
int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, bool status);
int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status);

/** return number of online tcp relays tied to the connection on success.
* return 0 on failure.
*/
unsigned int tcp_connection_to_online_tcp_relays(TCP_Connections *tcp_c, int connections_number);
unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);

/** Add a TCP relay tied to a connection.
*
Expand Down Expand Up @@ -205,7 +205,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);

/** Returns a new TCP_Connections object associated with the secret_key.
*
Expand All @@ -214,7 +214,7 @@ uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_rela
*
* Returns NULL on failure.
*/
TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, TCP_Proxy_Info *proxy_info);
TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, const TCP_Proxy_Info *proxy_info);

int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);

Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ static void do_TCP_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
#endif

void do_TCP_server(TCP_Server *tcp_server, Mono_Time *mono_time)
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
#ifdef TCP_SERVER_USE_EPOLL
do_TCP_epoll(tcp_server, mono_time);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t

/** Run the TCP_server
*/
void do_TCP_server(TCP_Server *tcp_server, Mono_Time *mono_time);
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time);

/** Kill the TCP server
*/
Expand Down
Loading

0 comments on commit 08bc0ac

Please sign in to comment.