cleanup: Add more nonnull and nullable annotations.

This commit is contained in:
iphydf 2022-02-08 19:15:37 +00:00
parent 5a3a0b6453
commit 10f86f6c00
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
80 changed files with 1466 additions and 609 deletions

View File

@ -286,7 +286,9 @@ int main(void)
options.port_range[0] = 41234;
options.port_range[1] = 44234;
options.log_callback = (logger_cb *)print_debug_log;
m = new_messenger(mono_time, &options, nullptr);
unsigned int err;
m = new_messenger(mono_time, &options, &err);
ck_assert(err == MESSENGER_ERROR_NONE);
/* setup a default friend and friendnum */
if (m_addfriend_norequest(m, friend_id) < 0) {

View File

@ -5,6 +5,7 @@ command = """\
else \
git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css;
fi && \
sed -i -e 's/^non_null([^)]*) *//;s/^nullable([^)]*) *//' $(find . -name "*.[ch]") && \
doxygen docs/Doxyfile \
"""
publish = "_docs/html"

View File

@ -1,4 +1,4 @@
#!/bin/bash
run
run -DVANILLA_NACL -I/usr/include/sodium
run "$@"
run -DVANILLA_NACL -I/usr/include/sodium "$@"

View File

@ -1 +1 @@
30845d5b6a5a2606afccceff83c7f1089040a800eb138c9ad92932cea2447e30 /usr/local/bin/tox-bootstrapd
502cc22df74fa369b2c09d117176705a1e801726db6f8360c688aee90973fa22 /usr/local/bin/tox-bootstrapd

View File

@ -11,6 +11,7 @@ WORKDIR /work
COPY . /work/
RUN cat docs/Doxyfile > Doxyfile \
&& echo "WARN_AS_ERROR = YES" >> Doxyfile \
&& sed -i -e 's/^non_null([^)]*) *//;s/^nullable([^)]*) *//' $(find . -name "*.[ch]") \
&& doxygen Doxyfile
FROM nginx:alpine

View File

@ -100,10 +100,11 @@ int main(int argc, char *argv[])
Messenger_Options options = {0};
options.ipv6enabled = ipv6enabled;
m = new_messenger(mono_time, &options, nullptr);
unsigned int err;
m = new_messenger(mono_time, &options, &err);
if (!m) {
fputs("Failed to allocate messenger datastructure\n", stderr);
fprintf(stderr, "Failed to allocate messenger datastructure: %d\n", err);
exit(0);
}

View File

@ -8,11 +8,18 @@ exports_files(
visibility = ["//c-toxcore:__pkg__"],
)
cc_library(
name = "attributes",
hdrs = ["attributes.h"],
visibility = ["//c-toxcore:__subpackages__"],
)
cc_library(
name = "ccompat",
srcs = ["ccompat.c"],
hdrs = ["ccompat.h"],
visibility = ["//c-toxcore:__subpackages__"],
deps = [":attributes"],
)
cc_library(

View File

@ -107,81 +107,68 @@ struct DHT {
unsigned int num_to_bootstrap;
};
non_null(1)
const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend)
{
return dht_friend->public_key;
}
non_null(1)
const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index)
{
return &dht_friend->client_list[index];
}
non_null(1)
const uint8_t *dht_get_self_public_key(const DHT *dht)
{
return dht->self_public_key;
}
non_null(1)
const uint8_t *dht_get_self_secret_key(const DHT *dht)
{
return dht->self_secret_key;
}
non_null(1, 2)
void dht_set_self_public_key(DHT *dht, const uint8_t *key)
{
memcpy(dht->self_public_key, key, CRYPTO_PUBLIC_KEY_SIZE);
}
non_null(1, 2)
void dht_set_self_secret_key(DHT *dht, const uint8_t *key)
{
memcpy(dht->self_secret_key, key, CRYPTO_SECRET_KEY_SIZE);
}
non_null(1)
Networking_Core *dht_get_net(const DHT *dht)
{
return dht->net;
}
non_null(1)
struct Ping *dht_get_ping(const DHT *dht)
{
return dht->ping;
}
non_null(1)
const Client_data *dht_get_close_clientlist(const DHT *dht)
{
return dht->close_clientlist;
}
non_null(1)
const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num)
{
assert(client_num < sizeof(dht->close_clientlist) / sizeof(dht->close_clientlist[0]));
return &dht->close_clientlist[client_num];
}
non_null(1)
uint16_t dht_get_num_friends(const DHT *dht)
{
return dht->num_friends;
}
non_null(1)
DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num)
{
assert(friend_num < dht->num_friends);
return &dht->friends_list[friend_num];
}
non_null(1)
const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num)
{
assert(friend_num < dht->num_friends);
return dht->friends_list[friend_num].public_key;
}
non_null(2)
non_null()
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
{
return (assoc->timestamp + BAD_NODE_TIMEOUT) <= cur_time;
@ -191,7 +178,7 @@ static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
*
* If the ip_port is already IPv4 this function returns a copy of the original ip_port.
*/
non_null(1)
non_null()
static IP_Port ip_port_normalize(const IP_Port *ip_port)
{
IP_Port res = *ip_port;
@ -210,7 +197,6 @@ static IP_Port ip_port_normalize(const IP_Port *ip_port)
* return 1 if pk1 is closer.
* return 2 if pk2 is closer.
*/
non_null(1, 2, 3)
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2)
{
for (size_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) {
@ -231,7 +217,7 @@ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2)
/** Return index of first unequal bit number.
*/
non_null(1, 2)
non_null()
static unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2)
{
unsigned int i;
@ -262,7 +248,6 @@ static unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2)
* If a shared key is already in shared_keys, copy it to shared_key.
* Otherwise generate it into shared_key and copy it to shared_keys
*/
non_null(1, 2, 3, 4, 5)
void get_shared_key(const Mono_Time *mono_time, Shared_Keys *shared_keys, uint8_t *shared_key,
const uint8_t *secret_key, const uint8_t *public_key)
{
@ -311,7 +296,6 @@ void get_shared_key(const Mono_Time *mono_time, Shared_Keys *shared_keys, uint8_
/** Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive.
*/
non_null(1, 2, 3)
void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
{
get_shared_key(dht->mono_time, &dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key);
@ -320,7 +304,6 @@ void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *publi
/** Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send.
*/
non_null(1, 2, 3)
void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
{
get_shared_key(dht->mono_time, &dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key);
@ -338,7 +321,6 @@ void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *publi
* return -1 on failure.
* return the length of the created packet on success.
*/
non_null(1, 2, 3, 4, 5)
int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_key, uint8_t *packet,
const uint8_t *recv_public_key, const uint8_t *data, uint32_t length, uint8_t request_id)
{
@ -377,7 +359,6 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke
*
* return -1 if not valid request.
*/
non_null(1, 2, 3, 4, 5, 6)
int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
uint8_t *request_id, const uint8_t *packet, uint16_t length)
{
@ -438,7 +419,6 @@ int packed_node_size(Family ip_family)
* Returns size of packed IP_Port data on success
* Return -1 on failure.
*/
non_null(1, 3)
int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
{
if (data == nullptr) {
@ -490,7 +470,7 @@ int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
}
}
non_null(1, 2, 4, 6)
non_null()
static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, const uint8_t type,
const uint8_t *plain, size_t plain_length, uint8_t *packet)
@ -521,7 +501,6 @@ static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
* Return size of unpacked ip_port on success.
* Return -1 on failure.
*/
non_null(1, 2)
int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool tcp_enabled)
{
if (data == nullptr) {
@ -589,7 +568,6 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
* return length of packed nodes on success.
* return -1 on failure.
*/
non_null(1, 3)
int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number)
{
uint32_t packed_length = 0;
@ -626,7 +604,6 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
* return number of unpacked nodes on success.
* return -1 on failure.
*/
non_null(1, 4)
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
uint16_t length, bool tcp_enabled)
{
@ -667,7 +644,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
*
* return index or UINT32_MAX if not found.
*/
nullable(1) non_null(3)
non_null(3) nullable(1)
static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, const uint8_t *pk)
{
assert(size == 0 || array != nullptr);
@ -681,7 +658,7 @@ static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, cons
return UINT32_MAX;
}
nullable(1) non_null(3)
non_null(3) nullable(1)
static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const uint8_t *pk)
{
assert(size == 0 || array != nullptr);
@ -695,7 +672,7 @@ static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const
return UINT32_MAX;
}
nullable(1) non_null(3)
non_null(3) nullable(1)
static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const uint8_t *pk)
{
assert(size == 0 || array != nullptr);
@ -713,7 +690,7 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const
*
* return index or UINT32_MAX if not found.
*/
nullable(1) non_null(3)
non_null(3) nullable(1)
static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port)
{
assert(size == 0 || array != nullptr);
@ -730,7 +707,7 @@ static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size,
/** Update ip_port of client if it's needed.
*/
non_null(1, 2, 4, 5)
non_null()
static void update_client(const Logger *log, const Mono_Time *mono_time, int index, Client_data *client,
const IP_Port *ip_port)
{
@ -772,7 +749,7 @@ static void update_client(const Logger *log, const Mono_Time *mono_time, int ind
*
* return True(1) or False(0)
*/
non_null(1, 2, 3, 5, 6)
non_null()
static int client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_time, Client_data *list, uint16_t length,
const uint8_t *public_key, const IP_Port *ip_port)
{
@ -820,7 +797,6 @@ static int client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_ti
return 1;
}
non_null(1, 3, 4, 5)
bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port,
const uint8_t *cmp_pk)
{
@ -846,7 +822,7 @@ bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, co
/**
* helper for get_close_nodes(). argument list is a monster :D
*/
non_null(2, 3, 5, 7)
non_null()
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key, Node_format *nodes_list,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
uint32_t *num_nodes_ptr, bool is_LAN)
@ -905,7 +881,7 @@ static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key,
* TODO(irungentoo): For the love of based <your favorite deity, in doubt use
* "love"> make this function cleaner and much more efficient.
*/
non_null(1, 2, 3)
non_null()
static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list,
Family sa_family, bool is_LAN)
{
@ -922,7 +898,6 @@ static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, N
return num_nodes;
}
non_null(1, 2, 3)
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
bool is_LAN)
{
@ -936,7 +911,7 @@ typedef struct DHT_Cmp_Data {
Client_data entry;
} DHT_Cmp_Data;
non_null(1, 2)
non_null()
static int dht_cmp_entry(const void *a, const void *b)
{
const DHT_Cmp_Data *cmp1 = (const DHT_Cmp_Data *)a;
@ -978,7 +953,7 @@ static int dht_cmp_entry(const void *a, const void *b)
* return 0 if node can't be stored.
* return 1 if it can.
*/
non_null(1, 3, 4)
non_null()
static unsigned int store_node_ok(const Client_data *client, uint64_t cur_time, const uint8_t *public_key,
const uint8_t *comp_public_key)
{
@ -987,7 +962,7 @@ static unsigned int store_node_ok(const Client_data *client, uint64_t cur_time,
|| id_closest(comp_public_key, client->public_key, public_key) == 2;
}
non_null(1, 4)
non_null()
static void sort_client_list(Client_data *list, uint64_t cur_time, unsigned int length,
const uint8_t *comp_public_key)
{
@ -1008,7 +983,7 @@ static void sort_client_list(Client_data *list, uint64_t cur_time, unsigned int
}
}
non_null(1, 2, 3)
non_null()
static void update_client_with_reset(const Mono_Time *mono_time, Client_data *client, const IP_Port *ip_port)
{
IPPTsPng *ipptp_write = nullptr;
@ -1047,7 +1022,7 @@ static void update_client_with_reset(const Mono_Time *mono_time, Client_data *cl
* than public_key.
*
* returns true when the item was stored, false otherwise */
non_null(1, 2, 4, 5, 6)
non_null()
static bool replace_all(const DHT *dht,
Client_data *list,
uint16_t length,
@ -1080,7 +1055,7 @@ static bool replace_all(const DHT *dht,
* return -1 on failure.
* return 0 on success.
*/
non_null(1, 2, 3)
non_null()
static int add_to_close(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port, bool simulate)
{
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@ -1113,13 +1088,12 @@ static int add_to_close(DHT *dht, const uint8_t *public_key, const IP_Port *ip_p
/** Return 1 if node can be added to close list, 0 if it can't.
*/
non_null(1, 2, 3)
bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{
return add_to_close(dht, public_key, ip_port, 1) == 0;
}
non_null(1, 4, 5)
non_null()
static bool is_pk_in_client_list(const Client_data *list, unsigned int client_list_length, uint64_t cur_time,
const uint8_t *public_key, const IP_Port *ip_port)
{
@ -1136,7 +1110,7 @@ static bool is_pk_in_client_list(const Client_data *list, unsigned int client_li
return !assoc_timeout(cur_time, assoc);
}
non_null(1, 2, 3)
non_null()
static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@ -1155,7 +1129,7 @@ static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const
* return false if the node should not be pinged.
* return true if it should.
*/
non_null(1, 2, 3)
non_null()
static bool ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{
bool ret = false;
@ -1221,7 +1195,6 @@ static bool ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, cons
*
* returns 1+ if the item is used in any list, 0 else
*/
non_null(1, 2, 3)
uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key)
{
IP_Port ipp_copy = ip_port_normalize(ip_port);
@ -1273,7 +1246,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
return used;
}
non_null(1, 2, 4, 5)
non_null()
static bool update_client_data(const Mono_Time *mono_time, Client_data *array, size_t size, const IP_Port *ip_port,
const uint8_t *pk, bool node_is_self)
{
@ -1305,7 +1278,7 @@ static bool update_client_data(const Mono_Time *mono_time, Client_data *array, s
/** If public_key is a friend or us, update ret_ip_port
* nodepublic_key is the id of the node that sent us this info.
*/
non_null(1, 2, 3, 4)
non_null()
static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
{
IP_Port ipp_copy = ip_port_normalize(ip_port);
@ -1326,7 +1299,6 @@ static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *pu
}
}
non_null(1, 2, 3, 4)
bool dht_getnodes(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id)
{
/* Check if packet is going to be sent to ourself. */
@ -1378,7 +1350,7 @@ bool dht_getnodes(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, c
}
/** Send a send nodes response: message for IPv6 nodes */
non_null(1, 2, 3, 4, 5, 7)
non_null()
static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id,
const uint8_t *sendback_data, uint16_t length, const uint8_t *shared_encryption_key)
{
@ -1427,7 +1399,7 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
#define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))
non_null(1, 2, 3, 5)
non_null()
static int handle_getnodes(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
if (length != (CRYPTO_SIZE + CRYPTO_MAC_SIZE + sizeof(uint64_t))) {
@ -1467,7 +1439,7 @@ static int handle_getnodes(void *object, const IP_Port *source, const uint8_t *p
}
/** Return true if we sent a getnode packet to the peer associated with the supplied info. */
non_null(1, 2, 3)
non_null()
static bool sent_getnode_to_node(DHT *dht, const uint8_t *public_key, const IP_Port *node_ip_port, uint64_t ping_id)
{
uint8_t data[sizeof(Node_format) * 2];
@ -1489,7 +1461,7 @@ static bool sent_getnode_to_node(DHT *dht, const uint8_t *public_key, const IP_P
return true;
}
non_null(1, 2, 3, 5, 7)
non_null()
static int handle_sendnodes_core(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
{
@ -1560,7 +1532,7 @@ static int handle_sendnodes_core(void *object, const IP_Port *source, const uint
return 0;
}
non_null(1, 2, 3, 5)
non_null()
static int handle_sendnodes_ipv6(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -1589,7 +1561,7 @@ static int handle_sendnodes_ipv6(void *object, const IP_Port *source, const uint
/*----------------------------------------------------------------------------------*/
/*------------------------END of packet handling functions--------------------------*/
nullable(2, 3, 5) non_null(1)
non_null(1) nullable(2, 3, 5)
static void dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback,
void *data, int32_t number, uint16_t *lock_count)
{
@ -1604,7 +1576,6 @@ static void dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback
}
}
nullable(3, 4, 6) non_null(1, 2)
int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
void *data, int32_t number, uint16_t *lock_count)
{
@ -1644,7 +1615,6 @@ int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
return 0;
}
non_null(1, 2)
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
{
const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key);
@ -1687,7 +1657,6 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
}
/* TODO(irungentoo): Optimize this. */
non_null(1, 2, 3)
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
{
ip_reset(&ip_port->ip);
@ -1722,7 +1691,7 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
}
/** returns number of nodes not in kill-timeout */
non_null(1, 2, 3, 4, 6)
non_null()
static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key,
Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
{
@ -1794,7 +1763,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
/** Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
* every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
*/
non_null(1)
non_null()
static void do_dht_friends(DHT *dht)
{
for (size_t i = 0; i < dht->num_friends; ++i) {
@ -1815,7 +1784,7 @@ static void do_dht_friends(DHT *dht)
/** Ping each client in the close nodes list every PING_INTERVAL seconds.
* Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
*/
non_null(1)
non_null()
static void do_Close(DHT *dht)
{
for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
@ -1855,13 +1824,11 @@ static void do_Close(DHT *dht)
}
}
non_null(1, 2, 3)
void dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key)
{
dht_getnodes(dht, ip_port, public_key, dht->self_public_key);
}
non_null(1, 2, 5)
int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
uint16_t port, const uint8_t *public_key)
{
@ -1896,7 +1863,6 @@ int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
*
* return -1 if failure.
*/
non_null(1, 2, 3)
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length)
{
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
@ -1926,7 +1892,7 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* return 0 if we are connected to friend or if no ips were found.
* return -1 if no such friend.
*/
non_null(1, 2)
non_null()
static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
{
if (friend_num >= dht->num_friends) {
@ -2021,7 +1987,7 @@ typedef bool foreach_ip_port_cb(const DHT *dht, const IP_Port *ip_port, uint32_t
* @param callback The callback to invoke for each IP/port.
* @param userdata Extra pointer passed to the callback.
*/
non_null(1, 2, 3, 4)
non_null()
static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
foreach_ip_port_cb *callback, void *userdata)
{
@ -2053,7 +2019,7 @@ static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
return n;
}
non_null(1, 2, 3, 4)
non_null()
static bool send_packet_to_friend(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
{
const Packet *packet = (const Packet *)userdata;
@ -2074,7 +2040,6 @@ static bool send_packet_to_friend(const DHT *dht, const IP_Port *ip_port, uint32
* return ip for friend.
* return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
*/
non_null(1, 2, 3)
uint32_t route_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);
@ -2097,7 +2062,7 @@ uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet
return foreach_ip_port(dht, dht_friend, send_packet_to_friend, &packet_userdata);
}
non_null(1, 2, 3, 4)
non_null()
static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
{
IP_Port *ip_list = (IP_Port *)userdata;
@ -2110,7 +2075,7 @@ static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, voi
*
* return number of nodes the packet was sent to.
*/
non_null(1, 2, 3)
non_null()
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);
@ -2142,7 +2107,7 @@ static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, con
/*----------------------------------------------------------------------------------*/
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/
non_null(1, 2)
non_null()
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];
@ -2177,7 +2142,7 @@ static int send_NATping(const DHT *dht, const uint8_t *public_key, uint64_t ping
}
/** Handle a received ping request for. */
non_null(1, 2, 3, 4, 6)
non_null()
static int handle_NATping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
uint16_t length, void *userdata)
{
@ -2221,7 +2186,7 @@ static int handle_NATping(void *object, const IP_Port *source, const uint8_t *so
*
* return ip of 0 if failure.
*/
non_null(1)
non_null()
static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
{
IP zero;
@ -2254,7 +2219,7 @@ static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_nu
*
* return number of ports and puts the list of ports in portlist.
*/
non_null(1, 2, 4)
non_null()
static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uint16_t len, const IP *ip)
{
uint16_t num = 0;
@ -2269,7 +2234,7 @@ static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uin
return num;
}
non_null(1, 2)
non_null()
static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint16_t numports, uint16_t friend_num)
{
if (!dht->hole_punching_enabled) {
@ -2328,7 +2293,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1
++dht->friends_list[friend_num].nat.tries;
}
non_null(1)
non_null()
static void do_NAT(DHT *dht)
{
const uint64_t temp_time = mono_time_get(dht->mono_time);
@ -2380,7 +2345,7 @@ static void do_NAT(DHT *dht)
*
* return the number of nodes.
*/
non_null(1, 4)
non_null()
static uint16_t list_nodes(const Client_data *list, size_t length, uint64_t cur_time,
Node_format *nodes, uint16_t max_num)
{
@ -2423,7 +2388,6 @@ static uint16_t list_nodes(const Client_data *list, size_t length, uint64_t cur_
*
* return the number of nodes.
*/
non_null(1, 2)
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num)
{
if (max_num == 0) {
@ -2449,7 +2413,6 @@ uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num)
*
* return the number of nodes.
*/
non_null(1, 2)
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);
@ -2457,14 +2420,13 @@ uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num)
/*----------------------------------------------------------------------------------*/
nullable(3, 4) non_null(1)
void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_cb *cb, void *object)
{
dht->cryptopackethandlers[byte].function = cb;
dht->cryptopackethandlers[byte].object = object;
}
non_null(1, 2, 3, 5)
non_null()
static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -2510,7 +2472,6 @@ static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_
/*----------------------------------------------------------------------------------*/
non_null(1, 2, 3)
DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool holepunching_enabled)
{
if (net == nullptr) {
@ -2566,7 +2527,6 @@ DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool
return dht;
}
non_null(1)
void do_dht(DHT *dht)
{
const uint64_t cur_time = mono_time_get(dht->mono_time);
@ -2588,7 +2548,6 @@ void do_dht(DHT *dht)
ping_iterate(dht->ping);
}
non_null(1)
void kill_dht(DHT *dht)
{
networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
@ -2614,7 +2573,6 @@ void kill_dht(DHT *dht)
#define MAX_SAVED_DHT_NODES (((DHT_FAKE_FRIEND_NUMBER * MAX_FRIEND_CLIENTS) + LCLIENT_LIST) * 2)
/** Get the size of the DHT (for saving). */
non_null(1)
uint32_t dht_size(const DHT *dht)
{
uint32_t numv4 = 0;
@ -2646,7 +2604,6 @@ uint32_t dht_size(const DHT *dht)
}
/** Save the DHT in data where data is an array of size dht_size(). */
non_null(1, 2)
void dht_save(const DHT *dht, uint8_t *data)
{
host_to_lendian_bytes32(data, DHT_STATE_COOKIE_GLOBAL);
@ -2717,7 +2674,6 @@ void dht_save(const DHT *dht, uint8_t *data)
* returns 0 if successful
* returns -1 otherwise
*/
non_null(1)
int dht_connect_after_load(DHT *dht)
{
if (dht == nullptr) {
@ -2745,7 +2701,7 @@ int dht_connect_after_load(DHT *dht)
return 0;
}
non_null(1, 2)
non_null()
static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
{
DHT *dht = (DHT *)outer;
@ -2792,7 +2748,6 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
* return -1 if failure.
* return 0 if success.
*/
non_null(1, 2)
int dht_load(DHT *dht, const uint8_t *data, uint32_t length)
{
const uint32_t cookie_len = sizeof(uint32_t);
@ -2813,7 +2768,6 @@ int dht_load(DHT *dht, const uint8_t *data, uint32_t length)
/** return false if we are not connected to the DHT.
* return true if we are.
*/
non_null(1)
bool dht_isconnected(const DHT *dht)
{
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
@ -2831,7 +2785,6 @@ bool dht_isconnected(const DHT *dht)
/** return false if we are not connected or only connected to lan peers with the DHT.
* return true if we are.
*/
non_null(1)
bool dht_non_lan_connected(const DHT *dht)
{
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
@ -2859,7 +2812,6 @@ bool dht_non_lan_connected(const DHT *dht)
* Return 1 if IP is a WAN address.
* Return 2 if IP is a LAN address.
*/
non_null(1, 2)
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest)
{
ipport_reset(dest);

View File

@ -11,6 +11,7 @@
#include <stdbool.h>
#include "attributes.h"
#include "crypto_core.h"
#include "logger.h"
#include "mono_time.h"
@ -68,8 +69,10 @@ extern "C" {
* return -1 on failure.
* return the length of the created packet on success.
*/
int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_key, uint8_t *packet,
const uint8_t *recv_public_key, const uint8_t *data, uint32_t length, uint8_t request_id);
non_null()
int create_request(
const uint8_t *send_public_key, const uint8_t *send_secret_key, uint8_t *packet,
const uint8_t *recv_public_key, const uint8_t *data, uint32_t length, uint8_t request_id);
/** Puts the senders public key in the request in public_key, the data from the request
* in data if a friend or ping request was sent to us and returns the length of the data.
@ -77,8 +80,10 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke
*
* return -1 if not valid request.
*/
int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
uint8_t *request_id, const uint8_t *packet, uint16_t length);
non_null()
int handle_request(
const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
uint8_t *request_id, const uint8_t *packet, uint16_t length);
typedef struct IPPTs {
IP_Port ip_port;
@ -127,8 +132,8 @@ typedef struct Node_format {
typedef struct DHT_Friend DHT_Friend;
const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend);
const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index);
non_null() const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend);
non_null() const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index);
/** Return packet size of packed node with ip_family on success.
* Return -1 on failure.
@ -142,6 +147,7 @@ int packed_node_size(Family ip_family);
* Returns size of packed IP_Port data on success
* Return -1 on failure.
*/
non_null()
int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port);
/** Unpack IP_Port structure from data of max size length into ip_port.
@ -151,6 +157,7 @@ int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port);
* Return size of unpacked ip_port on success.
* Return -1 on failure.
*/
non_null()
int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool tcp_enabled);
/** Pack number of nodes into data of maxlength length.
@ -158,6 +165,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
* return length of packed nodes on success.
* return -1 on failure.
*/
non_null()
int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number);
/** Unpack data of length into nodes of size max_num_nodes.
@ -167,6 +175,7 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
* return number of unpacked nodes on success.
* return -1 on failure.
*/
non_null(1, 4) nullable(3)
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
uint16_t length, bool tcp_enabled);
@ -195,19 +204,19 @@ typedef int cryptopacket_handler_cb(void *object, const IP_Port *ip_port, const
typedef struct DHT DHT;
const uint8_t *dht_get_self_public_key(const DHT *dht);
const uint8_t *dht_get_self_secret_key(const DHT *dht);
void dht_set_self_public_key(DHT *dht, const uint8_t *key);
void dht_set_self_secret_key(DHT *dht, const uint8_t *key);
non_null() const uint8_t *dht_get_self_public_key(const DHT *dht);
non_null() const uint8_t *dht_get_self_secret_key(const DHT *dht);
non_null() void dht_set_self_public_key(DHT *dht, const uint8_t *key);
non_null() void dht_set_self_secret_key(DHT *dht, const uint8_t *key);
Networking_Core *dht_get_net(const DHT *dht);
struct Ping *dht_get_ping(const DHT *dht);
const Client_data *dht_get_close_clientlist(const DHT *dht);
const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num);
uint16_t dht_get_num_friends(const DHT *dht);
non_null() Networking_Core *dht_get_net(const DHT *dht);
non_null() struct Ping *dht_get_ping(const DHT *dht);
non_null() const Client_data *dht_get_close_clientlist(const DHT *dht);
non_null() const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num);
non_null() uint16_t dht_get_num_friends(const DHT *dht);
DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num);
const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
non_null() DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num);
non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
/*----------------------------------------------------------------------------------*/
@ -217,17 +226,21 @@ const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
* If a shared key is already in shared_keys, copy it to shared_key.
* Otherwise generate it into shared_key and copy it to shared_keys
*/
void get_shared_key(const Mono_Time *mono_time, Shared_Keys *shared_keys, uint8_t *shared_key,
const uint8_t *secret_key, const uint8_t *public_key);
non_null()
void get_shared_key(
const Mono_Time *mono_time, Shared_Keys *shared_keys, uint8_t *shared_key,
const uint8_t *secret_key, const uint8_t *public_key);
/** Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive.
*/
non_null()
void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
/** Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send.
*/
non_null()
void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
@ -236,6 +249,7 @@ void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *publi
*
* Return true on success.
*/
non_null()
bool dht_getnodes(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id);
typedef void dht_ip_cb(void *object, int32_t number, const IP_Port *ip_port);
@ -252,6 +266,7 @@ typedef void dht_ip_cb(void *object, int32_t number, const IP_Port *ip_port);
* return 0 if success.
* return -1 if failure (friends list is full).
*/
non_null(1, 2) nullable(3, 4, 6)
int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
void *data, int32_t number, uint16_t *lock_count);
@ -261,6 +276,7 @@ int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
* return 0 if success.
* return -1 if failure (public_key not in friends list).
*/
non_null()
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count);
/** Get ip of friend.
@ -272,6 +288,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count);
* return 0, -- if public_key refers to a friend and we failed to find the friend (yet)
* return 1, ip if public_key refers to a friend and we found him
*/
non_null()
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
/** Compares pk1 and pk2 with pk.
@ -280,6 +297,7 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
* return 1 if pk1 is closer.
* return 2 if pk2 is closer.
*/
non_null()
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
/***
@ -287,11 +305,13 @@ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
*
* @return true iff the node was added to the list.
*/
bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port,
const uint8_t *cmp_pk);
non_null()
bool add_to_list(
Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port, const uint8_t *cmp_pk);
/** Return 1 if node can be added to close list, 0 if it can't.
*/
non_null()
bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port);
/** Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
@ -304,23 +324,27 @@ bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Po
* return the number of nodes returned.
*
*/
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
bool is_LAN);
non_null()
int get_close_nodes(
const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family, bool is_LAN);
/** Put up to max_num nodes in nodes from the random friends.
*
* return the number of nodes.
*/
non_null()
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.
*/
non_null()
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). */
non_null()
void do_dht(DHT *dht);
/*
@ -329,6 +353,7 @@ void do_dht(DHT *dht);
/** Sends a "get nodes" request to the given node with ip, port and public_key
* to setup connections
*/
non_null()
void dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
/** Resolves address into an IP address. If successful, sends a "get nodes"
@ -342,6 +367,7 @@ void dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
* returns 1 if the address could be converted into an IP address
* returns 0 otherwise
*/
non_null()
int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
uint16_t port, const uint8_t *public_key);
@ -350,6 +376,7 @@ int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
* returns 0 if successful
* returns -1 otherwise
*/
non_null()
int dht_connect_after_load(DHT *dht);
/* ROUTING FUNCTIONS */
@ -358,6 +385,7 @@ int dht_connect_after_load(DHT *dht);
*
* return -1 if failure.
*/
non_null()
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length);
/**
@ -366,18 +394,22 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* return ip for friend.
* return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
*/
non_null()
uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet);
/** Function to handle crypto packets.
*/
non_null(1) nullable(3, 4)
void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_cb *cb, void *object);
/* SAVE/LOAD functions */
/** Get the size of the DHT (for saving). */
non_null()
uint32_t dht_size(const DHT *dht);
/** Save the DHT in data where data is an array of size dht_size(). */
non_null()
void dht_save(const DHT *dht, uint8_t *data);
/** Load the DHT from data of size size.
@ -385,24 +417,30 @@ void dht_save(const DHT *dht, uint8_t *data);
* return -1 if failure.
* return 0 if success.
*/
non_null()
int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
/** Initialize DHT. */
non_null()
DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool holepunching_enabled);
non_null()
void kill_dht(DHT *dht);
/** return false if we are not connected to the DHT.
* return true if we are.
*/
non_null()
bool dht_isconnected(const DHT *dht);
/** return false if we are not connected or only connected to lan peers with the DHT.
* return true if we are.
*/
non_null()
bool dht_non_lan_connected(const DHT *dht);
non_null()
uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
/** Copies our own ip_port structure to `dest`. WAN addresses take priority over LAN addresses.
@ -413,6 +451,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
* Return 1 if IP is a WAN address.
* Return 2 if IP is a LAN address.
*/
non_null()
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest);
#ifdef __cplusplus

View File

@ -205,6 +205,7 @@ static Broadcast_Info *fetch_broadcast_info(uint16_t port)
* @retval true if sent to at least one broadcast target.
* @retval false on failure to find any valid broadcast target.
*/
non_null()
static bool send_broadcasts(const Networking_Core *net, const Broadcast_Info *broadcast, uint16_t port,
const uint8_t *data, uint16_t length)
{
@ -246,6 +247,7 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
return ip;
}
non_null()
static bool ip4_is_local(const IP4 *ip4)
{
/* Loopback. */
@ -276,6 +278,7 @@ bool ip_is_local(const IP *ip)
return false;
}
non_null()
static bool ip4_is_lan(const IP4 *ip4)
{
/* 10.0.0.0 to 10.255.255.255 range. */
@ -337,6 +340,7 @@ bool ip_is_lan(const IP *ip)
return false;
}
non_null(1, 2, 3) nullable(5)
static int handle_LANdiscovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -355,7 +359,7 @@ static int handle_LANdiscovery(void *object, const IP_Port *source, const uint8_
}
bool lan_discovery_send(Networking_Core *net, Broadcast_Info *broadcast, const uint8_t *dht_pk, uint16_t port)
bool lan_discovery_send(Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk, uint16_t port)
{
if (broadcast == nullptr) {
return false;

View File

@ -23,21 +23,25 @@ typedef struct Broadcast_Info Broadcast_Info;
*
* @return true on success, false on failure.
*/
bool lan_discovery_send(Networking_Core *net, Broadcast_Info *broadcast, const uint8_t *dht_pk, uint16_t port);
non_null()
bool lan_discovery_send(Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk, uint16_t port);
/**
* Sets up packet handlers.
*/
non_null()
Broadcast_Info *lan_discovery_init(DHT *dht);
/**
* Clear packet handlers.
*/
non_null()
void lan_discovery_kill(DHT *dht, Broadcast_Info *info);
/**
* Is IP a local ip or not.
*/
non_null()
bool ip_is_local(const IP *ip);
/**
@ -45,6 +49,7 @@ bool ip_is_local(const IP *ip);
*
* @return true if ip is a LAN ip, false if it is not.
*/
non_null()
bool ip_is_lan(const IP *ip);
#endif // C_TOXCORE_TOXCORE_LAN_DISCOVERY_H

View File

@ -5,7 +5,9 @@ libtoxcore_la_include_HEADERS = \
libtoxcore_la_includedir = $(includedir)/tox
libtoxcore_la_SOURCES = ../toxcore/ccompat.h \
libtoxcore_la_SOURCES = ../toxcore/attributes.h \
../toxcore/ccompat.c \
../toxcore/ccompat.h \
../toxcore/events/conference_connected.c \
../toxcore/events/conference_invite.c \
../toxcore/events/conference_message.c \

View File

@ -23,15 +23,12 @@
static_assert(MAX_CONCURRENT_FILE_PIPES <= UINT8_MAX + 1,
"uint8_t cannot represent all file transfer numbers");
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, uint8_t congestion_control);
static void m_register_default_plugins(Messenger *m);
/**
* Determines if the friendnumber passed is valid in the Messenger object.
*
* @param friendnumber The index in the friend list.
*/
non_null()
static bool friend_is_valid(const Messenger *m, int32_t friendnumber)
{
return (unsigned int)friendnumber < m->numfriends && m->friendlist[friendnumber].status != 0;
@ -41,6 +38,7 @@ static bool friend_is_valid(const Messenger *m, int32_t friendnumber)
*
* return -1 if realloc fails.
*/
non_null()
static int realloc_friendlist(Messenger *m, uint32_t num)
{
if (num == 0) {
@ -106,6 +104,7 @@ int getfriendcon_id(const Messenger *m, int32_t friendnumber)
/**
* return a uint16_t that represents the checksum of address of length len.
*/
non_null()
static uint16_t address_checksum(const uint8_t *address, uint32_t len)
{
uint8_t checksum[2] = {0};
@ -132,6 +131,7 @@ void getaddress(const Messenger *m, uint8_t *address)
memcpy(address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(nospam), &checksum, sizeof(checksum));
}
non_null()
static int send_online_packet(Messenger *m, int32_t friendnumber)
{
if (!friend_is_valid(m, friendnumber)) {
@ -143,6 +143,7 @@ static int send_online_packet(Messenger *m, int32_t friendnumber)
m->friendlist[friendnumber].friendcon_id), &packet, sizeof(packet), 0) != -1;
}
non_null()
static int send_offline_packet(Messenger *m, int friendcon_id)
{
uint8_t packet = PACKET_ID_OFFLINE;
@ -150,11 +151,15 @@ static int send_offline_packet(Messenger *m, int friendcon_id)
sizeof(packet), 0) != -1;
}
non_null(1) nullable(4)
static int m_handle_status(void *object, int i, uint8_t status, void *userdata);
non_null(1, 3) nullable(5)
static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata);
non_null(1, 3) nullable(5)
static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
void *userdata);
non_null()
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
{
if (m->numfriends == UINT32_MAX) {
@ -303,6 +308,7 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
return init_new_friend(m, real_pk, FRIEND_CONFIRMED);
}
non_null()
static int clear_receipts(Messenger *m, int32_t friendnumber)
{
if (!friend_is_valid(m, friendnumber)) {
@ -322,6 +328,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
return 0;
}
non_null()
static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
{
if (!friend_is_valid(m, friendnumber)) {
@ -351,6 +358,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
* return -1 on failure.
* return 0 if packet was received.
*/
non_null()
static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number)
{
if (!friend_is_valid(m, friendnumber)) {
@ -361,6 +369,7 @@ static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint
m->friendlist[friendnumber].friendcon_id), number);
}
non_null(1) nullable(3)
static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
{
if (!friend_is_valid(m, friendnumber)) {
@ -541,9 +550,33 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
return 0;
}
non_null()
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, uint8_t congestion_control)
{
if (!friend_is_valid(m, friendnumber)) {
return 0;
}
if (length >= MAX_CRYPTO_DATA_SIZE || m->friendlist[friendnumber].status != FRIEND_ONLINE) {
return 0;
}
VLA(uint8_t, packet, length + 1);
packet[0] = packet_id;
if (length != 0) {
memcpy(packet + 1, data, length);
}
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
m->friendlist[friendnumber].friendcon_id), packet, length + 1, congestion_control) != -1;
}
/** Send a name packet to friendnumber.
* length is the length with the NULL terminator.
*/
non_null()
static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
{
if (length > MAX_NAME_LENGTH) {
@ -807,22 +840,26 @@ int m_get_istyping(const Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].is_typing;
}
non_null()
static int send_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, 0);
}
non_null()
static int send_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), 0);
}
non_null()
static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
{
uint8_t typing = is_typing;
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), 0);
}
non_null()
static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{
if (!friend_is_valid(m, friendnumber)) {
@ -841,11 +878,13 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
return 0;
}
non_null()
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{
m->friendlist[friendnumber].userstatus = (Userstatus)status;
}
non_null()
static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
{
m->friendlist[friendnumber].is_typing = is_typing;
@ -908,6 +947,7 @@ void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionst
m->friend_connectionstatuschange_internal_userdata = userdata;
}
non_null(1) nullable(3)
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
{
int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
@ -927,7 +967,10 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userd
m->friendlist[friendnumber].last_connection_udp_tcp = (Connection_Status)ret;
}
non_null()
static void break_files(const Messenger *m, int32_t friendnumber);
non_null(1) nullable(4)
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
{
if (status == NOFRIEND) {
@ -959,34 +1002,13 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
}
}
non_null(1) nullable(4)
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
{
check_friend_connectionstatus(m, friendnumber, status, userdata);
m->friendlist[friendnumber].status = status;
}
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, uint8_t congestion_control)
{
if (!friend_is_valid(m, friendnumber)) {
return 0;
}
if (length >= MAX_CRYPTO_DATA_SIZE || m->friendlist[friendnumber].status != FRIEND_ONLINE) {
return 0;
}
VLA(uint8_t, packet, length + 1);
packet[0] = packet_id;
if (length != 0) {
memcpy(packet + 1, data, length);
}
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
m->friendlist[friendnumber].friendcon_id), packet, length + 1, congestion_control) != -1;
}
/*** CONFERENCES */
@ -1096,6 +1118,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* return 1 on success
* return 0 on failure
*/
non_null()
static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type,
uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
{
@ -1174,9 +1197,12 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
return i;
}
non_null(1) nullable(6)
static int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber,
uint8_t control_type, const uint8_t *data, uint16_t data_length)
{
assert(data_length == 0 || data != nullptr);
if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
return -1;
}
@ -1364,9 +1390,12 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
/** return packet number on success.
* return -1 on failure.
*/
non_null(1) nullable(4)
static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data,
uint16_t length)
{
assert(length == 0 || data != nullptr);
if (!friend_is_valid(m, friendnumber)) {
return -1;
}
@ -1399,6 +1428,8 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
uint16_t length)
{
assert(length == 0 || data != nullptr);
if (!friend_is_valid(m, friendnumber)) {
return -1;
}
@ -1471,6 +1502,7 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
* @return true if there's still work to do, false otherwise.
*
*/
non_null()
static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userdata, uint32_t *free_slots)
{
Friend *const friendcon = &m->friendlist[friendnumber];
@ -1539,6 +1571,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
return true;
}
non_null(1) nullable(3)
static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdata)
{
// We're not currently doing any file transfers.
@ -1595,6 +1628,7 @@ static void break_files(const Messenger *m, int32_t friendnumber)
}
}
non_null()
static struct File_Transfers *get_file_transfer(uint8_t receive_send, uint8_t filenumber,
uint32_t *real_filenumber, Friend *sender)
{
@ -1617,6 +1651,7 @@ static struct File_Transfers *get_file_transfer(uint8_t receive_send, uint8_t fi
/** return -1 on failure, 0 on success.
*/
non_null(1, 6) nullable(8)
static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
{
@ -1837,6 +1872,7 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
return 0;
}
non_null(1, 3) nullable(5)
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -1890,6 +1926,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
}
/** Function to filter out some friend requests*/
non_null()
static int friend_already_added(const uint8_t *real_pk, void *data)
{
const Messenger *m = (const Messenger *)data;
@ -1901,193 +1938,12 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
return -1;
}
/** Run this at startup.
* return allocated instance of Messenger on success.
* return 0 if there are problems.
*
* if error is not NULL it will be set to one of the values in the enum above.
*/
Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsigned int *error)
{
if (!options) {
return nullptr;
}
if (error) {
*error = MESSENGER_ERROR_OTHER;
}
Messenger *m = (Messenger *)calloc(1, sizeof(Messenger));
if (!m) {
return nullptr;
}
m->mono_time = mono_time;
m->fr = friendreq_new();
if (!m->fr) {
free(m);
return nullptr;
}
m->log = logger_new();
if (m->log == nullptr) {
friendreq_kill(m->fr);
free(m);
return nullptr;
}
logger_callback_log(m->log, options->log_callback, options->log_context, options->log_user_data);
unsigned int net_err = 0;
if (!options->udp_disabled && options->proxy_info.proxy_type != TCP_PROXY_NONE) {
// We don't currently support UDP over proxy.
LOGGER_WARNING(m->log, "UDP enabled and proxy set: disabling UDP");
options->udp_disabled = true;
}
if (options->udp_disabled) {
m->net = new_networking_no_udp(m->log);
} else {
IP ip;
ip_init(&ip, options->ipv6enabled);
m->net = new_networking_ex(m->log, &ip, options->port_range[0], options->port_range[1], &net_err);
}
if (m->net == nullptr) {
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
if (error && net_err == 1) {
*error = MESSENGER_ERROR_PORT;
}
return nullptr;
}
m->dht = new_dht(m->log, m->mono_time, m->net, options->hole_punching_enabled);
if (m->dht == nullptr) {
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info);
if (m->net_crypto == nullptr) {
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
m->onion = new_onion(m->log, m->mono_time, m->dht);
m->onion_a = new_onion_announce(m->log, m->mono_time, m->dht);
m->onion_c = new_onion_client(m->log, m->mono_time, m->net_crypto);
m->fr_c = new_friend_connections(m->log, m->mono_time, m->onion_c, options->local_discovery_enabled);
if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
if (options->tcp_server_port) {
m->tcp_server = new_TCP_server(m->log, options->ipv6enabled, 1, &options->tcp_server_port,
dht_get_self_secret_key(m->dht), m->onion);
if (m->tcp_server == nullptr) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
if (error) {
*error = MESSENGER_ERROR_TCP_SERVER;
}
return nullptr;
}
}
m->options = *options;
friendreq_init(m->fr, m->fr_c);
set_nospam(m->fr, random_u32());
set_filter_function(m->fr, &friend_already_added, m);
m->lastdump = 0;
m_register_default_plugins(m);
if (error) {
*error = MESSENGER_ERROR_NONE;
}
return m;
}
/** Run this before closing shop
* Free all datastructures.
*/
void kill_messenger(Messenger *m)
{
if (!m) {
return;
}
if (m->tcp_server) {
kill_TCP_server(m->tcp_server);
}
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
for (uint32_t i = 0; i < m->numfriends; ++i) {
clear_receipts(m, i);
}
logger_kill(m->log);
free(m->friendlist);
friendreq_kill(m->fr);
free(m->options.state_plugins);
free(m);
}
/** Check for and handle a timed-out friend request. If the request has
* timed-out then the friend status is set back to FRIEND_ADDED.
* i: friendlist index of the timed-out friend
* t: time
*/
non_null(1) nullable(4)
static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t, void *userdata)
{
Friend *f = &m->friendlist[i];
@ -2428,6 +2284,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
return 0;
}
non_null(1) nullable(2)
static void do_friends(Messenger *m, void *userdata)
{
uint64_t temp_time = mono_time_get(m->mono_time);
@ -2488,6 +2345,7 @@ static void do_friends(Messenger *m, void *userdata)
}
}
non_null(1) nullable(2)
static void connection_status_callback(Messenger *m, void *userdata)
{
unsigned int conn_status = onion_connection_status(m->onion_c);
@ -2506,6 +2364,7 @@ static void connection_status_callback(Messenger *m, void *userdata)
#define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1)
/** id_str should be of length at least IDSTRING_LEN */
non_null()
static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
{
if (length < IDSTRING_LEN) {
@ -2730,6 +2589,7 @@ static uint32_t friend_size(void)
return data;
}
non_null()
static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
{
#define VALUE_MEMBER(name) do { \
@ -2765,6 +2625,7 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
}
non_null()
static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
{
#define VALUE_MEMBER(name) do { \
@ -2800,6 +2661,7 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data
}
non_null()
static uint32_t m_state_plugins_size(const Messenger *m)
{
const uint32_t size32 = sizeof(uint32_t);
@ -2844,6 +2706,7 @@ bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb *siz
return true;
}
non_null()
static uint32_t m_plugin_size(const Messenger *m, State_Type type)
{
for (uint8_t i = 0; i < m->options.state_plugins_length; ++i) {
@ -2877,11 +2740,13 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data)
}
// nospam state plugin
non_null()
static uint32_t nospam_keys_size(const Messenger *m)
{
return sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
}
non_null()
static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length != m_plugin_size(m, STATE_TYPE_NOSPAMKEYS)) {
@ -2900,6 +2765,7 @@ static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uin
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS);
@ -2913,11 +2779,13 @@ static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
}
// DHT state plugin
non_null()
static uint32_t m_dht_size(const Messenger *m)
{
return dht_size(m->dht);
}
non_null()
static uint8_t *save_dht(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_DHT);
@ -2927,6 +2795,7 @@ static uint8_t *save_dht(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status m_dht_load(Messenger *m, const uint8_t *data, uint32_t length)
{
dht_load(m->dht, data, length); // TODO(endoffile78): Should we throw an error if dht_load fails?
@ -2934,11 +2803,13 @@ static State_Load_Status m_dht_load(Messenger *m, const uint8_t *data, uint32_t
}
// friendlist state plugin
non_null()
static uint32_t saved_friendslist_size(const Messenger *m)
{
return count_friendlist(m) * friend_size();
}
non_null()
static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_FRIENDS);
@ -2989,6 +2860,7 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
{
const uint32_t l_friend_size = friend_size();
@ -3033,11 +2905,13 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui
}
// name state plugin
non_null()
static uint32_t name_size(const Messenger *m)
{
return m->name_length;
}
non_null()
static uint8_t *save_name(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_NAME);
@ -3047,6 +2921,7 @@ static uint8_t *save_name(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length > 0 && length <= MAX_NAME_LENGTH) {
@ -3057,11 +2932,13 @@ static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t l
}
// status message state plugin
non_null()
static uint32_t status_message_size(const Messenger *m)
{
return m->statusmessage_length;
}
non_null()
static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUSMESSAGE);
@ -3071,6 +2948,7 @@ static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_status_message(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length > 0 && length <= MAX_STATUSMESSAGE_LENGTH) {
@ -3081,11 +2959,13 @@ static State_Load_Status load_status_message(Messenger *m, const uint8_t *data,
}
// status state plugin
non_null()
static uint32_t status_size(const Messenger *m)
{
return 1;
}
non_null()
static uint8_t *save_status(const Messenger *m, uint8_t *data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUS);
@ -3095,6 +2975,7 @@ static uint8_t *save_status(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length == 1) {
@ -3105,11 +2986,13 @@ static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t
}
// TCP Relay state plugin
non_null()
static uint32_t tcp_relay_size(const Messenger *m)
{
return NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6);
}
non_null()
static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
{
Node_format relays[NUM_SAVED_TCP_RELAYS] = {0};
@ -3134,6 +3017,7 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length != 0) {
@ -3152,11 +3036,13 @@ static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint
}
// path node state plugin
non_null()
static uint32_t path_node_size(const Messenger *m)
{
return NUM_SAVED_PATH_NODES * packed_node_size(net_family_tcp_ipv6);
}
non_null()
static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
{
Node_format nodes[NUM_SAVED_PATH_NODES];
@ -3175,6 +3061,7 @@ static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint32_t length)
{
Node_format nodes[NUM_SAVED_PATH_NODES];
@ -3194,6 +3081,7 @@ static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static void m_register_default_plugins(Messenger *m)
{
m_register_state_plugin(m, STATE_TYPE_NOSPAMKEYS, nospam_keys_size, load_nospam_keys, save_nospam_keys);
@ -3268,3 +3156,185 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s
return ret;
}
/** Run this at startup.
* return allocated instance of Messenger on success.
* return 0 if there are problems.
*
* if error is not NULL it will be set to one of the values in the enum above.
*/
Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsigned int *error)
{
if (!options) {
return nullptr;
}
if (error) {
*error = MESSENGER_ERROR_OTHER;
}
Messenger *m = (Messenger *)calloc(1, sizeof(Messenger));
if (!m) {
return nullptr;
}
m->mono_time = mono_time;
m->fr = friendreq_new();
if (!m->fr) {
free(m);
return nullptr;
}
m->log = logger_new();
if (m->log == nullptr) {
friendreq_kill(m->fr);
free(m);
return nullptr;
}
logger_callback_log(m->log, options->log_callback, options->log_context, options->log_user_data);
unsigned int net_err = 0;
if (!options->udp_disabled && options->proxy_info.proxy_type != TCP_PROXY_NONE) {
// We don't currently support UDP over proxy.
LOGGER_WARNING(m->log, "UDP enabled and proxy set: disabling UDP");
options->udp_disabled = true;
}
if (options->udp_disabled) {
m->net = new_networking_no_udp(m->log);
} else {
IP ip;
ip_init(&ip, options->ipv6enabled);
m->net = new_networking_ex(m->log, &ip, options->port_range[0], options->port_range[1], &net_err);
}
if (m->net == nullptr) {
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
if (error && net_err == 1) {
*error = MESSENGER_ERROR_PORT;
}
return nullptr;
}
m->dht = new_dht(m->log, m->mono_time, m->net, options->hole_punching_enabled);
if (m->dht == nullptr) {
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info);
if (m->net_crypto == nullptr) {
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
m->onion = new_onion(m->log, m->mono_time, m->dht);
m->onion_a = new_onion_announce(m->log, m->mono_time, m->dht);
m->onion_c = new_onion_client(m->log, m->mono_time, m->net_crypto);
m->fr_c = new_friend_connections(m->log, m->mono_time, m->onion_c, options->local_discovery_enabled);
if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
return nullptr;
}
if (options->tcp_server_port) {
m->tcp_server = new_TCP_server(m->log, options->ipv6enabled, 1, &options->tcp_server_port,
dht_get_self_secret_key(m->dht), m->onion);
if (m->tcp_server == nullptr) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
if (error) {
*error = MESSENGER_ERROR_TCP_SERVER;
}
return nullptr;
}
}
m->options = *options;
friendreq_init(m->fr, m->fr_c);
set_nospam(m->fr, random_u32());
set_filter_function(m->fr, &friend_already_added, m);
m->lastdump = 0;
m_register_default_plugins(m);
if (error) {
*error = MESSENGER_ERROR_NONE;
}
return m;
}
/** Run this before closing shop
* Free all datastructures.
*/
void kill_messenger(Messenger *m)
{
if (!m) {
return;
}
if (m->tcp_server) {
kill_TCP_server(m->tcp_server);
}
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_dht(m->dht);
kill_networking(m->net);
for (uint32_t i = 0; i < m->numfriends; ++i) {
clear_receipts(m, i);
}
logger_kill(m->log);
free(m->friendlist);
friendreq_kill(m->fr);
free(m->options.state_plugins);
free(m);
}

