| 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 <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2419 } | 2419 } |
| 2420 | 2420 |
| 2421 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { | 2421 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { |
| 2422 // Block the connection to queue the packet. | 2422 // Block the connection to queue the packet. |
| 2423 BlockOnNextWrite(); | 2423 BlockOnNextWrite(); |
| 2424 | 2424 |
| 2425 QuicStreamId stream_id = 2; | 2425 QuicStreamId stream_id = 2; |
| 2426 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); | 2426 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); |
| 2427 | 2427 |
| 2428 // Now that there is a queued packet, reset the stream. | 2428 // Now that there is a queued packet, reset the stream. |
| 2429 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); | 2429 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); |
| 2430 | 2430 |
| 2431 // Unblock the connection and verify that only the RST_STREAM is sent. | 2431 // Unblock the connection and verify that only the RST_STREAM is sent. |
| 2432 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2432 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2433 writer_->SetWritable(); | 2433 writer_->SetWritable(); |
| 2434 connection_.OnCanWrite(); | 2434 connection_.OnCanWrite(); |
| 2435 EXPECT_EQ(1u, writer_->frame_count()); | 2435 EXPECT_EQ(1u, writer_->frame_count()); |
| 2436 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); | 2436 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2437 } | 2437 } |
| 2438 | 2438 |
| 2439 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) { |
| 2440 // Block the connection to queue the packet. |
| 2441 BlockOnNextWrite(); |
| 2442 |
| 2443 QuicStreamId stream_id = 2; |
| 2444 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); |
| 2445 |
| 2446 // Now that there is a queued packet, reset the stream. |
| 2447 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2448 |
| 2449 // Unblock the connection and verify that the RST_STREAM is sent and the data |
| 2450 // packet is sent on QUIC_VERSION_29 or later versions. |
| 2451 if (version() > QUIC_VERSION_28) { |
| 2452 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2453 .Times(AtLeast(2)); |
| 2454 } else { |
| 2455 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2456 } |
| 2457 writer_->SetWritable(); |
| 2458 connection_.OnCanWrite(); |
| 2459 EXPECT_EQ(1u, writer_->frame_count()); |
| 2460 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2461 } |
| 2462 |
| 2439 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { | 2463 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { |
| 2440 QuicStreamId stream_id = 2; | 2464 QuicStreamId stream_id = 2; |
| 2441 QuicPacketNumber last_packet; | 2465 QuicPacketNumber last_packet; |
| 2442 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); | 2466 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2443 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); | 2467 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2444 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); | 2468 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); |
| 2445 | 2469 |
| 2446 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2470 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2447 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); | 2471 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); |
| 2448 | 2472 |
| 2449 // Lose a packet and ensure it does not trigger retransmission. | 2473 // Lose a packet and ensure it does not trigger retransmission. |
| 2450 QuicAckFrame nack_two = InitAckFrame(last_packet); | 2474 QuicAckFrame nack_two = InitAckFrame(last_packet); |
| 2451 NackPacket(last_packet - 1, &nack_two); | 2475 NackPacket(last_packet - 1, &nack_two); |
| 2452 PacketNumberSet lost_packets; | 2476 PacketNumberSet lost_packets; |
| 2453 lost_packets.insert(last_packet - 1); | 2477 lost_packets.insert(last_packet - 1); |
| 2454 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2478 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2455 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 2479 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2456 .WillOnce(Return(lost_packets)); | 2480 .WillOnce(Return(lost_packets)); |
| 2457 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2481 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2458 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 2482 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2459 ProcessAckPacket(&nack_two); | 2483 ProcessAckPacket(&nack_two); |
| 2460 } | 2484 } |
| 2461 | 2485 |
| 2486 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) { |
| 2487 QuicStreamId stream_id = 2; |
| 2488 QuicPacketNumber last_packet; |
| 2489 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2490 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2491 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); |
| 2492 |
| 2493 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2494 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2495 |
| 2496 // Lose a packet, ensure it triggers retransmission on QUIC_VERSION_29 |
| 2497 // or later versions. |
| 2498 QuicAckFrame nack_two = InitAckFrame(last_packet); |
| 2499 NackPacket(last_packet - 1, &nack_two); |
| 2500 PacketNumberSet lost_packets; |
| 2501 lost_packets.insert(last_packet - 1); |
| 2502 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2503 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2504 .WillOnce(Return(lost_packets)); |
| 2505 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2506 if (version() > QUIC_VERSION_28) { |
| 2507 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2508 .Times(AtLeast(1)); |
| 2509 } else { |
| 2510 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2511 } |
| 2512 ProcessAckPacket(&nack_two); |
| 2513 } |
| 2514 |
| 2462 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { | 2515 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { |
| 2463 QuicStreamId stream_id = 2; | 2516 QuicStreamId stream_id = 2; |
| 2464 QuicPacketNumber last_packet; | 2517 QuicPacketNumber last_packet; |
| 2465 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); | 2518 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2466 | 2519 |
| 2467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2520 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2468 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); | 2521 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); |
| 2469 | 2522 |
| 2470 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. | 2523 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. |
| 2471 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2524 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2472 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2525 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2473 connection_.GetRetransmissionAlarm()->Fire(); | 2526 connection_.GetRetransmissionAlarm()->Fire(); |
| 2474 EXPECT_EQ(1u, writer_->frame_count()); | 2527 EXPECT_EQ(1u, writer_->frame_count()); |
| 2475 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); | 2528 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2476 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); | 2529 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2477 } | 2530 } |
| 2478 | 2531 |
| 2532 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { |
| 2533 QuicStreamId stream_id = 2; |
| 2534 QuicPacketNumber last_packet; |
| 2535 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2536 |
| 2537 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2538 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2539 |
| 2540 // Fire the RTO and verify that the RST_STREAM is resent, the stream data |
| 2541 // is only sent on QUIC_VERSION_29 or later versions. |
| 2542 if (version() > QUIC_VERSION_28) { |
| 2543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2544 .Times(AtLeast(2)); |
| 2545 } else { |
| 2546 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2547 } |
| 2548 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2549 connection_.GetRetransmissionAlarm()->Fire(); |
| 2550 EXPECT_EQ(1u, writer_->frame_count()); |
| 2551 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2552 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2553 } |
| 2554 |
| 2479 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { | 2555 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { |
| 2480 QuicStreamId stream_id = 2; | 2556 QuicStreamId stream_id = 2; |
| 2481 QuicPacketNumber last_packet; | 2557 QuicPacketNumber last_packet; |
| 2482 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); | 2558 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2483 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); | 2559 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2484 BlockOnNextWrite(); | 2560 BlockOnNextWrite(); |
| 2485 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); | 2561 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); |
| 2486 | 2562 |
| 2487 // Lose a packet which will trigger a pending retransmission. | 2563 // Lose a packet which will trigger a pending retransmission. |
| 2488 QuicAckFrame ack = InitAckFrame(last_packet); | 2564 QuicAckFrame ack = InitAckFrame(last_packet); |
| 2489 NackPacket(last_packet - 1, &ack); | 2565 NackPacket(last_packet - 1, &ack); |
| 2490 PacketNumberSet lost_packets; | 2566 PacketNumberSet lost_packets; |
| 2491 lost_packets.insert(last_packet - 1); | 2567 lost_packets.insert(last_packet - 1); |
| 2492 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2568 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2493 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 2569 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2494 .WillOnce(Return(lost_packets)); | 2570 .WillOnce(Return(lost_packets)); |
| 2495 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2571 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2496 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 2572 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2497 ProcessAckPacket(&ack); | 2573 ProcessAckPacket(&ack); |
| 2498 | 2574 |
| 2499 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); | 2575 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); |
| 2500 | 2576 |
| 2501 // Unblock the connection and verify that the RST_STREAM is sent but not the | 2577 // Unblock the connection and verify that the RST_STREAM is sent but not the |
| 2502 // second data packet nor a retransmit. | 2578 // second data packet nor a retransmit. |
| 2503 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2579 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2504 writer_->SetWritable(); | 2580 writer_->SetWritable(); |
| 2505 connection_.OnCanWrite(); | 2581 connection_.OnCanWrite(); |
| 2506 EXPECT_EQ(1u, writer_->frame_count()); | 2582 EXPECT_EQ(1u, writer_->frame_count()); |
| 2507 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); | 2583 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2508 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); | 2584 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2509 } | 2585 } |
| 2510 | 2586 |
| 2587 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) { |
| 2588 QuicStreamId stream_id = 2; |
| 2589 QuicPacketNumber last_packet; |
| 2590 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2591 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2592 BlockOnNextWrite(); |
| 2593 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); |
| 2594 |
| 2595 // Lose a packet which will trigger a pending retransmission. |
| 2596 QuicAckFrame ack = InitAckFrame(last_packet); |
| 2597 NackPacket(last_packet - 1, &ack); |
| 2598 PacketNumberSet lost_packets; |
| 2599 lost_packets.insert(last_packet - 1); |
| 2600 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2601 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2602 .WillOnce(Return(lost_packets)); |
| 2603 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2604 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2605 ProcessAckPacket(&ack); |
| 2606 |
| 2607 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2608 |
| 2609 // Unblock the connection and verify that the RST_STREAM is sent and the |
| 2610 // second data packet or a retransmit is only sent on QUIC_VERSION_29 or |
| 2611 // later versions. |
| 2612 if (version() > QUIC_VERSION_28) { |
| 2613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2614 .Times(AtLeast(2)); |
| 2615 } else { |
| 2616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2617 } |
| 2618 writer_->SetWritable(); |
| 2619 connection_.OnCanWrite(); |
| 2620 EXPECT_EQ(1u, writer_->frame_count()); |
| 2621 if (version() > QUIC_VERSION_28) { |
| 2622 EXPECT_EQ(0u, writer_->rst_stream_frames().size()); |
| 2623 } else { |
| 2624 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2625 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2626 } |
| 2627 } |
| 2628 |
| 2511 TEST_P(QuicConnectionTest, DiscardRetransmit) { | 2629 TEST_P(QuicConnectionTest, DiscardRetransmit) { |
| 2512 QuicPacketNumber last_packet; | 2630 QuicPacketNumber last_packet; |
| 2513 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 2631 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 2514 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 | 2632 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 2515 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 | 2633 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 2516 | 2634 |
| 2517 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2635 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2518 | 2636 |
| 2519 // Instigate a loss with an ack. | 2637 // Instigate a loss with an ack. |
| 2520 QuicAckFrame nack_two = InitAckFrame(3); | 2638 QuicAckFrame nack_two = InitAckFrame(3); |
| (...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4544 QuicEncryptedPacket(buffer, encryped_length, false)); | 4662 QuicEncryptedPacket(buffer, encryped_length, false)); |
| 4545 EXPECT_EQ(0u, writer_->last_packet_size()); | 4663 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 4546 EXPECT_FALSE(connection_.HasQueuedData()); | 4664 EXPECT_FALSE(connection_.HasQueuedData()); |
| 4547 } | 4665 } |
| 4548 | 4666 |
| 4549 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4667 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 4550 // Start out with some unsupported version. | 4668 // Start out with some unsupported version. |
| 4551 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 4669 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
| 4552 QUIC_VERSION_UNSUPPORTED); | 4670 QUIC_VERSION_UNSUPPORTED); |
| 4553 | 4671 |
| 4554 QuicPacketHeader header; | |
| 4555 header.public_header.connection_id = connection_id_; | |
| 4556 header.public_header.version_flag = true; | |
| 4557 header.packet_number = 12; | |
| 4558 | |
| 4559 QuicVersionVector supported_versions; | |
| 4560 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 4561 supported_versions.push_back(kSupportedQuicVersions[i]); | |
| 4562 } | |
| 4563 | |
| 4564 // Send a version negotiation packet. | 4672 // Send a version negotiation packet. |
| 4565 scoped_ptr<QuicEncryptedPacket> encrypted( | 4673 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 4566 framer_.BuildVersionNegotiationPacket( | 4674 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4567 header.public_header, supported_versions)); | 4675 QuicSupportedVersions())); |
| 4568 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4676 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
| 4569 | 4677 |
| 4570 // Now force another packet. The connection should transition into | 4678 // Now force another packet. The connection should transition into |
| 4571 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4679 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
| 4680 QuicPacketHeader header; |
| 4681 header.public_header.connection_id = connection_id_; |
| 4682 header.packet_number = 12; |
| 4572 header.public_header.version_flag = false; | 4683 header.public_header.version_flag = false; |
| 4573 QuicFrames frames; | 4684 QuicFrames frames; |
| 4574 frames.push_back(QuicFrame(&frame1_)); | 4685 frames.push_back(QuicFrame(&frame1_)); |
| 4575 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4686 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
| 4576 char buffer[kMaxPacketSize]; | 4687 char buffer[kMaxPacketSize]; |
| 4577 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, | 4688 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
| 4578 buffer, kMaxPacketSize); | 4689 buffer, kMaxPacketSize); |
| 4579 ASSERT_NE(0u, encrypted_length); | 4690 ASSERT_NE(0u, encrypted_length); |
| 4580 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4691 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4581 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4692 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4582 connection_.ProcessUdpPacket( | 4693 connection_.ProcessUdpPacket( |
| 4583 kSelfAddress, kPeerAddress, | 4694 kSelfAddress, kPeerAddress, |
| 4584 QuicEncryptedPacket(buffer, encrypted_length, false)); | 4695 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 4585 | 4696 |
| 4586 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); | 4697 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); |
| 4587 } | 4698 } |
| 4588 | 4699 |
| 4589 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4700 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
| 4590 QuicPacketHeader header; | |
| 4591 header.public_header.connection_id = connection_id_; | |
| 4592 header.public_header.version_flag = true; | |
| 4593 header.packet_number = 12; | |
| 4594 | |
| 4595 QuicVersionVector supported_versions; | |
| 4596 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 4597 supported_versions.push_back(kSupportedQuicVersions[i]); | |
| 4598 } | |
| 4599 | |
| 4600 // Send a version negotiation packet with the version the client started with. | 4701 // Send a version negotiation packet with the version the client started with. |
| 4601 // It should be rejected. | 4702 // It should be rejected. |
| 4602 EXPECT_CALL(visitor_, | 4703 EXPECT_CALL(visitor_, |
| 4603 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 4704 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
| 4604 false)); | 4705 false)); |
| 4605 scoped_ptr<QuicEncryptedPacket> encrypted( | 4706 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 4606 framer_.BuildVersionNegotiationPacket( | 4707 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4607 header.public_header, supported_versions)); | 4708 QuicSupportedVersions())); |
| 4608 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4709 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
| 4609 } | 4710 } |
| 4610 | 4711 |
| 4611 TEST_P(QuicConnectionTest, CheckSendStats) { | 4712 TEST_P(QuicConnectionTest, CheckSendStats) { |
| 4612 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4713 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4613 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4714 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
| 4614 size_t first_packet_size = writer_->last_packet_size(); | 4715 size_t first_packet_size = writer_->last_packet_size(); |
| 4615 | 4716 |
| 4616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4717 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4617 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); | 4718 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5144 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 5245 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 5145 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 5246 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
| 5146 EXPECT_TRUE(connection_.goaway_sent()); | 5247 EXPECT_TRUE(connection_.goaway_sent()); |
| 5147 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 5248 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 5148 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 5249 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
| 5149 } | 5250 } |
| 5150 | 5251 |
| 5151 } // namespace | 5252 } // namespace |
| 5152 } // namespace test | 5253 } // namespace test |
| 5153 } // namespace net | 5254 } // namespace net |
| OLD | NEW |