Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_FRAMER_H_ | |
| 6 #define NET_QUIC_QUIC_FRAMER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/quic/crypto/quic_decrypter.h" | |
| 14 #include "net/quic/crypto/quic_encrypter.h" | |
| 15 #include "net/base/ip_endpoint.h" | |
| 16 #include "base/string_piece.h" | |
|
jar (doing other things)
2012/10/14 23:04:38
nit: alphabetize last two lines
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 class QuicEncrypter; | |
| 21 class QuicDecrypter; | |
| 22 class QuicFramer; | |
| 23 class QuicDataReader; | |
| 24 class QuicDataWriter; | |
| 25 | |
| 26 class QuicFramerVisitorInterface { | |
| 27 public: | |
| 28 virtual ~QuicFramerVisitorInterface() {} | |
| 29 | |
| 30 // Called if an error is detected in the QUIC protocol. | |
| 31 virtual void OnError(QuicFramer* framer) = 0; | |
| 32 | |
| 33 // Called when a new packet has been recieved. | |
|
jar (doing other things)
2012/10/14 23:04:38
Clarification: Is this called when the packet is r
Ryan Hamilton
2012/10/15 21:22:08
Commented.
| |
| 34 virtual void OnPacket(const IPEndPoint& peer_address) = 0; | |
| 35 | |
| 36 // Called when the header of a packet had been parsed. | |
| 37 // If OnPacketHeader returns false, framing for this packet will cease. | |
| 38 virtual bool OnPacketHeader(const QuicPacketHeader& header) = 0; | |
| 39 | |
| 40 // Called when a data packet is parsed that is part of an FEC group. | |
| 41 // |payload| is the non-encrypted FEC protected payload of the packet. | |
|
jar (doing other things)
2012/10/14 23:04:38
Due to out-of-order receipt, even with FECs only a
Ryan Hamilton
2012/10/15 21:22:08
In the code not committed as part of this CL, we m
| |
| 42 virtual void OnFecProtectedPayload(base::StringPiece payload) = 0; | |
| 43 | |
| 44 // Called when a StreamFragment has been parsed. | |
| 45 virtual void OnStreamFragment(const QuicStreamFragment& fragment) = 0; | |
| 46 | |
| 47 // Called when a AckFragment has been parsed. | |
| 48 virtual void OnAckFragment(const QuicAckFragment& fragment) = 0; | |
| 49 | |
| 50 // Called when a RstStreamFragment has been parsed. | |
| 51 virtual void OnRstStreamFragment( | |
| 52 const QuicRstStreamFragment& fragment) = 0; | |
| 53 | |
| 54 // Called when a ConnectionCloseFragment has been parsed. | |
| 55 virtual void OnConnectionCloseFragment( | |
| 56 const QuicConnectionCloseFragment& fragment) = 0; | |
| 57 | |
| 58 // Called when FEC data has been parsed. | |
|
jar (doing other things)
2012/10/14 23:04:38
Same question about which FEC group is being handl
Ryan Hamilton
2012/10/15 21:22:08
It is in the packet header that was passed in duri
| |
| 59 virtual void OnFecData(const QuicFecData& fec) = 0; | |
| 60 | |
| 61 // Called when a packet has been completely processed. | |
| 62 virtual void OnPacketComplete() = 0; | |
| 63 }; | |
| 64 | |
| 65 class QuicFecBuilderInterface { | |
| 66 public: | |
| 67 virtual ~QuicFecBuilderInterface() {} | |
| 68 | |
| 69 // Called when a data packet is constructed that is part of an FEC group. | |
| 70 // |payload| is the non-encrypted FEC protected payload of the packet. | |
| 71 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, | |
| 72 base::StringPiece payload) = 0; | |
| 73 }; | |
| 74 | |
| 75 class QuicFramer { | |
| 76 public: | |
| 77 // Constructs a new framer that will own |decrypter| and |encrypter|. | |
| 78 QuicFramer(QuicDecrypter* decrypter, QuicEncrypter* encrypter); | |
| 79 | |
| 80 virtual ~QuicFramer(); | |
| 81 | |
| 82 // Set callbacks to be called from the framer. A visitor must be set, or | |
| 83 // else the framer will likely crash. It is acceptable for the visitor | |
| 84 // to do nothing. If this is called multiple times, only the last visitor | |
| 85 // will be used. | |
| 86 void set_visitor(QuicFramerVisitorInterface* visitor) { | |
|
jar (doing other things)
2012/10/14 23:04:38
I wasn't familiar with the term visitor. Is this
Ryan Hamilton
2012/10/15 21:22:08
Yes.
| |
| 87 visitor_ = visitor; | |
| 88 } | |
| 89 | |
| 90 // Set a builder to be called from the framer when building FEC protected | |
|
jar (doing other things)
2012/10/14 23:04:38
It would be helpful to have the terms builder, fra
Ryan Hamilton
2012/10/15 21:22:08
Added a comment.
| |
| 91 // packets. If this is called multiple times, only the last builder | |
| 92 // will be used. The builder need not be set. | |
| 93 void set_fec_builder(QuicFecBuilderInterface* builder) { | |
| 94 fec_builder_ = builder; | |
| 95 } | |
| 96 | |
| 97 QuicErrorCode error() const { | |
| 98 return error_; | |
| 99 } | |
| 100 | |
| 101 // Pass a UDP packet into the framer for parsing. | |
| 102 // Return true if the packet was processed succesfully. |packet| must be a | |
| 103 // single, complete UDP packet (not a fragment of a packet). This packet | |
| 104 // might be null padded past the end of the payload, which will be correctly | |
| 105 // ignored. | |
| 106 bool ProcessPacket(const IPEndPoint& client_address, | |
| 107 const QuicEncryptedPacket& packet); | |
| 108 | |
| 109 // Pass a revived data packet into the framer for parsing. | |
|
jar (doing other things)
2012/10/14 23:04:38
I'm guessing that "revived" means "result of FEC b
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 110 // Return true if the packet was processed succesfully. |payload| must be | |
| 111 // the complete DECRYPTED payload of the revived packet. | |
| 112 bool ProcessRevivedPacket(const IPEndPoint& client_address, | |
|
jar (doing other things)
2012/10/14 23:04:38
I understood why the regular packet included IPEnd
Ryan Hamilton
2012/10/15 21:22:08
If the FEC packet were the first packet received f
jar (doing other things)
2012/10/16 19:24:00
hmm....
You're suggesting that the revived packet
Ryan Hamilton
2012/10/16 19:43:23
In my example, I was suggesting that the last rece
| |
| 113 const QuicPacketHeader& header, | |
| 114 base::StringPiece payload); | |
| 115 | |
| 116 // Creates a new QuicPacket populated with the fields in |header| and | |
| 117 // |fragments|. Assigns |*packet| to the address of the new object. | |
| 118 // Returns true upon success. | |
|
jar (doing other things)
2012/10/14 23:04:38
Is it assumed that the input is sized perfectly to
Ryan Hamilton
2012/10/15 21:22:08
If the packet can not be constructed as requested,
| |
| 119 bool ConstructFragementDataPacket(const QuicPacketHeader& header, | |
| 120 const QuicFragments& fragments, | |
| 121 QuicPacket** packet); | |
| 122 | |
| 123 // Creates a new QuicPacket populated with the fields in |header| and | |
| 124 // |fec|. Assigns |*packet| to the address of the new object. | |
| 125 // Returns true upon success. | |
| 126 bool ConstructFecPacket(const QuicPacketHeader& header, | |
| 127 const QuicFecData& fec, | |
| 128 QuicPacket** packet); | |
| 129 | |
| 130 // Increments the retransmission count by one, and updates the authentication | |
| 131 // hash accordingly. | |
| 132 void IncrementRetransmitCount(QuicPacket* packet); | |
| 133 | |
| 134 uint8 GetRetransmitCount(QuicPacket* packet); | |
| 135 | |
| 136 void WriteTransmissionTime(QuicTransmissionTime time, QuicPacket* packet); | |
| 137 | |
| 138 // Returns a new encrypted packet, owned by the caller. | |
| 139 QuicEncryptedPacket* EncryptPacket(const QuicPacket& packet); | |
| 140 | |
| 141 // Returns the maximum length of plaintext that can be encrypted | |
| 142 // to ciphertext no larger than |ciphertext_size|. | |
|
jar (doing other things)
2012/10/14 23:04:38
Is this for a single UDP packet?
Ryan Hamilton
2012/10/15 21:22:08
That is how this will be used, but this method doe
| |
| 143 size_t GetMaxPlaintextSize(size_t ciphertext_size); | |
| 144 | |
| 145 const std::string& detailed_error() { return detailed_error_; } | |
| 146 | |
| 147 private: | |
| 148 bool WritePacketHeader(const QuicPacketHeader& header, | |
| 149 QuicDataWriter* builder); | |
| 150 | |
| 151 bool ProcessPacketHeader(QuicPacketHeader* header, | |
| 152 const QuicEncryptedPacket& packet); | |
| 153 | |
| 154 bool ProcessFragmentData(); | |
| 155 bool ProcessStreamFragment(); | |
| 156 bool ProcessPDUFragment(); | |
| 157 bool ProcessAckFragment(QuicAckFragment* fragment); | |
| 158 bool ProcessRstStreamFragment(); | |
| 159 bool ProcessConnectionCloseFragment(); | |
| 160 | |
| 161 bool DecryptPayload(const QuicEncryptedPacket& packet); | |
| 162 | |
| 163 // Computes the wire size in bytes of the payload of |fragment|. | |
| 164 size_t ComputeFragmentPayloadLength(const QuicFragment& fragment); | |
| 165 | |
| 166 bool AppendStreamFragmentPayload( | |
| 167 const QuicStreamFragment& fragment, | |
| 168 QuicDataWriter* builder); | |
| 169 bool AppendAckFragmentPayload( | |
| 170 const QuicAckFragment& fragment, | |
| 171 QuicDataWriter* builder); | |
| 172 bool AppendRstStreamFragmentPayload( | |
| 173 const QuicRstStreamFragment& fragment, | |
| 174 QuicDataWriter* builder); | |
| 175 bool AppendConnectionCloseFragmentPayload( | |
| 176 const QuicConnectionCloseFragment& fragment, | |
| 177 QuicDataWriter* builder); | |
| 178 bool RaiseError(QuicErrorCode error); | |
| 179 | |
| 180 void set_error(QuicErrorCode error) { | |
| 181 error_ = error; | |
| 182 } | |
| 183 | |
| 184 void set_detailed_error(const char* error) { | |
| 185 detailed_error_ = error; | |
| 186 } | |
| 187 | |
| 188 std::string detailed_error_; | |
| 189 scoped_ptr<QuicDataReader> reader_; | |
| 190 QuicFramerVisitorInterface* visitor_; | |
| 191 QuicFecBuilderInterface* fec_builder_; | |
| 192 QuicErrorCode error_; | |
| 193 // Buffer containing decrypted payload data during parsing. | |
| 194 scoped_ptr<QuicData> decrypted_; | |
| 195 // Decrypter used to decrypt packets during parsing. | |
| 196 scoped_ptr<QuicDecrypter> decrypter_; | |
| 197 // Encrypter used to encrypt packets via EncryptPacket(). | |
| 198 scoped_ptr<QuicEncrypter> encrypter_; | |
| 199 }; | |
|
jar (doing other things)
2012/10/14 23:04:38
Should you have the macro to prevent copy construc
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 200 | |
| 201 } // namespace net | |
| 202 | |
| 203 #endif // NET_QUIC_QUIC_FRAMER_H_ | |
| OLD | NEW |