View File

@ -299,6 +299,7 @@ struct Messenger {
*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
*/
non_null()
void getaddress(const Messenger *m, uint8_t *address);
/**
@ -322,6 +323,7 @@ void getaddress(const Messenger *m, uint8_t *address);
* (the nospam for that friend was set to the new one).
* return FAERR_NOMEM if increasing the friend list size fails.
*/
non_null()
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
@ -332,11 +334,13 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
* return -6 if bad checksum in address.
* return -8 if increasing the friend list size fails.
*/
non_null()
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);
/** return the friend number associated to that public key.
* return -1 if no such friend.
*/
non_null()
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
/** Copies the public key associated to that friend id into real_pk buffer.
@ -345,11 +349,13 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
* return 0 if success.
* return -1 if failure.
*/
non_null()
int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk);
/** return friend connection id on success.
* return -1 if failure.
*/
non_null()
int getfriendcon_id(const Messenger *m, int32_t friendnumber);
/** Remove a friend.
@ -357,6 +363,7 @@ int getfriendcon_id(const Messenger *m, int32_t friendnumber);
* return 0 if success.
* return -1 if failure.
*/
non_null()
int m_delfriend(Messenger *m, int32_t friendnumber);
/** Checks friend's connection status.
@ -366,6 +373,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber);
* return CONNECTION_NONE (0) if friend is not connected to us (Offline).
* return -1 on failure.
*/
non_null()
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
/** Checks if there exists a friend with given friendnumber.
@ -373,6 +381,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
non_null()
int m_friend_exists(const Messenger *m, int32_t friendnumber);
/** Send a message of type to an online friend.
@ -386,6 +395,7 @@ int m_friend_exists(const Messenger *m, int32_t friendnumber);
*
* the value in message_id will be passed to your read_receipt callback when the other receives the message.
*/
non_null(1, 4) nullable(6)
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length,
uint32_t *message_id);
@ -398,6 +408,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
* return 0 if success.
* return -1 if failure.
*/
non_null()
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
/** Set our nickname.
@ -408,6 +419,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint1
* return 0 if success.
* return -1 if failure.
*/
non_null()
int setname(Messenger *m, const uint8_t *name, uint16_t length);
/**
@ -418,6 +430,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length);
* return length of the name.
* return 0 on error.
*/
non_null()
uint16_t getself_name(const Messenger *m, uint8_t *name);
/** Get name of friendnumber and put it in name.
@ -426,13 +439,14 @@ uint16_t getself_name(const Messenger *m, uint8_t *name);
* return length of name if success.
* return -1 if failure.
*/
non_null()
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name);
/** return the length of name, including null on success.
* return -1 on failure.
*/
int m_get_name_size(const Messenger *m, int32_t friendnumber);
int m_get_self_name_size(const Messenger *m);
non_null() int m_get_name_size(const Messenger *m, int32_t friendnumber);
non_null() int m_get_self_name_size(const Messenger *m);
/** Set our user status.
* You are responsible for freeing status after.
@ -440,8 +454,8 @@ int m_get_self_name_size(const Messenger *m);
* returns 0 on success.
* returns -1 on failure.
*/
int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
int m_set_userstatus(Messenger *m, uint8_t status);
non_null() int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
non_null() int m_set_userstatus(Messenger *m, uint8_t status);
/**
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
@ -449,8 +463,8 @@ int m_set_userstatus(Messenger *m, uint8_t status);
* returns the length of friendnumber's status message, including null on success.
* returns -1 on failure.
*/
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
int m_get_self_statusmessage_size(const Messenger *m);
non_null() int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
non_null() int m_get_self_statusmessage_size(const Messenger *m);
/** Copy friendnumber's status message into buf, truncating if size is over maxlen.
* Get the size you need to allocate from m_get_statusmessage_size.
@ -459,22 +473,22 @@ int m_get_self_statusmessage_size(const Messenger *m);
* returns the length of the copied data on success
* returns -1 on failure.
*/
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
non_null() int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
/** return one of Userstatus values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own Userstatus.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
uint8_t m_get_self_userstatus(const Messenger *m);
non_null() uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
non_null() uint8_t m_get_self_userstatus(const Messenger *m);
/** returns timestamp of last time friendnumber was seen online or 0 if never seen.
* if friendnumber is invalid this function will return UINT64_MAX.
*/
uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
non_null() uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
/** Set our typing status for a friend.
* You are responsible for turning it on or off.
@ -482,6 +496,7 @@ uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
* returns 0 on success.
* returns -1 on failure.
*/
non_null()
int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
/** Get the typing status of a friend.
@ -489,32 +504,34 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
* returns 0 if friend is not typing.
* returns 1 if friend is typing.
*/
non_null()
int m_get_istyping(const Messenger *m, int32_t friendnumber);
/** Set the function that will be executed when a friend request is received. */
non_null(1) nullable(2)
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);
/** Set the function that will be executed when a message from a friend is received. */
void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function);
non_null() void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function);
/** Set the callback for name changes.
* You are not responsible for freeing newname.
*/
void m_callback_namechange(Messenger *m, m_friend_name_cb *function);
non_null() void m_callback_namechange(Messenger *m, m_friend_name_cb *function);
/** Set the callback for status message changes.
*
* You are not responsible for freeing newstatus
*/
void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function);
non_null() void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function);
/** Set the callback for status type changes.
*/
void m_callback_userstatus(Messenger *m, m_friend_status_cb *function);
non_null() void m_callback_userstatus(Messenger *m, m_friend_status_cb *function);
/** Set the callback for typing changes.
*/
void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
non_null() void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
/** Set the callback for read receipts.
*
@ -524,7 +541,7 @@ void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
* Since core doesn't track ids for you, receipt may not correspond to any message.
* In that case, you should discard it.
*/
void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);
non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);
/** Set the callback for connection status changes.
*
@ -536,21 +553,22 @@ void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);
* "after being previously online" part.
* It's assumed that when adding friends, their connection status is offline.
*/
void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function);
non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function);
/** Same as previous but for internal A/V core usage only */
void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function,
void *userdata);
non_null() void m_callback_connectionstatus_internal_av(
Messenger *m, m_friend_connectionstatuschange_internal_cb *function, void *userdata);
/** Set the callback for typing changes.
*/
void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);
non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);
/*** CONFERENCES */
/** Set the callback for conference invites.
*/
non_null(1) nullable(2)
void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function);
/** Send a conference invite packet.
@ -558,6 +576,7 @@ void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function
* return 1 on success
* return 0 on failure
*/
non_null()
int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
/*** FILE SENDING */
@ -565,20 +584,20 @@ int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, cons
/** Set the callback for file send requests.
*/
void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function);
non_null() void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function);
/** Set the callback for file control requests.
*/
void callback_file_control(Messenger *m, m_file_recv_control_cb *function);
non_null() void callback_file_control(Messenger *m, m_file_recv_control_cb *function);
/** Set the callback for file data.
*/
void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function);
non_null() void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function);
/** Set the callback for file request chunk.
*/
void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function);
non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function);
/** Copy the file transfer file id to file_id
@ -587,6 +606,7 @@ void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function);
* return -1 if friend not valid.
* return -2 if filenumber not valid
*/
non_null()
int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id);
/** Send a file send request.
@ -598,6 +618,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* return -4 if could not send packet (friend offline).
*
*/
non_null()
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
@ -613,6 +634,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
* return -7 if resume file failed because it wasn't paused.
* return -8 if packet failed to send.
*/
non_null()
int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
/** Send a seek file control request.
@ -626,6 +648,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
* return -6 if position bad.
* return -8 if packet failed to send.
*/
non_null()
int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
/** Send file data.
@ -639,6 +662,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
* return -6 if packet queue full.
* return -7 if wrong position.
*/
non_null(1) nullable(5)
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
uint16_t length);
@ -646,6 +670,7 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
/** Set the callback for msi packets.
*/
non_null(1) nullable(2, 3)
void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata);
/** Send an msi packet.
@ -653,6 +678,7 @@ void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userda
* return 1 on success
* return 0 on failure
*/
non_null()
int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
/** Set handlers for lossy rtp packets.
@ -660,6 +686,7 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
* return -1 on failure.
* return 0 on success.
*/
non_null(1) nullable(4, 5)
int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte,
m_lossy_rtp_packet_cb *function, void *object);
@ -668,7 +695,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte,
/** Set handlers for custom lossy packets.
*
*/
void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler);
non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler);
/** High level function to send custom lossy packets.
*
@ -686,12 +713,14 @@ void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
non_null()
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/** Set handlers for custom lossless packets.
*
*/
non_null()
void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler);
/** High level function to send custom lossless packets.
@ -703,6 +732,7 @@ void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_pack
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
non_null()
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/*** Messenger constructor/destructor/operations. */
@ -720,14 +750,17 @@ typedef enum Messenger_Error {
*
* if error is not NULL it will be set to one of the values in the enum above.
*/
non_null()
Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsigned int *error);
/** Run this before closing shop
* Free all datastructures.
*/
non_null()
void kill_messenger(Messenger *m);
/** The main loop that needs to be run at least 20 times per second. */
non_null(1) nullable(2)
void do_messenger(Messenger *m, void *userdata);
/** Return the time in milliseconds before do_messenger() should be called again
@ -735,6 +768,7 @@ void do_messenger(Messenger *m, void *userdata);
*
* returns time (in ms) before the next do_messenger() needs to be run on success.
*/
non_null()
uint32_t messenger_run_interval(const Messenger *m);
/* SAVING AND LOADING FUNCTIONS: */
@ -744,13 +778,18 @@ uint32_t messenger_run_interval(const Messenger *m);
* returns true on success
* returns false on error
*/
bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb *size_callback,
m_state_load_cb *load_callback, m_state_save_cb *save_callback);
non_null()
bool m_register_state_plugin(Messenger *m, State_Type type,
m_state_size_cb *size_callback,
m_state_load_cb *load_callback,
m_state_save_cb *save_callback);
/** return size of the messenger data (for saving). */
non_null()
uint32_t messenger_size(const Messenger *m);
/** Save the messenger in data (must be allocated memory of size at least Messenger_size()) */
non_null()
uint8_t *messenger_save(const Messenger *m, uint8_t *data);
/** Load a state section.
@ -761,12 +800,14 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data);
* @param status Result of loading section is stored here if the section is handled.
* @return true iff section handled.
*/
non_null()
bool messenger_load_state_section(Messenger *m, const uint8_t *data, uint32_t length, uint16_t type,
State_Load_Status *status);
/** Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
non_null()
uint32_t count_friendlist(const Messenger *m);
/** Copy a list of valid friend IDs into the array out_list.
@ -774,6 +815,7 @@ uint32_t count_friendlist(const Messenger *m);
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
non_null()
uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size);
#endif

View File

@ -95,6 +95,7 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
/** return 1 on success
* return 0 on failure
*/
non_null()
static int connect_sock_to(const Logger *logger, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info)
{
IP_Port ipp_copy = *ip_port;
@ -112,6 +113,7 @@ static int connect_sock_to(const Logger *logger, Socket sock, const IP_Port *ip_
/** return 1 on success.
* return 0 on failure.
*/
non_null()
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
{
char one[] = "CONNECT ";
@ -142,6 +144,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).
*/
non_null()
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{
char success[] = "200";
@ -179,6 +182,7 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C
#define TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV4 0x01
#define TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 0x04
non_null()
static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
{
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
@ -193,6 +197,7 @@ static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
non_null()
static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{
uint8_t data[2];
@ -209,6 +214,7 @@ static int socks5_read_handshake_response(const Logger *logger, const TCP_Client
return -1;
}
non_null()
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_conn)
{
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
@ -239,6 +245,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
non_null()
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)) {
@ -271,6 +278,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP
/** return 0 on success.
* return -1 on failure.
*/
non_null()
static int generate_handshake(TCP_Client_Connection *tcp_conn)
{
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
@ -296,6 +304,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn)
* return 0 on success.
* return -1 on failure.
*/
non_null()
static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data)
{
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
@ -336,8 +345,8 @@ void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *s
con->status_callback_object = object;
}
static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con);
static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con);
non_null() static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con);
non_null() static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con);
/** return 1 on success.
* return 0 if could not send packet.
@ -419,6 +428,7 @@ void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_call
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
static int client_send_disconnect_notification(const Logger *logger, TCP_Client_Connection *con, uint8_t id)
{
uint8_t packet[1 + 1];
@ -595,6 +605,7 @@ TCP_Client_Connection *new_TCP_connection(const Logger *logger, const Mono_Time
/** return 0 on success
* return -1 on failure
*/
non_null(1, 2, 3) nullable(5)
static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data,
uint16_t length, void *userdata)
{
@ -749,6 +760,7 @@ static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection
return 0;
}
non_null(1, 2) nullable(3)
static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata)
{
uint8_t packet[MAX_PACKET_SIZE];
@ -772,6 +784,7 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
return true;
}
non_null(1, 2, 3) nullable(4)
static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time,
void *userdata)
{

View File

@ -38,28 +38,38 @@ typedef enum TCP_Client_Status {
typedef struct TCP_Client_Connection TCP_Client_Connection;
non_null()
const uint8_t *tcp_con_public_key(const TCP_Client_Connection *con);
non_null()
IP_Port tcp_con_ip_port(const TCP_Client_Connection *con);
non_null()
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *con);
non_null()
void *tcp_con_custom_object(const TCP_Client_Connection *con);
non_null()
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *con);
non_null()
void tcp_con_set_custom_object(TCP_Client_Connection *con, void *object);
non_null()
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
/** Create new TCP connection to ip_port/public_key
*/
non_null(1, 2, 3, 4, 5, 6) nullable(7)
TCP_Client_Connection *new_TCP_connection(const Logger *logger, const Mono_Time *mono_time, const IP_Port *ip_port,
const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info);
/** Run the TCP connection
*/
non_null(1, 2, 3) nullable(4)
void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata);
/** Kill the TCP connection
*/
nullable(1)
void kill_TCP_connection(TCP_Client_Connection *tcp_connection);
typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
@ -68,7 +78,9 @@ typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t le
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
int send_onion_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *data, uint16_t length);
non_null()
void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *onion_callback, void *object);
typedef int tcp_routing_response_cb(void *object, uint8_t connection_id, const uint8_t *public_key);
@ -78,14 +90,18 @@ 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).
*/
non_null()
int send_routing_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key);
non_null()
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object);
non_null()
void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id);
/** Set the number that will be used as an argument in the callbacks related to con_id.
@ -95,6 +111,7 @@ int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, ui
* return 0 on success.
* return -1 on failure.
*/
non_null()
int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32_t number);
typedef int tcp_routing_data_cb(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
@ -104,7 +121,9 @@ typedef int tcp_routing_data_cb(void *object, uint32_t number, uint8_t connectio
* return 0 if could not send packet.
* return -1 on failure.
*/
non_null()
int send_data(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length);
non_null()
void routing_data_handler(TCP_Client_Connection *con, tcp_routing_data_cb *data_callback, void *object);
typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
@ -114,8 +133,10 @@ typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8
* return 0 if could not send packet.
* return -1 on failure.
*/
non_null()
int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data,
uint16_t length);
non_null()
void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_callback, void *object);

