This is an automated email from the ASF dual-hosted git repository. shinrich pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new dd123e1 Promote netvc to ProxySession (#6759) dd123e1 is described below commit dd123e1eaa473bb466266e64873b541a4a50be7c Author: Susan Hinrichs <shinr...@yahoo-inc.com> AuthorDate: Tue May 12 19:51:09 2020 -0500 Promote netvc to ProxySession (#6759) Co-authored-by: Susan Hinrichs <shinr...@verizonmedia.com> --- proxy/ProxySession.cc | 53 ++++++++++++++++--- proxy/ProxySession.h | 19 ++++++- proxy/http/Http1ClientSession.cc | 106 +++++++++----------------------------- proxy/http/Http1ClientSession.h | 12 ----- proxy/http2/Http2ClientSession.cc | 89 +++++++++----------------------- proxy/http2/Http2ClientSession.h | 8 --- proxy/http3/Http3Session.cc | 16 +----- proxy/http3/Http3Session.h | 7 +-- 8 files changed, 111 insertions(+), 199 deletions(-) diff --git a/proxy/ProxySession.cc b/proxy/ProxySession.cc index ef910ea..3d9c203 100644 --- a/proxy/ProxySession.cc +++ b/proxy/ProxySession.cc @@ -28,6 +28,8 @@ ProxySession::ProxySession() : VConnection(nullptr) {} +ProxySession::ProxySession(NetVConnection *vc) : VConnection(nullptr), _vc(vc) {} + void ProxySession::set_session_active() { @@ -212,44 +214,49 @@ ProxySession::get_server_session() const void ProxySession::set_active_timeout(ink_hrtime timeout_in) { + if (_vc) { + _vc->set_active_timeout(timeout_in); + } } void ProxySession::set_inactivity_timeout(ink_hrtime timeout_in) { + if (_vc) { + _vc->set_inactivity_timeout(timeout_in); + } } void ProxySession::cancel_inactivity_timeout() { + if (_vc) { + _vc->cancel_inactivity_timeout(); + } } int ProxySession::populate_protocol(std::string_view *result, int size) const { - auto vc = this->get_netvc(); - return vc ? vc->populate_protocol(result, size) : 0; + return _vc ? _vc->populate_protocol(result, size) : 0; } const char * ProxySession::protocol_contains(std::string_view tag_prefix) const { - auto vc = this->get_netvc(); - return vc ? vc->protocol_contains(tag_prefix) : nullptr; + return _vc ? _vc->protocol_contains(tag_prefix) : nullptr; } sockaddr const * ProxySession::get_client_addr() { - NetVConnection *netvc = get_netvc(); - return netvc ? netvc->get_remote_addr() : nullptr; + return _vc ? _vc->get_remote_addr() : nullptr; } sockaddr const * ProxySession::get_local_addr() { - NetVConnection *netvc = get_netvc(); - return netvc ? netvc->get_local_addr() : nullptr; + return _vc ? _vc->get_local_addr() : nullptr; } void @@ -261,3 +268,33 @@ ProxySession::_handle_if_ssl(NetVConnection *new_vc) _ssl.get()->init(*ssl_vc); } } + +VIO * +ProxySession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) +{ + return _vc ? this->_vc->do_io_read(c, nbytes, buf) : nullptr; +} + +VIO * +ProxySession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner) +{ + return _vc ? this->_vc->do_io_write(c, nbytes, buf, owner) : nullptr; +} + +void +ProxySession::do_io_shutdown(ShutdownHowTo_t howto) +{ + this->_vc->do_io_shutdown(howto); +} + +void +ProxySession::reenable(VIO *vio) +{ + this->_vc->reenable(vio); +} + +bool +ProxySession::support_sni() const +{ + return _vc ? _vc->support_sni() : false; +} diff --git a/proxy/ProxySession.h b/proxy/ProxySession.h index d75b84d..f306ffc 100644 --- a/proxy/ProxySession.h +++ b/proxy/ProxySession.h @@ -78,6 +78,7 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN> { public: ProxySession(); + ProxySession(NetVConnection *vc); // noncopyable ProxySession(ProxySession &) = delete; @@ -99,7 +100,7 @@ public: virtual void decrement_current_active_client_connections_stat() = 0; // Virtual Accessors - virtual NetVConnection *get_netvc() const = 0; + NetVConnection *get_netvc() const; virtual int get_transact_count() const = 0; virtual const char *get_protocol_string() const = 0; @@ -139,7 +140,7 @@ public: TSHttpHookID get_hookid() const; bool has_hooks() const; - virtual bool support_sni() const = 0; + virtual bool support_sni() const; APIHook *hook_get(TSHttpHookID id) const; HttpAPIHooks const *feature_hooks() const; @@ -147,6 +148,12 @@ public: // Returns null pointer if session does not use a TLS connection. SSLProxySession const *ssl() const; + // Implement VConnection interface + VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override; + VIO *do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = 0, bool owner = false) override; + void do_io_shutdown(ShutdownHowTo_t howto) override; + void reenable(VIO *vio) override; + //////////////////// // Members @@ -175,6 +182,8 @@ protected: // the new_vc may be an SSLNetVConnection object. void _handle_if_ssl(NetVConnection *new_vc); + NetVConnection *_vc = nullptr; // The netvc associated with the concrete session class + private: void handle_api_return(int event); int state_api_callout(int event, void *edata); @@ -267,3 +276,9 @@ ProxySession::ssl() const { return _ssl.get(); } + +inline NetVConnection * +ProxySession::get_netvc() const +{ + return _vc; +} diff --git a/proxy/http/Http1ClientSession.cc b/proxy/http/Http1ClientSession.cc index 0c402bf..a998a80 100644 --- a/proxy/http/Http1ClientSession.cc +++ b/proxy/http/Http1ClientSession.cc @@ -117,9 +117,9 @@ Http1ClientSession::free() // Free the transaction resources this->trans.super_type::destroy(); - if (client_vc) { - client_vc->do_io_close(); - client_vc = nullptr; + if (_vc) { + _vc->do_io_close(); + _vc = nullptr; } super::free(); @@ -130,8 +130,8 @@ void Http1ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) { ink_assert(new_vc != nullptr); - ink_assert(client_vc == nullptr); - client_vc = new_vc; + ink_assert(_vc == nullptr); + _vc = new_vc; magic = HTTP_CS_MAGIC_ALIVE; mutex = new_vc->mutex; trans.mutex = mutex; // Share this mutex with the transaction @@ -188,7 +188,7 @@ Http1ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB HttpSsnDebug("[%" PRId64 "] session born, netvc %p", con_id, new_vc); - client_vc->set_tcp_congestion_control(CLIENT_SIDE); + _vc->set_tcp_congestion_control(CLIENT_SIDE); read_buffer = iobuf ? iobuf : new_MIOBuffer(HTTP_HEADER_BUFFER_SIZE_INDEX); _reader = reader ? reader : read_buffer->alloc_reader(); @@ -207,28 +207,6 @@ Http1ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB lmutex.clear(); } -VIO * -Http1ClientSession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) -{ - return (client_vc) ? client_vc->do_io_read(c, nbytes, buf) : nullptr; -} - -VIO * -Http1ClientSession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner) -{ - if (client_vc) { - return client_vc->do_io_write(c, nbytes, buf, owner); - } else { - return nullptr; - } -} - -void -Http1ClientSession::do_io_shutdown(ShutdownHowTo_t howto) -{ - client_vc->do_io_shutdown(howto); -} - void Http1ClientSession::do_io_close(int alerrno) { @@ -262,22 +240,22 @@ Http1ClientSession::do_io_close(int alerrno) SET_HANDLER(&Http1ClientSession::state_wait_for_close); HttpSsnDebug("[%" PRId64 "] session half close", con_id); - if (client_vc) { + if (_vc) { // We want the client to know that that we're finished // writing. The write shutdown accomplishes this. Unfortunately, // the IO Core semantics don't stop us from getting events // on the write side of the connection like timeouts so we // need to zero out the write of the continuation with // the do_io_write() call (INKqa05309) - client_vc->do_io_shutdown(IO_SHUTDOWN_WRITE); + _vc->do_io_shutdown(IO_SHUTDOWN_WRITE); - ka_vio = client_vc->do_io_read(this, INT64_MAX, read_buffer); + ka_vio = _vc->do_io_read(this, INT64_MAX, read_buffer); ink_assert(slave_ka_vio != ka_vio); // Set the active timeout to the same as the inactive time so // that this connection does not hang around forever if // the ua hasn't closed - client_vc->set_active_timeout(HRTIME_SECONDS(trans.get_sm()->t_state.txn_conf->keep_alive_no_activity_timeout_in)); + _vc->set_active_timeout(HRTIME_SECONDS(trans.get_sm()->t_state.txn_conf->keep_alive_no_activity_timeout_in)); } // [bug 2610799] Drain any data read. @@ -316,9 +294,9 @@ Http1ClientSession::state_wait_for_close(int event, void *data) case VC_EVENT_INACTIVITY_TIMEOUT: half_close = false; this->do_io_close(); - if (client_vc != nullptr) { - client_vc->do_io_close(); - client_vc = nullptr; + if (_vc != nullptr) { + _vc->do_io_close(); + _vc = nullptr; } break; case VC_EVENT_READ_READY: @@ -376,7 +354,7 @@ Http1ClientSession::state_slave_keep_alive(int event, void *data) int Http1ClientSession::state_keep_alive(int event, void *data) { - // Route the event. It is either for client vc or + // Route the event. It is either for vc or // the origin server slave vc if (data && data == slave_ka_vio) { return state_slave_keep_alive(event, data); @@ -396,9 +374,9 @@ Http1ClientSession::state_keep_alive(int event, void *data) case VC_EVENT_EOS: this->do_io_close(); - if (client_vc != nullptr) { - client_vc->do_io_close(); - client_vc = nullptr; + if (_vc != nullptr) { + _vc->do_io_close(); + _vc = nullptr; } break; @@ -417,11 +395,6 @@ Http1ClientSession::state_keep_alive(int event, void *data) return 0; } -void -Http1ClientSession::reenable(VIO *vio) -{ - client_vc->reenable(vio); -} // Called from the Http1Transaction::release void @@ -448,9 +421,9 @@ Http1ClientSession::release(ProxyTransaction *trans) ka_vio = this->do_io_read(this, INT64_MAX, read_buffer); ink_assert(slave_ka_vio != ka_vio); - if (client_vc) { - client_vc->cancel_active_timeout(); - client_vc->add_to_keep_alive_queue(); + if (_vc) { + _vc->cancel_active_timeout(); + _vc->add_to_keep_alive_queue(); } trans->destroy(); } @@ -460,12 +433,12 @@ void Http1ClientSession::new_transaction() { // If the client connection terminated during API callouts we're done. - if (nullptr == client_vc) { + if (nullptr == _vc) { this->do_io_close(); // calls the SSN_CLOSE hooks to match the SSN_START hooks. return; } - if (!client_vc->add_to_active_queue()) { + if (!_vc->add_to_active_queue()) { // no room in the active queue close the connection this->do_io_close(); return; @@ -546,7 +519,7 @@ bool Http1ClientSession::allow_half_open() const { // Only allow half open connections if the not over TLS - return (client_vc && dynamic_cast<SSLNetVConnection *>(client_vc) == nullptr); + return (_vc && dynamic_cast<SSLNetVConnection *>(_vc) == nullptr); } void @@ -567,12 +540,6 @@ Http1ClientSession::is_chunked_encoding_supported() const return true; } -NetVConnection * -Http1ClientSession::get_netvc() const -{ - return client_vc; -} - int Http1ClientSession::get_transact_count() const { @@ -591,35 +558,8 @@ Http1ClientSession::get_server_session() const return bound_ss; } -void -Http1ClientSession::set_active_timeout(ink_hrtime timeout_in) -{ - if (client_vc) - client_vc->set_active_timeout(timeout_in); -} - -void -Http1ClientSession::set_inactivity_timeout(ink_hrtime timeout_in) -{ - if (client_vc) - client_vc->set_inactivity_timeout(timeout_in); -} - -void -Http1ClientSession::cancel_inactivity_timeout() -{ - if (client_vc) - client_vc->cancel_inactivity_timeout(); -} - const char * Http1ClientSession::get_protocol_string() const { return "http"; } - -bool -Http1ClientSession::support_sni() const -{ - return client_vc ? client_vc->support_sni() : false; -} diff --git a/proxy/http/Http1ClientSession.h b/proxy/http/Http1ClientSession.h index 0a624d2..0076219 100644 --- a/proxy/http/Http1ClientSession.h +++ b/proxy/http/Http1ClientSession.h @@ -63,34 +63,22 @@ public: void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true) override; // Implement VConnection interface. - VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override; - VIO *do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = nullptr, - bool owner = false) override; - void do_io_close(int lerrno = -1) override; - void do_io_shutdown(ShutdownHowTo_t howto) override; - void reenable(VIO *vio) override; // Accessor Methods bool allow_half_open() const; void set_half_close_flag(bool flag) override; bool get_half_close_flag() const override; bool is_chunked_encoding_supported() const override; - NetVConnection *get_netvc() const override; int get_transact_count() const override; virtual bool is_outbound_transparent() const; Http1ServerSession *get_server_session() const override; - void set_active_timeout(ink_hrtime timeout_in) override; - void set_inactivity_timeout(ink_hrtime timeout_in) override; - void cancel_inactivity_timeout() override; const char *get_protocol_string() const override; void increment_current_active_client_connections_stat() override; void decrement_current_active_client_connections_stat() override; - bool support_sni() const override; - private: Http1ClientSession(Http1ClientSession &); diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc index 2ecfa2e..361f2f8 100644 --- a/proxy/http2/Http2ClientSession.cc +++ b/proxy/http2/Http2ClientSession.cc @@ -87,9 +87,9 @@ Http2ClientSession::free() this->_reenable_event = nullptr; } - if (client_vc) { - client_vc->do_io_close(); - client_vc = nullptr; + if (_vc) { + _vc->do_io_close(); + _vc = nullptr; } // Make sure the we are at the bottom of the stack @@ -151,7 +151,7 @@ Http2ClientSession::free() } } - ink_release_assert(this->client_vc == nullptr); + ink_release_assert(this->_vc == nullptr); delete _h2_pushed_urls; this->connection_state.destroy(); @@ -191,9 +191,9 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB this->_milestones.mark(Http2SsnMilestone::OPEN); // Unique client session identifier. - this->con_id = ProxySession::next_connection_id(); - this->client_vc = new_vc; - client_vc->set_inactivity_timeout(HRTIME_SECONDS(Http2::accept_no_activity_timeout)); + this->con_id = ProxySession::next_connection_id(); + this->_vc = new_vc; + _vc->set_inactivity_timeout(HRTIME_SECONDS(Http2::accept_no_activity_timeout)); this->schedule_event = nullptr; this->mutex = new_vc->mutex; this->in_destroy = false; @@ -206,9 +206,9 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB Debug("ssl_early_data", "read_from_early_data = %" PRId64, this->read_from_early_data); } - Http2SsnDebug("session born, netvc %p", this->client_vc); + Http2SsnDebug("session born, netvc %p", this->_vc); - this->client_vc->set_tcp_congestion_control(CLIENT_SIDE); + this->_vc->set_tcp_congestion_control(CLIENT_SIDE); this->read_buffer = iobuf ? iobuf : new_MIOBuffer(HTTP2_HEADER_BUFFER_SIZE_INDEX); this->read_buffer->water_mark = connection_state.server_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE); @@ -262,32 +262,6 @@ Http2ClientSession::set_upgrade_context(HTTPHdr *h) upgrade_context.req_header->field_delete(MIME_FIELD_HTTP2_SETTINGS, MIME_LEN_HTTP2_SETTINGS); } -VIO * -Http2ClientSession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) -{ - if (client_vc) { - return this->client_vc->do_io_read(c, nbytes, buf); - } else { - return nullptr; - } -} - -VIO * -Http2ClientSession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner) -{ - if (client_vc) { - return this->client_vc->do_io_write(c, nbytes, buf, owner); - } else { - return nullptr; - } -} - -void -Http2ClientSession::do_io_shutdown(ShutdownHowTo_t howto) -{ - this->client_vc->do_io_shutdown(howto); -} - // XXX Currently, we don't have a half-closed state, but we will need to // implement that. After we send a GOAWAY, there // are scenarios where we would like to complete the outstanding streams. @@ -313,12 +287,6 @@ Http2ClientSession::do_io_close(int alerrno) } void -Http2ClientSession::reenable(VIO *vio) -{ - this->client_vc->reenable(vio); -} - -void Http2ClientSession::set_half_close_local_flag(bool flag) { if (!half_close_local && flag) { @@ -377,9 +345,9 @@ Http2ClientSession::main_event_handler(int event, void *edata) case VC_EVENT_EOS: this->set_dying_event(event); this->do_io_close(); - if (client_vc != nullptr) { - client_vc->do_io_close(); - client_vc = nullptr; + if (_vc != nullptr) { + _vc->do_io_close(); + _vc = nullptr; } retval = 0; break; @@ -461,8 +429,8 @@ Http2ClientSession::state_read_connection_preface(int event, void *edata) this->_reader->consume(nbytes); HTTP2_SET_SESSION_HANDLER(&Http2ClientSession::state_start_frame_read); - client_vc->set_inactivity_timeout(HRTIME_SECONDS(Http2::no_activity_timeout_in)); - client_vc->set_active_timeout(HRTIME_SECONDS(Http2::active_timeout_in)); + _vc->set_inactivity_timeout(HRTIME_SECONDS(Http2::no_activity_timeout_in)); + _vc->set_active_timeout(HRTIME_SECONDS(Http2::active_timeout_in)); // XXX start the write VIO ... @@ -676,29 +644,24 @@ Http2ClientSession::_should_do_something_else() return (this->_n_frame_read & 0x7F) == 0; } -int64_t -Http2ClientSession::write_avail() -{ - return this->write_buffer->write_avail(); -} - -NetVConnection * -Http2ClientSession::get_netvc() const -{ - return client_vc; -} - sockaddr const * Http2ClientSession::get_client_addr() { - return client_vc ? client_vc->get_remote_addr() : &cached_client_addr.sa; + return _vc ? _vc->get_remote_addr() : &cached_client_addr.sa; } sockaddr const * Http2ClientSession::get_local_addr() { - return client_vc ? client_vc->get_local_addr() : &cached_local_addr.sa; + return _vc ? _vc->get_local_addr() : &cached_local_addr.sa; } + +int64_t +Http2ClientSession::write_avail() +{ + return this->write_buffer->write_avail(); +} + void Http2ClientSession::write_reenable() { @@ -761,9 +724,3 @@ Http2ClientSession::add_url_to_pushed_table(const char *url, int url_len) _h2_pushed_urls->emplace(url); } } - -bool -Http2ClientSession::support_sni() const -{ - return client_vc ? client_vc->support_sni() : false; -} diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h index dfdb34c..0f1f64b 100644 --- a/proxy/http2/Http2ClientSession.h +++ b/proxy/http2/Http2ClientSession.h @@ -90,11 +90,7 @@ public: // Methods // Implement VConnection interface - VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override; - VIO *do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = 0, bool owner = false) override; void do_io_close(int lerrno = -1) override; - void do_io_shutdown(ShutdownHowTo_t howto) override; - void reenable(VIO *vio) override; // Implement ProxySession interface void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override; @@ -109,7 +105,6 @@ public: //////////////////// // Accessors - NetVConnection *get_netvc() const override; sockaddr const *get_client_addr() override; sockaddr const *get_local_addr() override; int get_transact_count() const override; @@ -144,8 +139,6 @@ public: // Variables Http2ConnectionState connection_state; - bool support_sni() const override; - private: int main_event_handler(int, void *); @@ -163,7 +156,6 @@ private: int64_t total_write_len = 0; SessionHandler session_handler = nullptr; - NetVConnection *client_vc = nullptr; MIOBuffer *read_buffer = nullptr; IOBufferReader *_reader = nullptr; MIOBuffer *write_buffer = nullptr; diff --git a/proxy/http3/Http3Session.cc b/proxy/http3/Http3Session.cc index c393c30..db56c3c 100644 --- a/proxy/http3/Http3Session.cc +++ b/proxy/http3/Http3Session.cc @@ -118,24 +118,12 @@ HQSession::release(ProxyTransaction *trans) return; } -NetVConnection * -HQSession::get_netvc() const -{ - return this->_client_vc; -} - int HQSession::get_transact_count() const { return 0; } -bool -HQSession::support_sni() const -{ - return this->_client_vc ? this->_client_vc->support_sni() : false; -} - // // Http3Session // @@ -149,7 +137,7 @@ Http3Session::Http3Session(NetVConnection *vc) : HQSession(vc) Http3Session::~Http3Session() { - this->_client_vc = nullptr; + this->_vc = nullptr; delete this->_local_qpack; delete this->_remote_qpack; } @@ -202,7 +190,7 @@ Http3Session::remote_qpack() // Http09Session::~Http09Session() { - this->_client_vc = nullptr; + this->_vc = nullptr; } const char * diff --git a/proxy/http3/Http3Session.h b/proxy/http3/Http3Session.h index f688f8c..6bf5fd2 100644 --- a/proxy/http3/Http3Session.h +++ b/proxy/http3/Http3Session.h @@ -32,7 +32,7 @@ class HQSession : public ProxySession public: using super = ProxySession; ///< Parent type - HQSession(NetVConnection *vc) : _client_vc(vc){}; + HQSession(NetVConnection *vc) : ProxySession(vc){}; virtual ~HQSession(); // Implement VConnection interface @@ -47,17 +47,12 @@ public: void start() override; void destroy() override; void release(ProxyTransaction *trans) override; - NetVConnection *get_netvc() const override; int get_transact_count() const override; - bool support_sni() const override; // HQSession void add_transaction(HQTransaction *); HQTransaction *get_transaction(QUICStreamId); -protected: - NetVConnection *_client_vc = nullptr; - private: // this should be unordered map? Queue<HQTransaction> _transaction_list;