blob: 447ab95bf680d04184d5664637c8c2af323cb233 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef QUICHE_QUIC_CORE_QUIC_COALESCED_PACKET_H_
#define QUICHE_QUIC_CORE_QUIC_COALESCED_PACKET_H_
#include "net/third_party/quiche/src/quic/core/quic_packets.h"
namespace quic {
// QuicCoalescedPacket is used to buffer multiple packets which can be coalesced
// into the same UDP datagram.
class QUIC_EXPORT_PRIVATE QuicCoalescedPacket {
public:
QuicCoalescedPacket();
~QuicCoalescedPacket();
// Returns true if |packet| is successfully coalesced with existing packets.
// Returns false otherwise.
bool MaybeCoalescePacket(const SerializedPacket& packet,
const QuicSocketAddress& self_address,
const QuicSocketAddress& peer_address,
QuicBufferAllocator* allocator,
QuicPacketLength current_max_packet_length);
// Clears this coalesced packet.
void Clear();
// Copies encrypted_buffers_ to |buffer| and sets |length_copied| to the
// copied amount. Returns false if copy fails (i.e., |buffer_len| is not
// enough).
bool CopyEncryptedBuffers(char* buffer,
size_t buffer_len,
size_t* length_copied) const;
std::string ToString(size_t serialized_length) const;
// Returns true if this coalesced packet contains packet of |level|.
bool ContainsPacketOfEncryptionLevel(EncryptionLevel level) const;
const SerializedPacket* initial_packet() const {
return initial_packet_.get();
}
const QuicSocketAddress& self_address() const { return self_address_; }
const QuicSocketAddress& peer_address() const { return peer_address_; }
QuicPacketLength length() const { return length_; }
QuicPacketLength max_packet_length() const { return max_packet_length_; }
private:
// self/peer addresses are set when trying to coalesce the first packet.
// Packets with different self/peer addresses cannot be coalesced.
QuicSocketAddress self_address_;
QuicSocketAddress peer_address_;
// Length of this coalesced packet.
QuicPacketLength length_;
// Max packet length. Do not try to coalesce packet when max packet length
// changes (e.g., with MTU discovery).
QuicPacketLength max_packet_length_;
// Copies of packets' encrypted buffers according to different encryption
// levels.
std::string encrypted_buffers_[NUM_ENCRYPTION_LEVELS];
// A copy of ENCRYPTION_INITIAL packet if this coalesced packet contains one.
// Null otherwise. Please note, the encrypted_buffer field is not copied. The
// frames are copied to allow it be re-serialized when this coalesced packet
// gets sent.
std::unique_ptr<SerializedPacket> initial_packet_;
};
} // namespace quic
#endif // QUICHE_QUIC_CORE_QUIC_COALESCED_PACKET_H_
|