diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-13 21:41:06 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-13 21:41:06 +0000 |
commit | 044ac2b9432c93438a9b175ebee5c30ff5ab4b87 (patch) | |
tree | d015f811de4beba3835fd08de02c7178061577bd /net | |
parent | f1cb05bdd54e0c3a6d7b85c7ac0d810f5aa7ef39 (diff) | |
download | chromium_src-044ac2b9432c93438a9b175ebee5c30ff5ab4b87.zip chromium_src-044ac2b9432c93438a9b175ebee5c30ff5ab4b87.tar.gz chromium_src-044ac2b9432c93438a9b175ebee5c30ff5ab4b87.tar.bz2 |
Clean up a whole raft of differences in QUIC code between the internal and Chrome.
Review URL: https://codereview.chromium.org/11360185
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167477 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
33 files changed, 257 insertions, 308 deletions
diff --git a/net/quic/congestion_control/fix_rate_test.cc b/net/quic/congestion_control/fix_rate_test.cc index 2a5bcc7..07cfb0e 100644 --- a/net/quic/congestion_control/fix_rate_test.cc +++ b/net/quic/congestion_control/fix_rate_test.cc @@ -10,7 +10,6 @@ #include "net/quic/congestion_control/fix_rate_sender.h" #include "net/quic/test_tools/mock_clock.h" #include "net/quic/quic_protocol.h" -#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { @@ -50,7 +49,7 @@ TEST_F(FixRateTest, SenderAPI) { sender_->OnIncomingCongestionInfo(info); EXPECT_EQ(300000, sender_->BandwidthEstimate()); EXPECT_TRUE(sender_->TimeUntilSend(false).IsZero()); - EXPECT_EQ(kMaxPacketSize * 2u, sender_->AvailableCongestionWindow()); + EXPECT_EQ(kMaxPacketSize * 2, sender_->AvailableCongestionWindow()); sender_->SentPacket(1, kMaxPacketSize, false); EXPECT_EQ(3000u - kMaxPacketSize, sender_->AvailableCongestionWindow()); EXPECT_TRUE(sender_->TimeUntilSend(false).IsZero()); diff --git a/net/quic/congestion_control/leaky_bucket.h b/net/quic/congestion_control/leaky_bucket.h index 4dea418..0ea8bc7 100644 --- a/net/quic/congestion_control/leaky_bucket.h +++ b/net/quic/congestion_control/leaky_bucket.h @@ -7,8 +7,8 @@ // the buffer. // See http://en.wikipedia.org/wiki/Leaky_bucket for more details. -#ifndef GFE_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ -#define GFE_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ +#ifndef NET_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ +#define NET_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ #include "base/basictypes.h" #include "net/base/net_export.h" @@ -45,4 +45,4 @@ class NET_EXPORT_PRIVATE LeakyBucket { } // namespace net -#endif // GFE_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ +#endif // NET_QUIC_CONGESTION_CONTROL_LEAKY_BUCKET_H_ diff --git a/net/quic/congestion_control/leaky_bucket_test.cc b/net/quic/congestion_control/leaky_bucket_test.cc index 9851569..7035300 100644 --- a/net/quic/congestion_control/leaky_bucket_test.cc +++ b/net/quic/congestion_control/leaky_bucket_test.cc @@ -6,7 +6,6 @@ #include "base/memory/scoped_ptr.h" #include "net/quic/congestion_control/leaky_bucket.h" #include "net/quic/test_tools/mock_clock.h" -#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { diff --git a/net/quic/congestion_control/paced_sender.cc b/net/quic/congestion_control/paced_sender.cc index 127cdb2..38419d0 100644 --- a/net/quic/congestion_control/paced_sender.cc +++ b/net/quic/congestion_control/paced_sender.cc @@ -30,20 +30,20 @@ void PacedSender::SentPacket(size_t bytes) { } QuicTime::Delta PacedSender::TimeUntilSend(QuicTime::Delta time_until_send) { - if (time_until_send.ToMicroseconds() < kMaxSchedulingDelayUs) { - // Pace the data. - size_t pacing_window = kMaxSchedulingDelayUs * pace_in_bytes_per_s_ / - base::Time::kMicrosecondsPerSecond; - size_t min_window_size = kMinPacketBurstSize * kMaxPacketSize; - pacing_window = std::max(pacing_window, min_window_size); + if (time_until_send.ToMicroseconds() >= kMaxSchedulingDelayUs) { + return time_until_send; + } + // Pace the data. + size_t pacing_window = kMaxSchedulingDelayUs * pace_in_bytes_per_s_ / + base::Time::kMicrosecondsPerSecond; + size_t min_window_size = kMinPacketBurstSize * kMaxPacketSize; + pacing_window = std::max(pacing_window, min_window_size); - if (pacing_window > leaky_bucket_.BytesPending()) { - // We have not filled our pacing window yet. - return time_until_send; - } - return leaky_bucket_.TimeRemaining(); + if (pacing_window > leaky_bucket_.BytesPending()) { + // We have not filled our pacing window yet. + return time_until_send; } - return time_until_send; + return leaky_bucket_.TimeRemaining(); } size_t PacedSender::AvailableWindow(size_t available_congestion_window) { diff --git a/net/quic/congestion_control/paced_sender.h b/net/quic/congestion_control/paced_sender.h index afd8773..1b6f81d 100644 --- a/net/quic/congestion_control/paced_sender.h +++ b/net/quic/congestion_control/paced_sender.h @@ -4,8 +4,8 @@ // // Helper class that limits the congestion window to pace the packets. -#ifndef GFE_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ -#define GFE_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ +#ifndef NET_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ +#define NET_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ #include "base/basictypes.h" #include "net/base/net_export.h" @@ -41,4 +41,4 @@ class NET_EXPORT_PRIVATE PacedSender { } // namespace net -#endif // GFE_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ +#endif // NET_QUIC_CONGESTION_CONTROL_PACED_SENDER_H_ diff --git a/net/quic/congestion_control/paced_sender_test.cc b/net/quic/congestion_control/paced_sender_test.cc index 70582bf..62a45ab 100644 --- a/net/quic/congestion_control/paced_sender_test.cc +++ b/net/quic/congestion_control/paced_sender_test.cc @@ -23,7 +23,7 @@ class PacedSenderTest : public ::testing::Test { const QuicTime::Delta zero_time_; MockClock clock_; - scoped_ptr<net::PacedSender> paced_sender_; + scoped_ptr<PacedSender> paced_sender_; }; TEST_F(PacedSenderTest, Basic) { @@ -34,7 +34,7 @@ TEST_F(PacedSenderTest, Basic) { paced_sender_->SentPacket(kMaxPacketSize); EXPECT_TRUE(paced_sender_->TimeUntilSend(zero_time_).IsZero()); paced_sender_->SentPacket(kMaxPacketSize); - EXPECT_EQ(static_cast<int>(kMaxPacketSize * 2), + EXPECT_EQ(static_cast<int64>(kMaxPacketSize * 2), paced_sender_->TimeUntilSend(zero_time_).ToMicroseconds()); EXPECT_EQ(0u, paced_sender_->AvailableWindow(kMaxPacketSize * 4)); clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(24)); @@ -51,7 +51,7 @@ TEST_F(PacedSenderTest, LowRate) { paced_sender_->SentPacket(kMaxPacketSize); EXPECT_TRUE(paced_sender_->TimeUntilSend(zero_time_).IsZero()); paced_sender_->SentPacket(kMaxPacketSize); - EXPECT_EQ(static_cast<int>(kMaxPacketSize * 20), + EXPECT_EQ(static_cast<int64>(kMaxPacketSize * 20), paced_sender_->TimeUntilSend(zero_time_).ToMicroseconds()); EXPECT_EQ(0u, paced_sender_->AvailableWindow(kMaxPacketSize * 4)); clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(24)); diff --git a/net/quic/congestion_control/quic_send_scheduler.cc b/net/quic/congestion_control/quic_send_scheduler.cc index c500a70..bc942de 100644 --- a/net/quic/congestion_control/quic_send_scheduler.cc +++ b/net/quic/congestion_control/quic_send_scheduler.cc @@ -5,17 +5,20 @@ #include "net/quic/congestion_control/quic_send_scheduler.h" +#include <algorithm> #include <cmath> +#include <map> #include "base/stl_util.h" #include "base/time.h" #include "net/quic/congestion_control/send_algorithm_interface.h" //#include "util/gtl/map-util.h" +using std::map; +using std::max; + namespace net { -// To prevent too aggressive pacing we allow the following packet burst size. -const int kMinPacketBurstSize = 2; const int64 kNumMicrosPerSecond = base::Time::kMicrosecondsPerSecond; QuicSendScheduler::QuicSendScheduler( @@ -85,7 +88,7 @@ void QuicSendScheduler::OnIncomingAckFrame(const QuicAckFrame& ack_frame) { // * Remove all missing packets. // * Send each ACK in the list to send_algorithm_. QuicTime last_timestamp(QuicTime::FromMicroseconds(0)); - std::map<QuicPacketSequenceNumber, size_t> acked_packets; + map<QuicPacketSequenceNumber, size_t> acked_packets; PendingPacketsMap::iterator it, it_upper; it = pending_packets_.begin(); @@ -109,7 +112,7 @@ void QuicSendScheduler::OnIncomingAckFrame(const QuicAckFrame& ack_frame) { // sequence numbers will include the ACK aggregation delay. QuicTime::Delta rtt = clock_->Now().Subtract(last_timestamp); - std::map<QuicPacketSequenceNumber, size_t>::iterator it_acked_packets; + map<QuicPacketSequenceNumber, size_t>::iterator it_acked_packets; for (it_acked_packets = acked_packets.begin(); it_acked_packets != acked_packets.end(); ++it_acked_packets) { @@ -168,8 +171,8 @@ int QuicSendScheduler::SentBandwidth() { current_estimated_bandwidth_ = (sum * (kNumMicrosPerSecond / kBitrateSmoothingPeriod)) / kBitrateSmoothingBuckets; } - max_estimated_bandwidth_ = std::max(max_estimated_bandwidth_, - current_estimated_bandwidth_); + max_estimated_bandwidth_ = max(max_estimated_bandwidth_, + current_estimated_bandwidth_); return current_estimated_bandwidth_; } diff --git a/net/quic/crypto/crypto_protocol.h b/net/quic/crypto/crypto_protocol.h index a641769..7303c6b 100644 --- a/net/quic/crypto/crypto_protocol.h +++ b/net/quic/crypto/crypto_protocol.h @@ -16,8 +16,8 @@ namespace net { typedef uint32 CryptoTag; -typedef std::vector<CryptoTag> CryptoTagVector; typedef std::map<CryptoTag, base::StringPiece> CryptoTagValueMap; +typedef std::vector<CryptoTag> CryptoTagVector; struct NET_EXPORT_PRIVATE CryptoHandshakeMessage { CryptoHandshakeMessage(); ~CryptoHandshakeMessage(); @@ -31,7 +31,7 @@ struct NET_EXPORT_PRIVATE CryptoHandshakeMessage { // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is // stored in memory as a little endian uint32, we need // to reverse the order of the bytes. -#define MAKE_TAG(a,b,c,d) (d << 24) + (c << 16) + (b << 8) + a +#define MAKE_TAG(a, b, c, d) (d << 24) + (c << 16) + (b << 8) + a const CryptoTag kCHLO = MAKE_TAG('C', 'H', 'L', 'O'); // Client hello const CryptoTag kSHLO = MAKE_TAG('S', 'H', 'L', 'O'); // Server hello diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc index 47074a1..2113ba5 100644 --- a/net/quic/quic_connection.cc +++ b/net/quic/quic_connection.cc @@ -161,7 +161,9 @@ void QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { if (incoming_ack.received_info.largest_received > packet_creator_.sequence_number()) { - DLOG(ERROR) << "Client acked unsent packet"; + DLOG(ERROR) << "Client acked unsent packet:" + << incoming_ack.received_info.largest_received << " vs " + << packet_creator_.sequence_number(); // We got an error for data we have not sent. Error out. return false; } @@ -174,8 +176,7 @@ bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { kMaxUnackedPackets); if (incoming_ack.sent_info.least_unacked != 0 && - incoming_ack.sent_info.least_unacked < - least_packet_awaiting_ack_) { + incoming_ack.sent_info.least_unacked < least_packet_awaiting_ack_) { DLOG(INFO) << "Client sent low least_unacked"; // We never process old ack frames, so this number should only increase. return false; @@ -255,23 +256,21 @@ void QuicConnection::UpdatePacketInformationSentByPeer( const QuicAckFrame& incoming_ack) { // Iteratate through the packets which will the peer will not resend and // remove them from our missing list. - for (hash_set<QuicPacketSequenceNumber>::const_iterator it = + for (SequenceSet::const_iterator it = incoming_ack.sent_info.non_retransmiting.begin(); it != incoming_ack.sent_info.non_retransmiting.end(); ++it) { - DVLOG(1) << "no longer expecting " << *it; - outgoing_ack_.received_info.missing_packets.erase(*it); + DVLOG(1) << "no longer expecting " << *it; + outgoing_ack_.received_info.missing_packets.erase(*it); } // Make sure we also don't expect any packets lower than the peer's // last-packet-awaiting-ack. - if (incoming_ack.sent_info.least_unacked > - least_packet_awaiting_ack_) { + if (incoming_ack.sent_info.least_unacked > least_packet_awaiting_ack_) { for (QuicPacketSequenceNumber i = least_packet_awaiting_ack_; i < incoming_ack.sent_info.least_unacked; ++i) { outgoing_ack_.received_info.missing_packets.erase(i); } - least_packet_awaiting_ack_ = - incoming_ack.sent_info.least_unacked; + least_packet_awaiting_ack_ = incoming_ack.sent_info.least_unacked; } // Possibly close any FecGroups which are now irrelevant @@ -285,13 +284,15 @@ void QuicConnection::OnFecData(const QuicFecData& fec) { } void QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { - DLOG(INFO) << "Stream reset with error " << frame.error_code; + DLOG(INFO) << "Stream reset with error " + << QuicUtils::ErrorToString(frame.error_code); visitor_->OnRstStream(frame); } void QuicConnection::OnConnectionCloseFrame( const QuicConnectionCloseFrame& frame) { - DLOG(INFO) << "Connection closed with error " << frame.error_code; + DLOG(INFO) << "Connection closed with error " + << QuicUtils::ErrorToString(frame.error_code); connected_ = false; visitor_->ConnectionClose(frame.error_code, true); } @@ -306,7 +307,7 @@ void QuicConnection::OnPacketComplete() { clock_->Now(), last_packet_revived_); } else { - DLOG(INFO) << "Got revived packet with " << frames_.size(); + DLOG(INFO) << "Got revived packet with " << frames_.size() << " frames."; } if (frames_.size()) { @@ -471,7 +472,7 @@ bool QuicConnection::SendPacket(QuicPacketSequenceNumber sequence_number, outgoing_ack_.sent_info.least_unacked = sequence_number; } } else { - if (outgoing_ack_.sent_info.least_unacked!= 0 && + if (outgoing_ack_.sent_info.least_unacked != 0 && sequence_number > outgoing_ack_.sent_info.least_unacked) { outgoing_ack_.sent_info.non_retransmiting.insert(sequence_number); } @@ -479,11 +480,10 @@ bool QuicConnection::SendPacket(QuicPacketSequenceNumber sequence_number, scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); int error; - int rv = helper_->WritePacketToWire(sequence_number, *encrypted, - should_resend, &error); DLOG(INFO) << "Sending packet : " << (should_resend ? "data bearing " : " ack only ") << "packet " << sequence_number; + int rv = helper_->WritePacketToWire(*encrypted, &error); if (rv == -1) { if (error == ERR_IO_PENDING) { write_blocked_ = true; @@ -535,7 +535,7 @@ void QuicConnection::MaybeProcessRevivedPacket() { last_packet_revived_ = true; framer_.ProcessRevivedPacket(revived_header_, StringPiece(revived_payload_.get(), len)); - revived_payload_.reset(NULL); + revived_payload_.reset(); } QuicFecGroup* QuicConnection::GetFecGroup() { diff --git a/net/quic/quic_connection.h b/net/quic/quic_connection.h index 7dd7fa6..369bfc0 100644 --- a/net/quic/quic_connection.h +++ b/net/quic/quic_connection.h @@ -32,6 +32,7 @@ namespace net { class QuicClock; class QuicConnection; class QuicEncrypter; +class QuicFecGroup; class QuicReceiptMetricsCollector; class QuicSendScheduler; @@ -71,9 +72,7 @@ class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { // Sends the packet out to the peer, possibly simulating packet // loss if FLAGS_fake_packet_loss_percentage is set. If the write failed // errno will be copied to |*error|. - virtual int WritePacketToWire(QuicPacketSequenceNumber number, - const QuicEncryptedPacket& packet, - bool resend, + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, int* error) = 0; // Sets up an alarm to resend the packet with the given sequence number if we @@ -112,10 +111,10 @@ class NET_EXPORT_PRIVATE QuicConnection : public QuicFramerVisitorInterface { // Send the data payload to the peer. size_t SendStreamData(QuicStreamId id, - base::StringPiece data, - QuicStreamOffset offset, - bool fin, - QuicPacketSequenceNumber* last_packet); + base::StringPiece data, + QuicStreamOffset offset, + bool fin, + QuicPacketSequenceNumber* last_packet); // Send a stream reset frame to the peer. virtual void SendRstStream(QuicStreamId id, QuicErrorCode error, @@ -211,7 +210,6 @@ class NET_EXPORT_PRIVATE QuicConnection : public QuicFramerVisitorInterface { private: friend class QuicConnectionPeer; - typedef base::hash_set<QuicPacketSequenceNumber> SequenceSet; // Packets which have not been written to the wire. struct QueuedPacket { QueuedPacket(QuicPacketSequenceNumber sequence_number, @@ -292,9 +290,6 @@ class NET_EXPORT_PRIVATE QuicConnection : public QuicFramerVisitorInterface { QuicPacketHeader revived_header_; scoped_array<char> revived_payload_; - // Only set if we configure fake packet loss. - //scoped_ptr<MTRandom> random_; - QuicConnectionVisitorInterface* visitor_; QuicPacketCreator packet_creator_; diff --git a/net/quic/quic_connection_helper.cc b/net/quic/quic_connection_helper.cc index 40d5dcf..4623c82 100644 --- a/net/quic/quic_connection_helper.cc +++ b/net/quic/quic_connection_helper.cc @@ -37,15 +37,10 @@ QuicClock* QuicConnectionHelper::GetClock() { } int QuicConnectionHelper::WritePacketToWire( - QuicPacketSequenceNumber sequence_number, const QuicEncryptedPacket& packet, - bool resend, int* error) { if (connection_->ShouldSimulateLostPacket()) { - DLOG(INFO) << "Dropping " - << (resend ? "data bearing " : " ack only ") - << "packet " << sequence_number - << " due to fake packet loss."; + DLOG(INFO) << "Dropping packet due to fake packet loss."; *error = 0; return packet.length(); } diff --git a/net/quic/quic_connection_helper.h b/net/quic/quic_connection_helper.h index 2bd5f90..b00d091 100644 --- a/net/quic/quic_connection_helper.h +++ b/net/quic/quic_connection_helper.h @@ -37,9 +37,7 @@ class NET_EXPORT_PRIVATE QuicConnectionHelper // QuicConnectionHelperInterface virtual void SetConnection(QuicConnection* connection) OVERRIDE; virtual QuicClock* GetClock() OVERRIDE; - virtual int WritePacketToWire(QuicPacketSequenceNumber number, - const QuicEncryptedPacket& packet, - bool resend, + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, int* error) OVERRIDE; virtual void SetResendAlarm(QuicPacketSequenceNumber sequence_number, QuicTime::Delta delay) OVERRIDE; diff --git a/net/quic/quic_connection_helper_test.cc b/net/quic/quic_connection_helper_test.cc index 4df76de..de72e38 100644 --- a/net/quic/quic_connection_helper_test.cc +++ b/net/quic/quic_connection_helper_test.cc @@ -72,9 +72,7 @@ class TestConnectionHelper : public QuicConnectionHelper { virtual ~TestConnectionHelper() {} - virtual int WritePacketToWire(QuicPacketSequenceNumber number, - const QuicEncryptedPacket& packet, - bool resend, + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, int* error) { QuicFramer framer(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)); diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc index 0454842..753a086 100644 --- a/net/quic/quic_connection_test.cc +++ b/net/quic/quic_connection_test.cc @@ -7,8 +7,8 @@ #include "net/base/net_errors.h" #include "net/quic/congestion_control/quic_receipt_metrics_collector.h" #include "net/quic/congestion_control/quic_send_scheduler.h" +#include "net/quic/crypto/quic_decrypter.h" #include "net/quic/crypto/quic_encrypter.h" -#include "net/quic/crypto/null_encrypter.h" #include "net/quic/test_tools/mock_clock.h" #include "net/quic/test_tools/quic_test_utils.h" #include "testing/gmock/include/gmock/gmock.h" @@ -87,9 +87,7 @@ class TestConnectionHelper : public QuicConnectionHelperInterface { return clock_; } - virtual int WritePacketToWire(QuicPacketSequenceNumber number, - const QuicEncryptedPacket& packet, - bool resend, + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, int* error) { QuicFramer framer(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)); diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc index d0ace80..94a3caf 100644 --- a/net/quic/quic_crypto_client_stream.cc +++ b/net/quic/quic_crypto_client_stream.cc @@ -4,7 +4,8 @@ #include "net/quic/quic_crypto_client_stream.h" -#include "net/quic/quic_session.h" +#include "net/quic/crypto/crypto_protocol.h" +#include "net/quic/quic_protocol.h" namespace net { diff --git a/net/quic/quic_crypto_client_stream.h b/net/quic/quic_crypto_client_stream.h index 8f94884..aede3b1 100644 --- a/net/quic/quic_crypto_client_stream.h +++ b/net/quic/quic_crypto_client_stream.h @@ -10,6 +10,7 @@ namespace net { class QuicSession; +struct CryptoHandshakeMessage; class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream { diff --git a/net/quic/quic_crypto_stream.h b/net/quic/quic_crypto_stream.h index 91cb95f..2dce7d3 100644 --- a/net/quic/quic_crypto_stream.h +++ b/net/quic/quic_crypto_stream.h @@ -6,11 +6,13 @@ #define NET_QUIC_QUIC_CRYPTO_STREAM_H_ #include "net/quic/crypto/crypto_framer.h" +#include "net/quic/quic_protocol.h" #include "net/quic/reliable_quic_stream.h" namespace net { class QuicSession; +struct CryptoHandshakeMessage; // Crypto handshake messages in QUIC take place over a reserved // reliable stream with the id 1. Each endpoint (client and server) diff --git a/net/quic/quic_data_reader.cc b/net/quic/quic_data_reader.cc index 263bafb..3bb7fc3 100644 --- a/net/quic/quic_data_reader.cc +++ b/net/quic/quic_data_reader.cc @@ -15,38 +15,11 @@ QuicDataReader::QuicDataReader(const char* data, const size_t len) } bool QuicDataReader::ReadUInt16(uint16* result) { - // Make sure that we have the whole uint16. - // TODO(rch): use sizeof instead of magic numbers. - // Refactor to use a common Read(void* buffer, size_t len) - // method that will do the memcpy and the advancement of pos_. - if (!CanRead(2)) { - OnFailure(); - return false; - } - - // Read into result. - memcpy(result, data_ + pos_, 2); - - // Iterate. - pos_ += 2; - - return true; + return ReadBytes(result, sizeof(*result)); } bool QuicDataReader::ReadUInt32(uint32* result) { - // Make sure that we have the whole uint32. - if (!CanRead(4)) { - OnFailure(); - return false; - } - - // Read into result. - memcpy(result, data_ + pos_, 4); - - // Iterate. - pos_ += 4; - - return true; + return ReadBytes(result, sizeof(*result)); } bool QuicDataReader::ReadUInt48(uint64* result) { @@ -68,19 +41,7 @@ bool QuicDataReader::ReadUInt48(uint64* result) { } bool QuicDataReader::ReadUInt64(uint64* result) { - // Make sure that we have the whole uint64. - if (!CanRead(8)) { - OnFailure(); - return false; - } - - // Read into result. - memcpy(result, data_ + pos_, 8); - - // Iterate. - pos_ += 8; - - return true; + return ReadBytes(result, sizeof(*result)); } bool QuicDataReader::ReadUInt128(uint128* result) { @@ -109,15 +70,15 @@ bool QuicDataReader::ReadStringPiece16(StringPiece* result) { return ReadStringPiece(result, result_len); } -bool QuicDataReader::ReadBytes(void* result, size_t size) { +bool QuicDataReader::ReadStringPiece(StringPiece* result, size_t size) { // Make sure that we have enough data to read. if (!CanRead(size)) { OnFailure(); return false; } - // Read into result. - memcpy(result, data_ + pos_, size); + // Set result. + result->set(data_ + pos_, size); // Iterate. pos_ += size; @@ -125,16 +86,25 @@ bool QuicDataReader::ReadBytes(void* result, size_t size) { return true; } +StringPiece QuicDataReader::ReadRemainingPayload() { + StringPiece payload = PeekRemainingPayload(); + pos_ = len_; + return payload; +} -bool QuicDataReader::ReadStringPiece(StringPiece* result, size_t size) { +StringPiece QuicDataReader::PeekRemainingPayload() { + return StringPiece(data_ + pos_, len_ - pos_); +} + +bool QuicDataReader::ReadBytes(void* result, size_t size) { // Make sure that we have enough data to read. if (!CanRead(size)) { OnFailure(); return false; } - // Set result. - result->set(data_ + pos_, size); + // Read into result. + memcpy(result, data_ + pos_, size); // Iterate. pos_ += size; @@ -142,16 +112,6 @@ bool QuicDataReader::ReadStringPiece(StringPiece* result, size_t size) { return true; } -StringPiece QuicDataReader::PeekRemainingPayload() { - return StringPiece(data_ + pos_, len_ - pos_); -} - -StringPiece QuicDataReader::ReadRemainingPayload() { - StringPiece payload = PeekRemainingPayload(); - pos_ = len_; - return payload; -} - bool QuicDataReader::IsDoneReading() const { return len_ == pos_; } diff --git a/net/quic/quic_data_writer.cc b/net/quic/quic_data_writer.cc index b635b38..1db9f30 100644 --- a/net/quic/quic_data_writer.cc +++ b/net/quic/quic_data_writer.cc @@ -9,7 +9,6 @@ #include "base/basictypes.h" #include "base/logging.h" -#include "net/quic/quic_protocol.h" using base::StringPiece; using std::numeric_limits; diff --git a/net/quic/quic_framer.cc b/net/quic/quic_framer.cc index 76c8abe..708bd75 100644 --- a/net/quic/quic_framer.cc +++ b/net/quic/quic_framer.cc @@ -11,7 +11,6 @@ #include "net/quic/quic_data_writer.h" #include "net/quic/quic_utils.h" -using base::hash_set; using base::StringPiece; namespace net { @@ -671,8 +670,7 @@ bool QuicFramer::AppendAckFramePayload( return false; } - hash_set<QuicPacketSequenceNumber>::const_iterator it = - frame.received_info.missing_packets.begin(); + SequenceSet::const_iterator it = frame.received_info.missing_packets.begin(); for (; it != frame.received_info.missing_packets.end(); ++it) { if (!writer->WriteUInt48(*it)) { return false; diff --git a/net/quic/quic_framer.h b/net/quic/quic_framer.h index 4f9c4bd..b63257b 100644 --- a/net/quic/quic_framer.h +++ b/net/quic/quic_framer.h @@ -18,13 +18,13 @@ namespace net { -class QuicEncrypter; -class QuicDecrypter; -class QuicFramer; class QuicDataReader; class QuicDataWriter; +class QuicDecrypter; +class QuicEncrypter; +class QuicFramer; -// Class that receives callbacks from the framer when packets +// This class receives callbacks from the framer when packets // are processed. class NET_EXPORT_PRIVATE QuicFramerVisitorInterface { public: @@ -80,9 +80,9 @@ class NET_EXPORT_PRIVATE QuicFecBuilderInterface { base::StringPiece payload) = 0; }; -// Class for parsing and constructing QUIC packets. Has a +// Class for parsing and constructing QUIC packets. It has a // QuicFramerVisitorInterface that is called when packets are parsed. -// Also has a QuicFecBuilder that is called when packets are constructed +// It also has a QuicFecBuilder that is called when packets are constructed // in order to generate FEC data for subsequently building FEC packets. class NET_EXPORT_PRIVATE QuicFramer { public: @@ -130,8 +130,8 @@ class NET_EXPORT_PRIVATE QuicFramer { // |frames|. Assigns |*packet| to the address of the new object. // Returns true upon success. bool ConstructFrameDataPacket(const QuicPacketHeader& header, - const QuicFrames& frames, - QuicPacket** packet); + const QuicFrames& frames, + QuicPacket** packet); // Creates a new QuicPacket populated with the fields in |header| and // |fec|. Assigns |*packet| to the address of the new object. @@ -174,11 +174,11 @@ class NET_EXPORT_PRIVATE QuicFramer { size_t ComputeFramePayloadLength(const QuicFrame& frame); bool AppendStreamFramePayload(const QuicStreamFrame& frame, - QuicDataWriter* builder); + QuicDataWriter* builder); bool AppendAckFramePayload(const QuicAckFrame& frame, - QuicDataWriter* builder); + QuicDataWriter* builder); bool AppendRstStreamFramePayload(const QuicRstStreamFrame& frame, - QuicDataWriter* builder); + QuicDataWriter* builder); bool AppendConnectionCloseFramePayload( const QuicConnectionCloseFrame& frame, QuicDataWriter* builder); diff --git a/net/quic/quic_framer_test.cc b/net/quic/quic_framer_test.cc index f6dfb10..e2f9f2d 100644 --- a/net/quic/quic_framer_test.cc +++ b/net/quic/quic_framer_test.cc @@ -292,7 +292,7 @@ TEST_F(QuicFramerTest, PacketHeader) { EXPECT_FALSE(framer_.ProcessPacket(self_address_, peer_address_, encrypted)); EXPECT_EQ(expected_error, framer_.detailed_error()); - EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); + EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()) << " i: " << i; } } @@ -585,18 +585,16 @@ TEST_F(QuicFramerTest, AckFrame) { EXPECT_EQ(QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)), frame.received_info.time_received); - const hash_set<QuicPacketSequenceNumber>* sequence_nums = - &frame.received_info.missing_packets; - ASSERT_EQ(2u, sequence_nums->size()); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABB))); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABA))); + const SequenceSet& sequence_nums = frame.received_info.missing_packets; + ASSERT_EQ(2u, sequence_nums.size()); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABB))); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABA))); EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); ASSERT_EQ(3u, frame.sent_info.non_retransmiting.size()); - const hash_set<QuicPacketSequenceNumber>* non_retrans = - &frame.sent_info.non_retransmiting; - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AB0))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAF))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAE))); + const SequenceSet& non_retrans = frame.sent_info.non_retransmiting; + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AB0))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAF))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAE))); ASSERT_EQ(kNone, frame.congestion_info.type); // Now test framing boundaries @@ -700,18 +698,16 @@ TEST_F(QuicFramerTest, AckFrameTCP) { EXPECT_EQ(QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)), frame.received_info.time_received); - const hash_set<QuicPacketSequenceNumber>* sequence_nums = - &frame.received_info.missing_packets; - ASSERT_EQ(2u, sequence_nums->size()); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABB))); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABA))); + const SequenceSet& sequence_nums = frame.received_info.missing_packets; + ASSERT_EQ(2u, sequence_nums.size()); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABB))); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABA))); EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); ASSERT_EQ(3u, frame.sent_info.non_retransmiting.size()); - const hash_set<QuicPacketSequenceNumber>* non_retrans = - &frame.sent_info.non_retransmiting; - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AB0))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAF))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAE))); + const SequenceSet& non_retrans = frame.sent_info.non_retransmiting; + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AB0))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAF))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAE))); ASSERT_EQ(kTCP, frame.congestion_info.type); EXPECT_EQ(0x0201, frame.congestion_info.tcp.accumulated_number_of_lost_packets); @@ -806,18 +802,16 @@ TEST_F(QuicFramerTest, AckFrameInterArrival) { EXPECT_EQ(QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)), frame.received_info.time_received); - const hash_set<QuicPacketSequenceNumber>* sequence_nums = - &frame.received_info.missing_packets; - ASSERT_EQ(2u, sequence_nums->size()); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABB))); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABA))); + const SequenceSet& sequence_nums = frame.received_info.missing_packets; + ASSERT_EQ(2u, sequence_nums.size()); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABB))); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABA))); EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); ASSERT_EQ(3u, frame.sent_info.non_retransmiting.size()); - const hash_set<QuicPacketSequenceNumber>* non_retrans = - &frame.sent_info.non_retransmiting; - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AB0))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAF))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAE))); + const SequenceSet& non_retrans = frame.sent_info.non_retransmiting; + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AB0))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAF))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAE))); ASSERT_EQ(kInterArrival, frame.congestion_info.type); EXPECT_EQ(0x0302, frame.congestion_info.inter_arrival. accumulated_number_of_lost_packets); @@ -910,18 +904,16 @@ TEST_F(QuicFramerTest, AckFrameFixRate) { EXPECT_EQ(QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)), frame.received_info.time_received); - const hash_set<QuicPacketSequenceNumber>* sequence_nums = - &frame.received_info.missing_packets; - ASSERT_EQ(2u, sequence_nums->size()); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABB))); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABA))); + const SequenceSet& sequence_nums = frame.received_info.missing_packets; + ASSERT_EQ(2u, sequence_nums.size()); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABB))); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABA))); EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); ASSERT_EQ(3u, frame.sent_info.non_retransmiting.size()); - const hash_set<QuicPacketSequenceNumber>* non_retrans = - &frame.sent_info.non_retransmiting; - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AB0))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAF))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAE))); + const SequenceSet& non_retrans = frame.sent_info.non_retransmiting; + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AB0))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAF))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAE))); ASSERT_EQ(kFixRate, frame.congestion_info.type); EXPECT_EQ(static_cast<uint32>(0x04030201), frame.congestion_info.fix_rate.bitrate_in_bytes_per_second); @@ -1154,18 +1146,16 @@ TEST_F(QuicFramerTest, ConnectionCloseFrame) { EXPECT_EQ(QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)), frame.received_info.time_received); - const hash_set<QuicPacketSequenceNumber>* sequence_nums = - &frame.received_info.missing_packets; - ASSERT_EQ(2u, sequence_nums->size()); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABB))); - EXPECT_EQ(1u, sequence_nums->count(GG_UINT64_C(0x0123456789ABA))); + const SequenceSet& sequence_nums = frame.received_info.missing_packets; + ASSERT_EQ(2u, sequence_nums.size()); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABB))); + EXPECT_EQ(1u, sequence_nums.count(GG_UINT64_C(0x0123456789ABA))); EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); ASSERT_EQ(3u, frame.sent_info.non_retransmiting.size()); - const hash_set<QuicPacketSequenceNumber>* non_retrans = - &frame.sent_info.non_retransmiting; - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AB0))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAF))); - EXPECT_EQ(1u, non_retrans->count(GG_UINT64_C(0x0123456789AAE))); + const SequenceSet& non_retrans = frame.sent_info.non_retransmiting; + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AB0))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAF))); + EXPECT_EQ(1u, non_retrans.count(GG_UINT64_C(0x0123456789AAE))); ASSERT_EQ(kInterArrival, frame.congestion_info.type); EXPECT_EQ(0x0302, frame.congestion_info.inter_arrival. accumulated_number_of_lost_packets); @@ -1347,6 +1337,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacket) { // num_unacked_packets 0x02, #if defined(OS_WIN) + // Windows hash_set order is different. // unacked packet sequence number 0xBB, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1367,6 +1358,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacket) { // num non retransmitting packets 0x03, #if defined(OS_WIN) + // Windows hash_set order is different. // non retransmitting packet sequence number 0xB0, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1459,6 +1451,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketTCP) { // num_unacked_packets 0x02, #if defined(OS_WIN) + // Windows hash_set order is different. // unacked packet sequence number 0xBB, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1479,6 +1472,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketTCP) { // num non retransmitting packets 0x03, #if defined(OS_WIN) + // Windows hash_set order is different. // non retransmitting packet sequence number 0xB0, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1577,6 +1571,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketInterArrival) { // num_unacked_packets 0x02, #if defined(OS_WIN) + // Windows hash_set order is different. // unacked packet sequence number 0xBB, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1597,6 +1592,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketInterArrival) { // num non retransmitting packets 0x03, #if defined(OS_WIN) + // Windows hash_set order is different. // non retransmitting packet sequence number 0xB0, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1695,6 +1691,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketFixRate) { // num_unacked_packets 0x02, #if defined(OS_WIN) + // Windows hash_set order is different. // unacked packet sequence number 0xBB, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1715,6 +1712,7 @@ TEST_F(QuicFramerTest, ConstructAckFramePacketFixRate) { // num non retransmitting packets 0x03, #if defined(OS_WIN) + // Windows hash_set order is different. // non retransmitting packet sequence number 0xB0, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1921,6 +1919,7 @@ TEST_F(QuicFramerTest, ConstructCloseFramePacket) { // num_unacked_packets 0x02, #if defined(OS_WIN) + // Windows hash_set order is different. // unacked packet sequence number 0xBB, 0x9A, 0x78, 0x56, 0x34, 0x12, @@ -1941,6 +1940,7 @@ TEST_F(QuicFramerTest, ConstructCloseFramePacket) { // num non retransmitting packets 0x03, #if defined(OS_WIN) + // Windows hash_set order is different. // non retransmitting packet sequence number 0xB0, 0x9A, 0x78, 0x56, 0x34, 0x12, diff --git a/net/quic/quic_packet_creator.h b/net/quic/quic_packet_creator.h index 38874ad..4ce9c18 100644 --- a/net/quic/quic_packet_creator.h +++ b/net/quic/quic_packet_creator.h @@ -10,6 +10,7 @@ #include <utility> #include <vector> +#include "base/memory/scoped_ptr.h" #include "base/string_piece.h" #include "net/quic/quic_fec_group.h" #include "net/quic/quic_framer.h" diff --git a/net/quic/quic_protocol.cc b/net/quic/quic_protocol.cc index 0a2538b..878ffee 100644 --- a/net/quic/quic_protocol.cc +++ b/net/quic/quic_protocol.cc @@ -5,7 +5,6 @@ #include "net/quic/quic_protocol.h" using base::StringPiece; -using base::hash_set; using std::ostream; namespace net { @@ -34,16 +33,14 @@ ostream& operator<<(ostream& os, const QuicAckFrame& s) { os << "largest_received: " << s.received_info.largest_received << " time: " << s.received_info.time_received.ToMicroseconds() << " missing: "; - for (hash_set<QuicPacketSequenceNumber>::const_iterator it = - s.received_info.missing_packets.begin(); + for (SequenceSet::const_iterator it = s.received_info.missing_packets.begin(); it != s.received_info.missing_packets.end(); ++it) { os << *it << " "; } os << " least_waiting: " << s.sent_info.least_unacked << " no_retransmit: "; - for (hash_set<QuicPacketSequenceNumber>::const_iterator it = - s.sent_info.non_retransmiting.begin(); + for (SequenceSet::const_iterator it = s.sent_info.non_retransmiting.begin(); it != s.sent_info.non_retransmiting.end(); ++it) { os << *it << " "; } diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h index 2f35f40..fb45cf0 100644 --- a/net/quic/quic_protocol.h +++ b/net/quic/quic_protocol.h @@ -163,6 +163,8 @@ struct NET_EXPORT_PRIVATE QuicStreamFrame { base::StringPiece data; }; +typedef base::hash_set<QuicPacketSequenceNumber> SequenceSet; + struct NET_EXPORT_PRIVATE ReceivedPacketInfo { ReceivedPacketInfo(); ~ReceivedPacketInfo(); @@ -173,7 +175,7 @@ struct NET_EXPORT_PRIVATE ReceivedPacketInfo { // The set of packets which we're expecting and have not received. // This includes any packets between the lowest and largest_received // which we have neither seen nor been informed are non-retransmitting. - base::hash_set<QuicPacketSequenceNumber> missing_packets; + SequenceSet missing_packets; }; struct NET_EXPORT_PRIVATE SentPacketInfo { @@ -183,7 +185,7 @@ struct NET_EXPORT_PRIVATE SentPacketInfo { QuicPacketSequenceNumber least_unacked; // The set of packets between least_unacked and the last packet we have sent // which we will not resend. - base::hash_set<QuicPacketSequenceNumber> non_retransmiting; + SequenceSet non_retransmiting; }; // Defines for all types of congestion feedback that will be negotiated in QUIC, diff --git a/net/quic/quic_session.cc b/net/quic/quic_session.cc index 66ba4e0..5e5e911 100644 --- a/net/quic/quic_session.cc +++ b/net/quic/quic_session.cc @@ -76,7 +76,7 @@ void QuicSession::ConnectionClose(QuicErrorCode error, bool from_peer) { } int QuicSession::WriteData(QuicStreamId id, StringPiece data, - QuicStreamOffset offset, bool fin) { + QuicStreamOffset offset, bool fin) { return connection_->SendStreamData(id, data, offset, fin, NULL); } @@ -159,7 +159,6 @@ ReliableQuicStream* QuicSession::GetIncomingReliableStream( } ReliableQuicStream* stream = CreateIncomingReliableStream(stream_id); if (stream == NULL) { - connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); return NULL; } ActivateStream(stream); @@ -182,9 +181,9 @@ bool QuicSession::IsClosedStream(QuicStreamId id) { } // For peer created streams, we also need to consider implicitly created // streams. - return id <= largest_peer_created_stream_id_ && - implicitly_created_streams_.count(id) == 0; - } + return id <= largest_peer_created_stream_id_ && + implicitly_created_streams_.count(id) == 0; +} size_t QuicSession::GetNumOpenStreams() { return stream_map_.size() + implicitly_created_streams_.size(); diff --git a/net/quic/quic_session.h b/net/quic/quic_session.h index 07ff22f..a55e096 100644 --- a/net/quic/quic_session.h +++ b/net/quic/quic_session.h @@ -20,6 +20,9 @@ namespace net { +class QuicCryptoStream; +class ReliableQuicStream; + class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { public: QuicSession(QuicConnection* connection, bool is_server); @@ -50,6 +53,11 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { // Returns true once the crypto handshake is complete. virtual bool IsHandshakeComplete(); + // Returns true if the stream existed previously and has been closed. + // Returns false if the stream is still active or if the stream has + // not yet been created. + bool IsClosedStream(QuicStreamId id); + QuicConnection* connection() { return connection_.get(); } size_t num_active_requests() const { return stream_map_.size(); } const IPEndPoint& peer_address() const { @@ -64,7 +72,8 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { protected: // Creates a new stream, owned by the caller, to handle a peer-initiated - // stream. Returns NULL if max streams have already been opened. + // stream. Returns NULL and does error handling if the stream can not be + // created. virtual ReliableQuicStream* CreateIncomingReliableStream(QuicStreamId id) = 0; // Create a new stream, owned by the caller, to handle a locally-initiated @@ -80,11 +89,6 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { // Returns the stream id for a new stream. QuicStreamId GetNextStreamId(); - // Returns true if the stream existed previously and has been closed. - // Returns false if the stream is still active or if the stream has - // not yet been created. - bool IsClosedStream(QuicStreamId id); - ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id); size_t get_max_open_streams() const { diff --git a/net/quic/quic_stream_sequencer.cc b/net/quic/quic_stream_sequencer.cc index 4853ceb..f4959ae 100644 --- a/net/quic/quic_stream_sequencer.cc +++ b/net/quic/quic_stream_sequencer.cc @@ -44,7 +44,7 @@ bool QuicStreamSequencer::WillAcceptStreamFrame( size_t data_len = frame.data.size(); DCHECK_LE(data_len, max_frame_memory_); - uint64 byte_offset = frame.offset; + QuicStreamOffset byte_offset = frame.offset; if (byte_offset < num_bytes_consumed_ || frames_.find(byte_offset) != frames_.end()) { return false; @@ -76,6 +76,7 @@ bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { QuicStreamOffset byte_offset = frame.offset; const char* data = frame.data.data(); size_t data_len = frame.data.size(); + if (byte_offset == num_bytes_consumed_) { DVLOG(1) << "Processing byte offset " << byte_offset; size_t bytes_consumed = stream_->ProcessData(data, data_len); @@ -104,7 +105,7 @@ bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { } void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset, - bool half_close) { + bool half_close) { const QuicStreamOffset kMaxOffset = numeric_limits<QuicStreamOffset>::max(); // If we have a scheduled termination or close, any new offset should match diff --git a/net/quic/quic_stream_sequencer_test.cc b/net/quic/quic_stream_sequencer_test.cc index 148ace0f..24e2eb7 100644 --- a/net/quic/quic_stream_sequencer_test.cc +++ b/net/quic/quic_stream_sequencer_test.cc @@ -34,8 +34,8 @@ class QuicStreamSequencerPeer : public QuicStreamSequencer { : QuicStreamSequencer(max_mem, stream) {} virtual bool OnFrame(QuicStreamOffset byte_offset, - const char* data, - uint32 data_len) { + const char* data, + uint32 data_len) { QuicStreamFrame frame; frame.stream_id = 1; frame.offset = byte_offset; @@ -125,8 +125,7 @@ TEST_F(QuicStreamSequencerTest, RejectBufferedFrame) { } TEST_F(QuicStreamSequencerTest, FullFrameConsumed) { - EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)) - .WillOnce(Return(3)); + EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)).WillOnce(Return(3)); EXPECT_TRUE(sequencer_->OnFrame(0, "abc", 3)); EXPECT_EQ(0u, sequencer_->frames()->size()); @@ -134,8 +133,7 @@ TEST_F(QuicStreamSequencerTest, FullFrameConsumed) { } TEST_F(QuicStreamSequencerTest, PartialFrameConsumed) { - EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)) - .WillOnce(Return(2)); + EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)).WillOnce(Return(2)); EXPECT_TRUE(sequencer_->OnFrame(0, "abc", 3)); EXPECT_EQ(1u, sequencer_->frames()->size()); @@ -144,8 +142,7 @@ TEST_F(QuicStreamSequencerTest, PartialFrameConsumed) { } TEST_F(QuicStreamSequencerTest, NextxFrameNotConsumed) { - EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)) - .WillOnce(Return(0)); + EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)).WillOnce(Return(0)); EXPECT_TRUE(sequencer_->OnFrame(0, "abc", 3)); EXPECT_EQ(1u, sequencer_->frames()->size()); @@ -279,7 +276,7 @@ TEST_F(QuicStreamSequencerTest, BasicHalfUnordered) { EXPECT_TRUE(sequencer_->OnFrame(0, "abc", 3)); } -TEST_F(QuicStreamSequencerTest, CloseStreamBeforeCloseEqual) { +TEST_F(QuicStreamSequencerTest, TerminateStreamBeforeCloseEqual) { sequencer_->CloseStreamAtOffset(3, true); EXPECT_EQ(3u, sequencer_->close_offset()); @@ -331,17 +328,13 @@ class QuicSequencerRandomTest : public QuicStreamSequencerTest { int remaining_payload = payload_size; while (remaining_payload != 0) { int size = min(OneToN(6), remaining_payload); - int idx = payload_size - remaining_payload; - list_.push_back(make_pair(idx, string(kPayload + idx, size))); + int index = payload_size - remaining_payload; + list_.push_back(make_pair(index, string(kPayload + index, size))); remaining_payload -= size; } } QuicSequencerRandomTest() { - //int32 seed = ACMRandom::HostnamePidTimeSeed(); - //LOG(INFO) << "**** The current seed is " << seed << " ****"; - //random_.reset(new ACMRandom(seed)); - CreateFrames(); } @@ -355,12 +348,10 @@ class QuicSequencerRandomTest : public QuicStreamSequencerTest { to_process = base::RandInt(0, len); } output_.append(data, to_process); - LOG(ERROR) << output_; return to_process; } string output_; - //scoped_ptr<ACMRandom> random_; FrameList list_; }; @@ -375,12 +366,13 @@ TEST_F(QuicSequencerRandomTest, RandomFramesNoDroppingNoBackup) { } while (list_.size() != 0) { - int idx = OneToN(list_.size()) - 1; - LOG(ERROR) << "Sending index " << idx << " " << list_[idx].second.c_str(); + int index = OneToN(list_.size()) - 1; + LOG(ERROR) << "Sending index " << index << " " + << list_[index].second.data(); EXPECT_TRUE(sequencer_->OnFrame( - list_[idx].first, list_[idx].second.c_str(), - list_[idx].second.size())); - list_.erase(list_.begin() + idx); + list_[index].first, list_[index].second.data(), + list_[index].second.size())); + list_.erase(list_.begin() + index); } } @@ -397,13 +389,14 @@ TEST_F(QuicSequencerRandomTest, RandomFramesDroppingNoBackup) { } while (list_.size() != 0) { - int idx = OneToN(list_.size()) - 1; - LOG(ERROR) << "Sending index " << idx << " " << list_[idx].second.c_str(); + int index = OneToN(list_.size()) - 1; + LOG(ERROR) << "Sending index " << index << " " + << list_[index].second.data(); bool acked = sequencer_->OnFrame( - list_[idx].first, list_[idx].second.c_str(), - list_[idx].second.size()); + list_[index].first, list_[index].second.data(), + list_[index].second.size()); if (acked) { - list_.erase(list_.begin() + idx); + list_.erase(list_.begin() + index); } } } diff --git a/net/quic/reliable_quic_stream.cc b/net/quic/reliable_quic_stream.cc index d9f9343..d3e7cf8 100644 --- a/net/quic/reliable_quic_stream.cc +++ b/net/quic/reliable_quic_stream.cc @@ -27,7 +27,7 @@ ReliableQuicStream::~ReliableQuicStream() { bool ReliableQuicStream::WillAcceptStreamFrame( const QuicStreamFrame& frame) const { if (read_side_closed_) { - return false; + return true; } if (frame.stream_id != id_) { LOG(ERROR) << "Error!"; @@ -39,10 +39,9 @@ bool ReliableQuicStream::WillAcceptStreamFrame( bool ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { DCHECK_EQ(frame.stream_id, id_); if (read_side_closed_) { - // This can only happen if a client sends data after sending a fin or stream - // reset. - Close(QUIC_STREAM_DATA_AFTER_TERMINATION); - return false; + DLOG(INFO) << "Ignoring frame " << frame.stream_id; + // We don't want to be reading: blackhole the data. + return true; } bool accepted = sequencer_.OnStreamFrame(frame); @@ -106,6 +105,9 @@ int ReliableQuicStream::WriteData(StringPiece data, bool fin) { } void ReliableQuicStream::CloseReadSide() { + if (read_side_closed_) { + return; + } DLOG(INFO) << "Done reading from stream " << id(); read_side_closed_ = true; @@ -115,6 +117,9 @@ void ReliableQuicStream::CloseReadSide() { } void ReliableQuicStream::CloseWriteSide() { + if (write_side_closed_) { + return; + } DLOG(INFO) << "Done writing to stream " << id(); write_side_closed_ = true; diff --git a/net/quic/reliable_quic_stream.h b/net/quic/reliable_quic_stream.h index 2457bc0..653b7bb 100644 --- a/net/quic/reliable_quic_stream.h +++ b/net/quic/reliable_quic_stream.h @@ -22,7 +22,7 @@ class NET_EXPORT_PRIVATE ReliableQuicStream { virtual ~ReliableQuicStream(); bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const; - bool OnStreamFrame(const QuicStreamFrame& frame); + virtual bool OnStreamFrame(const QuicStreamFrame& frame); // Called when we get a stream reset from the client. // The rst will be passed through the sequencer, which will call @@ -52,6 +52,9 @@ class NET_EXPORT_PRIVATE ReliableQuicStream { QuicErrorCode error() const { return error_; } + bool read_side_closed() const { return read_side_closed_; } + bool write_side_closed() const { return write_side_closed_; } + protected: virtual int WriteData(base::StringPiece data, bool fin); // Close the read side of the socket. Further frames will not be accepted. @@ -61,8 +64,6 @@ class NET_EXPORT_PRIVATE ReliableQuicStream { QuicSession* session() { return session_; } - bool write_side_closed() { return write_side_closed_; } - private: friend class ReliableQuicStreamPeer; diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc index 7664589..1a08893 100644 --- a/net/quic/test_tools/quic_test_utils.cc +++ b/net/quic/test_tools/quic_test_utils.cc @@ -11,6 +11,7 @@ using std::min; using std::string; namespace net { + namespace test { MockFramerVisitor::MockFramerVisitor() { @@ -19,7 +20,8 @@ MockFramerVisitor::MockFramerVisitor() { .WillByDefault(testing::Return(true)); } -MockFramerVisitor::~MockFramerVisitor() {} +MockFramerVisitor::~MockFramerVisitor() { +} bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) { return true; @@ -58,6 +60,37 @@ MockScheduler::MockScheduler() MockScheduler::~MockScheduler() { } +MockConnection::MockConnection(QuicGuid guid, IPEndPoint address) + : QuicConnection(guid, address, new MockHelper()) { +} + +MockConnection::~MockConnection() { +} + +PacketSavingConnection::PacketSavingConnection(QuicGuid guid, + IPEndPoint address) + : MockConnection(guid, address) { +} + +PacketSavingConnection::~PacketSavingConnection() { +} + +bool PacketSavingConnection::SendPacket(QuicPacketSequenceNumber number, + QuicPacket* packet, + bool should_resend, + bool force, + bool is_retransmit) { + packets_.push_back(packet); + return true; +} + +MockSession::MockSession(QuicConnection* connection, bool is_server) + : QuicSession(connection, is_server) { +} + +MockSession::~MockSession() { +} + namespace { string HexDumpWithMarks(const char* data, int length, @@ -155,7 +188,7 @@ QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { header.fec_group = 0; QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, - data->AsStringPiece()); + data->AsStringPiece()); QuicFrame frame(&stream_frame); QuicFrames frames; @@ -165,37 +198,6 @@ QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { return packet; } -MockConnection::MockConnection(QuicGuid guid, IPEndPoint address) - : QuicConnection(guid, address, new MockHelper()) { -} - -MockConnection::~MockConnection() { -} - -PacketSavingConnection::PacketSavingConnection(QuicGuid guid, - IPEndPoint address) - : MockConnection(guid, address) { -} - -PacketSavingConnection::~PacketSavingConnection() { -} - -bool PacketSavingConnection::SendPacket(QuicPacketSequenceNumber number, - QuicPacket* packet, - bool should_resend, - bool force, - bool is_retransmit) { - packets_.push_back(packet); - return true; -} - -MockSession::MockSession(QuicConnection* connection, bool is_server) - : QuicSession(connection, is_server) { -} - -MockSession::~MockSession() { -} - } // namespace test } // namespace net diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h index 59f2632..8ae5582 100644 --- a/net/quic/test_tools/quic_test_utils.h +++ b/net/quic/test_tools/quic_test_utils.h @@ -40,6 +40,7 @@ class MockFramerVisitor : public QuicFramerVisitorInterface { MOCK_METHOD2(OnPacket, void(const IPEndPoint& self_address, const IPEndPoint& peer_address)); MOCK_METHOD0(OnRevivedPacket, void()); + // The constructor set this up to return true by default. MOCK_METHOD1(OnPacketHeader, bool(const QuicPacketHeader& header)); MOCK_METHOD1(OnFecProtectedPayload, void(base::StringPiece payload)); MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame& frame)); @@ -111,20 +112,6 @@ class MockConnectionVisitor : public QuicConnectionVisitorInterface { DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); }; -class MockScheduler : public QuicSendScheduler { - public: - MockScheduler(); - virtual ~MockScheduler(); - - MOCK_METHOD1(TimeUntilSend, QuicTime::Delta(bool)); - MOCK_METHOD1(OnIncomingAckFrame, void(const QuicAckFrame&)); - MOCK_METHOD3(SentPacket, void(QuicPacketSequenceNumber, size_t, bool)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockScheduler); -}; - - class MockHelper : public QuicConnectionHelperInterface { public: MockHelper(); @@ -132,9 +119,7 @@ class MockHelper : public QuicConnectionHelperInterface { MOCK_METHOD1(SetConnection, void(QuicConnection* connection)); QuicClock* GetClock(); - MOCK_METHOD4(WritePacketToWire, int(QuicPacketSequenceNumber number, - const QuicEncryptedPacket& packet, - bool resend, + MOCK_METHOD2(WritePacketToWire, int(const QuicEncryptedPacket& packet, int* error)); MOCK_METHOD2(SetResendAlarm, void(QuicPacketSequenceNumber sequence_number, QuicTime::Delta delay)); @@ -186,9 +171,9 @@ class PacketSavingConnection : public MockConnection { class MockSession : public QuicSession { public: MockSession(QuicConnection* connection, bool is_server); - ~MockSession(); + virtual ~MockSession(); - MOCK_METHOD4(OnPacket, bool(const IPEndPoint& seld_address, + MOCK_METHOD4(OnPacket, bool(const IPEndPoint& self_address, const IPEndPoint& peer_address, const QuicPacketHeader& header, const std::vector<QuicStreamFrame>& frame)); @@ -207,6 +192,19 @@ class MockSession : public QuicSession { DISALLOW_COPY_AND_ASSIGN(MockSession); }; +class MockScheduler : public QuicSendScheduler { + public: + MockScheduler(); + virtual ~MockScheduler(); + + MOCK_METHOD1(TimeUntilSend, QuicTime::Delta(bool)); + MOCK_METHOD1(OnIncomingAckFrame, void(const QuicAckFrame&)); + MOCK_METHOD3(SentPacket, void(QuicPacketSequenceNumber, size_t, bool)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockScheduler); +}; + } // namespace test } // namespace net |