mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added kill packets.
There should be no more delay between a peer closing their client and their friend being notified of them going offline. (unless the kill packet is lost)
This commit is contained in:
parent
ff4368add7
commit
1580a5c696
|
@ -100,6 +100,7 @@ lossy][data]
|
|||
data ids:
|
||||
0: padding (skipped until we hit a non zero (data id) byte)
|
||||
1: packet request packet (lossy packet)
|
||||
2: connection kill packet (lossy packet) (tells the other that the connection is over)
|
||||
...
|
||||
16+: reserved for Messenger usage (lossless packets).
|
||||
|
||||
|
|
|
@ -918,6 +918,23 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Send a kill packet.
|
||||
*
|
||||
* return -1 on failure.
|
||||
* return 0 on success.
|
||||
*/
|
||||
static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
|
||||
{
|
||||
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
|
||||
|
||||
if (conn == 0)
|
||||
return -1;
|
||||
|
||||
uint8_t kill_packet = PACKET_ID_KILL;
|
||||
return send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, conn->send_array.buffer_end,
|
||||
&kill_packet, sizeof(kill_packet));
|
||||
}
|
||||
|
||||
/* Handle a recieved data packet.
|
||||
*
|
||||
* return -1 on failure.
|
||||
|
@ -969,6 +986,9 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uin
|
|||
}
|
||||
|
||||
set_buffer_end(&conn->recv_array, num);
|
||||
} else if (real_data[0] == PACKET_ID_KILL) {
|
||||
conn->killed = 1;
|
||||
return 0;
|
||||
} else {
|
||||
Packet_Data dt;
|
||||
dt.time = current_time_monotonic();
|
||||
|
@ -1627,6 +1647,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
|
|||
int crypto_kill(Net_Crypto *c, int crypt_connection_id)
|
||||
{
|
||||
//TODO
|
||||
send_kill_packet(c, crypt_connection_id);
|
||||
return wipe_crypto_connection(c, crypt_connection_id);
|
||||
}
|
||||
|
||||
|
@ -1713,6 +1734,11 @@ static void kill_timedout(Net_Crypto *c)
|
|||
if (conn->temp_packet_num_sent < MAX_NUM_SENDPACKET_TRIES)
|
||||
continue;
|
||||
|
||||
conn->killed = 1;
|
||||
|
||||
}
|
||||
|
||||
if (conn->killed) {
|
||||
if (conn->connection_status_callback) {
|
||||
conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 0);
|
||||
crypto_kill(c, i);
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
|
||||
#define PACKET_ID_PADDING 0
|
||||
#define PACKET_ID_REQUEST 1
|
||||
#define PACKET_ID_KILL 2
|
||||
|
||||
#define CRYPTO_RESERVED_PACKETS 16
|
||||
|
||||
|
@ -119,6 +120,8 @@ typedef struct {
|
|||
uint64_t last_packets_left_set;
|
||||
|
||||
uint8_t sending; /* indicates if data is being sent or not. */
|
||||
|
||||
uint8_t killed; /* set to 1 to kill the connection. */
|
||||
} Crypto_Connection;
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user