Chromium Code Reviews| 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 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 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 virtual ~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 std::list of buffered packets for |connection_id| and removes | |
| 91 // them | |
| 92 // from the store. Returns an empty std::list if no early arrived packets for | |
| 93 // this | |
|
Ryan Hamilton
2016/05/26 22:17:36
nit: I'm not sure if this in the internal version
| |
| 94 // connection are present. | |
| 95 virtual std::list<BufferedPacket> DeliverPackets( | |
| 96 QuicConnectionId connection_id); | |
| 97 | |
| 98 // Examines how long packets have been buffered in the store for each | |
| 99 // connection. If they stay too long, removes them for new coming packets and | |
| 100 // calls |visitor_|'s OnPotentialConnectionExpire(). | |
| 101 // Resets the alarm at the end. | |
| 102 void OnExpirationTimeout(); | |
| 103 | |
| 104 private: | |
| 105 friend class test::QuicBufferedPacketStorePeer; | |
| 106 | |
| 107 // A map to store packet queues with creation time for each connection. | |
| 108 BufferedPacketMap undecryptable_packets_; | |
| 109 | |
| 110 // The max time the packets of a connection can be buffer in the store. | |
| 111 QuicTime::Delta connection_life_span_; | |
| 112 | |
| 113 VisitorInterface* visitor_; // Unowned. | |
| 114 | |
| 115 QuicClock* clock_; // Unowned. | |
| 116 | |
| 117 // This alarm fires every |connection_life_span_| to clean up | |
| 118 // packets staying in the store for too long. | |
| 119 std::unique_ptr<QuicAlarm> expiration_alarm_; | |
| 120 }; | |
| 121 | |
| 122 } // namespace net | |
| 123 | |
| 124 #endif // NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ | |
| OLD | NEW |