mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Exposed and tested disconnect notification TCP packets.
This commit is contained in:
parent
1e7164fcee
commit
a514167952
|
@ -446,6 +446,15 @@ START_TEST(test_client)
|
|||
do_TCP_connection(conn);
|
||||
do_TCP_connection(conn2);
|
||||
ck_assert_msg(data_callback_good == 1, "data callback not called");
|
||||
status_callback_good = 0;
|
||||
send_disconnect_request(conn2, 0);
|
||||
c_sleep(50);
|
||||
do_TCP_server(tcp_s);
|
||||
c_sleep(50);
|
||||
do_TCP_connection(conn);
|
||||
do_TCP_connection(conn2);
|
||||
ck_assert_msg(status_callback_good == 1, "status callback not called");
|
||||
ck_assert_msg(status_callback_status == 1, "wrong status");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
@ -300,6 +300,20 @@ static int send_ping_response(TCP_Client_Connection *con, uint64_t ping_id)
|
|||
return write_packet_TCP_secure_connection(con, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if (con_id >= NUM_CLIENT_CONNECTIONS)
|
||||
return -1;
|
||||
|
||||
con->connections[con_id].status = 0;
|
||||
con->connections[con_id].number = 0;
|
||||
return send_disconnect_notification(con, con_id + NUM_RESERVED_PORTS);
|
||||
}
|
||||
|
||||
/* return 1 on success.
|
||||
* return 0 if could not send packet.
|
||||
* return -1 on failure (connection must be killed).
|
||||
|
@ -564,6 +578,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection)
|
|||
|
||||
if (sizeof(data) == len) {
|
||||
if (handle_handshake(TCP_connection, data) == 0) {
|
||||
TCP_connection->kill_at = ~0;
|
||||
TCP_connection->status = TCP_CLIENT_CONFIRMED;
|
||||
} else {
|
||||
TCP_connection->kill_at = 0;
|
||||
|
|
|
@ -105,6 +105,12 @@ void routing_response_handler(TCP_Client_Connection *con, int (*response_callbac
|
|||
void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number,
|
||||
uint8_t connection_id, uint8_t status), void *object);
|
||||
|
||||
/* 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.
|
||||
*
|
||||
* When not set by this function, the number is ~0.
|
||||
|
|
Loading…
Reference in New Issue
Block a user