mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
cleanup: Remove more implicit bool conversions.
Also use `bool` type in place of `uint8_t` which was the old bool type in toxcore before C99.
This commit is contained in:
parent
3e6fc59f91
commit
c2c7c9f0fd
|
@ -1635,7 +1635,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
|
|||
DHT_Friend *const dht_friend = &dht->friends_list[friend_num];
|
||||
--dht_friend->lock_count;
|
||||
|
||||
if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/
|
||||
if (dht_friend->lock_count > 0 && lock_count > 0) { /* DHT friend is still in use.*/
|
||||
--lock_count;
|
||||
dht_friend->callbacks[lock_count].ip_callback = nullptr;
|
||||
dht_friend->callbacks[lock_count].data = nullptr;
|
||||
|
@ -1846,7 +1846,7 @@ 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);
|
||||
}
|
||||
|
||||
int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
|
||||
int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
|
||||
uint16_t port, const uint8_t *public_key)
|
||||
{
|
||||
IP_Port ip_port_v64;
|
||||
|
|
|
@ -365,15 +365,15 @@ void dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
|
|||
* request to the given node with ip, port and public_key to setup connections
|
||||
*
|
||||
* address can be a hostname or an IP address (IPv4 or IPv6).
|
||||
* if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
|
||||
* if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
|
||||
* if ipv6enabled is false, the resolving sticks STRICTLY to IPv4 addresses
|
||||
* if ipv6enabled is true, the resolving looks for IPv6 addresses first,
|
||||
* then IPv4 addresses.
|
||||
*
|
||||
* 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,
|
||||
int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
|
||||
uint16_t port, const uint8_t *public_key);
|
||||
|
||||
/** Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
|
||||
|
|
|
@ -140,7 +140,7 @@ static int send_online_packet(Messenger *m, int32_t friendnumber)
|
|||
|
||||
uint8_t packet = PACKET_ID_ONLINE;
|
||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id), &packet, sizeof(packet), 0) != -1;
|
||||
m->friendlist[friendnumber].friendcon_id), &packet, sizeof(packet), false) != -1;
|
||||
}
|
||||
|
||||
non_null()
|
||||
|
@ -148,11 +148,11 @@ static int send_offline_packet(Messenger *m, int friendcon_id)
|
|||
{
|
||||
uint8_t packet = PACKET_ID_OFFLINE;
|
||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), &packet,
|
||||
sizeof(packet), 0) != -1;
|
||||
sizeof(packet), false) != -1;
|
||||
}
|
||||
|
||||
non_null(1) nullable(4)
|
||||
static int m_handle_status(void *object, int i, uint8_t status, void *userdata);
|
||||
static int m_handle_status(void *object, int i, bool 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)
|
||||
|
@ -531,7 +531,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
|
|||
}
|
||||
|
||||
const int64_t packet_num = write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id), packet, length + 1, 0);
|
||||
m->friendlist[friendnumber].friendcon_id), packet, length + 1, false);
|
||||
|
||||
if (packet_num == -1) {
|
||||
LOGGER_WARNING(m->log, "failed to write crypto packet for message of length %d to friend %d",
|
||||
|
@ -552,7 +552,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
|
|||
|
||||
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)
|
||||
uint32_t length, bool congestion_control)
|
||||
{
|
||||
if (!friend_is_valid(m, friendnumber)) {
|
||||
return 0;
|
||||
|
@ -583,7 +583,7 @@ static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *n
|
|||
return 0;
|
||||
}
|
||||
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_NICKNAME, name, length, 0);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_NICKNAME, name, length, false);
|
||||
}
|
||||
|
||||
/** Set the name and name_length of a friend.
|
||||
|
@ -843,20 +843,20 @@ int m_get_istyping(const Messenger *m, int32_t friendnumber)
|
|||
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);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, false);
|
||||
}
|
||||
|
||||
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);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), false);
|
||||
}
|
||||
|
||||
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);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), false);
|
||||
}
|
||||
|
||||
non_null()
|
||||
|
@ -1024,7 +1024,7 @@ void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function
|
|||
*/
|
||||
int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_CONFERENCE, data, length, 0);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_CONFERENCE, data, length, false);
|
||||
}
|
||||
|
||||
/*** FILE SENDING */
|
||||
|
@ -1138,7 +1138,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
|
|||
memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH, filename, filename_length);
|
||||
}
|
||||
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, SIZEOF_VLA(packet), 0);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, SIZEOF_VLA(packet), false);
|
||||
}
|
||||
|
||||
/** Send a file send request.
|
||||
|
@ -1214,7 +1214,7 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui
|
|||
memcpy(packet + 3, data, data_length);
|
||||
}
|
||||
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, SIZEOF_VLA(packet), 0);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, SIZEOF_VLA(packet), false);
|
||||
}
|
||||
|
||||
/** Send a file control request.
|
||||
|
@ -1401,12 +1401,12 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u
|
|||
packet[0] = PACKET_ID_FILE_DATA;
|
||||
packet[1] = filenumber;
|
||||
|
||||
if (length) {
|
||||
if (length != 0) {
|
||||
memcpy(packet + 2, data, length);
|
||||
}
|
||||
|
||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id), packet, SIZEOF_VLA(packet), 1);
|
||||
m->friendlist[friendnumber].friendcon_id), packet, SIZEOF_VLA(packet), true);
|
||||
}
|
||||
|
||||
#define MAX_FILE_DATA_SIZE (MAX_CRYPTO_DATA_SIZE - 2)
|
||||
|
@ -1624,12 +1624,12 @@ 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,
|
||||
static struct File_Transfers *get_file_transfer(bool receive_send, uint8_t filenumber,
|
||||
uint32_t *real_filenumber, Friend *sender)
|
||||
{
|
||||
struct File_Transfers *ft;
|
||||
|
||||
if (receive_send == 0) {
|
||||
if (!receive_send) {
|
||||
*real_filenumber = (filenumber + 1) << 16;
|
||||
ft = &sender->file_receiving[filenumber];
|
||||
} else {
|
||||
|
@ -1647,15 +1647,9 @@ 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,
|
||||
static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool receive_send, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
|
||||
{
|
||||
if (receive_send > 1) {
|
||||
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): receive_send value is invalid (should be 0 or 1): %d",
|
||||
friendnumber, filenumber, receive_send);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t real_filenumber;
|
||||
struct File_Transfers *ft = get_file_transfer(receive_send, filenumber, &real_filenumber, &m->friendlist[friendnumber]);
|
||||
|
||||
|
@ -1772,7 +1766,7 @@ void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userda
|
|||
*/
|
||||
int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0);
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, false);
|
||||
}
|
||||
|
||||
static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
|
||||
|
@ -1913,7 +1907,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
|
|||
}
|
||||
|
||||
if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
|
||||
m->friendlist[friendnumber].friendcon_id), data, length, true) == -1) {
|
||||
return -5;
|
||||
}
|
||||
|
||||
|
@ -1952,7 +1946,7 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t,
|
|||
}
|
||||
}
|
||||
|
||||
static int m_handle_status(void *object, int i, uint8_t status, void *userdata)
|
||||
static int m_handle_status(void *object, int i, bool status, void *userdata)
|
||||
{
|
||||
Messenger *m = (Messenger *)object;
|
||||
|
||||
|
@ -2060,7 +2054,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
|||
break;
|
||||
}
|
||||
|
||||
const bool typing = !!data[0];
|
||||
const bool typing = data[0] != 0;
|
||||
|
||||
set_friend_typing(m, i, typing);
|
||||
|
||||
|
@ -2149,7 +2143,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
|||
VLA(uint8_t, filename_terminated, filename_length + 1);
|
||||
const uint8_t *filename = nullptr;
|
||||
|
||||
if (filename_length) {
|
||||
if (filename_length != 0) {
|
||||
/* Force NULL terminate file name. */
|
||||
memcpy(filename_terminated, data + head_length, filename_length);
|
||||
filename_terminated[filename_length] = 0;
|
||||
|
@ -2173,7 +2167,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
|||
break;
|
||||
}
|
||||
|
||||
const uint8_t send_receive = data[0];
|
||||
const bool send_receive = data[0] != 0;
|
||||
uint8_t filenumber = data[1];
|
||||
const uint8_t control_type = data[2];
|
||||
|
||||
|
@ -2239,7 +2233,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
|||
|
||||
ft->transferred += file_data_length;
|
||||
|
||||
if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) {
|
||||
if (file_data_length > 0 && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) {
|
||||
file_data_length = 0;
|
||||
file_data = nullptr;
|
||||
position = ft->transferred;
|
||||
|
@ -3283,7 +3277,7 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, Messe
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (options->tcp_server_port) {
|
||||
if (options->tcp_server_port != 0) {
|
||||
m->tcp_server = new_TCP_server(m->log, options->ipv6enabled, 1, &options->tcp_server_port,
|
||||
dht_get_self_secret_key(m->dht), m->onion);
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C
|
|||
// drain all data
|
||||
const uint16_t data_left = net_socket_data_recv_buffer(tcp_conn->con.sock);
|
||||
|
||||
if (data_left) {
|
||||
if (data_left > 0) {
|
||||
VLA(uint8_t, temp_data, data_left);
|
||||
read_TCP_packet(logger, tcp_conn->con.sock, temp_data, data_left, &tcp_conn->con.ip_port);
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
|
|||
non_null()
|
||||
static void wipe_secure_connection(TCP_Secure_Connection *con)
|
||||
{
|
||||
if (con->status) {
|
||||
if (con->status != 0) {
|
||||
wipe_priority_list(con->con.priority_queue_start);
|
||||
crypto_memzero(con, sizeof(TCP_Secure_Connection));
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *co
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (con->connections[con_number].status) {
|
||||
if (con->connections[con_number].status != 0) {
|
||||
if (con->connections[con_number].status == 2) {
|
||||
const uint32_t index = con->connections[con_number].index;
|
||||
const uint8_t other_id = con->connections[con_number].other_id;
|
||||
|
@ -831,7 +831,7 @@ static Socket new_listening_TCP_socket(const Logger *logger, Family family, uint
|
|||
return sock;
|
||||
}
|
||||
|
||||
TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
|
||||
TCP_Server *new_TCP_server(const Logger *logger, bool ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
|
||||
const uint8_t *secret_key, Onion *onion)
|
||||
{
|
||||
if (num_sockets == 0 || ports == nullptr) {
|
||||
|
|
|
@ -35,7 +35,7 @@ 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,
|
||||
TCP_Server *new_TCP_server(const Logger *logger, bool ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
|
||||
const uint8_t *secret_key, Onion *onion);
|
||||
|
||||
/** Run the TCP_server
|
||||
|
|
|
@ -307,7 +307,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
|
|||
data[0] = PACKET_ID_SHARE_RELAYS;
|
||||
++length;
|
||||
|
||||
if (write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, data, length, 0) != -1) {
|
||||
if (write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, data, length, false) != -1) {
|
||||
friend_con->share_relays_lastsent = mono_time_get(fr_c->mono_time);
|
||||
return 1;
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
|
|||
|
||||
friend_con->dht_pk_lastrecv = mono_time_get(fr_c->mono_time);
|
||||
|
||||
if (friend_con->dht_lock) {
|
||||
if (friend_con->dht_lock > 0) {
|
||||
if (dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) {
|
||||
LOGGER_ERROR(fr_c->logger, "a. Could not delete dht peer. Please report this.");
|
||||
return;
|
||||
|
@ -386,7 +386,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
|
|||
}
|
||||
|
||||
non_null()
|
||||
static int handle_status(void *object, int number, uint8_t status, void *userdata)
|
||||
static int handle_status(void *object, int number, bool status, void *userdata)
|
||||
{
|
||||
Friend_Connections *const fr_c = (Friend_Connections *)object;
|
||||
Friend_Conn *const friend_con = get_conn(fr_c, number);
|
||||
|
@ -395,17 +395,17 @@ static int handle_status(void *object, int number, uint8_t status, void *userdat
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool status_changed = 0;
|
||||
bool status_changed = false;
|
||||
|
||||
if (status) { /* Went online. */
|
||||
status_changed = 1;
|
||||
status_changed = true;
|
||||
friend_con->status = FRIENDCONN_STATUS_CONNECTED;
|
||||
friend_con->ping_lastrecv = mono_time_get(fr_c->mono_time);
|
||||
friend_con->share_relays_lastsent = 0;
|
||||
onion_set_friend_online(fr_c->onion_c, friend_con->onion_friendnum, status);
|
||||
} else { /* Went offline. */
|
||||
if (friend_con->status != FRIENDCONN_STATUS_CONNECTING) {
|
||||
status_changed = 1;
|
||||
status_changed = true;
|
||||
friend_con->dht_pk_lastrecv = mono_time_get(fr_c->mono_time);
|
||||
onion_set_friend_online(fr_c->onion_c, friend_con->onion_friendnum, status);
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
|
|||
if (friend_con->crypt_connection_id != -1) {
|
||||
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
|
||||
friend_con->crypt_connection_id = -1;
|
||||
handle_status(object, number, 0, userdata); /* Going offline. */
|
||||
handle_status(object, number, false, userdata); /* Going offline. */
|
||||
}
|
||||
|
||||
friend_new_connection(fr_c, number);
|
||||
|
@ -604,7 +604,7 @@ static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id)
|
|||
}
|
||||
|
||||
/* If dht_temp_pk does not contains a pk. */
|
||||
if (!friend_con->dht_lock) {
|
||||
if (friend_con->dht_lock == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -633,7 +633,7 @@ static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
|
|||
}
|
||||
|
||||
const uint8_t ping = PACKET_ID_ALIVE;
|
||||
const int64_t ret = write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, &ping, sizeof(ping), 0);
|
||||
const int64_t ret = write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, &ping, sizeof(ping), false);
|
||||
|
||||
if (ret != -1) {
|
||||
friend_con->ping_lastsent = mono_time_get(fr_c->mono_time);
|
||||
|
@ -824,7 +824,7 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (friend_con->lock_count) {
|
||||
if (friend_con->lock_count > 0) {
|
||||
--friend_con->lock_count;
|
||||
return 0;
|
||||
}
|
||||
|
@ -832,7 +832,7 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id)
|
|||
onion_delfriend(fr_c->onion_c, friend_con->onion_friendnum);
|
||||
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
|
||||
|
||||
if (friend_con->dht_lock) {
|
||||
if (friend_con->dht_lock > 0) {
|
||||
dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
|
||||
}
|
||||
|
||||
|
@ -876,7 +876,7 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
|
|||
|
||||
if (friend_con->status == FRIENDCONN_STATUS_CONNECTED) {
|
||||
packet[0] = PACKET_ID_FRIEND_REQUESTS;
|
||||
return write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, packet, SIZEOF_VLA(packet), 0) != -1;
|
||||
return write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, packet, SIZEOF_VLA(packet), false) != -1;
|
||||
}
|
||||
|
||||
packet[0] = CRYPTO_PACKET_FRIEND_REQ;
|
||||
|
@ -960,7 +960,7 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
|
|||
if (friend_con != nullptr) {
|
||||
if (friend_con->status == FRIENDCONN_STATUS_CONNECTING) {
|
||||
if (friend_con->dht_pk_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
|
||||
if (friend_con->dht_lock) {
|
||||
if (friend_con->dht_lock > 0) {
|
||||
dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
|
||||
friend_con->dht_lock = 0;
|
||||
memset(friend_con->dht_temp_pk, 0, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
@ -971,7 +971,7 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
|
|||
friend_con->dht_ip_port.ip.family = net_family_unspec;
|
||||
}
|
||||
|
||||
if (friend_con->dht_lock) {
|
||||
if (friend_con->dht_lock > 0) {
|
||||
if (friend_new_connection(fr_c, i) == 0) {
|
||||
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, &friend_con->dht_ip_port, 0);
|
||||
connect_to_saved_tcp_relays(fr_c, i, MAX_FRIEND_TCP_CONNECTIONS / 2); /* Only fill it half up. */
|
||||
|
@ -990,7 +990,7 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
|
|||
/* If we stopped receiving ping packets, kill it. */
|
||||
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
|
||||
friend_con->crypt_connection_id = -1;
|
||||
handle_status(fr_c, i, 0, userdata); /* Going offline. */
|
||||
handle_status(fr_c, i, false, userdata); /* Going offline. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,9 +84,9 @@ int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, const Frie
|
|||
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);
|
||||
typedef int global_status_cb(void *object, int id, bool status, void *userdata);
|
||||
|
||||
typedef int fc_status_cb(void *object, int id, uint8_t status, void *userdata);
|
||||
typedef int fc_status_cb(void *object, int id, bool status, void *userdata);
|
||||
typedef int fc_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
|
||||
typedef int fc_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
|
||||
|
||||
|
|
|
@ -1036,7 +1036,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)
|
||||
static int g_handle_any_status(void *object, int friendcon_id, bool status, void *userdata)
|
||||
{
|
||||
Group_Chats *g_c = (Group_Chats *)object;
|
||||
|
||||
|
@ -1048,7 +1048,7 @@ static int g_handle_any_status(void *object, int friendcon_id, uint8_t status, v
|
|||
}
|
||||
|
||||
non_null(1) nullable(4)
|
||||
static int g_handle_status(void *object, int friendcon_id, uint8_t status, void *userdata)
|
||||
static int g_handle_status(void *object, int friendcon_id, bool status, void *userdata)
|
||||
{
|
||||
Group_Chats *g_c = (Group_Chats *)object;
|
||||
|
||||
|
@ -1450,7 +1450,7 @@ static bool send_packet_group_peer(const Friend_Connections *fr_c, int friendcon
|
|||
memcpy(packet + 1, &group_num, sizeof(uint16_t));
|
||||
memcpy(packet + 1 + sizeof(uint16_t), data, length);
|
||||
return write_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id), packet,
|
||||
SIZEOF_VLA(packet), 0) != -1;
|
||||
SIZEOF_VLA(packet), false) != -1;
|
||||
}
|
||||
|
||||
/** Send a group lossy packet to friendcon_id.
|
||||
|
@ -1526,7 +1526,7 @@ static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk
|
|||
memcpy(packet + 2, g->id, GROUP_ID_LENGTH);
|
||||
|
||||
if (write_cryptpacket(friendconn_net_crypto(g_c->fr_c), friend_connection_crypt_connection_id(g_c->fr_c, friendcon_id),
|
||||
packet, sizeof(packet), 0) == -1) {
|
||||
packet, sizeof(packet), false) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2106,7 +2106,7 @@ static int send_packet_online(const Friend_Connections *fr_c, int friendcon_id,
|
|||
packet[1 + sizeof(uint16_t)] = type;
|
||||
memcpy(packet + 1 + sizeof(uint16_t) + 1, id, GROUP_ID_LENGTH);
|
||||
return write_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id), packet,
|
||||
sizeof(packet), 0) != -1;
|
||||
sizeof(packet), false) != -1;
|
||||
}
|
||||
|
||||
non_null()
|
||||
|
|
|
@ -112,7 +112,7 @@ typedef struct Crypto_Connection {
|
|||
/* TCP_connection connection_number */
|
||||
unsigned int connection_number_tcp;
|
||||
|
||||
uint8_t maximum_speed_reached;
|
||||
bool maximum_speed_reached;
|
||||
|
||||
/* Must be a pointer, because the struct is moved in memory */
|
||||
pthread_mutex_t *mutex;
|
||||
|
@ -1161,7 +1161,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
|
|||
dt->sent_time = current_time_monotonic(c->mono_time);
|
||||
}
|
||||
|
||||
conn->maximum_speed_reached = 0;
|
||||
conn->maximum_speed_reached = false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1172,7 +1172,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
|
|||
*/
|
||||
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)
|
||||
bool congestion_control)
|
||||
{
|
||||
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) {
|
||||
LOGGER_ERROR(c->log, "rejecting too large (or empty) packet of size %d on crypt connection %d", length,
|
||||
|
@ -1207,7 +1207,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!congestion_control && conn->maximum_speed_reached) {
|
||||
if (congestion_control && conn->maximum_speed_reached) {
|
||||
return packet_num;
|
||||
}
|
||||
|
||||
|
@ -1218,7 +1218,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
|
|||
dt1->sent_time = current_time_monotonic(c->mono_time);
|
||||
}
|
||||
} else {
|
||||
conn->maximum_speed_reached = 1;
|
||||
conn->maximum_speed_reached = true;
|
||||
LOGGER_DEBUG(c->log, "send_data_packet failed (packet_num = %ld)", (long)packet_num);
|
||||
}
|
||||
|
||||
|
@ -1510,8 +1510,8 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
|
|||
}
|
||||
|
||||
if (conn->connection_status_callback != nullptr) {
|
||||
conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 0,
|
||||
userdata);
|
||||
conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id,
|
||||
false, userdata);
|
||||
}
|
||||
|
||||
while (1) { /* TODO(irungentoo): is this really the best way to do this? */
|
||||
|
@ -1597,8 +1597,8 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
|
|||
conn->status = CRYPTO_CONN_ESTABLISHED;
|
||||
|
||||
if (conn->connection_status_callback != nullptr) {
|
||||
conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 1,
|
||||
userdata);
|
||||
conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id,
|
||||
true, userdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2861,7 +2861,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
|
|||
* 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)
|
||||
bool congestion_control)
|
||||
{
|
||||
if (length == 0) {
|
||||
// We need at least a packet id.
|
||||
|
|
|
@ -125,7 +125,7 @@ typedef struct New_Connection {
|
|||
uint8_t cookie_length;
|
||||
} New_Connection;
|
||||
|
||||
typedef int connection_status_cb(void *object, int id, uint8_t status, void *userdata);
|
||||
typedef int connection_status_cb(void *object, int id, bool status, void *userdata);
|
||||
typedef int connection_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
|
||||
typedef int connection_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
|
||||
typedef void dht_pk_cb(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata);
|
||||
|
@ -243,7 +243,7 @@ bool max_speed_reached(Net_Crypto *c, int crypt_connection_id);
|
|||
*/
|
||||
non_null()
|
||||
int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id,
|
||||
const uint8_t *data, uint16_t length, uint8_t congestion_control);
|
||||
const uint8_t *data, uint16_t length, bool congestion_control);
|
||||
|
||||
/** Check if packet_number was received by the other side.
|
||||
*
|
||||
|
|
|
@ -1196,7 +1196,7 @@ bool ipport_isset(const IP_Port *ipport)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ipport->port) {
|
||||
if (ipport->port == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1337,9 +1337,9 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
}
|
||||
|
||||
IP ip4;
|
||||
ip_init(&ip4, 0); // ipv6enabled = 0
|
||||
ip_init(&ip4, false); // ipv6enabled = false
|
||||
IP ip6;
|
||||
ip_init(&ip6, 1); // ipv6enabled = 1
|
||||
ip_init(&ip6, true); // ipv6enabled = true
|
||||
|
||||
int result = 0;
|
||||
bool done = false;
|
||||
|
|
|
@ -250,7 +250,7 @@ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uin
|
|||
non_null()
|
||||
static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num)
|
||||
{
|
||||
if (!max_num) {
|
||||
if (max_num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1708,7 +1708,7 @@ static void do_announce(Onion_Client *onion_c)
|
|||
|
||||
unsigned int interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED;
|
||||
|
||||
if (list_nodes[i].is_stored && path_exists(onion_c->mono_time, &onion_c->onion_paths_self, list_nodes[i].path_used)) {
|
||||
if (list_nodes[i].is_stored != 0 && path_exists(onion_c->mono_time, &onion_c->onion_paths_self, list_nodes[i].path_used)) {
|
||||
interval = ANNOUNCE_INTERVAL_ANNOUNCED;
|
||||
|
||||
const uint32_t pathnum = list_nodes[i].path_used % NUMBER_ONION_PATHS;
|
||||
|
|
|
@ -2587,12 +2587,12 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
|
|||
const uint16_t port = net_htons(net_port(tox->m->net));
|
||||
unlock(tox);
|
||||
|
||||
if (port) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
|
||||
} else {
|
||||
if (port == 0) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
|
||||
return port;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user