| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/core/quic_buffered_packet_store.h" | 5 #include "net/quic/core/quic_buffered_packet_store.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | |
| 8 #include "net/quic/core/quic_flags.h" | 7 #include "net/quic/core/quic_flags.h" |
| 9 #include "net/quic/platform/api/quic_bug_tracker.h" | 8 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 10 | 9 #include "net/quic/platform/api/quic_map_util.h" |
| 11 using base::ContainsKey; | |
| 12 | 10 |
| 13 namespace net { | 11 namespace net { |
| 14 | 12 |
| 15 typedef QuicBufferedPacketStore::BufferedPacket BufferedPacket; | 13 typedef QuicBufferedPacketStore::BufferedPacket BufferedPacket; |
| 16 typedef QuicBufferedPacketStore::BufferedPacketList BufferedPacketList; | 14 typedef QuicBufferedPacketStore::BufferedPacketList BufferedPacketList; |
| 17 typedef QuicBufferedPacketStore::EnqueuePacketResult EnqueuePacketResult; | 15 typedef QuicBufferedPacketStore::EnqueuePacketResult EnqueuePacketResult; |
| 18 | 16 |
| 19 // Max number of connections this store can keep track. | 17 // Max number of connections this store can keep track. |
| 20 static const size_t kDefaultMaxConnectionsInStore = 100; | 18 static const size_t kDefaultMaxConnectionsInStore = 100; |
| 21 // Up to half of the capacity can be used for storing non-CHLO packets. | 19 // Up to half of the capacity can be used for storing non-CHLO packets. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 QuicBufferedPacketStore::~QuicBufferedPacketStore() {} | 76 QuicBufferedPacketStore::~QuicBufferedPacketStore() {} |
| 79 | 77 |
| 80 EnqueuePacketResult QuicBufferedPacketStore::EnqueuePacket( | 78 EnqueuePacketResult QuicBufferedPacketStore::EnqueuePacket( |
| 81 QuicConnectionId connection_id, | 79 QuicConnectionId connection_id, |
| 82 const QuicReceivedPacket& packet, | 80 const QuicReceivedPacket& packet, |
| 83 QuicSocketAddress server_address, | 81 QuicSocketAddress server_address, |
| 84 QuicSocketAddress client_address, | 82 QuicSocketAddress client_address, |
| 85 bool is_chlo) { | 83 bool is_chlo) { |
| 86 QUIC_BUG_IF(!FLAGS_quic_allow_chlo_buffering) | 84 QUIC_BUG_IF(!FLAGS_quic_allow_chlo_buffering) |
| 87 << "Shouldn't buffer packets if disabled via flag."; | 85 << "Shouldn't buffer packets if disabled via flag."; |
| 88 QUIC_BUG_IF(is_chlo && ContainsKey(connections_with_chlo_, connection_id)) | 86 QUIC_BUG_IF(is_chlo && QuicContainsKey(connections_with_chlo_, connection_id)) |
| 89 << "Shouldn't buffer duplicated CHLO on connection " << connection_id; | 87 << "Shouldn't buffer duplicated CHLO on connection " << connection_id; |
| 90 | 88 |
| 91 if (!ContainsKey(undecryptable_packets_, connection_id) && | 89 if (!QuicContainsKey(undecryptable_packets_, connection_id) && |
| 92 ShouldBufferPacket(is_chlo)) { | 90 ShouldBufferPacket(is_chlo)) { |
| 93 // Drop the packet if the upper limit of undecryptable packets has been | 91 // Drop the packet if the upper limit of undecryptable packets has been |
| 94 // reached or the whole capacity of the store has been reached. | 92 // reached or the whole capacity of the store has been reached. |
| 95 return TOO_MANY_CONNECTIONS; | 93 return TOO_MANY_CONNECTIONS; |
| 96 } else if (!ContainsKey(undecryptable_packets_, connection_id)) { | 94 } else if (!QuicContainsKey(undecryptable_packets_, connection_id)) { |
| 97 undecryptable_packets_.emplace( | 95 undecryptable_packets_.emplace( |
| 98 std::make_pair(connection_id, BufferedPacketList())); | 96 std::make_pair(connection_id, BufferedPacketList())); |
| 99 } | 97 } |
| 100 CHECK(ContainsKey(undecryptable_packets_, connection_id)); | 98 CHECK(QuicContainsKey(undecryptable_packets_, connection_id)); |
| 101 BufferedPacketList& queue = | 99 BufferedPacketList& queue = |
| 102 undecryptable_packets_.find(connection_id)->second; | 100 undecryptable_packets_.find(connection_id)->second; |
| 103 | 101 |
| 104 if (!is_chlo) { | 102 if (!is_chlo) { |
| 105 // If current packet is not CHLO, it might not be buffered because store | 103 // If current packet is not CHLO, it might not be buffered because store |
| 106 // only buffers certain number of undecryptable packets per connection. | 104 // only buffers certain number of undecryptable packets per connection. |
| 107 size_t num_non_chlo_packets = | 105 size_t num_non_chlo_packets = |
| 108 ContainsKey(connections_with_chlo_, connection_id) | 106 QuicContainsKey(connections_with_chlo_, connection_id) |
| 109 ? (queue.buffered_packets.size() - 1) | 107 ? (queue.buffered_packets.size() - 1) |
| 110 : queue.buffered_packets.size(); | 108 : queue.buffered_packets.size(); |
| 111 if (num_non_chlo_packets >= kDefaultMaxUndecryptablePackets) { | 109 if (num_non_chlo_packets >= kDefaultMaxUndecryptablePackets) { |
| 112 // If there are kMaxBufferedPacketsPerConnection packets buffered up for | 110 // If there are kMaxBufferedPacketsPerConnection packets buffered up for |
| 113 // this connection, drop the current packet. | 111 // this connection, drop the current packet. |
| 114 return TOO_MANY_PACKETS; | 112 return TOO_MANY_PACKETS; |
| 115 } | 113 } |
| 116 } | 114 } |
| 117 | 115 |
| 118 if (queue.buffered_packets.empty()) { | 116 if (queue.buffered_packets.empty()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 } else { | 129 } else { |
| 132 // Buffer non-CHLO packets in arrival order. | 130 // Buffer non-CHLO packets in arrival order. |
| 133 queue.buffered_packets.push_back(std::move(new_entry)); | 131 queue.buffered_packets.push_back(std::move(new_entry)); |
| 134 } | 132 } |
| 135 MaybeSetExpirationAlarm(); | 133 MaybeSetExpirationAlarm(); |
| 136 return SUCCESS; | 134 return SUCCESS; |
| 137 } | 135 } |
| 138 | 136 |
| 139 bool QuicBufferedPacketStore::HasBufferedPackets( | 137 bool QuicBufferedPacketStore::HasBufferedPackets( |
| 140 QuicConnectionId connection_id) const { | 138 QuicConnectionId connection_id) const { |
| 141 return ContainsKey(undecryptable_packets_, connection_id); | 139 return QuicContainsKey(undecryptable_packets_, connection_id); |
| 142 } | 140 } |
| 143 | 141 |
| 144 bool QuicBufferedPacketStore::HasChlosBuffered() const { | 142 bool QuicBufferedPacketStore::HasChlosBuffered() const { |
| 145 return !connections_with_chlo_.empty(); | 143 return !connections_with_chlo_.empty(); |
| 146 } | 144 } |
| 147 | 145 |
| 148 std::list<BufferedPacket> QuicBufferedPacketStore::DeliverPackets( | 146 std::list<BufferedPacket> QuicBufferedPacketStore::DeliverPackets( |
| 149 QuicConnectionId connection_id) { | 147 QuicConnectionId connection_id) { |
| 150 std::list<BufferedPacket> packets_to_deliver; | 148 std::list<BufferedPacket> packets_to_deliver; |
| 151 auto it = undecryptable_packets_.find(connection_id); | 149 auto it = undecryptable_packets_.find(connection_id); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 *connection_id = connections_with_chlo_.front().first; | 209 *connection_id = connections_with_chlo_.front().first; |
| 212 connections_with_chlo_.pop_front(); | 210 connections_with_chlo_.pop_front(); |
| 213 | 211 |
| 214 std::list<BufferedPacket> packets = DeliverPackets(*connection_id); | 212 std::list<BufferedPacket> packets = DeliverPackets(*connection_id); |
| 215 DCHECK(!packets.empty()) << "Try to deliver connectons without CHLO"; | 213 DCHECK(!packets.empty()) << "Try to deliver connectons without CHLO"; |
| 216 return packets; | 214 return packets; |
| 217 } | 215 } |
| 218 | 216 |
| 219 bool QuicBufferedPacketStore::HasChloForConnection( | 217 bool QuicBufferedPacketStore::HasChloForConnection( |
| 220 QuicConnectionId connection_id) { | 218 QuicConnectionId connection_id) { |
| 221 return ContainsKey(connections_with_chlo_, connection_id); | 219 return QuicContainsKey(connections_with_chlo_, connection_id); |
| 222 } | 220 } |
| 223 | 221 |
| 224 } // namespace net | 222 } // namespace net |
| OLD | NEW |