cleanup: Make parameters pointers-to-const where possible.

This commit is contained in:
iphydf 2022-01-16 01:25:43 +00:00
parent 09bb9b8a23
commit 422c8d1125
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
19 changed files with 90 additions and 86 deletions

View File

@ -1 +1 @@
78791fce8556684ee8210d6b79b11c5fd7a2c35c96589aec4b8641a62b0414a3 /usr/local/bin/tox-bootstrapd 7be4fcdc11f74036b97de9569eb06f82296f193db3e18e671171f3bc059f95a6 /usr/local/bin/tox-bootstrapd

View File

@ -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], 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); VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE);
uint8_t nonce[CRYPTO_NONCE_SIZE]; uint8_t nonce[CRYPTO_NONCE_SIZE];
@ -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); 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); unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@ -2124,7 +2125,7 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu
* *
* return ip of 0 if failure. * 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 zero;
ip_reset(&zero); ip_reset(&zero);
@ -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. * 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; uint16_t num = 0;
@ -2279,8 +2280,8 @@ static void do_NAT(DHT *dht)
* *
* return the number of nodes. * return the number of nodes.
*/ */
static uint16_t list_nodes(Client_data *list, size_t length, uint64_t cur_time, Node_format *nodes, static uint16_t list_nodes(const Client_data *list, size_t length, uint64_t cur_time,
uint16_t max_num) Node_format *nodes, uint16_t max_num)
{ {
if (max_num == 0) { if (max_num == 0) {
return 0; return 0;

View File

@ -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]; uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
data[0] = NET_PACKET_LAN_DISCOVERY; data[0] = NET_PACKET_LAN_DISCOVERY;

View File

@ -19,7 +19,7 @@
/** /**
* Send a LAN discovery pcaket to the broadcast address with port port. * 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. * Sets up packet handlers.

View File

@ -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, 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) { if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
return -1; return -1;

View File

@ -148,7 +148,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
* return 0 if no data received. * return 0 if no data received.
* return -1 on failure (connection refused). * 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"; char success[] = "200";
uint8_t data[16]; // draining works the best if the length is a power of 2 uint8_t data[16]; // draining works the best if the length is a power of 2
@ -190,7 +190,7 @@ static void proxy_socks5_generate_handshake(TCP_Client_Connection *tcp_conn)
* return 0 if no data received. * return 0 if no data received.
* return -1 on failure (connection refused). * 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]; uint8_t data[2];
int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data)); int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data));
@ -236,7 +236,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
* return 0 if no data received. * return 0 if no data received.
* return -1 on failure (connection refused). * 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)) { if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)];
@ -470,7 +470,7 @@ static int write_packet_TCP_client_secure_connection(TCP_Client_Connection *con,
* return 0 if could not send packet. * return 0 if could not send packet.
* return -1 on failure (connection must be killed). * 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]; uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE];
packet[0] = TCP_PACKET_ROUTING_REQUEST; packet[0] = TCP_PACKET_ROUTING_REQUEST;
@ -957,8 +957,8 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c
/** Run the TCP connection /** Run the TCP connection
*/ */
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
void *userdata) TCP_Client_Connection *tcp_connection, void *userdata)
{ {
if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) {
return; return;

View File

@ -54,8 +54,8 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip
/** Run the TCP connection /** Run the TCP connection
*/ */
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
void *userdata); TCP_Client_Connection *tcp_connection, void *userdata);
/** Kill the TCP connection /** Kill the TCP connection
*/ */
@ -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 0 if could not send packet.
* return -1 on failure (connection must be killed). * 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_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); void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);

View File