View File

@ -10,7 +10,7 @@
void wipe_priority_list(TCP_Priority_List *p)
{
while (p) {
while (p != nullptr) {
TCP_Priority_List *pp = p;
p = p->next;
free(pp->data);
@ -214,6 +214,7 @@ int read_TCP_packet(const Logger *logger, Socket sock, uint8_t *data, uint16_t l
* return 0 if nothing has been read from socket.
* return -1 on failure.
*/
non_null()
static uint16_t read_TCP_length(const Logger *logger, Socket sock, const IP_Port *ip_port)
{
const uint16_t count = net_socket_data_recv_buffer(sock);

View File

@ -17,6 +17,7 @@ struct TCP_Priority_List {
uint8_t *data;
};
nullable(1)
void wipe_priority_list(TCP_Priority_List *p);
#define NUM_RESERVED_PORTS 16
@ -60,22 +61,26 @@ typedef struct TCP_Connection {
/** return 0 if pending data was sent completely
* return -1 if it wasn't
*/
non_null()
int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con);
/** return 0 if pending data was sent completely
* return -1 if it wasn't
*/
non_null()
int send_pending_data(const Logger *logger, TCP_Connection *con);
/** return 0 on failure (only if calloc fails)
* return 1 on success
*/
non_null()
bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent);
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
int write_packet_TCP_secure_connection(const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
bool priority);
@ -84,12 +89,14 @@ int write_packet_TCP_secure_connection(const Logger *logger, TCP_Connection *con
* return length on success
* return -1 on failure/no data in buffer.
*/
non_null()
int read_TCP_packet(const Logger *logger, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port);
/** return length of received packet on success.
* return 0 if could not read any packet.
* return -1 on failure (connection must be killed).
*/
non_null()
int read_packet_TCP_secure_connection(const Logger *logger, Socket sock, uint16_t *next_packet_length,
const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data,
uint16_t max_len, const IP_Port *ip_port);

View File

@ -62,6 +62,7 @@ uint32_t tcp_connections_count(const TCP_Connections *tcp_c)
* return -1 if realloc fails.
* return 0 if it succeeds.
*/
non_null()
static int realloc_TCP_Connection_to(TCP_Connection_to **array, size_t num)
{
if (!num) {
@ -82,6 +83,7 @@ static int realloc_TCP_Connection_to(TCP_Connection_to **array, size_t num)
return 0;
}
non_null()
static int realloc_TCP_con(TCP_con **array, size_t num)
{
if (!num) {
@ -105,6 +107,7 @@ static int realloc_TCP_con(TCP_con **array, size_t num)
/**
* Return true if the connections_number is valid.
*/
non_null()
static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number)
{
if ((unsigned int)connections_number >= tcp_c->connections_length) {
@ -125,6 +128,7 @@ static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connec
/**
* Return true if the tcp_connections_number is valid.
*/
non_null()
static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
{
if ((uint32_t)tcp_connections_number >= tcp_c->tcp_connections_length) {
@ -147,6 +151,7 @@ static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tc
* return -1 on failure.
* return connections_number on success.
*/
non_null()
static int create_connection(TCP_Connections *tcp_c)
{
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
@ -171,6 +176,7 @@ static int create_connection(TCP_Connections *tcp_c)
* return -1 on failure.
* return tcp_connections_number on success.
*/
non_null()
static int create_tcp_connection(TCP_Connections *tcp_c)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
@ -195,6 +201,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
{
if (!connections_number_is_valid(tcp_c, connections_number)) {
@ -223,6 +230,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
@ -247,6 +255,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0;
}
non_null()
static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
{
if (!connections_number_is_valid(tcp_c, connections_number)) {
@ -256,6 +265,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
return &tcp_c->connections[connections_number];
}
non_null()
static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
{
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
@ -440,6 +450,7 @@ int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connectio
return -1;
}
non_null()
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.
@ -488,6 +499,7 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_
* return connections_number on success.
* return -1 on failure.
*/
non_null()
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) {
@ -663,6 +675,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n
return 0;
}
non_null()
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) {
@ -677,6 +690,7 @@ static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int
/** return index on success.
* return -1 on failure.
*/
non_null()
static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{
if (tcp_connection_in_conn(con_to, tcp_connections_number)) {
@ -698,6 +712,7 @@ static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tc
/** return index on success.
* return -1 on failure.
*/
non_null()
static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{
for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
@ -715,6 +730,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.
*/
non_null()
static unsigned int online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
{
unsigned int count = 0;
@ -733,6 +749,7 @@ static unsigned int online_tcp_connection_from_conn(const TCP_Connection_to *con
/** return index on success.
* return -1 on failure.
*/
non_null()
static int set_tcp_connection_status(TCP_Connection_to *con_to, unsigned int tcp_connections_number,
uint8_t status,
uint8_t connection_id)
@ -783,6 +800,7 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number
return wipe_tcp_connection(tcp_c, tcp_connections_number);
}
non_null()
static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -829,6 +847,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
return 0;
}
non_null()
static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -873,6 +892,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
return 0;
}
non_null()
static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -906,6 +926,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
* return 0 on success.
* return -1 on failure.
*/
non_null()
static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_connections_number,
const uint8_t *public_key)
{
@ -926,6 +947,7 @@ static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_
return 0;
}
non_null()
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;
@ -959,6 +981,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
return 0;
}
non_null()
static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
{
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
@ -997,6 +1020,7 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
return 0;
}
non_null(1, 4) nullable(6)
static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
uint16_t length, void *userdata)
{
@ -1027,6 +1051,7 @@ static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connect
return 0;
}
non_null()
static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -1060,6 +1085,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const
return 0;
}
non_null()
static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
{
TCP_Connections *tcp_c = (TCP_Connections *)object;
@ -1076,6 +1102,7 @@ static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length
* return 0 on success.
* return -1 on failure.
*/
non_null()
static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -1097,6 +1124,7 @@ static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_n
return 0;
}
non_null()
static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@ -1137,6 +1165,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0;
}
non_null()
static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk)
{
IP_Port ipp_copy = *ip_port;
@ -1418,6 +1447,7 @@ TCP_Connections *new_tcp_connections(const Logger *logger, Mono_Time *mono_time,
return temp;
}
non_null(1, 2) nullable(3)
static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *userdata)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
@ -1464,6 +1494,7 @@ static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *use
}
}
non_null()
static void kill_nonused_tcp(TCP_Connections *tcp_c)
{
if (tcp_c->tcp_connections_length <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {

View File

@ -71,11 +71,14 @@ typedef struct TCP_con {
typedef struct TCP_Connections TCP_Connections;
non_null()
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
non_null()
uint32_t tcp_connections_count(const TCP_Connections *tcp_c);
/** Returns the number of connected TCP relays */
non_null()
uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
/** Send a packet to the TCP connection.
@ -83,6 +86,7 @@ uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet,
uint16_t length);
@ -94,6 +98,7 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num
* return TCP connection number on success.
* return -1 on failure.
*/
non_null()
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.
@ -101,6 +106,7 @@ int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);
* return 0 on success.
* return -1 on failure.
*/
non_null()
int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *data,
uint16_t length);
@ -111,6 +117,7 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_
* return 0 on success.
* return -1 on failure.
*/
non_null()
int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
/** Send an oob packet via the TCP relay corresponding to tcp_connections_number.
@ -118,22 +125,26 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
* return 0 on success.
* return -1 on failure.
*/
non_null()
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);
non_null()
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.
*/
non_null()
void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
typedef int tcp_onion_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
/** Set the callback for TCP onion packets.
*/
non_null(1) nullable(2, 3)
void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
@ -141,6 +152,7 @@ typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp
/** Set the callback for TCP oob data packets.
*/
non_null()
void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
/** Create a new TCP connection to public_key.
@ -152,11 +164,13 @@ void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *
* return connections_number on success.
* return -1 on failure.
*/
non_null()
int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int id);
/** return 0 on success.
* return -1 on failure.
*/
non_null()
int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
/** Set connection status.
@ -169,11 +183,13 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success.
* return -1 on failure.
*/
non_null()
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.
*/
non_null()
unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);
/** Add a TCP relay tied to a connection.
@ -183,6 +199,7 @@ unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, i
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number);
@ -193,6 +210,7 @@ int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connection
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, const IP_Port *ip_port,
const uint8_t *relay_pk);
@ -201,6 +219,7 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, con
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk);
/** Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
@ -209,6 +228,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const u
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
non_null()
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.
@ -218,12 +238,16 @@ uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tc
*
* Returns NULL on failure.
*/
non_null()
TCP_Connections *new_tcp_connections(const Logger *logger, Mono_Time *mono_time, const uint8_t *secret_key,
const TCP_Proxy_Info *proxy_info);
non_null()
int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);
non_null(1, 2) nullable(3)
void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
non_null()
void kill_tcp_connections(TCP_Connections *tcp_c);
#endif

View File

@ -105,6 +105,7 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server)
* return -1 on failure
* return 0 on success.
*/
non_null()
static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
{
const uint32_t new_size = tcp_server->size_accepted_connections + num;
@ -130,6 +131,7 @@ static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
return 0;
}
non_null()
static void wipe_secure_connection(TCP_Secure_Connection *con)
{
if (con->status) {
@ -138,12 +140,14 @@ static void wipe_secure_connection(TCP_Secure_Connection *con)
}
}
non_null()
static void move_secure_connection(TCP_Secure_Connection *con_new, TCP_Secure_Connection *con_old)
{
*con_new = *con_old;
crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
}
non_null()
static void free_accepted_connection_array(TCP_Server *tcp_server)
{
if (tcp_server->accepted_connection_array == nullptr) {
@ -162,12 +166,14 @@ static void free_accepted_connection_array(TCP_Server *tcp_server)
/** return index corresponding to connection with peer on success
* return -1 on failure.
*/
non_null()
static int get_TCP_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
{
return bs_list_find(&tcp_server->accepted_key_list, public_key);
}
non_null()
static int kill_accepted(TCP_Server *tcp_server, int index);
/** Add accepted TCP connection to the list.
@ -175,6 +181,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index);
* return index on success
* return -1 on failure
*/
non_null()
static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con)
{
int index = get_TCP_connection_index(tcp_server, con->public_key);
@ -224,6 +231,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
* return 0 on success
* return -1 on failure
*/
non_null()
static int del_accepted(TCP_Server *tcp_server, int index)
{
if ((uint32_t)index >= tcp_server->size_accepted_connections) {
@ -250,12 +258,14 @@ static int del_accepted(TCP_Server *tcp_server, int index)
/** Kill a TCP_Secure_Connection
*/
non_null()
static void kill_TCP_secure_connection(TCP_Secure_Connection *con)
{
kill_sock(con->con.sock);
wipe_secure_connection(con);
}
non_null()
static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *con, uint8_t con_number);
/** Kill an accepted TCP_Secure_Connection
@ -286,6 +296,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index)
/** return 1 if everything went well.
* return -1 if the connection must be killed.
*/
non_null()
static int handle_TCP_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
const uint8_t *self_secret_key)
{
@ -349,6 +360,7 @@ static int handle_TCP_handshake(const Logger *logger, TCP_Secure_Connection *con
* return 0 if we didn't get it yet.
* return -1 if the connection must be killed.
*/
non_null()
static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key)
{
uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
@ -366,6 +378,7 @@ static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
static int send_routing_response(const Logger *logger, TCP_Secure_Connection *con, uint8_t rpid,
const uint8_t *public_key)
{
@ -381,6 +394,7 @@ static int send_routing_response(const Logger *logger, TCP_Secure_Connection *co
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
static int send_connect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
@ -391,6 +405,7 @@ static int send_connect_notification(const Logger *logger, TCP_Secure_Connection
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
non_null()
static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
@ -400,6 +415,7 @@ static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connect
/** return 0 on success.
* return -1 on failure (connection must be killed).
*/
non_null()
static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
{
uint32_t index = -1;
@ -481,6 +497,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
/** return 0 on success.
* return -1 on failure (connection must be killed).
*/
non_null()
static int handle_TCP_oob_send(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
uint16_t length)
{
@ -540,6 +557,7 @@ static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *co
return -1;
}
non_null()
static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length)
{
TCP_Server *tcp_server = (TCP_Server *)object;
@ -569,6 +587,7 @@ static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t
/** return 0 on success
* return -1 on failure
*/
non_null()
static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
{
if (length == 0) {
@ -717,6 +736,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
}
non_null()
static int confirm_TCP_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con,
const uint8_t *data, uint16_t length)
{
@ -743,6 +763,7 @@ static int confirm_TCP_connection(TCP_Server *tcp_server, const Mono_Time *mono_
/** return index on success
* return -1 on failure
*/
non_null()
static int accept_connection(TCP_Server *tcp_server, Socket sock)
{
if (!sock_valid(sock)) {
@ -884,6 +905,7 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t
}
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_TCP_accept_new(TCP_Server *tcp_server)
{
for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) {
@ -896,6 +918,7 @@ static void do_TCP_accept_new(TCP_Server *tcp_server)
}
#endif
non_null()
static int do_incoming(TCP_Server *tcp_server, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->incoming_connection_queue[i];
@ -933,6 +956,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
return index_new;
}
non_null()
static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->unconfirmed_connection_queue[i];
@ -959,6 +983,7 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
return confirm_TCP_connection(tcp_server, mono_time, conn, packet, len);
}
non_null()
static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i];
@ -986,6 +1011,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
return true;
}
non_null()
static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
{
while (tcp_process_secure_packet(tcp_server, i)) {
@ -995,6 +1021,7 @@ static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
}
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_TCP_incoming(TCP_Server *tcp_server)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
@ -1002,6 +1029,7 @@ static void do_TCP_incoming(TCP_Server *tcp_server)
}
}
non_null()
static void do_TCP_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
@ -1010,6 +1038,7 @@ static void do_TCP_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_tim
}
#endif
non_null()
static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
#ifdef TCP_SERVER_USE_EPOLL
@ -1067,6 +1096,7 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
#ifdef TCP_SERVER_USE_EPOLL
non_null()
static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
#define MAX_EVENTS 16
@ -1193,6 +1223,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
return nfds > 0;
}
non_null()
static void do_TCP_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
while (tcp_epoll_process(tcp_server, mono_time)) {

View File

@ -27,20 +27,25 @@ typedef enum TCP_Status {
typedef struct TCP_Server TCP_Server;
non_null()
const uint8_t *tcp_server_public_key(const TCP_Server *tcp_server);
non_null()
size_t tcp_server_listen_count(const TCP_Server *tcp_server);
/** Create new TCP server instance.
*/
non_null(1, 4, 5) nullable(6)
TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
const uint8_t *secret_key, Onion *onion);
/** Run the TCP_server
*/
non_null()
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
/** Kill the TCP server
*/
non_null()
void kill_TCP_server(TCP_Server *tcp_server);

31
toxcore/attributes.h Normal file
View File

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2022 The TokTok team.
*/
/**
* printf and nonnull attributes for GCC/Clang and Cimple.
*/
#ifndef C_TOXCORE_TOXCORE_ATTRIBUTES_H
#define C_TOXCORE_TOXCORE_ATTRIBUTES_H
/* No declarations here. */
//!TOKSTYLE-
#ifdef __GNUC__
#define GNU_PRINTF(f, a) __attribute__((__format__(__printf__, f, a)))
#else
#define GNU_PRINTF(f, a)
#endif
#if defined(__GNUC__) && !defined(NDEBUG)
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
#else
#define non_null(...)
#endif
#define nullable(...)
//!TOKSTYLE+
#endif // C_TOXCORE_TOXCORE_ATTRIBUTES_H

View File

@ -8,10 +8,11 @@
#ifndef C_TOXCORE_TOXCORE_CCOMPAT_H
#define C_TOXCORE_TOXCORE_CCOMPAT_H
#include <stdbool.h>
#include <stdint.h>
bool unused_for_tokstyle(void);
#include "attributes.h"
/* No declarations here. */
//!TOKSTYLE-
@ -63,14 +64,10 @@ bool unused_for_tokstyle(void);
#ifdef __GNUC__
#define GNU_PRINTF(f, a) __attribute__((__format__(__printf__, f, a)))
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
#else
#define GNU_PRINTF(f, a)
#define non_null(...)
#endif
#define nullable(...)
//!TOKSTYLE+
#endif // C_TOXCORE_TOXCORE_CCOMPAT_H

View File

@ -69,6 +69,7 @@ static uint8_t *crypto_malloc(size_t bytes)
return ptr;
}
nullable(1)
static void crypto_free(uint8_t *ptr, size_t bytes)
{
if (ptr != nullptr) {
@ -80,7 +81,6 @@ static void crypto_free(uint8_t *ptr, size_t bytes)
}
#endif // !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
non_null(1)
void crypto_memzero(void *data, size_t length)
{
#ifndef VANILLA_NACL
@ -90,7 +90,6 @@ void crypto_memzero(void *data, size_t length)
#endif
}
non_null(1)
bool crypto_memlock(void *data, size_t length)
{
#ifndef VANILLA_NACL
@ -105,7 +104,6 @@ bool crypto_memlock(void *data, size_t length)
#endif
}
non_null(1)
bool crypto_memunlock(void *data, size_t length)
{
#ifndef VANILLA_NACL
@ -120,7 +118,6 @@ bool crypto_memunlock(void *data, size_t length)
#endif
}
non_null(1, 2)
int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@ -131,7 +128,6 @@ int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2)
#endif
}
non_null(1, 2)
int32_t crypto_sha512_cmp(const uint8_t *cksum1, const uint8_t *cksum2)
{
#ifndef VANILLA_NACL
@ -178,7 +174,6 @@ uint32_t random_range_u32(uint32_t upper_bound)
#endif // VANILLA_NACL
}
non_null(1)
bool public_key_valid(const uint8_t *public_key)
{
if (public_key[31] >= 128) { /* Last bit of key is always zero. */
@ -188,14 +183,12 @@ bool public_key_valid(const uint8_t *public_key)
return 1;
}
non_null(1, 2, 3)
int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key,
uint8_t *shared_key)
{
return crypto_box_beforenm(shared_key, public_key, secret_key);
}
non_null(1, 2, 3, 5)
int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *plain, size_t length, uint8_t *encrypted)
{
@ -247,7 +240,6 @@ int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
return length + crypto_box_MACBYTES;
}
non_null(1, 2, 3, 5)
int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *encrypted, size_t length, uint8_t *plain)
{
@ -296,7 +288,6 @@ int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
return length - crypto_box_MACBYTES;
}
non_null(1, 2, 3, 4, 6)
int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *plain, size_t length, uint8_t *encrypted)
{
@ -311,7 +302,6 @@ int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const
return ret;
}
non_null(1, 2, 3, 4, 6)
int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *encrypted, size_t length, uint8_t *plain)
{
@ -326,7 +316,6 @@ int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const
return ret;
}
non_null(1)
void increment_nonce(uint8_t *nonce)
{
/* TODO(irungentoo): use `increment_nonce_number(nonce, 1)` or
@ -346,7 +335,6 @@ void increment_nonce(uint8_t *nonce)
}
}
non_null(1)
void increment_nonce_number(uint8_t *nonce, uint32_t increment)
{
/* NOTE don't use breaks inside this loop
@ -369,19 +357,16 @@ void increment_nonce_number(uint8_t *nonce, uint32_t increment)
}
}
non_null(1)
void random_nonce(uint8_t *nonce)
{
random_bytes(nonce, crypto_box_NONCEBYTES);
}
non_null(1)
void new_symmetric_key(uint8_t *key)
{
random_bytes(key, CRYPTO_SYMMETRIC_KEY_SIZE);
}
non_null(1, 2)
int32_t crypto_new_keypair(uint8_t *public_key, uint8_t *secret_key)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@ -394,25 +379,21 @@ int32_t crypto_new_keypair(uint8_t *public_key, uint8_t *secret_key)
#endif
}
non_null(1, 2)
void crypto_derive_public_key(uint8_t *public_key, const uint8_t *secret_key)
{
crypto_scalarmult_curve25519_base(public_key, secret_key);
}
non_null(1, 2)
void crypto_sha256(uint8_t *hash, const uint8_t *data, size_t length)
{
crypto_hash_sha256(hash, data, length);
}
non_null(1, 2)
void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length)
{
crypto_hash_sha512(hash, data, length);
}
non_null(1)
void random_bytes(uint8_t *data, size_t length)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION

View File

@ -13,6 +13,8 @@
#include <stddef.h>
#include <stdint.h>
#include "attributes.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -65,16 +67,19 @@ extern "C" {
* will be no reads to the written data. Use this function if you want to be
* sure the memory is indeed zeroed.
*/
non_null()
void crypto_memzero(void *data, size_t length);
/**
* @brief Compute a SHA256 hash (32 bytes).
*/
non_null()
void crypto_sha256(uint8_t *hash, const uint8_t *data, size_t length);
/**
* @brief Compute a SHA512 hash (64 bytes).
*/
non_null()
void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length);
/**
@ -84,7 +89,8 @@ void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length);
* @retval 0 if both mem locations of length are equal
* @retval -1 if they are not
*/
int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2);
non_null()
int32_t public_key_cmp(const uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]);
/**
* @brief Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to
@ -92,6 +98,7 @@ int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2);
*
* @return 0 if both mem locations of length are equal, -1 if they are not.
*/
non_null()
int32_t crypto_sha512_cmp(const uint8_t *cksum1, const uint8_t *cksum2);
/**
@ -125,11 +132,13 @@ uint32_t random_range_u32(uint32_t upper_bound);
/**
* @brief Fill the given nonce with random bytes.
*/
non_null()
void random_nonce(uint8_t *nonce);
/**
* @brief Fill an array of bytes with random values.
*/
non_null()
void random_bytes(uint8_t *bytes, size_t length);
/**
@ -139,6 +148,7 @@ void random_bytes(uint8_t *bytes, size_t length);
*
* @return false if it isn't, true if it is.
*/
non_null()
bool public_key_valid(const uint8_t *public_key);
/**
@ -146,11 +156,13 @@ bool public_key_valid(const uint8_t *public_key);
*
* Every call to this function is likely to generate a different keypair.
*/
non_null()
int32_t crypto_new_keypair(uint8_t *public_key, uint8_t *secret_key);
/**
* @brief Derive the public key from a given secret key.
*/
non_null()
void crypto_derive_public_key(uint8_t *public_key, const uint8_t *secret_key);
/**
@ -164,6 +176,7 @@ void crypto_derive_public_key(uint8_t *public_key, const uint8_t *secret_key);
* @retval -1 if there was a problem.
* @retval >=0 length of encrypted data if everything was fine.
*/
non_null()
int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *plain,
size_t length, uint8_t *encrypted);
@ -178,6 +191,7 @@ int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const
* @retval -1 if there was a problem (decryption failed).
* @retval >=0 length of plain text data if everything was fine.
*/
non_null()
int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *encrypted, size_t length, uint8_t *plain);
@ -188,6 +202,7 @@ int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const
* shared-key generation once so it does not have to be performed on every
* encrypt/decrypt.
*/
non_null()
int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key, uint8_t *shared_key);
/**
@ -200,6 +215,7 @@ int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key,
* @return -1 if there was a problem, length of encrypted data if everything
* was fine.
*/
non_null()
int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce, const uint8_t *plain, size_t length,
uint8_t *encrypted);
@ -213,6 +229,7 @@ int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
* @return -1 if there was a problem (decryption failed), length of plain data
* if everything was fine.
*/
non_null()
int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce, const uint8_t *encrypted, size_t length,
uint8_t *plain);
@ -220,6 +237,7 @@ int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
* @brief Increment the given nonce by 1 in big endian (rightmost byte incremented
* first).
*/
non_null()
void increment_nonce(uint8_t *nonce);
/**
@ -227,11 +245,13 @@ void increment_nonce(uint8_t *nonce);
*
* The number should be in host byte order.
*/
non_null()
void increment_nonce_number(uint8_t *nonce, uint32_t increment);
/**
* @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
*/
non_null()
void new_symmetric_key(uint8_t *key);
/**
@ -242,6 +262,7 @@ void new_symmetric_key(uint8_t *key);
*
* @return true on success.
*/
non_null()
bool crypto_memlock(void *data, size_t length);
/**
@ -255,6 +276,7 @@ bool crypto_memlock(void *data, size_t length);
*
* @return true on success.
*/
non_null()
bool crypto_memunlock(void *data, size_t length);
#ifdef __cplusplus

View File

