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