@ -289,7 +289,8 @@ uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c)
* return -1 on failure. * return -1 on failure.
* return 0 on success. * 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); TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
@ -372,7 +373,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
* return TCP connection number on success. * return TCP connection number on success.
* return -1 on failure. * 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(); const uint32_t r = random_u32();
@ -415,8 +416,8 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_numb
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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 *packet, uint16_t length) const uint8_t *public_key, const uint8_t *packet, uint16_t length)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -437,14 +438,14 @@ int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_num
return -1; 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. /** Send an oob packet via the TCP relay corresponding to relay_pk.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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) const uint8_t *packet, uint16_t length)
{ {
int tcp_con_number = find_tcp_connection_relay(tcp_c, relay_pk); int tcp_con_number = find_tcp_connection_relay(tcp_c, relay_pk);
@ -485,7 +486,7 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_
* return connections_number on success. * return connections_number on success.
* return -1 on failure. * 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) { for (unsigned int i = 0; i < tcp_c->connections_length; ++i) {
TCP_Connection_to *con_to = get_connection(tcp_c, i); TCP_Connection_to *con_to = get_connection(tcp_c, i);
@ -505,7 +506,7 @@ static int find_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_
* return connections_number on success. * return connections_number on success.
* return -1 on failure. * 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) { for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, i); TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
@ -603,7 +604,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number)
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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); TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
@ -660,7 +661,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number,
return 0; 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) { for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) { if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@ -712,7 +713,7 @@ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int t
/** return number of online connections on success. /** return number of online connections on success.
* return -1 on failure. * 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; unsigned int count = 0;
@ -903,7 +904,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -1266,7 +1267,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 number of online tcp relays tied to the connection on success.
* return 0 on failure. * 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); TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
@ -1283,7 +1284,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 number of relays copied to tcp_relays on success.
* return 0 on failure. * 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(); const uint32_t r = random_u32();
uint32_t copied = 0; uint32_t copied = 0;
@ -1387,7 +1388,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
* *
* Returns NULL on failure. * 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) { if (secret_key == nullptr) {
return nullptr; return nullptr;

View File

@ -80,7 +80,8 @@ uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
* return -1 on failure. * return -1 on failure.
* return 0 on success. * 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. /** Return a random TCP connection number for use in send_tcp_onion_request.
* *
@ -90,7 +91,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
* return TCP connection number on success. * return TCP connection number on success.
* return -1 on failure. * 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. /** Send an onion packet via the TCP relay corresponding to tcp_connections_number.
* *
@ -114,12 +115,12 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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); 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); 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); const uint8_t *packet, uint16_t length);
/** Set the callback for TCP data packets. /** Set the callback for TCP data packets.
@ -165,12 +166,12 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success. * return 0 on success.
* return -1 on failure. * 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 number of online tcp relays tied to the connection on success.
* return 0 on failure. * 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. /** Add a TCP relay tied to a connection.
* *
@ -205,7 +206,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 number of relays copied to tcp_relays on success.
* return 0 on failure. * 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. /** Returns a new TCP_Connections object associated with the secret_key.
* *
@ -214,7 +215,7 @@ uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_rela
* *
* Returns NULL on failure. * 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); int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);

View File

@ -1430,7 +1430,7 @@ static void do_TCP_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
} }
#endif #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 #ifdef TCP_SERVER_USE_EPOLL
do_TCP_epoll(tcp_server, mono_time); do_TCP_epoll(tcp_server, mono_time);

View File

@ -74,7 +74,7 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t
/** Run the TCP_server /** 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 /** Kill the TCP server
*/ */

View File

@ -190,7 +190,7 @@ Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
/** return friendcon_id corresponding to the real public key on success. /** return friendcon_id corresponding to the real public key on success.
* return -1 on failure. * return -1 on failure.
*/ */
int getfriend_conn_id_pk(Friend_Connections *fr_c, const uint8_t *real_pk) int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk)
{ {
for (uint32_t i = 0; i < fr_c->num_cons; ++i) { for (uint32_t i = 0; i < fr_c->num_cons; ++i) {
Friend_Conn *friend_con = get_conn(fr_c, i); Friend_Conn *friend_con = get_conn(fr_c, i);
@ -622,7 +622,7 @@ static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id) int friend_connection_lock(const Friend_Connections *fr_c, int friendcon_id)
{ {
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id); Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -638,7 +638,7 @@ int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id)
* return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected. * return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* return FRIENDCONN_STATUS_NONE on failure. * return FRIENDCONN_STATUS_NONE on failure.
*/ */
unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id) unsigned int friend_con_connected(const Friend_Connections *fr_c, int friendcon_id)
{ {
const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id); const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -654,7 +654,7 @@ unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id)
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id) int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, const Friend_Connections *fr_c, int friendcon_id)
{ {
const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id); const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -686,7 +686,7 @@ void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *
* return 0 on success. * return 0 on success.
* return -1 on failure * return -1 on failure
*/ */
int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id, unsigned int index,
fc_status_cb *status_callback, fc_status_cb *status_callback,
fc_data_cb *data_callback, fc_data_cb *data_callback,
fc_lossy_data_cb *lossy_data_callback, fc_lossy_data_cb *lossy_data_callback,
@ -724,7 +724,7 @@ void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *glob
* return crypt_connection_id on success. * return crypt_connection_id on success.
* return -1 on failure. * return -1 on failure.
*/ */
int friend_connection_crypt_connection_id(Friend_Connections *fr_c, int friendcon_id) int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int friendcon_id)
{ {
const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id); const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);

