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); |
| 36 | |
| 37 | // IETF defined frame append/process methods. |
| 38 | static bool ProcessIetfStreamFrame(QuicFramer* framer, |
| 39 | QuicDataReader* reader, |
| 40 | uint8_t frame_type, |
| 41 | QuicStreamFrame* frame); |
| 42 | static bool AppendIetfStreamFrame(QuicFramer* framer, |
| 43 | const QuicStreamFrame& frame, |
| 44 | bool last_frame_in_packet, |
| 45 | QuicDataWriter* writer); |
| 46 | static bool ProcessCryptoFrame(QuicFramer* framer, |
| 47 | QuicDataReader* reader, |
| 48 | QuicCryptoFrame* frame); |
| 49 | static bool AppendCryptoFrame(QuicFramer* framer, |
| 50 | const QuicCryptoFrame& frame, |
| 51 | QuicDataWriter* writer); |
| 52 | |
| 53 | static bool AppendIetfConnectionCloseFrame( |
| 54 | QuicFramer* framer, |
| 55 | const QuicConnectionCloseFrame& frame, |
| 56 | QuicDataWriter* writer); |
| 57 | static bool AppendApplicationCloseFrame( |
| 58 | QuicFramer* framer, |
| 59 | const QuicApplicationCloseFrame& frame, |
| 60 | QuicDataWriter* writer); |
| 61 | static bool ProcessIetfConnectionCloseFrame(QuicFramer* framer, |
| 62 | QuicDataReader* reader, |
| 63 | QuicConnectionCloseFrame* frame); |
| 64 | static bool ProcessApplicationCloseFrame(QuicFramer* framer, |
| 65 | QuicDataReader* reader, |
| 66 | QuicApplicationCloseFrame* frame); |
| 67 | static bool ProcessIetfAckFrame(QuicFramer* framer, |
| 68 | QuicDataReader* reader, |
| 69 | uint64_t frame_type, |
| 70 | QuicAckFrame* ack_frame); |
| 71 | static bool AppendIetfAckFrameAndTypeByte(QuicFramer* framer, |
| 72 | const QuicAckFrame& frame, |
| 73 | QuicDataWriter* writer); |
| 74 | static size_t GetIetfAckFrameSize(QuicFramer* framer, |
| 75 | const QuicAckFrame& frame); |
| 76 | static bool AppendIetfResetStreamFrame(QuicFramer* framer, |
| 77 | const QuicRstStreamFrame& frame, |
| 78 | QuicDataWriter* writer); |
| 79 | static bool ProcessIetfResetStreamFrame(QuicFramer* framer, |
| 80 | QuicDataReader* reader, |
| 81 | QuicRstStreamFrame* frame); |
| 82 | |
| 83 | static bool ProcessPathChallengeFrame(QuicFramer* framer, |
| 84 | QuicDataReader* reader, |
| 85 | QuicPathChallengeFrame* frame); |
| 86 | static bool ProcessPathResponseFrame(QuicFramer* framer, |
| 87 | QuicDataReader* reader, |
| 88 | QuicPathResponseFrame* frame); |
| 89 | |
| 90 | static bool AppendPathChallengeFrame(QuicFramer* framer, |
| 91 | const QuicPathChallengeFrame& frame, |
| 92 | QuicDataWriter* writer); |
| 93 | static bool AppendPathResponseFrame(QuicFramer* framer, |
| 94 | const QuicPathResponseFrame& frame, |
| 95 | QuicDataWriter* writer); |
| 96 | |
| 97 | static bool ProcessStopSendingFrame(QuicFramer* framer, |
| 98 | QuicDataReader* reader, |
| 99 | QuicStopSendingFrame* stop_sending_frame); |
| 100 | static bool AppendStopSendingFrame( |
| 101 | QuicFramer* framer, |
| 102 | const QuicStopSendingFrame& stop_sending_frame, |
| 103 | QuicDataWriter* writer); |
| 104 | |
| 105 | // Append/consume IETF-Format MAX_DATA and MAX_STREAM_DATA frames |
| 106 | static bool AppendMaxDataFrame(QuicFramer* framer, |
| 107 | const QuicWindowUpdateFrame& frame, |
| 108 | QuicDataWriter* writer); |
| 109 | static bool AppendMaxStreamDataFrame(QuicFramer* framer, |
| 110 | const QuicWindowUpdateFrame& frame, |
| 111 | QuicDataWriter* writer); |
| 112 | static bool ProcessMaxDataFrame(QuicFramer* framer, |
| 113 | QuicDataReader* reader, |
| 114 | QuicWindowUpdateFrame* frame); |
| 115 | static bool ProcessMaxStreamDataFrame(QuicFramer* framer, |
| 116 | QuicDataReader* reader, |
| 117 | QuicWindowUpdateFrame* frame); |
| 118 | static bool AppendMaxStreamsFrame(QuicFramer* framer, |
| 119 | const QuicMaxStreamIdFrame& frame, |
| 120 | QuicDataWriter* writer); |
| 121 | static bool ProcessMaxStreamsFrame(QuicFramer* framer, |
| 122 | QuicDataReader* reader, |
| 123 | QuicMaxStreamIdFrame* frame, |
| 124 | uint64_t frame_type); |
| 125 | static bool AppendIetfBlockedFrame(QuicFramer* framer, |
| 126 | const QuicBlockedFrame& frame, |
| 127 | QuicDataWriter* writer); |
| 128 | static bool ProcessIetfBlockedFrame(QuicFramer* framer, |
| 129 | QuicDataReader* reader, |
| 130 | QuicBlockedFrame* frame); |
| 131 | |
| 132 | static bool AppendStreamBlockedFrame(QuicFramer* framer, |
| 133 | const QuicBlockedFrame& frame, |
| 134 | QuicDataWriter* writer); |
| 135 | static bool ProcessStreamBlockedFrame(QuicFramer* framer, |
| 136 | QuicDataReader* reader, |
| 137 | QuicBlockedFrame* frame); |
| 138 | |
| 139 | static bool AppendStreamsBlockedFrame(QuicFramer* framer, |
| 140 | const QuicStreamIdBlockedFrame& frame, |
| 141 | QuicDataWriter* writer); |
| 142 | static bool ProcessStreamsBlockedFrame(QuicFramer* framer, |
| 143 | QuicDataReader* reader, |
| 144 | QuicStreamIdBlockedFrame* frame, |
| 145 | uint64_t frame_type); |
| 146 | |
| 147 | static bool AppendNewConnectionIdFrame(QuicFramer* framer, |
| 148 | const QuicNewConnectionIdFrame& frame, |
| 149 | QuicDataWriter* writer); |
| 150 | static bool ProcessNewConnectionIdFrame(QuicFramer* framer, |
| 151 | QuicDataReader* reader, |
| 152 | QuicNewConnectionIdFrame* frame); |
| 153 | static bool AppendRetireConnectionIdFrame( |
| 154 | QuicFramer* framer, |
| 155 | const QuicRetireConnectionIdFrame& frame, |
| 156 | QuicDataWriter* writer); |
| 157 | static bool ProcessRetireConnectionIdFrame( |
| 158 | QuicFramer* framer, |
| 159 | QuicDataReader* reader, |
| 160 | QuicRetireConnectionIdFrame* frame); |
| 161 | static size_t ComputeFrameLength(QuicFramer* framer, |
| 162 | const QuicFrame& frame, |
| 163 | bool last_frame_in_packet, |
| 164 | QuicPacketNumberLength packet_number_length); |
| 165 | static void SetFirstSendingPacketNumber(QuicFramer* framer, |
| 166 | uint64_t packet_number); |
| 167 | static void SetExpectedConnectionIDLength( |
| 168 | QuicFramer* framer, |
| 169 | uint8_t expected_connection_id_length); |
| 170 | }; |
| 171 | |
| 172 | } // namespace test |
| 173 | |
| 174 | } // namespace quic |
| 175 | |
| 176 | #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_FRAMER_PEER_H_ |