Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: net/quic/core/quic_packets.h

Issue 2547583002: Landing Recent QUIC changes until Fri Nov 18 23:21:04 2016 +0000 (Closed)
Patch Set: Remove explicit HTTP/2 enum usage Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_packet_writer.h ('k') | net/quic/core/quic_packets.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_PROTOCOL_H_
6 #define NET_QUIC_QUIC_PROTOCOL_H_
7
8 #include <limits>
9 #include <list>
10 #include <memory>
11 #include <ostream>
12 #include <string>
13 #include <utility>
14 #include <vector>
15
16 #include "base/logging.h"
17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/strings/string_piece.h"
20 #include "net/base/int128.h"
21 #include "net/base/iovec.h"
22 #include "net/base/net_export.h"
23 #include "net/quic/core/frames/quic_frame.h"
24 #include "net/quic/core/quic_ack_listener_interface.h"
25 #include "net/quic/core/quic_bandwidth.h"
26 #include "net/quic/core/quic_constants.h"
27 #include "net/quic/core/quic_error_codes.h"
28 #include "net/quic/core/quic_time.h"
29 #include "net/quic/core/quic_types.h"
30 #include "net/quic/core/quic_versions.h"
31 #include "net/quic/platform/api/quic_socket_address.h"
32
33 namespace net {
34
35 class QuicPacket;
36 struct QuicPacketHeader;
37
38 // Size in bytes of the data packet header.
39 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version,
40 const QuicPacketHeader& header);
41
42 NET_EXPORT_PRIVATE size_t
43 GetPacketHeaderSize(QuicVersion version,
44 QuicConnectionIdLength connection_id_length,
45 bool include_version,
46 bool include_path_id,
47 bool include_diversification_nonce,
48 QuicPacketNumberLength packet_number_length);
49
50 // Index of the first byte in a QUIC packet of encrypted data.
51 NET_EXPORT_PRIVATE size_t
52 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header);
53
54 NET_EXPORT_PRIVATE size_t
55 GetStartOfEncryptedData(QuicVersion version,
56 QuicConnectionIdLength connection_id_length,
57 bool include_version,
58 bool include_path_id,
59 bool include_diversification_nonce,
60 QuicPacketNumberLength packet_number_length);
61
62 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
63 QuicPacketPublicHeader();
64 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
65 ~QuicPacketPublicHeader();
66
67 // Universal header. All QuicPacket headers will have a connection_id and
68 // public flags.
69 QuicConnectionId connection_id;
70 QuicConnectionIdLength connection_id_length;
71 bool multipath_flag;
72 bool reset_flag;
73 bool version_flag;
74 QuicPacketNumberLength packet_number_length;
75 QuicVersionVector versions;
76 // nonce contains an optional, 32-byte nonce value. If not included in the
77 // packet, |nonce| will be empty.
78 DiversificationNonce* nonce;
79 };
80
81 // Header for Data packets.
82 struct NET_EXPORT_PRIVATE QuicPacketHeader {
83 QuicPacketHeader();
84 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
85 QuicPacketHeader(const QuicPacketHeader& other);
86
87 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
88 const QuicPacketHeader& s);
89
90 QuicPacketPublicHeader public_header;
91 QuicPacketNumber packet_number;
92 QuicPathId path_id;
93 };
94
95 struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
96 QuicPublicResetPacket();
97 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
98
99 QuicPacketPublicHeader public_header;
100 QuicPublicResetNonceProof nonce_proof;
101 // TODO(fayang): remove rejected_packet_number when deprecating
102 // FLAGS_quic_remove_packet_number_from_public_reset.
103 QuicPacketNumber rejected_packet_number;
104 QuicSocketAddress client_address;
105 };
106
107 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
108
109 class NET_EXPORT_PRIVATE QuicData {
110 public:
111 QuicData(const char* buffer, size_t length);
112 QuicData(const char* buffer, size_t length, bool owns_buffer);
113 virtual ~QuicData();
114
115 base::StringPiece AsStringPiece() const {
116 return base::StringPiece(data(), length());
117 }
118
119 const char* data() const { return buffer_; }
120 size_t length() const { return length_; }
121
122 private:
123 const char* buffer_;
124 size_t length_;
125 bool owns_buffer_;
126
127 DISALLOW_COPY_AND_ASSIGN(QuicData);
128 };
129
130 class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
131 public:
132 // TODO(fayang): 4 fields from public header are passed in as arguments.
133 // Consider to add a convenience method which directly accepts the entire
134 // public header.
135 QuicPacket(char* buffer,
136 size_t length,
137 bool owns_buffer,
138 QuicConnectionIdLength connection_id_length,
139 bool includes_version,
140 bool includes_path_id,
141 bool includes_diversification_nonce,
142 QuicPacketNumberLength packet_number_length);
143
144 base::StringPiece AssociatedData(QuicVersion version) const;
145 base::StringPiece Plaintext(QuicVersion version) const;
146
147 char* mutable_data() { return buffer_; }
148
149 private:
150 char* buffer_;
151 const QuicConnectionIdLength connection_id_length_;
152 const bool includes_version_;
153 const bool includes_path_id_;
154 const bool includes_diversification_nonce_;
155 const QuicPacketNumberLength packet_number_length_;
156
157 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
158 };
159
160 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
161 public:
162 QuicEncryptedPacket(const char* buffer, size_t length);
163 QuicEncryptedPacket(const char* buffer, size_t length, bool owns_buffer);
164
165 // Clones the packet into a new packet which owns the buffer.
166 std::unique_ptr<QuicEncryptedPacket> Clone() const;
167
168 // By default, gtest prints the raw bytes of an object. The bool data
169 // member (in the base class QuicData) causes this object to have padding
170 // bytes, which causes the default gtest object printer to read
171 // uninitialize memory. So we need to teach gtest how to print this object.
172 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
173 std::ostream& os,
174 const QuicEncryptedPacket& s);
175
176 private:
177 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
178 };
179
180 // A received encrypted QUIC packet, with a recorded time of receipt.
181 class NET_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket {
182 public:
183 QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time);
184 QuicReceivedPacket(const char* buffer,
185 size_t length,
186 QuicTime receipt_time,
187 bool owns_buffer);
188 QuicReceivedPacket(const char* buffer,
189 size_t length,
190 QuicTime receipt_time,
191 bool owns_buffer,
192 int ttl,
193 bool ttl_valid);
194
195 // Clones the packet into a new packet which owns the buffer.
196 std::unique_ptr<QuicReceivedPacket> Clone() const;
197
198 // Returns the time at which the packet was received.
199 QuicTime receipt_time() const { return receipt_time_; }
200
201 // This is the TTL of the packet, assuming ttl_vaild_ is true.
202 int ttl() const { return ttl_; }
203
204 // By default, gtest prints the raw bytes of an object. The bool data
205 // member (in the base class QuicData) causes this object to have padding
206 // bytes, which causes the default gtest object printer to read
207 // uninitialize memory. So we need to teach gtest how to print this object.
208 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
209 std::ostream& os,
210 const QuicReceivedPacket& s);
211
212 private:
213 const QuicTime receipt_time_;
214 int ttl_;
215
216 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacket);
217 };
218
219 struct NET_EXPORT_PRIVATE SerializedPacket {
220 SerializedPacket(QuicPathId path_id,
221 QuicPacketNumber packet_number,
222 QuicPacketNumberLength packet_number_length,
223 const char* encrypted_buffer,
224 QuicPacketLength encrypted_length,
225 bool has_ack,
226 bool has_stop_waiting);
227 SerializedPacket(const SerializedPacket& other);
228 ~SerializedPacket();
229
230 // Not owned.
231 const char* encrypted_buffer;
232 QuicPacketLength encrypted_length;
233 QuicFrames retransmittable_frames;
234 IsHandshake has_crypto_handshake;
235 // -1: full padding to the end of a max-sized packet
236 // 0: no padding
237 // otherwise: only pad up to num_padding_bytes bytes
238 int16_t num_padding_bytes;
239 QuicPathId path_id;
240 QuicPacketNumber packet_number;
241 QuicPacketNumberLength packet_number_length;
242 EncryptionLevel encryption_level;
243 bool has_ack;
244 bool has_stop_waiting;
245 TransmissionType transmission_type;
246 QuicPathId original_path_id;
247 QuicPacketNumber original_packet_number;
248
249 // Optional notifiers which will be informed when this packet has been ACKed.
250 std::list<AckListenerWrapper> listeners;
251 };
252
253 // Deletes and clears all the frames and the packet from serialized packet.
254 NET_EXPORT_PRIVATE void ClearSerializedPacket(
255 SerializedPacket* serialized_packet);
256
257 // Allocates a new char[] of size |packet.encrypted_length| and copies in
258 // |packet.encrypted_buffer|.
259 NET_EXPORT_PRIVATE char* CopyBuffer(const SerializedPacket& packet);
260
261 } // namespace net
262
263 #endif // NET_QUIC_QUIC_PROTOCOL_H_
OLDNEW
« no previous file with comments | « net/quic/core/quic_packet_writer.h ('k') | net/quic/core/quic_packets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698