| 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_QUIC_BUFFERED_PACKET_STORE_H_ | 5 #ifndef NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
| 6 #define NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ | 6 #define NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
| 7 | 7 |
| 8 #include "net/base/ip_address.h" | 8 #include "net/base/ip_address.h" |
| 9 #include "net/base/linked_hash_map.h" | 9 #include "net/base/linked_hash_map.h" |
| 10 #include "net/quic/quic_alarm.h" | 10 #include "net/quic/quic_alarm.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class NET_EXPORT_PRIVATE QuicBufferedPacketStore { | 25 class NET_EXPORT_PRIVATE QuicBufferedPacketStore { |
| 26 public: | 26 public: |
| 27 enum EnqueuePacketResult { | 27 enum EnqueuePacketResult { |
| 28 SUCCESS = 0, | 28 SUCCESS = 0, |
| 29 TOO_MANY_PACKETS, // Too many packets stored up for a certain connection. | 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. | 30 TOO_MANY_CONNECTIONS // Too many connections stored up in the store. |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // A packets with client/server address. | 33 // A packets with client/server address. |
| 34 struct NET_EXPORT_PRIVATE BufferedPacket { | 34 struct NET_EXPORT_PRIVATE BufferedPacket { |
| 35 BufferedPacket(std::unique_ptr<QuicEncryptedPacket> packet, | 35 BufferedPacket(std::unique_ptr<QuicReceivedPacket> packet, |
| 36 IPEndPoint server_address, | 36 IPEndPoint server_address, |
| 37 IPEndPoint client_address); | 37 IPEndPoint client_address); |
| 38 BufferedPacket(BufferedPacket&& other); | 38 BufferedPacket(BufferedPacket&& other); |
| 39 | 39 |
| 40 BufferedPacket& operator=(BufferedPacket&& other); | 40 BufferedPacket& operator=(BufferedPacket&& other); |
| 41 | 41 |
| 42 ~BufferedPacket(); | 42 ~BufferedPacket(); |
| 43 | 43 |
| 44 std::unique_ptr<QuicEncryptedPacket> packet; | 44 std::unique_ptr<QuicReceivedPacket> packet; |
| 45 IPEndPoint server_address; | 45 IPEndPoint server_address; |
| 46 IPEndPoint client_address; | 46 IPEndPoint client_address; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // A queue of BufferedPackets for a connection. | 49 // A queue of BufferedPackets for a connection. |
| 50 struct NET_EXPORT_PRIVATE BufferedPacketList { | 50 struct NET_EXPORT_PRIVATE BufferedPacketList { |
| 51 BufferedPacketList(); | 51 BufferedPacketList(); |
| 52 BufferedPacketList(BufferedPacketList&& other); | 52 BufferedPacketList(BufferedPacketList&& other); |
| 53 | 53 |
| 54 BufferedPacketList& operator=(BufferedPacketList&& other); | 54 BufferedPacketList& operator=(BufferedPacketList&& other); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 class NET_EXPORT_PRIVATE VisitorInterface { | 65 class NET_EXPORT_PRIVATE VisitorInterface { |
| 66 public: | 66 public: |
| 67 virtual ~VisitorInterface() {} | 67 virtual ~VisitorInterface() {} |
| 68 | 68 |
| 69 // Called for each expired connection when alarm fires. | 69 // Called for each expired connection when alarm fires. |
| 70 virtual void OnExpiredPackets(QuicConnectionId connection_id, | 70 virtual void OnExpiredPackets(QuicConnectionId connection_id, |
| 71 BufferedPacketList early_arrived_packets) = 0; | 71 BufferedPacketList early_arrived_packets) = 0; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 QuicBufferedPacketStore(VisitorInterface* vistor, | 74 QuicBufferedPacketStore(VisitorInterface* vistor, |
| 75 QuicClock* clock, | 75 const QuicClock* clock, |
| 76 QuicAlarmFactory* alarm_factory); | 76 QuicAlarmFactory* alarm_factory); |
| 77 | 77 |
| 78 QuicBufferedPacketStore(const QuicBufferedPacketStore&) = delete; | 78 QuicBufferedPacketStore(const QuicBufferedPacketStore&) = delete; |
| 79 | 79 |
| 80 ~QuicBufferedPacketStore(); | 80 ~QuicBufferedPacketStore(); |
| 81 | 81 |
| 82 QuicBufferedPacketStore& operator=(const QuicBufferedPacketStore&) = delete; | 82 QuicBufferedPacketStore& operator=(const QuicBufferedPacketStore&) = delete; |
| 83 | 83 |
| 84 // Adds a copy of packet into packet queue for given connection. | 84 // Adds a copy of packet into packet queue for given connection. |
| 85 EnqueuePacketResult EnqueuePacket(QuicConnectionId connection_id, | 85 EnqueuePacketResult EnqueuePacket(QuicConnectionId connection_id, |
| 86 const QuicEncryptedPacket& packet, | 86 const QuicReceivedPacket& packet, |
| 87 IPEndPoint server_address, | 87 IPEndPoint server_address, |
| 88 IPEndPoint client_address); | 88 IPEndPoint client_address); |
| 89 | 89 |
| 90 // Returns true if there are any packets buffered for |connection_id|. |
| 91 bool HasBufferedPackets(QuicConnectionId connection_id) const; |
| 92 |
| 90 // Returns the list of buffered packets for |connection_id| and removes them | 93 // 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 | 94 // from the store. Returns an empty list if no early arrived packets for this |
| 92 // connection are present. | 95 // connection are present. |
| 93 std::list<BufferedPacket> DeliverPackets(QuicConnectionId connection_id); | 96 std::list<BufferedPacket> DeliverPackets(QuicConnectionId connection_id); |
| 94 | 97 |
| 95 // Examines how long packets have been buffered in the store for each | 98 // 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 | 99 // connection. If they stay too long, removes them for new coming packets and |
| 97 // calls |visitor_|'s OnPotentialConnectionExpire(). | 100 // calls |visitor_|'s OnPotentialConnectionExpire(). |
| 98 // Resets the alarm at the end. | 101 // Resets the alarm at the end. |
| 99 void OnExpirationTimeout(); | 102 void OnExpirationTimeout(); |
| 100 | 103 |
| 101 private: | 104 private: |
| 102 friend class test::QuicBufferedPacketStorePeer; | 105 friend class test::QuicBufferedPacketStorePeer; |
| 103 | 106 |
| 104 // A map to store packet queues with creation time for each connection. | 107 // A map to store packet queues with creation time for each connection. |
| 105 BufferedPacketMap undecryptable_packets_; | 108 BufferedPacketMap undecryptable_packets_; |
| 106 | 109 |
| 107 // The max time the packets of a connection can be buffer in the store. | 110 // The max time the packets of a connection can be buffer in the store. |
| 108 QuicTime::Delta connection_life_span_; | 111 QuicTime::Delta connection_life_span_; |
| 109 | 112 |
| 110 VisitorInterface* visitor_; // Unowned. | 113 VisitorInterface* visitor_; // Unowned. |
| 111 | 114 |
| 112 QuicClock* clock_; // Unowned. | 115 const QuicClock* clock_; // Unowned. |
| 113 | 116 |
| 114 // This alarm fires every |connection_life_span_| to clean up | 117 // This alarm fires every |connection_life_span_| to clean up |
| 115 // packets staying in the store for too long. | 118 // packets staying in the store for too long. |
| 116 std::unique_ptr<QuicAlarm> expiration_alarm_; | 119 std::unique_ptr<QuicAlarm> expiration_alarm_; |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 } // namespace net | 122 } // namespace net |
| 120 | 123 |
| 121 #endif // NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ | 124 #endif // NET_QUIC_QUIC_BUFFERED_PACKET_STORE_H_ |
| OLD | NEW |