xref: /trafficserver/proxy/http3/Http09App.cc (revision 71c99b80)
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 "Http09App.h"
25 
26 #include "tscore/ink_resolver.h"
27 
28 #include "P_Net.h"
29 #include "P_VConnection.h"
30 #include "QUICDebugNames.h"
31 
32 #include "Http3Session.h"
33 #include "Http3Transaction.h"
34 
35 static constexpr char debug_tag[]   = "quic_simple_app";
36 static constexpr char debug_tag_v[] = "v_quic_simple_app";
37 
Http09App(QUICNetVConnection * client_vc,IpAllow::ACL && session_acl,const HttpSessionAccept::Options & options)38 Http09App::Http09App(QUICNetVConnection *client_vc, IpAllow::ACL &&session_acl, const HttpSessionAccept::Options &options)
39   : QUICApplication(client_vc)
40 {
41   this->_ssn                 = new Http09Session(client_vc);
42   this->_ssn->acl            = std::move(session_acl);
43   this->_ssn->accept_options = &options;
44   this->_ssn->new_connection(client_vc, nullptr, nullptr);
45 
46   this->_qc->stream_manager()->set_default_application(this);
47 
48   SET_HANDLER(&Http09App::main_event_handler);
49 }
50 
~Http09App()51 Http09App::~Http09App()
52 {
53   delete this->_ssn;
54 }
55 
56 int
main_event_handler(int event,Event * data)57 Http09App::main_event_handler(int event, Event *data)
58 {
59   Debug(debug_tag_v, "[%s] %s (%d)", this->_qc->cids().data(), get_vc_event_name(event), event);
60 
61   VIO *vio                = reinterpret_cast<VIO *>(data);
62   QUICStreamIO *stream_io = this->_find_stream_io(vio);
63 
64   if (stream_io == nullptr) {
65     Debug(debug_tag, "[%s] Unknown Stream", this->_qc->cids().data());
66     return -1;
67   }
68 
69   QUICStreamId stream_id = stream_io->stream_id();
70   Http09Transaction *txn = static_cast<Http09Transaction *>(this->_ssn->get_transaction(stream_id));
71 
72   uint8_t dummy;
73   switch (event) {
74   case VC_EVENT_READ_READY:
75   case VC_EVENT_READ_COMPLETE:
76     if (!stream_io->is_bidirectional()) {
77       // FIXME Ignore unidirectional streams for now
78       break;
79     }
80     if (stream_io->peek(&dummy, 1)) {
81       if (txn == nullptr) {
82         txn = new Http09Transaction(this->_ssn, stream_io);
83         SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread());
84 
85         txn->new_transaction();
86       } else {
87         SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread());
88         txn->handleEvent(event);
89       }
90     }
91     break;
92   case VC_EVENT_WRITE_READY:
93   case VC_EVENT_WRITE_COMPLETE:
94     if (txn != nullptr) {
95       SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread());
96       txn->handleEvent(event);
97     }
98     break;
99   case VC_EVENT_EOS:
100   case VC_EVENT_ERROR:
101   case VC_EVENT_INACTIVITY_TIMEOUT:
102   case VC_EVENT_ACTIVE_TIMEOUT:
103     ink_assert(false);
104     break;
105   default:
106     break;
107   }
108 
109   return EVENT_CONT;
110 }
111