| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tools/quic/quic_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 bool connection_rejected_statelessly, | 107 bool connection_rejected_statelessly, |
| 108 std::vector<std::unique_ptr<QuicEncryptedPacket>>* packets) { | 108 std::vector<std::unique_ptr<QuicEncryptedPacket>>* packets) { |
| 109 time_wait_list_manager_.AddConnectionIdToTimeWait( | 109 time_wait_list_manager_.AddConnectionIdToTimeWait( |
| 110 connection_id, version, connection_rejected_statelessly, packets); | 110 connection_id, version, connection_rejected_statelessly, packets); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) { | 113 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) { |
| 114 return time_wait_list_manager_.IsConnectionIdInTimeWait(connection_id); | 114 return time_wait_list_manager_.IsConnectionIdInTimeWait(connection_id); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void ProcessPacket(QuicConnectionId connection_id, | 117 void ProcessPacket(QuicConnectionId connection_id) { |
| 118 QuicPacketNumber packet_number) { | |
| 119 QuicEncryptedPacket packet(nullptr, 0); | |
| 120 time_wait_list_manager_.ProcessPacket(server_address_, client_address_, | 118 time_wait_list_manager_.ProcessPacket(server_address_, client_address_, |
| 121 connection_id, packet_number, packet); | 119 connection_id); |
| 122 } | 120 } |
| 123 | 121 |
| 124 QuicEncryptedPacket* ConstructEncryptedPacket( | 122 QuicEncryptedPacket* ConstructEncryptedPacket( |
| 125 QuicConnectionId connection_id, | 123 QuicConnectionId connection_id, |
| 126 QuicPacketNumber packet_number) { | 124 QuicPacketNumber packet_number) { |
| 127 return net::test::ConstructEncryptedPacket(connection_id, false, false, | 125 return net::test::ConstructEncryptedPacket(connection_id, false, false, |
| 128 packet_number, "data"); | 126 packet_number, "data"); |
| 129 } | 127 } |
| 130 | 128 |
| 131 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 129 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
| 132 NiceMock<MockFakeTimeEpollServer> epoll_server_; | 130 NiceMock<MockFakeTimeEpollServer> epoll_server_; |
| 133 QuicEpollConnectionHelper helper_; | 131 QuicEpollConnectionHelper helper_; |
| 134 QuicEpollAlarmFactory alarm_factory_; | 132 QuicEpollAlarmFactory alarm_factory_; |
| 135 StrictMock<MockPacketWriter> writer_; | 133 StrictMock<MockPacketWriter> writer_; |
| 136 StrictMock<MockQuicSessionVisitor> visitor_; | 134 StrictMock<MockQuicSessionVisitor> visitor_; |
| 137 QuicTimeWaitListManager time_wait_list_manager_; | 135 QuicTimeWaitListManager time_wait_list_manager_; |
| 138 QuicConnectionId connection_id_; | 136 QuicConnectionId connection_id_; |
| 139 QuicSocketAddress server_address_; | 137 QuicSocketAddress server_address_; |
| 140 QuicSocketAddress client_address_; | 138 QuicSocketAddress client_address_; |
| 141 bool writer_is_blocked_; | 139 bool writer_is_blocked_; |
| 142 }; | 140 }; |
| 143 | 141 |
| 144 class ValidatePublicResetPacketPredicate | 142 class ValidatePublicResetPacketPredicate |
| 145 : public MatcherInterface<const std::tr1::tuple<const char*, int>> { | 143 : public MatcherInterface<const std::tr1::tuple<const char*, int>> { |
| 146 public: | 144 public: |
| 147 explicit ValidatePublicResetPacketPredicate(QuicConnectionId connection_id, | 145 explicit ValidatePublicResetPacketPredicate(QuicConnectionId connection_id) |
| 148 QuicPacketNumber number) | 146 : connection_id_(connection_id) {} |
| 149 : connection_id_(connection_id), packet_number_(number) {} | |
| 150 | 147 |
| 151 bool MatchAndExplain( | 148 bool MatchAndExplain( |
| 152 const std::tr1::tuple<const char*, int> packet_buffer, | 149 const std::tr1::tuple<const char*, int> packet_buffer, |
| 153 testing::MatchResultListener* /* listener */) const override { | 150 testing::MatchResultListener* /* listener */) const override { |
| 154 FramerVisitorCapturingPublicReset visitor; | 151 FramerVisitorCapturingPublicReset visitor; |
| 155 QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), | 152 QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), |
| 156 Perspective::IS_CLIENT); | 153 Perspective::IS_CLIENT); |
| 157 framer.set_visitor(&visitor); | 154 framer.set_visitor(&visitor); |
| 158 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), | 155 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), |
| 159 std::tr1::get<1>(packet_buffer)); | 156 std::tr1::get<1>(packet_buffer)); |
| 160 framer.ProcessPacket(encrypted); | 157 framer.ProcessPacket(encrypted); |
| 161 QuicPublicResetPacket packet = visitor.public_reset_packet(); | 158 QuicPublicResetPacket packet = visitor.public_reset_packet(); |
| 162 return connection_id_ == GetPeerInMemoryConnectionId( | 159 return connection_id_ == GetPeerInMemoryConnectionId( |
| 163 packet.public_header.connection_id) && | 160 packet.public_header.connection_id) && |
| 164 packet.public_header.reset_flag && | 161 packet.public_header.reset_flag && |
| 165 !packet.public_header.version_flag && | 162 !packet.public_header.version_flag && |
| 166 packet_number_ == packet.rejected_packet_number && | |
| 167 net::test::TestPeerIPAddress() == packet.client_address.host() && | 163 net::test::TestPeerIPAddress() == packet.client_address.host() && |
| 168 kTestPort == packet.client_address.port(); | 164 kTestPort == packet.client_address.port(); |
| 169 } | 165 } |
| 170 | 166 |
| 171 void DescribeTo(::std::ostream* os) const override {} | 167 void DescribeTo(::std::ostream* os) const override {} |
| 172 | 168 |
| 173 void DescribeNegationTo(::std::ostream* os) const override {} | 169 void DescribeNegationTo(::std::ostream* os) const override {} |
| 174 | 170 |
| 175 private: | 171 private: |
| 176 QuicConnectionId connection_id_; | 172 QuicConnectionId connection_id_; |
| 177 QuicPacketNumber packet_number_; | |
| 178 }; | 173 }; |
| 179 | 174 |
| 180 Matcher<const std::tr1::tuple<const char*, int>> PublicResetPacketEq( | 175 Matcher<const std::tr1::tuple<const char*, int>> PublicResetPacketEq( |
| 181 QuicConnectionId connection_id, | 176 QuicConnectionId connection_id) { |
| 182 QuicPacketNumber packet_number) { | 177 return MakeMatcher(new ValidatePublicResetPacketPredicate(connection_id)); |
| 183 return MakeMatcher( | |
| 184 new ValidatePublicResetPacketPredicate(connection_id, packet_number)); | |
| 185 } | 178 } |
| 186 | 179 |
| 187 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { | 180 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { |
| 188 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 181 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
| 189 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 182 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 190 AddConnectionId(connection_id_); | 183 AddConnectionId(connection_id_); |
| 191 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 184 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
| 192 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 185 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 193 } | 186 } |
| 194 | 187 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 216 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 209 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
| 217 const size_t kConnectionCloseLength = 100; | 210 const size_t kConnectionCloseLength = 100; |
| 218 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 211 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 219 std::vector<std::unique_ptr<QuicEncryptedPacket>> termination_packets; | 212 std::vector<std::unique_ptr<QuicEncryptedPacket>> termination_packets; |
| 220 termination_packets.push_back( | 213 termination_packets.push_back( |
| 221 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( | 214 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( |
| 222 new char[kConnectionCloseLength], kConnectionCloseLength, true))); | 215 new char[kConnectionCloseLength], kConnectionCloseLength, true))); |
| 223 AddConnectionId(connection_id_, QuicVersionMax(), | 216 AddConnectionId(connection_id_, QuicVersionMax(), |
| 224 /*connection_rejected_statelessly=*/false, | 217 /*connection_rejected_statelessly=*/false, |
| 225 &termination_packets); | 218 &termination_packets); |
| 226 const int kRandomSequenceNumber = 1; | |
| 227 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 219 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
| 228 server_address_.host(), client_address_, _)) | 220 server_address_.host(), client_address_, _)) |
| 229 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 221 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 230 | 222 |
| 231 ProcessPacket(connection_id_, kRandomSequenceNumber); | 223 ProcessPacket(connection_id_); |
| 232 } | 224 } |
| 233 | 225 |
| 234 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { | 226 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { |
| 235 const size_t kConnectionCloseLength = 100; | 227 const size_t kConnectionCloseLength = 100; |
| 236 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 228 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 237 std::vector<std::unique_ptr<QuicEncryptedPacket>> termination_packets; | 229 std::vector<std::unique_ptr<QuicEncryptedPacket>> termination_packets; |
| 238 termination_packets.push_back( | 230 termination_packets.push_back( |
| 239 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( | 231 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( |
| 240 new char[kConnectionCloseLength], kConnectionCloseLength, true))); | 232 new char[kConnectionCloseLength], kConnectionCloseLength, true))); |
| 241 termination_packets.push_back( | 233 termination_packets.push_back( |
| 242 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( | 234 std::unique_ptr<QuicEncryptedPacket>(new QuicEncryptedPacket( |
| 243 new char[kConnectionCloseLength], kConnectionCloseLength, true))); | 235 new char[kConnectionCloseLength], kConnectionCloseLength, true))); |
| 244 AddConnectionId(connection_id_, QuicVersionMax(), | 236 AddConnectionId(connection_id_, QuicVersionMax(), |
| 245 /*connection_rejected_statelessly=*/false, | 237 /*connection_rejected_statelessly=*/false, |
| 246 &termination_packets); | 238 &termination_packets); |
| 247 const int kRandomSequenceNumber = 1; | |
| 248 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 239 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
| 249 server_address_.host(), client_address_, _)) | 240 server_address_.host(), client_address_, _)) |
| 250 .Times(2) | 241 .Times(2) |
| 251 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); | 242 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 252 | 243 |
| 253 ProcessPacket(connection_id_, kRandomSequenceNumber); | 244 ProcessPacket(connection_id_); |
| 254 } | 245 } |
| 255 | 246 |
| 256 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { | 247 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { |
| 257 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 248 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 258 AddConnectionId(connection_id_); | 249 AddConnectionId(connection_id_); |
| 259 const int kRandomSequenceNumber = 1; | |
| 260 EXPECT_CALL(writer_, | 250 EXPECT_CALL(writer_, |
| 261 WritePacket(_, _, server_address_.host(), client_address_, _)) | 251 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 262 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, 0))) | 252 .With(Args<0, 1>(PublicResetPacketEq(connection_id_))) |
| 263 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 253 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
| 264 | 254 |
| 265 ProcessPacket(connection_id_, kRandomSequenceNumber); | 255 ProcessPacket(connection_id_); |
| 266 } | 256 } |
| 267 | 257 |
| 268 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { | 258 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { |
| 269 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 259 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 270 AddConnectionId(connection_id_); | 260 AddConnectionId(connection_id_); |
| 271 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 261 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
| 272 for (int packet_number = 1; packet_number < 101; ++packet_number) { | 262 for (int packet_number = 1; packet_number < 101; ++packet_number) { |
| 273 if ((packet_number & (packet_number - 1)) == 0) { | 263 if ((packet_number & (packet_number - 1)) == 0) { |
| 274 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) | 264 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) |
| 275 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 265 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 276 } | 266 } |
| 277 ProcessPacket(connection_id_, packet_number); | 267 ProcessPacket(connection_id_); |
| 278 // Send public reset with exponential back off. | 268 // Send public reset with exponential back off. |
| 279 if ((packet_number & (packet_number - 1)) == 0) { | 269 if ((packet_number & (packet_number - 1)) == 0) { |
| 280 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 270 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
| 281 &time_wait_list_manager_, packet_number)); | 271 &time_wait_list_manager_, packet_number)); |
| 282 } else { | 272 } else { |
| 283 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 273 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
| 284 &time_wait_list_manager_, packet_number)); | 274 &time_wait_list_manager_, packet_number)); |
| 285 } | 275 } |
| 286 } | 276 } |
| 287 } | 277 } |
| 288 | 278 |
| 289 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { | 279 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { |
| 290 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 280 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 291 AddStatelessConnectionId(connection_id_); | 281 AddStatelessConnectionId(connection_id_); |
| 292 const int kRandomSequenceNumber = 1; | |
| 293 | 282 |
| 294 EXPECT_CALL(writer_, | 283 EXPECT_CALL(writer_, |
| 295 WritePacket(_, _, server_address_.host(), client_address_, _)) | 284 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 296 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 285 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 297 | 286 |
| 298 ProcessPacket(connection_id_, kRandomSequenceNumber); | 287 ProcessPacket(connection_id_); |
| 299 } | 288 } |
| 300 | 289 |
| 301 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 290 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
| 302 const size_t kConnectionIdCount = 100; | 291 const size_t kConnectionIdCount = 100; |
| 303 const size_t kOldConnectionIdCount = 31; | 292 const size_t kOldConnectionIdCount = 31; |
| 304 | 293 |
| 305 // Add connection_ids such that their expiry time is time_wait_period_. | 294 // Add connection_ids such that their expiry time is time_wait_period_. |
| 306 epoll_server_.set_now_in_usec(0); | 295 epoll_server_.set_now_in_usec(0); |
| 307 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; | 296 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; |
| 308 ++connection_id) { | 297 ++connection_id) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { | 336 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { |
| 348 QuicConnectionId connection_id = 1; | 337 QuicConnectionId connection_id = 1; |
| 349 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 338 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
| 350 AddConnectionId(connection_id); | 339 AddConnectionId(connection_id); |
| 351 QuicPacketNumber packet_number = 234; | 340 QuicPacketNumber packet_number = 234; |
| 352 std::unique_ptr<QuicEncryptedPacket> packet( | 341 std::unique_ptr<QuicEncryptedPacket> packet( |
| 353 ConstructEncryptedPacket(connection_id, packet_number)); | 342 ConstructEncryptedPacket(connection_id, packet_number)); |
| 354 // Let first write through. | 343 // Let first write through. |
| 355 EXPECT_CALL(writer_, | 344 EXPECT_CALL(writer_, |
| 356 WritePacket(_, _, server_address_.host(), client_address_, _)) | 345 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 357 .With(Args<0, 1>(PublicResetPacketEq(connection_id, 0))) | 346 .With(Args<0, 1>(PublicResetPacketEq(connection_id))) |
| 358 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 347 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
| 359 ProcessPacket(connection_id, packet_number); | 348 ProcessPacket(connection_id); |
| 360 | 349 |
| 361 // write block for the next packet. | 350 // write block for the next packet. |
| 362 EXPECT_CALL(writer_, | 351 EXPECT_CALL(writer_, |
| 363 WritePacket(_, _, server_address_.host(), client_address_, _)) | 352 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 364 .With(Args<0, 1>(PublicResetPacketEq(connection_id, 0))) | 353 .With(Args<0, 1>(PublicResetPacketEq(connection_id))) |
| 365 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), | 354 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), |
| 366 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); | 355 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); |
| 367 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 356 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 368 ProcessPacket(connection_id, packet_number); | 357 ProcessPacket(connection_id); |
| 369 // 3rd packet. No public reset should be sent; | 358 // 3rd packet. No public reset should be sent; |
| 370 ProcessPacket(connection_id, packet_number); | 359 ProcessPacket(connection_id); |
| 371 | 360 |
| 372 // write packet should not be called since we are write blocked but the | 361 // write packet should not be called since we are write blocked but the |
| 373 // should be queued. | 362 // should be queued. |
| 374 QuicConnectionId other_connection_id = 2; | 363 QuicConnectionId other_connection_id = 2; |
| 375 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); | 364 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); |
| 376 AddConnectionId(other_connection_id); | 365 AddConnectionId(other_connection_id); |
| 377 QuicPacketNumber other_packet_number = 23423; | 366 QuicPacketNumber other_packet_number = 23423; |
| 378 std::unique_ptr<QuicEncryptedPacket> other_packet( | 367 std::unique_ptr<QuicEncryptedPacket> other_packet( |
| 379 ConstructEncryptedPacket(other_connection_id, other_packet_number)); | 368 ConstructEncryptedPacket(other_connection_id, other_packet_number)); |
| 380 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(0); | 369 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(0); |
| 381 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 370 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 382 ProcessPacket(other_connection_id, other_packet_number); | 371 ProcessPacket(other_connection_id); |
| 383 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); | 372 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); |
| 384 | 373 |
| 385 // Now expect all the write blocked public reset packets to be sent again. | 374 // Now expect all the write blocked public reset packets to be sent again. |
| 386 writer_is_blocked_ = false; | 375 writer_is_blocked_ = false; |
| 387 EXPECT_CALL(writer_, | 376 EXPECT_CALL(writer_, |
| 388 WritePacket(_, _, server_address_.host(), client_address_, _)) | 377 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 389 .With(Args<0, 1>(PublicResetPacketEq(connection_id, 0))) | 378 .With(Args<0, 1>(PublicResetPacketEq(connection_id))) |
| 390 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 379 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
| 391 EXPECT_CALL(writer_, | 380 EXPECT_CALL(writer_, |
| 392 WritePacket(_, _, server_address_.host(), client_address_, _)) | 381 WritePacket(_, _, server_address_.host(), client_address_, _)) |
| 393 .With(Args<0, 1>(PublicResetPacketEq(other_connection_id, 0))) | 382 .With(Args<0, 1>(PublicResetPacketEq(other_connection_id))) |
| 394 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); | 383 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); |
| 395 time_wait_list_manager_.OnCanWrite(); | 384 time_wait_list_manager_.OnCanWrite(); |
| 396 } | 385 } |
| 397 | 386 |
| 398 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { | 387 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { |
| 399 const int kConnectionId1 = 123; | 388 const int kConnectionId1 = 123; |
| 400 const int kConnectionId2 = 456; | 389 const int kConnectionId2 = 456; |
| 401 const int kConnectionId3 = 789; | 390 const int kConnectionId3 = 789; |
| 402 | 391 |
| 403 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId1)); | 392 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(kConnectionId1)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 AddConnectionId(connection_id_, QuicVersionMax(), | 424 AddConnectionId(connection_id_, QuicVersionMax(), |
| 436 /*connection_rejected_statelessly=*/false, | 425 /*connection_rejected_statelessly=*/false, |
| 437 &termination_packets); | 426 &termination_packets); |
| 438 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 427 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 439 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 428 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
| 440 | 429 |
| 441 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 430 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
| 442 server_address_.host(), client_address_, _)) | 431 server_address_.host(), client_address_, _)) |
| 443 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 432 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 444 | 433 |
| 445 const int kRandomSequenceNumber = 1; | 434 ProcessPacket(connection_id_); |
| 446 ProcessPacket(connection_id_, kRandomSequenceNumber); | |
| 447 | 435 |
| 448 const QuicTime::Delta time_wait_period = | 436 const QuicTime::Delta time_wait_period = |
| 449 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 437 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
| 450 | 438 |
| 451 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 439 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
| 452 // Now set the current time as time_wait_period + offset usecs. | 440 // Now set the current time as time_wait_period + offset usecs. |
| 453 epoll_server_.set_now_in_usec((time_wait_period + offset).ToMicroseconds()); | 441 epoll_server_.set_now_in_usec((time_wait_period + offset).ToMicroseconds()); |
| 454 // After the connection_ids are cleaned up, check the next alarm interval. | 442 // After the connection_ids are cleaned up, check the next alarm interval. |
| 455 int64_t next_alarm_time = | 443 int64_t next_alarm_time = |
| 456 epoll_server_.ApproximateNowInUsec() + time_wait_period.ToMicroseconds(); | 444 epoll_server_.ApproximateNowInUsec() + time_wait_period.ToMicroseconds(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections), | 511 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections), |
| 524 time_wait_list_manager_.num_connections()); | 512 time_wait_list_manager_.num_connections()); |
| 525 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); | 513 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
| 526 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); | 514 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
| 527 } | 515 } |
| 528 } | 516 } |
| 529 | 517 |
| 530 } // namespace | 518 } // namespace |
| 531 } // namespace test | 519 } // namespace test |
| 532 } // namespace net | 520 } // namespace net |
| OLD | NEW |