@ -25,17 +25,20 @@ struct Tox_Event_Conference_Connected {
uint32_t conference_number;
};
non_null()
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *conference_connected)
{
*conference_connected = (Tox_Event_Conference_Connected) {
0
};
}
non_null()
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *conference_connected)
{
return;
}
non_null()
static void tox_event_conference_connected_set_conference_number(
Tox_Event_Conference_Connected *conference_connected, uint32_t conference_number)
{
@ -49,6 +52,7 @@ uint32_t tox_event_conference_connected_get_conference_number(
return conference_connected->conference_number;
}
non_null()
static void tox_event_conference_connected_pack(
const Tox_Event_Conference_Connected *event, msgpack_packer *mp)
{
@ -57,6 +61,7 @@ static void tox_event_conference_connected_pack(
msgpack_pack_uint32(mp, event->conference_number);
}
non_null()
static bool tox_event_conference_connected_unpack(
Tox_Event_Conference_Connected *event, const msgpack_object *obj)
{
@ -77,6 +82,7 @@ static bool tox_event_conference_connected_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *events)
{
if (events->conference_connected_size == UINT32_MAX) {

View File

@ -28,17 +28,20 @@ struct Tox_Event_Conference_Invite {
size_t cookie_length;
};
non_null()
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *conference_invite)
{
*conference_invite = (Tox_Event_Conference_Invite) {
0
};
}
non_null()
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *conference_invite)
{
free(conference_invite->cookie);
}
non_null()
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *conference_invite,
uint32_t friend_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_conference_invite_get_friend_number(const Tox_Event_Conferenc
return conference_invite->friend_number;
}
non_null()
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *conference_invite,
Tox_Conference_Type type)
{
@ -63,6 +67,7 @@ Tox_Conference_Type tox_event_conference_invite_get_type(const Tox_Event_Confere
return conference_invite->type;
}
non_null()
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *conference_invite,
const uint8_t *cookie, size_t cookie_length)
{
@ -95,6 +100,7 @@ const uint8_t *tox_event_conference_invite_get_cookie(const Tox_Event_Conference
return conference_invite->cookie;
}
non_null()
static void tox_event_conference_invite_pack(
const Tox_Event_Conference_Invite *event, msgpack_packer *mp)
{
@ -106,6 +112,7 @@ static void tox_event_conference_invite_pack(
msgpack_pack_bin_body(mp, event->cookie, event->cookie_length);
}
non_null()
static bool tox_event_conference_invite_unpack(
Tox_Event_Conference_Invite *event, const msgpack_object *obj)
{
@ -128,6 +135,7 @@ static bool tox_event_conference_invite_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *events)
{
if (events->conference_invite_size == UINT32_MAX) {

View File

@ -29,17 +29,20 @@ struct Tox_Event_Conference_Message {
size_t message_length;
};
non_null()
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *conference_message)
{
*conference_message = (Tox_Event_Conference_Message) {
0
};
}
non_null()
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *conference_message)
{
free(conference_message->message);
}
non_null()
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *conference_message,
uint32_t conference_number)
{
@ -52,6 +55,7 @@ uint32_t tox_event_conference_message_get_conference_number(const Tox_Event_Conf
return conference_message->conference_number;
}
non_null()
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *conference_message,
uint32_t peer_number)
{
@ -64,6 +68,7 @@ uint32_t tox_event_conference_message_get_peer_number(const Tox_Event_Conference
return conference_message->peer_number;
}
non_null()
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *conference_message,
Tox_Message_Type type)
{
@ -76,6 +81,7 @@ Tox_Message_Type tox_event_conference_message_get_type(const Tox_Event_Conferenc
return conference_message->type;
}
non_null()
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *conference_message,
const uint8_t *message, size_t message_length)
{
@ -108,6 +114,7 @@ const uint8_t *tox_event_conference_message_get_message(const Tox_Event_Conferen
return conference_message->message;
}
non_null()
static void tox_event_conference_message_pack(
const Tox_Event_Conference_Message *event, msgpack_packer *mp)
{
@ -120,6 +127,7 @@ static void tox_event_conference_message_pack(
msgpack_pack_bin_body(mp, event->message, event->message_length);
}
non_null()
static bool tox_event_conference_message_unpack(
Tox_Event_Conference_Message *event, const msgpack_object *obj)
{
@ -143,6 +151,7 @@ static bool tox_event_conference_message_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *events)
{
if (events->conference_message_size == UINT32_MAX) {

View File

@ -25,6 +25,7 @@ struct Tox_Event_Conference_Peer_List_Changed {
uint32_t conference_number;
};
non_null()
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed
*conference_peer_list_changed)
{
@ -32,12 +33,14 @@ static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conferenc
0
};
}
non_null()
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed
*conference_peer_list_changed)
{
return;
}
non_null()
static void tox_event_conference_peer_list_changed_set_conference_number(Tox_Event_Conference_Peer_List_Changed
*conference_peer_list_changed, uint32_t conference_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_conference_peer_list_changed_get_conference_number(const Tox_
return conference_peer_list_changed->conference_number;
}
non_null()
static void tox_event_conference_peer_list_changed_pack(
const Tox_Event_Conference_Peer_List_Changed *event, msgpack_packer *mp)
{
@ -59,6 +63,7 @@ static void tox_event_conference_peer_list_changed_pack(
msgpack_pack_uint32(mp, event->conference_number);
}
non_null()
static bool tox_event_conference_peer_list_changed_unpack(
Tox_Event_Conference_Peer_List_Changed *event, const msgpack_object *obj)
{
@ -79,6 +84,7 @@ static bool tox_event_conference_peer_list_changed_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *events)
{
if (events->conference_peer_list_changed_size == UINT32_MAX) {

View File

@ -28,17 +28,20 @@ struct Tox_Event_Conference_Peer_Name {
size_t name_length;
};
non_null()
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *conference_peer_name)
{
*conference_peer_name = (Tox_Event_Conference_Peer_Name) {
0
};
}
non_null()
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *conference_peer_name)
{
free(conference_peer_name->name);
}
non_null()
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t conference_number)
{
@ -52,6 +55,7 @@ uint32_t tox_event_conference_peer_name_get_conference_number(const Tox_Event_Co
return conference_peer_name->conference_number;
}
non_null()
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t peer_number)
{
@ -64,6 +68,7 @@ uint32_t tox_event_conference_peer_name_get_peer_number(const Tox_Event_Conferen
return conference_peer_name->peer_number;
}
non_null()
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *conference_peer_name,
const uint8_t *name, size_t name_length)
{
@ -96,6 +101,7 @@ const uint8_t *tox_event_conference_peer_name_get_name(const Tox_Event_Conferenc
return conference_peer_name->name;
}
non_null()
static void tox_event_conference_peer_name_pack(
const Tox_Event_Conference_Peer_Name *event, msgpack_packer *mp)
{
@ -107,6 +113,7 @@ static void tox_event_conference_peer_name_pack(
msgpack_pack_bin_body(mp, event->name, event->name_length);
}
non_null()
static bool tox_event_conference_peer_name_unpack(
Tox_Event_Conference_Peer_Name *event, const msgpack_object *obj)
{
@ -129,6 +136,7 @@ static bool tox_event_conference_peer_name_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *events)
{
if (events->conference_peer_name_size == UINT32_MAX) {

View File

@ -28,17 +28,20 @@ struct Tox_Event_Conference_Title {
size_t title_length;
};
non_null()
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *conference_title)
{
*conference_title = (Tox_Event_Conference_Title) {
0
};
}
non_null()
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *conference_title)
{
free(conference_title->title);
}
non_null()
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *conference_title,
uint32_t conference_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_conference_title_get_conference_number(const Tox_Event_Confer
return conference_title->conference_number;
}
non_null()
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *conference_title,
uint32_t peer_number)
{
@ -63,6 +67,7 @@ uint32_t tox_event_conference_title_get_peer_number(const Tox_Event_Conference_T
return conference_title->peer_number;
}
non_null()
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *conference_title, const uint8_t *title,
size_t title_length)
{
@ -95,6 +100,7 @@ const uint8_t *tox_event_conference_title_get_title(const Tox_Event_Conference_T
return conference_title->title;
}
non_null()
static void tox_event_conference_title_pack(
const Tox_Event_Conference_Title *event, msgpack_packer *mp)
{
@ -106,6 +112,7 @@ static void tox_event_conference_title_pack(
msgpack_pack_bin_body(mp, event->title, event->title_length);
}
non_null()
static bool tox_event_conference_title_unpack(
Tox_Event_Conference_Title *event, const msgpack_object *obj)
{
@ -128,6 +135,7 @@ static bool tox_event_conference_title_unpack(
*****************************************************/
non_null()
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *events)
{
if (events->conference_title_size == UINT32_MAX) {

View File

@ -7,6 +7,7 @@
#include <msgpack.h>
#include "../attributes.h"
#include "../tox_events.h"
#ifdef __cplusplus
@ -126,76 +127,86 @@ tox_friend_status_message_cb tox_events_handle_friend_status_message;
tox_friend_typing_cb tox_events_handle_friend_typing;
tox_self_connection_status_cb tox_events_handle_self_connection_status;
void tox_events_clear_conference_connected(Tox_Events *events);
void tox_events_clear_conference_invite(Tox_Events *events);
void tox_events_clear_conference_message(Tox_Events *events);
void tox_events_clear_conference_peer_list_changed(Tox_Events *events);
void tox_events_clear_conference_peer_name(Tox_Events *events);
void tox_events_clear_conference_title(Tox_Events *events);
void tox_events_clear_file_chunk_request(Tox_Events *events);
void tox_events_clear_file_recv_chunk(Tox_Events *events);
void tox_events_clear_file_recv_control(Tox_Events *events);
void tox_events_clear_file_recv(Tox_Events *events);
void tox_events_clear_friend_connection_status(Tox_Events *events);
void tox_events_clear_friend_lossless_packet(Tox_Events *events);
void tox_events_clear_friend_lossy_packet(Tox_Events *events);
void tox_events_clear_friend_message(Tox_Events *events);
void tox_events_clear_friend_name(Tox_Events *events);
void tox_events_clear_friend_read_receipt(Tox_Events *events);
void tox_events_clear_friend_request(Tox_Events *events);
void tox_events_clear_friend_status_message(Tox_Events *events);
void tox_events_clear_friend_status(Tox_Events *events);
void tox_events_clear_friend_typing(Tox_Events *events);
void tox_events_clear_self_connection_status(Tox_Events *events);
// non_null()
typedef void tox_events_clear_cb(Tox_Events *events);
void tox_events_pack_conference_connected(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_conference_invite(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_conference_message(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_conference_peer_list_changed(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_conference_peer_name(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_conference_title(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_file_chunk_request(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_file_recv_chunk(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_file_recv_control(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_file_recv(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_connection_status(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_lossless_packet(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_lossy_packet(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_message(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_name(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_read_receipt(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_request(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_status_message(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_status(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_friend_typing(const Tox_Events *events, msgpack_packer *mp);
void tox_events_pack_self_connection_status(const Tox_Events *events, msgpack_packer *mp);
tox_events_clear_cb tox_events_clear_conference_connected;
tox_events_clear_cb tox_events_clear_conference_invite;
tox_events_clear_cb tox_events_clear_conference_message;
tox_events_clear_cb tox_events_clear_conference_peer_list_changed;
tox_events_clear_cb tox_events_clear_conference_peer_name;
tox_events_clear_cb tox_events_clear_conference_title;
tox_events_clear_cb tox_events_clear_file_chunk_request;
tox_events_clear_cb tox_events_clear_file_recv_chunk;
tox_events_clear_cb tox_events_clear_file_recv_control;
tox_events_clear_cb tox_events_clear_file_recv;
tox_events_clear_cb tox_events_clear_friend_connection_status;
tox_events_clear_cb tox_events_clear_friend_lossless_packet;
tox_events_clear_cb tox_events_clear_friend_lossy_packet;
tox_events_clear_cb tox_events_clear_friend_message;
tox_events_clear_cb tox_events_clear_friend_name;
tox_events_clear_cb tox_events_clear_friend_read_receipt;
tox_events_clear_cb tox_events_clear_friend_request;
tox_events_clear_cb tox_events_clear_friend_status_message;
tox_events_clear_cb tox_events_clear_friend_status;
tox_events_clear_cb tox_events_clear_friend_typing;
tox_events_clear_cb tox_events_clear_self_connection_status;
void tox_events_pack(const Tox_Events *events, msgpack_packer *mp);
// non_null()
typedef void tox_events_pack_cb(const Tox_Events *events, msgpack_packer *mp);
bool tox_events_unpack_conference_connected(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_conference_invite(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_conference_message(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_conference_peer_list_changed(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_conference_peer_name(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_conference_title(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_file_chunk_request(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_file_recv_chunk(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_file_recv_control(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_file_recv(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_connection_status(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_lossless_packet(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_lossy_packet(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_message(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_name(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_read_receipt(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_request(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_status_message(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_status(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_friend_typing(Tox_Events *events, const msgpack_object *obj);
bool tox_events_unpack_self_connection_status(Tox_Events *events, const msgpack_object *obj);
tox_events_pack_cb tox_events_pack_conference_connected;
tox_events_pack_cb tox_events_pack_conference_invite;
tox_events_pack_cb tox_events_pack_conference_message;
tox_events_pack_cb tox_events_pack_conference_peer_list_changed;
tox_events_pack_cb tox_events_pack_conference_peer_name;
tox_events_pack_cb tox_events_pack_conference_title;
tox_events_pack_cb tox_events_pack_file_chunk_request;
tox_events_pack_cb tox_events_pack_file_recv_chunk;
tox_events_pack_cb tox_events_pack_file_recv_control;
tox_events_pack_cb tox_events_pack_file_recv;
tox_events_pack_cb tox_events_pack_friend_connection_status;
tox_events_pack_cb tox_events_pack_friend_lossless_packet;
tox_events_pack_cb tox_events_pack_friend_lossy_packet;
tox_events_pack_cb tox_events_pack_friend_message;
tox_events_pack_cb tox_events_pack_friend_name;
tox_events_pack_cb tox_events_pack_friend_read_receipt;
tox_events_pack_cb tox_events_pack_friend_request;
tox_events_pack_cb tox_events_pack_friend_status_message;
tox_events_pack_cb tox_events_pack_friend_status;
tox_events_pack_cb tox_events_pack_friend_typing;
tox_events_pack_cb tox_events_pack_self_connection_status;
bool tox_events_unpack(Tox_Events *events, const msgpack_object *obj);
tox_events_pack_cb tox_events_pack;
// non_null()
typedef bool tox_events_unpack_cb(Tox_Events *events, const msgpack_object *obj);
tox_events_unpack_cb tox_events_unpack_conference_connected;
tox_events_unpack_cb tox_events_unpack_conference_invite;
tox_events_unpack_cb tox_events_unpack_conference_message;
tox_events_unpack_cb tox_events_unpack_conference_peer_list_changed;
tox_events_unpack_cb tox_events_unpack_conference_peer_name;
tox_events_unpack_cb tox_events_unpack_conference_title;
tox_events_unpack_cb tox_events_unpack_file_chunk_request;
tox_events_unpack_cb tox_events_unpack_file_recv_chunk;
tox_events_unpack_cb tox_events_unpack_file_recv_control;
tox_events_unpack_cb tox_events_unpack_file_recv;
tox_events_unpack_cb tox_events_unpack_friend_connection_status;
tox_events_unpack_cb tox_events_unpack_friend_lossless_packet;
tox_events_unpack_cb tox_events_unpack_friend_lossy_packet;
tox_events_unpack_cb tox_events_unpack_friend_message;
tox_events_unpack_cb tox_events_unpack_friend_name;
tox_events_unpack_cb tox_events_unpack_friend_read_receipt;
tox_events_unpack_cb tox_events_unpack_friend_request;
tox_events_unpack_cb tox_events_unpack_friend_status_message;
tox_events_unpack_cb tox_events_unpack_friend_status;
tox_events_unpack_cb tox_events_unpack_friend_typing;
tox_events_unpack_cb tox_events_unpack_self_connection_status;
tox_events_unpack_cb tox_events_unpack;
non_null()
Tox_Events_State *tox_events_alloc(void *user_data);
#ifdef __cplusplus

View File

@ -28,17 +28,20 @@ struct Tox_Event_File_Chunk_Request {
uint16_t length;
};
non_null()
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *file_chunk_request)
{
*file_chunk_request = (Tox_Event_File_Chunk_Request) {
0
};
}
non_null()
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *file_chunk_request)
{
return;
}
non_null()
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t friend_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_file_chunk_request_get_friend_number(const Tox_Event_File_Chu
return file_chunk_request->friend_number;
}
non_null()
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t file_number)
{
@ -63,6 +67,7 @@ uint32_t tox_event_file_chunk_request_get_file_number(const Tox_Event_File_Chunk
return file_chunk_request->file_number;
}
non_null()
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *file_chunk_request,
uint64_t position)
{
@ -75,6 +80,7 @@ uint64_t tox_event_file_chunk_request_get_position(const Tox_Event_File_Chunk_Re
return file_chunk_request->position;
}
non_null()
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *file_chunk_request, uint16_t length)
{
assert(file_chunk_request != nullptr);
@ -86,6 +92,7 @@ uint16_t tox_event_file_chunk_request_get_length(const Tox_Event_File_Chunk_Requ
return file_chunk_request->length;
}
non_null()
static void tox_event_file_chunk_request_pack(
const Tox_Event_File_Chunk_Request *event, msgpack_packer *mp)
{
@ -97,6 +104,7 @@ static void tox_event_file_chunk_request_pack(
msgpack_pack_uint16(mp, event->length);
}
non_null()
static bool tox_event_file_chunk_request_unpack(
Tox_Event_File_Chunk_Request *event, const msgpack_object *obj)
{
@ -120,6 +128,7 @@ static bool tox_event_file_chunk_request_unpack(
*****************************************************/
non_null()
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *events)
{
if (events->file_chunk_request_size == UINT32_MAX) {

View File

@ -30,17 +30,20 @@ struct Tox_Event_File_Recv {
size_t filename_length;
};
non_null()
static void tox_event_file_recv_construct(Tox_Event_File_Recv *file_recv)
{
*file_recv = (Tox_Event_File_Recv) {
0
};
}
non_null()
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *file_recv)
{
free(file_recv->filename);
}
non_null()
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *file_recv,
uint32_t friend_number)
{
@ -53,6 +56,7 @@ uint32_t tox_event_file_recv_get_friend_number(const Tox_Event_File_Recv *file_r
return file_recv->friend_number;
}
non_null()
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *file_recv,
uint32_t file_number)
{
@ -65,6 +69,7 @@ uint32_t tox_event_file_recv_get_file_number(const Tox_Event_File_Recv *file_rec
return file_recv->file_number;
}
non_null()
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *file_recv,
uint32_t kind)
{
@ -77,6 +82,7 @@ uint32_t tox_event_file_recv_get_kind(const Tox_Event_File_Recv *file_recv)
return file_recv->kind;
}
non_null()
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *file_recv,
uint32_t file_size)
{
@ -89,6 +95,7 @@ uint32_t tox_event_file_recv_get_file_size(const Tox_Event_File_Recv *file_recv)
return file_recv->file_size;
}
non_null()
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv, const uint8_t *filename,
size_t filename_length)
{
@ -121,6 +128,7 @@ const uint8_t *tox_event_file_recv_get_filename(const Tox_Event_File_Recv *file_
return file_recv->filename;
}
non_null()
static void tox_event_file_recv_pack(
const Tox_Event_File_Recv *event, msgpack_packer *mp)
{
@ -134,6 +142,7 @@ static void tox_event_file_recv_pack(
msgpack_pack_bin_body(mp, event->filename, event->filename_length);
}
non_null()
static bool tox_event_file_recv_unpack(
Tox_Event_File_Recv *event, const msgpack_object *obj)
{
@ -158,6 +167,7 @@ static bool tox_event_file_recv_unpack(
*****************************************************/
non_null()
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events)
{
if (events->file_recv_size == UINT32_MAX) {

View File

@ -29,17 +29,20 @@ struct Tox_Event_File_Recv_Chunk {
size_t data_length;
};
non_null()
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *file_recv_chunk)
{
*file_recv_chunk = (Tox_Event_File_Recv_Chunk) {
0
};
}
non_null()
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *file_recv_chunk)
{
free(file_recv_chunk->data);
}
non_null()
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t friend_number)
{
@ -52,6 +55,7 @@ uint32_t tox_event_file_recv_chunk_get_friend_number(const Tox_Event_File_Recv_C
return file_recv_chunk->friend_number;
}
non_null()
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t file_number)
{
@ -64,6 +68,7 @@ uint32_t tox_event_file_recv_chunk_get_file_number(const Tox_Event_File_Recv_Chu
return file_recv_chunk->file_number;
}
non_null()
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t position)
{
@ -76,6 +81,7 @@ uint32_t tox_event_file_recv_chunk_get_position(const Tox_Event_File_Recv_Chunk
return file_recv_chunk->position;
}
non_null()
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_recv_chunk, const uint8_t *data,
size_t data_length)
{
@ -108,6 +114,7 @@ const uint8_t *tox_event_file_recv_chunk_get_data(const Tox_Event_File_Recv_Chun
return file_recv_chunk->data;
}
non_null()
static void tox_event_file_recv_chunk_pack(
const Tox_Event_File_Recv_Chunk *event, msgpack_packer *mp)
{
@ -120,6 +127,7 @@ static void tox_event_file_recv_chunk_pack(
msgpack_pack_bin_body(mp, event->data, event->data_length);
}
non_null()
static bool tox_event_file_recv_chunk_unpack(
Tox_Event_File_Recv_Chunk *event, const msgpack_object *obj)
{
@ -143,6 +151,7 @@ static bool tox_event_file_recv_chunk_unpack(
*****************************************************/
non_null()
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *events)
{
if (events->file_recv_chunk_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_File_Recv_Control {
Tox_File_Control control;
};
non_null()
static void tox_event_file_recv_control_construct(Tox_Event_File_Recv_Control *file_recv_control)
{
*file_recv_control = (Tox_Event_File_Recv_Control) {
0
};
}
non_null()
static void tox_event_file_recv_control_destruct(Tox_Event_File_Recv_Control *file_recv_control)
{
return;
}
non_null()
static void tox_event_file_recv_control_set_friend_number(Tox_Event_File_Recv_Control *file_recv_control,
uint32_t friend_number)
{
@ -50,6 +53,7 @@ uint32_t tox_event_file_recv_control_get_friend_number(const Tox_Event_File_Recv
return file_recv_control->friend_number;
}
non_null()
static void tox_event_file_recv_control_set_file_number(Tox_Event_File_Recv_Control *file_recv_control,
uint32_t file_number)
{
@ -62,6 +66,7 @@ uint32_t tox_event_file_recv_control_get_file_number(const Tox_Event_File_Recv_C
return file_recv_control->file_number;
}
non_null()
static void tox_event_file_recv_control_set_control(Tox_Event_File_Recv_Control *file_recv_control,
Tox_File_Control control)
{
@ -74,6 +79,7 @@ Tox_File_Control tox_event_file_recv_control_get_control(const Tox_Event_File_Re
return file_recv_control->control;
}
non_null()
static void tox_event_file_recv_control_pack(
const Tox_Event_File_Recv_Control *event, msgpack_packer *mp)
{
@ -84,6 +90,7 @@ static void tox_event_file_recv_control_pack(
msgpack_pack_uint32(mp, event->control);
}
non_null()
static bool tox_event_file_recv_control_unpack(
Tox_Event_File_Recv_Control *event, const msgpack_object *obj)
{
@ -106,6 +113,7 @@ static bool tox_event_file_recv_control_unpack(
*****************************************************/
non_null()
static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events *events)
{
if (events->file_recv_control_size == UINT32_MAX) {

View File

@ -26,17 +26,20 @@ struct Tox_Event_Friend_Connection_Status {
Tox_Connection connection_status;
};
non_null()
static void tox_event_friend_connection_status_construct(Tox_Event_Friend_Connection_Status *friend_connection_status)
{
*friend_connection_status = (Tox_Event_Friend_Connection_Status) {
0
};
}
non_null()
static void tox_event_friend_connection_status_destruct(Tox_Event_Friend_Connection_Status *friend_connection_status)
{
return;
}
non_null()
static void tox_event_friend_connection_status_set_friend_number(Tox_Event_Friend_Connection_Status
*friend_connection_status, uint32_t friend_number)
{
@ -50,6 +53,7 @@ uint32_t tox_event_friend_connection_status_get_friend_number(const Tox_Event_Fr
return friend_connection_status->friend_number;
}
non_null()
static void tox_event_friend_connection_status_set_connection_status(Tox_Event_Friend_Connection_Status
*friend_connection_status, Tox_Connection connection_status)
{
@ -63,6 +67,7 @@ Tox_Connection tox_event_friend_connection_status_get_connection_status(const To
return friend_connection_status->connection_status;
}
non_null()
static void tox_event_friend_connection_status_pack(
const Tox_Event_Friend_Connection_Status *event, msgpack_packer *mp)
{
@ -72,6 +77,7 @@ static void tox_event_friend_connection_status_pack(
msgpack_pack_uint32(mp, event->connection_status);
}
non_null()
static bool tox_event_friend_connection_status_unpack(
Tox_Event_Friend_Connection_Status *event, const msgpack_object *obj)
{
@ -93,6 +99,7 @@ static bool tox_event_friend_connection_status_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_status(Tox_Events *events)
{
if (events->friend_connection_status_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_Friend_Lossless_Packet {
size_t data_length;
};
non_null()
static void tox_event_friend_lossless_packet_construct(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet)
{
*friend_lossless_packet = (Tox_Event_Friend_Lossless_Packet) {
0
};
}
non_null()
static void tox_event_friend_lossless_packet_destruct(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet)
{
free(friend_lossless_packet->data);
}
non_null()
static void tox_event_friend_lossless_packet_set_friend_number(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet,
uint32_t friend_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_friend_lossless_packet_get_friend_number(const Tox_Event_Frie
return friend_lossless_packet->friend_number;
}
non_null()
static bool tox_event_friend_lossless_packet_set_data(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet,
const uint8_t *data, size_t data_length)
{
@ -83,6 +87,7 @@ const uint8_t *tox_event_friend_lossless_packet_get_data(const Tox_Event_Friend_
return friend_lossless_packet->data;
}
non_null()
static void tox_event_friend_lossless_packet_pack(
const Tox_Event_Friend_Lossless_Packet *event, msgpack_packer *mp)
{
@ -93,6 +98,7 @@ static void tox_event_friend_lossless_packet_pack(
msgpack_pack_bin_body(mp, event->data, event->data_length);
}
non_null()
static bool tox_event_friend_lossless_packet_unpack(
Tox_Event_Friend_Lossless_Packet *event, const msgpack_object *obj)
{
@ -114,6 +120,7 @@ static bool tox_event_friend_lossless_packet_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(Tox_Events *events)
{
if (events->friend_lossless_packet_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_Friend_Lossy_Packet {
size_t data_length;
};
non_null()
static void tox_event_friend_lossy_packet_construct(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet)
{
*friend_lossy_packet = (Tox_Event_Friend_Lossy_Packet) {
0
};
}
non_null()
static void tox_event_friend_lossy_packet_destruct(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet)
{
free(friend_lossy_packet->data);
}
non_null()
static void tox_event_friend_lossy_packet_set_friend_number(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet,
uint32_t friend_number)
{
@ -50,6 +53,7 @@ uint32_t tox_event_friend_lossy_packet_get_friend_number(const Tox_Event_Friend_
return friend_lossy_packet->friend_number;
}
non_null()
static bool tox_event_friend_lossy_packet_set_data(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet,
const uint8_t *data, size_t data_length)
{
@ -82,6 +86,7 @@ const uint8_t *tox_event_friend_lossy_packet_get_data(const Tox_Event_Friend_Los
return friend_lossy_packet->data;
}
non_null()
static void tox_event_friend_lossy_packet_pack(
const Tox_Event_Friend_Lossy_Packet *event, msgpack_packer *mp)
{
@ -92,6 +97,7 @@ static void tox_event_friend_lossy_packet_pack(
msgpack_pack_bin_body(mp, event->data, event->data_length);
}
non_null()
static bool tox_event_friend_lossy_packet_unpack(
Tox_Event_Friend_Lossy_Packet *event, const msgpack_object *obj)
{
@ -113,6 +119,7 @@ static bool tox_event_friend_lossy_packet_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Events *events)
{
if (events->friend_lossy_packet_size == UINT32_MAX) {

View File

@ -28,17 +28,20 @@ struct Tox_Event_Friend_Message {
size_t message_length;
};
non_null()
static void tox_event_friend_message_construct(Tox_Event_Friend_Message *friend_message)
{
*friend_message = (Tox_Event_Friend_Message) {
0
};
}
non_null()
static void tox_event_friend_message_destruct(Tox_Event_Friend_Message *friend_message)
{
free(friend_message->message);
}
non_null()
static void tox_event_friend_message_set_friend_number(Tox_Event_Friend_Message *friend_message,
uint32_t friend_number)
{
@ -51,6 +54,7 @@ uint32_t tox_event_friend_message_get_friend_number(const Tox_Event_Friend_Messa
return friend_message->friend_number;
}
non_null()
static void tox_event_friend_message_set_type(Tox_Event_Friend_Message *friend_message, Tox_Message_Type type)
{
assert(friend_message != nullptr);
@ -62,6 +66,7 @@ Tox_Message_Type tox_event_friend_message_get_type(const Tox_Event_Friend_Messag
return friend_message->type;
}
non_null()
static bool tox_event_friend_message_set_message(Tox_Event_Friend_Message *friend_message, const uint8_t *message,
size_t message_length)
{
@ -94,6 +99,7 @@ const uint8_t *tox_event_friend_message_get_message(const Tox_Event_Friend_Messa
return friend_message->message;
}
non_null()
static void tox_event_friend_message_pack(
const Tox_Event_Friend_Message *event, msgpack_packer *mp)
{
@ -105,6 +111,7 @@ static void tox_event_friend_message_pack(
msgpack_pack_bin_body(mp, event->message, event->message_length);
}
non_null()
static bool tox_event_friend_message_unpack(
Tox_Event_Friend_Message *event, const msgpack_object *obj)
{
@ -127,6 +134,7 @@ static bool tox_event_friend_message_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *events)
{
if (events->friend_message_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_Friend_Name {
size_t name_length;
};
non_null()
static void tox_event_friend_name_construct(Tox_Event_Friend_Name *friend_name)
{
*friend_name = (Tox_Event_Friend_Name) {
0
};
}
non_null()
static void tox_event_friend_name_destruct(Tox_Event_Friend_Name *friend_name)
{
free(friend_name->name);
}
non_null()
static void tox_event_friend_name_set_friend_number(Tox_Event_Friend_Name *friend_name,
uint32_t friend_number)
{
@ -50,6 +53,7 @@ uint32_t tox_event_friend_name_get_friend_number(const Tox_Event_Friend_Name *fr
return friend_name->friend_number;
}
non_null()
static bool tox_event_friend_name_set_name(Tox_Event_Friend_Name *friend_name, const uint8_t *name,
size_t name_length)
{
@ -82,6 +86,7 @@ const uint8_t *tox_event_friend_name_get_name(const Tox_Event_Friend_Name *frien
return friend_name->name;
}
non_null()
static void tox_event_friend_name_pack(
const Tox_Event_Friend_Name *event, msgpack_packer *mp)
{
@ -92,6 +97,7 @@ static void tox_event_friend_name_pack(
msgpack_pack_bin_body(mp, event->name, event->name_length);
}
non_null()
static bool tox_event_friend_name_unpack(
Tox_Event_Friend_Name *event, const msgpack_object *obj)
{
@ -113,6 +119,7 @@ static bool tox_event_friend_name_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *events)
{
if (events->friend_name_size == UINT32_MAX) {

View File

@ -26,17 +26,20 @@ struct Tox_Event_Friend_Read_Receipt {
uint32_t message_id;
};
non_null()
static void tox_event_friend_read_receipt_construct(Tox_Event_Friend_Read_Receipt *friend_read_receipt)
{
*friend_read_receipt = (Tox_Event_Friend_Read_Receipt) {
0
};
}
non_null()
static void tox_event_friend_read_receipt_destruct(Tox_Event_Friend_Read_Receipt *friend_read_receipt)
{
return;
}
non_null()
static void tox_event_friend_read_receipt_set_friend_number(Tox_Event_Friend_Read_Receipt *friend_read_receipt,
uint32_t friend_number)
{
@ -49,6 +52,7 @@ uint32_t tox_event_friend_read_receipt_get_friend_number(const Tox_Event_Friend_
return friend_read_receipt->friend_number;
}
non_null()
static void tox_event_friend_read_receipt_set_message_id(Tox_Event_Friend_Read_Receipt *friend_read_receipt,
uint32_t message_id)
{
@ -61,6 +65,7 @@ uint32_t tox_event_friend_read_receipt_get_message_id(const Tox_Event_Friend_Rea
return friend_read_receipt->message_id;
}
non_null()
static void tox_event_friend_read_receipt_pack(
const Tox_Event_Friend_Read_Receipt *event, msgpack_packer *mp)
{
@ -70,6 +75,7 @@ static void tox_event_friend_read_receipt_pack(
msgpack_pack_uint32(mp, event->message_id);
}
non_null()
static bool tox_event_friend_read_receipt_unpack(
Tox_Event_Friend_Read_Receipt *event, const msgpack_object *obj)
{
@ -91,6 +97,7 @@ static bool tox_event_friend_read_receipt_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Events *events)
{
if (events->friend_read_receipt_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_Friend_Request {
size_t message_length;
};
non_null()
static void tox_event_friend_request_construct(Tox_Event_Friend_Request *friend_request)
{
*friend_request = (Tox_Event_Friend_Request) {
0
};
}
non_null()
static void tox_event_friend_request_destruct(Tox_Event_Friend_Request *friend_request)
{
free(friend_request->message);
}
non_null()
static bool tox_event_friend_request_set_public_key(Tox_Event_Friend_Request *friend_request, const uint8_t *public_key)
{
assert(friend_request != nullptr);
@ -51,6 +54,7 @@ const uint8_t *tox_event_friend_request_get_public_key(const Tox_Event_Friend_Re
return friend_request->public_key;
}
non_null()
static bool tox_event_friend_request_set_message(Tox_Event_Friend_Request *friend_request, const uint8_t *message,
size_t message_length)
{
@ -83,6 +87,7 @@ const uint8_t *tox_event_friend_request_get_message(const Tox_Event_Friend_Reque
return friend_request->message;
}
non_null()
static void tox_event_friend_request_pack(
const Tox_Event_Friend_Request *event, msgpack_packer *mp)
{
@ -94,6 +99,7 @@ static void tox_event_friend_request_pack(
msgpack_pack_bin_body(mp, event->message, event->message_length);
}
non_null()
static bool tox_event_friend_request_unpack(
Tox_Event_Friend_Request *event, const msgpack_object *obj)
{
@ -115,6 +121,7 @@ static bool tox_event_friend_request_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *events)
{
if (events->friend_request_size == UINT32_MAX) {

View File

@ -26,17 +26,20 @@ struct Tox_Event_Friend_Status {
Tox_User_Status connection_status;
};
non_null()
static void tox_event_friend_status_construct(Tox_Event_Friend_Status *friend_status)
{
*friend_status = (Tox_Event_Friend_Status) {
0
};
}
non_null()
static void tox_event_friend_status_destruct(Tox_Event_Friend_Status *friend_status)
{
return;
}
non_null()
static void tox_event_friend_status_set_friend_number(Tox_Event_Friend_Status *friend_status,
uint32_t friend_number)
{
@ -49,6 +52,7 @@ uint32_t tox_event_friend_status_get_friend_number(const Tox_Event_Friend_Status
return friend_status->friend_number;
}
non_null()
static void tox_event_friend_status_set_connection_status(Tox_Event_Friend_Status *friend_status,
Tox_User_Status connection_status)
{
@ -61,6 +65,7 @@ Tox_User_Status tox_event_friend_status_get_connection_status(const Tox_Event_Fr
return friend_status->connection_status;
}
non_null()
static void tox_event_friend_status_pack(
const Tox_Event_Friend_Status *event, msgpack_packer *mp)
{
@ -70,6 +75,7 @@ static void tox_event_friend_status_pack(
msgpack_pack_uint32(mp, event->connection_status);
}
non_null()
static bool tox_event_friend_status_unpack(
Tox_Event_Friend_Status *event, const msgpack_object *obj)
{
@ -91,6 +97,7 @@ static bool tox_event_friend_status_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *events)
{
if (events->friend_status_size == UINT32_MAX) {

View File

@ -27,17 +27,20 @@ struct Tox_Event_Friend_Status_Message {
size_t status_message_length;
};
non_null()
static void tox_event_friend_status_message_construct(Tox_Event_Friend_Status_Message *friend_status_message)
{
*friend_status_message = (Tox_Event_Friend_Status_Message) {
0
};
}
non_null()
static void tox_event_friend_status_message_destruct(Tox_Event_Friend_Status_Message *friend_status_message)
{
free(friend_status_message->status_message);
}
non_null()
static void tox_event_friend_status_message_set_friend_number(Tox_Event_Friend_Status_Message *friend_status_message,
uint32_t friend_number)
{
@ -50,6 +53,7 @@ uint32_t tox_event_friend_status_message_get_friend_number(const Tox_Event_Frien
return friend_status_message->friend_number;
}
non_null()
static bool tox_event_friend_status_message_set_status_message(Tox_Event_Friend_Status_Message *friend_status_message,
const uint8_t *status_message, size_t status_message_length)
{
@ -84,6 +88,7 @@ const uint8_t *tox_event_friend_status_message_get_status_message(const Tox_Even
return friend_status_message->status_message;
}
non_null()
static void tox_event_friend_status_message_pack(
const Tox_Event_Friend_Status_Message *event, msgpack_packer *mp)
{
@ -94,6 +99,7 @@ static void tox_event_friend_status_message_pack(
msgpack_pack_bin_body(mp, event->status_message, event->status_message_length);
}
non_null()
static bool tox_event_friend_status_message_unpack(
Tox_Event_Friend_Status_Message *event, const msgpack_object *obj)
{
@ -115,6 +121,7 @@ static bool tox_event_friend_status_message_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox_Events *events)
{
if (events->friend_status_message_size == UINT32_MAX) {

View File

@ -26,17 +26,20 @@ struct Tox_Event_Friend_Typing {
bool typing;
};
non_null()
static void tox_event_friend_typing_construct(Tox_Event_Friend_Typing *friend_typing)
{
*friend_typing = (Tox_Event_Friend_Typing) {
0
};
}
non_null()
static void tox_event_friend_typing_destruct(Tox_Event_Friend_Typing *friend_typing)
{
return;
}
non_null()
static void tox_event_friend_typing_set_friend_number(Tox_Event_Friend_Typing *friend_typing,
uint32_t friend_number)
{
@ -49,6 +52,7 @@ uint32_t tox_event_friend_typing_get_friend_number(const Tox_Event_Friend_Typing
return friend_typing->friend_number;
}
non_null()
static void tox_event_friend_typing_set_typing(Tox_Event_Friend_Typing *friend_typing, bool typing)
{
assert(friend_typing != nullptr);
@ -60,6 +64,7 @@ bool tox_event_friend_typing_get_typing(const Tox_Event_Friend_Typing *friend_ty
return friend_typing->typing;
}
non_null()
static void tox_event_friend_typing_pack(
const Tox_Event_Friend_Typing *event, msgpack_packer *mp)
{
@ -74,6 +79,7 @@ static void tox_event_friend_typing_pack(
}
}
non_null()
static bool tox_event_friend_typing_unpack(
Tox_Event_Friend_Typing *event, const msgpack_object *obj)
{
@ -95,6 +101,7 @@ static bool tox_event_friend_typing_unpack(
*****************************************************/
non_null()
static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *events)
{
if (events->friend_typing_size == UINT32_MAX) {

View File

@ -25,17 +25,20 @@ struct Tox_Event_Self_Connection_Status {
Tox_Connection connection_status;
};
non_null()
static void tox_event_self_connection_status_construct(Tox_Event_Self_Connection_Status *self_connection_status)
{
*self_connection_status = (Tox_Event_Self_Connection_Status) {
TOX_CONNECTION_NONE
};
}
non_null()
static void tox_event_self_connection_status_destruct(Tox_Event_Self_Connection_Status *self_connection_status)
{
return;
}
non_null()
static void tox_event_self_connection_status_set_connection_status(Tox_Event_Self_Connection_Status
*self_connection_status, Tox_Connection connection_status)
{
@ -49,6 +52,7 @@ Tox_Connection tox_event_self_connection_status_get_connection_status(const Tox_
return self_connection_status->connection_status;
}
non_null()
static void tox_event_self_connection_status_pack(
const Tox_Event_Self_Connection_Status *event, msgpack_packer *mp)
{
@ -57,6 +61,7 @@ static void tox_event_self_connection_status_pack(
msgpack_pack_uint32(mp, event->connection_status);
}
non_null()
static bool tox_event_self_connection_status_unpack(
Tox_Event_Self_Connection_Status *event, const msgpack_object *obj)
{
@ -77,6 +82,7 @@ static bool tox_event_self_connection_status_unpack(
*****************************************************/
non_null()
static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(Tox_Events *events)
{
if (events->self_connection_status_size == UINT32_MAX) {

View File

@ -95,6 +95,7 @@ const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc)
/** return true if the friendcon_id is valid.
* return false if the friendcon_id is not valid.
*/
non_null()
static bool friendconn_id_valid(const Friend_Connections *fr_c, int friendcon_id)
{
return (unsigned int)friendcon_id < fr_c->num_cons &&
@ -108,6 +109,7 @@ static bool friendconn_id_valid(const Friend_Connections *fr_c, int friendcon_id
* return false if realloc fails.
* return true if it succeeds.
*/
non_null()
static bool realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
{
if (num == 0) {
@ -131,6 +133,7 @@ static bool realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
* return -1 on failure.
* return friendcon_id on success.
*/
non_null()
static int create_friend_conn(Friend_Connections *fr_c)
{
for (uint32_t i = 0; i < fr_c->num_cons; ++i) {
@ -155,6 +158,7 @@ static int create_friend_conn(Friend_Connections *fr_c)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
{
if (!friendconn_id_valid(fr_c, friendcon_id)) {
@ -211,6 +215,7 @@ int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, const IP_Port *ip_port,
const uint8_t *public_key)
{
@ -248,6 +253,7 @@ static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, cons
}
/** Connect to number saved relays for friend. */
non_null()
static void connect_to_saved_tcp_relays(Friend_Connections *fr_c, int friendcon_id, unsigned int number)
{
const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -268,6 +274,7 @@ static void connect_to_saved_tcp_relays(Friend_Connections *fr_c, int friendcon_
}
}
non_null()
static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -305,6 +312,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
}
/** callback for recv TCP relay nodes. */
non_null()
static int tcp_relay_node_callback(void *object, uint32_t number, const IP_Port *ip_port, const uint8_t *public_key)
{
Friend_Connections *fr_c = (Friend_Connections *)object;
@ -321,8 +329,11 @@ static int tcp_relay_node_callback(void *object, uint32_t number, const IP_Port
return add_tcp_relay(fr_c->net_crypto, ip_port, public_key);
}
non_null()
static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id);
/** Callback for DHT ip_port changes. */
non_null()
static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
@ -346,6 +357,7 @@ static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port
}
}
non_null()
static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -369,6 +381,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
}
non_null()
static int handle_status(void *object, int number, uint8_t status, void *userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
@ -416,6 +429,7 @@ static int handle_status(void *object, int number, uint8_t status, void *userdat
}
/** Callback for dht public key changes. */
non_null()
static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
@ -442,6 +456,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
non_null()
static int handle_packet(void *object, int number, const uint8_t *data, uint16_t length, void *userdata)
{
if (length == 0) {
@ -500,6 +515,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t
return 0;
}
non_null()
static int handle_lossy_packet(void *object, int number, const uint8_t *data, uint16_t length, void *userdata)
{
if (length == 0) {
@ -530,6 +546,7 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
return 0;
}
non_null()
static int handle_new_connections(void *object, const New_Connection *n_c)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
@ -602,6 +619,7 @@ static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id)
return 0;
}
non_null()
static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@ -706,6 +724,11 @@ int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id
return -1;
}
if (object != nullptr && (status_callback == nullptr || data_callback == nullptr || lossy_data_callback == nullptr)) {
LOGGER_ERROR(fr_c->logger, "non-null user data object but null callbacks");
return -1;
}
friend_con->callbacks[index].status_callback = status_callback;
friend_con->callbacks[index].data_callback = data_callback;
friend_con->callbacks[index].lossy_data_callback = lossy_data_callback;
@ -719,6 +742,11 @@ int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id
/** Set global status callback for friend connections. */
void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *global_status_callback, void *object)
{
if (object != nullptr && global_status_callback == nullptr) {
LOGGER_ERROR(fr_c->logger, "non-null user data object but null callback");
object = nullptr;
}
fr_c->global_status_callback = global_status_callback;
fr_c->global_status_callback_object = object;
}
@ -894,6 +922,7 @@ Friend_Connections *new_friend_connections(const Logger *logger, const Mono_Time
}
/** Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */
non_null()
static void lan_discovery(Friend_Connections *fr_c)
{
if (fr_c->last_lan_discovery + LAN_DISCOVERY_INTERVAL < mono_time_get(fr_c->mono_time)) {

View File

@ -48,11 +48,12 @@ typedef enum Friendconn_Status {
typedef struct Friend_Connections Friend_Connections;
Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c);
non_null() Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c);
/** return friendcon_id corresponding to the real public key on success.
* return -1 on failure.
*/
non_null()
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.
@ -60,12 +61,14 @@ int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk)
* return 0 on success.
* return -1 on failure.
*/
non_null()
int friend_connection_lock(const Friend_Connections *fr_c, int friendcon_id);
/** return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
* return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* return FRIENDCONN_STATUS_NONE on failure.
*/
non_null()
unsigned int friend_con_connected(const Friend_Connections *fr_c, int friendcon_id);
/** Copy public keys associated to friendcon_id.
@ -73,10 +76,12 @@ unsigned int friend_con_connected(const Friend_Connections *fr_c, int friendcon_
* return 0 on success.
* return -1 on failure.
*/
non_null(3) nullable(1, 2)
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.
*/
non_null()
void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk, void *userdata);
typedef int global_status_cb(void *object, int id, uint8_t status, void *userdata);
@ -86,6 +91,7 @@ typedef int fc_data_cb(void *object, int id, const uint8_t *data, uint16_t lengt
typedef int fc_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
/** Set global status callback for friend connections. */
non_null(1) nullable(2, 3)
void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *global_status_callback, void *object);
/** Set the callbacks for the friend connection.
@ -94,6 +100,7 @@ void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *glob
* return 0 on success.
* return -1 on failure
*/
non_null(1) nullable(4, 5, 6, 7)
int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id, unsigned int index,
fc_status_cb *status_callback,
fc_data_cb *data_callback,
@ -105,6 +112,7 @@ int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id
* return crypt_connection_id on success.
* return -1 on failure.
*/
non_null()
int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int friendcon_id);
/** Create a new friend connection.
@ -113,6 +121,7 @@ int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int fr
* return -1 on failure.
* return connection id on success.
*/
non_null()
int new_friend_connection(Friend_Connections *fr_c, const uint8_t *real_public_key);
/** Kill a friend connection.
@ -120,6 +129,7 @@ int new_friend_connection(Friend_Connections *fr_c, const uint8_t *real_public_k
* return -1 on failure.
* return 0 on success.
*/
non_null()
int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id);
/** Send a Friend request packet.
@ -128,32 +138,37 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id);
* return 0 if it sent the friend request directly to the friend.
* return the number of peers it was routed through if it did not send it directly.
*/
int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *data,
uint16_t length);
non_null()
int send_friend_request_packet(
Friend_Connections *fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *data, uint16_t length);
typedef int fr_request_cb(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t len,
void *userdata);
typedef int fr_request_cb(
void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t len, void *userdata);
/** Set friend request callback.
*
* This function will be called every time a friend request packet is received.
*/
non_null()
void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_request_callback, void *object);
/** Create new friend_connections instance. */
Friend_Connections *new_friend_connections(const Logger *logger, const Mono_Time *mono_time, Onion_Client *onion_c,
bool local_discovery_enabled);
non_null()
Friend_Connections *new_friend_connections(
const Logger *logger, const Mono_Time *mono_time, Onion_Client *onion_c, bool local_discovery_enabled);
/** main friend_connections loop. */
non_null()
void do_friend_connections(Friend_Connections *fr_c, void *userdata);
/** Free everything related with friend_connections. */
non_null()
void kill_friend_connections(Friend_Connections *fr_c);
typedef struct Friend_Conn Friend_Conn;
Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id);
int friend_conn_get_onion_friendnum(const Friend_Conn *fc);
const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc);
non_null() Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id);
non_null() int friend_conn_get_onion_friendnum(const Friend_Conn *fc);
non_null() const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc);
#endif

View File

@ -66,6 +66,7 @@ void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void
}
/** Add to list of received friend requests. */
non_null()
static void addto_receivedlist(Friend_Requests *fr, const uint8_t *real_pk)
{
if (fr->received.requests_index >= MAX_RECEIVED_STORED) {
@ -81,6 +82,7 @@ static void addto_receivedlist(Friend_Requests *fr, const uint8_t *real_pk)
* return false if it did not.
* return true if it did.
*/
non_null()
static bool request_received(const Friend_Requests *fr, const uint8_t *real_pk)
{
for (uint32_t i = 0; i < MAX_RECEIVED_STORED; ++i) {
@ -110,6 +112,7 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk)
}
non_null()
static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length,
void *userdata)
{

View File

@ -16,14 +16,15 @@
typedef struct Friend_Requests Friend_Requests;
/** Set and get the nospam variable used to prevent one type of friend request spam. */
void set_nospam(Friend_Requests *fr, uint32_t num);
uint32_t get_nospam(const Friend_Requests *fr);
non_null() void set_nospam(Friend_Requests *fr, uint32_t num);
non_null() uint32_t get_nospam(const Friend_Requests *fr);
/** Remove real_pk from received_requests list.
*
* return 0 if it removed it successfully.
* return -1 if it didn't find it.
*/
non_null()
int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk);
typedef void fr_friend_request_cb(void *object, const uint8_t *public_key, const uint8_t *message, size_t length,
@ -31,6 +32,7 @@ typedef void fr_friend_request_cb(void *object, const uint8_t *public_key, const
/** Set the function that will be executed when a friend request for us is received.
*/
non_null()
void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object);
typedef int filter_function_cb(const uint8_t *public_key, void *user_data);
@ -38,12 +40,14 @@ typedef int filter_function_cb(const uint8_t *public_key, void *user_data);
/** Set the function used to check if a friend request should be displayed to the user or not.
* It must return 0 if the request is ok (anything else if it is bad.)
*/
non_null()
void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void *userdata);
/** Sets up friendreq packet handlers. */
non_null()
void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c);
Friend_Requests *friendreq_new(void);
void friendreq_kill(Friend_Requests *fr);
non_null() void friendreq_kill(Friend_Requests *fr);
#endif

View File

@ -57,6 +57,7 @@ typedef enum Peer_Id {
static_assert(GROUP_ID_LENGTH == CRYPTO_PUBLIC_KEY_SIZE,
"GROUP_ID_LENGTH should be equal to CRYPTO_PUBLIC_KEY_SIZE");
non_null()
static bool group_id_eq(const uint8_t *a, const uint8_t *b)
{
return public_key_cmp(a, b) == 0;
@ -65,6 +66,7 @@ static bool group_id_eq(const uint8_t *a, const uint8_t *b)
/** return false if the groupnumber is not valid.
* return true if the groupnumber is valid.
*/
non_null()
static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
{
return groupnumber < g_c->num_chats
@ -78,6 +80,7 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
* return false if realloc fails.
* return true if it succeeds.
*/
non_null()
static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
{
if (num == 0) {
@ -96,6 +99,7 @@ static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
return true;
}
non_null()
static void setup_conference(Group_c *g)
{
memset(g, 0, sizeof(Group_c));
@ -108,6 +112,7 @@ static void setup_conference(Group_c *g)
* return -1 on failure.
* return groupnumber on success.
*/
non_null()
static int32_t create_group_chat(Group_Chats *g_c)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
@ -131,6 +136,7 @@ static int32_t create_group_chat(Group_Chats *g_c)
*
* return true on success.
*/
non_null()
static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
{
if (!is_groupnumber_valid(g_c, groupnumber)) {
@ -154,6 +160,7 @@ static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
return true;
}
non_null()
static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber)
{
if (!is_groupnumber_valid(g_c, groupnumber)) {
@ -171,6 +178,7 @@ static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber)
*
* TODO(irungentoo): make this more efficient.
*/
non_null()
static int peer_in_group(const Group_c *g, const uint8_t *real_pk)
{
for (uint32_t i = 0; i < g->numpeers; ++i) {
@ -182,6 +190,7 @@ static int peer_in_group(const Group_c *g, const uint8_t *real_pk)
return -1;
}
non_null()
static int frozen_in_group(const Group_c *g, const uint8_t *real_pk)
{
for (uint32_t i = 0; i < g->numfrozen; ++i) {
@ -201,6 +210,7 @@ static int frozen_in_group(const Group_c *g, const uint8_t *real_pk)
*
* TODO(irungentoo): make this more efficient and maybe use constant time comparisons?
*/
non_null()
static int32_t get_group_num(const Group_Chats *g_c, const uint8_t type, const uint8_t *id)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
@ -231,6 +241,7 @@ int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id)
*
* TODO(irungentoo): make this more efficient.
*/
non_null()
static int get_peer_index(const Group_c *g, uint16_t peer_number)
{
for (uint32_t i = 0; i < g->numpeers; ++i) {
@ -243,6 +254,7 @@ static int get_peer_index(const Group_c *g, uint16_t peer_number)
}
non_null()
static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2)
{
uint64_t cmp1 = 0;
@ -262,6 +274,7 @@ typedef enum Groupchat_Closest_Change {
GROUPCHAT_CLOSEST_CHANGE_REMOVED,
} Groupchat_Closest_Change;
non_null()
static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *temp_pk)
{
if (public_key_cmp(g->real_pk, real_pk) == 0) {
@ -337,6 +350,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te
return true;
}
non_null()
static bool pk_in_closest_peers(const Group_c *g, const uint8_t *real_pk)
{
for (unsigned int i = 0; i < DESIRED_CLOSEST; ++i) {
@ -352,8 +366,10 @@ static bool pk_in_closest_peers(const Group_c *g, const uint8_t *real_pk)
return false;
}
non_null()
static void remove_connection_reason(Group_Chats *g_c, Group_c *g, uint16_t i, uint8_t reason);
non_null()
static void purge_closest(Group_Chats *g_c, uint32_t groupnumber)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -380,12 +396,15 @@ static void purge_closest(Group_Chats *g_c, uint32_t groupnumber)
}
}
non_null()
static int send_packet_online(const Friend_Connections *fr_c, int friendcon_id, uint16_t group_num,
uint8_t type, const uint8_t *id);
non_null()
static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g, uint8_t reason,
uint8_t lock);
non_null(1) nullable(3)
static void add_closest_connections(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -432,6 +451,7 @@ static void add_closest_connections(Group_Chats *g_c, uint32_t groupnumber, void
}
}
non_null(1) nullable(3)
static bool connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -459,6 +479,7 @@ static bool connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *use
return true;
}
non_null()
static int get_frozen_index(const Group_c *g, uint16_t peer_number)
{
for (uint32_t i = 0; i < g->numfrozen; ++i) {
@ -470,6 +491,7 @@ static int get_frozen_index(const Group_c *g, uint16_t peer_number)
return -1;
}
non_null()
static bool delete_frozen(Group_c *g, uint32_t frozen_index)
{
if (frozen_index >= g->numfrozen) {
@ -503,6 +525,7 @@ static bool delete_frozen(Group_c *g, uint32_t frozen_index)
* return peer index if peer is in the conference.
* return -1 otherwise, and on error.
*/
non_null(1) nullable(4)
static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_number, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -558,8 +581,10 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
return thawed_index;
}
non_null(1) nullable(4)
static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata);
non_null(1, 3) nullable(4)
static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -593,6 +618,7 @@ static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, cons
* return peer_index if success or peer already in chat.
* return -1 if error.
*/
non_null(1, 3, 4) nullable(6)
static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk,
uint16_t peer_number, void *userdata, bool fresh, bool do_gc_callback)
{
@ -667,6 +693,7 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
return new_index;
}
non_null()
static void remove_connection(Group_Chats *g_c, Group_c *g, uint16_t i)
{
if (g->connections[i].reasons & GROUPCHAT_CONNECTION_REASON_INTRODUCER) {
@ -677,6 +704,7 @@ static void remove_connection(Group_Chats *g_c, Group_c *g, uint16_t i)
g->connections[i].type = GROUPCHAT_CONNECTION_NONE;
}
non_null()
static void remove_from_closest(Group_c *g, int peer_index)
{
for (uint32_t i = 0; i < DESIRED_CLOSEST; ++i) {
@ -757,6 +785,7 @@ static int cmp_u64(uint64_t a, uint64_t b)
}
/** Order peers with friends first and with more recently active earlier */
non_null()
static int cmp_frozen(const void *a, const void *b)
{
const Group_Peer *pa = (const Group_Peer *)a;
@ -773,6 +802,7 @@ static int cmp_frozen(const void *a, const void *b)
*
* return true if any frozen peers are removed.
*/
non_null()
static bool delete_old_frozen(Group_c *g)
{
if (g->numfrozen <= g->maxfrozen) {
@ -801,8 +831,10 @@ static bool delete_old_frozen(Group_c *g)
return true;
}
non_null()
static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk);
non_null(1) nullable(4)
static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -843,6 +875,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
*
* return true on success.
*/
non_null(1, 4) nullable(6)
static bool setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len,
void *userdata, bool do_gc_callback)
{
@ -881,6 +914,7 @@ static bool setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, cons
*
* return true on success.
*/
non_null(1, 4) nullable(6)
static bool settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *title, uint8_t title_len,
void *userdata)
{
@ -912,6 +946,7 @@ static bool settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, con
}
/** Check if the group has no online connection, and freeze all peers if so */
non_null(1) nullable(3)
static void check_disconnected(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
{
const Group_c *g = get_group_c(g_c, groupnumber);
@ -933,6 +968,7 @@ static void check_disconnected(Group_Chats *g_c, uint32_t groupnumber, void *use
}
}
non_null(1) nullable(5)
static void set_conns_type_connections(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint8_t type,
void *userdata)
{
@ -961,6 +997,7 @@ static void set_conns_type_connections(Group_Chats *g_c, uint32_t groupnumber, i
}
/** Set the type for all connections with friendcon_id */
non_null(1) nullable(4)
static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t type, void *userdata)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
@ -968,6 +1005,7 @@ static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t
}
}
non_null()
static void rejoin_frozen_friend(Group_Chats *g_c, int friendcon_id)
{
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
@ -989,6 +1027,7 @@ static void rejoin_frozen_friend(Group_Chats *g_c, int friendcon_id)
}
}
non_null(1) nullable(4)
static int g_handle_any_status(void *object, int friendcon_id, uint8_t status, void *userdata)
{
Group_Chats *g_c = (Group_Chats *)object;
@ -1000,6 +1039,7 @@ static int g_handle_any_status(void *object, int friendcon_id, uint8_t status, v
return 0;
}
non_null(1) nullable(4)
static int g_handle_status(void *object, int friendcon_id, uint8_t status, void *userdata)
{
Group_Chats *g_c = (Group_Chats *)object;
@ -1014,7 +1054,9 @@ static int g_handle_status(void *object, int friendcon_id, uint8_t status, void
return 0;
}
non_null(1, 3) nullable(5)
static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
non_null(1, 3) nullable(5)
static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
/** Add friend to group chat.
@ -1069,6 +1111,7 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g,
return ind;
}
non_null()
static unsigned int send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
/** Removes reason for keeping connection.
@ -1131,6 +1174,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
return groupnumber;
}
non_null()
static bool group_leave(const Group_Chats *g_c, uint32_t groupnumber, bool permanent);
/** Delete a groupchat from the chats array, informing the group first as
@ -1174,6 +1218,7 @@ int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently
return wipe_group_chat(g_c, groupnumber);
}
non_null()
static const Group_Peer *peer_in_list(const Group_c *g, uint32_t peernumber, bool frozen)
{
const Group_Peer *list = frozen ? g->frozen : g->group;
@ -1386,6 +1431,7 @@ bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id
* return 1 on success
* return 0 on failure
*/
non_null()
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)
{
@ -1407,6 +1453,7 @@ static unsigned int send_packet_group_peer(const Friend_Connections *fr_c, int f
* return 1 on success
* return 0 on failure
*/
non_null()
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)
{
@ -1483,8 +1530,10 @@ static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk
return true;
}
non_null()
static unsigned int send_peer_query(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
non_null()
static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t friendnumber, const uint8_t *data,
uint16_t length);
@ -1693,12 +1742,14 @@ int callback_groupchat_delete(const Group_Chats *g_c, uint32_t groupnumber, grou
return 0;
}
non_null(1) nullable(4)
static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data,
uint16_t len);
/** send a ping message
* return true on success
*/
non_null()
static bool group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
{
if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) {
@ -1711,6 +1762,7 @@ static bool group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
/** send a new_peer message
* return true on success
*/
non_null()
static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk,
const uint8_t *temp_pk)
{
@ -1731,6 +1783,7 @@ static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, ui
/** send a kill_peer message
* return true on success
*/
non_null()
static bool group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num)
{
uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
@ -1748,6 +1801,7 @@ static bool group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, u
/** send a freeze_peer message
* return true on success
*/
non_null()
static bool group_freeze_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num)
{
uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
@ -1765,6 +1819,7 @@ static bool group_freeze_peer_send(const Group_Chats *g_c, uint32_t groupnumber,
/** send a name message
* return true on success
*/
non_null()
static bool group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *nick, uint16_t nick_len)
{
if (nick_len > MAX_NAME_LENGTH) {
@ -1876,6 +1931,7 @@ int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title
return g->title_len;
}
non_null()
static bool get_peer_number(const Group_c *g, const uint8_t *real_pk, uint16_t *peer_number)
{
const int peer_index = peer_in_group(g, real_pk);
@ -1895,6 +1951,7 @@ static bool get_peer_number(const Group_c *g, const uint8_t *real_pk, uint16_t *
return false;
}
non_null(1, 3) nullable(5)
static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -2022,6 +2079,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
* return index on success
* return -1 on failure.
*/
non_null()
static int friend_in_connections(const Group_c *g, int friendcon_id)
{
for (unsigned int i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
@ -2039,6 +2097,7 @@ static int friend_in_connections(const Group_c *g, int friendcon_id)
/** return number of connections.
*/
non_null()
static unsigned int count_connected(const Group_c *g)
{
unsigned int count = 0;
@ -2065,8 +2124,10 @@ static int send_packet_online(const Friend_Connections *fr_c, int friendcon_id,
sizeof(packet), 0) != -1;
}
non_null()
static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber);
non_null()
static int handle_packet_online(const Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length)
{
if (length != ONLINE_PACKET_DATA_SIZE) {
@ -2126,6 +2187,7 @@ static int handle_packet_online(const Group_Chats *g_c, int friendcon_id, const
return 0;
}
non_null(1, 3) nullable(5)
static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -2189,6 +2251,7 @@ static unsigned int send_peer_query(const Group_Chats *g_c, int friendcon_id, ui
/** return number of peers sent on success.
* return 0 on failure.
*/
non_null()
static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int friendcon_id, uint16_t group_num)
{
uint8_t response_packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))];
@ -2239,6 +2302,7 @@ static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int fri
return sent;
}
non_null(1, 3) nullable(5)
static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -2296,6 +2360,7 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8
return 0;
}
non_null(1, 3) nullable(6)
static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
int connection_index, void *userdata)
{
@ -2346,6 +2411,7 @@ static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const u
*
* return number of messages sent.
*/
non_null()
static unsigned int send_message_all_connections(const Group_Chats *g_c, const Group_c *g, const uint8_t *data,
uint16_t length, int receiver)
{
@ -2374,6 +2440,7 @@ static unsigned int send_message_all_connections(const Group_Chats *g_c, const G
*
* return number of messages sent.
*/
non_null()
static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Group_c *g, const uint8_t *data,
uint16_t length, int receiver)
{
@ -2447,6 +2514,7 @@ static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Gro
static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data,
uint16_t len)
{
assert(len == 0 || data != nullptr);
Group_c *g = get_group_c(g_c, groupnumber);
if (!g) {
@ -2476,7 +2544,7 @@ static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint
packet[sizeof(uint16_t) + sizeof(uint32_t)] = message_id;
if (len) {
if (len != 0) {
memcpy(packet + sizeof(uint16_t) + sizeof(uint32_t) + 1, data, len);
}
@ -2548,6 +2616,7 @@ int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const
return 0;
}
non_null()
static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_t message_id, Group_Peer *peer)
{
const bool ignore_older = message_id == GROUP_MESSAGE_NAME_ID || message_id == GROUP_MESSAGE_TITLE_ID;
@ -2576,6 +2645,7 @@ static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_
* return true if message should be processed.
* return false otherwise.
*/
non_null()
static bool check_message_info(uint32_t message_number, uint8_t message_id, Group_Peer *peer)
{
Message_Info *const i = find_message_slot_or_reject(message_number, message_id, peer);
@ -2600,6 +2670,7 @@ static bool check_message_info(uint32_t message_number, uint8_t message_id, Grou
return true;
}
non_null(1, 3) nullable(6)
static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
int connection_index, void *userdata)
{
@ -2831,6 +2902,7 @@ static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data,
*
* TODO(irungentoo): test this
*/
non_null()
static int lossy_packet_not_received(const Group_c *g, int peer_index, uint16_t message_number)
{
if (peer_index == -1) {
@ -3052,6 +3124,7 @@ static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber)
/** Seconds of inactivity after which to freeze a peer */
#define FREEZE_TIMEOUT (GROUP_PING_INTERVAL * 3)
non_null(1) nullable(3)
static bool groupchat_freeze_timedout(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
@ -3078,6 +3151,7 @@ static bool groupchat_freeze_timedout(Group_Chats *g_c, uint32_t groupnumber, vo
}
/** Push non-empty slots to start. */
non_null()
static void squash_connections(Group_c *g)
{
uint16_t num_connected = 0;
@ -3096,6 +3170,7 @@ static void squash_connections(Group_c *g)
#define MIN_EMPTY_CONNECTIONS (1 + MAX_GROUP_CONNECTIONS / 10)
non_null()
static uint16_t empty_connection_count(const Group_c *g)
{
uint16_t to_clear = MIN_EMPTY_CONNECTIONS;
@ -3117,6 +3192,7 @@ static uint16_t empty_connection_count(const Group_c *g)
* connections. This invalidates connections array indices (which is
* why we do this periodically rather than on adding a connection).
*/
non_null()
static void clean_connections(Group_Chats *g_c, Group_c *g)
{
for (uint16_t to_clear = empty_connection_count(g); to_clear > 0; --to_clear) {
@ -3169,11 +3245,13 @@ void send_name_all_groups(const Group_Chats *g_c)
#define SAVED_PEER_SIZE_CONSTANT (2 * CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint16_t) + sizeof(uint64_t) + 1)
non_null()
static uint32_t saved_peer_size(const Group_Peer *peer)
{
return SAVED_PEER_SIZE_CONSTANT + peer->nick_len;
}
non_null()
static uint8_t *save_peer(const Group_Peer *peer, uint8_t *data)
{
memcpy(data, peer->real_pk, CRYPTO_PUBLIC_KEY_SIZE);
@ -3200,6 +3278,7 @@ static uint8_t *save_peer(const Group_Peer *peer, uint8_t *data)
#define SAVED_CONF_SIZE_CONSTANT (1 + GROUP_ID_LENGTH + sizeof(uint32_t) \
+ sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + 1)
non_null()
static uint32_t saved_conf_size(const Group_c *g)
{
uint32_t len = SAVED_CONF_SIZE_CONSTANT + g->title_len;
@ -3222,6 +3301,7 @@ static uint32_t saved_conf_size(const Group_c *g)
#define SAVE_OFFSET_MESSAGE_NUMBER (1 << 16)
#define SAVE_OFFSET_LOSSY_MESSAGE_NUMBER (1 << 13)
non_null()
static uint8_t *save_conf(const Group_c *g, uint8_t *data)
{
*data = g->type;
@ -3266,6 +3346,7 @@ static uint8_t *save_conf(const Group_c *g, uint8_t *data)
return data;
}
non_null()
static uint32_t conferences_section_size(const Group_Chats *g_c)
{
uint32_t len = 0;
@ -3306,6 +3387,7 @@ uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_conferences(Group_Chats *g_c, const uint8_t *data, uint32_t length)
{
const uint8_t *init_data = data;

View File

@ -195,28 +195,34 @@ typedef struct Group_Chats {
} Group_Chats;
/** Set the callback for group invites. */
non_null()
void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function);
/** Set the callback for group connection. */
non_null()
void g_callback_group_connected(Group_Chats *g_c, g_conference_connected_cb *function);
/** Set the callback for group messages. */
non_null()
void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function);
/** Set callback function for title changes. */
non_null()
void g_callback_group_title(Group_Chats *g_c, title_cb *function);
/** Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
*/
non_null()
void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function);
/** Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
*/
non_null()
void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function);
/** Creates a new groupchat and puts it in the chats array.
@ -226,6 +232,7 @@ void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *functi
* return group number on success.
* return -1 on failure.
*/
non_null()
int add_groupchat(Group_Chats *g_c, uint8_t type);
/** Delete a groupchat from the chats array, informing the group first as
@ -234,6 +241,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type);
* return 0 on success.
* return -1 if groupnumber is invalid.
*/
non_null()
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently);
/** Copy the public key of (frozen, if frozen is true) peernumber who is in
@ -243,6 +251,7 @@ int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently
* return -1 if groupnumber is invalid.
* return -2 if peernumber is invalid.
*/
non_null()
int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *pk, bool frozen);
/**
@ -251,6 +260,7 @@ int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, uint32_t pee
* return -1 if groupnumber is invalid.
* return -2 if peernumber is invalid.
*/
non_null()
int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, bool frozen);
/** Copy the name of (frozen, if frozen is true) peernumber who is in
@ -260,7 +270,9 @@ int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, uint32_t p
* return -1 if groupnumber is invalid.
* return -2 if peernumber is invalid.
*/
int group_peername(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *name, bool frozen);
non_null()
int group_peername(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *name,
bool frozen);
/** Copy last active timestamp of frozen peernumber who is in groupnumber to
* last_active.
@ -269,14 +281,16 @@ int group_peername(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernu
* return -1 if groupnumber is invalid.
* return -2 if peernumber is invalid.
*/
int group_frozen_last_active(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber,
uint64_t *last_active);
non_null()
int group_frozen_last_active(
const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint64_t *last_active);
/** Set maximum number of frozen peers.
*
* return 0 on success.
* return -1 if groupnumber is invalid.
*/
non_null()
int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t maxfrozen);
/** invite friendnumber to groupnumber.
@ -286,6 +300,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 -3 if we are not connected to the group chat.
*/
non_null()
int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber);
/** Join a group (we need to have been invited first.)
@ -301,19 +316,22 @@ int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupn
* return -5 if group instance failed to initialize.
* return -6 if join packet fails to send.
*/
int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data,
uint16_t length);
non_null()
int join_groupchat(
Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length);
/** send a group message
* return 0 on success
* see: send_message_group() for error codes.
*/
non_null()
int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length);
/** send a group action
* return 0 on success
* see: send_message_group() for error codes.
*/
non_null()
int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length);
/** set the group's title, limited to MAX_NAME_LENGTH
@ -322,6 +340,7 @@ int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_
* return -2 if title is too long or empty.
* return -3 if packet fails to send.
*/
non_null()
int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len);
@ -329,6 +348,7 @@ int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t
* return -1 of groupnumber is invalid.
* return -2 if title is too long or empty.
*/
non_null()
int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber);
/** Get group title from groupnumber and put it in title.
@ -338,12 +358,14 @@ int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber);
* return -1 if groupnumber is invalid.
* return -2 if title is too long or empty.
*/
non_null()
int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title);
/** Return the number of (frozen, if frozen is true) peers in the group chat on
* success.
* return -1 if groupnumber is invalid.
*/
non_null()
int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen);
/** return 1 if the peernumber corresponds to ours.
@ -352,9 +374,11 @@ int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen
* return -2 if peernumber is invalid.
* return -3 if we are not connected to the group chat.
*/
non_null()
int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber);
/** Set handlers for custom lossy packets. */
non_null()
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function);
/** High level function to send custom lossy packets.
@ -362,12 +386,14 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_pa
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length);
/** Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_chatlist.
*/
non_null()
uint32_t count_chatlist(const Group_Chats *g_c);
/** Copy a list of valid chat IDs into the array out_list.
@ -375,6 +401,7 @@ uint32_t count_chatlist(const Group_Chats *g_c);
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
non_null()
uint32_t copy_chatlist(const Group_Chats *g_c, uint32_t *out_list, uint32_t list_size);
/** return the type of groupchat (GROUPCHAT_TYPE_) that groupnumber is.
@ -382,6 +409,7 @@ uint32_t copy_chatlist(const Group_Chats *g_c, uint32_t *out_list, uint32_t list
* return -1 on failure.
* return type on success.
*/
non_null()
int group_get_type(const Group_Chats *g_c, uint32_t groupnumber);
/** Copies the unique id of `group_chat[groupnumber]` into `id`.
@ -389,12 +417,14 @@ int group_get_type(const Group_Chats *g_c, uint32_t groupnumber);
* return false on failure.
* return true on success.
*/
non_null()
bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id);
int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id);
non_null() int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id);
/** Send current name (set in messenger) to all online groups.
*/
non_null()
void send_name_all_groups(const Group_Chats *g_c);
/** Set the object that is tied to the group chat.
@ -402,6 +432,7 @@ void send_name_all_groups(const Group_Chats *g_c);
* return 0 on success.
* return -1 on failure
*/
non_null(1) nullable(3)
int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object);
/** Set the object that is tied to the group peer.
@ -409,6 +440,7 @@ int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object)
* return 0 on success.
* return -1 on failure
*/
non_null(1) nullable(4)
int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, void *object);
/** Return the object tied to the group chat previously set by group_set_object.
@ -416,6 +448,7 @@ int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
* return NULL on failure.
* return object on success.
*/
non_null()
void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber);
/** Return the object tied to the group chat peer previously set by group_peer_set_object.
@ -423,6 +456,7 @@ void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber);
* return NULL on failure.
* return object on success.
*/
non_null()
void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber);
/** Set a function to be called when a new peer joins a group chat.
@ -430,6 +464,7 @@ void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, uint32
* return 0 on success.
* return -1 on failure.
*/
non_null(1) nullable(3)
int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function);
/** Set a function to be called when a peer leaves a group chat.
@ -437,6 +472,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, pe
* return 0 on success.
* return -1 on failure.
*/
non_null(1) nullable(3)
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.
@ -444,12 +480,15 @@ int callback_groupchat_peer_delete(const Group_Chats *g_c, uint32_t groupnumber,
* return 0 on success.
* return -1 on failure.
*/
non_null(1) nullable(3)
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). */
non_null()
uint32_t conferences_size(const Group_Chats *g_c);
/** Save the conferences in data (must be allocated memory of size at least conferences_size()) */
non_null()
uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data);
/**
@ -461,16 +500,20 @@ uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data);
* @param status Result of loading section is stored here if the section is handled.
* @return true iff section handled.
*/
bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint32_t length, uint16_t type,
State_Load_Status *status);
non_null()
bool conferences_load_state_section(
Group_Chats *g_c, const uint8_t *data, uint32_t length, uint16_t type, State_Load_Status *status);
/** Create new groupchat instance. */
non_null()
Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m);
/** main groupchats loop. */
non_null(1) nullable(2)
void do_groupchats(Group_Chats *g_c, void *userdata);
/** Free everything related with group chats. */
non_null()
void kill_groupchats(Group_Chats *g_c);
#endif

View File

@ -40,6 +40,7 @@ list_index(uint32_t i)
* < 0 : no match, returns index (return value is list_index(index)) where
* the data should be inserted
*/
non_null()
static int find(const BS_List *list, const uint8_t *data)
{
// should work well, but could be improved
@ -105,6 +106,7 @@ static int find(const BS_List *list, const uint8_t *data)
*
* @return true on success.
*/
non_null()
static bool resize(BS_List *list, uint32_t new_size)
{
if (new_size == 0) {

View File

@ -13,6 +13,8 @@
#include <stdint.h>
#include "attributes.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -32,9 +34,11 @@ typedef struct BS_List {
* 1 : success
* 0 : failure
*/
non_null()
int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity);
/** Free a list initiated with list_init */
non_null()
void bs_list_free(BS_List *list);
/** Retrieve the id of an element in the list
@ -43,6 +47,7 @@ void bs_list_free(BS_List *list);
* >= 0 : id associated with data
* -1 : failure
*/
non_null()
int bs_list_find(const BS_List *list, const uint8_t *data);
/** Add an element with associated id to the list
@ -51,6 +56,7 @@ int bs_list_find(const BS_List *list, const uint8_t *data);
* 1 : success
* 0 : failure (data already in list)
*/
non_null()
int bs_list_add(BS_List *list, const uint8_t *data, int id);
/** Remove element from the list
@ -59,6 +65,7 @@ int bs_list_add(BS_List *list, const uint8_t *data, int id);
* 1 : success
* 0 : failure (element not found or id does not match)
*/
non_null()
int bs_list_remove(BS_List *list, const uint8_t *data, int id);
#ifdef __cplusplus

View File

@ -44,6 +44,7 @@ static const char *logger_level_name(Logger_Level level)
return "<unknown>";
}
non_null(1, 3, 5, 6) nullable(7)
static void logger_stderr_handler(void *context, Logger_Level level, const char *file, int line, const char *func,
const char *message, void *userdata)
{

View File

@ -39,12 +39,14 @@ Logger *logger_new(void);
/**
* Frees all resources associated with the logger.
*/
non_null()
void logger_kill(Logger *log);
/**
* Sets the logger callback. Disables logging if set to NULL.
* The context parameter is passed to the callback as first argument.
*/
non_null(1) nullable(2, 3, 4)
void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata);
/**
@ -57,6 +59,7 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
* be built with -DUSE_STDERR_LOGGER for this to work. It will cause an
* assertion failure otherwise.
*/
non_null()
void logger_write(
const Logger *log, Logger_Level level, const char *file, int line, const char *func,
const char *format, ...) GNU_PRINTF(6, 7);

View File

@ -56,6 +56,7 @@ struct Mono_Time {
void *user_data;
};
non_null(1) nullable(2)
static uint64_t current_time_monotonic_default(Mono_Time *mono_time, void *user_data)
{
uint64_t time = 0;
@ -106,6 +107,7 @@ static uint64_t current_time_monotonic_default(Mono_Time *mono_time, void *user_
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
non_null(1) nullable(2)
static uint64_t current_time_monotonic_dummy(Mono_Time *mono_time, void *user_data)
{
return fuzz_get_count();

View File

@ -8,6 +8,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "attributes.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -44,28 +46,32 @@ extern "C" {
typedef struct Mono_Time Mono_Time;
Mono_Time *mono_time_new(void);
void mono_time_free(Mono_Time *mono_time);
non_null() void mono_time_free(Mono_Time *mono_time);
/**
* Update mono_time; subsequent calls to mono_time_get or mono_time_is_timeout
* will use the time at the call to mono_time_update.
*/
non_null()
void mono_time_update(Mono_Time *mono_time);
/**
* Return unix time since epoch in seconds.
*/
non_null()
uint64_t mono_time_get(const Mono_Time *mono_time);
/**
* Return true iff timestamp is at least timeout seconds in the past.
*/
non_null()
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout);
/**
* Return current monotonic time in milliseconds (ms). The starting point is
* unspecified.
*/
non_null()
uint64_t current_time_monotonic(Mono_Time *mono_time);
typedef uint64_t mono_time_current_time_cb(Mono_Time *mono_time, void *user_data);
@ -76,6 +82,7 @@ typedef uint64_t mono_time_current_time_cb(Mono_Time *mono_time, void *user_data
* The caller is obligated to ensure that current_time_monotonic() continues
* to increase monotonically.
*/
non_null(1) nullable(2, 3)
void mono_time_set_current_time_callback(Mono_Time *mono_time,
mono_time_current_time_cb *current_time_callback, void *user_data);

View File

@ -173,6 +173,7 @@ DHT *nc_get_dht(const Net_Crypto *c)
return c->dht;
}
non_null()
static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connection_id)
{
if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) {
@ -210,6 +211,7 @@ static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connecti
* return -1 on failure.
* return COOKIE_REQUEST_LENGTH on success.
*/
non_null()
static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uint8_t *dht_public_key,
uint64_t number, uint8_t *shared_key)
{
@ -241,6 +243,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uin
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int create_cookie(const Mono_Time *mono_time, uint8_t *cookie, const uint8_t *bytes,
const uint8_t *encryption_key)
{
@ -263,6 +266,7 @@ static int create_cookie(const Mono_Time *mono_time, uint8_t *cookie, const uint
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int open_cookie(const Mono_Time *mono_time, uint8_t *bytes, const uint8_t *cookie,
const uint8_t *encryption_key)
{
@ -294,6 +298,7 @@ static int open_cookie(const Mono_Time *mono_time, uint8_t *bytes, const uint8_t
* return -1 on failure.
* return COOKIE_RESPONSE_LENGTH on success.
*/
non_null()
static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const uint8_t *request_plain,
const uint8_t *shared_key, const uint8_t *dht_public_key)
{
@ -325,6 +330,7 @@ static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const ui
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key,
uint8_t *dht_public_key, const uint8_t *packet, uint16_t length)
{
@ -347,6 +353,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
/** Handle the cookie request packet (for raw UDP)
*/
non_null(1, 2, 3) nullable(5)
static int udp_handle_cookie_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -374,6 +381,7 @@ static int udp_handle_cookie_request(void *object, const IP_Port *source, const
/** Handle the cookie request packet (for TCP)
*/
non_null()
static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number, const uint8_t *packet,
uint16_t length)
{
@ -397,6 +405,7 @@ static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number
/** Handle the cookie request packet (for TCP oob packets)
*/
non_null()
static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_connections_number,
const uint8_t *dht_public_key, const uint8_t *packet, uint16_t length)
{
@ -430,6 +439,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.
*/
non_null()
static int handle_cookie_response(uint8_t *cookie, uint64_t *number,
const uint8_t *packet, uint16_t length,
const uint8_t *shared_key)
@ -460,6 +470,7 @@ static int handle_cookie_response(uint8_t *cookie, uint64_t *number,
* return -1 on failure.
* return HANDSHAKE_PACKET_LENGTH on success.
*/
non_null()
static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const uint8_t *cookie, const uint8_t *nonce,
const uint8_t *session_pk, const uint8_t *peer_real_pk, const uint8_t *peer_dht_pubkey)
{
@ -508,6 +519,7 @@ static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const u
* return -1 on failure.
* return 0 on success.
*/
non_null(1, 2, 3, 4, 5, 6, 7) nullable(9)
static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint16_t length, const uint8_t *expected_real_pk)
{
@ -521,7 +533,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
return -1;
}
if (expected_real_pk && public_key_cmp(cookie_plain, expected_real_pk) != 0) {
if (expected_real_pk != nullptr && public_key_cmp(cookie_plain, expected_real_pk) != 0) {
return -1;
}
@ -550,6 +562,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
}
non_null()
static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
{
if (!crypt_connection_id_is_valid(c, crypt_connection_id)) {
@ -565,6 +578,7 @@ static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_c
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -603,6 +617,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, const
* return IP_Port with family 0 on failure.
* return IP_Port on success.
*/
non_null()
static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connection_id)
{
const IP_Port empty = {0};
@ -660,6 +675,7 @@ static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connecti
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
{
// TODO(irungentoo): TCP, etc...
@ -730,6 +746,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
/** Return number of packets in array
* Note that holes are counted too.
*/
non_null()
static uint32_t num_packets_array(const Packets_Array *array)
{
return array->buffer_end - array->buffer_start;
@ -740,6 +757,7 @@ static uint32_t num_packets_array(const Packets_Array *array)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packet_Data *data)
{
if (number - array->buffer_start >= CRYPTO_PACKET_BUFFER_SIZE) {
@ -774,6 +792,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe
* return 0 if data at number is empty.
* return 1 if data pointer was put in data.
*/
non_null()
static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number)
{
const uint32_t num_spots = num_packets_array(array);
@ -797,6 +816,7 @@ static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint
* return -1 on failure.
* return packet number on success.
*/
non_null()
static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *data)
{
const uint32_t num_spots = num_packets_array(array);
@ -823,6 +843,7 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d
* return -1 on failure.
* return packet number on success.
*/
non_null()
static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data)
{
if (array->buffer_end == array->buffer_start) {
@ -848,6 +869,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data)
* return -1 on failure.
* return 0 on success
*/
non_null()
static int clear_buffer_until(Packets_Array *array, uint32_t number)
{
const uint32_t num_spots = num_packets_array(array);
@ -871,6 +893,7 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number)
return 0;
}
non_null()
static int clear_buffer(Packets_Array *array)
{
uint32_t i;
@ -893,6 +916,7 @@ static int clear_buffer(Packets_Array *array)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int set_buffer_end(Packets_Array *array, uint32_t number)
{
if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) {
@ -913,6 +937,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number)
* return -1 on failure.
* return length of packet on success.
*/
non_null()
static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array)
{
if (length == 0) {
@ -966,6 +991,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets
* return -1 on failure.
* return number of requested packets on success.
*/
non_null()
static int handle_request_packet(Mono_Time *mono_time, Packets_Array *send_array,
const uint8_t *data, uint16_t length,
uint64_t *latest_send_time, uint64_t rtt_time)
@ -1048,6 +1074,7 @@ static int handle_request_packet(Mono_Time *mono_time, Packets_Array *send_array
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
{
const uint16_t max_length = MAX_CRYPTO_PACKET_SIZE - (1 + sizeof(uint16_t) + CRYPTO_MAC_SIZE);
@ -1088,6 +1115,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
const uint8_t *data, uint16_t length)
{
@ -1108,6 +1136,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3
return send_data_packet(c, crypt_connection_id, packet, SIZEOF_VLA(packet));
}
non_null()
static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1141,6 +1170,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
/** return -1 if data could not be put in packet queue.
* return positive packet number if data was put into the queue.
*/
non_null()
static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length,
uint8_t congestion_control)
{
@ -1195,6 +1225,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
/** Get the lowest 2 bytes from the nonce and convert
* them to host byte format before returning them.
*/
non_null()
static uint16_t get_nonce_uint16(const uint8_t *nonce)
{
uint16_t num;
@ -1211,6 +1242,7 @@ static uint16_t get_nonce_uint16(const uint8_t *nonce)
* return -1 on failure.
* return length of data on success.
*/
non_null()
static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet,
uint16_t length)
{
@ -1252,6 +1284,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1276,6 +1309,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return number of packets sent on success.
*/
non_null()
static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32_t max_num)
{
if (max_num == 0) {
@ -1329,6 +1363,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
@ -1364,6 +1399,7 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1389,6 +1425,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1416,6 +1453,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie,
const uint8_t *dht_public_key)
{
@ -1445,6 +1483,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const u
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1458,6 +1497,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
&kill_packet, sizeof(kill_packet));
}
non_null(1) nullable(3)
static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userdata)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1490,6 +1530,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
* return -1 on failure.
* return 0 on success.
*/
non_null(1, 3) nullable(6)
static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
{
@ -1632,6 +1673,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
return 0;
}
non_null()
static int handle_packet_cookie_response(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1663,6 +1705,7 @@ static int handle_packet_cookie_response(Net_Crypto *c, int crypt_connection_id,
return 0;
}
non_null(1, 3) nullable(5)
static int handle_packet_crypto_hs(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -1706,6 +1749,7 @@ static int handle_packet_crypto_hs(Net_Crypto *c, int crypt_connection_id, const
return 0;
}
non_null(1, 3) nullable(6)
static int handle_packet_crypto_data(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
{
@ -1727,6 +1771,7 @@ static int handle_packet_crypto_data(Net_Crypto *c, int crypt_connection_id, con
* return -1 on failure.
* return 0 on success.
*/
non_null(1, 3) nullable(6)
static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
{
@ -1754,6 +1799,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
* return -1 if realloc fails.
* return 0 if it succeeds.
*/
non_null()
static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
{
if (num == 0) {
@ -1779,6 +1825,7 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
* return -1 on failure.
* return connection id on success.
*/
non_null()
static int create_crypto_connection(Net_Crypto *c)
{
while (1) { /* TODO(irungentoo): is this really the best way to do this? */
@ -1840,6 +1887,7 @@ static int create_crypto_connection(Net_Crypto *c)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
{
if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) {
@ -1882,6 +1930,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
* return -1 if there are no connections like we are looking for.
* return id if it found it.
*/
non_null()
static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
{
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
@ -1904,6 +1953,7 @@ static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
* return positive number on success.
* 0 if source was a direct UDP connection.
*/
non_null()
static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, const IP_Port *source)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1954,6 +2004,7 @@ void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_cal
* return -1 on failure.
* return 0 on success.
*/
non_null(1, 2, 3) nullable(5)
static int handle_new_connection_handshake(Net_Crypto *c, const IP_Port *source, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -2161,6 +2212,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
}
non_null(1, 3) nullable(5)
static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -2194,6 +2246,7 @@ static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_
return 0;
}
non_null(1, 2, 4) nullable(6)
static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length, void *userdata)
{
@ -2305,6 +2358,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u
return ret;
}
non_null()
static void do_tcp(Net_Crypto *c, void *userdata)
{
pthread_mutex_lock(&c->tcp_mutex);
@ -2436,6 +2490,7 @@ int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id, dht_pk_cb *
* return -1 on failure.
* return connection id on success.
*/
non_null()
static int crypto_id_ip_port(const Net_Crypto *c, const IP_Port *ip_port)
{
return bs_list_find(&c->ip_port_list, (const uint8_t *)ip_port);
@ -2451,6 +2506,7 @@ static int crypto_id_ip_port(const Net_Crypto *c, const IP_Port *ip_port)
* Crypto data packets.
*
*/
non_null(1, 2, 3) nullable(5)
static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -2514,6 +2570,7 @@ static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t
*/
#define SEND_QUEUE_RATIO 2.0
non_null()
static void send_crypto_packets(Net_Crypto *c)
{
const uint64_t temp_time = current_time_monotonic(c->mono_time);
@ -3035,6 +3092,7 @@ Net_Crypto *new_net_crypto(const Logger *log, Mono_Time *mono_time, DHT *dht, co
return temp;
}
non_null(1) nullable(2)
static void kill_timedout(Net_Crypto *c, void *userdata)
{
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {

View File

@ -110,10 +110,10 @@
typedef struct Net_Crypto Net_Crypto;
const uint8_t *nc_get_self_public_key(const Net_Crypto *c);
const uint8_t *nc_get_self_secret_key(const Net_Crypto *c);
TCP_Connections *nc_get_tcp_c(const Net_Crypto *c);
DHT *nc_get_dht(const Net_Crypto *c);
non_null() const uint8_t *nc_get_self_public_key(const Net_Crypto *c);
non_null() const uint8_t *nc_get_self_secret_key(const Net_Crypto *c);
non_null() TCP_Connections *nc_get_tcp_c(const Net_Crypto *c);
non_null() DHT *nc_get_dht(const Net_Crypto *c);
typedef struct New_Connection {
IP_Port source;
@ -137,6 +137,7 @@ typedef int new_connection_cb(void *object, const New_Connection *n_c);
*
* n_c is only valid for the duration of the function call.
*/
non_null()
void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_callback, void *object);
/** Accept a crypto connection.
@ -144,6 +145,7 @@ void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_cal
* return -1 on failure.
* return connection id on success.
*/
non_null()
int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c);
/** Create a crypto connection.
@ -152,6 +154,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c);
* return -1 on failure.
* return connection id on success.
*/
non_null()
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const uint8_t *dht_public_key);
/** Set the direct ip of the crypto connection.
@ -161,6 +164,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
* return -1 on failure.
* return 0 on success.
*/
non_null()
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port, bool connected);
/** Set function to be called when connection with crypt_connection_id goes connects/disconnects.
@ -173,6 +177,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
* return -1 on failure.
* return 0 on success.
*/
non_null()
int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
connection_status_cb *connection_status_callback, void *object, int id);
@ -184,6 +189,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
non_null()
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
connection_data_cb *connection_data_callback, void *object, int id);
@ -196,6 +202,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
non_null()
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);
@ -209,17 +216,20 @@ int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object,
uint32_t number);
non_null()
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.
* return 0 if failure.
*/
non_null()
uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id);
/** Return 1 if max speed was reached for this connection (no more data can be physically through the pipe).
* Return 0 if it wasn't reached.
*/
non_null()
bool max_speed_reached(Net_Crypto *c, int crypt_connection_id);
/** Sends a lossless cryptopacket.
@ -231,8 +241,9 @@ bool max_speed_reached(Net_Crypto *c, int crypt_connection_id);
*
* congestion_control: should congestion control apply to this packet?
*/
int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length,
uint8_t congestion_control);
non_null()
int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id,
const uint8_t *data, uint16_t length, uint8_t congestion_control);
/** Check if packet_number was received by the other side.
*
@ -248,6 +259,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
* when `buffer_end < buffer_start`.
*/
non_null()
int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t packet_number);
/** Sends a lossy cryptopacket.
@ -257,6 +269,7 @@ int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t
*
* The first byte of data must be in the PACKET_ID_RANGE_LOSSY.
*/
non_null()
int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length);
/** Add a tcp relay, associating it to a crypt_connection_id.
@ -264,13 +277,16 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
* return 0 if it was added.
* return -1 if it wasn't.
*/
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port, const uint8_t *public_key);
non_null()
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port,
const uint8_t *public_key);
/** Add a tcp relay to the array.
*
* return 0 if it was added.
* return -1 if it wasn't.
*/
non_null()
int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_key);
/** Return a random TCP connection number for use in send_tcp_onion_request.
@ -281,6 +297,7 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k
* return TCP connection number on success.
* return -1 on failure.
*/
non_null()
int get_random_tcp_con_number(Net_Crypto *c);
/** Send an onion packet via the TCP relay corresponding to tcp_connections_number.
@ -288,7 +305,9 @@ int get_random_tcp_con_number(Net_Crypto *c);
* return 0 on success.
* return -1 on failure.
*/
int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length);
non_null()
int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length);
/** Copy a maximum of num TCP relays we are connected to to tcp_relays.
* NOTE that the family of the copied ip ports will be set to TCP_INET or TCP_INET6.
@ -296,6 +315,7 @@ int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number, c
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
non_null()
unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
/** Kill a crypto connection.
@ -303,6 +323,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u
* return -1 on failure.
* return 0 on success.
*/
non_null()
int crypto_kill(Net_Crypto *c, int crypt_connection_id);
/** return true if connection is valid, false otherwise
@ -310,12 +331,14 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
* sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
* sets online_tcp_relays to the number of connected tcp relays this connection has.
*/
bool crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
unsigned int *online_tcp_relays);
non_null(1, 3) nullable(4)
bool crypto_connection_status(
const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, unsigned int *online_tcp_relays);
/** Generate our public and private keys.
* Only call this function the first time the program starts.
*/
non_null()
void new_keys(Net_Crypto *c);
/** Save the public and private keys to the keys array.
@ -323,27 +346,30 @@ void new_keys(Net_Crypto *c);
*
* TODO(irungentoo): Save only secret key.
*/
non_null()
void save_keys(const Net_Crypto *c, uint8_t *keys);
/** Load the secret key.
* Length must be CRYPTO_SECRET_KEY_SIZE.
*/
non_null()
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.
*/
non_null()
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.
*/
non_null()
uint32_t crypto_run_interval(const Net_Crypto *c);
/** Main loop. */
non_null(1) nullable(2)
void do_net_crypto(Net_Crypto *c, void *userdata);
void kill_net_crypto(Net_Crypto *c);
non_null() void kill_net_crypto(Net_Crypto *c);
#endif

View File

@ -120,21 +120,25 @@ static bool should_ignore_recv_error(int err)
return err == EWOULDBLOCK;
}
non_null()
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
{
return inet_ntop(AF_INET, addr, buf, bufsize);
}
non_null()
static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t bufsize)
{
return inet_ntop(AF_INET6, addr, buf, bufsize);
}
non_null()
static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
{
return inet_pton(AF_INET, addrString, addrbuf);
}
non_null()
static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
{
return inet_pton(AF_INET6, addrString, addrbuf);
@ -152,6 +156,7 @@ static bool should_ignore_recv_error(int err)
return err == WSAEWOULDBLOCK || err == WSAECONNRESET;
}
non_null()
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
{
struct sockaddr_in saddr = {0};
@ -168,6 +173,7 @@ static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufs
return buf;
}
non_null()
static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t bufsize)
{
struct sockaddr_in6 saddr = {0};
@ -184,6 +190,7 @@ static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t buf
return buf;
}
non_null()
static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
{
struct sockaddr_in saddr = {0};
@ -199,6 +206,7 @@ static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
return 1;
}
non_null()
static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
{
struct sockaddr_in6 saddr = {0};
@ -285,22 +293,26 @@ static const Family *make_tox_family(int family)
}
}
non_null()
static void get_ip4(IP4 *result, const struct in_addr *addr)
{
result->uint32 = addr->s_addr;
}
non_null()
static void get_ip6(IP6 *result, const struct in6_addr *addr)
{
assert(sizeof(result->uint8) == sizeof(addr->s6_addr));
memcpy(result->uint8, addr->s6_addr, sizeof(result->uint8));
}
non_null()
static void fill_addr4(const IP4 *ip, struct in_addr *addr)
{
addr->s_addr = ip->uint32;
}
non_null()
static void fill_addr6(const IP6 *ip, struct in6_addr *addr)
{
assert(sizeof(ip->uint8) == sizeof(addr->s6_addr));
@ -464,6 +476,7 @@ bool set_socket_dualstack(Socket sock)
}
non_null()
static uint32_t data_0(uint16_t buflen, const uint8_t *buffer)
{
uint32_t data = 0;
@ -474,6 +487,7 @@ static uint32_t data_0(uint16_t buflen, const uint8_t *buffer)
return data;
}
non_null()
static uint32_t data_1(uint16_t buflen, const uint8_t *buffer)
{
uint32_t data = 0;
@ -485,6 +499,7 @@ static uint32_t data_1(uint16_t buflen, const uint8_t *buffer)
return data;
}
non_null()
static void loglogdata(const Logger *log, const char *message, const uint8_t *buffer,
uint16_t buflen, const IP_Port *ip_port, long res)
{
@ -632,6 +647,7 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
* Packet data is put into data.
* Packet length is put into length.
*/
non_null()
static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length)
{
memset(ip_port, 0, sizeof(IP_Port));

View File

@ -164,10 +164,12 @@ extern const Socket net_invalid_socket;
/**
* Calls send(sockfd, buf, len, MSG_NOSIGNAL).
*/
non_null()
int net_send(const Logger *log, Socket sock, const uint8_t *buf, size_t len, const IP_Port *ip_port);
/**
* Calls recv(sockfd, buf, len, MSG_NOSIGNAL).
*/
non_null()
int net_recv(const Logger *log, Socket sock, uint8_t *buf, size_t len, const IP_Port *ip_port);
/**
* Calls listen(sockfd, backlog).
@ -191,15 +193,22 @@ uint16_t net_htons(uint16_t hostshort);
uint32_t net_ntohl(uint32_t hostlong);
uint16_t net_ntohs(uint16_t hostshort);
non_null()
size_t net_pack_u16(uint8_t *bytes, uint16_t v);
non_null()
size_t net_pack_u32(uint8_t *bytes, uint32_t v);
non_null()
size_t net_pack_u64(uint8_t *bytes, uint64_t v);
non_null()
size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v);
non_null()
size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v);
non_null()
size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v);
/** Does the IP6 struct a contain an IPv4 address in an IPv6 one? */
non_null()
bool ipv6_ipv4_in_v6(const IP6 *a);
#define TOX_ENABLE_IPV6_DEFAULT true
@ -221,6 +230,7 @@ bool ipv6_ipv4_in_v6(const IP6 *a);
*
* returns ip_str
*/
non_null()
const char *ip_ntoa(const IP *ip, char *ip_str, size_t length);
/**
@ -235,6 +245,7 @@ const char *ip_ntoa(const IP *ip, char *ip_str, size_t length);
*
* @return true on success, false on failure.
*/
non_null()
bool ip_parse_addr(const IP *ip, char *address, size_t length);
/**
@ -247,6 +258,7 @@ bool ip_parse_addr(const IP *ip, char *address, size_t length);
*
* @return true on success, false on failure.
*/
non_null()
bool addr_parse_ip(const char *address, IP *to);
/**
@ -256,6 +268,7 @@ bool addr_parse_ip(const char *address, IP *to);
*
* @return false when not equal or when uninitialized.
*/
nullable(1, 2)
bool ip_equal(const IP *a, const IP *b);
/**
@ -265,21 +278,29 @@ bool ip_equal(const IP *a, const IP *b);
*
* @return false when not equal or when uninitialized.
*/
nullable(1, 2)
bool ipport_equal(const IP_Port *a, const IP_Port *b);
/** nulls out ip */
non_null()
void ip_reset(IP *ip);
/** nulls out ip_port */
non_null()
void ipport_reset(IP_Port *ipport);
/** nulls out ip, sets family according to flag */
non_null()
void ip_init(IP *ip, bool ipv6enabled);
/** checks if ip is valid */
non_null()
bool ip_isset(const IP *ip);
/** checks if ip is valid */
non_null()
bool ipport_isset(const IP_Port *ipport);
/** copies an ip structure (careful about direction!) */
non_null()
void ip_copy(IP *target, const IP *source);
/** copies an ip_port structure (careful about direction!) */
non_null()
void ipport_copy(IP_Port *target, const IP_Port *source);
/**
@ -299,6 +320,7 @@ void ipport_copy(IP_Port *target, const IP_Port *source);
*
* @return 0 on failure, `TOX_ADDR_RESOLVE_*` on success.
*/
non_null(1, 2) nullable(3)
int addr_resolve(const char *address, IP *to, IP *extra);
/**
@ -315,6 +337,7 @@ int addr_resolve(const char *address, IP *to, IP *extra);
*
* @return true on success, false on failure
*/
non_null(1, 2) nullable(3)
bool addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra);
/** Function to receive data, ip and port of sender is put into ip_port.
@ -325,7 +348,9 @@ typedef int packet_handler_cb(void *object, const IP_Port *ip_port, const uint8_
typedef struct Networking_Core Networking_Core;
non_null()
Family net_family(const Networking_Core *net);
non_null()
uint16_t net_port(const Networking_Core *net);
/** Run this before creating sockets.
@ -382,6 +407,7 @@ typedef struct Packet {
/**
* Function to send a network packet to a given IP/port.
*/
non_null()
int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packet);
/**
@ -389,12 +415,15 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
*
* @deprecated Use send_packet instead.
*/
non_null()
int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t *data, uint16_t length);
/** Function to call when packet beginning with byte is received. */
non_null(1) nullable(3, 4)
void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_cb *cb, void *object);
/** Call this several times a second. */
non_null(1) nullable(2)
void networking_poll(const Networking_Core *net, void *userdata);
/** Connect a socket to the address specified by the ip_port.
@ -402,6 +431,7 @@ void networking_poll(const Networking_Core *net, void *userdata);
* Return 0 on success.
* Return -1 on failure.
*/
non_null()
int net_connect(const Logger *log, Socket sock, const IP_Port *ip_port);
/** High-level getaddrinfo implementation.
@ -415,10 +445,12 @@ int net_connect(const Logger *log, Socket sock, const IP_Port *ip_port);
* return number of elements in res array
* and -1 on error.
*/
non_null()
int32_t net_getipport(const char *node, IP_Port **res, int tox_type);
/** Deallocates memory allocated by net_getipport
*/
nullable(1)
void net_freeipport(IP_Port *ip_ports);
/**
@ -452,11 +484,13 @@ char *net_new_strerror(int error);
* It's valid to pass NULL as the argument, the function does nothing in this
* case.
*/
non_null()
void net_kill_strerror(char *strerror);
/** Initialize networking.
* Added for reverse compatibility with old new_networking calls.
*/
non_null()
Networking_Core *new_networking(const Logger *log, const IP *ip, uint16_t port);
/** Initialize networking.
* Bind to ip and port.
@ -468,11 +502,14 @@ Networking_Core *new_networking(const Logger *log, const IP *ip, uint16_t port);
*
* If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other.
*/
non_null(1, 2) nullable(5)
Networking_Core *new_networking_ex(const Logger *log, const IP *ip, uint16_t port_from, uint16_t port_to,
unsigned int *error);
non_null()
Networking_Core *new_networking_no_udp(const Logger *log);
/** Function to cleanup networking stuff (doesn't do much right now). */
non_null()
void kill_networking(Networking_Core *net);
#ifdef __cplusplus

View File

@ -25,6 +25,7 @@
#define KEY_REFRESH_INTERVAL (2 * 60 * 60)
/** Change symmetric keys every 2 hours to make paths expire eventually. */
non_null()
static void change_symmetric_key(Onion *onion)
{
if (mono_time_is_timeout(onion->mono_time, onion->timestamp, KEY_REFRESH_INTERVAL)) {
@ -34,6 +35,7 @@ static void change_symmetric_key(Onion *onion)
}
/** packing and unpacking functions */
non_null()
static void ip_pack(uint8_t *data, const IP *source)
{
data[0] = source->family.value;
@ -47,6 +49,7 @@ static void ip_pack(uint8_t *data, const IP *source)
}
/** return 0 on success, -1 on failure. */
non_null()
static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bool disable_family_check)
{
if (data_size < (1 + SIZE_IP6)) {
@ -69,6 +72,7 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bo
return valid ? 0 : -1;
}
non_null()
static void ipport_pack(uint8_t *data, const IP_Port *source)
{
ip_pack(data, &source->ip);
@ -76,6 +80,7 @@ static void ipport_pack(uint8_t *data, const IP_Port *source)
}
/** return 0 on success, -1 on failure. */
non_null()
static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size, bool disable_family_check)
{
if (data_size < (SIZE_IP + SIZE_PORT)) {
@ -312,6 +317,7 @@ int send_onion_response(const Networking_Core *net, const IP_Port *dest, const u
return 0;
}
non_null()
static int handle_send_initial(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -383,6 +389,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, const I
return 0;
}
non_null()
static int handle_send_1(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
@ -440,6 +447,7 @@ static int handle_send_1(void *object, const IP_Port *source, const uint8_t *pac
return 0;
}
non_null()
static int handle_send_2(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
@ -506,6 +514,7 @@ static int handle_send_2(void *object, const IP_Port *source, const uint8_t *pac
}
non_null()
static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
@ -553,6 +562,7 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac
return 0;
}
non_null()
static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
@ -600,6 +610,7 @@ static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *pac
return 0;
}
non_null()
static int handle_recv_1(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;

View File

@ -77,6 +77,7 @@ typedef struct Onion_Path {
* return -1 on failure.
* return 0 on success.
*/
non_null()
int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *nodes);
/** Dump nodes in onion path to nodes of length num_nodes.
@ -84,6 +85,7 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
* return -1 on failure.
* return 0 on success.
*/
non_null()
int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path);
/** Create a onion packet.
@ -95,6 +97,7 @@ int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_
* return -1 on failure.
* return length of created packet on success.
*/
non_null()
int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, const IP_Port *dest,
const uint8_t *data, uint16_t length);
@ -108,6 +111,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion
* return -1 on failure.
* return length of created packet on success.
*/
non_null()
int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, const IP_Port *dest,
const uint8_t *data, uint16_t length);
@ -119,6 +123,7 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_onion_packet(const Networking_Core *net, const Onion_Path *path, const IP_Port *dest, const uint8_t *data,
uint16_t length);
@ -128,6 +133,7 @@ int send_onion_packet(const Networking_Core *net, const Onion_Path *path, const
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_onion_response(const Networking_Core *net, const IP_Port *dest, const uint8_t *data, uint16_t length,
const uint8_t *ret);
@ -141,14 +147,18 @@ int send_onion_response(const Networking_Core *net, const IP_Port *dest, const u
* Source family must be set to something else than TOX_AF_INET6 or TOX_AF_INET so that the callback gets called
* when the response is received.
*/
non_null()
int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, const IP_Port *source, const uint8_t *nonce);
/** Set the callback to be called when the dest ip_port doesn't have TOX_AF_INET6 or TOX_AF_INET as the family.
*/
non_null(1) nullable(2, 3)
void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *object);
non_null()
Onion *new_onion(const Logger *log, Mono_Time *mono_time, DHT *dht);
non_null()
void kill_onion(Onion *onion);

View File

@ -45,6 +45,7 @@ struct Onion_Announce {
Shared_Keys shared_keys_recv;
};
non_null()
static bool onion_ping_id_eq(const uint8_t *a, const uint8_t *b)
{
return public_key_cmp(a, b) == 0;
@ -229,6 +230,7 @@ int send_data_request(const Networking_Core *net, const Onion_Path *path, const
}
/** Generate a ping_id and put it in ping_id */
non_null()
static void generate_ping_id(const Onion_Announce *onion_a, uint64_t time, const uint8_t *public_key,
const IP_Port *ret_ip_port, uint8_t *ping_id)
{
@ -246,6 +248,7 @@ static void generate_ping_id(const Onion_Announce *onion_a, uint64_t time, const
* return -1 if no
* return position in list if yes
*/
non_null()
static int in_entries(const Onion_Announce *onion_a, const uint8_t *public_key)
{
for (unsigned int i = 0; i < ONION_ANNOUNCE_MAX_ENTRIES; ++i) {
@ -264,6 +267,7 @@ typedef struct Cmp_Data {
Onion_Announce_Entry entry;
} Cmp_Data;
non_null()
static int cmp_entry(const void *a, const void *b)
{
const Cmp_Data *cmp1 = (const Cmp_Data *)a;
@ -300,6 +304,7 @@ static int cmp_entry(const void *a, const void *b)
return 0;
}
non_null()
static void sort_onion_announce_list(Onion_Announce_Entry *list, unsigned int length, const Mono_Time *mono_time,
const uint8_t *comp_public_key)
{
@ -325,6 +330,7 @@ static void sort_onion_announce_list(Onion_Announce_Entry *list, unsigned int le
* return -1 if failure
* return position if added
*/
non_null()
static int add_to_entries(Onion_Announce *onion_a, const IP_Port *ret_ip_port, const uint8_t *public_key,
const uint8_t *data_public_key, const uint8_t *ret)
{
@ -360,6 +366,7 @@ static int add_to_entries(Onion_Announce *onion_a, const IP_Port *ret_ip_port, c
return in_entries(onion_a, public_key);
}
non_null()
static int handle_announce_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -461,6 +468,7 @@ static int handle_announce_request(void *object, const IP_Port *source, const ui
return 0;
}
non_null()
static int handle_data_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{

View File

@ -31,7 +31,9 @@
typedef struct Onion_Announce Onion_Announce;
/** These two are not public; they are for tests only! */
non_null()
uint8_t *onion_announce_entry_public_key(Onion_Announce *onion_a, uint32_t entry);
non_null()
void onion_announce_entry_set_time(Onion_Announce *onion_a, uint32_t entry, uint64_t time);
/** Create an onion announce request packet in packet of max_packet_length (recommended size ONION_ANNOUNCE_REQUEST_SIZE).
@ -47,6 +49,7 @@ void onion_announce_entry_set_time(Onion_Announce *onion_a, uint32_t entry, uint
* return -1 on failure.
* return packet length on success.
*/
non_null()
int create_announce_request(uint8_t *packet, uint16_t max_packet_length, const uint8_t *dest_client_id,
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);
@ -61,6 +64,7 @@ int create_announce_request(uint8_t *packet, uint16_t max_packet_length, const u
* return -1 on failure.
* return 0 on success.
*/
non_null()
int create_data_request(uint8_t *packet, uint16_t max_packet_length, const uint8_t *public_key,
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length);
@ -78,6 +82,7 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, const uint8
* return -1 on failure.
* return 0 on success.
*/
non_null()
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,
@ -99,13 +104,16 @@ int send_announce_request(const Networking_Core *net, const Onion_Path *path, No
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_data_request(const Networking_Core *net, const Onion_Path *path, const 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);
non_null()
Onion_Announce *new_onion_announce(const Logger *log, Mono_Time *mono_time, DHT *dht);
non_null()
void kill_onion_announce(Onion_Announce *onion_a);

View File

@ -179,6 +179,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, const IP_Port *ip_port, const
* return -1 on failure
* return 0 on success
*/
non_null()
static int onion_add_path_node(Onion_Client *onion_c, const IP_Port *ip_port, const uint8_t *public_key)
{
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
@ -246,6 +247,7 @@ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uin
*
* return the number of nodes.
*/
non_null()
static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num)
{
if (!max_num) {
@ -309,6 +311,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
* return -1 if nodes are suitable for creating a new path.
* return path number of already existing similar path if one already exists.
*/
non_null()
static int is_path_used(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, const Node_format *nodes)
{
for (unsigned int i = 0; i < NUMBER_ONION_PATHS; ++i) {
@ -330,6 +333,7 @@ static int is_path_used(const Mono_Time *mono_time, const Onion_Client_Paths *on
}
/** is path timed out */
non_null()
static bool path_timed_out(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t pathnum)
{
pathnum = pathnum % NUMBER_ONION_PATHS;
@ -343,6 +347,7 @@ static bool path_timed_out(const Mono_Time *mono_time, const Onion_Client_Paths
}
/** should node be considered to have timed out */
non_null()
static bool onion_node_timed_out(const Onion_Node *node, const Mono_Time *mono_time)
{
return (node->timestamp == 0
@ -359,6 +364,7 @@ static bool onion_node_timed_out(const Onion_Node *node, const Mono_Time *mono_t
* TODO(irungentoo): Make this function better, it currently probably is
* vulnerable to some attacks that could deanonimize us.
*/
non_null()
static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path)
{
if (pathnum == UINT32_MAX) {
@ -406,6 +412,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
}
/** Does path with path_num exist. */
non_null()
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)) {
@ -418,6 +425,7 @@ static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *on
/** Set path timeouts, return the path number.
*
*/
non_null()
static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t path_num)
{
if (num > onion_c->num_friends) {
@ -455,6 +463,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, const IP_Port *dest,
const uint8_t *data, uint16_t length)
{
@ -502,6 +511,7 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa
* return 0 on success
*
*/
non_null()
static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, const IP_Port *ip_port,
uint32_t path_num, uint64_t *sendback)
{
@ -529,6 +539,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *publ
* return -1 on failure
* return num (see new_sendback(...)) on success
*/
non_null()
static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey,
IP_Port *ret_ip_port, uint32_t *path_num)
{
@ -549,6 +560,7 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
return num;
}
non_null(1, 3, 4) nullable(5)
static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, const IP_Port *dest,
const uint8_t *dest_pubkey, const uint8_t *ping_id, uint32_t pathnum)
{
@ -605,6 +617,7 @@ typedef struct Onion_Client_Cmp_Data {
Onion_Node entry;
} Onion_Client_Cmp_Data;
non_null()
static int onion_client_cmp_entry(const void *a, const void *b)
{
const Onion_Client_Cmp_Data *cmp1 = (const Onion_Client_Cmp_Data *)a;
@ -641,6 +654,7 @@ static int onion_client_cmp_entry(const void *a, const void *b)
return 0;
}
non_null()
static void sort_onion_node_list(Onion_Node *list, unsigned int length, const Mono_Time *mono_time,
const uint8_t *comp_public_key)
{
@ -661,6 +675,7 @@ static void sort_onion_node_list(Onion_Node *list, unsigned int length, const Mo
}
}
non_null()
static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, const IP_Port *ip_port,
uint8_t is_stored, const uint8_t *pingid_or_key, uint32_t path_used)
{
@ -741,6 +756,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
return 0;
}
non_null()
static int good_to_ping(const Mono_Time *mono_time, Last_Pinged *last_pinged, uint8_t *last_pinged_index,
const uint8_t *public_key)
{
@ -758,6 +774,7 @@ static int good_to_ping(const Mono_Time *mono_time, Last_Pinged *last_pinged, ui
return 1;
}
non_null()
static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_format *nodes, uint16_t num_nodes,
const IP_Port *source)
{
@ -821,6 +838,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
return 0;
}
non_null()
static int handle_announce_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -890,6 +908,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
#define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE
non_null()
static int handle_data_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -931,6 +950,7 @@ static int handle_data_response(void *object, const IP_Port *source, const uint8
#define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE)
#define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES)
non_null(1, 2, 3) nullable(5)
static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length,
void *userdata)
{
@ -996,6 +1016,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
return 0;
}
non_null()
static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length, void *userdata)
{
if (length == 0) {
@ -1106,6 +1127,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data,
* return the number of packets sent on success
* return -1 on failure.
*/
non_null()
static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length)
{
if ((uint32_t)friend_num >= onion_c->num_friends) {
@ -1143,6 +1165,7 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin
return route_to_friend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, &packet);
}
non_null()
static int handle_dht_dhtpk(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
uint16_t length, void *userdata)
{
@ -1181,6 +1204,7 @@ static int handle_dht_dhtpk(void *object, const IP_Port *source, const uint8_t *
* return the number of packets sent on success
* return -1 on failure.
*/
non_null()
static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
{
if (friend_num >= onion_c->num_friends) {
@ -1254,6 +1278,7 @@ int onion_friend_num(const Onion_Client *onion_c, const uint8_t *public_key)
* return -1 if realloc fails.
* return 0 if it succeeds.
*/
non_null()
static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num)
{
if (num == 0) {
@ -1488,6 +1513,7 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on
return 0;
}
non_null()
static void populate_path_nodes(Onion_Client *onion_c)
{
Node_format nodes_list[MAX_FRIEND_CLIENTS];
@ -1499,6 +1525,7 @@ static void populate_path_nodes(Onion_Client *onion_c)
}
}
non_null()
static void populate_path_nodes_tcp(Onion_Client *onion_c)
{
Node_format nodes_list[MAX_SENT_NODES];
@ -1518,6 +1545,7 @@ static void populate_path_nodes_tcp(Onion_Client *onion_c)
#define ONION_FRIEND_BACKOFF_FACTOR 4
#define ONION_FRIEND_MAX_PING_INTERVAL (5*60*MAX_ONION_CLIENTS)
non_null()
static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
{
if (friendnum >= onion_c->num_friends) {
@ -1648,6 +1676,7 @@ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_ha
#define TIME_TO_STABLE (ONION_NODE_PING_INTERVAL * 6)
#define ANNOUNCE_INTERVAL_STABLE (ONION_NODE_PING_INTERVAL * 8)
non_null()
static void do_announce(Onion_Client *onion_c)
{
unsigned int count = 0;
@ -1738,6 +1767,7 @@ static void do_announce(Onion_Client *onion_c)
/** return 0 if we are not connected to the network.
* return 1 if we are.
*/
non_null()
static int onion_isconnected(const Onion_Client *onion_c)
{
unsigned int num = 0;

View File

@ -52,7 +52,9 @@
typedef struct Onion_Client Onion_Client;
non_null()
DHT *onion_get_dht(const Onion_Client *onion_c);
non_null()
Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c);
/** Add a node to the path_nodes bootstrap array.
@ -60,12 +62,14 @@ Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c);
* return -1 on failure
* return 0 on success
*/
non_null()
int onion_add_bs_path_node(Onion_Client *onion_c, const IP_Port *ip_port, const uint8_t *public_key);
/** Put up to max_num nodes in nodes.
*
* return the number of nodes.
*/
non_null()
uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num);
/** Get the friend_num of a friend.
@ -73,6 +77,7 @@ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uin
* return -1 on failure.
* return friend number on success.
*/
non_null()
int onion_friend_num(const Onion_Client *onion_c, const uint8_t *public_key);
/** Add a friend who we want to connect to.
@ -80,6 +85,7 @@ int onion_friend_num(const Onion_Client *onion_c, const uint8_t *public_key);
* return -1 on failure.
* return the friend number on success or if the friend was already added.
*/
non_null()
int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key);
/** Delete a friend.
@ -87,6 +93,7 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key);
* return -1 on failure.
* return the deleted friend number on success.
*/
non_null()
int onion_delfriend(Onion_Client *onion_c, int friend_num);
/** Set if friend is online or not.
@ -98,6 +105,7 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num);
* return -1 on failure.
* return 0 on success.
*/
non_null()
int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_online);
/** Get the ip of friend friendnum and put it in ip_port
@ -107,6 +115,7 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on
* return 1, ip if public_key refers to a friend and we found him
*
*/
non_null()
int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port);
typedef int recv_tcp_relay_cb(void *object, uint32_t number, const IP_Port *ip_port, const uint8_t *public_key);
@ -119,6 +128,7 @@ typedef int recv_tcp_relay_cb(void *object, uint32_t number, const IP_Port *ip_p
* return -1 on failure.
* return 0 on success.
*/
non_null()
int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num,
recv_tcp_relay_cb *callback, void *object, uint32_t number);
@ -132,6 +142,7 @@ typedef void onion_dht_pk_cb(void *data, int32_t number, const uint8_t *dht_publ
* return -1 on failure.
* return 0 on success.
*/
non_null()
int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, onion_dht_pk_cb *function, void *object,
uint32_t number);
@ -140,6 +151,7 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, onion_dht_pk_cb
* return -1 on failure.
* return 0 on success.
*/
non_null()
int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key);
/** Copy friends DHT public key into dht_key.
@ -147,6 +159,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
* return 0 on failure (no key copied).
* return 1 on success (key copied).
*/
non_null()
unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
#define ONION_DATA_IN_RESPONSE_MIN_SIZE (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
@ -161,18 +174,23 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_
* return the number of packets sent on success
* return -1 on failure.
*/
non_null()
int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length);
typedef int oniondata_handler_cb(void *object, const uint8_t *source_pubkey, const uint8_t *data,
uint16_t len, void *userdata);
/** Function to call when onion data packet with contents beginning with byte is received. */
non_null(1) nullable(3, 4)
void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_cb *cb, void *object);
non_null()
void do_onion_client(Onion_Client *onion_c);
non_null()
Onion_Client *new_onion_client(const Logger *logger, Mono_Time *mono_time, Net_Crypto *c);
non_null()
void kill_onion_client(Onion_Client *onion_c);
@ -180,6 +198,7 @@ void kill_onion_client(Onion_Client *onion_c);
* return 1 if we are connected with TCP only.
* return 2 if we are also connected with UDP.
*/
non_null()
unsigned int onion_connection_status(const Onion_Client *onion_c);
#endif

View File

@ -90,6 +90,7 @@ void ping_send_request(Ping *ping, const IP_Port *ipp, const uint8_t *public_key
sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
}
non_null()
static int ping_send_response(const Ping *ping, const IP_Port *ipp, const uint8_t *public_key,
uint64_t ping_id, const uint8_t *shared_encryption_key)
{
@ -120,6 +121,7 @@ static int ping_send_response(const Ping *ping, const IP_Port *ipp, const uint8_
return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk));
}
non_null()
static int handle_ping_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -167,6 +169,7 @@ static int handle_ping_request(void *object, const IP_Port *source, const uint8_
return 0;
}
non_null()
static int handle_ping_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
@ -234,6 +237,7 @@ static int handle_ping_response(void *object, const IP_Port *source, const uint8
* return 1 if it is.
* return 0 if it isn't.
*/
non_null()
static int in_list(const Client_data *list, uint16_t length, const Mono_Time *mono_time, const uint8_t *public_key,
const IP_Port *ip_port)
{

View File

@ -17,8 +17,10 @@
typedef struct Ping Ping;
non_null()
Ping *ping_new(const struct Mono_Time *mono_time, DHT *dht);
non_null()
void ping_kill(Ping *ping);
/** Add nodes to the to_ping list.
@ -31,10 +33,13 @@ void ping_kill(Ping *ping);
* return 0 if node was added.
* return -1 if node was not added.
*/
non_null()
int32_t ping_add(Ping *ping, const uint8_t *public_key, const IP_Port *ip_port);
non_null()
void ping_iterate(Ping *ping);
non_null()
void ping_send_request(Ping *ping, const IP_Port *ipp, const uint8_t *public_key);
#endif // C_TOXCORE_TOXCORE_PING_H

View File

@ -62,6 +62,7 @@ Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
return empty_array;
}
non_null()
static void clear_entry(Ping_Array *array, uint32_t index)
{
const Ping_Array_Entry empty = {nullptr};
@ -87,6 +88,7 @@ void ping_array_kill(Ping_Array *array)
/** Clear timed out entries.
*/
non_null()
static void ping_array_clear_timedout(Ping_Array *array, const Mono_Time *mono_time)
{
while (array->last_deleted != array->last_added) {

View File

@ -33,6 +33,7 @@ struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout);
/**
* @brief Free all the allocated memory in a @ref Ping_Array.
*/
non_null()
void ping_array_kill(struct Ping_Array *array);
/**
@ -40,6 +41,7 @@ void ping_array_kill(struct Ping_Array *array);
*
* @return ping_id on success, 0 on failure.
*/
non_null()
uint64_t ping_array_add(struct Ping_Array *array, const struct Mono_Time *mono_time, const uint8_t *data,
uint32_t length);
@ -50,6 +52,7 @@ uint64_t ping_array_add(struct Ping_Array *array, const struct Mono_Time *mono_t
*
* @return length of data copied on success, -1 on failure.
*/
non_null()
int32_t ping_array_check(struct Ping_Array *array, const struct Mono_Time *mono_time, uint8_t *data, size_t length,
uint64_t ping_id);

View File

@ -53,9 +53,11 @@ typedef enum State_Load_Status {
typedef State_Load_Status state_load_cb(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
/** state load/save */
non_null()
int state_load(const Logger *log, state_load_cb *state_load_callback, void *outer,
const uint8_t *data, uint32_t length, uint16_t cookie_inner);
non_null()
uint8_t *state_write_section_header(uint8_t *data, uint16_t cookie_type, uint32_t len, uint32_t section_type);
// Utilities for state data serialisation.
@ -63,13 +65,19 @@ uint8_t *state_write_section_header(uint8_t *data, uint16_t cookie_type, uint32_
uint16_t lendian_to_host16(uint16_t lendian);
uint16_t host_to_lendian16(uint16_t host);
non_null()
void host_to_lendian_bytes64(uint8_t *dest, uint64_t num);
non_null()
void lendian_bytes_to_host64(uint64_t *dest, const uint8_t *lendian);
non_null()
void host_to_lendian_bytes32(uint8_t *dest, uint32_t num);
non_null()
void lendian_bytes_to_host32(uint32_t *dest, const uint8_t *lendian);
non_null()
void host_to_lendian_bytes16(uint8_t *dest, uint16_t num);
non_null()
void lendian_bytes_to_host16(uint16_t *dest, const uint8_t *lendian);
#ifdef __cplusplus

View File

@ -80,6 +80,7 @@ struct Tox {
void *toxav_object; // workaround to store a ToxAV object (setter and getter functions are available)
};
non_null()
static void lock(const Tox *tox)
{
if (tox->mutex != nullptr) {
@ -87,6 +88,7 @@ static void lock(const Tox *tox)
}
}
non_null()
static void unlock(const Tox *tox)
{
if (tox->mutex != nullptr) {
@ -99,6 +101,7 @@ struct Tox_Userdata {
void *user_data;
};
non_null(1) nullable(3)
static void tox_self_connection_status_handler(Messenger *m, unsigned int connection_status, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -108,6 +111,7 @@ static void tox_self_connection_status_handler(Messenger *m, unsigned int connec
}
}
non_null(1, 3) nullable(5)
static void tox_friend_name_handler(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length,
void *user_data)
{
@ -118,6 +122,7 @@ static void tox_friend_name_handler(Messenger *m, uint32_t friend_number, const
}
}
non_null(1, 3) nullable(5)
static void tox_friend_status_message_handler(Messenger *m, uint32_t friend_number, const uint8_t *message,
size_t length, void *user_data)
{
@ -128,6 +133,7 @@ static void tox_friend_status_message_handler(Messenger *m, uint32_t friend_numb
}
}
non_null(1) nullable(4)
static void tox_friend_status_handler(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -137,6 +143,7 @@ static void tox_friend_status_handler(Messenger *m, uint32_t friend_number, unsi
}
}
non_null(1) nullable(4)
static void tox_friend_connection_status_handler(Messenger *m, uint32_t friend_number, unsigned int connection_status,
void *user_data)
{
@ -148,6 +155,7 @@ static void tox_friend_connection_status_handler(Messenger *m, uint32_t friend_n
}
}
non_null(1) nullable(4)
static void tox_friend_typing_handler(Messenger *m, uint32_t friend_number, bool is_typing, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -157,6 +165,7 @@ static void tox_friend_typing_handler(Messenger *m, uint32_t friend_number, bool
}
}
non_null(1) nullable(4)
static void tox_friend_read_receipt_handler(Messenger *m, uint32_t friend_number, uint32_t message_id, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -166,6 +175,7 @@ static void tox_friend_read_receipt_handler(Messenger *m, uint32_t friend_number
}
}
non_null(1, 2, 3) nullable(5)
static void tox_friend_request_handler(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length,
void *user_data)
{
@ -176,6 +186,7 @@ static void tox_friend_request_handler(Messenger *m, const uint8_t *public_key,
}
}
non_null(1, 4) nullable(6)
static void tox_friend_message_handler(Messenger *m, uint32_t friend_number, unsigned int type, const uint8_t *message,
size_t length, void *user_data)
{
@ -187,6 +198,7 @@ static void tox_friend_message_handler(Messenger *m, uint32_t friend_number, uns
}
}
non_null(1) nullable(5)
static void tox_file_recv_control_handler(Messenger *m, uint32_t friend_number, uint32_t file_number,
unsigned int control, void *user_data)
{
@ -198,6 +210,7 @@ static void tox_file_recv_control_handler(Messenger *m, uint32_t friend_number,
}
}
non_null(1) nullable(6)
static void tox_file_chunk_request_handler(Messenger *m, uint32_t friend_number, uint32_t file_number,
uint64_t position, size_t length, void *user_data)
{
@ -209,6 +222,7 @@ static void tox_file_chunk_request_handler(Messenger *m, uint32_t friend_number,
}
}
non_null(1, 6) nullable(8)
static void tox_file_recv_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, uint32_t kind,
uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data)
{
@ -220,6 +234,7 @@ static void tox_file_recv_handler(Messenger *m, uint32_t friend_number, uint32_t
}
}
non_null(1, 5) nullable(7)
static void tox_file_recv_chunk_handler(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
const uint8_t *data, size_t length, void *user_data)
{
@ -231,6 +246,7 @@ static void tox_file_recv_chunk_handler(Messenger *m, uint32_t friend_number, ui
}
}
non_null(1, 4) nullable(6)
static void tox_conference_invite_handler(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie,
size_t length, void *user_data)
{
@ -242,6 +258,7 @@ static void tox_conference_invite_handler(Messenger *m, uint32_t friend_number,
}
}
non_null(1) nullable(3)
static void tox_conference_connected_handler(Messenger *m, uint32_t conference_number, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -251,6 +268,7 @@ static void tox_conference_connected_handler(Messenger *m, uint32_t conference_n
}
}
non_null(1, 5) nullable(7)
static void tox_conference_message_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type,
const uint8_t *message, size_t length, void *user_data)
{
@ -262,6 +280,7 @@ static void tox_conference_message_handler(Messenger *m, uint32_t conference_num
}
}
non_null(1, 4) nullable(6)
static void tox_conference_title_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number,
const uint8_t *title, size_t length, void *user_data)
{
@ -273,6 +292,7 @@ static void tox_conference_title_handler(Messenger *m, uint32_t conference_numbe
}
}
non_null(1, 4) nullable(6)
static void tox_conference_peer_name_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number,
const uint8_t *name, size_t length, void *user_data)
{
@ -284,6 +304,7 @@ static void tox_conference_peer_name_handler(Messenger *m, uint32_t conference_n
}
}
non_null(1) nullable(3)
static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conference_number, void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
@ -293,6 +314,7 @@ static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conf
}
}
non_null(1, 4) nullable(6)
static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id,
const uint8_t *data, size_t length, void *user_data)
{
@ -307,6 +329,7 @@ static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number
}
}
non_null(1, 4) nullable(6)
static void tox_friend_lossless_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id,
const uint8_t *data, size_t length, void *user_data)
{
@ -327,6 +350,7 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
return TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch);
}
non_null()
static State_Load_Status state_load_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
{
const Tox *tox = (const Tox *)outer;
@ -352,6 +376,7 @@ static State_Load_Status state_load_callback(void *outer, const uint8_t *data, u
}
/** Load tox from data of size length. */
non_null()
static int tox_load(Tox *tox, const uint8_t *data, uint32_t length)
{
uint32_t data32[2];
@ -632,12 +657,12 @@ static uint32_t end_size(void)
return 2 * sizeof(uint32_t);
}
non_null()
static void end_save(uint8_t *data)
{
state_write_section_header(data, STATE_COOKIE_TYPE, 0, STATE_TYPE_END);
}
non_null(1)
size_t tox_get_savedata_size(const Tox *tox)
{
assert(tox != nullptr);
@ -650,7 +675,6 @@ size_t tox_get_savedata_size(const Tox *tox)
return ret;
}
non_null(1)
void tox_get_savedata(const Tox *tox, uint8_t *savedata)
{
assert(tox != nullptr);
@ -678,7 +702,6 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata)
unlock(tox);
}
non_null(1)
bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error)
{
assert(tox != nullptr);
@ -730,7 +753,6 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
return 0;
}
non_null(1)
bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
Tox_Err_Bootstrap *error)
{
@ -777,7 +799,6 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
return 0;
}
non_null(1)
Tox_Connection tox_self_get_connection_status(const Tox *tox)
{
assert(tox != nullptr);
@ -797,14 +818,12 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox)
}
non_null(1)
void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback)
{
assert(tox != nullptr);
tox->self_connection_status_callback = callback;
}
non_null(1)
uint32_t tox_iteration_interval(const Tox *tox)
{
assert(tox != nullptr);
@ -814,7 +833,6 @@ uint32_t tox_iteration_interval(const Tox *tox)
return ret;
}
non_null(1)
void tox_iterate(Tox *tox, void *user_data)
{
assert(tox != nullptr);
@ -829,7 +847,6 @@ void tox_iterate(Tox *tox, void *user_data)
unlock(tox);
}
non_null(1)
void tox_self_get_address(const Tox *tox, uint8_t *address)
{
assert(tox != nullptr);
@ -841,7 +858,6 @@ void tox_self_get_address(const Tox *tox, uint8_t *address)
}
}
non_null(1)
void tox_self_set_nospam(Tox *tox, uint32_t nospam)
{
assert(tox != nullptr);
@ -850,7 +866,6 @@ void tox_self_set_nospam(Tox *tox, uint32_t nospam)
unlock(tox);
}
non_null(1)
uint32_t tox_self_get_nospam(const Tox *tox)
{
assert(tox != nullptr);
@ -860,7 +875,6 @@ uint32_t tox_self_get_nospam(const Tox *tox)
return ret;
}
non_null(1)
void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
{
assert(tox != nullptr);
@ -872,7 +886,6 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
}
}
non_null(1)
void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
{
assert(tox != nullptr);
@ -884,7 +897,6 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
}
}
non_null(1)
bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error)
{
assert(tox != nullptr);
@ -909,7 +921,6 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set
return 0;
}
non_null(1)
size_t tox_self_get_name_size(const Tox *tox)
{
assert(tox != nullptr);
@ -919,7 +930,6 @@ size_t tox_self_get_name_size(const Tox *tox)
return ret;
}
non_null(1)
void tox_self_get_name(const Tox *tox, uint8_t *name)
{
assert(tox != nullptr);
@ -931,7 +941,6 @@ void tox_self_get_name(const Tox *tox, uint8_t *name)
}
}
non_null(1)
bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error)
{
assert(tox != nullptr);
@ -954,7 +963,6 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t
return 0;
}
non_null(1)
size_t tox_self_get_status_message_size(const Tox *tox)
{
assert(tox != nullptr);
@ -964,7 +972,6 @@ size_t tox_self_get_status_message_size(const Tox *tox)
return ret;
}
non_null(1)
void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
{
assert(tox != nullptr);
@ -976,7 +983,6 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
}
}
non_null(1)
void tox_self_set_status(Tox *tox, Tox_User_Status status)
{
assert(tox != nullptr);
@ -985,7 +991,6 @@ void tox_self_set_status(Tox *tox, Tox_User_Status status)
unlock(tox);
}
non_null(1)
Tox_User_Status tox_self_get_status(const Tox *tox)
{
assert(tox != nullptr);
@ -995,6 +1000,7 @@ Tox_User_Status tox_self_get_status(const Tox *tox)
return (Tox_User_Status)status;
}
non_null(1) nullable(3)
static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add *error)
{
switch (ret) {
@ -1041,7 +1047,6 @@ static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add
}
}
non_null(1)
uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length,
Tox_Err_Friend_Add *error)
{
@ -1066,7 +1071,6 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message
return UINT32_MAX;
}
non_null(1)
uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error)
{
assert(tox != nullptr);
@ -1090,7 +1094,6 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F
return UINT32_MAX;
}
non_null(1)
bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error)
{
assert(tox != nullptr);
@ -1108,7 +1111,6 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *
return 1;
}
non_null(1)
uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error)
{
assert(tox != nullptr);
@ -1131,7 +1133,6 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox
return ret;
}
non_null(1)
bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key,
Tox_Err_Friend_Get_Public_Key *error)
{
@ -1154,7 +1155,6 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *
return 1;
}
non_null(1)
bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
{
assert(tox != nullptr);
@ -1164,7 +1164,6 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
return ret;
}
non_null(1)
uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error)
{
assert(tox != nullptr);
@ -1181,7 +1180,6 @@ uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_
return timestamp;
}
non_null(1)
size_t tox_self_get_friend_list_size(const Tox *tox)
{
assert(tox != nullptr);
@ -1191,7 +1189,6 @@ size_t tox_self_get_friend_list_size(const Tox *tox)
return ret;
}
non_null(1)
void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
{
assert(tox != nullptr);
@ -1204,7 +1201,6 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
}
}
non_null(1)
size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1221,7 +1217,6 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_
return ret;
}
non_null(1)
bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1244,14 +1239,12 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name,
return 1;
}
non_null(1)
void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback)
{
assert(tox != nullptr);
tox->friend_name_callback = callback;
}
non_null(1)
size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1268,7 +1261,6 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number
return ret;
}
non_null(1)
bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message,
Tox_Err_Friend_Query *error)
{
@ -1296,14 +1288,12 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8
return ret == size;
}
non_null(1)
void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback)
{
assert(tox != nullptr);
tox->friend_status_message_callback = callback;
}
non_null(1)
Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1320,14 +1310,12 @@ Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, To
return (Tox_User_Status)ret;
}
non_null(1)
void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback)
{
assert(tox != nullptr);
tox->friend_status_callback = callback;
}
non_null(1)
Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1344,14 +1332,12 @@ Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
return (Tox_Connection)ret;
}
non_null(1)
void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
{
assert(tox != nullptr);
tox->friend_connection_status_callback = callback;
}
non_null(1)
bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
assert(tox != nullptr);
@ -1368,14 +1354,12 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien
return !!ret;
}
non_null(1)
void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback)
{
assert(tox != nullptr);
tox->friend_typing_callback = callback;
}
non_null(1)
bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error)
{
assert(tox != nullptr);
@ -1392,6 +1376,7 @@ bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_
return 1;
}
non_null(1) nullable(3)
static void set_message_error(const Logger *log, int ret, Tox_Err_Friend_Send_Message *error)
{
switch (ret) {
@ -1433,7 +1418,6 @@ static void set_message_error(const Logger *log, int ret, Tox_Err_Friend_Send_Me
}
}
non_null(1)
uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message,
size_t length, Tox_Err_Friend_Send_Message *error)
{
@ -1457,21 +1441,18 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T
return message_id;
}
non_null(1)
void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback)
{
assert(tox != nullptr);
tox->friend_read_receipt_callback = callback;
}
non_null(1)
void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback)
{
assert(tox != nullptr);
tox->friend_request_callback = callback;
}
non_null(1)
void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback)
{
assert(tox != nullptr);
@ -1488,7 +1469,6 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
return 1;
}
non_null(1)
bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
Tox_Err_File_Control *error)
{
@ -1551,7 +1531,6 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, To
return 0;
}
non_null(1)
bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
Tox_Err_File_Seek *error)
{
@ -1604,14 +1583,12 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
return 0;
}
non_null(1)
void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
{
assert(tox != nullptr);
tox->file_recv_control_callback = callback;
}
non_null(1)
bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
Tox_Err_File_Get *error)
{
@ -1640,7 +1617,6 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
return 0;
}
non_null(1)
uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error)
{
@ -1696,7 +1672,6 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
return UINT32_MAX;
}
non_null(1)
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
size_t length, Tox_Err_File_Send_Chunk *error)
{
@ -1753,70 +1728,60 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number,
return 0;
}
non_null(1)
void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback)
{
assert(tox != nullptr);
tox->file_chunk_request_callback = callback;
}
non_null(1)
void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback)
{
assert(tox != nullptr);
tox->file_recv_callback = callback;
}
non_null(1)
void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback)
{
assert(tox != nullptr);
tox->file_recv_chunk_callback = callback;
}
non_null(1)
void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback)
{
assert(tox != nullptr);
tox->conference_invite_callback = callback;
}
non_null(1)
void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback)
{
assert(tox != nullptr);
tox->conference_connected_callback = callback;
}
non_null(1)
void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback)
{
assert(tox != nullptr);
tox->conference_message_callback = callback;
}
non_null(1)
void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback)
{
assert(tox != nullptr);
tox->conference_title_callback = callback;
}
non_null(1)
void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback)
{
assert(tox != nullptr);
tox->conference_peer_name_callback = callback;
}
non_null(1)
void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback)
{
assert(tox != nullptr);
tox->conference_peer_list_changed_callback = callback;
}
non_null(1)
uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
{
assert(tox != nullptr);
@ -1833,7 +1798,6 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
return ret;
}
non_null(1)
bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
{
assert(tox != nullptr);
@ -1850,7 +1814,6 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere
return true;
}
non_null(1)
uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error)
{
assert(tox != nullptr);
@ -1867,7 +1830,6 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T
return ret;
}
non_null(1)
size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
Tox_Err_Conference_Peer_Query *error)
{
@ -1892,7 +1854,6 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num
return ret;
}
non_null(1)
bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name,
Tox_Err_Conference_Peer_Query *error)
{
@ -1917,7 +1878,6 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
return true;
}
non_null(1)
bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
{
@ -1942,7 +1902,6 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb
return true;
}
non_null(1)
bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
Tox_Err_Conference_Peer_Query *error)
{
@ -1972,7 +1931,6 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb
return ret;
}
non_null(1)
uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number,
Tox_Err_Conference_Peer_Query *error)
{
@ -1990,7 +1948,6 @@ uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_n
return ret;
}
non_null(1)
size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t conference_number,
uint32_t offline_peer_number,
Tox_Err_Conference_Peer_Query *error)
@ -2016,7 +1973,6 @@ size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t confer
return ret;
}
non_null(1)
bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t offline_peer_number,
uint8_t *name,
Tox_Err_Conference_Peer_Query *error)
@ -2042,7 +1998,6 @@ bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_nu
return true;
}
non_null(1)
bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t conference_number,
uint32_t offline_peer_number,
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
@ -2068,7 +2023,6 @@ bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t confere
return true;
}
non_null(1)
uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t conference_number,
uint32_t offline_peer_number,
Tox_Err_Conference_Peer_Query *error)
@ -2096,7 +2050,6 @@ uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t co
return last_active;
}
non_null(1)
bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number,
uint32_t max_offline_peers,
Tox_Err_Conference_Set_Max_Offline *error)
@ -2115,7 +2068,6 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number,
return true;
}
non_null(1)
bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number,
Tox_Err_Conference_Invite *error)
{
@ -2145,7 +2097,6 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference
return true;
}
non_null(1)
uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length,
Tox_Err_Conference_Join *error)
{
@ -2190,7 +2141,6 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
return ret;
}
non_null(1)
bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message,
size_t length, Tox_Err_Conference_Send_Message *error)
{
@ -2232,7 +2182,6 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa
return true;
}
non_null(1)
size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error)
{
assert(tox != nullptr);
@ -2256,7 +2205,6 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number,
return ret;
}
non_null(1)
bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title,
Tox_Err_Conference_Title *error)
{
@ -2281,7 +2229,6 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_
return true;
}
non_null(1)
bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length,
Tox_Err_Conference_Title *error)
{
@ -2311,7 +2258,6 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_
return true;
}
non_null(1)
size_t tox_conference_get_chatlist_size(const Tox *tox)
{
assert(tox != nullptr);
@ -2321,7 +2267,6 @@ size_t tox_conference_get_chatlist_size(const Tox *tox)
return ret;
}
non_null(1)
void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
{
assert(tox != nullptr);
@ -2331,7 +2276,6 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
unlock(tox);
}
non_null(1)
Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number,
Tox_Err_Conference_Get_Type *error)
{
@ -2349,7 +2293,6 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_
return (Tox_Conference_Type)ret;
}
non_null(1)
bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id)
{
assert(tox != nullptr);
@ -2360,14 +2303,12 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *
}
// TODO(iphydf): Delete in 0.3.0.
non_null(1)
bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid)
{
assert(tox != nullptr);
return tox_conference_get_id(tox, conference_number, uid);
}
non_null(1)
uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error)
{
assert(tox != nullptr);
@ -2391,7 +2332,6 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere
}
// TODO(iphydf): Delete in 0.3.0.
non_null(1)
uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error)
{
assert(tox != nullptr);
@ -2418,6 +2358,7 @@ uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Confe
return res;
}
nullable(2)
static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error)
{
switch (ret) {
@ -2453,7 +2394,6 @@ static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error
}
}
non_null(1)
bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
Tox_Err_Friend_Custom_Packet *error)
{
@ -2487,7 +2427,6 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
return 0;
}
non_null(1)
void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback)
{
assert(tox != nullptr);
@ -2498,7 +2437,6 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call
}
}
non_null(1)
void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid)
{
assert(tox != nullptr);
@ -2508,7 +2446,6 @@ void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packe
}
}
non_null(1)
bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
Tox_Err_Friend_Custom_Packet *error)
{
@ -2537,7 +2474,6 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin
return 0;
}
non_null(1)
void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback)
{
assert(tox != nullptr);
@ -2547,7 +2483,6 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb
}
}
non_null(1)
void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid)
{
assert(tox != nullptr);
@ -2558,7 +2493,6 @@ void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless
}
}
non_null(1)
void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
{
assert(tox != nullptr);
@ -2570,7 +2504,6 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
}
}
non_null(1)
void tox_set_av_object(Tox *tox, void *object)
{
assert(tox != nullptr);
@ -2579,7 +2512,6 @@ void tox_set_av_object(Tox *tox, void *object)
unlock(tox);
}
non_null(1)
void *tox_get_av_object(const Tox *tox)
{
assert(tox != nullptr);
@ -2589,7 +2521,6 @@ void *tox_get_av_object(const Tox *tox)
return object;
}
non_null(1)
uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
{
assert(tox != nullptr);
@ -2606,7 +2537,6 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
return port;
}
non_null(1)
uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error)
{
assert(tox != nullptr);

View File

@ -161,6 +161,7 @@ void tox_events_callback_self_connection_status(
dispatch->self_connection_status_callback = callback;
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_connected(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -174,6 +175,7 @@ static void tox_dispatch_invoke_conference_connected(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_invite(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -187,6 +189,7 @@ static void tox_dispatch_invoke_conference_invite(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_message(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -200,6 +203,7 @@ static void tox_dispatch_invoke_conference_message(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_peer_list_changed(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -213,6 +217,7 @@ static void tox_dispatch_invoke_conference_peer_list_changed(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_peer_name(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -226,6 +231,7 @@ static void tox_dispatch_invoke_conference_peer_name(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_conference_title(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -239,6 +245,7 @@ static void tox_dispatch_invoke_conference_title(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_file_chunk_request(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -252,6 +259,7 @@ static void tox_dispatch_invoke_file_chunk_request(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_file_recv(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -265,6 +273,7 @@ static void tox_dispatch_invoke_file_recv(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_file_recv_chunk(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -278,6 +287,7 @@ static void tox_dispatch_invoke_file_recv_chunk(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_file_recv_control(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -291,6 +301,7 @@ static void tox_dispatch_invoke_file_recv_control(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_connection_status(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -304,6 +315,7 @@ static void tox_dispatch_invoke_friend_connection_status(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_lossless_packet(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -317,6 +329,7 @@ static void tox_dispatch_invoke_friend_lossless_packet(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_lossy_packet(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -330,6 +343,7 @@ static void tox_dispatch_invoke_friend_lossy_packet(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_message(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -343,6 +357,7 @@ static void tox_dispatch_invoke_friend_message(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_name(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -356,6 +371,7 @@ static void tox_dispatch_invoke_friend_name(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_read_receipt(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -369,6 +385,7 @@ static void tox_dispatch_invoke_friend_read_receipt(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_request(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -382,6 +399,7 @@ static void tox_dispatch_invoke_friend_request(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_status(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -395,6 +413,7 @@ static void tox_dispatch_invoke_friend_status(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_status_message(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -408,6 +427,7 @@ static void tox_dispatch_invoke_friend_status_message(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_friend_typing(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{
@ -421,6 +441,7 @@ static void tox_dispatch_invoke_friend_typing(
}
}
non_null(1, 3) nullable(2, 4)
static void tox_dispatch_invoke_self_connection_status(
const Tox_Dispatch *dispatch, const Tox_Events *events, Tox *tox, void *user_data)
{

View File

@ -113,6 +113,7 @@ bool tox_events_unpack(Tox_Events *events, const msgpack_object *obj)
&& tox_events_unpack_self_connection_status(events, &obj->via.array.ptr[20]);
}
non_null()
static int count_bytes(void *data, const char *buf, size_t len)
{
uint32_t *count = (uint32_t *)data;
@ -130,6 +131,7 @@ uint32_t tox_events_bytes_size(const Tox_Events *events)
return count;
}
non_null()
static int write_bytes(void *data, const char *buf, size_t len)
{
uint8_t **bytes = (uint8_t **)data;
@ -180,6 +182,7 @@ Tox_Events *tox_events_load(const uint8_t *bytes, uint32_t bytes_size)
return events;
}
non_null(2, 3) nullable(1)
static bool tox_events_to_object(const Tox_Events *events, msgpack_unpacked *msg, msgpack_sbuffer *sbuf)
{
msgpack_sbuffer_init(sbuf);

View File

@ -8,19 +8,20 @@
#include <msgpack.h>
#include <stdint.h>
#include "attributes.h"
#include "tox.h"
bool tox_unpack_bool(bool *val, const msgpack_object *obj);
bool tox_unpack_u16(uint16_t *val, const msgpack_object *obj);
bool tox_unpack_u32(uint32_t *val, const msgpack_object *obj);
bool tox_unpack_u64(uint64_t *val, const msgpack_object *obj);
bool tox_unpack_bin(uint8_t **data, size_t *data_length, const msgpack_object *obj);
bool tox_unpack_bin_fixed(uint8_t *data, uint32_t data_length, const msgpack_object *obj);
non_null() bool tox_unpack_bool(bool *val, const msgpack_object *obj);
non_null() bool tox_unpack_u16(uint16_t *val, const msgpack_object *obj);
non_null() bool tox_unpack_u32(uint32_t *val, const msgpack_object *obj);
non_null() bool tox_unpack_u64(uint64_t *val, const msgpack_object *obj);
non_null() bool tox_unpack_bin(uint8_t **data, size_t *data_length, const msgpack_object *obj);
non_null() bool tox_unpack_bin_fixed(uint8_t *data, uint32_t data_length, const msgpack_object *obj);
bool tox_unpack_conference_type(Tox_Conference_Type *val, const msgpack_object *obj);
bool tox_unpack_connection(Tox_Connection *val, const msgpack_object *obj);
bool tox_unpack_file_control(Tox_File_Control *val, const msgpack_object *obj);
bool tox_unpack_message_type(Tox_Message_Type *val, const msgpack_object *obj);
bool tox_unpack_user_status(Tox_User_Status *val, const msgpack_object *obj);
non_null() bool tox_unpack_conference_type(Tox_Conference_Type *val, const msgpack_object *obj);
non_null() bool tox_unpack_connection(Tox_Connection *val, const msgpack_object *obj);
non_null() bool tox_unpack_file_control(Tox_File_Control *val, const msgpack_object *obj);
non_null() bool tox_unpack_message_type(Tox_Message_Type *val, const msgpack_object *obj);
non_null() bool tox_unpack_user_status(Tox_User_Status *val, const msgpack_object *obj);
#endif // C_TOXCORE_TOXCORE_TOX_UNPACK_H

View File

@ -21,11 +21,11 @@ extern "C" {
#endif
/** id functions */
bool id_equal(const uint8_t *dest, const uint8_t *src);
uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */
non_null() bool id_equal(const uint8_t *dest, const uint8_t *src);
non_null() uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */
/** Returns -1 if failed or 0 if success */
int create_recursive_mutex(pthread_mutex_t *mutex);
non_null() int create_recursive_mutex(pthread_mutex_t *mutex);
// Safe min/max functions with specific types. This forces the conversion to the
// desired type before the comparison expression, giving the choice of