|
|
|
@ -154,10 +154,6 @@ enum {
|
|
|
|
|
ST_NUM_STATES, // used for bounds checking
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const cstr flagnames[] = {
|
|
|
|
|
"ST_DATA","ST_FIN","ST_STATE","ST_RESET","ST_SYN"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum CONN_STATE {
|
|
|
|
|
CS_UNINITIALIZED = 0,
|
|
|
|
|
CS_IDLE,
|
|
|
|
@ -169,10 +165,17 @@ enum CONN_STATE {
|
|
|
|
|
CS_DESTROY
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if UTP_DEBUG_LOGGING
|
|
|
|
|
static const cstr flagnames[] = {
|
|
|
|
|
"ST_DATA","ST_FIN","ST_STATE","ST_RESET","ST_SYN"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const cstr statenames[] = {
|
|
|
|
|
"UNINITIALIZED", "IDLE","SYN_SENT", "SYN_RECV", "CONNECTED","CONNECTED_FULL","DESTROY_DELAY","RESET","DESTROY"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct OutgoingPacket {
|
|
|
|
|
size_t length;
|
|
|
|
|
size_t payload;
|
|
|
|
@ -1178,7 +1181,7 @@ void UTPSocket::check_timeouts()
|
|
|
|
|
// Increase RTO
|
|
|
|
|
const uint new_timeout = ignore_loss ? retransmit_timeout : retransmit_timeout * 2;
|
|
|
|
|
|
|
|
|
|
// They initiated the connection but failed to respond before the rto.
|
|
|
|
|
// They initiated the connection but failed to respond before the rto.
|
|
|
|
|
// A malicious client can also spoof the destination address of a ST_SYN bringing us to this state.
|
|
|
|
|
// Kill the connection and do not notify the upper layer
|
|
|
|
|
if (state == CS_SYN_RECV) {
|
|
|
|
@ -1797,7 +1800,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo
|
|
|
|
|
// or a malicious attempt to attach the uTP implementation.
|
|
|
|
|
// acking a packet that hasn't been sent yet!
|
|
|
|
|
// SYN packets have an exception, since there are no previous packets
|
|
|
|
|
if ((pk_flags != ST_SYN || conn->state != CS_SYN_RECV) &&
|
|
|
|
|
if ((pk_flags != ST_SYN || conn->state != CS_SYN_RECV) &&
|
|
|
|
|
(wrapping_compare_less(conn->seq_nr - 1, pk_ack_nr, ACK_NR_MASK)
|
|
|
|
|
|| wrapping_compare_less(pk_ack_nr, conn->seq_nr - 1 - curr_window, ACK_NR_MASK))) {
|
|
|
|
|
#if UTP_DEBUG_LOGGING
|
|
|
|
@ -1966,7 +1969,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo
|
|
|
|
|
if (pkt == 0 || pkt->transmissions == 0) continue;
|
|
|
|
|
assert((int)(pkt->payload) >= 0);
|
|
|
|
|
acked_bytes += pkt->payload;
|
|
|
|
|
if (conn->mtu_probe_seq && seq == conn->mtu_probe_seq) {
|
|
|
|
|
if (conn->mtu_probe_seq && seq == static_cast< int >(conn->mtu_probe_seq)) {
|
|
|
|
|
conn->mtu_floor = conn->mtu_probe_size;
|
|
|
|
|
conn->mtu_search_update();
|
|
|
|
|
conn->log(UTP_LOG_MTU, "MTU [ACK] floor:%d ceiling:%d current:%d"
|
|
|
|
@ -2163,7 +2166,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo
|
|
|
|
|
// Outgoing connection completion
|
|
|
|
|
if (pk_flags == ST_STATE && conn->state == CS_SYN_SENT) {
|
|
|
|
|
conn->state = CS_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the user has defined the ON_CONNECT callback, use that to
|
|
|
|
|
// notify the user that the socket is now connected. If ON_CONNECT
|
|
|
|
|
// has not been defined, notify the user via ON_STATE_CHANGE.
|
|
|
|
@ -2173,7 +2176,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo
|
|
|
|
|
utp_call_on_state_change(conn->ctx, conn, UTP_STATE_CONNECT);
|
|
|
|
|
|
|
|
|
|
// We've sent a fin, and everything was ACKed (including the FIN).
|
|
|
|
|
// cur_window_packets == acks means that this packet acked all
|
|
|
|
|
// cur_window_packets == acks means that this packet acked all
|
|
|
|
|
// the remaining packets that were in-flight.
|
|
|
|
|
} else if (conn->fin_sent && conn->cur_window_packets == acks) {
|
|
|
|
|
conn->fin_sent_acked = true;
|
|
|
|
@ -3075,7 +3078,7 @@ static UTPSocket* parse_icmp_payload(utp_context *ctx, const byte *buffer, size_
|
|
|
|
|
// @len: buffer length
|
|
|
|
|
// @to: destination address of the original UDP pakcet
|
|
|
|
|
// @tolen: address length
|
|
|
|
|
// @next_hop_mtu:
|
|
|
|
|
// @next_hop_mtu:
|
|
|
|
|
int utp_process_icmp_fragmentation(utp_context *ctx, const byte* buffer, size_t len, const struct sockaddr *to, socklen_t tolen, uint16 next_hop_mtu)
|
|
|
|
|
{
|
|
|
|
|
UTPSocket* conn = parse_icmp_payload(ctx, buffer, len, to, tolen);
|
|
|
|
|