QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2013 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 QUICHE_QUIC_TEST_TOOLS_QUIC_FRAMER_PEER_H_ |
| 6 | #define QUICHE_QUIC_TEST_TOOLS_QUIC_FRAMER_PEER_H_ |
| 7 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 9 | #include "net/third_party/quiche/src/quic/core/quic_framer.h" |
| 10 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | namespace test { |
| 15 | |
| 16 | class QuicFramerPeer { |
| 17 | public: |
| 18 | QuicFramerPeer() = delete; |
| 19 | |
| 20 | static uint64_t CalculatePacketNumberFromWire( |
| 21 | QuicFramer* framer, |
| 22 | QuicPacketNumberLength packet_number_length, |
| 23 | QuicPacketNumber last_packet_number, |
| 24 | uint64_t packet_number); |
| 25 | static void SetLastSerializedConnectionId(QuicFramer* framer, |
| 26 | QuicConnectionId connection_id); |
| 27 | static void SetLargestPacketNumber(QuicFramer* framer, |
| 28 | QuicPacketNumber packet_number); |
| 29 | static void SetPerspective(QuicFramer* framer, Perspective perspective); |
| 30 | |
| 31 | // SwapCrypters exchanges the state of the crypters of |framer1| with |
| 32 | // |framer2|. |
| 33 | static void SwapCrypters(QuicFramer* framer1, QuicFramer* framer2); |
| 34 | |
| 35 | static QuicEncrypter* GetEncrypter(QuicFramer* framer, EncryptionLevel level); |
QUICHE team | fbfd362 | 2019-03-26 10:59:32 -0700 | [diff] [blame] | 36 | static QuicDecrypter* GetDecrypter(QuicFramer* framer, EncryptionLevel level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | |
| 38 | // IETF defined frame append/process methods. |
| 39 | static bool ProcessIetfStreamFrame(QuicFramer* framer, |
| 40 | QuicDataReader* reader, |
| 41 | uint8_t frame_type, |
| 42 | QuicStreamFrame* frame); |
| 43 | static bool AppendIetfStreamFrame(QuicFramer* framer, |
| 44 | const QuicStreamFrame& frame, |
| 45 | bool last_frame_in_packet, |
| 46 | QuicDataWriter* writer); |
| 47 | static bool ProcessCryptoFrame(QuicFramer* framer, |
| 48 | QuicDataReader* reader, |
| 49 | QuicCryptoFrame* frame); |
| 50 | static bool AppendCryptoFrame(QuicFramer* framer, |
| 51 | const QuicCryptoFrame& frame, |
| 52 | QuicDataWriter* writer); |
| 53 | |
| 54 | static bool AppendIetfConnectionCloseFrame( |
| 55 | QuicFramer* framer, |
| 56 | const QuicConnectionCloseFrame& frame, |
| 57 | QuicDataWriter* writer); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 58 | static bool ProcessIetfConnectionCloseFrame(QuicFramer* framer, |
| 59 | QuicDataReader* reader, |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 60 | QuicConnectionCloseType type, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | QuicConnectionCloseFrame* frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 62 | static bool ProcessIetfAckFrame(QuicFramer* framer, |
| 63 | QuicDataReader* reader, |
| 64 | uint64_t frame_type, |
| 65 | QuicAckFrame* ack_frame); |
| 66 | static bool AppendIetfAckFrameAndTypeByte(QuicFramer* framer, |
| 67 | const QuicAckFrame& frame, |
| 68 | QuicDataWriter* writer); |
| 69 | static size_t GetIetfAckFrameSize(QuicFramer* framer, |
| 70 | const QuicAckFrame& frame); |
| 71 | static bool AppendIetfResetStreamFrame(QuicFramer* framer, |
| 72 | const QuicRstStreamFrame& frame, |
| 73 | QuicDataWriter* writer); |
| 74 | static bool ProcessIetfResetStreamFrame(QuicFramer* framer, |
| 75 | QuicDataReader* reader, |
| 76 | QuicRstStreamFrame* frame); |
| 77 | |
| 78 | static bool ProcessPathChallengeFrame(QuicFramer* framer, |
| 79 | QuicDataReader* reader, |
| 80 | QuicPathChallengeFrame* frame); |
| 81 | static bool ProcessPathResponseFrame(QuicFramer* framer, |
| 82 | QuicDataReader* reader, |
| 83 | QuicPathResponseFrame* frame); |
| 84 | |
| 85 | static bool AppendPathChallengeFrame(QuicFramer* framer, |
| 86 | const QuicPathChallengeFrame& frame, |
| 87 | QuicDataWriter* writer); |
| 88 | static bool AppendPathResponseFrame(QuicFramer* framer, |
| 89 | const QuicPathResponseFrame& frame, |
| 90 | QuicDataWriter* writer); |
| 91 | |
| 92 | static bool ProcessStopSendingFrame(QuicFramer* framer, |
| 93 | QuicDataReader* reader, |
| 94 | QuicStopSendingFrame* stop_sending_frame); |
| 95 | static bool AppendStopSendingFrame( |
| 96 | QuicFramer* framer, |
| 97 | const QuicStopSendingFrame& stop_sending_frame, |
| 98 | QuicDataWriter* writer); |
| 99 | |
| 100 | // Append/consume IETF-Format MAX_DATA and MAX_STREAM_DATA frames |
| 101 | static bool AppendMaxDataFrame(QuicFramer* framer, |
| 102 | const QuicWindowUpdateFrame& frame, |
| 103 | QuicDataWriter* writer); |
| 104 | static bool AppendMaxStreamDataFrame(QuicFramer* framer, |
| 105 | const QuicWindowUpdateFrame& frame, |
| 106 | QuicDataWriter* writer); |
| 107 | static bool ProcessMaxDataFrame(QuicFramer* framer, |
| 108 | QuicDataReader* reader, |
| 109 | QuicWindowUpdateFrame* frame); |
| 110 | static bool ProcessMaxStreamDataFrame(QuicFramer* framer, |
| 111 | QuicDataReader* reader, |
| 112 | QuicWindowUpdateFrame* frame); |
| 113 | static bool AppendMaxStreamsFrame(QuicFramer* framer, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 114 | const QuicMaxStreamsFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 115 | QuicDataWriter* writer); |
| 116 | static bool ProcessMaxStreamsFrame(QuicFramer* framer, |
| 117 | QuicDataReader* reader, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 118 | QuicMaxStreamsFrame* frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 119 | uint64_t frame_type); |
| 120 | static bool AppendIetfBlockedFrame(QuicFramer* framer, |
| 121 | const QuicBlockedFrame& frame, |
| 122 | QuicDataWriter* writer); |
| 123 | static bool ProcessIetfBlockedFrame(QuicFramer* framer, |
| 124 | QuicDataReader* reader, |
| 125 | QuicBlockedFrame* frame); |
| 126 | |
| 127 | static bool AppendStreamBlockedFrame(QuicFramer* framer, |
| 128 | const QuicBlockedFrame& frame, |
| 129 | QuicDataWriter* writer); |
| 130 | static bool ProcessStreamBlockedFrame(QuicFramer* framer, |
| 131 | QuicDataReader* reader, |
| 132 | QuicBlockedFrame* frame); |
| 133 | |
| 134 | static bool AppendStreamsBlockedFrame(QuicFramer* framer, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 135 | const QuicStreamsBlockedFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 136 | QuicDataWriter* writer); |
| 137 | static bool ProcessStreamsBlockedFrame(QuicFramer* framer, |
| 138 | QuicDataReader* reader, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 139 | QuicStreamsBlockedFrame* frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 140 | uint64_t frame_type); |
| 141 | |
| 142 | static bool AppendNewConnectionIdFrame(QuicFramer* framer, |
| 143 | const QuicNewConnectionIdFrame& frame, |
| 144 | QuicDataWriter* writer); |
| 145 | static bool ProcessNewConnectionIdFrame(QuicFramer* framer, |
| 146 | QuicDataReader* reader, |
| 147 | QuicNewConnectionIdFrame* frame); |
| 148 | static bool AppendRetireConnectionIdFrame( |
| 149 | QuicFramer* framer, |
| 150 | const QuicRetireConnectionIdFrame& frame, |
| 151 | QuicDataWriter* writer); |
| 152 | static bool ProcessRetireConnectionIdFrame( |
| 153 | QuicFramer* framer, |
| 154 | QuicDataReader* reader, |
| 155 | QuicRetireConnectionIdFrame* frame); |
| 156 | static size_t ComputeFrameLength(QuicFramer* framer, |
| 157 | const QuicFrame& frame, |
| 158 | bool last_frame_in_packet, |
| 159 | QuicPacketNumberLength packet_number_length); |
| 160 | static void SetFirstSendingPacketNumber(QuicFramer* framer, |
| 161 | uint64_t packet_number); |
| 162 | static void SetExpectedConnectionIDLength( |
| 163 | QuicFramer* framer, |
| 164 | uint8_t expected_connection_id_length); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 165 | static QuicPacketNumber GetLargestDecryptedPacketNumber( |
| 166 | QuicFramer* framer, |
| 167 | PacketNumberSpace packet_number_space); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | } // namespace test |
| 171 | |
| 172 | } // namespace quic |
| 173 | |
| 174 | #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_FRAMER_PEER_H_ |