Skip to content

Commit

Permalink
cleanup: Sync comments in all toxcore/*.[ch].
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Dec 21, 2021
1 parent aaba738 commit 08d82dc
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 161 deletions.
16 changes: 12 additions & 4 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ int packed_node_size(Family ip_family)


/** Packs an IP_Port structure into data of max size length.
*
* Packed_length is the offset of data currently packed.
*
* Returns size of packed IP_Port data on success
* Return -1 on failure.
Expand Down Expand Up @@ -473,6 +475,8 @@ static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
}

/** Unpack IP_Port structure from data of max size length into ip_port.
*
* len_processed is the offset of data currently unpacked.
*
* Return size of unpacked ip_port on success.
* Return -1 on failure.
Expand Down Expand Up @@ -1464,7 +1468,7 @@ static bool sent_getnode_to_node(DHT *dht, const uint8_t *public_key, IP_Port no
return true;
}

/** Function is needed in following functions. */
/* Function is needed in following functions. */
static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id,
const uint8_t *nodes_data, uint16_t nodes_data_length);

Expand Down Expand Up @@ -1873,7 +1877,7 @@ int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
return 0;
}

/** Send the given packet to node with public_key
/** Send the given packet to node with public_key.
*
* return -1 if failure.
*/
Expand Down Expand Up @@ -2904,10 +2908,14 @@ void dht_save(const DHT *dht, uint8_t *data)
free(clients);
}

/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
/** Bootstrap from this number of nodes every time dht_connect_after_load() is called */
#define SAVE_BOOTSTAP_FREQUENCY 8

/** Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */
/** Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
*
* returns 0 if successful
* returns -1 otherwise
*/
int dht_connect_after_load(DHT *dht)
{
if (dht == nullptr) {
Expand Down
13 changes: 8 additions & 5 deletions toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ extern "C" {
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
/** 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.
* packet is the request packet and length is its length
* return -1 if not valid request. */
* packet is the request packet and length is its length.
*
* 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);

Expand Down Expand Up @@ -294,7 +296,7 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
*/
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);

/**
/***
* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
*
* @return true iff the node was added to the list.
Expand Down Expand Up @@ -373,7 +375,8 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe

/** Send the following packet to everyone who tells us they are connected to friend_id.
*
* return number of nodes it sent the packet to.
* return ip for friend.
* return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
*/
int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *packet, uint16_t length);

Expand Down
48 changes: 24 additions & 24 deletions toxcore/TCP_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
con->custom_uint = value;
}

/* return 1 on success
/** return 1 on success
* return 0 on failure
*/
static int connect_sock_to(Socket sock, IP_Port ip_port, const TCP_Proxy_Info *proxy_info)
Expand All @@ -115,7 +115,7 @@ static int connect_sock_to(Socket sock, IP_Port ip_port, const TCP_Proxy_Info *p
return 1;
}

/* return 1 on success.
/** return 1 on success.
* return 0 on failure.
*/
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
Expand Down Expand Up @@ -144,7 +144,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
return 1;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
Expand Down Expand Up @@ -186,7 +186,7 @@ static void proxy_socks5_generate_handshake(TCP_Client_Connection *tcp_conn)
tcp_conn->last_packet_sent = 0;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
Expand Down Expand Up @@ -232,7 +232,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
tcp_conn->last_packet_sent = 0;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if no data received.
* return -1 on failure (connection refused).
*/
Expand Down Expand Up @@ -265,7 +265,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, TCP_Clien
return -1;
}

/* return 0 on success.
/** return 0 on success.
* return -1 on failure.
*/
static int generate_handshake(TCP_Client_Connection *tcp_conn)
Expand All @@ -288,7 +288,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn)
return 0;
}

/* data must be of length TCP_SERVER_HANDSHAKE_SIZE
/** data must be of length TCP_SERVER_HANDSHAKE_SIZE
*
* return 0 on success.
* return -1 on failure.
Expand All @@ -309,7 +309,7 @@ static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data
return 0;
}

/* return 0 if pending data was sent completely
/** return 0 if pending data was sent completely
* return -1 if it wasn't
*/
static int client_send_pending_data_nonpriority(TCP_Client_Connection *con)
Expand All @@ -335,7 +335,7 @@ static int client_send_pending_data_nonpriority(TCP_Client_Connection *con)
return -1;
}

