xref: /trafficserver/proxy/http3/Http3Session.cc (revision 64e44402)
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 #include "Http3Session.h"
25 
26 #include "Http3.h"
27 
28 //
29 // HQSession
30 //
~HQSession()31 HQSession ::~HQSession()
32 {
33   for (HQTransaction *t = this->_transaction_list.head; t; t = static_cast<HQTransaction *>(t->link.next)) {
34     delete t;
35   }
36 }
37 
38 void
add_transaction(HQTransaction * trans)39 HQSession::add_transaction(HQTransaction *trans)
40 {
41   this->_transaction_list.enqueue(trans);
42 
43   return;
44 }
45 
46 HQTransaction *
get_transaction(QUICStreamId id)47 HQSession::get_transaction(QUICStreamId id)
48 {
49   for (HQTransaction *t = this->_transaction_list.head; t; t = static_cast<HQTransaction *>(t->link.next)) {
50     if (t->get_transaction_id() == static_cast<int>(id)) {
51       return t;
52     }
53   }
54 
55   return nullptr;
56 }
57 
58 VIO *
do_io_read(Continuation * c,int64_t nbytes,MIOBuffer * buf)59 HQSession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
60 {
61   ink_assert(false);
62   return nullptr;
63 }
64 
65 VIO *
do_io_write(Continuation * c,int64_t nbytes,IOBufferReader * buf,bool owner)66 HQSession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
67 {
68   ink_assert(false);
69   return nullptr;
70 }
71 
72 void
do_io_close(int lerrno)73 HQSession::do_io_close(int lerrno)
74 {
75   // TODO
76   return;
77 }
78 
79 void
do_io_shutdown(ShutdownHowTo_t howto)80 HQSession::do_io_shutdown(ShutdownHowTo_t howto)
81 {
82   ink_assert(false);
83   return;
84 }
85 
86 void
reenable(VIO * vio)87 HQSession::reenable(VIO *vio)
88 {
89   ink_assert(false);
90   return;
91 }
92 
93 void
new_connection(NetVConnection * new_vc,MIOBuffer * iobuf,IOBufferReader * reade)94 HQSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reade)
95 {
96   this->con_id = static_cast<QUICConnection *>(reinterpret_cast<QUICNetVConnection *>(new_vc))->connection_id();
97 
98   return;
99 }
100 
101 void
start()102 HQSession::start()
103 {
104   ink_assert(false);
105   return;
106 }
107 
108 void
destroy()109 HQSession::destroy()
110 {
111   ink_assert(false);
112   return;
113 }
114 
115 void
release(ProxyTransaction * trans)116 HQSession::release(ProxyTransaction *trans)
117 {
118   return;
119 }
120 
121 NetVConnection *
get_netvc() const122 HQSession::get_netvc() const
123 {
124   return this->_client_vc;
125 }
126 
127 int
get_transact_count() const128 HQSession::get_transact_count() const
129 {
130   return 0;
131 }
132 
133 bool
support_sni() const134 HQSession::support_sni() const
135 {
136   return this->_client_vc ? this->_client_vc->support_sni() : false;
137 }
138 
139 //
140 // Http3Session
141 //
Http3Session(NetVConnection * vc)142 Http3Session::Http3Session(NetVConnection *vc) : HQSession(vc)
143 {
144   this->_local_qpack  = new QPACK(static_cast<QUICNetVConnection *>(vc), HTTP3_DEFAULT_MAX_HEADER_LIST_SIZE,
145                                  HTTP3_DEFAULT_HEADER_TABLE_SIZE, HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
146   this->_remote_qpack = new QPACK(static_cast<QUICNetVConnection *>(vc), HTTP3_DEFAULT_MAX_HEADER_LIST_SIZE,
147                                   HTTP3_DEFAULT_HEADER_TABLE_SIZE, HTTP3_DEFAULT_QPACK_BLOCKED_STREAMS);
148 }
149 
~Http3Session()150 Http3Session::~Http3Session()
151 {
152   this->_client_vc = nullptr;
153   delete this->_local_qpack;
154   delete this->_remote_qpack;
155 }
156 
157 const char *
get_protocol_string() const158 Http3Session::get_protocol_string() const
159 {
160   return IP_PROTO_TAG_HTTP_3.data();
161 }
162 
163 int
populate_protocol(std::string_view * result,int size) const164 Http3Session::populate_protocol(std::string_view *result, int size) const
165 {
166   int retval = 0;
167   if (size > retval) {
168     result[retval++] = IP_PROTO_TAG_HTTP_3;
169     if (size > retval) {
170       retval += super::populate_protocol(result + retval, size - retval);
171     }
172   }
173   return retval;
174 }
175 
176 void
increment_current_active_client_connections_stat()177 Http3Session::increment_current_active_client_connections_stat()
178 {
179   // TODO Implement stats
180 }
181 
182 void
decrement_current_active_client_connections_stat()183 Http3Session::decrement_current_active_client_connections_stat()
184 {
185   // TODO Implement stats
186 }
187 
188 QPACK *
local_qpack()189 Http3Session::local_qpack()
190 {
191   return this->_local_qpack;
192 }
193 
194 QPACK *
remote_qpack()195 Http3Session::remote_qpack()
196 {
197   return this->_remote_qpack;
198 }
199 
200 //
201 // Http09Session
202 //
~Http09Session()203 Http09Session::~Http09Session()
204 {
205   this->_client_vc = nullptr;
206 }
207 
208 const char *
get_protocol_string() const209 Http09Session::get_protocol_string() const
210 {
211   return IP_PROTO_TAG_HTTP_QUIC.data();
212 }
213 
214 int
populate_protocol(std::string_view * result,int size) const215 Http09Session::populate_protocol(std::string_view *result, int size) const
216 {
217   int retval = 0;
218   if (size > retval) {
219     result[retval++] = IP_PROTO_TAG_HTTP_QUIC;
220     if (size > retval) {
221       retval += super::populate_protocol(result + retval, size - retval);
222     }
223   }
224   return retval;
225 }
226 
227 void
increment_current_active_client_connections_stat()228 Http09Session::increment_current_active_client_connections_stat()
229 {
230   // TODO Implement stats
231 }
232 
233 void
decrement_current_active_client_connections_stat()234 Http09Session::decrement_current_active_client_connections_stat()
235 {
236   // TODO Implement stats
237 }
238