1 /** @file
2 
3   QUICNextProtocolAccept
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 "P_QUICNextProtocolAccept.h"
25 
26 static QUICNetVConnection *
quic_netvc_cast(int event,void * edata)27 quic_netvc_cast(int event, void *edata)
28 {
29   union {
30     VIO *vio;
31     NetVConnection *vc;
32   } ptr;
33 
34   switch (event) {
35   case NET_EVENT_ACCEPT:
36     ptr.vc = static_cast<NetVConnection *>(edata);
37     return dynamic_cast<QUICNetVConnection *>(ptr.vc);
38   case VC_EVENT_INACTIVITY_TIMEOUT:
39   case VC_EVENT_READ_COMPLETE:
40   case VC_EVENT_ERROR:
41     ptr.vio = static_cast<VIO *>(edata);
42     return dynamic_cast<QUICNetVConnection *>(ptr.vio->vc_server);
43   default:
44     return nullptr;
45   }
46 }
47 
48 int
mainEvent(int event,void * edata)49 QUICNextProtocolAccept::mainEvent(int event, void *edata)
50 {
51   QUICNetVConnection *netvc = quic_netvc_cast(event, edata);
52 
53   Debug("v_quic", "[%s] event %d netvc %p", netvc->cids().data(), event, netvc);
54   switch (event) {
55   case NET_EVENT_ACCEPT:
56     ink_release_assert(netvc != nullptr);
57     netvc->registerNextProtocolSet(&this->protoset, this->protoenabled);
58     return EVENT_CONT;
59   default:
60     netvc->do_io_close();
61     return EVENT_DONE;
62   }
63 }
64 
65 bool
accept(NetVConnection *,MIOBuffer *,IOBufferReader *)66 QUICNextProtocolAccept::accept(NetVConnection *, MIOBuffer *, IOBufferReader *)
67 {
68   ink_release_assert(0);
69   return false;
70 }
71 
72 bool
registerEndpoint(const char * protocol,Continuation * handler)73 QUICNextProtocolAccept::registerEndpoint(const char *protocol, Continuation *handler)
74 {
75   return this->protoset.registerEndpoint(protocol, handler);
76 }
77 
78 void
enableProtocols(const SessionProtocolSet & protos)79 QUICNextProtocolAccept::enableProtocols(const SessionProtocolSet &protos)
80 {
81   this->protoenabled = protos;
82 }
83 
QUICNextProtocolAccept()84 QUICNextProtocolAccept::QUICNextProtocolAccept() : SessionAccept(nullptr)
85 {
86   SET_HANDLER(&QUICNextProtocolAccept::mainEvent);
87 }
88 
89 SSLNextProtocolSet *
getProtoSet()90 QUICNextProtocolAccept::getProtoSet()
91 {
92   return &this->protoset;
93 }
94 
~QUICNextProtocolAccept()95 QUICNextProtocolAccept::~QUICNextProtocolAccept() {}
96