/* return 0 if pending data was sent completely
/** return 0 if pending data was sent completely
* return -1 if it wasn't
*/
static int client_send_pending_data(TCP_Client_Connection *con)
Expand Down Expand Up @@ -374,7 +374,7 @@ static int client_send_pending_data(TCP_Client_Connection *con)
return -1;
}

/* return 0 on failure (only if malloc fails)
/** return 0 on failure (only if malloc fails)
* return 1 on success
*/
static bool client_add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
Expand All @@ -401,7 +401,7 @@ static bool client_add_priority(TCP_Client_Connection *con, const uint8_t *packe
return 1;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand Down Expand Up @@ -466,7 +466,7 @@ static int write_packet_TCP_client_secure_connection(TCP_Client_Connection *con,
return 1;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -493,7 +493,7 @@ void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *s
static int tcp_send_ping_response(TCP_Client_Connection *con);
static int tcp_send_ping_request(TCP_Client_Connection *con);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure.
*/
Expand All @@ -517,7 +517,7 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, u
return write_packet_TCP_client_secure_connection(con, packet, SIZEOF_VLA(packet), 0);
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure.
*/
Expand All @@ -535,7 +535,7 @@ int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const
}


/* Set the number that will be used as an argument in the callbacks related to con_id.
/** Set the number that will be used as an argument in the callbacks related to con_id.
*
* When not set by this function, the number is -1.
*
Expand Down Expand Up @@ -568,7 +568,7 @@ void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_call
con->oob_data_callback_object = object;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -580,7 +580,7 @@ static int client_send_disconnect_notification(TCP_Client_Connection *con, uint8
return write_packet_TCP_client_secure_connection(con, packet, sizeof(packet), 1);
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -602,7 +602,7 @@ static int tcp_send_ping_request(TCP_Client_Connection *con)
return ret;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -624,7 +624,7 @@ static int tcp_send_ping_response(TCP_Client_Connection *con)
return ret;
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -639,7 +639,7 @@ int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id)
return client_send_disconnect_notification(con, con_id + NUM_RESERVED_PORTS);
}

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -657,7 +657,7 @@ void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *o
con->onion_callback_object = object;
}

/* Create new TCP connection to ip_port/public_key
/** Create new TCP connection to ip_port/public_key
*/
TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, 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)
Expand Down Expand Up @@ -743,7 +743,7 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip
return temp;
}

/* return 0 on success
/** return 0 on success
* return -1 on failure
*/
static int handle_TCP_client_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
Expand Down Expand Up @@ -955,7 +955,7 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c
return 0;
}

/* Run the TCP connection
/** Run the TCP connection
*/
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection,
void *userdata)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Co
}
}

/* Kill the TCP connection
/** Kill the TCP connection
*/
void kill_TCP_connection(TCP_Client_Connection *tcp_connection)
{
Expand Down
18 changes: 9 additions & 9 deletions toxcore/TCP_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ uint32_t tcp_con_custom_uint(const TCP_Client_Connection *con);
void tcp_con_set_custom_object(TCP_Client_Connection *con, void *object);
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);

/* Create new TCP connection to ip_port/public_key
/** Create new TCP connection to ip_port/public_key
*/
TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, 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
/** Run the TCP connection
*/
void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection,
void *userdata);

/* Kill the TCP connection
/** Kill the TCP connection
*/
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);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
Expand All @@ -73,21 +73,21 @@ void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *o
typedef int tcp_routing_response_cb(void *object, uint8_t connection_id, const uint8_t *public_key);
typedef int tcp_routing_status_cb(void *object, uint32_t number, uint8_t connection_id, uint8_t status);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key);
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object);
void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_disconnect_request(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.
/** Set the number that will be used as an argument in the callbacks related to con_id.
*
* When not set by this function, the number is -1.
*
Expand All @@ -99,7 +99,7 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32
typedef int tcp_routing_data_cb(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
uint16_t length, void *userdata);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure.
*/
Expand All @@ -109,7 +109,7 @@ void routing_data_handler(TCP_Client_Connection *con, tcp_routing_data_cb *data_
typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata);

/* return 1 on success.
/** return 1 on success.
* return 0 if could not send packet.
* return -1 on failure.
*/
Expand Down
Loading

0 comments on commit 08d82dc

Please sign in to comment.