1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/** @file
Http2CommonSession.h
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "HTTP2.h"
#include "ProxySession.h"
#include "Http2ConnectionState.h"
#include "Http2Frame.h"
// Name Edata Description
// HTTP2_SESSION_EVENT_INIT Http2CommonSession * HTTP/2 session is born
// HTTP2_SESSION_EVENT_FINI Http2CommonSession * HTTP/2 session is ended
// HTTP2_SESSION_EVENT_RECV Http2Frame * Received a frame
// HTTP2_SESSION_EVENT_XMIT Http2Frame * Send this frame
#define HTTP2_SESSION_EVENT_INIT (HTTP2_SESSION_EVENTS_START + 1)
#define HTTP2_SESSION_EVENT_FINI (HTTP2_SESSION_EVENTS_START + 2)
#define HTTP2_SESSION_EVENT_RECV (HTTP2_SESSION_EVENTS_START + 3)
#define HTTP2_SESSION_EVENT_XMIT (HTTP2_SESSION_EVENTS_START + 4)
#define HTTP2_SESSION_EVENT_SHUTDOWN_INIT (HTTP2_SESSION_EVENTS_START + 5)
#define HTTP2_SESSION_EVENT_SHUTDOWN_CONT (HTTP2_SESSION_EVENTS_START + 6)
#define HTTP2_SESSION_EVENT_REENABLE (HTTP2_SESSION_EVENTS_START + 7)
enum class Http2SessionCod : int {
NOT_PROVIDED,
HIGH_ERROR_RATE,
};
enum class Http2SsnMilestone {
OPEN = 0,
CLOSE,
LAST_ENTRY,
};
size_t const HTTP2_HEADER_BUFFER_SIZE_INDEX = CLIENT_CONNECTION_FIRST_READ_BUFFER_SIZE_INDEX;
/**
@startuml
title HTTP/2 Session Handler - state of reading HTTP/2 frame
hide empty description
[*] --> state_read_connection_preface : start()
state_read_connection_preface --> state_start_frame_read : receive connection preface
state_start_frame_read --> state_start_frame_read : do_complete_frame_read()
state_start_frame_read --> state_complete_frame_read : reading HTTP/2 frame is halfway but no data in the buffer
state_complete_frame_read --> state_start_frame_read : do_complete_frame_read()
@enduml
*/
class Http2CommonSession
{
public:
using SessionHandler = int (Http2CommonSession::*)(int, void *);
virtual ~Http2CommonSession() = default;
/////////////////////
// Methods
bool common_free(ProxySession *ssn);
void write_reenable();
int64_t xmit(const Http2TxFrame &frame, bool flush = true);
void flush();
int64_t get_connection_id();
Ptr<ProxyMutex> &get_mutex();
NetVConnection *get_netvc();
void do_clear_session_active();
////////////////////
// Accessors
void set_dying_event(int event);
int get_dying_event() const;
bool ready_to_free() const;
bool is_recursing() const;
void set_half_close_local_flag(bool flag);
bool get_half_close_local_flag() const;
bool is_url_pushed(const char *url, int url_len);
void add_url_to_pushed_table(const char *url, int url_len);
// Record history from Http2ConnectionState
void remember(const SourceLocation &location, int event, int reentrant = NO_REENTRANT);
int64_t write_avail();
bool is_write_high_water() const;
virtual ProxySession *get_proxy_session() = 0;
///////////////////
// Variables
Http2ConnectionState connection_state;
protected:
// SessionHandler(s) - state of reading frame
int state_read_connection_preface(int, void *);
int state_start_frame_read(int, void *);
int state_complete_frame_read(int, void *);
// state_start_frame_read and state_complete_frame_read are set up as session event handler.
// Both feed into do_process_frame_read which may iterate if there are multiple frames ready on the wire
int do_process_frame_read(int event, VIO *vio, bool inside_frame);
int do_start_frame_read(Http2ErrorCode &ret_error);
int do_complete_frame_read();
bool _should_do_something_else();
////////
// Variables
SessionHandler session_handler = nullptr;
MIOBuffer *read_buffer = nullptr;
IOBufferReader *_read_buffer_reader = nullptr;
VIO *write_vio = nullptr;
MIOBuffer *write_buffer = nullptr;
IOBufferReader *_write_buffer_reader = nullptr;
Http2FrameHeader current_hdr = {0, 0, 0, 0};
uint32_t _write_size_threshold = 0;
uint32_t _write_time_threshold = 100;
ink_hrtime _write_buffer_last_flush = 0;
History<HISTORY_DEFAULT_SIZE> _history;
Milestones<Http2SsnMilestone, static_cast<size_t>(Http2SsnMilestone::LAST_ENTRY)> _milestones;
int dying_event = 0;
bool kill_me = false;
Http2SessionCod cause_of_death = Http2SessionCod::NOT_PROVIDED;
bool half_close_local = false;
int recursion = 0;
std::unordered_set<std::string> *_h2_pushed_urls = nullptr;
Event *_reenable_event = nullptr;
int _n_frame_read = 0;
uint32_t _pending_sending_data_size = 0;
int64_t read_from_early_data = 0;
bool cur_frame_from_early_data = false;
};
///////////////////////////////////////////////
// INLINE
inline bool
Http2CommonSession::ready_to_free() const
{
return kill_me;
}
inline void
Http2CommonSession::set_dying_event(int event)
{
dying_event = event;
}
inline int
Http2CommonSession::get_dying_event() const
{
return dying_event;
}
inline bool
Http2CommonSession::is_recursing() const
{
return recursion > 0;
}
inline bool
Http2CommonSession::get_half_close_local_flag() const
{
return half_close_local;
}
inline bool
Http2CommonSession::is_url_pushed(const char *url, int url_len)
{
if (_h2_pushed_urls == nullptr) {
return false;
}
return _h2_pushed_urls->find(url) != _h2_pushed_urls->end();
}
inline int64_t
Http2CommonSession::get_connection_id()
{
return get_proxy_session()->connection_id();
}
inline Ptr<ProxyMutex> &
Http2CommonSession::get_mutex()
{
return get_proxy_session()->mutex;
}
inline NetVConnection *
Http2CommonSession::get_netvc()
{
return get_proxy_session()->get_netvc();
}
inline void
Http2CommonSession::do_clear_session_active()
{
get_proxy_session()->clear_session_active();
}
|