| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // Pacing will be enabled if the client negotiates it. | 244 // Pacing will be enabled if the client negotiates it. |
| 245 sent_packet_manager_.MaybeEnablePacing(); | 245 sent_packet_manager_.MaybeEnablePacing(); |
| 246 } | 246 } |
| 247 #endif | 247 #endif |
| 248 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " | 248 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " |
| 249 << connection_id; | 249 << connection_id; |
| 250 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_)); | 250 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_)); |
| 251 framer_.set_visitor(this); | 251 framer_.set_visitor(this); |
| 252 framer_.set_received_entropy_calculator(&received_packet_manager_); | 252 framer_.set_received_entropy_calculator(&received_packet_manager_); |
| 253 stats_.connection_creation_time = clock_->ApproximateNow(); | 253 stats_.connection_creation_time = clock_->ApproximateNow(); |
| 254 sent_packet_manager_.set_network_change_visitor(&packet_generator_); | 254 sent_packet_manager_.set_network_change_visitor(this); |
| 255 } | 255 } |
| 256 | 256 |
| 257 QuicConnection::~QuicConnection() { | 257 QuicConnection::~QuicConnection() { |
| 258 if (owns_writer_) { | 258 if (owns_writer_) { |
| 259 delete writer_; | 259 delete writer_; |
| 260 } | 260 } |
| 261 STLDeleteElements(&undecryptable_packets_); | 261 STLDeleteElements(&undecryptable_packets_); |
| 262 STLDeleteValues(&group_map_); | 262 STLDeleteValues(&group_map_); |
| 263 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 263 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
| 264 it != queued_packets_.end(); ++it) { | 264 it != queued_packets_.end(); ++it) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 SendConnectionClose(QUIC_INVALID_ACK_DATA); | 551 SendConnectionClose(QUIC_INVALID_ACK_DATA); |
| 552 return false; | 552 return false; |
| 553 } | 553 } |
| 554 | 554 |
| 555 last_ack_frames_.push_back(incoming_ack); | 555 last_ack_frames_.push_back(incoming_ack); |
| 556 return connected_; | 556 return connected_; |
| 557 } | 557 } |
| 558 | 558 |
| 559 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { | 559 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { |
| 560 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; | 560 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; |
| 561 received_packet_manager_.UpdatePacketInformationReceivedByPeer(incoming_ack); | |
| 562 | |
| 563 sent_entropy_manager_.ClearEntropyBefore( | |
| 564 received_packet_manager_.least_packet_awaited_by_peer() - 1); | |
| 565 | |
| 566 sent_packet_manager_.OnIncomingAck(incoming_ack, | 561 sent_packet_manager_.OnIncomingAck(incoming_ack, |
| 567 time_of_last_received_packet_); | 562 time_of_last_received_packet_); |
| 563 sent_entropy_manager_.ClearEntropyBefore( |
| 564 sent_packet_manager_.least_packet_awaited_by_peer() - 1); |
| 568 if (sent_packet_manager_.HasPendingRetransmissions()) { | 565 if (sent_packet_manager_.HasPendingRetransmissions()) { |
| 569 WriteIfNotBlocked(); | 566 WriteIfNotBlocked(); |
| 570 } | 567 } |
| 571 | 568 |
| 572 // Always reset the retransmission alarm when an ack comes in, since we now | 569 // Always reset the retransmission alarm when an ack comes in, since we now |
| 573 // have a better estimate of the current rtt than when it was set. | 570 // have a better estimate of the current rtt than when it was set. |
| 574 QuicTime retransmission_time = | 571 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); |
| 575 sent_packet_manager_.GetRetransmissionTime(); | |
| 576 retransmission_alarm_->Update(retransmission_time, | 572 retransmission_alarm_->Update(retransmission_time, |
| 577 QuicTime::Delta::FromMilliseconds(1)); | 573 QuicTime::Delta::FromMilliseconds(1)); |
| 578 } | 574 } |
| 579 | 575 |
| 580 void QuicConnection::ProcessStopWaitingFrame( | 576 void QuicConnection::ProcessStopWaitingFrame( |
| 581 const QuicStopWaitingFrame& stop_waiting) { | 577 const QuicStopWaitingFrame& stop_waiting) { |
| 582 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; | 578 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; |
| 583 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 579 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
| 584 // Possibly close any FecGroups which are now irrelevant. | 580 // Possibly close any FecGroups which are now irrelevant. |
| 585 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); | 581 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 | 623 |
| 628 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { | 624 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { |
| 629 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { | 625 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { |
| 630 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" | 626 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" |
| 631 << incoming_ack.largest_observed << " vs " | 627 << incoming_ack.largest_observed << " vs " |
| 632 << packet_generator_.sequence_number(); | 628 << packet_generator_.sequence_number(); |
| 633 // We got an error for data we have not sent. Error out. | 629 // We got an error for data we have not sent. Error out. |
| 634 return false; | 630 return false; |
| 635 } | 631 } |
| 636 | 632 |
| 637 if (incoming_ack.largest_observed < | 633 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { |
| 638 received_packet_manager_.peer_largest_observed_packet()) { | |
| 639 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" | 634 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" |
| 640 << incoming_ack.largest_observed << " vs " | 635 << incoming_ack.largest_observed << " vs " |
| 641 << received_packet_manager_.peer_largest_observed_packet(); | 636 << sent_packet_manager_.largest_observed(); |
| 642 // A new ack has a diminished largest_observed value. Error out. | 637 // A new ack has a diminished largest_observed value. Error out. |
| 643 // If this was an old packet, we wouldn't even have checked. | 638 // If this was an old packet, we wouldn't even have checked. |
| 644 return false; | 639 return false; |
| 645 } | 640 } |
| 646 | 641 |
| 647 if (!incoming_ack.missing_packets.empty() && | 642 if (!incoming_ack.missing_packets.empty() && |
| 648 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { | 643 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { |
| 649 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 644 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
| 650 << *incoming_ack.missing_packets.rbegin() | 645 << *incoming_ack.missing_packets.rbegin() |
| 651 << " which is greater than largest observed: " | 646 << " which is greater than largest observed: " |
| 652 << incoming_ack.largest_observed; | 647 << incoming_ack.largest_observed; |
| 653 return false; | 648 return false; |
| 654 } | 649 } |
| 655 | 650 |
| 656 if (!incoming_ack.missing_packets.empty() && | 651 if (!incoming_ack.missing_packets.empty() && |
| 657 *incoming_ack.missing_packets.begin() < | 652 *incoming_ack.missing_packets.begin() < |
| 658 received_packet_manager_.least_packet_awaited_by_peer()) { | 653 sent_packet_manager_.least_packet_awaited_by_peer()) { |
| 659 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 654 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
| 660 << *incoming_ack.missing_packets.begin() | 655 << *incoming_ack.missing_packets.begin() |
| 661 << " which is smaller than least_packet_awaited_by_peer_: " | 656 << " which is smaller than least_packet_awaited_by_peer_: " |
| 662 << received_packet_manager_.least_packet_awaited_by_peer(); | 657 << sent_packet_manager_.least_packet_awaited_by_peer(); |
| 663 return false; | 658 return false; |
| 664 } | 659 } |
| 665 | 660 |
| 666 if (!sent_entropy_manager_.IsValidEntropy( | 661 if (!sent_entropy_manager_.IsValidEntropy( |
| 667 incoming_ack.largest_observed, | 662 incoming_ack.largest_observed, |
| 668 incoming_ack.missing_packets, | 663 incoming_ack.missing_packets, |
| 669 incoming_ack.entropy_hash)) { | 664 incoming_ack.entropy_hash)) { |
| 670 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; | 665 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; |
| 671 return false; | 666 return false; |
| 672 } | 667 } |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 // This assures we won't try to write *forced* packets when blocked. | 1360 // This assures we won't try to write *forced* packets when blocked. |
| 1366 // Return true to stop processing. | 1361 // Return true to stop processing. |
| 1367 if (writer_->IsWriteBlocked()) { | 1362 if (writer_->IsWriteBlocked()) { |
| 1368 visitor_->OnWriteBlocked(); | 1363 visitor_->OnWriteBlocked(); |
| 1369 return true; | 1364 return true; |
| 1370 } | 1365 } |
| 1371 } else { | 1366 } else { |
| 1372 encrypted_deleter.reset(encrypted); | 1367 encrypted_deleter.reset(encrypted); |
| 1373 } | 1368 } |
| 1374 | 1369 |
| 1375 LOG_IF(DFATAL, encrypted->length() > | 1370 if (!FLAGS_quic_allow_oversized_packets_for_test) { |
| 1376 packet_generator_.max_packet_length()) | 1371 DCHECK_LE(encrypted->length(), kMaxPacketSize); |
| 1377 << "Writing an encrypted packet larger than max_packet_length:" | 1372 } |
| 1378 << packet_generator_.max_packet_length() << " encrypted length: " | 1373 DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length()); |
| 1379 << encrypted->length(); | |
| 1380 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number | 1374 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number |
| 1381 << " : " << (packet.packet->is_fec_packet() ? "FEC " : | 1375 << " : " << (packet.packet->is_fec_packet() ? "FEC " : |
| 1382 (packet.retransmittable == HAS_RETRANSMITTABLE_DATA | 1376 (packet.retransmittable == HAS_RETRANSMITTABLE_DATA |
| 1383 ? "data bearing " : " ack only ")) | 1377 ? "data bearing " : " ack only ")) |
| 1384 << ", encryption level: " | 1378 << ", encryption level: " |
| 1385 << QuicUtils::EncryptionLevelToString(packet.encryption_level) | 1379 << QuicUtils::EncryptionLevelToString(packet.encryption_level) |
| 1386 << ", length:" << packet.packet->length() << ", encrypted length:" | 1380 << ", length:" << packet.packet->length() << ", encrypted length:" |
| 1387 << encrypted->length(); | 1381 << encrypted->length(); |
| 1388 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl | 1382 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl |
| 1389 << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece()); | 1383 << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece()); |
| 1390 | 1384 |
| 1391 DCHECK(encrypted->length() <= kMaxPacketSize || | |
| 1392 FLAGS_quic_allow_oversized_packets_for_test) | |
| 1393 << "Packet " << sequence_number << " will not be read; too large: " | |
| 1394 << packet.packet->length() << " " << encrypted->length() << " " | |
| 1395 << " close: " << (packet.type == CONNECTION_CLOSE ? "yes" : "no"); | |
| 1396 | |
| 1397 DCHECK(pending_write_.get() == NULL); | |
| 1398 pending_write_.reset(new QueuedPacket(packet)); | |
| 1399 | |
| 1400 WriteResult result = writer_->WritePacket(encrypted->data(), | 1385 WriteResult result = writer_->WritePacket(encrypted->data(), |
| 1401 encrypted->length(), | 1386 encrypted->length(), |
| 1402 self_address().address(), | 1387 self_address().address(), |
| 1403 peer_address()); | 1388 peer_address()); |
| 1404 if (result.error_code == ERR_IO_PENDING) { | 1389 if (result.error_code == ERR_IO_PENDING) { |
| 1405 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1390 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
| 1406 } | 1391 } |
| 1407 if (debug_visitor_.get() != NULL) { | 1392 if (debug_visitor_.get() != NULL) { |
| 1408 // Pass the write result to the visitor. | 1393 // Pass the write result to the visitor. |
| 1409 debug_visitor_->OnPacketSent(sequence_number, | 1394 debug_visitor_->OnPacketSent(sequence_number, |
| 1410 packet.encryption_level, | 1395 packet.encryption_level, |
| 1411 packet.transmission_type, | 1396 packet.transmission_type, |
| 1412 *encrypted, | 1397 *encrypted, |
| 1413 result); | 1398 result); |
| 1414 } | 1399 } |
| 1400 |
| 1415 if (result.status == WRITE_STATUS_BLOCKED) { | 1401 if (result.status == WRITE_STATUS_BLOCKED) { |
| 1416 visitor_->OnWriteBlocked(); | 1402 visitor_->OnWriteBlocked(); |
| 1417 // If the socket buffers the the data, then the packet should not | 1403 // If the socket buffers the the data, then the packet should not |
| 1418 // be queued and sent again, which would result in an unnecessary | 1404 // be queued and sent again, which would result in an unnecessary |
| 1419 // duplicate packet being sent. The helper must call OnPacketSent | 1405 // duplicate packet being sent. The helper must call OnCanWrite |
| 1420 // when the packet is actually sent. | 1406 // when the write completes, and OnWriteError if an error occurs. |
| 1421 if (writer_->IsWriteBlockedDataBuffered()) { | 1407 if (!writer_->IsWriteBlockedDataBuffered()) { |
| 1422 return true; | 1408 return false; |
| 1423 } | 1409 } |
| 1424 pending_write_.reset(); | 1410 } |
| 1411 QuicTime now = clock_->Now(); |
| 1412 if (packet.transmission_type == NOT_RETRANSMISSION) { |
| 1413 time_of_last_sent_new_packet_ = now; |
| 1414 } |
| 1415 SetPingAlarm(); |
| 1416 DVLOG(1) << ENDPOINT << "time of last sent packet: " |
| 1417 << now.ToDebuggingValue(); |
| 1418 |
| 1419 // TODO(ianswett): Change the sequence number length and other packet creator |
| 1420 // options by a more explicit API than setting a struct value directly, |
| 1421 // perhaps via the NetworkChangeVisitor. |
| 1422 packet_generator_.UpdateSequenceNumberLength( |
| 1423 sent_packet_manager_.least_packet_awaited_by_peer(), |
| 1424 sent_packet_manager_.GetCongestionWindow()); |
| 1425 |
| 1426 bool reset_retransmission_alarm = |
| 1427 sent_packet_manager_.OnPacketSent(sequence_number, |
| 1428 now, |
| 1429 encrypted->length(), |
| 1430 packet.transmission_type, |
| 1431 packet.retransmittable); |
| 1432 |
| 1433 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
| 1434 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(), |
| 1435 QuicTime::Delta::FromMilliseconds(1)); |
| 1436 } |
| 1437 |
| 1438 stats_.bytes_sent += result.bytes_written; |
| 1439 ++stats_.packets_sent; |
| 1440 if (packet.transmission_type != NOT_RETRANSMISSION) { |
| 1441 stats_.bytes_retransmitted += result.bytes_written; |
| 1442 ++stats_.packets_retransmitted; |
| 1443 } |
| 1444 |
| 1445 if (result.status == WRITE_STATUS_ERROR) { |
| 1446 OnWriteError(result.error_code); |
| 1425 return false; | 1447 return false; |
| 1426 } | 1448 } |
| 1427 | 1449 |
| 1428 if (OnPacketSent(result)) { | 1450 return true; |
| 1429 return true; | |
| 1430 } | |
| 1431 return false; | |
| 1432 } | 1451 } |
| 1433 | 1452 |
| 1434 bool QuicConnection::ShouldDiscardPacket( | 1453 bool QuicConnection::ShouldDiscardPacket( |
| 1435 EncryptionLevel level, | 1454 EncryptionLevel level, |
| 1436 QuicPacketSequenceNumber sequence_number, | 1455 QuicPacketSequenceNumber sequence_number, |
| 1437 HasRetransmittableData retransmittable) { | 1456 HasRetransmittableData retransmittable) { |
| 1438 if (!connected_) { | 1457 if (!connected_) { |
| 1439 DVLOG(1) << ENDPOINT | 1458 DVLOG(1) << ENDPOINT |
| 1440 << "Not sending packet as connection is disconnected."; | 1459 << "Not sending packet as connection is disconnected."; |
| 1441 return true; | 1460 return true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1465 if (retransmittable == HAS_RETRANSMITTABLE_DATA && | 1484 if (retransmittable == HAS_RETRANSMITTABLE_DATA && |
| 1466 !sent_packet_manager_.HasRetransmittableFrames(sequence_number)) { | 1485 !sent_packet_manager_.HasRetransmittableFrames(sequence_number)) { |
| 1467 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << sequence_number | 1486 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << sequence_number |
| 1468 << " A previous transmission was acked while write blocked."; | 1487 << " A previous transmission was acked while write blocked."; |
| 1469 return true; | 1488 return true; |
| 1470 } | 1489 } |
| 1471 | 1490 |
| 1472 return false; | 1491 return false; |
| 1473 } | 1492 } |
| 1474 | 1493 |
| 1475 bool QuicConnection::OnPacketSent(WriteResult result) { | 1494 void QuicConnection::OnWriteError(int error_code) { |
| 1476 DCHECK_NE(WRITE_STATUS_BLOCKED, result.status); | 1495 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code |
| 1477 if (pending_write_.get() == NULL) { | 1496 << " (" << ErrorToString(error_code) << ")"; |
| 1478 LOG(DFATAL) << "OnPacketSent called without a pending write."; | 1497 // We can't send an error as the socket is presumably borked. |
| 1479 return false; | 1498 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
| 1480 } | |
| 1481 | |
| 1482 QuicPacketSequenceNumber sequence_number = pending_write_->sequence_number; | |
| 1483 TransmissionType transmission_type = pending_write_->transmission_type; | |
| 1484 HasRetransmittableData retransmittable = pending_write_->retransmittable; | |
| 1485 size_t length = pending_write_->length; | |
| 1486 pending_write_.reset(); | |
| 1487 | |
| 1488 if (result.status == WRITE_STATUS_ERROR) { | |
| 1489 DVLOG(1) << ENDPOINT << "Write failed with error: " << result.error_code | |
| 1490 << " (" << ErrorToString(result.error_code) << ")"; | |
| 1491 // We can't send an error as the socket is presumably borked. | |
| 1492 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | |
| 1493 return false; | |
| 1494 } | |
| 1495 | |
| 1496 QuicTime now = clock_->Now(); | |
| 1497 if (transmission_type == NOT_RETRANSMISSION) { | |
| 1498 time_of_last_sent_new_packet_ = now; | |
| 1499 } | |
| 1500 SetPingAlarm(); | |
| 1501 DVLOG(1) << ENDPOINT << "time of last sent packet: " | |
| 1502 << now.ToDebuggingValue(); | |
| 1503 | |
| 1504 // TODO(ianswett): Change the sequence number length and other packet creator | |
| 1505 // options by a more explicit API than setting a struct value directly. | |
| 1506 packet_generator_.UpdateSequenceNumberLength( | |
| 1507 received_packet_manager_.least_packet_awaited_by_peer(), | |
| 1508 sent_packet_manager_.GetCongestionWindow()); | |
| 1509 | |
| 1510 bool reset_retransmission_alarm = | |
| 1511 sent_packet_manager_.OnPacketSent(sequence_number, now, length, | |
| 1512 transmission_type, retransmittable); | |
| 1513 | |
| 1514 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { | |
| 1515 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); | |
| 1516 retransmission_alarm_->Update(retransmission_time, | |
| 1517 QuicTime::Delta::FromMilliseconds(1)); | |
| 1518 } | |
| 1519 | |
| 1520 stats_.bytes_sent += result.bytes_written; | |
| 1521 ++stats_.packets_sent; | |
| 1522 | |
| 1523 if (transmission_type != NOT_RETRANSMISSION) { | |
| 1524 stats_.bytes_retransmitted += result.bytes_written; | |
| 1525 ++stats_.packets_retransmitted; | |
| 1526 } | |
| 1527 | |
| 1528 return true; | |
| 1529 } | 1499 } |
| 1530 | 1500 |
| 1531 bool QuicConnection::OnSerializedPacket( | 1501 bool QuicConnection::OnSerializedPacket( |
| 1532 const SerializedPacket& serialized_packet) { | 1502 const SerializedPacket& serialized_packet) { |
| 1533 if (serialized_packet.retransmittable_frames) { | 1503 if (serialized_packet.retransmittable_frames) { |
| 1534 serialized_packet.retransmittable_frames-> | 1504 serialized_packet.retransmittable_frames-> |
| 1535 set_encryption_level(encryption_level_); | 1505 set_encryption_level(encryption_level_); |
| 1536 } | 1506 } |
| 1537 sent_packet_manager_.OnSerializedPacket(serialized_packet); | 1507 sent_packet_manager_.OnSerializedPacket(serialized_packet); |
| 1538 // The TransmissionType is NOT_RETRANSMISSION because all retransmissions | 1508 // The TransmissionType is NOT_RETRANSMISSION because all retransmissions |
| 1539 // serialize packets and invoke SendOrQueuePacket directly. | 1509 // serialize packets and invoke SendOrQueuePacket directly. |
| 1540 return SendOrQueuePacket(encryption_level_, | 1510 return SendOrQueuePacket(encryption_level_, |
| 1541 serialized_packet, | 1511 serialized_packet, |
| 1542 NOT_RETRANSMISSION); | 1512 NOT_RETRANSMISSION); |
| 1543 } | 1513 } |
| 1544 | 1514 |
| 1515 void QuicConnection::OnCongestionWindowChange(QuicByteCount congestion_window) { |
| 1516 packet_generator_.OnCongestionWindowChange(congestion_window); |
| 1517 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); |
| 1518 } |
| 1519 |
| 1545 void QuicConnection::OnHandshakeComplete() { | 1520 void QuicConnection::OnHandshakeComplete() { |
| 1546 sent_packet_manager_.SetHandshakeConfirmed(); | 1521 sent_packet_manager_.SetHandshakeConfirmed(); |
| 1547 } | 1522 } |
| 1548 | 1523 |
| 1549 bool QuicConnection::SendOrQueuePacket(EncryptionLevel level, | 1524 bool QuicConnection::SendOrQueuePacket(EncryptionLevel level, |
| 1550 const SerializedPacket& packet, | 1525 const SerializedPacket& packet, |
| 1551 TransmissionType transmission_type) { | 1526 TransmissionType transmission_type) { |
| 1552 if (packet.packet == NULL) { | 1527 if (packet.packet == NULL) { |
| 1553 LOG(DFATAL) << "NULL packet passed in to SendOrQueuePacket"; | 1528 LOG(DFATAL) << "NULL packet passed in to SendOrQueuePacket"; |
| 1554 return true; | 1529 return true; |
| 1555 } | 1530 } |
| 1556 | 1531 |
| 1557 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number, | 1532 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number, |
| 1558 packet.entropy_hash); | 1533 packet.entropy_hash); |
| 1559 QueuedPacket queued_packet(packet, level, transmission_type); | 1534 QueuedPacket queued_packet(packet, level, transmission_type); |
| 1560 // If there are already queued packets, put this at the end, | 1535 // If there are already queued packets, put this at the end, |
| 1561 // unless it's ConnectionClose, in which case it is written immediately. | 1536 // unless it's ConnectionClose, in which case it is written immediately. |
| 1562 if ((queued_packet.type == CONNECTION_CLOSE || queued_packets_.empty()) && | 1537 if ((queued_packet.type == CONNECTION_CLOSE || queued_packets_.empty()) && |
| 1563 WritePacket(queued_packet)) { | 1538 WritePacket(queued_packet)) { |
| 1564 delete packet.packet; | 1539 delete packet.packet; |
| 1565 return true; | 1540 return true; |
| 1566 } | 1541 } |
| 1567 queued_packet.type = QUEUED; | 1542 queued_packet.type = QUEUED; |
| 1568 queued_packets_.push_back(queued_packet); | 1543 queued_packets_.push_back(queued_packet); |
| 1569 return false; | 1544 return false; |
| 1570 } | 1545 } |
| 1571 | 1546 |
| 1572 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { | 1547 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { |
| 1573 stop_waiting->least_unacked = GetLeastUnacked(); | 1548 stop_waiting->least_unacked = GetLeastUnacked(); |
| 1574 stop_waiting->entropy_hash = sent_entropy_manager_.EntropyHash( | 1549 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( |
| 1575 stop_waiting->least_unacked - 1); | 1550 stop_waiting->least_unacked - 1); |
| 1576 } | 1551 } |
| 1577 | 1552 |
| 1578 void QuicConnection::SendPing() { | 1553 void QuicConnection::SendPing() { |
| 1579 if (retransmission_alarm_->IsSet()) { | 1554 if (retransmission_alarm_->IsSet()) { |
| 1580 return; | 1555 return; |
| 1581 } | 1556 } |
| 1582 if (version() == QUIC_VERSION_16) { | 1557 if (version() == QUIC_VERSION_16) { |
| 1583 // TODO(rch): remove this when we remove version 15 and 16. | 1558 // TODO(rch): remove this when we remove version 15 and 16. |
| 1584 // This is a horrible hideous hack which we should not support. | 1559 // This is a horrible hideous hack which we should not support. |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 return; | 1785 return; |
| 1811 } | 1786 } |
| 1812 connected_ = false; | 1787 connected_ = false; |
| 1813 if (debug_visitor_.get() != NULL) { | 1788 if (debug_visitor_.get() != NULL) { |
| 1814 debug_visitor_->OnConnectionClosed(error, from_peer); | 1789 debug_visitor_->OnConnectionClosed(error, from_peer); |
| 1815 } | 1790 } |
| 1816 visitor_->OnConnectionClosed(error, from_peer); | 1791 visitor_->OnConnectionClosed(error, from_peer); |
| 1817 // Cancel the alarms so they don't trigger any action now that the | 1792 // Cancel the alarms so they don't trigger any action now that the |
| 1818 // connection is closed. | 1793 // connection is closed. |
| 1819 ack_alarm_->Cancel(); | 1794 ack_alarm_->Cancel(); |
| 1795 ping_alarm_->Cancel(); |
| 1820 resume_writes_alarm_->Cancel(); | 1796 resume_writes_alarm_->Cancel(); |
| 1821 retransmission_alarm_->Cancel(); | 1797 retransmission_alarm_->Cancel(); |
| 1822 send_alarm_->Cancel(); | 1798 send_alarm_->Cancel(); |
| 1823 timeout_alarm_->Cancel(); | 1799 timeout_alarm_->Cancel(); |
| 1824 } | 1800 } |
| 1825 | 1801 |
| 1826 void QuicConnection::SendGoAway(QuicErrorCode error, | 1802 void QuicConnection::SendGoAway(QuicErrorCode error, |
| 1827 QuicStreamId last_good_stream_id, | 1803 QuicStreamId last_good_stream_id, |
| 1828 const string& reason) { | 1804 const string& reason) { |
| 1829 DVLOG(1) << ENDPOINT << "Going away with error " | 1805 DVLOG(1) << ENDPOINT << "Going away with error " |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 // If we changed the generator's batch state, restore original batch state. | 1985 // If we changed the generator's batch state, restore original batch state. |
| 2010 if (!already_in_batch_mode_) { | 1986 if (!already_in_batch_mode_) { |
| 2011 DVLOG(1) << "Leaving Batch Mode."; | 1987 DVLOG(1) << "Leaving Batch Mode."; |
| 2012 connection_->packet_generator_.FinishBatchOperations(); | 1988 connection_->packet_generator_.FinishBatchOperations(); |
| 2013 } | 1989 } |
| 2014 DCHECK_EQ(already_in_batch_mode_, | 1990 DCHECK_EQ(already_in_batch_mode_, |
| 2015 connection_->packet_generator_.InBatchMode()); | 1991 connection_->packet_generator_.InBatchMode()); |
| 2016 } | 1992 } |
| 2017 | 1993 |
| 2018 } // namespace net | 1994 } // namespace net |
| OLD | NEW |