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 #ifndef NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ |
6 #define NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ | 6 #define NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ |
7 | 7 |
8 #include "net/base/linked_hash_map.h" | 8 #include "net/base/linked_hash_map.h" |
9 #include "net/base/net_export.h" | |
10 #include "net/quic/core/quic_alarm.h" | 9 #include "net/quic/core/quic_alarm.h" |
11 #include "net/quic/core/quic_alarm_factory.h" | 10 #include "net/quic/core/quic_alarm_factory.h" |
12 #include "net/quic/core/quic_packets.h" | 11 #include "net/quic/core/quic_packets.h" |
13 #include "net/quic/core/quic_time.h" | 12 #include "net/quic/core/quic_time.h" |
14 #include "net/quic/platform/api/quic_clock.h" | 13 #include "net/quic/platform/api/quic_clock.h" |
| 14 #include "net/quic/platform/api/quic_export.h" |
15 #include "net/quic/platform/api/quic_socket_address.h" | 15 #include "net/quic/platform/api/quic_socket_address.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 namespace test { | 19 namespace test { |
20 class QuicBufferedPacketStorePeer; | 20 class QuicBufferedPacketStorePeer; |
21 } // namespace test | 21 } // namespace test |
22 | 22 |
23 // This class buffers packets for each connection until either | 23 // This class buffers packets for each connection until either |
24 // 1) They are requested to be delivered via | 24 // 1) They are requested to be delivered via |
25 // DeliverPacket()/DeliverPacketsForNextConnection(), or | 25 // DeliverPacket()/DeliverPacketsForNextConnection(), or |
26 // 2) They expire after exceeding their lifetime in the store. | 26 // 2) They expire after exceeding their lifetime in the store. |
27 // | 27 // |
28 // It can only buffer packets on certain number of connections. It has two pools | 28 // It can only buffer packets on certain number of connections. It has two pools |
29 // of connections: connections with CHLO buffered and those without CHLO. The | 29 // of connections: connections with CHLO buffered and those without CHLO. The |
30 // latter has its own upper limit along with the max number of connections this | 30 // latter has its own upper limit along with the max number of connections this |
31 // store can hold. The former pool can grow till this store is full. | 31 // store can hold. The former pool can grow till this store is full. |
32 class NET_EXPORT_PRIVATE QuicBufferedPacketStore { | 32 class QUIC_EXPORT_PRIVATE QuicBufferedPacketStore { |
33 public: | 33 public: |
34 enum EnqueuePacketResult { | 34 enum EnqueuePacketResult { |
35 SUCCESS = 0, | 35 SUCCESS = 0, |
36 TOO_MANY_PACKETS, // Too many packets stored up for a certain connection. | 36 TOO_MANY_PACKETS, // Too many packets stored up for a certain connection. |
37 TOO_MANY_CONNECTIONS // Too many connections stored up in the store. | 37 TOO_MANY_CONNECTIONS // Too many connections stored up in the store. |
38 }; | 38 }; |
39 | 39 |
40 // A packets with client/server address. | 40 // A packets with client/server address. |
41 struct NET_EXPORT_PRIVATE BufferedPacket { | 41 struct QUIC_EXPORT_PRIVATE BufferedPacket { |
42 BufferedPacket(std::unique_ptr<QuicReceivedPacket> packet, | 42 BufferedPacket(std::unique_ptr<QuicReceivedPacket> packet, |
43 QuicSocketAddress server_address, | 43 QuicSocketAddress server_address, |
44 QuicSocketAddress client_address); | 44 QuicSocketAddress client_address); |
45 BufferedPacket(BufferedPacket&& other); | 45 BufferedPacket(BufferedPacket&& other); |
46 | 46 |
47 BufferedPacket& operator=(BufferedPacket&& other); | 47 BufferedPacket& operator=(BufferedPacket&& other); |
48 | 48 |
49 ~BufferedPacket(); | 49 ~BufferedPacket(); |
50 | 50 |
51 std::unique_ptr<QuicReceivedPacket> packet; | 51 std::unique_ptr<QuicReceivedPacket> packet; |
52 QuicSocketAddress server_address; | 52 QuicSocketAddress server_address; |
53 QuicSocketAddress client_address; | 53 QuicSocketAddress client_address; |
54 }; | 54 }; |
55 | 55 |
56 // A queue of BufferedPackets for a connection. | 56 // A queue of BufferedPackets for a connection. |
57 struct NET_EXPORT_PRIVATE BufferedPacketList { | 57 struct QUIC_EXPORT_PRIVATE BufferedPacketList { |
58 BufferedPacketList(); | 58 BufferedPacketList(); |
59 BufferedPacketList(BufferedPacketList&& other); | 59 BufferedPacketList(BufferedPacketList&& other); |
60 | 60 |
61 BufferedPacketList& operator=(BufferedPacketList&& other); | 61 BufferedPacketList& operator=(BufferedPacketList&& other); |
62 | 62 |
63 ~BufferedPacketList(); | 63 ~BufferedPacketList(); |
64 | 64 |
65 std::list<BufferedPacket> buffered_packets; | 65 std::list<BufferedPacket> buffered_packets; |
66 QuicTime creation_time; | 66 QuicTime creation_time; |
67 }; | 67 }; |
68 | 68 |
69 typedef linked_hash_map<QuicConnectionId, BufferedPacketList> | 69 typedef linked_hash_map<QuicConnectionId, BufferedPacketList> |
70 BufferedPacketMap; | 70 BufferedPacketMap; |
71 | 71 |
72 class NET_EXPORT_PRIVATE VisitorInterface { | 72 class QUIC_EXPORT_PRIVATE VisitorInterface { |
73 public: | 73 public: |
74 virtual ~VisitorInterface() {} | 74 virtual ~VisitorInterface() {} |
75 | 75 |
76 // Called for each expired connection when alarm fires. | 76 // Called for each expired connection when alarm fires. |
77 virtual void OnExpiredPackets(QuicConnectionId connection_id, | 77 virtual void OnExpiredPackets(QuicConnectionId connection_id, |
78 BufferedPacketList early_arrived_packets) = 0; | 78 BufferedPacketList early_arrived_packets) = 0; |
79 }; | 79 }; |
80 | 80 |
81 QuicBufferedPacketStore(VisitorInterface* vistor, | 81 QuicBufferedPacketStore(VisitorInterface* vistor, |
82 const QuicClock* clock, | 82 const QuicClock* clock, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 std::unique_ptr<QuicAlarm> expiration_alarm_; | 152 std::unique_ptr<QuicAlarm> expiration_alarm_; |
153 | 153 |
154 // Keeps track of connection with CHLO buffered up already and the order they | 154 // Keeps track of connection with CHLO buffered up already and the order they |
155 // arrive. | 155 // arrive. |
156 linked_hash_map<QuicConnectionId, bool> connections_with_chlo_; | 156 linked_hash_map<QuicConnectionId, bool> connections_with_chlo_; |
157 }; | 157 }; |
158 | 158 |
159 } // namespace net | 159 } // namespace net |
160 | 160 |
161 #endif // NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ | 161 #endif // NET_QUIC_CORE_QUIC_BUFFERED_PACKET_STORE_H_ |
OLD | NEW |