| OLD | NEW |
| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 #endif | 198 #endif |
| 199 | 199 |
| 200 ////////////////////////////////////////////////////////////////////// | 200 ////////////////////////////////////////////////////////////////////// |
| 201 // PseudoTcp | 201 // PseudoTcp |
| 202 ////////////////////////////////////////////////////////////////////// | 202 ////////////////////////////////////////////////////////////////////// |
| 203 | 203 |
| 204 uint32_t PseudoTcp::Now() { | 204 uint32_t PseudoTcp::Now() { |
| 205 #if 0 // Use this to synchronize timers with logging timestamps (easier debug) | 205 #if 0 // Use this to synchronize timers with logging timestamps (easier debug) |
| 206 return rtc::TimeSince(StartTime()); | 206 return static_cast<uint32_t>(rtc::TimeSince(StartTime())); |
| 207 #else | 207 #else |
| 208 return rtc::Time(); | 208 return rtc::Time32(); |
| 209 #endif | 209 #endif |
| 210 } | 210 } |
| 211 | 211 |
| 212 PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv) | 212 PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv) |
| 213 : m_notify(notify), | 213 : m_notify(notify), |
| 214 m_shutdown(SD_NONE), | 214 m_shutdown(SD_NONE), |
| 215 m_error(0), | 215 m_error(0), |
| 216 m_rbuf_len(DEFAULT_RCV_BUF_SIZE), | 216 m_rbuf_len(DEFAULT_RCV_BUF_SIZE), |
| 217 m_rbuf(m_rbuf_len), | 217 m_rbuf(m_rbuf_len), |
| 218 m_sbuf_len(DEFAULT_SND_BUF_SIZE), | 218 m_sbuf_len(DEFAULT_SND_BUF_SIZE), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (m_state == TCP_ESTABLISHED) { | 282 if (m_state == TCP_ESTABLISHED) { |
| 283 adjustMTU(); | 283 adjustMTU(); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 void PseudoTcp::NotifyClock(uint32_t now) { | 287 void PseudoTcp::NotifyClock(uint32_t now) { |
| 288 if (m_state == TCP_CLOSED) | 288 if (m_state == TCP_CLOSED) |
| 289 return; | 289 return; |
| 290 | 290 |
| 291 // Check if it's time to retransmit a segment | 291 // Check if it's time to retransmit a segment |
| 292 if (m_rto_base && (rtc::TimeDiff(m_rto_base + m_rx_rto, now) <= 0)) { | 292 if (m_rto_base && (rtc::TimeDiff32(m_rto_base + m_rx_rto, now) <= 0)) { |
| 293 if (m_slist.empty()) { | 293 if (m_slist.empty()) { |
| 294 ASSERT(false); | 294 ASSERT(false); |
| 295 } else { | 295 } else { |
| 296 // Note: (m_slist.front().xmit == 0)) { | 296 // Note: (m_slist.front().xmit == 0)) { |
| 297 // retransmit segments | 297 // retransmit segments |
| 298 #if _DEBUGMSG >= _DBG_NORMAL | 298 #if _DEBUGMSG >= _DBG_NORMAL |
| 299 LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto | 299 LOG(LS_INFO) << "timeout retransmit (rto: " << m_rx_rto |
| 300 << ") (rto_base: " << m_rto_base | 300 << ") (rto_base: " << m_rto_base |
| 301 << ") (now: " << now | 301 << ") (now: " << now |
| 302 << ") (dup_acks: " << static_cast<unsigned>(m_dup_acks) | 302 << ") (dup_acks: " << static_cast<unsigned>(m_dup_acks) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 313 m_cwnd = m_mss; | 313 m_cwnd = m_mss; |
| 314 | 314 |
| 315 // Back off retransmit timer. Note: the limit is lower when connecting. | 315 // Back off retransmit timer. Note: the limit is lower when connecting. |
| 316 uint32_t rto_limit = (m_state < TCP_ESTABLISHED) ? DEF_RTO : MAX_RTO; | 316 uint32_t rto_limit = (m_state < TCP_ESTABLISHED) ? DEF_RTO : MAX_RTO; |
| 317 m_rx_rto = std::min(rto_limit, m_rx_rto * 2); | 317 m_rx_rto = std::min(rto_limit, m_rx_rto * 2); |
| 318 m_rto_base = now; | 318 m_rto_base = now; |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 // Check if it's time to probe closed windows | 322 // Check if it's time to probe closed windows |
| 323 if ((m_snd_wnd == 0) | 323 if ((m_snd_wnd == 0) && (rtc::TimeDiff32(m_lastsend + m_rx_rto, now) <= 0)) { |
| 324 && (rtc::TimeDiff(m_lastsend + m_rx_rto, now) <= 0)) { | 324 if (rtc::TimeDiff32(now, m_lastrecv) >= 15000) { |
| 325 if (rtc::TimeDiff(now, m_lastrecv) >= 15000) { | |
| 326 closedown(ECONNABORTED); | 325 closedown(ECONNABORTED); |
| 327 return; | 326 return; |
| 328 } | 327 } |
| 329 | 328 |
| 330 // probe the window | 329 // probe the window |
| 331 packet(m_snd_nxt - 1, 0, 0, 0); | 330 packet(m_snd_nxt - 1, 0, 0, 0); |
| 332 m_lastsend = now; | 331 m_lastsend = now; |
| 333 | 332 |
| 334 // back off retransmit timer | 333 // back off retransmit timer |
| 335 m_rx_rto = std::min(MAX_RTO, m_rx_rto * 2); | 334 m_rx_rto = std::min(MAX_RTO, m_rx_rto * 2); |
| 336 } | 335 } |
| 337 | 336 |
| 338 // Check if it's time to send delayed acks | 337 // Check if it's time to send delayed acks |
| 339 if (m_t_ack && (rtc::TimeDiff(m_t_ack + m_ack_delay, now) <= 0)) { | 338 if (m_t_ack && (rtc::TimeDiff32(m_t_ack + m_ack_delay, now) <= 0)) { |
| 340 packet(m_snd_nxt, 0, 0, 0); | 339 packet(m_snd_nxt, 0, 0, 0); |
| 341 } | 340 } |
| 342 | 341 |
| 343 #if PSEUDO_KEEPALIVE | 342 #if PSEUDO_KEEPALIVE |
| 344 // Check for idle timeout | 343 // Check for idle timeout |
| 345 if ((m_state == TCP_ESTABLISHED) && (TimeDiff(m_lastrecv + IDLE_TIMEOUT, now)
<= 0)) { | 344 if ((m_state == TCP_ESTABLISHED) && |
| 345 (TimeDiff32(m_lastrecv + IDLE_TIMEOUT, now) <= 0)) { |
| 346 closedown(ECONNABORTED); | 346 closedown(ECONNABORTED); |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // Check for ping timeout (to keep udp mapping open) | 350 // Check for ping timeout (to keep udp mapping open) |
| 351 if ((m_state == TCP_ESTABLISHED) && (TimeDiff(m_lasttraffic + (m_bOutgoing ? I
DLE_PING * 3/2 : IDLE_PING), now) <= 0)) { | 351 if ((m_state == TCP_ESTABLISHED) && |
| 352 (TimeDiff32(m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 : IDLE_PING), |
| 353 now) <= 0)) { |
| 352 packet(m_snd_nxt, 0, 0, 0); | 354 packet(m_snd_nxt, 0, 0, 0); |
| 353 } | 355 } |
| 354 #endif // PSEUDO_KEEPALIVE | 356 #endif // PSEUDO_KEEPALIVE |
| 355 } | 357 } |
| 356 | 358 |
| 357 bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) { | 359 bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) { |
| 358 if (len > MAX_PACKET) { | 360 if (len > MAX_PACKET) { |
| 359 LOG_F(WARNING) << "packet too large"; | 361 LOG_F(WARNING) << "packet too large"; |
| 360 return false; | 362 return false; |
| 361 } | 363 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 } | 616 } |
| 615 | 617 |
| 616 if (m_state == TCP_CLOSED) { | 618 if (m_state == TCP_CLOSED) { |
| 617 nTimeout = CLOSED_TIMEOUT; | 619 nTimeout = CLOSED_TIMEOUT; |
| 618 return true; | 620 return true; |
| 619 } | 621 } |
| 620 | 622 |
| 621 nTimeout = DEFAULT_TIMEOUT; | 623 nTimeout = DEFAULT_TIMEOUT; |
| 622 | 624 |
| 623 if (m_t_ack) { | 625 if (m_t_ack) { |
| 624 nTimeout = | 626 nTimeout = std::min<int32_t>(nTimeout, |
| 625 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_t_ack + m_ack_delay, now)); | 627 rtc::TimeDiff32(m_t_ack + m_ack_delay, now)); |
| 626 } | 628 } |
| 627 if (m_rto_base) { | 629 if (m_rto_base) { |
| 628 nTimeout = | 630 nTimeout = std::min<int32_t>(nTimeout, |
| 629 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_rto_base + m_rx_rto, now)); | 631 rtc::TimeDiff32(m_rto_base + m_rx_rto, now)); |
| 630 } | 632 } |
| 631 if (m_snd_wnd == 0) { | 633 if (m_snd_wnd == 0) { |
| 632 nTimeout = | 634 nTimeout = std::min<int32_t>(nTimeout, |
| 633 std::min<int32_t>(nTimeout, rtc::TimeDiff(m_lastsend + m_rx_rto, now)); | 635 rtc::TimeDiff32(m_lastsend + m_rx_rto, now)); |
| 634 } | 636 } |
| 635 #if PSEUDO_KEEPALIVE | 637 #if PSEUDO_KEEPALIVE |
| 636 if (m_state == TCP_ESTABLISHED) { | 638 if (m_state == TCP_ESTABLISHED) { |
| 637 nTimeout = std::min<int32_t>( | 639 nTimeout = std::min<int32_t>( |
| 638 nTimeout, rtc::TimeDiff(m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 | 640 nTimeout, |
| 639 : IDLE_PING), | 641 rtc::TimeDiff32( |
| 640 now)); | 642 m_lasttraffic + (m_bOutgoing ? IDLE_PING * 3 / 2 : IDLE_PING), |
| 643 now)); |
| 641 } | 644 } |
| 642 #endif // PSEUDO_KEEPALIVE | 645 #endif // PSEUDO_KEEPALIVE |
| 643 return true; | 646 return true; |
| 644 } | 647 } |
| 645 | 648 |
| 646 bool PseudoTcp::process(Segment& seg) { | 649 bool PseudoTcp::process(Segment& seg) { |
| 647 // If this is the wrong conversation, send a reset!?! (with the correct conver
sation?) | 650 // If this is the wrong conversation, send a reset!?! (with the correct conver
sation?) |
| 648 if (seg.conv != m_conv) { | 651 if (seg.conv != m_conv) { |
| 649 //if ((seg.flags & FLAG_RST) == 0) { | 652 //if ((seg.flags & FLAG_RST) == 0) { |
| 650 // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0); | 653 // packet(tcb, seg.ack, 0, FLAG_RST, 0, 0); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 706 |
| 704 // Update timestamp | 707 // Update timestamp |
| 705 if ((seg.seq <= m_ts_lastack) && (m_ts_lastack < seg.seq + seg.len)) { | 708 if ((seg.seq <= m_ts_lastack) && (m_ts_lastack < seg.seq + seg.len)) { |
| 706 m_ts_recent = seg.tsval; | 709 m_ts_recent = seg.tsval; |
| 707 } | 710 } |
| 708 | 711 |
| 709 // Check if this is a valuable ack | 712 // Check if this is a valuable ack |
| 710 if ((seg.ack > m_snd_una) && (seg.ack <= m_snd_nxt)) { | 713 if ((seg.ack > m_snd_una) && (seg.ack <= m_snd_nxt)) { |
| 711 // Calculate round-trip time | 714 // Calculate round-trip time |
| 712 if (seg.tsecr) { | 715 if (seg.tsecr) { |
| 713 int32_t rtt = rtc::TimeDiff(now, seg.tsecr); | 716 int32_t rtt = rtc::TimeDiff32(now, seg.tsecr); |
| 714 if (rtt >= 0) { | 717 if (rtt >= 0) { |
| 715 if (m_rx_srtt == 0) { | 718 if (m_rx_srtt == 0) { |
| 716 m_rx_srtt = rtt; | 719 m_rx_srtt = rtt; |
| 717 m_rx_rttvar = rtt / 2; | 720 m_rx_rttvar = rtt / 2; |
| 718 } else { | 721 } else { |
| 719 uint32_t unsigned_rtt = static_cast<uint32_t>(rtt); | 722 uint32_t unsigned_rtt = static_cast<uint32_t>(rtt); |
| 720 uint32_t abs_err = unsigned_rtt > m_rx_srtt | 723 uint32_t abs_err = unsigned_rtt > m_rx_srtt |
| 721 ? unsigned_rtt - m_rx_srtt | 724 ? unsigned_rtt - m_rx_srtt |
| 722 : m_rx_srtt - unsigned_rtt; | 725 : m_rx_srtt - unsigned_rtt; |
| 723 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; | 726 m_rx_rttvar = (3 * m_rx_rttvar + abs_err) / 4; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 if (m_rto_base == 0) { | 1029 if (m_rto_base == 0) { |
| 1027 m_rto_base = now; | 1030 m_rto_base = now; |
| 1028 } | 1031 } |
| 1029 | 1032 |
| 1030 return true; | 1033 return true; |
| 1031 } | 1034 } |
| 1032 | 1035 |
| 1033 void PseudoTcp::attemptSend(SendFlags sflags) { | 1036 void PseudoTcp::attemptSend(SendFlags sflags) { |
| 1034 uint32_t now = Now(); | 1037 uint32_t now = Now(); |
| 1035 | 1038 |
| 1036 if (rtc::TimeDiff(now, m_lastsend) > static_cast<long>(m_rx_rto)) { | 1039 if (rtc::TimeDiff32(now, m_lastsend) > static_cast<long>(m_rx_rto)) { |
| 1037 m_cwnd = m_mss; | 1040 m_cwnd = m_mss; |
| 1038 } | 1041 } |
| 1039 | 1042 |
| 1040 #if _DEBUGMSG | 1043 #if _DEBUGMSG |
| 1041 bool bFirst = true; | 1044 bool bFirst = true; |
| 1042 RTC_UNUSED(bFirst); | 1045 RTC_UNUSED(bFirst); |
| 1043 #endif // _DEBUGMSG | 1046 #endif // _DEBUGMSG |
| 1044 | 1047 |
| 1045 while (true) { | 1048 while (true) { |
| 1046 uint32_t cwnd = m_cwnd; | 1049 uint32_t cwnd = m_cwnd; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 m_rbuf_len = new_size; | 1277 m_rbuf_len = new_size; |
| 1275 m_rwnd_scale = scale_factor; | 1278 m_rwnd_scale = scale_factor; |
| 1276 m_ssthresh = new_size; | 1279 m_ssthresh = new_size; |
| 1277 | 1280 |
| 1278 size_t available_space = 0; | 1281 size_t available_space = 0; |
| 1279 m_rbuf.GetWriteRemaining(&available_space); | 1282 m_rbuf.GetWriteRemaining(&available_space); |
| 1280 m_rcv_wnd = static_cast<uint32_t>(available_space); | 1283 m_rcv_wnd = static_cast<uint32_t>(available_space); |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 } // namespace cricket | 1286 } // namespace cricket |
| OLD | NEW |