21 #ifndef UTP_UTPPROTOCOL_H
22 #define UTP_UTPPROTOCOL_H
26 #include <ktorrent_export.h>
27 #include <util/constants.h>
51 unsigned int version: 4;
54 bt::Uint16 connection_id;
55 bt::Uint32 timestamp_microseconds;
56 bt::Uint32 timestamp_difference_microseconds;
61 void read(
const bt::Uint8* data);
62 void write(bt::Uint8* data)
const;
63 static bt::Uint32 size();
79 bt::Uint8 extension_bitmask[8];
88 const bt::Uint8 SELECTIVE_ACK_ID = 1;
89 const bt::Uint8 EXTENSION_BITS_ID = 2;
92 const bt::Uint8 ST_DATA = 0;
93 const bt::Uint8 ST_FIN = 1;
94 const bt::Uint8 ST_STATE = 2;
95 const bt::Uint8 ST_RESET = 3;
96 const bt::Uint8 ST_SYN = 4;
98 KTORRENT_EXPORT QString TypeToString(bt::Uint8 type);
109 const bt::Uint32 MIN_PACKET_SIZE = 150;
110 const bt::Uint32 MAX_PACKET_SIZE = 16384;
112 const bt::Uint32 DELAY_WINDOW_SIZE = 2*60*1000;
113 const bt::Uint32 CCONTROL_TARGET = 100;
114 const bt::Uint32 MAX_CWND_INCREASE_PACKETS_PER_RTT = 500;
115 const bt::Uint32 MAX_TIMEOUT = 30000;
116 const bt::Uint32 CONNECT_TIMEOUT = 30000;
117 const bt::Uint32 KEEP_ALIVE_TIMEOUT = 30000;
119 const bt::Uint32 IP_AND_UDP_OVERHEAD = 28;
135 inline bool Acked(
const SelectiveAck* sack, bt::Uint16 bit)
138 if (bit < 2 || bit > 8*sack->length + 1)
141 const bt::Uint8* bitset = sack->bitmask;
142 int byte = (bit - 2) / 8;
143 int bit_off = (bit - 2) % 8;
144 return bitset[byte] & (0x01 << bit_off);
148 inline void Ack(SelectiveAck* sack, bt::Uint16 bit)
151 if (bit < 2 || bit > 8*sack->length + 1)
154 bt::Uint8* bitset = sack->bitmask;
155 int byte = (bit - 2) / 8;
156 int bit_off = (bit - 2) % 8;
157 bitset[byte] |= (0x01 << bit_off);
173 const Header* header()
const {
return &hdr;}
175 bt::Uint32 dataOffset()
const {
return data_off;}
176 bt::Uint32 dataSize()
const {
return data_size;}
179 const bt::Uint8* packet;
185 bt::Uint32 data_size;
189 inline bool SeqNrCmpSE(bt::Uint16 a, bt::Uint16 b)
191 if (qAbs(b - a) < 32768)
198 inline bool SeqNrCmpS(bt::Uint16 a, bt::Uint16 b)
200 if (qAbs(b - a) < 32768)
207 inline bt::Uint16 SeqNrDiff(bt::Uint16 a, bt::Uint16 b)
209 if (qAbs(b - a) < 32768)
212 return a + (65536 - b);
214 return b + (65536 - a);
218 #endif // UTP_UTPPROTOCOL_H