Const correctness for various packet callbacks

This commit is contained in:
Marc Schütz 2014-06-13 22:55:15 +02:00
parent 714b2aeaee
commit 4940c4c62b
11 changed files with 44 additions and 44 deletions

View File

@ -1067,7 +1067,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
return sendpacket(dht->net, ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len);
}
static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES;
@ -1194,7 +1194,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
return 0;
}
static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
DHT *dht = object;
Node_format plain_nodes[MAX_SENT_NODES];
@ -2296,7 +2296,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
dht->cryptopackethandlers[byte].object = object;
}
static int cryptopacket_handle(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
DHT *dht = object;

View File

@ -98,7 +98,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, uint8_t *data, uint16_t length)
static uint32_t send_broadcasts(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 */
@ -207,7 +207,7 @@ int LAN_ip(IP ip)
return -1;
}
static int handle_LANdiscovery(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
DHT *dht = object;

View File

@ -1261,7 +1261,7 @@ int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES],
return group_client_names(m->chats[groupnumber], names, lengths, length);
}
static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_group(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Messenger *m = object;

View File

@ -619,7 +619,7 @@ static int rm_connection_index(TCP_Server *TCP_server, TCP_Secure_Connection *co
}
}
static int handle_onion_recv_1(void *object, IP_Port dest, uint8_t *data, uint16_t length)
static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length)
{
TCP_Server *TCP_server = object;
uint32_t index = dest.ip.ip6.uint32[0];

View File

@ -120,7 +120,7 @@ static int create_cookie(uint8_t *cookie, uint8_t *bytes, uint8_t *encryption_ke
* return -1 on failure.
* return 0 on success.
*/
static int open_cookie(uint8_t *bytes, uint8_t *cookie, uint8_t *encryption_key)
static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key)
{
uint8_t contents[COOKIE_CONTENTS_LENGTH];
int len = decrypt_data_symmetric(encryption_key, cookie, cookie + crypto_box_NONCEBYTES,
@ -178,7 +178,7 @@ static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *reque
* return 0 on success.
*/
static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key,
uint8_t *packet, uint16_t length)
const uint8_t *packet, uint16_t length)
{
if (length != COOKIE_REQUEST_LENGTH)
return -1;
@ -197,7 +197,7 @@ static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t
/* Handle the cookie request packet (for raw UDP)
*/
static int udp_handle_cookie_request(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Net_Crypto *c = object;
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
@ -275,8 +275,8 @@ static int tcp_oob_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *T
* return -1 on failure.
* return COOKIE_LENGTH on success.
*/
static int handle_cookie_response(uint8_t *cookie, uint64_t *number, uint8_t *packet, uint32_t length,
uint8_t *shared_key)
static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8_t *packet, uint32_t length,
const uint8_t *shared_key)
{
if (length != COOKIE_RESPONSE_LENGTH)
return -1;
@ -349,7 +349,7 @@ static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cook
* return 0 on success.
*/
static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
uint8_t *dht_public_key, uint8_t *cookie, uint8_t *packet, uint32_t length, uint8_t *expected_real_pk)
uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, uint8_t *expected_real_pk)
{
if (length != HANDSHAKE_PACKET_LENGTH)
return -1;
@ -815,7 +815,7 @@ static uint16_t get_nonce_uint16(uint8_t *nonce)
* return -1 on failure.
* return length of data on success.
*/
static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint8_t *packet, uint16_t length)
static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet, uint16_t length)
{
if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE)
return -1;
@ -1039,7 +1039,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length)
static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
{
if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE)
return -1;
@ -1133,7 +1133,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uin
* return -1 on failure.
* return 0 on success.
*/
static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length)
static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
return -1;
@ -1370,7 +1370,7 @@ void new_connection_handler(Net_Crypto *c, int (*new_connection_callback)(void *
* return -1 on failure.
* return 0 on success.
*/
static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, uint8_t *data, uint16_t length)
static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const uint8_t *data, uint16_t length)
{
New_Connection n_c;
n_c.cookie = malloc(COOKIE_LENGTH);
@ -2123,7 +2123,7 @@ static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port)
* Crypto data packets.
*
*/
static int udp_handle_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE)
return 1;

View File

