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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 is_server), | 159 is_server), |
160 helper_(helper), | 160 helper_(helper), |
161 writer_(writer), | 161 writer_(writer), |
162 encryption_level_(ENCRYPTION_NONE), | 162 encryption_level_(ENCRYPTION_NONE), |
163 clock_(helper->GetClock()), | 163 clock_(helper->GetClock()), |
164 random_generator_(helper->GetRandomGenerator()), | 164 random_generator_(helper->GetRandomGenerator()), |
165 guid_(guid), | 165 guid_(guid), |
166 peer_address_(address), | 166 peer_address_(address), |
167 largest_seen_packet_with_ack_(0), | 167 largest_seen_packet_with_ack_(0), |
168 pending_version_negotiation_packet_(false), | 168 pending_version_negotiation_packet_(false), |
169 write_blocked_(false), | |
170 received_packet_manager_(kTCP), | 169 received_packet_manager_(kTCP), |
171 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 170 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
172 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 171 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
173 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 172 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
174 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 173 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
175 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 174 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
176 debug_visitor_(NULL), | 175 debug_visitor_(NULL), |
177 packet_creator_(guid_, &framer_, random_generator_, is_server), | 176 packet_creator_(guid_, &framer_, random_generator_, is_server), |
178 packet_generator_(this, NULL, &packet_creator_), | 177 packet_generator_(this, NULL, &packet_creator_), |
179 idle_network_timeout_( | 178 idle_network_timeout_( |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 764 } |
766 | 765 |
767 void QuicConnection::SendVersionNegotiationPacket() { | 766 void QuicConnection::SendVersionNegotiationPacket() { |
768 scoped_ptr<QuicEncryptedPacket> version_packet( | 767 scoped_ptr<QuicEncryptedPacket> version_packet( |
769 packet_creator_.SerializeVersionNegotiationPacket( | 768 packet_creator_.SerializeVersionNegotiationPacket( |
770 framer_.supported_versions())); | 769 framer_.supported_versions())); |
771 // TODO(satyamshekhar): implement zero server state negotiation. | 770 // TODO(satyamshekhar): implement zero server state negotiation. |
772 WriteResult result = | 771 WriteResult result = |
773 writer_->WritePacket(version_packet->data(), version_packet->length(), | 772 writer_->WritePacket(version_packet->data(), version_packet->length(), |
774 self_address().address(), peer_address(), this); | 773 self_address().address(), peer_address(), this); |
775 if (result.status == WRITE_STATUS_BLOCKED) { | |
776 write_blocked_ = true; | |
777 } | |
778 if (result.status == WRITE_STATUS_OK || | 774 if (result.status == WRITE_STATUS_OK || |
779 (result.status == WRITE_STATUS_BLOCKED && | 775 (result.status == WRITE_STATUS_BLOCKED && |
780 writer_->IsWriteBlockedDataBuffered())) { | 776 writer_->IsWriteBlockedDataBuffered())) { |
781 pending_version_negotiation_packet_ = false; | 777 pending_version_negotiation_packet_ = false; |
782 return; | 778 return; |
783 } | 779 } |
784 if (result.status == WRITE_STATUS_ERROR) { | 780 if (result.status == WRITE_STATUS_ERROR) { |
785 // We can't send an error as the socket is presumably borked. | 781 // We can't send an error as the socket is presumably borked. |
786 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | 782 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
787 } | 783 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 870 } |
875 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " | 871 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " |
876 << last_header_.packet_sequence_number; | 872 << last_header_.packet_sequence_number; |
877 return; | 873 return; |
878 } | 874 } |
879 MaybeProcessUndecryptablePackets(); | 875 MaybeProcessUndecryptablePackets(); |
880 MaybeProcessRevivedPacket(); | 876 MaybeProcessRevivedPacket(); |
881 } | 877 } |
882 | 878 |
883 bool QuicConnection::OnCanWrite() { | 879 bool QuicConnection::OnCanWrite() { |
884 write_blocked_ = false; | 880 DCHECK(!writer_->IsWriteBlocked()); |
885 return DoWrite(); | |
886 } | |
887 | 881 |
888 bool QuicConnection::WriteIfNotBlocked() { | |
889 if (write_blocked_) { | |
890 return false; | |
891 } | |
892 return DoWrite(); | |
893 } | |
894 | |
895 bool QuicConnection::DoWrite() { | |
896 DCHECK(!write_blocked_); | |
897 WriteQueuedPackets(); | 882 WriteQueuedPackets(); |
898 | |
899 WritePendingRetransmissions(); | 883 WritePendingRetransmissions(); |
900 | 884 |
901 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? | 885 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? |
902 IS_HANDSHAKE : NOT_HANDSHAKE; | 886 IS_HANDSHAKE : NOT_HANDSHAKE; |
903 // Sending queued packets may have caused the socket to become write blocked, | 887 // Sending queued packets may have caused the socket to become write blocked, |
904 // or the congestion manager to prohibit sending. If we've sent everything | 888 // or the congestion manager to prohibit sending. If we've sent everything |
905 // we had queued and we're still not blocked, let the visitor know it can | 889 // we had queued and we're still not blocked, let the visitor know it can |
906 // write more. | 890 // write more. |
907 if (CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, | 891 if (CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, |
908 pending_handshake)) { | 892 pending_handshake)) { |
909 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere. | 893 // Set |include_ack| to false in bundler; ack inclusion happens elsewhere. |
910 scoped_ptr<ScopedPacketBundler> bundler( | 894 scoped_ptr<ScopedPacketBundler> bundler( |
911 new ScopedPacketBundler(this, false)); | 895 new ScopedPacketBundler(this, false)); |
912 bool all_bytes_written = visitor_->OnCanWrite(); | 896 bool all_bytes_written = visitor_->OnCanWrite(); |
913 bundler.reset(); | 897 bundler.reset(); |
914 // After the visitor writes, it may have caused the socket to become write | 898 // After the visitor writes, it may have caused the socket to become write |
915 // blocked or the congestion manager to prohibit sending, so check again. | 899 // blocked or the congestion manager to prohibit sending, so check again. |
916 pending_handshake = visitor_->HasPendingHandshake() ? IS_HANDSHAKE | 900 pending_handshake = visitor_->HasPendingHandshake() ? IS_HANDSHAKE |
917 : NOT_HANDSHAKE; | 901 : NOT_HANDSHAKE; |
918 if (!all_bytes_written && !resume_writes_alarm_->IsSet() && | 902 if (!all_bytes_written && !resume_writes_alarm_->IsSet() && |
919 CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, | 903 CanWrite(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, |
920 pending_handshake)) { | 904 pending_handshake)) { |
921 // We're not write blocked, but some stream didn't write out all of its | 905 // We're not write blocked, but some stream didn't write out all of its |
922 // bytes. Register for 'immediate' resumption so we'll keep writing after | 906 // bytes. Register for 'immediate' resumption so we'll keep writing after |
923 // other quic connections have had a chance to use the socket. | 907 // other quic connections have had a chance to use the socket. |
924 resume_writes_alarm_->Set(clock_->ApproximateNow()); | 908 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
925 } | 909 } |
926 } | 910 } |
927 | 911 |
928 return !write_blocked_; | 912 return !writer_->IsWriteBlocked(); |
| 913 } |
| 914 |
| 915 void QuicConnection::WriteIfNotBlocked() { |
| 916 if (!writer_->IsWriteBlocked()) { |
| 917 OnCanWrite(); |
| 918 } |
929 } | 919 } |
930 | 920 |
931 bool QuicConnection::ProcessValidatedPacket() { | 921 bool QuicConnection::ProcessValidatedPacket() { |
932 if (address_migrating_) { | 922 if (address_migrating_) { |
933 SendConnectionCloseWithDetails( | 923 SendConnectionCloseWithDetails( |
934 QUIC_ERROR_MIGRATING_ADDRESS, | 924 QUIC_ERROR_MIGRATING_ADDRESS, |
935 "Address migration is not yet a supported feature"); | 925 "Address migration is not yet a supported feature"); |
936 return false; | 926 return false; |
937 } | 927 } |
938 time_of_last_received_packet_ = clock_->Now(); | 928 time_of_last_received_packet_ = clock_->Now(); |
939 DVLOG(1) << ENDPOINT << "time of last received packet: " | 929 DVLOG(1) << ENDPOINT << "time of last received packet: " |
940 << time_of_last_received_packet_.ToDebuggingValue(); | 930 << time_of_last_received_packet_.ToDebuggingValue(); |
941 | 931 |
942 if (is_server_ && encryption_level_ == ENCRYPTION_NONE && | 932 if (is_server_ && encryption_level_ == ENCRYPTION_NONE && |
943 last_size_ > options()->max_packet_length) { | 933 last_size_ > options()->max_packet_length) { |
944 options()->max_packet_length = last_size_; | 934 options()->max_packet_length = last_size_; |
945 } | 935 } |
946 return true; | 936 return true; |
947 } | 937 } |
948 | 938 |
949 bool QuicConnection::WriteQueuedPackets() { | 939 void QuicConnection::WriteQueuedPackets() { |
950 DCHECK(!write_blocked_); | 940 DCHECK(!writer_->IsWriteBlocked()); |
951 | 941 |
952 if (pending_version_negotiation_packet_) { | 942 if (pending_version_negotiation_packet_) { |
953 SendVersionNegotiationPacket(); | 943 SendVersionNegotiationPacket(); |
954 } | 944 } |
955 | 945 |
956 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); | 946 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); |
957 while (!write_blocked_ && packet_iterator != queued_packets_.end()) { | 947 while (!writer_->IsWriteBlocked() && |
| 948 packet_iterator != queued_packets_.end()) { |
958 if (WritePacket(packet_iterator->encryption_level, | 949 if (WritePacket(packet_iterator->encryption_level, |
959 packet_iterator->sequence_number, | 950 packet_iterator->sequence_number, |
960 packet_iterator->packet, | 951 packet_iterator->packet, |
961 packet_iterator->transmission_type, | 952 packet_iterator->transmission_type, |
962 packet_iterator->retransmittable, | 953 packet_iterator->retransmittable, |
963 packet_iterator->handshake, | 954 packet_iterator->handshake, |
964 packet_iterator->forced)) { | 955 packet_iterator->forced)) { |
| 956 delete packet_iterator->packet; |
965 packet_iterator = queued_packets_.erase(packet_iterator); | 957 packet_iterator = queued_packets_.erase(packet_iterator); |
966 } else { | 958 } else { |
967 // Continue, because some queued packets may still be writable. | 959 // Continue, because some queued packets may still be writable. |
968 // This can happen if a retransmit send fail. | 960 // This can happen if a retransmit send fails. |
969 ++packet_iterator; | 961 ++packet_iterator; |
970 } | 962 } |
971 } | 963 } |
972 | |
973 return !write_blocked_; | |
974 } | 964 } |
975 | 965 |
976 void QuicConnection::WritePendingRetransmissions() { | 966 void QuicConnection::WritePendingRetransmissions() { |
977 // Keep writing as long as there's a pending retransmission which can be | 967 // Keep writing as long as there's a pending retransmission which can be |
978 // written. | 968 // written. |
979 while (sent_packet_manager_.HasPendingRetransmissions()) { | 969 while (sent_packet_manager_.HasPendingRetransmissions()) { |
980 const QuicSentPacketManager::PendingRetransmission pending = | 970 const QuicSentPacketManager::PendingRetransmission pending = |
981 sent_packet_manager_.NextPendingRetransmission(); | 971 sent_packet_manager_.NextPendingRetransmission(); |
982 if (HasForcedFrames(&pending.retransmittable_frames) == NO_FORCE && | 972 if (HasForcedFrames(&pending.retransmittable_frames) == NO_FORCE && |
983 !CanWrite(pending.transmission_type, HAS_RETRANSMITTABLE_DATA, | 973 !CanWrite(pending.transmission_type, HAS_RETRANSMITTABLE_DATA, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 if (handshake == IS_HANDSHAKE) { | 1018 if (handshake == IS_HANDSHAKE) { |
1029 return true; | 1019 return true; |
1030 } | 1020 } |
1031 | 1021 |
1032 return CanWrite(transmission_type, retransmittable, handshake); | 1022 return CanWrite(transmission_type, retransmittable, handshake); |
1033 } | 1023 } |
1034 | 1024 |
1035 bool QuicConnection::CanWrite(TransmissionType transmission_type, | 1025 bool QuicConnection::CanWrite(TransmissionType transmission_type, |
1036 HasRetransmittableData retransmittable, | 1026 HasRetransmittableData retransmittable, |
1037 IsHandshake handshake) { | 1027 IsHandshake handshake) { |
1038 if (write_blocked_) { | 1028 if (writer_->IsWriteBlocked()) { |
1039 return false; | 1029 return false; |
1040 } | 1030 } |
1041 | 1031 |
1042 // TODO(rch): consider removing this check so that if an ACK comes in | 1032 // TODO(rch): consider removing this check so that if an ACK comes in |
1043 // before the alarm goes it, we might be able send out a packet. | 1033 // before the alarm goes it, we might be able send out a packet. |
1044 // This check assumes that if the send alarm is set, it applies equally to all | 1034 // This check assumes that if the send alarm is set, it applies equally to all |
1045 // types of transmissions. | 1035 // types of transmissions. |
1046 if (send_alarm_->IsSet()) { | 1036 if (send_alarm_->IsSet()) { |
1047 DVLOG(1) << "Send alarm set. Not sending."; | 1037 DVLOG(1) << "Send alarm set. Not sending."; |
1048 return false; | 1038 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
1066 } | 1056 } |
1067 | 1057 |
1068 bool QuicConnection::WritePacket(EncryptionLevel level, | 1058 bool QuicConnection::WritePacket(EncryptionLevel level, |
1069 QuicPacketSequenceNumber sequence_number, | 1059 QuicPacketSequenceNumber sequence_number, |
1070 QuicPacket* packet, | 1060 QuicPacket* packet, |
1071 TransmissionType transmission_type, | 1061 TransmissionType transmission_type, |
1072 HasRetransmittableData retransmittable, | 1062 HasRetransmittableData retransmittable, |
1073 IsHandshake handshake, | 1063 IsHandshake handshake, |
1074 Force forced) { | 1064 Force forced) { |
1075 if (ShouldDiscardPacket(level, sequence_number, retransmittable)) { | 1065 if (ShouldDiscardPacket(level, sequence_number, retransmittable)) { |
1076 delete packet; | |
1077 return true; | 1066 return true; |
1078 } | 1067 } |
1079 | 1068 |
1080 // If we're write blocked, we know we can't write. | 1069 // If the writer is blocked, we must not write. However, if the packet is |
1081 if (write_blocked_) { | 1070 // forced (i.e., it's the ConnectionClose packet), we still need to encrypt it |
1082 return false; | 1071 // and hand it off to TimeWaitListManager. |
1083 } | 1072 // We check nonforced packets here and forced after encryption. |
1084 | |
1085 // If we are not forced and we can't write, then simply return false; | |
1086 if (forced == NO_FORCE && | 1073 if (forced == NO_FORCE && |
1087 !CanWrite(transmission_type, retransmittable, handshake)) { | 1074 !CanWrite(transmission_type, retransmittable, handshake)) { |
1088 return false; | 1075 return false; |
1089 } | 1076 } |
1090 | 1077 |
1091 // Some encryption algorithms require the packet sequence numbers not be | 1078 // Some encryption algorithms require the packet sequence numbers not be |
1092 // repeated. | 1079 // repeated. |
1093 DCHECK_LE(sequence_number_of_last_inorder_packet_, sequence_number); | 1080 DCHECK_LE(sequence_number_of_last_inorder_packet_, sequence_number); |
1094 // Only increase this when packets have not been queued. Once they're queued | 1081 // Only increase this when packets have not been queued. Once they're queued |
1095 // due to a write block, there is the chance of sending forced and other | 1082 // due to a write block, there is the chance of sending forced and other |
1096 // higher priority packets out of order. | 1083 // higher priority packets out of order. |
1097 if (queued_packets_.empty()) { | 1084 if (queued_packets_.empty()) { |
1098 sequence_number_of_last_inorder_packet_ = sequence_number; | 1085 sequence_number_of_last_inorder_packet_ = sequence_number; |
1099 } | 1086 } |
1100 | 1087 |
1101 scoped_ptr<QuicEncryptedPacket> encrypted( | 1088 QuicEncryptedPacket* encrypted = |
1102 framer_.EncryptPacket(level, sequence_number, *packet)); | 1089 framer_.EncryptPacket(level, sequence_number, *packet); |
1103 if (encrypted.get() == NULL) { | 1090 if (encrypted == NULL) { |
1104 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " | 1091 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " |
1105 << sequence_number; | 1092 << sequence_number; |
| 1093 // CloseConnection does not send close packet, so no infinite loop here. |
1106 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1094 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1107 return false; | 1095 return false; |
1108 } | 1096 } |
1109 | 1097 |
1110 // If it's the ConnectionClose packet, the only FORCED frame type, | 1098 // Forced packets are eventually owned by TimeWaitListManager; nonforced are |
1111 // clone a copy for resending later by the TimeWaitListManager. | 1099 // deleted at the end of this call. |
1112 if (forced == FORCE) { | 1100 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; |
| 1101 if (forced == NO_FORCE) { |
| 1102 encrypted_deleter.reset(encrypted); |
| 1103 } else { // forced == FORCE |
1113 DCHECK(connection_close_packet_.get() == NULL); | 1104 DCHECK(connection_close_packet_.get() == NULL); |
1114 connection_close_packet_.reset(encrypted->Clone()); | 1105 connection_close_packet_.reset(encrypted); |
| 1106 // This assures we won't try to write *forced* packets when blocked. |
| 1107 // Return true to stop processing. |
| 1108 if (writer_->IsWriteBlocked()) { |
| 1109 return true; |
| 1110 } |
1115 } | 1111 } |
1116 | 1112 |
1117 if (encrypted->length() > options()->max_packet_length) { | 1113 if (encrypted->length() > options()->max_packet_length) { |
1118 LOG(DFATAL) << "Writing an encrypted packet larger than max_packet_length:" | 1114 LOG(DFATAL) << "Writing an encrypted packet larger than max_packet_length:" |
1119 << options()->max_packet_length << " encrypted length: " | 1115 << options()->max_packet_length << " encrypted length: " |
1120 << encrypted->length(); | 1116 << encrypted->length(); |
1121 } | 1117 } |
1122 DVLOG(1) << ENDPOINT << "Sending packet number " << sequence_number | 1118 DVLOG(1) << ENDPOINT << "Sending packet number " << sequence_number |
1123 << " : " << (packet->is_fec_packet() ? "FEC " : | 1119 << " : " << (packet->is_fec_packet() ? "FEC " : |
1124 (retransmittable == HAS_RETRANSMITTABLE_DATA | 1120 (retransmittable == HAS_RETRANSMITTABLE_DATA |
(...skipping 21 matching lines...) Expand all Loading... |
1146 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1142 writer_->WritePacket(encrypted->data(), encrypted->length(), |
1147 self_address().address(), peer_address(), this); | 1143 self_address().address(), peer_address(), this); |
1148 if (result.error_code == ERR_IO_PENDING) { | 1144 if (result.error_code == ERR_IO_PENDING) { |
1149 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1145 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1150 } | 1146 } |
1151 if (debug_visitor_) { | 1147 if (debug_visitor_) { |
1152 // Pass the write result to the visitor. | 1148 // Pass the write result to the visitor. |
1153 debug_visitor_->OnPacketSent(sequence_number, level, *encrypted, result); | 1149 debug_visitor_->OnPacketSent(sequence_number, level, *encrypted, result); |
1154 } | 1150 } |
1155 if (result.status == WRITE_STATUS_BLOCKED) { | 1151 if (result.status == WRITE_STATUS_BLOCKED) { |
1156 // TODO(satyashekhar): It might be more efficient (fewer system calls), if | |
1157 // all connections share this variable i.e this becomes a part of | |
1158 // PacketWriterInterface. | |
1159 write_blocked_ = true; | |
1160 // If the socket buffers the the data, then the packet should not | 1152 // If the socket buffers the the data, then the packet should not |
1161 // be queued and sent again, which would result in an unnecessary | 1153 // be queued and sent again, which would result in an unnecessary |
1162 // duplicate packet being sent. The helper must call OnPacketSent | 1154 // duplicate packet being sent. The helper must call OnPacketSent |
1163 // when the packet is actually sent. | 1155 // when the packet is actually sent. |
1164 if (writer_->IsWriteBlockedDataBuffered()) { | 1156 if (writer_->IsWriteBlockedDataBuffered()) { |
1165 delete packet; | |
1166 return true; | 1157 return true; |
1167 } | 1158 } |
1168 pending_write_.reset(); | 1159 pending_write_.reset(); |
1169 return false; | 1160 return false; |
1170 } | 1161 } |
1171 | 1162 |
1172 if (OnPacketSent(result)) { | 1163 if (OnPacketSent(result)) { |
1173 delete packet; | |
1174 return true; | 1164 return true; |
1175 } | 1165 } |
1176 return false; | 1166 return false; |
1177 } | 1167 } |
1178 | 1168 |
1179 bool QuicConnection::ShouldDiscardPacket( | 1169 bool QuicConnection::ShouldDiscardPacket( |
1180 EncryptionLevel level, | 1170 EncryptionLevel level, |
1181 QuicPacketSequenceNumber sequence_number, | 1171 QuicPacketSequenceNumber sequence_number, |
1182 HasRetransmittableData retransmittable) { | 1172 HasRetransmittableData retransmittable) { |
1183 if (!connected_) { | 1173 if (!connected_) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 NOT_HANDSHAKE : packet.retransmittable_frames->HasCryptoHandshake(); | 1301 NOT_HANDSHAKE : packet.retransmittable_frames->HasCryptoHandshake(); |
1312 Force forced = HasForcedFrames(packet.retransmittable_frames); | 1302 Force forced = HasForcedFrames(packet.retransmittable_frames); |
1313 HasRetransmittableData retransmittable = | 1303 HasRetransmittableData retransmittable = |
1314 (transmission_type != NOT_RETRANSMISSION || | 1304 (transmission_type != NOT_RETRANSMISSION || |
1315 packet.retransmittable_frames != NULL) ? | 1305 packet.retransmittable_frames != NULL) ? |
1316 HAS_RETRANSMITTABLE_DATA : NO_RETRANSMITTABLE_DATA; | 1306 HAS_RETRANSMITTABLE_DATA : NO_RETRANSMITTABLE_DATA; |
1317 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number, | 1307 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number, |
1318 packet.entropy_hash); | 1308 packet.entropy_hash); |
1319 if (WritePacket(level, packet.sequence_number, packet.packet, | 1309 if (WritePacket(level, packet.sequence_number, packet.packet, |
1320 transmission_type, retransmittable, handshake, forced)) { | 1310 transmission_type, retransmittable, handshake, forced)) { |
| 1311 delete packet.packet; |
1321 return true; | 1312 return true; |
1322 } | 1313 } |
1323 queued_packets_.push_back(QueuedPacket(packet.sequence_number, packet.packet, | 1314 queued_packets_.push_back(QueuedPacket(packet.sequence_number, packet.packet, |
1324 level, transmission_type, | 1315 level, transmission_type, |
1325 retransmittable, handshake, forced)); | 1316 retransmittable, handshake, forced)); |
1326 return false; | 1317 return false; |
1327 } | 1318 } |
1328 | 1319 |
1329 void QuicConnection::UpdateSentPacketInfo(SentPacketInfo* sent_info) { | 1320 void QuicConnection::UpdateSentPacketInfo(SentPacketInfo* sent_info) { |
1330 sent_info->least_unacked = sent_packet_manager_.GetLeastUnackedSentPacket(); | 1321 sent_info->least_unacked = sent_packet_manager_.GetLeastUnackedSentPacket(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 } | 1471 } |
1481 return group_map_[fec_group_num]; | 1472 return group_map_[fec_group_num]; |
1482 } | 1473 } |
1483 | 1474 |
1484 void QuicConnection::SendConnectionClose(QuicErrorCode error) { | 1475 void QuicConnection::SendConnectionClose(QuicErrorCode error) { |
1485 SendConnectionCloseWithDetails(error, string()); | 1476 SendConnectionCloseWithDetails(error, string()); |
1486 } | 1477 } |
1487 | 1478 |
1488 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, | 1479 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, |
1489 const string& details) { | 1480 const string& details) { |
1490 if (!write_blocked_) { | 1481 // If we're write blocked, WritePacket() will not send, but will capture the |
1491 SendConnectionClosePacket(error, details); | 1482 // serialized packet. |
1492 } | 1483 SendConnectionClosePacket(error, details); |
1493 CloseConnection(error, false); | 1484 CloseConnection(error, false); |
1494 } | 1485 } |
1495 | 1486 |
1496 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, | 1487 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, |
1497 const string& details) { | 1488 const string& details) { |
1498 DVLOG(1) << ENDPOINT << "Force closing " << guid() << " with error " | 1489 DVLOG(1) << ENDPOINT << "Force closing " << guid() << " with error " |
1499 << QuicUtils::ErrorToString(error) << " (" << error << ") " | 1490 << QuicUtils::ErrorToString(error) << " (" << error << ") " |
1500 << details; | 1491 << details; |
1501 ScopedPacketBundler ack_bundler(this, true); | 1492 ScopedPacketBundler ack_bundler(this, true); |
1502 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 1493 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 // If we changed the generator's batch state, restore original batch state. | 1655 // If we changed the generator's batch state, restore original batch state. |
1665 if (!already_in_batch_mode_) { | 1656 if (!already_in_batch_mode_) { |
1666 DVLOG(1) << "Leaving Batch Mode."; | 1657 DVLOG(1) << "Leaving Batch Mode."; |
1667 connection_->packet_generator_.FinishBatchOperations(); | 1658 connection_->packet_generator_.FinishBatchOperations(); |
1668 } | 1659 } |
1669 DCHECK_EQ(already_in_batch_mode_, | 1660 DCHECK_EQ(already_in_batch_mode_, |
1670 connection_->packet_generator_.InBatchMode()); | 1661 connection_->packet_generator_.InBatchMode()); |
1671 } | 1662 } |
1672 | 1663 |
1673 } // namespace net | 1664 } // namespace net |
OLD | NEW |