1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include <deque>
27 #include "QUICFrame.h"
28 
29 class QUICFrameGenerator;
30 
31 struct QUICFrameInformation {
32   QUICFrameType type;
33   QUICEncryptionLevel level;
34 
35   uint8_t data[128] = {};
36 };
37 
38 struct QUICFrameInformationDeleter {
39   void operator()(QUICFrameInformation *p);
40 };
41 
42 using QUICFrameInformationUPtr = std::unique_ptr<QUICFrameInformation, QUICFrameInformationDeleter>;
43 
44 constexpr QUICFrameType RETRANSMITTED_FRAME_TYPE[] = {QUICFrameType::STREAM, QUICFrameType::CRYPTO};
45 
46 struct StreamFrameInfo {
47   QUICStreamId stream_id;
48   QUICOffset offset;
49   bool has_fin;
50   Ptr<IOBufferBlock> block;
51 };
52 
53 struct CryptoFrameInfo {
54   QUICOffset offset;
55   Ptr<IOBufferBlock> block;
56 };
57 
58 struct RstStreamFrameInfo {
59   QUICAppErrorCode error_code;
60   QUICOffset final_offset;
61 };
62 
63 struct StopSendingFrameInfo {
64   QUICAppErrorCode error_code;
65 };
66 
67 struct AckFrameInfo {
68   QUICPacketNumber largest_acknowledged;
69 };
70 
71 class QUICFrameRetransmitter
72 {
73 public:
74   virtual QUICFrame *create_retransmitted_frame(uint8_t *buf, QUICEncryptionLevel level, uint16_t maximum_frame_size,
75                                                 QUICFrameId id = 0, QUICFrameGenerator *owner = nullptr);
76   virtual void save_frame_info(QUICFrameInformationUPtr info);
77   bool is_retransmited_frame_queue_empty() const;
78 
79 private:
80   QUICFrame *_create_stream_frame(uint8_t *buf, QUICFrameInformationUPtr &info, uint16_t maximum_frame_size,
81                                   std::deque<QUICFrameInformationUPtr> &tmp_queue, QUICFrameId id, QUICFrameGenerator *owner);
82   QUICFrame *_create_crypto_frame(uint8_t *buf, QUICFrameInformationUPtr &info, uint16_t maximum_frame_size,
83                                   std::deque<QUICFrameInformationUPtr> &tmp_queue, QUICFrameId id, QUICFrameGenerator *owner);
84 
85   void _append_info_queue(std::deque<QUICFrameInformationUPtr> &tmp_queue);
86 
87   std::deque<QUICFrameInformationUPtr> _lost_frame_info_queue;
88 };
89 
90 extern ClassAllocator<QUICFrameInformation> quicFrameInformationAllocator;
91 
92 inline void
operator ()(QUICFrameInformation * p)93 QUICFrameInformationDeleter::operator()(QUICFrameInformation *p)
94 {
95   quicFrameInformationAllocator.free(p);
96 }
97