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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 | 133 |
134 MockConnection* connection2() { | 134 MockConnection* connection2() { |
135 return reinterpret_cast<MockConnection*>(session2_->connection()); | 135 return reinterpret_cast<MockConnection*>(session2_->connection()); |
136 } | 136 } |
137 | 137 |
138 void ProcessPacket(IPEndPoint client_address, | 138 void ProcessPacket(IPEndPoint client_address, |
139 QuicConnectionId connection_id, | 139 QuicConnectionId connection_id, |
140 bool has_version_flag, | 140 bool has_version_flag, |
141 const string& data) { | 141 const string& data) { |
| 142 ProcessPacket(client_address, connection_id, has_version_flag, data, |
| 143 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_SEQUENCE_NUMBER); |
| 144 } |
| 145 |
| 146 void ProcessPacket(IPEndPoint client_address, |
| 147 QuicConnectionId connection_id, |
| 148 bool has_version_flag, |
| 149 const string& data, |
| 150 QuicConnectionIdLength connection_id_length, |
| 151 QuicSequenceNumberLength sequence_number_length) { |
142 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 152 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
143 connection_id, has_version_flag, false, 1, data)); | 153 connection_id, has_version_flag, false, 1, data, connection_id_length, |
| 154 sequence_number_length)); |
144 data_ = string(packet->data(), packet->length()); | 155 data_ = string(packet->data(), packet->length()); |
145 dispatcher_.ProcessPacket(server_address_, client_address, *packet); | 156 dispatcher_.ProcessPacket(server_address_, client_address, *packet); |
146 } | 157 } |
147 | 158 |
148 void ValidatePacket(const QuicEncryptedPacket& packet) { | 159 void ValidatePacket(const QuicEncryptedPacket& packet) { |
149 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); | 160 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); |
150 EXPECT_EQ(data_, packet.AsStringPiece()); | 161 EXPECT_EQ(data_, packet.AsStringPiece()); |
151 } | 162 } |
152 | 163 |
153 void CreateTimeWaitListManager() { | 164 void CreateTimeWaitListManager() { |
154 time_wait_list_manager_ = new MockTimeWaitListManager( | 165 time_wait_list_manager_ = new MockTimeWaitListManager( |
155 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_); | 166 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_); |
156 // dispatcher takes the ownership of time_wait_list_manager. | 167 // dispatcher_ takes the ownership of time_wait_list_manager_. |
157 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, | 168 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, |
158 time_wait_list_manager_); | 169 time_wait_list_manager_); |
159 } | 170 } |
160 | 171 |
161 EpollServer eps_; | 172 EpollServer eps_; |
162 QuicConfig config_; | 173 QuicConfig config_; |
163 QuicCryptoServerConfig crypto_config_; | 174 QuicCryptoServerConfig crypto_config_; |
164 IPEndPoint server_address_; | 175 IPEndPoint server_address_; |
165 TestDispatcher dispatcher_; | 176 TestDispatcher dispatcher_; |
166 MockTimeWaitListManager* time_wait_list_manager_; | 177 MockTimeWaitListManager* time_wait_list_manager_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { | 263 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { |
253 CreateTimeWaitListManager(); | 264 CreateTimeWaitListManager(); |
254 | 265 |
255 IPEndPoint client_address(net::test::Loopback4(), 1); | 266 IPEndPoint client_address(net::test::Loopback4(), 1); |
256 QuicConnectionId connection_id = 1; | 267 QuicConnectionId connection_id = 1; |
257 // Dispatcher forwards all packets for this connection_id to the time wait | 268 // Dispatcher forwards all packets for this connection_id to the time wait |
258 // list manager. | 269 // list manager. |
259 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); | 270 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); |
260 EXPECT_CALL(*time_wait_list_manager_, | 271 EXPECT_CALL(*time_wait_list_manager_, |
261 ProcessPacket(_, _, connection_id, _, _)).Times(1); | 272 ProcessPacket(_, _, connection_id, _, _)).Times(1); |
262 string data = "foo"; | 273 ProcessPacket(client_address, connection_id, false, "data"); |
263 ProcessPacket(client_address, connection_id, false, "foo"); | |
264 } | 274 } |
265 | 275 |
266 TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) { | 276 TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) { |
267 CreateTimeWaitListManager(); | 277 CreateTimeWaitListManager(); |
268 | 278 |
269 IPEndPoint client_address(net::test::Loopback4(), 0); | 279 IPEndPoint client_address(net::test::Loopback4(), 0); |
270 IPAddressNumber any4; | 280 IPAddressNumber any4; |
271 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); | 281 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); |
272 server_address_ = IPEndPoint(any4, 5); | 282 server_address_ = IPEndPoint(any4, 5); |
273 | 283 |
| 284 // dispatcher_ should drop this packet. |
274 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0); | 285 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0); |
275 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); | 286 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); |
276 ProcessPacket(client_address, 1, true, "foo"); | 287 ProcessPacket(client_address, 1, true, "foo"); |
277 EXPECT_EQ(client_address, dispatcher_.current_client_address()); | 288 EXPECT_EQ(client_address, dispatcher_.current_client_address()); |
278 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); | 289 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); |
279 } | 290 } |
280 | 291 |
281 class BlockingWriter : public QuicPacketWriterWrapper { | 292 class BlockingWriter : public QuicPacketWriterWrapper { |
282 public: | 293 public: |
283 BlockingWriter() : write_blocked_(false) {} | 294 BlockingWriter() : write_blocked_(false) {} |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // And we'll resume where we left off when we get another call. | 480 // And we'll resume where we left off when we get another call. |
470 EXPECT_CALL(*connection2(), OnCanWrite()); | 481 EXPECT_CALL(*connection2(), OnCanWrite()); |
471 dispatcher_.OnCanWrite(); | 482 dispatcher_.OnCanWrite(); |
472 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 483 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
473 } | 484 } |
474 | 485 |
475 } // namespace | 486 } // namespace |
476 } // namespace test | 487 } // namespace test |
477 } // namespace tools | 488 } // namespace tools |
478 } // namespace net | 489 } // namespace net |
OLD | NEW |