Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: webrtc/p2p/base/pseudotcp.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/pseudotcp.h ('k') | webrtc/p2p/base/pseudotcp_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 21 matching lines...) Expand all
32 #define _DBG_VERBOSE 2 32 #define _DBG_VERBOSE 2
33 #define _DEBUGMSG _DBG_NONE 33 #define _DEBUGMSG _DBG_NONE
34 34
35 namespace cricket { 35 namespace cricket {
36 36
37 ////////////////////////////////////////////////////////////////////// 37 //////////////////////////////////////////////////////////////////////
38 // Network Constants 38 // Network Constants
39 ////////////////////////////////////////////////////////////////////// 39 //////////////////////////////////////////////////////////////////////
40 40
41 // Standard MTUs 41 // Standard MTUs
42 const uint16 PACKET_MAXIMUMS[] = { 42 const uint16_t PACKET_MAXIMUMS[] = {
43 65535, // Theoretical maximum, Hyperchannel 43 65535, // Theoretical maximum, Hyperchannel
44 32000, // Nothing 44 32000, // Nothing
45 17914, // 16Mb IBM Token Ring 45 17914, // 16Mb IBM Token Ring
46 8166, // IEEE 802.4 46 8166, // IEEE 802.4
47 //4464, // IEEE 802.5 (4Mb max) 47 // 4464, // IEEE 802.5 (4Mb max)
48 4352, // FDDI 48 4352, // FDDI
49 //2048, // Wideband Network 49 // 2048, // Wideband Network
50 2002, // IEEE 802.5 (4Mb recommended) 50 2002, // IEEE 802.5 (4Mb recommended)
51 //1536, // Expermental Ethernet Networks 51 // 1536, // Expermental Ethernet Networks
52 //1500, // Ethernet, Point-to-Point (default) 52 // 1500, // Ethernet, Point-to-Point (default)
53 1492, // IEEE 802.3 53 1492, // IEEE 802.3
54 1006, // SLIP, ARPANET 54 1006, // SLIP, ARPANET
55 //576, // X.25 Networks 55 // 576, // X.25 Networks
56 //544, // DEC IP Portal 56 // 544, // DEC IP Portal
57 //512, // NETBIOS 57 // 512, // NETBIOS
58 508, // IEEE 802/Source-Rt Bridge, ARCNET 58 508, // IEEE 802/Source-Rt Bridge, ARCNET
59 296, // Point-to-Point (low delay) 59 296, // Point-to-Point (low delay)
60 //68, // Official minimum 60 // 68, // Official minimum
61 0, // End of list marker 61 0, // End of list marker
62 }; 62 };
63 63
64 const uint32 MAX_PACKET = 65535; 64 const uint32_t MAX_PACKET = 65535;
65 // Note: we removed lowest level because packet overhead was larger! 65 // Note: we removed lowest level because packet overhead was larger!
66 const uint32 MIN_PACKET = 296; 66 const uint32_t MIN_PACKET = 296;
67 67
68 const uint32 IP_HEADER_SIZE = 20; // (+ up to 40 bytes of options?) 68 const uint32_t IP_HEADER_SIZE = 20; // (+ up to 40 bytes of options?)
69 const uint32 UDP_HEADER_SIZE = 8; 69 const uint32_t UDP_HEADER_SIZE = 8;
70 // TODO: Make JINGLE_HEADER_SIZE transparent to this code? 70 // TODO: Make JINGLE_HEADER_SIZE transparent to this code?
71 const uint32 JINGLE_HEADER_SIZE = 64; // when relay framing is in use 71 const uint32_t JINGLE_HEADER_SIZE = 64; // when relay framing is in use
72 72
73 // Default size for receive and send buffer. 73 // Default size for receive and send buffer.
74 const uint32 DEFAULT_RCV_BUF_SIZE = 60 * 1024; 74 const uint32_t DEFAULT_RCV_BUF_SIZE = 60 * 1024;
75 const uint32 DEFAULT_SND_BUF_SIZE = 90 * 1024; 75 const uint32_t DEFAULT_SND_BUF_SIZE = 90 * 1024;
76 76
77 ////////////////////////////////////////////////////////////////////// 77 //////////////////////////////////////////////////////////////////////
78 // Global Constants and Functions 78 // Global Constants and Functions
79 ////////////////////////////////////////////////////////////////////// 79 //////////////////////////////////////////////////////////////////////
80 // 80 //
81 // 0 1 2 3 81 // 0 1 2 3
82 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 82 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
83 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 83 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 // 0 | Conversation Number | 84 // 0 | Conversation Number |
85 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 85 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86 // 4 | Sequence Number | 86 // 4 | Sequence Number |
87 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 87 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88 // 8 | Acknowledgment Number | 88 // 8 | Acknowledgment Number |
89 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 89 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 // | | |U|A|P|R|S|F| | 90 // | | |U|A|P|R|S|F| |
91 // 12 | Control | |R|C|S|S|Y|I| Window | 91 // 12 | Control | |R|C|S|S|Y|I| Window |
92 // | | |G|K|H|T|N|N| | 92 // | | |G|K|H|T|N|N| |
93 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 93 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 // 16 | Timestamp sending | 94 // 16 | Timestamp sending |
95 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 95 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 // 20 | Timestamp receiving | 96 // 20 | Timestamp receiving |
97 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 97 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 // 24 | data | 98 // 24 | data |
99 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 99 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100 // 100 //
101 ////////////////////////////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////
102 102
103 #define PSEUDO_KEEPALIVE 0 103 #define PSEUDO_KEEPALIVE 0
104 104
105 const uint32 HEADER_SIZE = 24; 105 const uint32_t HEADER_SIZE = 24;
106 const uint32 PACKET_OVERHEAD = HEADER_SIZE + UDP_HEADER_SIZE + IP_HEADER_SIZE + JINGLE_HEADER_SIZE; 106 const uint32_t PACKET_OVERHEAD =
107 HEADER_SIZE + UDP_HEADER_SIZE + IP_HEADER_SIZE + JINGLE_HEADER_SIZE;
107 108
108 const uint32 MIN_RTO = 250; // 250 ms (RFC1122, Sec 4.2.3.1 "fractions of a second") 109 const uint32_t MIN_RTO =
109 const uint32 DEF_RTO = 3000; // 3 seconds (RFC1122, Sec 4.2.3.1) 110 250; // 250 ms (RFC1122, Sec 4.2.3.1 "fractions of a second")
110 const uint32 MAX_RTO = 60000; // 60 seconds 111 const uint32_t DEF_RTO = 3000; // 3 seconds (RFC1122, Sec 4.2.3.1)
111 const uint32 DEF_ACK_DELAY = 100; // 100 milliseconds 112 const uint32_t MAX_RTO = 60000; // 60 seconds
113 const uint32_t DEF_ACK_DELAY = 100; // 100 milliseconds
112 114
113 const uint8 FLAG_CTL = 0x02; 115 const uint8_t FLAG_CTL = 0x02;
114 const uint8 FLAG_RST = 0x04; 116 const uint8_t FLAG_RST = 0x04;
115 117
116 const uint8 CTL_CONNECT = 0; 118 const uint8_t CTL_CONNECT = 0;
117 119
118 // TCP options. 120 // TCP options.
119 const uint8 TCP_OPT_EOL = 0; // End of list. 121 const uint8_t TCP_OPT_EOL = 0; // End of list.
120 const uint8 TCP_OPT_NOOP = 1; // No-op. 122 const uint8_t TCP_OPT_NOOP = 1; // No-op.
121 const uint8 TCP_OPT_MSS = 2; // Maximum segment size. 123 const uint8_t TCP_OPT_MSS = 2; // Maximum segment size.
122 const uint8 TCP_OPT_WND_SCALE = 3; // Window scale factor. 124 const uint8_t TCP_OPT_WND_SCALE = 3; // Window scale factor.
123 125
124 const long DEFAULT_TIMEOUT = 4000; // If there are no pending clocks, wake up ev ery 4 seconds 126 const long DEFAULT_TIMEOUT = 4000; // If there are no pending clocks, wake up ev ery 4 seconds
125 const long CLOSED_TIMEOUT = 60 * 1000; // If the connection is closed, once per minute 127 const long CLOSED_TIMEOUT = 60 * 1000; // If the connection is closed, once per minute
126 128
127 #if PSEUDO_KEEPALIVE 129 #if PSEUDO_KEEPALIVE
128 // !?! Rethink these times 130 // !?! Rethink these times
129 const uint32 IDLE_PING = 20 * 1000; // 20 seconds (note: WinXP SP2 firewall udp timeout is 90 seconds) 131 const uint32_t IDLE_PING =
130 const uint32 IDLE_TIMEOUT = 90 * 1000; // 90 seconds; 132 20 *
133 1000; // 20 seconds (note: WinXP SP2 firewall udp timeout is 90 seconds)
134 const uint32_t IDLE_TIMEOUT = 90 * 1000; // 90 seconds;
131 #endif // PSEUDO_KEEPALIVE 135 #endif // PSEUDO_KEEPALIVE
132 136
133 ////////////////////////////////////////////////////////////////////// 137 //////////////////////////////////////////////////////////////////////
134 // Helper Functions 138 // Helper Functions
135 ////////////////////////////////////////////////////////////////////// 139 //////////////////////////////////////////////////////////////////////
136 140
137 inline void long_to_bytes(uint32 val, void* buf) { 141 inline void long_to_bytes(uint32_t val, void* buf) {
138 *static_cast<uint32*>(buf) = rtc::HostToNetwork32(val); 142 *static_cast<uint32_t*>(buf) = rtc::HostToNetwork32(val);
139 } 143 }
140 144
141 inline void short_to_bytes(uint16 val, void* buf) { 145 inline void short_to_bytes(uint16_t val, void* buf) {
142 *static_cast<uint16*>(buf) = rtc::HostToNetwork16(val); 146 *static_cast<uint16_t*>(buf) = rtc::HostToNetwork16(val);
143 } 147 }
144 148
145 inline uint32 bytes_to_long(const void* buf) { 149 inline uint32_t bytes_to_long(const void* buf) {
146 return rtc::NetworkToHost32(*static_cast<const uint32*>(buf)); 150 return rtc::NetworkToHost32(*static_cast<const uint32_t*>(buf));
147 } 151 }
148 152
149 inline uint16 bytes_to_short(const void* buf) { 153 inline uint16_t bytes_to_short(const void* buf) {
150 return rtc::NetworkToHost16(*static_cast<const uint16*>(buf)); 154 return rtc::NetworkToHost16(*static_cast<const uint16_t*>(buf));
151 } 155 }
152 156
153 uint32 bound(uint32 lower, uint32 middle, uint32 upper) { 157 uint32_t bound(uint32_t lower, uint32_t middle, uint32_t upper) {
154 return std::min(std::max(lower, middle), upper); 158 return std::min(std::max(lower, middle), upper);
155 } 159 }
156 160
157 ////////////////////////////////////////////////////////////////////// 161 //////////////////////////////////////////////////////////////////////
158 // Debugging Statistics 162 // Debugging Statistics
159 ////////////////////////////////////////////////////////////////////// 163 //////////////////////////////////////////////////////////////////////
160 164
161 #if 0 // Not used yet 165 #if 0 // Not used yet
162 166
163 enum Stat { 167 enum Stat {
(...skipping 25 matching lines...) Expand all
189 } 193 }
190 LOG(LS_INFO) << "Stats[" << buffer << "]"; 194 LOG(LS_INFO) << "Stats[" << buffer << "]";
191 } 195 }
192 196
193 #endif 197 #endif
194 198
195 ////////////////////////////////////////////////////////////////////// 199 //////////////////////////////////////////////////////////////////////
196 // PseudoTcp 200 // PseudoTcp
197 ////////////////////////////////////////////////////////////////////// 201 //////////////////////////////////////////////////////////////////////
198 202
199 uint32 PseudoTcp::Now() { 203 uint32_t PseudoTcp::Now() {
200 #if 0 // Use this to synchronize timers with logging timestamps (easier debug) 204 #if 0 // Use this to synchronize timers with logging timestamps (easier debug)
201 return rtc::TimeSince(StartTime()); 205 return rtc::TimeSince(StartTime());
202 #else 206 #else
203 return rtc::Time(); 207 return rtc::Time();
204 #endif 208 #endif
205 } 209 }
206 210
207 PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32 conv) 211 PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv)
208 : m_notify(notify), 212 : m_notify(notify),
209 m_shutdown(SD_NONE), 213 m_shutdown(SD_NONE),
210 m_error(0), 214 m_error(0),
211 m_rbuf_len(DEFAULT_RCV_BUF_SIZE), 215 m_rbuf_len(DEFAULT_RCV_BUF_SIZE),
212 m_rbuf(m_rbuf_len), 216 m_rbuf(m_rbuf_len),
213 m_sbuf_len(DEFAULT_SND_BUF_SIZE), 217 m_sbuf_len(DEFAULT_SND_BUF_SIZE),
214 m_sbuf(m_sbuf_len) { 218 m_sbuf(m_sbuf_len) {
215
216 // Sanity check on buffer sizes (needed for OnTcpWriteable notification logic) 219 // Sanity check on buffer sizes (needed for OnTcpWriteable notification logic)
217 ASSERT(m_rbuf_len + MIN_PACKET < m_sbuf_len); 220 ASSERT(m_rbuf_len + MIN_PACKET < m_sbuf_len);
218 221
219 uint32 now = Now(); 222 uint32_t now = Now();
220 223
221 m_state = TCP_LISTEN; 224 m_state = TCP_LISTEN;
222 m_conv = conv; 225 m_conv = conv;
223 m_rcv_wnd = m_rbuf_len; 226 m_rcv_wnd = m_rbuf_len;
224 m_rwnd_scale = m_swnd_scale = 0; 227 m_rwnd_scale = m_swnd_scale = 0;
225 m_snd_nxt = 0; 228 m_snd_nxt = 0;
226 m_snd_wnd = 1; 229 m_snd_wnd = 1;
227 m_snd_una = m_rcv_nxt = 0; 230 m_snd_una = m_rcv_nxt = 0;
228 m_bReadEnable = true; 231 m_bReadEnable = true;
229 m_bWriteEnable = false; 232 m_bWriteEnable = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 269
267 m_state = TCP_SYN_SENT; 270 m_state = TCP_SYN_SENT;
268 LOG(LS_INFO) << "State: TCP_SYN_SENT"; 271 LOG(LS_INFO) << "State: TCP_SYN_SENT";
269 272
270 queueConnectMessage(); 273 queueConnectMessage();
271 attemptSend(); 274 attemptSend();
272 275
273 return 0; 276 return 0;
274 } 277 }
275 278
276 void PseudoTcp::NotifyMTU(uint16 mtu) { 279 void PseudoTcp::NotifyMTU(uint16_t mtu) {
277 m_mtu_advise = mtu; 280 m_mtu_advise = mtu;
278 if (m_state == TCP_ESTABLISHED) { 281 if (m_state == TCP_ESTABLISHED) {
279 adjustMTU(); 282 adjustMTU();
280 } 283 }
281 } 284 }
282 285
283 void PseudoTcp::NotifyClock(uint32 now) { 286 void PseudoTcp::NotifyClock(uint32_t now) {
284 if (m_state == TCP_CLOSED) 287 if (m_state == TCP_CLOSED)
285 return; 288 return;
286 289
287 // Check if it's time to retransmit a segment 290 // Check if it's time to retransmit a segment
288 if (m_rto_base && (rtc::TimeDiff(m_rto_base + m_rx_rto, now) <= 0)) { 291 if (m_rto_base && (rtc::TimeDiff(m_rto_base + m_rx_rto, now) <= 0)) {
289 if (m_slist.empty()) { 292 if (m_slist.empty()) {
290 ASSERT(false); 293 ASSERT(false);
291 } else { 294 } else {
292 // Note: (m_slist.front().xmit == 0)) { 295 // Note: (m_slist.front().xmit == 0)) {
293 // retransmit segments 296 // retransmit segments
294 #if _DEBUGMSG >= _DBG_NORMAL 297 #if _DEBUGMSG >= _DBG_NORMAL
295 LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto 298 LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto
296 << ") (rto_base: " << m_rto_base 299 << ") (rto_base: " << m_rto_base
297 << ") (now: " << now 300 << ") (now: " << now
298 << ") (dup_acks: " << static_cast<unsigned>(m_dup_acks) 301 << ") (dup_acks: " << static_cast<unsigned>(m_dup_acks)
299 << ")"; 302 << ")";
300 #endif // _DEBUGMSG 303 #endif // _DEBUGMSG
301 if (!transmit(m_slist.begin(), now)) { 304 if (!transmit(m_slist.begin(), now)) {
302 closedown(ECONNABORTED); 305 closedown(ECONNABORTED);
303 return; 306 return;
304 } 307 }
305 308
306 uint32 nInFlight = m_snd_nxt - m_snd_una; 309 uint32_t nInFlight = m_snd_nxt - m_snd_una;
307 m_ssthresh = std::max(nInFlight / 2, 2 * m_mss); 310 m_ssthresh = std::max(nInFlight / 2, 2 * m_mss);
308 //LOG(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFl ight << " m_mss: " << m_mss; 311 //LOG(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFl ight << " m_mss: " << m_mss;
309 m_cwnd = m_mss; 312 m_cwnd = m_mss;
310 313
311 // Back off retransmit timer. Note: the limit is lower when connecting. 314 // Back off retransmit timer. Note: the limit is lower when connecting.
312 uint32 rto_limit = (m_state < TCP_ESTABLISHED) ? DEF_RTO : MAX_RTO; 315 uint32_t rto_limit = (m_state < TCP_ESTABLISHED) ? DEF_RTO : MAX_RTO;
313 m_rx_rto = std::min(rto_limit, m_rx_rto * 2); 316 m_rx_rto = std::min(rto_limit, m_rx_rto * 2);
314 m_rto_base = now; 317 m_rto_base = now;
315 } 318 }
316 } 319 }
317 320
318 // Check if it's time to probe closed windows 321 // Check if it's time to probe closed windows
319 if ((m_snd_wnd == 0) 322 if ((m_snd_wnd == 0)
320 && (rtc::TimeDiff(m_lastsend + m_rx_rto, now) <= 0)) { 323 && (rtc::TimeDiff(m_lastsend + m_rx_rto, now) <= 0)) {
321 if (rtc::TimeDiff(now, m_lastrecv) >= 15000) { 324 if (rtc::TimeDiff(now, m_lastrecv) >= 15000) {
322 closedown(ECONNABORTED); 325 closedown(ECONNABORTED);
(...skipping 25 matching lines...) Expand all
348 packet(m_snd_nxt, 0, 0, 0); 351 packet(m_snd_nxt, 0, 0, 0);
349 } 352 }
350 #endif // PSEUDO_KEEPALIVE 353 #endif // PSEUDO_KEEPALIVE
351 } 354 }
352 355
353 bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) { 356 bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) {
354 if (len > MAX_PACKET) { 357 if (len > MAX_PACKET) {
355 LOG_F(WARNING) << "packet too large"; 358 LOG_F(WARNING) << "packet too large";
356 return false; 359 return false;
357 } 360 }
358 return parse(reinterpret_cast<const uint8 *>(buffer), uint32(len)); 361 return parse(reinterpret_cast<const uint8_t*>(buffer), uint32_t(len));
359 } 362 }
360 363
361 bool PseudoTcp::GetNextClock(uint32 now, long& timeout) { 364 bool PseudoTcp::GetNextClock(uint32_t now, long& timeout) {
362 return clock_check(now, timeout); 365 return clock_check(now, timeout);
363 } 366 }
364 367
365 void PseudoTcp::GetOption(Option opt, int* value) { 368 void PseudoTcp::GetOption(Option opt, int* value) {
366 if (opt == OPT_NODELAY) { 369 if (opt == OPT_NODELAY) {
367 *value = m_use_nagling ? 0 : 1; 370 *value = m_use_nagling ? 0 : 1;
368 } else if (opt == OPT_ACKDELAY) { 371 } else if (opt == OPT_ACKDELAY) {
369 *value = m_ack_delay; 372 *value = m_ack_delay;
370 } else if (opt == OPT_SNDBUF) { 373 } else if (opt == OPT_SNDBUF) {
371 *value = m_sbuf_len; 374 *value = m_sbuf_len;
(...skipping 12 matching lines...) Expand all
384 ASSERT(m_state == TCP_LISTEN); 387 ASSERT(m_state == TCP_LISTEN);
385 resizeSendBuffer(value); 388 resizeSendBuffer(value);
386 } else if (opt == OPT_RCVBUF) { 389 } else if (opt == OPT_RCVBUF) {
387 ASSERT(m_state == TCP_LISTEN); 390 ASSERT(m_state == TCP_LISTEN);
388 resizeReceiveBuffer(value); 391 resizeReceiveBuffer(value);
389 } else { 392 } else {
390 ASSERT(false); 393 ASSERT(false);
391 } 394 }
392 } 395 }
393 396
394 uint32 PseudoTcp::GetCongestionWindow() const { 397 uint32_t PseudoTcp::GetCongestionWindow() const {
395 return m_cwnd; 398 return m_cwnd;
396 } 399 }
397 400
398 uint32 PseudoTcp::GetBytesInFlight() const { 401 uint32_t PseudoTcp::GetBytesInFlight() const {
399 return m_snd_nxt - m_snd_una; 402 return m_snd_nxt - m_snd_una;
400 } 403 }
401 404
402 uint32 PseudoTcp::GetBytesBufferedNotSent() const { 405 uint32_t PseudoTcp::GetBytesBufferedNotSent() const {
403 size_t buffered_bytes = 0; 406 size_t buffered_bytes = 0;
404 m_sbuf.GetBuffered(&buffered_bytes); 407 m_sbuf.GetBuffered(&buffered_bytes);
405 return static_cast<uint32>(m_snd_una + buffered_bytes - m_snd_nxt); 408 return static_cast<uint32_t>(m_snd_una + buffered_bytes - m_snd_nxt);
406 } 409 }
407 410
408 uint32 PseudoTcp::GetRoundTripTimeEstimateMs() const { 411 uint32_t PseudoTcp::GetRoundTripTimeEstimateMs() const {
409 return m_rx_srtt; 412 return m_rx_srtt;
410 } 413 }
411 414
412 // 415 //
413 // IPStream Implementation 416 // IPStream Implementation
414 // 417 //
415 418
416 int PseudoTcp::Recv(char* buffer, size_t len) { 419 int PseudoTcp::Recv(char* buffer, size_t len) {
417 if (m_state != TCP_ESTABLISHED) { 420 if (m_state != TCP_ESTABLISHED) {
418 m_error = ENOTCONN; 421 m_error = ENOTCONN;
419 return SOCKET_ERROR; 422 return SOCKET_ERROR;
420 } 423 }
421 424
422 size_t read = 0; 425 size_t read = 0;
423 rtc::StreamResult result = m_rbuf.Read(buffer, len, &read, NULL); 426 rtc::StreamResult result = m_rbuf.Read(buffer, len, &read, NULL);
424 427
425 // If there's no data in |m_rbuf|. 428 // If there's no data in |m_rbuf|.
426 if (result == rtc::SR_BLOCK) { 429 if (result == rtc::SR_BLOCK) {
427 m_bReadEnable = true; 430 m_bReadEnable = true;
428 m_error = EWOULDBLOCK; 431 m_error = EWOULDBLOCK;
429 return SOCKET_ERROR; 432 return SOCKET_ERROR;
430 } 433 }
431 ASSERT(result == rtc::SR_SUCCESS); 434 ASSERT(result == rtc::SR_SUCCESS);
432 435
433 size_t available_space = 0; 436 size_t available_space = 0;
434 m_rbuf.GetWriteRemaining(&available_space); 437 m_rbuf.GetWriteRemaining(&available_space);
435 438
436 if (uint32(available_space) - m_rcv_wnd >= 439 if (uint32_t(available_space) - m_rcv_wnd >=
437 std::min<uint32>(m_rbuf_len / 2, m_mss)) { 440 std::min<uint32_t>(m_rbuf_len / 2, m_mss)) {
438 // TODO(jbeda): !?! Not sure about this was closed business 441 // TODO(jbeda): !?! Not sure about this was closed business
439 bool bWasClosed = (m_rcv_wnd == 0); 442 bool bWasClosed = (m_rcv_wnd == 0);
440 m_rcv_wnd = static_cast<uint32>(available_space); 443 m_rcv_wnd = static_cast<uint32_t>(available_space);
441 444
442 if (bWasClosed) { 445 if (bWasClosed) {
443 attemptSend(sfImmediateAck); 446 attemptSend(sfImmediateAck);
444 } 447 }
445 } 448 }
446 449
447 return static_cast<int>(read); 450 return static_cast<int>(read);
448 } 451 }
449 452
450 int PseudoTcp::Send(const char* buffer, size_t len) { 453 int PseudoTcp::Send(const char* buffer, size_t len) {
451 if (m_state != TCP_ESTABLISHED) { 454 if (m_state != TCP_ESTABLISHED) {
452 m_error = ENOTCONN; 455 m_error = ENOTCONN;
453 return SOCKET_ERROR; 456 return SOCKET_ERROR;
454 } 457 }
455 458
456 size_t available_space = 0; 459 size_t available_space = 0;
457 m_sbuf.GetWriteRemaining(&available_space); 460 m_sbuf.GetWriteRemaining(&available_space);
458 461
459 if (!available_space) { 462 if (!available_space) {
460 m_bWriteEnable = true; 463 m_bWriteEnable = true;
461 m_error = EWOULDBLOCK; 464 m_error = EWOULDBLOCK;
462 return SOCKET_ERROR; 465 return SOCKET_ERROR;
463 } 466 }
464 467
465 int written = queue(buffer, uint32(len), false); 468 int written = queue(buffer, uint32_t(len), false);
466 attemptSend(); 469 attemptSend();
467 return written; 470 return written;
468 } 471 }
469 472
470 void PseudoTcp::Close(bool force) { 473 void PseudoTcp::Close(bool force) {
471 LOG_F(LS_VERBOSE) << "(" << (force ? "true" : "false") << ")"; 474 LOG_F(LS_VERBOSE) << "(" << (force ? "true" : "false") << ")";
472 m_shutdown = force ? SD_FORCEFUL : SD_GRACEFUL; 475 m_shutdown = force ? SD_FORCEFUL : SD_GRACEFUL;
473 } 476 }
474 477
475 int PseudoTcp::GetError() { 478 int PseudoTcp::GetError() {
476 return m_error; 479 return m_error;
477 } 480 }
478 481
479 // 482 //
480 // Internal Implementation 483 // Internal Implementation
481 // 484 //
482 485
483 uint32 PseudoTcp::queue(const char* data, uint32 len, bool bCtrl) { 486 uint32_t PseudoTcp::queue(const char* data, uint32_t len, bool bCtrl) {
484 size_t available_space = 0; 487 size_t available_space = 0;
485 m_sbuf.GetWriteRemaining(&available_space); 488 m_sbuf.GetWriteRemaining(&available_space);
486 489
487 if (len > static_cast<uint32>(available_space)) { 490 if (len > static_cast<uint32_t>(available_space)) {
488 ASSERT(!bCtrl); 491 ASSERT(!bCtrl);
489 len = static_cast<uint32>(available_space); 492 len = static_cast<uint32_t>(available_space);
490 } 493 }
491 494
492 // We can concatenate data if the last segment is the same type 495 // We can concatenate data if the last segment is the same type
493 // (control v. regular data), and has not been transmitted yet 496 // (control v. regular data), and has not been transmitted yet
494 if (!m_slist.empty() && (m_slist.back().bCtrl == bCtrl) && 497 if (!m_slist.empty() && (m_slist.back().bCtrl == bCtrl) &&
495 (m_slist.back().xmit == 0)) { 498 (m_slist.back().xmit == 0)) {
496 m_slist.back().len += len; 499 m_slist.back().len += len;
497 } else { 500 } else {
498 size_t snd_buffered = 0; 501 size_t snd_buffered = 0;
499 m_sbuf.GetBuffered(&snd_buffered); 502 m_sbuf.GetBuffered(&snd_buffered);
500 SSegment sseg(static_cast<uint32>(m_snd_una + snd_buffered), len, bCtrl); 503 SSegment sseg(static_cast<uint32_t>(m_snd_una + snd_buffered), len, bCtrl);
501 m_slist.push_back(sseg); 504 m_slist.push_back(sseg);
502 } 505 }
503 506
504 size_t written = 0; 507 size_t written = 0;
505 m_sbuf.Write(data, len, &written, NULL); 508 m_sbuf.Write(data, len, &written, NULL);
506 return static_cast<uint32>(written); 509 return static_cast<uint32_t>(written);
507 } 510 }
508 511
509 IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32 seq, uint8 flags, 512 IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
510 uint32 offset, uint32 len) { 513 uint8_t flags,
514 uint32_t offset,
515 uint32_t len) {
511 ASSERT(HEADER_SIZE + len <= MAX_PACKET); 516 ASSERT(HEADER_SIZE + len <= MAX_PACKET);
512 517
513 uint32 now = Now(); 518 uint32_t now = Now();
514 519
515 rtc::scoped_ptr<uint8[]> buffer(new uint8[MAX_PACKET]); 520 rtc::scoped_ptr<uint8_t[]> buffer(new uint8_t[MAX_PACKET]);
516 long_to_bytes(m_conv, buffer.get()); 521 long_to_bytes(m_conv, buffer.get());
517 long_to_bytes(seq, buffer.get() + 4); 522 long_to_bytes(seq, buffer.get() + 4);
518 long_to_bytes(m_rcv_nxt, buffer.get() + 8); 523 long_to_bytes(m_rcv_nxt, buffer.get() + 8);
519 buffer[12] = 0; 524 buffer[12] = 0;
520 buffer[13] = flags; 525 buffer[13] = flags;
521 short_to_bytes( 526 short_to_bytes(static_cast<uint16_t>(m_rcv_wnd >> m_rwnd_scale),
522 static_cast<uint16>(m_rcv_wnd >> m_rwnd_scale), buffer.get() + 14); 527 buffer.get() + 14);
523 528
524 // Timestamp computations 529 // Timestamp computations
525 long_to_bytes(now, buffer.get() + 16); 530 long_to_bytes(now, buffer.get() + 16);
526 long_to_bytes(m_ts_recent, buffer.get() + 20); 531 long_to_bytes(m_ts_recent, buffer.get() + 20);
527 m_ts_lastack = m_rcv_nxt; 532 m_ts_lastack = m_rcv_nxt;
528 533
529 if (len) { 534 if (len) {
530 size_t bytes_read = 0; 535 size_t bytes_read = 0;
531 rtc::StreamResult result = m_sbuf.ReadOffset( 536 rtc::StreamResult result = m_sbuf.ReadOffset(
532 buffer.get() + HEADER_SIZE, len, offset, &bytes_read); 537 buffer.get() + HEADER_SIZE, len, offset, &bytes_read);
533 RTC_UNUSED(result); 538 RTC_UNUSED(result);
534 ASSERT(result == rtc::SR_SUCCESS); 539 ASSERT(result == rtc::SR_SUCCESS);
535 ASSERT(static_cast<uint32>(bytes_read) == len); 540 ASSERT(static_cast<uint32_t>(bytes_read) == len);
536 } 541 }
537 542
538 #if _DEBUGMSG >= _DBG_VERBOSE 543 #if _DEBUGMSG >= _DBG_VERBOSE
539 LOG(LS_INFO) << "<-- <CONV=" << m_conv 544 LOG(LS_INFO) << "<-- <CONV=" << m_conv
540 << "><FLG=" << static_cast<unsigned>(flags) 545 << "><FLG=" << static_cast<unsigned>(flags)
541 << "><SEQ=" << seq << ":" << seq + len 546 << "><SEQ=" << seq << ":" << seq + len
542 << "><ACK=" << m_rcv_nxt 547 << "><ACK=" << m_rcv_nxt
543 << "><WND=" << m_rcv_wnd 548 << "><WND=" << m_rcv_wnd
544 << "><TS=" << (now % 10000) 549 << "><TS=" << (now % 10000)
545 << "><TSR=" << (m_ts_recent % 10000) 550 << "><TSR=" << (m_ts_recent % 10000)
(...skipping 11 matching lines...) Expand all
557 m_t_ack = 0; 562 m_t_ack = 0;
558 if (len > 0) { 563 if (len > 0) {
559 m_lastsend = now; 564 m_lastsend = now;
560 } 565 }
561 m_lasttraffic = now; 566 m_lasttraffic = now;
562 m_bOutgoing = true; 567 m_bOutgoing = true;
563 568
564 return IPseudoTcpNotify::WR_SUCCESS; 569 return IPseudoTcpNotify::WR_SUCCESS;
565 } 570 }
566 571
567 bool PseudoTcp::parse(const uint8* buffer, uint32 size) { 572 bool PseudoTcp::parse(const uint8_t* buffer, uint32_t size) {
568 if (size < 12) 573 if (size < 12)
569 return false; 574 return false;
570 575
571 Segment seg; 576 Segment seg;
572 seg.conv = bytes_to_long(buffer); 577 seg.conv = bytes_to_long(buffer);
573 seg.seq = bytes_to_long(buffer + 4); 578 seg.seq = bytes_to_long(buffer + 4);
574 seg.ack = bytes_to_long(buffer + 8); 579 seg.ack = bytes_to_long(buffer + 8);
575 seg.flags = buffer[13]; 580 seg.flags = buffer[13];
576 seg.wnd = bytes_to_short(buffer + 14); 581 seg.wnd = bytes_to_short(buffer + 14);
577 582
(...skipping 10 matching lines...) Expand all
588 << "><ACK=" << seg.ack 593 << "><ACK=" << seg.ack
589 << "><WND=" << seg.wnd 594 << "><WND=" << seg.wnd
590 << "><TS=" << (seg.tsval % 10000) 595 << "><TS=" << (seg.tsval % 10000)
591 << "><TSR=" << (seg.tsecr % 10000) 596 << "><TSR=" << (seg.tsecr % 10000)
592 << "><LEN=" << seg.len << ">"; 597 << "><LEN=" << seg.len << ">";
593 #endif // _DEBUGMSG 598 #endif // _DEBUGMSG
594 599
595 return process(seg); 600 return process(seg);
596 } 601 }
597 602
598 bool PseudoTcp::clock_check(uint32 now, long& nTimeout) { 603 bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
599 if (m_shutdown == SD_FORCEFUL) 604 if (m_shutdown == SD_FORCEFUL)
600 return false; 605 return false;
601 606
602 size_t snd_buffered = 0; 607 size_t snd_buffered = 0;
603 m_sbuf.GetBuffered(&snd_buffered); 608 m_sbuf.GetBuffered(&snd_buffered);
604 if ((m_shutdown == SD_GRACEFUL) 609 if ((m_shutdown == SD_GRACEFUL)
605 && ((m_state != TCP_ESTABLISHED) 610 && ((m_state != TCP_ESTABLISHED)
606 || ((snd_buffered == 0) && (m_t_ack == 0)))) { 611 || ((snd_buffered == 0) && (m_t_ack == 0)))) {
607 return false; 612 return false;
608 } 613 }
609 614
610 if (m_state == TCP_CLOSED) { 615 if (m_state == TCP_CLOSED) {
611 nTimeout = CLOSED_TIMEOUT; 616 nTimeout = CLOSED_TIMEOUT;
612 return true; 617 return true;
613 } 618 }
614 619
615 nTimeout = DEFAULT_TIMEOUT; 620 nTimeout = DEFAULT_TIMEOUT;
616 621
617 if (m_t_ack) { 622 if (m_t_ack) {
618 nTimeout = 623 nTimeout =
619 std::min<int32>(nTimeout, rtc::TimeDiff(m_t_ack + m_ack_delay, now)); 624 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_t_ack + m_ack_delay, now));
620 } 625 }
621 if (m_rto_base) { 626 if (m_rto_base) {
622 nTimeout = 627 nTimeout =
623 std::min<int32>(nTimeout, rtc::TimeDiff(m_rto_base + m_rx_rto, now)); 628 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_rto_base + m_rx_rto, now));
624 } 629 }
625 if (m_snd_wnd == 0) { 630 if (m_snd_wnd == 0) {
626 nTimeout = 631 nTimeout =
627 std::min<int32>(nTimeout, rtc::TimeDiff(m_lastsend + m_rx_rto, now)); 632 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_lastsend + m_rx_rto, now));
628 } 633 }
629 #if PSEUDO_KEEPALIVE 634 #if PSEUDO_KEEPALIVE
630 if (m_state == TCP_ESTABLISHED) { 635 if (m_state == TCP_ESTABLISHED) {
631 nTimeout = std::min<int32>( 636 nTimeout = std::min<int32_t>(
632 nTimeout, rtc::TimeDiff(m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 637 nTimeout, rtc::TimeDiff(m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2
633 : IDLE_PING), 638 : IDLE_PING),
634 now)); 639 now));
635 } 640 }
636 #endif // PSEUDO_KEEPALIVE 641 #endif // PSEUDO_KEEPALIVE
637 return true; 642 return true;
638 } 643 }
639 644
640 bool PseudoTcp::process(Segment& seg) { 645 bool PseudoTcp::process(Segment& seg) {
641 // If this is the wrong conversation, send a reset!?! (with the correct conver sation?) 646 // If this is the wrong conversation, send a reset!?! (with the correct conver sation?)
642 if (seg.conv != m_conv) { 647 if (seg.conv != m_conv) {
643 //if ((seg.flags & FLAG_RST) == 0) { 648 //if ((seg.flags & FLAG_RST) == 0) {
644 // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0); 649 // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0);
645 //} 650 //}
646 LOG_F(LS_ERROR) << "wrong conversation"; 651 LOG_F(LS_ERROR) << "wrong conversation";
647 return false; 652 return false;
648 } 653 }
649 654
650 uint32 now = Now(); 655 uint32_t now = Now();
651 m_lasttraffic = m_lastrecv = now; 656 m_lasttraffic = m_lastrecv = now;
652 m_bOutgoing = false; 657 m_bOutgoing = false;
653 658
654 if (m_state == TCP_CLOSED) { 659 if (m_state == TCP_CLOSED) {
655 // !?! send reset? 660 // !?! send reset?
656 LOG_F(LS_ERROR) << "closed"; 661 LOG_F(LS_ERROR) << "closed";
657 return false; 662 return false;
658 } 663 }
659 664
660 // Check if this is a reset segment 665 // Check if this is a reset segment
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 702
698 // Update timestamp 703 // Update timestamp
699 if ((seg.seq <= m_ts_lastack) && (m_ts_lastack < seg.seq + seg.len)) { 704 if ((seg.seq <= m_ts_lastack) && (m_ts_lastack < seg.seq + seg.len)) {
700 m_ts_recent = seg.tsval; 705 m_ts_recent = seg.tsval;
701 } 706 }
702 707
703 // Check if this is a valuable ack 708 // Check if this is a valuable ack
704 if ((seg.ack > m_snd_una) && (seg.ack <= m_snd_nxt)) { 709 if ((seg.ack > m_snd_una) && (seg.ack <= m_snd_nxt)) {
705 // Calculate round-trip time 710 // Calculate round-trip time
706 if (seg.tsecr) { 711 if (seg.tsecr) {
707 int32 rtt = rtc::TimeDiff(now, seg.tsecr); 712 int32_t rtt = rtc::TimeDiff(now, seg.tsecr);
708 if (rtt >= 0) { 713 if (rtt >= 0) {
709 if (m_rx_srtt == 0) { 714 if (m_rx_srtt == 0) {
710 m_rx_srtt = rtt; 715 m_rx_srtt = rtt;
711 m_rx_rttvar = rtt / 2; 716 m_rx_rttvar = rtt / 2;
712 } else { 717 } else {
713 uint32 unsigned_rtt = static_cast<uint32>(rtt); 718 uint32_t unsigned_rtt = static_cast<uint32_t>(rtt);
714 uint32 abs_err = unsigned_rtt > m_rx_srtt ? unsigned_rtt - m_rx_srtt 719 uint32_t abs_err = unsigned_rtt > m_rx_srtt
715 : m_rx_srtt - unsigned_rtt; 720 ? unsigned_rtt - m_rx_srtt
721 : m_rx_srtt - unsigned_rtt;
716 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; 722 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4;
717 m_rx_srtt = (7 * m_rx_srtt + rtt) / 8; 723 m_rx_srtt = (7 * m_rx_srtt + rtt) / 8;
718 } 724 }
719 m_rx_rto = bound( 725 m_rx_rto =
720 MIN_RTO, m_rx_srtt + std::max<uint32>(1, 4 * m_rx_rttvar), MAX_RTO); 726 bound(MIN_RTO, m_rx_srtt + std::max<uint32_t>(1, 4 * m_rx_rttvar),
727 MAX_RTO);
721 #if _DEBUGMSG >= _DBG_VERBOSE 728 #if _DEBUGMSG >= _DBG_VERBOSE
722 LOG(LS_INFO) << "rtt: " << rtt 729 LOG(LS_INFO) << "rtt: " << rtt
723 << " srtt: " << m_rx_srtt 730 << " srtt: " << m_rx_srtt
724 << " rto: " << m_rx_rto; 731 << " rto: " << m_rx_rto;
725 #endif // _DEBUGMSG 732 #endif // _DEBUGMSG
726 } else { 733 } else {
727 ASSERT(false); 734 ASSERT(false);
728 } 735 }
729 } 736 }
730 737
731 m_snd_wnd = static_cast<uint32>(seg.wnd) << m_swnd_scale; 738 m_snd_wnd = static_cast<uint32_t>(seg.wnd) << m_swnd_scale;
732 739
733 uint32 nAcked = seg.ack - m_snd_una; 740 uint32_t nAcked = seg.ack - m_snd_una;
734 m_snd_una = seg.ack; 741 m_snd_una = seg.ack;
735 742
736 m_rto_base = (m_snd_una == m_snd_nxt) ? 0 : now; 743 m_rto_base = (m_snd_una == m_snd_nxt) ? 0 : now;
737 744
738 m_sbuf.ConsumeReadData(nAcked); 745 m_sbuf.ConsumeReadData(nAcked);
739 746
740 for (uint32 nFree = nAcked; nFree > 0; ) { 747 for (uint32_t nFree = nAcked; nFree > 0;) {
741 ASSERT(!m_slist.empty()); 748 ASSERT(!m_slist.empty());
742 if (nFree < m_slist.front().len) { 749 if (nFree < m_slist.front().len) {
743 m_slist.front().len -= nFree; 750 m_slist.front().len -= nFree;
744 nFree = 0; 751 nFree = 0;
745 } else { 752 } else {
746 if (m_slist.front().len > m_largest) { 753 if (m_slist.front().len > m_largest) {
747 m_largest = m_slist.front().len; 754 m_largest = m_slist.front().len;
748 } 755 }
749 nFree -= m_slist.front().len; 756 nFree -= m_slist.front().len;
750 m_slist.pop_front(); 757 m_slist.pop_front();
751 } 758 }
752 } 759 }
753 760
754 if (m_dup_acks >= 3) { 761 if (m_dup_acks >= 3) {
755 if (m_snd_una >= m_recover) { // NewReno 762 if (m_snd_una >= m_recover) { // NewReno
756 uint32 nInFlight = m_snd_nxt - m_snd_una; 763 uint32_t nInFlight = m_snd_nxt - m_snd_una;
757 m_cwnd = std::min(m_ssthresh, nInFlight + m_mss); // (Fast Retransmit) 764 m_cwnd = std::min(m_ssthresh, nInFlight + m_mss); // (Fast Retransmit)
758 #if _DEBUGMSG >= _DBG_NORMAL 765 #if _DEBUGMSG >= _DBG_NORMAL
759 LOG(LS_INFO) << "exit recovery"; 766 LOG(LS_INFO) << "exit recovery";
760 #endif // _DEBUGMSG 767 #endif // _DEBUGMSG
761 m_dup_acks = 0; 768 m_dup_acks = 0;
762 } else { 769 } else {
763 #if _DEBUGMSG >= _DBG_NORMAL 770 #if _DEBUGMSG >= _DBG_NORMAL
764 LOG(LS_INFO) << "recovery retransmit"; 771 LOG(LS_INFO) << "recovery retransmit";
765 #endif // _DEBUGMSG 772 #endif // _DEBUGMSG
766 if (!transmit(m_slist.begin(), now)) { 773 if (!transmit(m_slist.begin(), now)) {
767 closedown(ECONNABORTED); 774 closedown(ECONNABORTED);
768 return false; 775 return false;
769 } 776 }
770 m_cwnd += m_mss - std::min(nAcked, m_cwnd); 777 m_cwnd += m_mss - std::min(nAcked, m_cwnd);
771 } 778 }
772 } else { 779 } else {
773 m_dup_acks = 0; 780 m_dup_acks = 0;
774 // Slow start, congestion avoidance 781 // Slow start, congestion avoidance
775 if (m_cwnd < m_ssthresh) { 782 if (m_cwnd < m_ssthresh) {
776 m_cwnd += m_mss; 783 m_cwnd += m_mss;
777 } else { 784 } else {
778 m_cwnd += std::max<uint32>(1, m_mss * m_mss / m_cwnd); 785 m_cwnd += std::max<uint32_t>(1, m_mss * m_mss / m_cwnd);
779 } 786 }
780 } 787 }
781 } else if (seg.ack == m_snd_una) { 788 } else if (seg.ack == m_snd_una) {
782 // !?! Note, tcp says don't do this... but otherwise how does a closed windo w become open? 789 // !?! Note, tcp says don't do this... but otherwise how does a closed windo w become open?
783 m_snd_wnd = static_cast<uint32>(seg.wnd) << m_swnd_scale; 790 m_snd_wnd = static_cast<uint32_t>(seg.wnd) << m_swnd_scale;
784 791
785 // Check duplicate acks 792 // Check duplicate acks
786 if (seg.len > 0) { 793 if (seg.len > 0) {
787 // it's a dup ack, but with a data payload, so don't modify m_dup_acks 794 // it's a dup ack, but with a data payload, so don't modify m_dup_acks
788 } else if (m_snd_una != m_snd_nxt) { 795 } else if (m_snd_una != m_snd_nxt) {
789 m_dup_acks += 1; 796 m_dup_acks += 1;
790 if (m_dup_acks == 3) { // (Fast Retransmit) 797 if (m_dup_acks == 3) { // (Fast Retransmit)
791 #if _DEBUGMSG >= _DBG_NORMAL 798 #if _DEBUGMSG >= _DBG_NORMAL
792 LOG(LS_INFO) << "enter recovery"; 799 LOG(LS_INFO) << "enter recovery";
793 LOG(LS_INFO) << "recovery retransmit"; 800 LOG(LS_INFO) << "recovery retransmit";
794 #endif // _DEBUGMSG 801 #endif // _DEBUGMSG
795 if (!transmit(m_slist.begin(), now)) { 802 if (!transmit(m_slist.begin(), now)) {
796 closedown(ECONNABORTED); 803 closedown(ECONNABORTED);
797 return false; 804 return false;
798 } 805 }
799 m_recover = m_snd_nxt; 806 m_recover = m_snd_nxt;
800 uint32 nInFlight = m_snd_nxt - m_snd_una; 807 uint32_t nInFlight = m_snd_nxt - m_snd_una;
801 m_ssthresh = std::max(nInFlight / 2, 2 * m_mss); 808 m_ssthresh = std::max(nInFlight / 2, 2 * m_mss);
802 //LOG(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nIn Flight << " m_mss: " << m_mss; 809 //LOG(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nIn Flight << " m_mss: " << m_mss;
803 m_cwnd = m_ssthresh + 3 * m_mss; 810 m_cwnd = m_ssthresh + 3 * m_mss;
804 } else if (m_dup_acks > 3) { 811 } else if (m_dup_acks > 3) {
805 m_cwnd += m_mss; 812 m_cwnd += m_mss;
806 } 813 }
807 } else { 814 } else {
808 m_dup_acks = 0; 815 m_dup_acks = 0;
809 } 816 }
810 } 817 }
811 818
812 // !?! A bit hacky 819 // !?! A bit hacky
813 if ((m_state == TCP_SYN_RECEIVED) && !bConnect) { 820 if ((m_state == TCP_SYN_RECEIVED) && !bConnect) {
814 m_state = TCP_ESTABLISHED; 821 m_state = TCP_ESTABLISHED;
815 LOG(LS_INFO) << "State: TCP_ESTABLISHED"; 822 LOG(LS_INFO) << "State: TCP_ESTABLISHED";
816 adjustMTU(); 823 adjustMTU();
817 if (m_notify) { 824 if (m_notify) {
818 m_notify->OnTcpOpen(this); 825 m_notify->OnTcpOpen(this);
819 } 826 }
820 //notify(evOpen); 827 //notify(evOpen);
821 } 828 }
822 829
823 // If we make room in the send queue, notify the user 830 // If we make room in the send queue, notify the user
824 // The goal it to make sure we always have at least enough data to fill the 831 // The goal it to make sure we always have at least enough data to fill the
825 // window. We'd like to notify the app when we are halfway to that point. 832 // window. We'd like to notify the app when we are halfway to that point.
826 const uint32 kIdealRefillSize = (m_sbuf_len + m_rbuf_len) / 2; 833 const uint32_t kIdealRefillSize = (m_sbuf_len + m_rbuf_len) / 2;
827 size_t snd_buffered = 0; 834 size_t snd_buffered = 0;
828 m_sbuf.GetBuffered(&snd_buffered); 835 m_sbuf.GetBuffered(&snd_buffered);
829 if (m_bWriteEnable && static_cast<uint32>(snd_buffered) < kIdealRefillSize) { 836 if (m_bWriteEnable &&
837 static_cast<uint32_t>(snd_buffered) < kIdealRefillSize) {
830 m_bWriteEnable = false; 838 m_bWriteEnable = false;
831 if (m_notify) { 839 if (m_notify) {
832 m_notify->OnTcpWriteable(this); 840 m_notify->OnTcpWriteable(this);
833 } 841 }
834 //notify(evWrite); 842 //notify(evWrite);
835 } 843 }
836 844
837 // Conditions were acks must be sent: 845 // Conditions were acks must be sent:
838 // 1) Segment is too old (they missed an ACK) (immediately) 846 // 1) Segment is too old (they missed an ACK) (immediately)
839 // 2) Segment is too new (we missed a segment) (immediately) 847 // 2) Segment is too new (we missed a segment) (immediately)
(...skipping 15 matching lines...) Expand all
855 if (seg.seq > m_rcv_nxt) { 863 if (seg.seq > m_rcv_nxt) {
856 LOG_F(LS_INFO) << "too new"; 864 LOG_F(LS_INFO) << "too new";
857 } else if (seg.seq + seg.len <= m_rcv_nxt) { 865 } else if (seg.seq + seg.len <= m_rcv_nxt) {
858 LOG_F(LS_INFO) << "too old"; 866 LOG_F(LS_INFO) << "too old";
859 } 867 }
860 } 868 }
861 #endif // _DEBUGMSG 869 #endif // _DEBUGMSG
862 870
863 // Adjust the incoming segment to fit our receive buffer 871 // Adjust the incoming segment to fit our receive buffer
864 if (seg.seq < m_rcv_nxt) { 872 if (seg.seq < m_rcv_nxt) {
865 uint32 nAdjust = m_rcv_nxt - seg.seq; 873 uint32_t nAdjust = m_rcv_nxt - seg.seq;
866 if (nAdjust < seg.len) { 874 if (nAdjust < seg.len) {
867 seg.seq += nAdjust; 875 seg.seq += nAdjust;
868 seg.data += nAdjust; 876 seg.data += nAdjust;
869 seg.len -= nAdjust; 877 seg.len -= nAdjust;
870 } else { 878 } else {
871 seg.len = 0; 879 seg.len = 0;
872 } 880 }
873 } 881 }
874 882
875 size_t available_space = 0; 883 size_t available_space = 0;
876 m_rbuf.GetWriteRemaining(&available_space); 884 m_rbuf.GetWriteRemaining(&available_space);
877 885
878 if ((seg.seq + seg.len - m_rcv_nxt) > static_cast<uint32>(available_space)) { 886 if ((seg.seq + seg.len - m_rcv_nxt) >
879 uint32 nAdjust = seg.seq + seg.len - m_rcv_nxt - static_cast<uint32>(availab le_space); 887 static_cast<uint32_t>(available_space)) {
888 uint32_t nAdjust =
889 seg.seq + seg.len - m_rcv_nxt - static_cast<uint32_t>(available_space);
880 if (nAdjust < seg.len) { 890 if (nAdjust < seg.len) {
881 seg.len -= nAdjust; 891 seg.len -= nAdjust;
882 } else { 892 } else {
883 seg.len = 0; 893 seg.len = 0;
884 } 894 }
885 } 895 }
886 896
887 bool bIgnoreData = (seg.flags & FLAG_CTL) || (m_shutdown != SD_NONE); 897 bool bIgnoreData = (seg.flags & FLAG_CTL) || (m_shutdown != SD_NONE);
888 bool bNewData = false; 898 bool bNewData = false;
889 899
890 if (seg.len > 0) { 900 if (seg.len > 0) {
891 if (bIgnoreData) { 901 if (bIgnoreData) {
892 if (seg.seq == m_rcv_nxt) { 902 if (seg.seq == m_rcv_nxt) {
893 m_rcv_nxt += seg.len; 903 m_rcv_nxt += seg.len;
894 } 904 }
895 } else { 905 } else {
896 uint32 nOffset = seg.seq - m_rcv_nxt; 906 uint32_t nOffset = seg.seq - m_rcv_nxt;
897 907
898 rtc::StreamResult result = m_rbuf.WriteOffset(seg.data, seg.len, 908 rtc::StreamResult result = m_rbuf.WriteOffset(seg.data, seg.len,
899 nOffset, NULL); 909 nOffset, NULL);
900 ASSERT(result == rtc::SR_SUCCESS); 910 ASSERT(result == rtc::SR_SUCCESS);
901 RTC_UNUSED(result); 911 RTC_UNUSED(result);
902 912
903 if (seg.seq == m_rcv_nxt) { 913 if (seg.seq == m_rcv_nxt) {
904 m_rbuf.ConsumeWriteBuffer(seg.len); 914 m_rbuf.ConsumeWriteBuffer(seg.len);
905 m_rcv_nxt += seg.len; 915 m_rcv_nxt += seg.len;
906 m_rcv_wnd -= seg.len; 916 m_rcv_wnd -= seg.len;
907 bNewData = true; 917 bNewData = true;
908 918
909 RList::iterator it = m_rlist.begin(); 919 RList::iterator it = m_rlist.begin();
910 while ((it != m_rlist.end()) && (it->seq <= m_rcv_nxt)) { 920 while ((it != m_rlist.end()) && (it->seq <= m_rcv_nxt)) {
911 if (it->seq + it->len > m_rcv_nxt) { 921 if (it->seq + it->len > m_rcv_nxt) {
912 sflags = sfImmediateAck; // (Fast Recovery) 922 sflags = sfImmediateAck; // (Fast Recovery)
913 uint32 nAdjust = (it->seq + it->len) - m_rcv_nxt; 923 uint32_t nAdjust = (it->seq + it->len) - m_rcv_nxt;
914 #if _DEBUGMSG >= _DBG_NORMAL 924 #if _DEBUGMSG >= _DBG_NORMAL
915 LOG(LS_INFO) << "Recovered " << nAdjust << " bytes (" << m_rcv_nxt < < " -> " << m_rcv_nxt + nAdjust << ")"; 925 LOG(LS_INFO) << "Recovered " << nAdjust << " bytes (" << m_rcv_nxt < < " -> " << m_rcv_nxt + nAdjust << ")";
916 #endif // _DEBUGMSG 926 #endif // _DEBUGMSG
917 m_rbuf.ConsumeWriteBuffer(nAdjust); 927 m_rbuf.ConsumeWriteBuffer(nAdjust);
918 m_rcv_nxt += nAdjust; 928 m_rcv_nxt += nAdjust;
919 m_rcv_wnd -= nAdjust; 929 m_rcv_wnd -= nAdjust;
920 } 930 }
921 it = m_rlist.erase(it); 931 it = m_rlist.erase(it);
922 } 932 }
923 } else { 933 } else {
(...skipping 19 matching lines...) Expand all
943 m_bReadEnable = false; 953 m_bReadEnable = false;
944 if (m_notify) { 954 if (m_notify) {
945 m_notify->OnTcpReadable(this); 955 m_notify->OnTcpReadable(this);
946 } 956 }
947 //notify(evRead); 957 //notify(evRead);
948 } 958 }
949 959
950 return true; 960 return true;
951 } 961 }
952 962
953 bool PseudoTcp::transmit(const SList::iterator& seg, uint32 now) { 963 bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
954 if (seg->xmit >= ((m_state == TCP_ESTABLISHED) ? 15 : 30)) { 964 if (seg->xmit >= ((m_state == TCP_ESTABLISHED) ? 15 : 30)) {
955 LOG_F(LS_VERBOSE) << "too many retransmits"; 965 LOG_F(LS_VERBOSE) << "too many retransmits";
956 return false; 966 return false;
957 } 967 }
958 968
959 uint32 nTransmit = std::min(seg->len, m_mss); 969 uint32_t nTransmit = std::min(seg->len, m_mss);
960 970
961 while (true) { 971 while (true) {
962 uint32 seq = seg->seq; 972 uint32_t seq = seg->seq;
963 uint8 flags = (seg->bCtrl ? FLAG_CTL : 0); 973 uint8_t flags = (seg->bCtrl ? FLAG_CTL : 0);
964 IPseudoTcpNotify::WriteResult wres = packet(seq, 974 IPseudoTcpNotify::WriteResult wres = packet(seq,
965 flags, 975 flags,
966 seg->seq - m_snd_una, 976 seg->seq - m_snd_una,
967 nTransmit); 977 nTransmit);
968 978
969 if (wres == IPseudoTcpNotify::WR_SUCCESS) 979 if (wres == IPseudoTcpNotify::WR_SUCCESS)
970 break; 980 break;
971 981
972 if (wres == IPseudoTcpNotify::WR_FAIL) { 982 if (wres == IPseudoTcpNotify::WR_FAIL) {
973 LOG_F(LS_VERBOSE) << "packet failed"; 983 LOG_F(LS_VERBOSE) << "packet failed";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 seg->xmit += 1; 1023 seg->xmit += 1;
1014 //seg->tstamp = now; 1024 //seg->tstamp = now;
1015 if (m_rto_base == 0) { 1025 if (m_rto_base == 0) {
1016 m_rto_base = now; 1026 m_rto_base = now;
1017 } 1027 }
1018 1028
1019 return true; 1029 return true;
1020 } 1030 }
1021 1031
1022 void PseudoTcp::attemptSend(SendFlags sflags) { 1032 void PseudoTcp::attemptSend(SendFlags sflags) {
1023 uint32 now = Now(); 1033 uint32_t now = Now();
1024 1034
1025 if (rtc::TimeDiff(now, m_lastsend) > static_cast<long>(m_rx_rto)) { 1035 if (rtc::TimeDiff(now, m_lastsend) > static_cast<long>(m_rx_rto)) {
1026 m_cwnd = m_mss; 1036 m_cwnd = m_mss;
1027 } 1037 }
1028 1038
1029 #if _DEBUGMSG 1039 #if _DEBUGMSG
1030 bool bFirst = true; 1040 bool bFirst = true;
1031 RTC_UNUSED(bFirst); 1041 RTC_UNUSED(bFirst);
1032 #endif // _DEBUGMSG 1042 #endif // _DEBUGMSG
1033 1043
1034 while (true) { 1044 while (true) {
1035 uint32 cwnd = m_cwnd; 1045 uint32_t cwnd = m_cwnd;
1036 if ((m_dup_acks == 1) || (m_dup_acks == 2)) { // Limited Transmit 1046 if ((m_dup_acks == 1) || (m_dup_acks == 2)) { // Limited Transmit
1037 cwnd += m_dup_acks * m_mss; 1047 cwnd += m_dup_acks * m_mss;
1038 } 1048 }
1039 uint32 nWindow = std::min(m_snd_wnd, cwnd); 1049 uint32_t nWindow = std::min(m_snd_wnd, cwnd);
1040 uint32 nInFlight = m_snd_nxt - m_snd_una; 1050 uint32_t nInFlight = m_snd_nxt - m_snd_una;
1041 uint32 nUseable = (nInFlight < nWindow) ? (nWindow - nInFlight) : 0; 1051 uint32_t nUseable = (nInFlight < nWindow) ? (nWindow - nInFlight) : 0;
1042 1052
1043 size_t snd_buffered = 0; 1053 size_t snd_buffered = 0;
1044 m_sbuf.GetBuffered(&snd_buffered); 1054 m_sbuf.GetBuffered(&snd_buffered);
1045 uint32 nAvailable = 1055 uint32_t nAvailable =
1046 std::min(static_cast<uint32>(snd_buffered) - nInFlight, m_mss); 1056 std::min(static_cast<uint32_t>(snd_buffered) - nInFlight, m_mss);
1047 1057
1048 if (nAvailable > nUseable) { 1058 if (nAvailable > nUseable) {
1049 if (nUseable * 4 < nWindow) { 1059 if (nUseable * 4 < nWindow) {
1050 // RFC 813 - avoid SWS 1060 // RFC 813 - avoid SWS
1051 nAvailable = 0; 1061 nAvailable = 0;
1052 } else { 1062 } else {
1053 nAvailable = nUseable; 1063 nAvailable = nUseable;
1054 } 1064 }
1055 } 1065 }
1056 1066
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 if (!transmit(seg, now)) { 1119 if (!transmit(seg, now)) {
1110 LOG_F(LS_VERBOSE) << "transmit failed"; 1120 LOG_F(LS_VERBOSE) << "transmit failed";
1111 // TODO: consider closing socket 1121 // TODO: consider closing socket
1112 return; 1122 return;
1113 } 1123 }
1114 1124
1115 sflags = sfNone; 1125 sflags = sfNone;
1116 } 1126 }
1117 } 1127 }
1118 1128
1119 void 1129 void PseudoTcp::closedown(uint32_t err) {
1120 PseudoTcp::closedown(uint32 err) {
1121 LOG(LS_INFO) << "State: TCP_CLOSED"; 1130 LOG(LS_INFO) << "State: TCP_CLOSED";
1122 m_state = TCP_CLOSED; 1131 m_state = TCP_CLOSED;
1123 if (m_notify) { 1132 if (m_notify) {
1124 m_notify->OnTcpClosed(this, err); 1133 m_notify->OnTcpClosed(this, err);
1125 } 1134 }
1126 //notify(evClose, err); 1135 //notify(evClose, err);
1127 } 1136 }
1128 1137
1129 void 1138 void
1130 PseudoTcp::adjustMTU() { 1139 PseudoTcp::adjustMTU() {
1131 // Determine our current mss level, so that we can adjust appropriately later 1140 // Determine our current mss level, so that we can adjust appropriately later
1132 for (m_msslevel = 0; PACKET_MAXIMUMS[m_msslevel + 1] > 0; ++m_msslevel) { 1141 for (m_msslevel = 0; PACKET_MAXIMUMS[m_msslevel + 1] > 0; ++m_msslevel) {
1133 if (static_cast<uint16>(PACKET_MAXIMUMS[m_msslevel]) <= m_mtu_advise) { 1142 if (static_cast<uint16_t>(PACKET_MAXIMUMS[m_msslevel]) <= m_mtu_advise) {
1134 break; 1143 break;
1135 } 1144 }
1136 } 1145 }
1137 m_mss = m_mtu_advise - PACKET_OVERHEAD; 1146 m_mss = m_mtu_advise - PACKET_OVERHEAD;
1138 // !?! Should we reset m_largest here? 1147 // !?! Should we reset m_largest here?
1139 #if _DEBUGMSG >= _DBG_NORMAL 1148 #if _DEBUGMSG >= _DBG_NORMAL
1140 LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes"; 1149 LOG(LS_INFO) << "Adjusting mss to " << m_mss << " bytes";
1141 #endif // _DEBUGMSG 1150 #endif // _DEBUGMSG
1142 // Enforce minimums on ssthresh and cwnd 1151 // Enforce minimums on ssthresh and cwnd
1143 m_ssthresh = std::max(m_ssthresh, 2 * m_mss); 1152 m_ssthresh = std::max(m_ssthresh, 2 * m_mss);
(...skipping 15 matching lines...) Expand all
1159 void 1168 void
1160 PseudoTcp::queueConnectMessage() { 1169 PseudoTcp::queueConnectMessage() {
1161 rtc::ByteBuffer buf(rtc::ByteBuffer::ORDER_NETWORK); 1170 rtc::ByteBuffer buf(rtc::ByteBuffer::ORDER_NETWORK);
1162 1171
1163 buf.WriteUInt8(CTL_CONNECT); 1172 buf.WriteUInt8(CTL_CONNECT);
1164 if (m_support_wnd_scale) { 1173 if (m_support_wnd_scale) {
1165 buf.WriteUInt8(TCP_OPT_WND_SCALE); 1174 buf.WriteUInt8(TCP_OPT_WND_SCALE);
1166 buf.WriteUInt8(1); 1175 buf.WriteUInt8(1);
1167 buf.WriteUInt8(m_rwnd_scale); 1176 buf.WriteUInt8(m_rwnd_scale);
1168 } 1177 }
1169 m_snd_wnd = static_cast<uint32>(buf.Length()); 1178 m_snd_wnd = static_cast<uint32_t>(buf.Length());
1170 queue(buf.Data(), static_cast<uint32>(buf.Length()), true); 1179 queue(buf.Data(), static_cast<uint32_t>(buf.Length()), true);
1171 } 1180 }
1172 1181
1173 void 1182 void PseudoTcp::parseOptions(const char* data, uint32_t len) {
1174 PseudoTcp::parseOptions(const char* data, uint32 len) { 1183 std::set<uint8_t> options_specified;
1175 std::set<uint8> options_specified;
1176 1184
1177 // See http://www.freesoft.org/CIE/Course/Section4/8.htm for 1185 // See http://www.freesoft.org/CIE/Course/Section4/8.htm for
1178 // parsing the options list. 1186 // parsing the options list.
1179 rtc::ByteBuffer buf(data, len); 1187 rtc::ByteBuffer buf(data, len);
1180 while (buf.Length()) { 1188 while (buf.Length()) {
1181 uint8 kind = TCP_OPT_EOL; 1189 uint8_t kind = TCP_OPT_EOL;
1182 buf.ReadUInt8(&kind); 1190 buf.ReadUInt8(&kind);
1183 1191
1184 if (kind == TCP_OPT_EOL) { 1192 if (kind == TCP_OPT_EOL) {
1185 // End of option list. 1193 // End of option list.
1186 break; 1194 break;
1187 } else if (kind == TCP_OPT_NOOP) { 1195 } else if (kind == TCP_OPT_NOOP) {
1188 // No op. 1196 // No op.
1189 continue; 1197 continue;
1190 } 1198 }
1191 1199
1192 // Length of this option. 1200 // Length of this option.
1193 ASSERT(len != 0); 1201 ASSERT(len != 0);
1194 RTC_UNUSED(len); 1202 RTC_UNUSED(len);
1195 uint8 opt_len = 0; 1203 uint8_t opt_len = 0;
1196 buf.ReadUInt8(&opt_len); 1204 buf.ReadUInt8(&opt_len);
1197 1205
1198 // Content of this option. 1206 // Content of this option.
1199 if (opt_len <= buf.Length()) { 1207 if (opt_len <= buf.Length()) {
1200 applyOption(kind, buf.Data(), opt_len); 1208 applyOption(kind, buf.Data(), opt_len);
1201 buf.Consume(opt_len); 1209 buf.Consume(opt_len);
1202 } else { 1210 } else {
1203 LOG(LS_ERROR) << "Invalid option length received."; 1211 LOG(LS_ERROR) << "Invalid option length received.";
1204 return; 1212 return;
1205 } 1213 }
1206 options_specified.insert(kind); 1214 options_specified.insert(kind);
1207 } 1215 }
1208 1216
1209 if (options_specified.find(TCP_OPT_WND_SCALE) == options_specified.end()) { 1217 if (options_specified.find(TCP_OPT_WND_SCALE) == options_specified.end()) {
1210 LOG(LS_WARNING) << "Peer doesn't support window scaling"; 1218 LOG(LS_WARNING) << "Peer doesn't support window scaling";
1211 1219
1212 if (m_rwnd_scale > 0) { 1220 if (m_rwnd_scale > 0) {
1213 // Peer doesn't support TCP options and window scaling. 1221 // Peer doesn't support TCP options and window scaling.
1214 // Revert receive buffer size to default value. 1222 // Revert receive buffer size to default value.
1215 resizeReceiveBuffer(DEFAULT_RCV_BUF_SIZE); 1223 resizeReceiveBuffer(DEFAULT_RCV_BUF_SIZE);
1216 m_swnd_scale = 0; 1224 m_swnd_scale = 0;
1217 } 1225 }
1218 } 1226 }
1219 } 1227 }
1220 1228
1221 void 1229 void PseudoTcp::applyOption(char kind, const char* data, uint32_t len) {
1222 PseudoTcp::applyOption(char kind, const char* data, uint32 len) {
1223 if (kind == TCP_OPT_MSS) { 1230 if (kind == TCP_OPT_MSS) {
1224 LOG(LS_WARNING) << "Peer specified MSS option which is not supported."; 1231 LOG(LS_WARNING) << "Peer specified MSS option which is not supported.";
1225 // TODO: Implement. 1232 // TODO: Implement.
1226 } else if (kind == TCP_OPT_WND_SCALE) { 1233 } else if (kind == TCP_OPT_WND_SCALE) {
1227 // Window scale factor. 1234 // Window scale factor.
1228 // http://www.ietf.org/rfc/rfc1323.txt 1235 // http://www.ietf.org/rfc/rfc1323.txt
1229 if (len != 1) { 1236 if (len != 1) {
1230 LOG_F(WARNING) << "Invalid window scale option received."; 1237 LOG_F(WARNING) << "Invalid window scale option received.";
1231 return; 1238 return;
1232 } 1239 }
1233 applyWindowScaleOption(data[0]); 1240 applyWindowScaleOption(data[0]);
1234 } 1241 }
1235 } 1242 }
1236 1243
1237 void 1244 void PseudoTcp::applyWindowScaleOption(uint8_t scale_factor) {
1238 PseudoTcp::applyWindowScaleOption(uint8 scale_factor) {
1239 m_swnd_scale = scale_factor; 1245 m_swnd_scale = scale_factor;
1240 } 1246 }
1241 1247
1242 void 1248 void PseudoTcp::resizeSendBuffer(uint32_t new_size) {
1243 PseudoTcp::resizeSendBuffer(uint32 new_size) {
1244 m_sbuf_len = new_size; 1249 m_sbuf_len = new_size;
1245 m_sbuf.SetCapacity(new_size); 1250 m_sbuf.SetCapacity(new_size);
1246 } 1251 }
1247 1252
1248 void 1253 void PseudoTcp::resizeReceiveBuffer(uint32_t new_size) {
1249 PseudoTcp::resizeReceiveBuffer(uint32 new_size) { 1254 uint8_t scale_factor = 0;
1250 uint8 scale_factor = 0;
1251 1255
1252 // Determine the scale factor such that the scaled window size can fit 1256 // Determine the scale factor such that the scaled window size can fit
1253 // in a 16-bit unsigned integer. 1257 // in a 16-bit unsigned integer.
1254 while (new_size > 0xFFFF) { 1258 while (new_size > 0xFFFF) {
1255 ++scale_factor; 1259 ++scale_factor;
1256 new_size >>= 1; 1260 new_size >>= 1;
1257 } 1261 }
1258 1262
1259 // Determine the proper size of the buffer. 1263 // Determine the proper size of the buffer.
1260 new_size <<= scale_factor; 1264 new_size <<= scale_factor;
1261 bool result = m_rbuf.SetCapacity(new_size); 1265 bool result = m_rbuf.SetCapacity(new_size);
1262 1266
1263 // Make sure the new buffer is large enough to contain data in the old 1267 // Make sure the new buffer is large enough to contain data in the old
1264 // buffer. This should always be true because this method is called either 1268 // buffer. This should always be true because this method is called either
1265 // before connection is established or when peers are exchanging connect 1269 // before connection is established or when peers are exchanging connect
1266 // messages. 1270 // messages.
1267 ASSERT(result); 1271 ASSERT(result);
1268 RTC_UNUSED(result); 1272 RTC_UNUSED(result);
1269 m_rbuf_len = new_size; 1273 m_rbuf_len = new_size;
1270 m_rwnd_scale = scale_factor; 1274 m_rwnd_scale = scale_factor;
1271 m_ssthresh = new_size; 1275 m_ssthresh = new_size;
1272 1276
1273 size_t available_space = 0; 1277 size_t available_space = 0;
1274 m_rbuf.GetWriteRemaining(&available_space); 1278 m_rbuf.GetWriteRemaining(&available_space);
1275 m_rcv_wnd = static_cast<uint32>(available_space); 1279 m_rcv_wnd = static_cast<uint32_t>(available_space);
1276 } 1280 }
1277 1281
1278 } // namespace cricket 1282 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/pseudotcp.h ('k') | webrtc/p2p/base/pseudotcp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698