View File

@ -53,27 +53,27 @@ Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c);
/** return friendcon_id corresponding to the real public key on success. /** return friendcon_id corresponding to the real public key on success.
* return -1 on failure. * return -1 on failure.
*/ */
int getfriend_conn_id_pk(Friend_Connections *fr_c, const uint8_t *real_pk); int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk);
/** Increases lock_count for the connection with friendcon_id by 1. /** Increases lock_count for the connection with friendcon_id by 1.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id); int friend_connection_lock(const Friend_Connections *fr_c, int friendcon_id);
/** return FRIENDCONN_STATUS_CONNECTED if the friend is connected. /** return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
* return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected. * return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* return FRIENDCONN_STATUS_NONE on failure. * return FRIENDCONN_STATUS_NONE on failure.
*/ */
unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id); unsigned int friend_con_connected(const Friend_Connections *fr_c, int friendcon_id);
/** Copy public keys associated to friendcon_id. /** Copy public keys associated to friendcon_id.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id); int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, const Friend_Connections *fr_c, int friendcon_id);
/** Set temp dht key for connection. /** Set temp dht key for connection.
*/ */
@ -101,7 +101,7 @@ void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *glob
* return 0 on success. * return 0 on success.
* return -1 on failure * return -1 on failure
*/ */
int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id, unsigned int index,
fc_status_cb *status_callback, fc_status_cb *status_callback,
fc_data_cb *data_callback, fc_data_cb *data_callback,
fc_lossy_data_cb *lossy_data_callback, fc_lossy_data_cb *lossy_data_callback,
@ -112,7 +112,7 @@ int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsi
* return crypt_connection_id on success. * return crypt_connection_id on success.
* return -1 on failure. * return -1 on failure.
*/ */
int friend_connection_crypt_connection_id(Friend_Connections *fr_c, int friendcon_id); int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int friendcon_id);
/** Create a new friend connection. /** Create a new friend connection.
* If one to that real public key already exists, increase lock count and return it. * If one to that real public key already exists, increase lock count and return it.

View File

@ -337,7 +337,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te
return true; return true;
} }
static bool pk_in_closest_peers(const Group_c *g, uint8_t *real_pk) static bool pk_in_closest_peers(const Group_c *g, const uint8_t *real_pk)
{ {
for (unsigned int i = 0; i < DESIRED_CLOSEST; ++i) { for (unsigned int i = 0; i < DESIRED_CLOSEST; ++i) {
if (!g->closest_peers[i].entry) { if (!g->closest_peers[i].entry) {
@ -1430,7 +1430,7 @@ static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendco
* return -2 if invite packet failed to send. * return -2 if invite packet failed to send.
* return -3 if we are not connected to the group chat. * return -3 if we are not connected to the group chat.
*/ */
int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber) int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber)
{ {
Group_c *g = get_group_c(g_c, groupnumber); Group_c *g = get_group_c(g_c, groupnumber);
@ -1664,7 +1664,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, pe
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function) int callback_groupchat_peer_delete(const Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function)
{ {
Group_c *g = get_group_c(g_c, groupnumber); Group_c *g = get_group_c(g_c, groupnumber);
@ -1681,7 +1681,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function) int callback_groupchat_delete(const Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function)
{ {
Group_c *g = get_group_c(g_c, groupnumber); Group_c *g = get_group_c(g_c, groupnumber);
@ -1712,7 +1712,7 @@ static bool group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
* return true on success * return true on success
*/ */
static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk, static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk,
uint8_t *temp_pk) const uint8_t *temp_pk)
{ {
uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH];
@ -2065,7 +2065,7 @@ static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16
sizeof(packet), 0) != -1; sizeof(packet), 0) != -1;
} }
static bool ping_groupchat(Group_Chats *g_c, uint32_t groupnumber); static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber);
static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length) static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length)
{ {
@ -3033,7 +3033,7 @@ void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, uint32
/* Interval in seconds to send ping messages */ /* Interval in seconds to send ping messages */
#define GROUP_PING_INTERVAL 20 #define GROUP_PING_INTERVAL 20
static bool ping_groupchat(Group_Chats *g_c, uint32_t groupnumber) static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber)
{ {
Group_c *g = get_group_c(g_c, groupnumber); Group_c *g = get_group_c(g_c, groupnumber);
@ -3097,7 +3097,7 @@ static void squash_connections(Group_c *g)
#define MIN_EMPTY_CONNECTIONS (1 + MAX_GROUP_CONNECTIONS / 10) #define MIN_EMPTY_CONNECTIONS (1 + MAX_GROUP_CONNECTIONS / 10)
static uint16_t empty_connection_count(Group_c *g) static uint16_t empty_connection_count(const Group_c *g)
{ {
uint16_t to_clear = MIN_EMPTY_CONNECTIONS; uint16_t to_clear = MIN_EMPTY_CONNECTIONS;
@ -3152,7 +3152,7 @@ static void clean_connections(Group_Chats *g_c, Group_c *g)
/** Send current name (set in messenger) to all online groups. /** Send current name (set in messenger) to all online groups.
*/ */
void send_name_all_groups(Group_Chats *g_c) void send_name_all_groups(const Group_Chats *g_c)
{ {
for (uint16_t i = 0; i < g_c->num_chats; ++i) { for (uint16_t i = 0; i < g_c->num_chats; ++i) {
Group_c *g = get_group_c(g_c, i); Group_c *g = get_group_c(g_c, i);
@ -3431,7 +3431,7 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3
/** Create new groupchat instance. */ /** Create new groupchat instance. */
Group_Chats *new_groupchats(Mono_Time *mono_time, Messenger *m) Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m)
{ {
if (!m) { if (!m) {
return nullptr; return nullptr;

View File

@ -286,7 +286,7 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
* return -2 if invite packet failed to send. * return -2 if invite packet failed to send.
* return -3 if we are not connected to the group chat. * return -3 if we are not connected to the group chat.
*/ */
int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber); int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber);
/** Join a group (we need to have been invited first.) /** Join a group (we need to have been invited first.)
* *
@ -395,7 +395,7 @@ int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id);
/** Send current name (set in messenger) to all online groups. /** Send current name (set in messenger) to all online groups.
*/ */
void send_name_all_groups(Group_Chats *g_c); void send_name_all_groups(const Group_Chats *g_c);
/** Set the object that is tied to the group chat. /** Set the object that is tied to the group chat.
* *
@ -437,14 +437,14 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, pe
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function); int callback_groupchat_peer_delete(const Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function);
/** Set a function to be called when the group chat is deleted. /** Set a function to be called when the group chat is deleted.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function); int callback_groupchat_delete(const Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function);
/** Return size of the conferences data (for saving). */ /** Return size of the conferences data (for saving). */
uint32_t conferences_size(const Group_Chats *g_c); uint32_t conferences_size(const Group_Chats *g_c);
@ -465,7 +465,7 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3
State_Load_Status *status); State_Load_Status *status);
/** Create new groupchat instance. */ /** Create new groupchat instance. */
Group_Chats *new_groupchats(Mono_Time *mono_time, Messenger *m); Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m);
/** main groupchats loop. */ /** main groupchats loop. */
void do_groupchats(Group_Chats *g_c, void *userdata); void do_groupchats(Group_Chats *g_c, void *userdata);

View File

@ -207,8 +207,8 @@ static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connecti
* return -1 on failure. * return -1 on failure.
* return COOKIE_REQUEST_LENGTH on success. * return COOKIE_REQUEST_LENGTH on success.
*/ */
static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *dht_public_key, uint64_t number, static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uint8_t *dht_public_key,
uint8_t *shared_key) uint64_t number, uint8_t *shared_key)
{ {
uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH]; uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t padding[CRYPTO_PUBLIC_KEY_SIZE] = {0}; uint8_t padding[CRYPTO_PUBLIC_KEY_SIZE] = {0};
@ -601,7 +601,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por
* return IP_Port with family 0 on failure. * return IP_Port with family 0 on failure.
* return IP_Port on success. * return IP_Port on success.
*/ */
static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connection_id)
{ {
const IP_Port empty = {0}; const IP_Port empty = {0};
@ -1988,7 +1988,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
* return -1 on failure. * return -1 on failure.
* return connection id on success. * return connection id on success.
*/ */
int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c) int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c)
{ {
if (getcryptconnection_id(c, n_c->public_key) != -1) { if (getcryptconnection_id(c, n_c->public_key) != -1) {
return -1; return -1;
@ -2361,7 +2361,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id,
connection_lossy_data_cb *connection_lossy_data_callback, connection_lossy_data_cb *connection_lossy_data_callback,
void *object, int id) void *object, int id)
{ {
@ -2388,7 +2388,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object, uint32_t number) int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object, uint32_t number)
{ {
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2811,7 +2811,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
* It CANNOT be simplified to `packet_number < buffer_start`, as it will fail * It CANNOT be simplified to `packet_number < buffer_start`, as it will fail
* when `buffer_end < buffer_start`. * when `buffer_end < buffer_start`.
*/ */
int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number) int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t packet_number)
{ {
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);

View File

@ -144,7 +144,7 @@ void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_cal
* return -1 on failure. * return -1 on failure.
* return connection id on success. * return connection id on success.
*/ */
int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c); int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c);
/* Create a crypto connection. /* Create a crypto connection.
* If one to that real public key already exists, return it. * If one to that real public key already exists, return it.
@ -196,7 +196,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id,
connection_lossy_data_cb *connection_lossy_data_callback, void *object, int id); connection_lossy_data_cb *connection_lossy_data_callback, void *object, int id);
/* Set the function for this friend that will be callbacked with object and number if /* Set the function for this friend that will be callbacked with object and number if
@ -209,7 +209,8 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object, uint32_t number); int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object,
uint32_t number);
/* returns the number of packet slots left in the sendbuffer. /* returns the number of packet slots left in the sendbuffer.
* return 0 if failure. * return 0 if failure.
@ -240,7 +241,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number); int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t packet_number);
/* Sends a lossy cryptopacket. /* Sends a lossy cryptopacket.
* *

View File

@ -326,7 +326,7 @@ static int is_path_used(const Mono_Time *mono_time, const Onion_Client_Paths *on
} }
/** is path timed out */ /** is path timed out */
static bool path_timed_out(const Mono_Time *mono_time, Onion_Client_Paths *onion_paths, uint32_t pathnum) static bool path_timed_out(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t pathnum)
{ {
pathnum = pathnum % NUMBER_ONION_PATHS; pathnum = pathnum % NUMBER_ONION_PATHS;
@ -737,7 +737,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
return 0; return 0;
} }
static int good_to_ping(Mono_Time *mono_time, Last_Pinged *last_pinged, uint8_t *last_pinged_index, static int good_to_ping(const Mono_Time *mono_time, Last_Pinged *last_pinged, uint8_t *last_pinged_index,
const uint8_t *public_key) const uint8_t *public_key)
{ {
for (unsigned int i = 0; i < MAX_STORED_PINGED_NODES; ++i) { for (unsigned int i = 0; i < MAX_STORED_PINGED_NODES; ++i) {

View File

@ -90,8 +90,8 @@ void ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk)); 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, static int ping_send_response(const Ping *ping, IP_Port ipp, const uint8_t *public_key,
uint8_t *shared_encryption_key) uint64_t ping_id, const uint8_t *shared_encryption_key)
{ {
uint8_t pk[DHT_PING_SIZE]; uint8_t pk[DHT_PING_SIZE];