OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
| 6 #define NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
| 7 |
| 8 #include "net/base/ip_address.h" |
| 9 #include "net/base/linked_hash_map.h" |
| 10 #include "net/quic/quic_alarm.h" |
| 11 #include "net/quic/quic_alarm_factory.h" |
| 12 #include "net/quic/quic_clock.h" |
| 13 #include "net/quic/quic_protocol.h" |
| 14 #include "net/quic/quic_time.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 namespace test { |
| 19 class QuicBufferedPacketStorePeer; |
| 20 } // namespace test |
| 21 |
| 22 // This class buffers undeliverable packets for each connection until either |
| 23 // 1) They are requested to be delivered via DeliverPacket(), or |
| 24 // 2) They expire after exceeding their lifetime in the store. |
| 25 class NET_EXPORT_PRIVATE QuicBufferedPacketStore { |
| 26 public: |
| 27 enum EnqueuePacketResult { |
| 28 SUCCESS = 0, |
| 29 TOO_MANY_PACKETS, // Too many packets stored up for a certain connection. |
| 30 TOO_MANY_CONNECTIONS // Too many connections stored up in the store. |
| 31 }; |
| 32 |
| 33 // A packets with client/server address. |
| 34 struct NET_EXPORT_PRIVATE BufferedPacket { |
| 35 BufferedPacket(std::unique_ptr<QuicEncryptedPacket> packet, |
| 36 IPEndPoint server_address, |
| 37 IPEndPoint client_address); |
| 38 BufferedPacket(BufferedPacket&& other); |
| 39 |
| 40 BufferedPacket& operator=(BufferedPacket&& other); |
| 41 |
| 42 ~BufferedPacket(); |
| 43 |
| 44 std::unique_ptr<QuicEncryptedPacket> packet; |
| 45 IPEndPoint server_address; |
| 46 IPEndPoint client_address; |
| 47 }; |
| 48 |
| 49 // A queue of BufferedPackets for a connection. |
| 50 struct NET_EXPORT_PRIVATE BufferedPacketList { |
| 51 BufferedPacketList(); |
| 52 BufferedPacketList(BufferedPacketList&& other); |
| 53 |
| 54 BufferedPacketList& operator=(BufferedPacketList&& other); |
| 55 |
| 56 ~BufferedPacketList(); |
| 57 |
| 58 std::list<BufferedPacket> buffered_packets; |
| 59 QuicTime creation_time; |
| 60 }; |
| 61 |
| 62 typedef linked_hash_map<QuicConnectionId, BufferedPacketList> |
| 63 BufferedPacketMap; |
| 64 |
| 65 class NET_EXPORT_PRIVATE VisitorInterface { |
| 66 public: |
| 67 virtual ~VisitorInterface() {} |
| 68 |
| 69 // Called for each expired connection when alarm fires. |
| 70 virtual void OnExpiredPackets(QuicConnectionId connection_id, |
| 71 BufferedPacketList early_arrived_packets) = 0; |
| 72 }; |
| 73 |
| 74 QuicBufferedPacketStore(VisitorInterface* vistor, |
| 75 QuicClock* clock, |
| 76 QuicAlarmFactory* alarm_factory); |
| 77 |
| 78 QuicBufferedPacketStore(const QuicBufferedPacketStore&) = delete; |
| 79 |
| 80 ~QuicBufferedPacketStore(); |
| 81 |
| 82 QuicBufferedPacketStore& operator=(const QuicBufferedPacketStore&) = delete; |
| 83 |
| 84 // Adds a copy of packet into packet queue for given connection. |
| 85 EnqueuePacketResult EnqueuePacket(QuicConnectionId connection_id, |
| 86 const QuicEncryptedPacket& packet, |
| 87 IPEndPoint server_address, |
| 88 IPEndPoint client_address); |
| 89 |
| 90 // Returns the list of buffered packets for |connection_id| and removes them |
| 91 // from the store. Returns an empty list if no early arrived packets for this |
| 92 // connection are present. |
| 93 std::list<BufferedPacket> DeliverPackets(QuicConnectionId connection_id); |
| 94 |
| 95 // Examines how long packets have been buffered in the store for each |
| 96 // connection. If they stay too long, removes them for new coming packets and |
| 97 // calls |visitor_|'s OnPotentialConnectionExpire(). |
| 98 // Resets the alarm at the end. |
| 99 void OnExpirationTimeout(); |
| 100 |
| 101 private: |
| 102 friend class test::QuicBufferedPacketStorePeer; |
| 103 |
| 104 // A map to store packet queues with creation time for each connection. |
| 105 BufferedPacketMap undecryptable_packets_; |
| 106 |
| 107 // The max time the packets of a connection can be buffer in the store. |
| 108 QuicTime::Delta connection_life_span_; |
| 109 |
| 110 VisitorInterface* visitor_; // Unowned. |
| 111 |
| 112 QuicClock* clock_; // Unowned. |
| 113 |
| 114 // This alarm fires every |connection_life_span_| to clean up |
| 115 // packets staying in the store for too long. |
| 116 std::unique_ptr<QuicAlarm> expiration_alarm_; |
| 117 }; |
| 118 |
| 119 } // namespace net |
| 120 |
| 121 #endif // NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
OLD | NEW |