Skip to content

Commit

Permalink
cleanup: Even more pointer-to-const parameters.
Browse files Browse the repository at this point in the history
I missed these the first time around.
  • Loading branch information
iphydf committed Jan 16, 2022
1 parent c7ecee7 commit b2ec494
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t
* return 0 on success.
* return -1 on failure.
*/
int groupchat_disable_av(Group_Chats *g_c, uint32_t groupnumber)
int groupchat_disable_av(const Group_Chats *g_c, uint32_t groupnumber)
{
if (group_get_type(g_c, groupnumber) != GROUPCHAT_TYPE_AV) {
return -1;
Expand Down Expand Up @@ -501,7 +501,7 @@ int groupchat_disable_av(Group_Chats *g_c, uint32_t groupnumber)

/* Return whether A/V is enabled in the groupchat.
*/
bool groupchat_av_enabled(Group_Chats *g_c, uint32_t groupnumber)
bool groupchat_av_enabled(const Group_Chats *g_c, uint32_t groupnumber)
{
return group_get_object(g_c, groupnumber) != nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions toxav/groupav.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t
* return 0 on success.
* return -1 on failure.
*/
int groupchat_disable_av(Group_Chats *g_c, uint32_t groupnumber);
int groupchat_disable_av(const Group_Chats *g_c, uint32_t groupnumber);

/* Return whether A/V is enabled in the groupchat.
*/
bool groupchat_av_enabled(Group_Chats *g_c, uint32_t groupnumber);
bool groupchat_av_enabled(const Group_Chats *g_c, uint32_t groupnumber);

#endif // C_TOXCORE_TOXAV_GROUPAV_H
8 changes: 4 additions & 4 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ static bool get_ip_port(const DHT *dht, IP_Port ip_port, uint32_t *n, void *user
*
* return number of nodes the packet was sent to.
*/
static uint32_t routeone_to_friend(DHT *dht, const uint8_t *friend_id, const Packet *packet)
static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet)
{
const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id);

Expand Down Expand Up @@ -2048,7 +2048,7 @@ static uint32_t routeone_to_friend(DHT *dht, const uint8_t *friend_id, const Pac
/*----------------------------------------------------------------------------------*/
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/

static int send_NATping(DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
static int send_NATping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
{
uint8_t data[sizeof(uint64_t) + 1];
uint8_t packet_data[MAX_CRYPTO_REQUEST_SIZE];
Expand Down Expand Up @@ -2322,7 +2322,7 @@ static uint16_t list_nodes(const Client_data *list, size_t length, uint64_t cur_
*
* return the number of nodes.
*/
uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num)
{
if (max_num == 0) {
return 0;
Expand All @@ -2347,7 +2347,7 @@ uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
*
* return the number of nodes.
*/
uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num)
{
return list_nodes(dht->close_clientlist, LCLIENT_LIST, dht->cur_time, nodes, max_num);
}
Expand Down
4 changes: 2 additions & 2 deletions toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *node
*
* return the number of nodes.
*/
uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);

/** Put up to max_num nodes in nodes from the closelist.
*
* return the number of nodes.
*/
uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);

/** Run this function at least a couple times per second (It's the main loop). */
void do_dht(DHT *dht);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void fetch_broadcast_info(uint16_t port)
* return 1 if sent to at least one broadcast target.
* return 0 on failure to find any valid broadcast target.
*/
static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8_t *data, uint16_t length)
static uint32_t send_broadcasts(const Networking_Core *net, uint16_t port, const uint8_t *data, uint16_t length)
{
/* fetch only once? on every packet? every X seconds?
* old: every packet, new: once */
Expand Down
12 changes: 7 additions & 5 deletions toxcore/TCP_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ 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(const 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,
const uint8_t *public_key)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);

Expand All @@ -926,7 +927,7 @@ static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
{
TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object;
TCP_Connections *tcp_c = (TCP_Connections *)tcp_con_custom_object(tcp_client_con);
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);

unsigned int tcp_connections_number = tcp_con_custom_uint(tcp_client_con);
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
Expand Down Expand Up @@ -1044,7 +1045,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const
/* TODO(irungentoo): optimize */
int connections_number = find_tcp_connection_to(tcp_c, public_key);

TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
const TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) {
return tcp_conn_data_callback(object, connections_number, 0, data, length, userdata);
Expand Down Expand Up @@ -1193,7 +1194,8 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t
* return 0 on success.
* return -1 on failure.
*/
int add_tcp_number_relay_connection(TCP_Connections *tcp_c, int connections_number, unsigned int tcp_connections_number)
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number)
{
TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

Expand Down Expand Up @@ -1269,7 +1271,7 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
*/
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);
const TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);

if (!con_to) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, i
* return 0 on success.
* return -1 on failure.
*/
int add_tcp_number_relay_connection(TCP_Connections *tcp_c, int connections_number,
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number);

/** Add a TCP relay tied to a connection.
Expand Down
2 changes: 1 addition & 1 deletion toxcore/friend_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
return 0;
}

static int handle_new_connections(void *object, New_Connection *n_c)
static int handle_new_connections(void *object, const New_Connection *n_c)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
const int friendcon_id = getfriend_conn_id_pk(fr_c, n_c->public_key);
Expand Down
12 changes: 6 additions & 6 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ static void purge_closest(Group_Chats *g_c, uint32_t groupnumber)
}
}

static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t type,
const uint8_t *id);
static int send_packet_online(const Friend_Connections *fr_c, int friendcon_id, uint16_t group_num,
uint8_t type, const uint8_t *id);

static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g, uint8_t reason,
uint8_t lock);
Expand Down Expand Up @@ -1386,7 +1386,7 @@ bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id
* return 1 on success
* return 0 on failure
*/
static unsigned int send_packet_group_peer(Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
static unsigned int send_packet_group_peer(const Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
uint16_t group_num, const uint8_t *data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
Expand All @@ -1407,7 +1407,7 @@ static unsigned int send_packet_group_peer(Friend_Connections *fr_c, int friendc
* return 1 on success
* return 0 on failure
*/
static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
static unsigned int send_lossy_group_peer(const Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
uint16_t group_num, const uint8_t *data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
Expand Down Expand Up @@ -2052,8 +2052,8 @@ static unsigned int count_connected(const Group_c *g)
return count;
}

static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t type,
const uint8_t *id)
static int send_packet_online(const Friend_Connections *fr_c, int friendcon_id, uint16_t group_num,
uint8_t type, const uint8_t *id)
{
uint8_t packet[1 + ONLINE_PACKET_DATA_SIZE];
group_num = net_htons(group_num);
Expand Down
11 changes: 6 additions & 5 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length,
void *userdata)
{
Net_Crypto *c = (Net_Crypto *)object;
const Net_Crypto *c = (const Net_Crypto *)object;
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
Expand All @@ -371,7 +371,8 @@ static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t

/* Handle the cookie request packet (for TCP)
*/
static int tcp_handle_cookie_request(Net_Crypto *c, int connections_number, const uint8_t *packet, uint16_t length)
static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number, const uint8_t *packet,
uint16_t length)
{
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
Expand Down Expand Up @@ -426,7 +427,7 @@ static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_c
* return -1 on failure.
* return COOKIE_LENGTH on success.
*/
static int handle_cookie_response(const Logger *log, uint8_t *cookie, uint64_t *number,
static int handle_cookie_response(uint8_t *cookie, uint64_t *number,
const uint8_t *packet, uint16_t length,
const uint8_t *shared_key)
{
Expand Down Expand Up @@ -1655,7 +1656,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
uint8_t cookie[COOKIE_LENGTH];
uint64_t number;

if (handle_cookie_response(c->log, cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) {
if (handle_cookie_response(cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) {
return -1;
}

Expand Down Expand Up @@ -2956,7 +2957,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk)
/* Run this to (re)initialize net_crypto.
* Sets all the global connection variables to their default values.
*/
Net_Crypto *new_net_crypto(const Logger *log, Mono_Time *mono_time, DHT *dht, TCP_Proxy_Info *proxy_info)
Net_Crypto *new_net_crypto(const Logger *log, Mono_Time *mono_time, DHT *dht, const TCP_Proxy_Info *proxy_info)
{
if (dht == nullptr) {
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions toxcore/net_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ typedef int connection_status_cb(void *object, int id, uint8_t status, void *use
typedef int connection_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
typedef int connection_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
typedef void dht_pk_cb(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata);
typedef int new_connection_cb(void *object, New_Connection *n_c);
typedef int new_connection_cb(void *object, const New_Connection *n_c);

/* Set function to be called when someone requests a new connection to us.
*
Expand Down Expand Up @@ -321,7 +321,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk);
/* Create new instance of Net_Crypto.
* Sets all the global connection variables to their default values.
*/
Net_Crypto *new_net_crypto(const Logger *log, Mono_Time *mono_time, DHT *dht, TCP_Proxy_Info *proxy_info);
Net_Crypto *new_net_crypto(const Logger *log, Mono_Time *mono_time, DHT *dht, const TCP_Proxy_Info *proxy_info);

/* return the optimal interval in ms for running do_net_crypto.
*/
Expand Down
6 changes: 4 additions & 2 deletions toxcore/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O
* return -1 on failure.
* return 0 on success.
*/
int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint16_t length)
int send_onion_packet(const Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data,
uint16_t length)
{
uint8_t packet[ONION_MAX_PACKET_SIZE];
int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length);
Expand All @@ -292,7 +293,8 @@ int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest
* return -1 on failure.
* return 0 on success.
*/
int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint16_t length, const uint8_t *ret)
int send_onion_response(const Networking_Core *net, IP_Port dest, const uint8_t *data, uint16_t length,
const uint8_t *ret)
{
if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) {
return -1;
Expand Down
6 changes: 4 additions & 2 deletions toxcore/onion.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O
* return -1 on failure.
* return 0 on success.
*/
int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint16_t length);
int send_onion_packet(const Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data,
uint16_t length);

/** Create and send a onion response sent initially to dest with.
* Maximum length of data is ONION_RESPONSE_MAX_DATA_SIZE.
*
* return -1 on failure.
* return 0 on success.
*/
int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint16_t length, const uint8_t *ret);
int send_onion_response(const Networking_Core *net, IP_Port dest, const uint8_t *data, uint16_t length,
const uint8_t *ret);

/** Function to handle/send received decrypted versions of the packet sent with send_onion_packet.
*
Expand Down
9 changes: 5 additions & 4 deletions toxcore/onion_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, const uint8
* return -1 on failure.
* return 0 on success.
*/
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
uint64_t sendback_data)
int send_announce_request(const Networking_Core *net, const Onion_Path *path, Node_format dest,
const uint8_t *public_key, const uint8_t *secret_key,
const uint8_t *ping_id, const uint8_t *client_id,
const uint8_t *data_public_key, uint64_t sendback_data)
{
uint8_t request[ONION_ANNOUNCE_REQUEST_SIZE];
int len = create_announce_request(request, sizeof(request), dest.public_key, public_key, secret_key, ping_id, client_id,
Expand Down Expand Up @@ -202,7 +203,7 @@ int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_for
* return -1 on failure.
* return 0 on success.
*/
int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
int send_data_request(const Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length)
{
uint8_t request[ONION_MAX_DATA_SIZE];
Expand Down
9 changes: 5 additions & 4 deletions toxcore/onion_announce.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, const uint8
* return -1 on failure.
* return 0 on success.
*/
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
uint64_t sendback_data);
int send_announce_request(const Networking_Core *net, const Onion_Path *path, Node_format dest,
const uint8_t *public_key, const uint8_t *secret_key,
const uint8_t *ping_id, const uint8_t *client_id,
const uint8_t *data_public_key, uint64_t sendback_data);

/** Create and send an onion data request packet.
*
Expand All @@ -98,7 +99,7 @@ int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_for
* return -1 on failure.
* return 0 on success.
*/
int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
int send_data_request(const Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length);


Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
}

/** Does path with path_num exist. */
static bool path_exists(const Mono_Time *mono_time, Onion_Client_Paths *onion_paths, uint32_t path_num)
static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num)
{
if (path_timed_out(mono_time, onion_paths, path_num)) {
return 0;
Expand Down

0 comments on commit b2ec494

Please sign in to comment.