@ -270,7 +270,7 @@ int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra);
* Packet data is put into data.
* Packet length is put into length.
*/
typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, uint8_t *data, uint32_t len);
typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, const uint8_t *data, uint32_t len);
typedef struct {
packet_handler_callback function;

View File

@ -149,7 +149,7 @@ int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
* return -1 on failure.
* return 0 on success.
*/
int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint32_t length, uint8_t *ret)
int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint32_t length, const uint8_t *ret)
{
if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0)
return -1;
@ -165,7 +165,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint3
return 0;
}
static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -189,7 +189,7 @@ static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, ui
return onion_send_1(onion, plain, len, source, packet + 1);
}
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uint8_t *nonce)
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce)
{
IP_Port send_to;
ipport_unpack(&send_to, plain);
@ -219,7 +219,7 @@ int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uin
return 0;
}
static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -268,7 +268,7 @@ static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t
return 0;
}
static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -316,7 +316,7 @@ static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t
}
static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -350,7 +350,7 @@ static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t
return 0;
}
static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -384,7 +384,7 @@ static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t
return 0;
}
static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion *onion = object;
@ -417,7 +417,7 @@ static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t
return 0;
}
void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, uint8_t *, uint16_t), void *object)
void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, const uint8_t *, uint16_t), void *object)
{
onion->recv_1_function = function;
onion->callback_object = object;

View File

@ -35,7 +35,7 @@ typedef struct {
Shared_Keys shared_keys_2;
Shared_Keys shared_keys_3;
int (*recv_1_function)(void *, IP_Port, uint8_t *, uint16_t);
int (*recv_1_function)(void *, IP_Port, const uint8_t *, uint16_t);
void *callback_object;
} Onion;
@ -94,7 +94,7 @@ int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
* return -1 on failure.
* return 0 on success.
*/
int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint32_t length, uint8_t *ret);
int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint32_t length, const uint8_t *ret);
/* Function to handle/send received decrypted versions of the packet sent with send_onion_packet.
*
@ -106,13 +106,13 @@ int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint3
* Source family must be set to something else than AF_INET6 or AF_INET so that the callback gets called
* when the response is received.
*/
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uint8_t *nonce);
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce);
/* Set the callback to be called when the dest ip_port doesn't have AF_INET6 or AF_INET as the family.
*
* Format: function(void *object, IP_Port dest, uint8_t *data, uint32_t length)
*/
void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, uint8_t *, uint16_t), void *object);
void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, const uint8_t *, uint16_t), void *object);
Onion *new_onion(DHT *dht);

View File

@ -115,7 +115,7 @@ int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
}
/* Generate a ping_id and put it in ping_id */
static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, uint8_t *public_key, IP_Port ret_ip_port,
static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, const uint8_t *public_key, IP_Port ret_ip_port,
uint8_t *ping_id)
{
time /= PING_ID_TIMEOUT;
@ -132,7 +132,7 @@ static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, uint8_t *pu
* return -1 if no
* return position in list if yes
*/
static int in_entries(Onion_Announce *onion_a, uint8_t *public_key)
static int in_entries(const Onion_Announce *onion_a, const uint8_t *public_key)
{
uint32_t i;
@ -179,8 +179,8 @@ static int cmp_entry(const void *a, const void *b)
* return -1 if failure
* return position if added
*/
static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, uint8_t *public_key, uint8_t *data_public_key,
uint8_t *ret)
static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const uint8_t *public_key, const uint8_t *data_public_key,
const uint8_t *ret)
{
int pos = in_entries(onion_a, public_key);
@ -213,14 +213,14 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, uint8_t
return in_entries(onion_a, public_key);
}
static int handle_announce_request(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion_Announce *onion_a = object;
if (length != ANNOUNCE_REQUEST_SIZE_RECV)
return 1;
uint8_t *packet_public_key = packet + 1 + crypto_box_NONCEBYTES;
const uint8_t *packet_public_key = packet + 1 + crypto_box_NONCEBYTES;
uint8_t shared_key[crypto_box_BEFORENMBYTES];
get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key);
@ -302,7 +302,7 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet
return 0;
}
static int handle_data_request(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion_Announce *onion_a = object;

View File

@ -164,7 +164,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key
* return ~0 on failure
* return num (see new_sendback(...)) on success
*/
static uint32_t check_sendback(Onion_Client *onion_c, uint8_t *sendback, uint8_t *ret_pubkey, IP_Port *ret_ip_port)
static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey, IP_Port *ret_ip_port)
{
uint64_t sback;
memcpy(&sback, sendback, sizeof(uint64_t));
@ -377,7 +377,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n
return 0;
}
static int handle_announce_response(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion_Client *onion_c = object;
@ -432,7 +432,7 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe
#define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE
static int handle_data_response(void *object, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
{
Onion_Client *onion_c = object;

View File

@ -129,7 +129,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *client_id,
return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
}
static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet, uint32_t length)
{
DHT *dht = _dht;
int rc;
@ -168,7 +168,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint
return 0;
}
static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uint32_t length)
static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packet, uint32_t length)
{
DHT *dht = _dht;
int rc;