| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
| 14 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 14 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 15 #include "net/quic/core/crypto/quic_random.h" | 15 #include "net/quic/core/crypto/quic_random.h" |
| 16 #include "net/quic/core/quic_crypto_stream.h" | 16 #include "net/quic/core/quic_crypto_stream.h" |
| 17 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
| 18 #include "net/quic/core/quic_utils.h" | 18 #include "net/quic/core/quic_utils.h" |
| 19 #include "net/quic/platform/api/quic_str_cat.h" |
| 19 #include "net/quic/test_tools/crypto_test_utils.h" | 20 #include "net/quic/test_tools/crypto_test_utils.h" |
| 20 #include "net/quic/test_tools/fake_proof_source.h" | 21 #include "net/quic/test_tools/fake_proof_source.h" |
| 21 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" | 22 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" |
| 22 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 23 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 23 #include "net/quic/test_tools/quic_test_utils.h" | 24 #include "net/quic/test_tools/quic_test_utils.h" |
| 24 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h" | 25 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h" |
| 25 #include "net/test/gtest_util.h" | 26 #include "net/test/gtest_util.h" |
| 26 #include "net/tools/epoll_server/epoll_server.h" | 27 #include "net/tools/epoll_server/epoll_server.h" |
| 27 #include "net/tools/quic/chlo_extractor.h" | 28 #include "net/tools/quic/chlo_extractor.h" |
| 28 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 29 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| (...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 InSequence s; | 1201 InSequence s; |
| 1201 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1202 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1202 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1203 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1203 QuicConnectionId conn_id = 1; | 1204 QuicConnectionId conn_id = 1; |
| 1204 // A bunch of non-CHLO should be buffered upon arrival, and the first one | 1205 // A bunch of non-CHLO should be buffered upon arrival, and the first one |
| 1205 // should trigger ShouldCreateOrBufferPacketForConnection(). | 1206 // should trigger ShouldCreateOrBufferPacketForConnection(). |
| 1206 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)) | 1207 EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id)) |
| 1207 .Times(1); | 1208 .Times(1); |
| 1208 for (size_t i = 1; i <= kDefaultMaxUndecryptablePackets + 1; ++i) { | 1209 for (size_t i = 1; i <= kDefaultMaxUndecryptablePackets + 1; ++i) { |
| 1209 ProcessPacket(client_address, conn_id, true, false, | 1210 ProcessPacket(client_address, conn_id, true, false, |
| 1210 "data packet " + IntToString(i + 1), | 1211 QuicStrCat("data packet ", i + 1), PACKET_8BYTE_CONNECTION_ID, |
| 1211 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 1212 PACKET_6BYTE_PACKET_NUMBER, kDefaultPathId, |
| 1212 kDefaultPathId, | |
| 1213 /*packet_number=*/i + 1); | 1213 /*packet_number=*/i + 1); |
| 1214 } | 1214 } |
| 1215 EXPECT_EQ(0u, dispatcher_->session_map().size()) | 1215 EXPECT_EQ(0u, dispatcher_->session_map().size()) |
| 1216 << "No session should be created before CHLO arrives."; | 1216 << "No session should be created before CHLO arrives."; |
| 1217 | 1217 |
| 1218 // Pop out the last packet as it is also be dropped by the store. | 1218 // Pop out the last packet as it is also be dropped by the store. |
| 1219 data_connection_map_[conn_id].pop_back(); | 1219 data_connection_map_[conn_id].pop_back(); |
| 1220 // When CHLO arrives, a new session should be created, and all packets | 1220 // When CHLO arrives, a new session should be created, and all packets |
| 1221 // buffered should be delivered to the session. | 1221 // buffered should be delivered to the session. |
| 1222 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) | 1222 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 } else { | 1255 } else { |
| 1256 if (i <= kNumConnections - 1) { | 1256 if (i <= kNumConnections - 1) { |
| 1257 // As they are on different connection, they should trigger | 1257 // As they are on different connection, they should trigger |
| 1258 // ShouldCreateOrBufferPacketForConnection(). The last packet should be | 1258 // ShouldCreateOrBufferPacketForConnection(). The last packet should be |
| 1259 // dropped. | 1259 // dropped. |
| 1260 EXPECT_CALL(*dispatcher_, | 1260 EXPECT_CALL(*dispatcher_, |
| 1261 ShouldCreateOrBufferPacketForConnection(conn_id)); | 1261 ShouldCreateOrBufferPacketForConnection(conn_id)); |
| 1262 } | 1262 } |
| 1263 } | 1263 } |
| 1264 ProcessPacket(client_address, conn_id, true, false, | 1264 ProcessPacket(client_address, conn_id, true, false, |
| 1265 "data packet on connection " + IntToString(i), | 1265 QuicStrCat("data packet on connection ", i), |
| 1266 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 1266 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
| 1267 kDefaultPathId, | 1267 kDefaultPathId, |
| 1268 /*packet_number=*/2); | 1268 /*packet_number=*/2); |
| 1269 } | 1269 } |
| 1270 | 1270 |
| 1271 // Pop out the packet on last connection as it shouldn't be enqueued in store | 1271 // Pop out the packet on last connection as it shouldn't be enqueued in store |
| 1272 // as well. | 1272 // as well. |
| 1273 data_connection_map_[kNumConnections].pop_front(); | 1273 data_connection_map_[kNumConnections].pop_front(); |
| 1274 | 1274 |
| 1275 // Reset session creation counter to ensure processing CHLO can always | 1275 // Reset session creation counter to ensure processing CHLO can always |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 // Tests that a retransmitted CHLO arrives after a connection for the | 1333 // Tests that a retransmitted CHLO arrives after a connection for the |
| 1334 // CHLO has been created. | 1334 // CHLO has been created. |
| 1335 TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) { | 1335 TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) { |
| 1336 InSequence s; | 1336 InSequence s; |
| 1337 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1337 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1338 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1338 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1339 QuicConnectionId conn_id = 1; | 1339 QuicConnectionId conn_id = 1; |
| 1340 ProcessPacket(client_address, conn_id, true, false, | 1340 ProcessPacket(client_address, conn_id, true, false, |
| 1341 "data packet " + IntToString(2), PACKET_8BYTE_CONNECTION_ID, | 1341 QuicStrCat("data packet ", 2), PACKET_8BYTE_CONNECTION_ID, |
| 1342 PACKET_6BYTE_PACKET_NUMBER, kDefaultPathId, | 1342 PACKET_6BYTE_PACKET_NUMBER, kDefaultPathId, |
| 1343 /*packet_number=*/2); | 1343 /*packet_number=*/2); |
| 1344 | 1344 |
| 1345 // When CHLO arrives, a new session should be created, and all packets | 1345 // When CHLO arrives, a new session should be created, and all packets |
| 1346 // buffered should be delivered to the session. | 1346 // buffered should be delivered to the session. |
| 1347 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) | 1347 EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address)) |
| 1348 .Times(1) // Only triggered by 1st CHLO. | 1348 .Times(1) // Only triggered by 1st CHLO. |
| 1349 .WillOnce(testing::Return(CreateSession( | 1349 .WillOnce(testing::Return(CreateSession( |
| 1350 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, | 1350 dispatcher_.get(), config_, conn_id, client_address, &mock_helper_, |
| 1351 &mock_alarm_factory_, &crypto_config_, | 1351 &mock_alarm_factory_, &crypto_config_, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1366 InSequence s; | 1366 InSequence s; |
| 1367 CreateTimeWaitListManager(); | 1367 CreateTimeWaitListManager(); |
| 1368 QuicBufferedPacketStore* store = | 1368 QuicBufferedPacketStore* store = |
| 1369 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); | 1369 QuicDispatcherPeer::GetBufferedPackets(dispatcher_.get()); |
| 1370 QuicBufferedPacketStorePeer::set_clock(store, mock_helper_.GetClock()); | 1370 QuicBufferedPacketStorePeer::set_clock(store, mock_helper_.GetClock()); |
| 1371 | 1371 |
| 1372 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); | 1372 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); |
| 1373 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); | 1373 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); |
| 1374 QuicConnectionId conn_id = 1; | 1374 QuicConnectionId conn_id = 1; |
| 1375 ProcessPacket(client_address, conn_id, true, false, | 1375 ProcessPacket(client_address, conn_id, true, false, |
| 1376 "data packet " + IntToString(2), PACKET_8BYTE_CONNECTION_ID, | 1376 QuicStrCat("data packet ", 2), PACKET_8BYTE_CONNECTION_ID, |
| 1377 PACKET_6BYTE_PACKET_NUMBER, kDefaultPathId, | 1377 PACKET_6BYTE_PACKET_NUMBER, kDefaultPathId, |
| 1378 /*packet_number=*/2); | 1378 /*packet_number=*/2); |
| 1379 | 1379 |
| 1380 mock_helper_.AdvanceTime( | 1380 mock_helper_.AdvanceTime( |
| 1381 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); | 1381 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs)); |
| 1382 QuicAlarm* alarm = QuicBufferedPacketStorePeer::expiration_alarm(store); | 1382 QuicAlarm* alarm = QuicBufferedPacketStorePeer::expiration_alarm(store); |
| 1383 // Cancel alarm as if it had been fired. | 1383 // Cancel alarm as if it had been fired. |
| 1384 alarm->Cancel(); | 1384 alarm->Cancel(); |
| 1385 store->OnExpirationTimeout(); | 1385 store->OnExpirationTimeout(); |
| 1386 // New arrived CHLO will be dropped because this connection is in time wait | 1386 // New arrived CHLO will be dropped because this connection is in time wait |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 check.Call(2); | 2082 check.Call(2); |
| 2083 GetFakeProofSource()->InvokePendingCallback(0); | 2083 GetFakeProofSource()->InvokePendingCallback(0); |
| 2084 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 2084 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 2085 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 2085 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 2086 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 2086 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| 2087 } | 2087 } |
| 2088 | 2088 |
| 2089 } // namespace | 2089 } // namespace |
| 2090 } // namespace test | 2090 } // namespace test |
| 2091 } // namespace net | 2091 } // namespace net |
| OLD | NEW |