You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2019/10/22 14:05:22 UTC
[trafficserver] 04/06: ProxySsn Refactor move code to cc
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit a0d955185085f10df7d887c5bd7bcea52b8bc1e5
Author: Aaron Canary <ac...@oath.com>
AuthorDate: Tue Aug 27 15:48:03 2019 -0500
ProxySsn Refactor move code to cc
Organizing Header files into something readable
+
+
(cherry picked from commit c8ca9f69a777eab01953b6cb16c91e8d6ddcbca2)
---
proxy/http/Http1ClientSession.cc | 83 ++++++++++++++++
proxy/http/Http1ClientSession.h | 108 ++++----------------
proxy/http/Http1ServerSession.cc | 40 ++++++++
proxy/http/Http1ServerSession.h | 68 +++----------
proxy/http/Http1Transaction.cc | 71 ++++++++++++++
proxy/http/Http1Transaction.h | 96 ++++--------------
proxy/http2/Http2ClientSession.cc | 122 +++++++++++++++++++++++
proxy/http2/Http2ClientSession.h | 166 ++++++++-----------------------
proxy/http2/Http2Stream.cc | 125 ++++++++++++++++++++++++
proxy/http2/Http2Stream.h | 200 ++++++++++----------------------------
10 files changed, 583 insertions(+), 496 deletions(-)
diff --git a/proxy/http/Http1ClientSession.cc b/proxy/http/Http1ClientSession.cc
index 4258362..87edda3 100644
--- a/proxy/http/Http1ClientSession.cc
+++ b/proxy/http/Http1ClientSession.cc
@@ -514,3 +514,86 @@ Http1ClientSession::decrement_current_active_client_connections_stat()
{
HTTP_DECREMENT_DYN_STAT(http_current_active_client_connections_stat);
}
+
+void
+Http1ClientSession::start()
+{
+ // Troll for data to get a new transaction
+ this->release(&trans);
+}
+
+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);
+}
+
+void
+Http1ClientSession::set_half_close_flag(bool flag)
+{
+ half_close = flag;
+}
+
+bool
+Http1ClientSession::get_half_close_flag() const
+{
+ return half_close;
+}
+
+bool
+Http1ClientSession::is_chunked_encoding_supported() const
+{
+ return true;
+}
+
+NetVConnection *
+Http1ClientSession::get_netvc() const
+{
+ return client_vc;
+}
+
+int
+Http1ClientSession::get_transact_count() const
+{
+ return transact_count;
+}
+
+bool
+Http1ClientSession::is_outbound_transparent() const
+{
+ return f_outbound_transparent;
+}
+
+Http1ServerSession *
+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";
+}
diff --git a/proxy/http/Http1ClientSession.h b/proxy/http/Http1ClientSession.h
index 60542ee..7403d42 100644
--- a/proxy/http/Http1ClientSession.h
+++ b/proxy/http/Http1ClientSession.h
@@ -53,18 +53,14 @@ public:
Http1ClientSession();
// Implement ProxySession interface.
+ void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
+ void start() override;
+ void release(ProxyTransaction *trans) override; // Indicate we are done with a transaction
+ void release_transaction();
void destroy() override;
void free() override;
- void release_transaction();
- void
- start() override
- {
- // Troll for data to get a new transaction
- this->release(&trans);
- }
-
- void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
+ 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;
@@ -75,86 +71,20 @@ public:
void do_io_shutdown(ShutdownHowTo_t howto) override;
void reenable(VIO *vio) override;
- bool
- allow_half_open()
- {
- // Only allow half open connections if the not over TLS
- return (client_vc && dynamic_cast<SSLNetVConnection *>(client_vc) == nullptr);
- }
-
- void
- set_half_close_flag(bool flag) override
- {
- half_close = flag;
- }
-
- bool
- get_half_close_flag() const override
- {
- return half_close;
- }
-
- bool
- is_chunked_encoding_supported() const override
- {
- return true;
- }
-
- NetVConnection *
- get_netvc() const override
- {
- return client_vc;
- }
-
- int
- get_transact_count() const override
- {
- return transact_count;
- }
-
- virtual bool
- is_outbound_transparent() const
- {
- return f_outbound_transparent;
- }
-
- // Indicate we are done with a transaction
- void release(ProxyTransaction *trans) override;
-
- void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true) override;
-
- Http1ServerSession *
- get_server_session() const override
- {
- return bound_ss;
- }
-
- void
- set_active_timeout(ink_hrtime timeout_in) override
- {
- if (client_vc)
- client_vc->set_active_timeout(timeout_in);
- }
-
- void
- set_inactivity_timeout(ink_hrtime timeout_in) override
- {
- if (client_vc)
- client_vc->set_inactivity_timeout(timeout_in);
- }
-
- void
- cancel_inactivity_timeout() override
- {
- if (client_vc)
- client_vc->cancel_inactivity_timeout();
- }
-
- const char *
- get_protocol_string() const override
- {
- return "http";
- }
+ // 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;
diff --git a/proxy/http/Http1ServerSession.cc b/proxy/http/Http1ServerSession.cc
index 23d7b53..23ba7b3 100644
--- a/proxy/http/Http1ServerSession.cc
+++ b/proxy/http/Http1ServerSession.cc
@@ -203,3 +203,43 @@ Http1ServerSession::release()
ink_assert(r == HSM_DONE);
}
}
+
+IOBufferReader *
+Http1ServerSession::get_reader()
+{
+ return buf_reader;
+};
+
+NetVConnection *
+Http1ServerSession::get_netvc() const
+{
+ return server_vc;
+};
+
+void
+Http1ServerSession::set_netvc(NetVConnection *new_vc)
+{
+ server_vc = new_vc;
+}
+
+// Keys for matching hostnames
+IpEndpoint const &
+Http1ServerSession::get_server_ip() const
+{
+ ink_release_assert(server_vc != nullptr);
+ return server_vc->get_remote_endpoint();
+}
+
+int
+Http1ServerSession::populate_protocol(std::string_view *result, int size) const
+{
+ auto vc = this->get_netvc();
+ return vc ? vc->populate_protocol(result, size) : 0;
+}
+
+const char *
+Http1ServerSession::protocol_contains(std::string_view tag_prefix) const
+{
+ auto vc = this->get_netvc();
+ return vc ? vc->protocol_contains(tag_prefix) : nullptr;
+}
diff --git a/proxy/http/Http1ServerSession.h b/proxy/http/Http1ServerSession.h
index e1851ef..f558f3a 100644
--- a/proxy/http/Http1ServerSession.h
+++ b/proxy/http/Http1ServerSession.h
@@ -63,55 +63,32 @@ public:
Http1ServerSession(self_type const &) = delete;
self_type &operator=(self_type const &) = delete;
- void destroy();
+ ////////////////////
+ // Methods
void new_connection(NetVConnection *new_vc);
+ void release();
+ void destroy();
- /** Enable tracking the number of outbound session.
- *
- * @param group The connection tracking group.
- *
- * The @a group must have already incremented the connection count. It will be cleaned up when the
- * session terminates.
- */
- void enable_outbound_connection_tracking(OutboundConnTrack::Group *group);
-
- IOBufferReader *
- get_reader()
- {
- return buf_reader;
- };
-
+ // VConnection Methods
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;
- void release();
+ void enable_outbound_connection_tracking(OutboundConnTrack::Group *group);
+ IOBufferReader *get_reader();
void attach_hostname(const char *hostname);
- NetVConnection *
- get_netvc() const
- {
- return server_vc;
- };
- void
- set_netvc(NetVConnection *new_vc)
- {
- server_vc = new_vc;
- }
-
- // Keys for matching hostnames
- IpEndpoint const &
- get_server_ip() const
- {
- ink_release_assert(server_vc != nullptr);
- return server_vc->get_remote_endpoint();
- }
-
+ NetVConnection *get_netvc() const;
+ void set_netvc(NetVConnection *new_vc);
+ IpEndpoint const &get_server_ip() const;
+ int populate_protocol(std::string_view *result, int size) const;
+ const char *protocol_contains(std::string_view tag_prefix) const;
+
+ ////////////////////
+ // Variables
CryptoHash hostname_hash;
int64_t con_id = 0;
@@ -136,7 +113,6 @@ public:
// Copy of the owning SM's server session sharing settings
TSServerSessionSharingMatchType sharing_match = TS_SERVER_SESSION_SHARING_MATCH_BOTH;
TSServerSessionSharingPoolType sharing_pool = TS_SERVER_SESSION_SHARING_POOL_GLOBAL;
- // int share_session;
/// Hash map descriptor class for IP map.
struct IPLinkage {
@@ -178,20 +154,6 @@ public:
// an asynchronous cancel on NT
MIOBuffer *read_buffer = nullptr;
- virtual int
- populate_protocol(std::string_view *result, int size) const
- {
- auto vc = this->get_netvc();
- return vc ? vc->populate_protocol(result, size) : 0;
- }
-
- virtual const char *
- protocol_contains(std::string_view tag_prefix) const
- {
- auto vc = this->get_netvc();
- return vc ? vc->protocol_contains(tag_prefix) : nullptr;
- }
-
private:
NetVConnection *server_vc = nullptr;
int magic = HTTP_SS_MAGIC_DEAD;
diff --git a/proxy/http/Http1Transaction.cc b/proxy/http/Http1Transaction.cc
index 6ccd291..e69991e 100644
--- a/proxy/http/Http1Transaction.cc
+++ b/proxy/http/Http1Transaction.cc
@@ -46,6 +46,11 @@ Http1Transaction::release(IOBufferReader *r)
}
}
+void Http1Transaction::destroy() // todo make ~Http1Transaction()
+{
+ current_reader = nullptr;
+}
+
void
Http1Transaction::transaction_done()
{
@@ -54,6 +59,12 @@ Http1Transaction::transaction_done()
}
}
+void
+Http1Transaction::reenable(VIO *vio)
+{
+ proxy_ssn->reenable(vio);
+}
+
bool
Http1Transaction::allow_half_open() const
{
@@ -76,3 +87,63 @@ Http1Transaction::decrement_client_transactions_stat()
{
HTTP_DECREMENT_DYN_STAT(http_current_client_transactions_stat);
}
+
+// Implement VConnection interface.
+VIO *
+Http1Transaction::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
+{
+ return proxy_ssn->do_io_read(c, nbytes, buf);
+}
+VIO *
+Http1Transaction::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
+{
+ return proxy_ssn->do_io_write(c, nbytes, buf, owner);
+}
+
+void
+Http1Transaction::do_io_close(int lerrno)
+{
+ proxy_ssn->do_io_close(lerrno);
+ // this->destroy(); Parent owns this data structure. No need for separate destroy.
+}
+
+void
+Http1Transaction::do_io_shutdown(ShutdownHowTo_t howto)
+{
+ proxy_ssn->do_io_shutdown(howto);
+}
+
+void
+Http1Transaction::set_reader(IOBufferReader *reader)
+{
+ sm_reader = reader;
+}
+
+void
+Http1Transaction::set_active_timeout(ink_hrtime timeout_in)
+{
+ if (proxy_ssn)
+ proxy_ssn->set_active_timeout(timeout_in);
+}
+void
+Http1Transaction::set_inactivity_timeout(ink_hrtime timeout_in)
+{
+ if (proxy_ssn)
+ proxy_ssn->set_inactivity_timeout(timeout_in);
+}
+void
+Http1Transaction::cancel_inactivity_timeout()
+{
+ if (proxy_ssn)
+ proxy_ssn->cancel_inactivity_timeout();
+}
+//
+int
+Http1Transaction::get_transaction_id() const
+{
+ // For HTTP/1 there is only one on-going transaction at a time per session/connection. Therefore, the transaction count can be
+ // presumed not to increase during the lifetime of a transaction, thus this function will return a consistent unique transaction
+ // identifier.
+ //
+ return proxy_ssn->get_transact_count();
+}
diff --git a/proxy/http/Http1Transaction.h b/proxy/http/Http1Transaction.h
index eccd833..3c3215d 100644
--- a/proxy/http/Http1Transaction.h
+++ b/proxy/http/Http1Transaction.h
@@ -33,90 +33,34 @@ public:
using super_type = ProxyTransaction;
Http1Transaction() {}
- // Implement VConnection interface.
- VIO *
- do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override
- {
- return proxy_ssn->do_io_read(c, nbytes, buf);
- }
- VIO *
- do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = nullptr, bool owner = false) override
- {
- return proxy_ssn->do_io_write(c, nbytes, buf, owner);
- }
-
- void
- do_io_close(int lerrno = -1) override
- {
- proxy_ssn->do_io_close(lerrno);
- // this->destroy(); Parent owns this data structure. No need for separate destroy.
- }
-
- // Don't destroy your elements. Rely on the Http1ClientSession to clean up the
- // Http1Transaction class as necessary. The super::destroy() clears the
- // mutex, which Http1ClientSession owns.
- void
- destroy() override
- {
- current_reader = nullptr;
- }
-
- void
- do_io_shutdown(ShutdownHowTo_t howto) override
- {
- proxy_ssn->do_io_shutdown(howto);
- }
-
- void
- reenable(VIO *vio) override
- {
- proxy_ssn->reenable(vio);
- }
-
- void
- set_reader(IOBufferReader *reader)
- {
- sm_reader = reader;
- }
+ ////////////////////
+ // Methods
void release(IOBufferReader *r) override;
+ void destroy() override; // todo make ~Http1Transaction()
- bool allow_half_open() const 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;
- // Pass on the timeouts to the netvc
- void
- set_active_timeout(ink_hrtime timeout_in) override
- {
- if (proxy_ssn)
- proxy_ssn->set_active_timeout(timeout_in);
- }
- void
- set_inactivity_timeout(ink_hrtime timeout_in) override
- {
- if (proxy_ssn)
- proxy_ssn->set_inactivity_timeout(timeout_in);
- }
- void
- cancel_inactivity_timeout() override
- {
- if (proxy_ssn)
- proxy_ssn->cancel_inactivity_timeout();
- }
+ bool allow_half_open() 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;
void transaction_done() override;
-
- int
- get_transaction_id() const override
- {
- // For HTTP/1 there is only one on-going transaction at a time per session/connection. Therefore, the transaction count can be
- // presumed not to increase during the lifetime of a transaction, thus this function will return a consistent unique transaction
- // identifier.
- //
- return proxy_ssn->get_transact_count();
- }
-
+ int get_transaction_id() const override;
void increment_client_transactions_stat() override;
void decrement_client_transactions_stat() override;
+ void set_reader(IOBufferReader *reader);
+
+ ////////////////////
+ // Variables
+
protected:
bool outbound_transparent{false};
};
diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
index a4658d5..f52155c 100644
--- a/proxy/http2/Http2ClientSession.cc
+++ b/proxy/http2/Http2ClientSession.cc
@@ -649,3 +649,125 @@ Http2ClientSession::_should_do_something_else()
// Do something else every 128 incoming frames
return (this->_n_frame_read & 0x7F) == 0;
}
+
+bool
+Http2ClientSession::ready_to_free() const
+{
+ return kill_me;
+}
+
+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;
+}
+
+sockaddr const *
+Http2ClientSession::get_local_addr()
+{
+ return client_vc ? client_vc->get_local_addr() : &cached_local_addr.sa;
+}
+void
+Http2ClientSession::write_reenable()
+{
+ write_vio->reenable();
+}
+
+const Http2UpgradeContext &
+Http2ClientSession::get_upgrade_context() const
+{
+ return upgrade_context;
+}
+
+int
+Http2ClientSession::get_transact_count() const
+{
+ return connection_state.get_stream_requests();
+}
+
+void
+Http2ClientSession::release(ProxyTransaction *trans)
+{
+}
+
+void
+Http2ClientSession::set_dying_event(int event)
+{
+ dying_event = event;
+}
+
+int
+Http2ClientSession::get_dying_event() const
+{
+ return dying_event;
+}
+
+bool
+Http2ClientSession::is_recursing() const
+{
+ return recursion > 0;
+}
+
+const char *
+Http2ClientSession::get_protocol_string() const
+{
+ return "http/2";
+}
+
+int
+Http2ClientSession::populate_protocol(std::string_view *result, int size) const
+{
+ int retval = 0;
+ if (size > retval) {
+ result[retval++] = IP_PROTO_TAG_HTTP_2_0;
+ if (size > retval) {
+ retval += super::populate_protocol(result + retval, size - retval);
+ }
+ }
+ return retval;
+}
+
+const char *
+Http2ClientSession::protocol_contains(std::string_view prefix) const
+{
+ const char *retval = nullptr;
+
+ if (prefix.size() <= IP_PROTO_TAG_HTTP_2_0.size() && strncmp(IP_PROTO_TAG_HTTP_2_0.data(), prefix.data(), prefix.size()) == 0) {
+ retval = IP_PROTO_TAG_HTTP_2_0.data();
+ } else {
+ retval = super::protocol_contains(prefix);
+ }
+ return retval;
+}
+
+bool
+Http2ClientSession::get_half_close_local_flag() const
+{
+ return half_close_local;
+}
+
+bool
+Http2ClientSession::is_url_pushed(const char *url, int url_len)
+{
+ return h2_pushed_urls.find(url) != h2_pushed_urls.end();
+}
+
+void
+Http2ClientSession::add_url_to_pushed_table(const char *url, int url_len)
+{
+ if (h2_pushed_urls.size() < Http2::push_diary_size) {
+ h2_pushed_urls.emplace(url);
+ }
+}
+
+int64_t
+Http2ClientSession::write_buffer_size()
+{
+ return write_buffer->max_read_avail();
+}
diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h
index 433be89..48df0f0 100644
--- a/proxy/http2/Http2ClientSession.h
+++ b/proxy/http2/Http2ClientSession.h
@@ -160,148 +160,54 @@ private:
class Http2ClientSession : public ProxySession
{
public:
- typedef ProxySession super; ///< Parent type.
- typedef int (Http2ClientSession::*SessionHandler)(int, void *);
+ using super = ProxySession; ///< Parent type.
+ using SessionHandler = int (Http2ClientSession::*)(int, void *);
Http2ClientSession();
- // Implement ProxySession interface.
- void start() override;
- void destroy() override;
- void free() override;
- void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
+ /////////////////////
+ // Methods
- bool
- ready_to_free() const
- {
- return kill_me;
- }
-
- // Implement VConnection interface.
+ // 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;
+ 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;
- NetVConnection *
- get_netvc() const override
- {
- return client_vc;
- }
-
- sockaddr const *
- get_client_addr() override
- {
- return client_vc ? client_vc->get_remote_addr() : &cached_client_addr.sa;
- }
-
- sockaddr const *
- get_local_addr() override
- {
- return client_vc ? client_vc->get_local_addr() : &cached_local_addr.sa;
- }
-
- void
- write_reenable()
- {
- write_vio->reenable();
- }
-
- void set_upgrade_context(HTTPHdr *h);
-
- const Http2UpgradeContext &
- get_upgrade_context() const
- {
- return upgrade_context;
- }
-
- int
- get_transact_count() const override
- {
- return connection_state.get_stream_requests();
- }
-
- void
- release(ProxyTransaction *trans) override
- {
- }
-
- Http2ConnectionState connection_state;
- void
- set_dying_event(int event)
- {
- dying_event = event;
- }
-
- int
- get_dying_event() const
- {
- return dying_event;
- }
-
- bool
- is_recursing() const
- {
- return recursion > 0;
- }
-
- const char *
- get_protocol_string() const override
- {
- return "http/2";
- }
-
- int
- populate_protocol(std::string_view *result, int size) const override
- {
- int retval = 0;
- if (size > retval) {
- result[retval++] = IP_PROTO_TAG_HTTP_2_0;
- if (size > retval) {
- retval += super::populate_protocol(result + retval, size - retval);
- }
- }
- return retval;
- }
-
- const char *
- protocol_contains(std::string_view prefix) const override
- {
- const char *retval = nullptr;
-
- if (prefix.size() <= IP_PROTO_TAG_HTTP_2_0.size() && strncmp(IP_PROTO_TAG_HTTP_2_0.data(), prefix.data(), prefix.size()) == 0) {
- retval = IP_PROTO_TAG_HTTP_2_0.data();
- } else {
- retval = super::protocol_contains(prefix);
- }
- return retval;
- }
+ // Implement ProxySession interface
+ void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
+ void start() override;
+ void destroy() override;
+ void release(ProxyTransaction *trans) override;
+ void free() override;
+ // more methods
+ void write_reenable();
+
+ ////////////////////
+ // Accessors
+ NetVConnection *get_netvc() const override;
+ sockaddr const *get_client_addr() override;
+ sockaddr const *get_local_addr() override;
+ int get_transact_count() const override;
+ const char *get_protocol_string() const override;
+ int populate_protocol(std::string_view *result, int size) const override;
+ const char *protocol_contains(std::string_view prefix) const override;
void increment_current_active_client_connections_stat() override;
void decrement_current_active_client_connections_stat() override;
+ void set_upgrade_context(HTTPHdr *h);
+ const Http2UpgradeContext &get_upgrade_context() const;
+ 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
- {
- return half_close_local;
- }
-
- bool
- is_url_pushed(const char *url, int url_len)
- {
- return h2_pushed_urls.find(url) != h2_pushed_urls.end();
- }
-
- void
- add_url_to_pushed_table(const char *url, int url_len)
- {
- if (h2_pushed_urls.size() < Http2::push_diary_size) {
- h2_pushed_urls.emplace(url);
- }
- }
+ 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);
+ int64_t write_buffer_size();
// Record history from Http2ConnectionState
void remember(const SourceLocation &location, int event, int reentrant = NO_REENTRANT);
@@ -310,6 +216,10 @@ public:
Http2ClientSession(Http2ClientSession &) = delete;
Http2ClientSession &operator=(const Http2ClientSession &) = delete;
+ ///////////////////
+ // Variables
+ Http2ConnectionState connection_state;
+
private:
int main_event_handler(int, void *);
diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc
index 8bdb163..2694a33 100644
--- a/proxy/http2/Http2Stream.cc
+++ b/proxy/http2/Http2Stream.cc
@@ -38,6 +38,27 @@
ClassAllocator<Http2Stream> http2StreamAllocator("http2StreamAllocator");
+Http2Stream::Http2Stream(Http2StreamId sid, ssize_t initial_rwnd) : _id(sid), _client_rwnd(initial_rwnd)
+{
+ SET_HANDLER(&Http2Stream::main_event_handler);
+}
+
+void
+Http2Stream::init(Http2StreamId sid, ssize_t initial_rwnd)
+{
+ this->mark_milestone(Http2StreamMilestone::OPEN);
+
+ this->_id = sid;
+ this->_thread = this_ethread();
+ this->_client_rwnd = initial_rwnd;
+
+ sm_reader = request_reader = request_buffer.alloc_reader();
+ // FIXME: Are you sure? every "stream" needs request_header?
+ _req_header.create(HTTP_TYPE_REQUEST);
+ response_header.create(HTTP_TYPE_RESPONSE);
+ http_parser_init(&http_parser);
+}
+
int
Http2Stream::main_event_handler(int event, void *edata)
{
@@ -1037,3 +1058,107 @@ Http2Stream::_switch_thread_if_not_on_right_thread(int event, void *edata)
}
return true;
}
+
+bool
+Http2Stream::is_body_done() const
+{
+ return body_done;
+}
+
+void
+Http2Stream::mark_body_done()
+{
+ body_done = true;
+ if (response_is_chunked()) {
+ ink_assert(chunked_handler.state == ChunkedHandler::CHUNK_READ_DONE ||
+ chunked_handler.state == ChunkedHandler::CHUNK_READ_ERROR);
+ this->write_vio.nbytes = response_header.length_get() + chunked_handler.dechunked_size;
+ }
+}
+
+void
+Http2Stream::update_sent_count(unsigned num_bytes)
+{
+ bytes_sent += num_bytes;
+ this->write_vio.ndone += num_bytes;
+}
+
+Http2StreamId
+Http2Stream::get_id() const
+{
+ return _id;
+}
+
+int
+Http2Stream::get_transaction_id() const
+{
+ return _id;
+}
+
+Http2StreamState
+Http2Stream::get_state() const
+{
+ return _state;
+}
+
+void
+Http2Stream::update_initial_rwnd(Http2WindowSize new_size)
+{
+ this->_client_rwnd = new_size;
+}
+
+bool
+Http2Stream::has_trailing_header() const
+{
+ return trailing_header;
+}
+
+void
+Http2Stream::set_request_headers(HTTPHdr &h2_headers)
+{
+ _req_header.copy(&h2_headers);
+}
+
+// Check entire DATA payload length if content-length: header is exist
+void
+Http2Stream::increment_data_length(uint64_t length)
+{
+ data_length += length;
+}
+
+bool
+Http2Stream::payload_length_is_valid() const
+{
+ uint32_t content_length = _req_header.get_content_length();
+ return content_length == 0 || content_length == data_length;
+}
+
+bool
+Http2Stream::response_is_chunked() const
+{
+ return chunked;
+}
+
+bool
+Http2Stream::allow_half_open() const
+{
+ return false;
+}
+
+bool
+Http2Stream::is_client_state_writeable() const
+{
+ return _state == Http2StreamState::HTTP2_STREAM_STATE_OPEN || _state == Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_REMOTE ||
+ _state == Http2StreamState::HTTP2_STREAM_STATE_RESERVED_LOCAL;
+}
+bool
+Http2Stream::is_closed() const
+{
+ return closed;
+}
+
+bool
+Http2Stream::is_first_transaction() const
+{
+ return is_first_transaction_flag;
+}
diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h
index 8b747bd..8b0489b 100644
--- a/proxy/http2/Http2Stream.h
+++ b/proxy/http2/Http2Stream.h
@@ -50,122 +50,31 @@ enum class Http2StreamMilestone {
class Http2Stream : public ProxyTransaction
{
public:
- typedef ProxyTransaction super; ///< Parent type.
- Http2Stream(Http2StreamId sid = 0, ssize_t initial_rwnd = Http2::initial_window_size) : _id(sid), _client_rwnd(initial_rwnd)
- {
- SET_HANDLER(&Http2Stream::main_event_handler);
- }
-
- void
- init(Http2StreamId sid, ssize_t initial_rwnd)
- {
- this->mark_milestone(Http2StreamMilestone::OPEN);
-
- this->_id = sid;
- this->_thread = this_ethread();
- this->_client_rwnd = initial_rwnd;
-
- sm_reader = request_reader = request_buffer.alloc_reader();
- // FIXME: Are you sure? every "stream" needs request_header?
- _req_header.create(HTTP_TYPE_REQUEST);
- response_header.create(HTTP_TYPE_RESPONSE);
- http_parser_init(&http_parser);
- }
+ using super = ProxyTransaction; ///< Parent type.
- int main_event_handler(int event, void *edata);
-
- void destroy() override;
+ Http2Stream(Http2StreamId sid = 0, ssize_t initial_rwnd = Http2::initial_window_size);
- bool
- is_body_done() const
- {
- return body_done;
- }
-
- void
- mark_body_done()
- {
- body_done = true;
- if (response_is_chunked()) {
- ink_assert(chunked_handler.state == ChunkedHandler::CHUNK_READ_DONE ||
- chunked_handler.state == ChunkedHandler::CHUNK_READ_ERROR);
- this->write_vio.nbytes = response_header.length_get() + chunked_handler.dechunked_size;
- }
- }
-
- void
- update_sent_count(unsigned num_bytes)
- {
- bytes_sent += num_bytes;
- this->write_vio.ndone += num_bytes;
- }
-
- Http2StreamId
- get_id() const
- {
- return _id;
- }
-
- int
- get_transaction_id() const override
- {
- return _id;
- }
-
- Http2StreamState
- get_state() const
- {
- return _state;
- }
+ void init(Http2StreamId sid, ssize_t initial_rwnd);
- bool change_state(uint8_t type, uint8_t flags);
+ int main_event_handler(int event, void *edata);
- void
- update_initial_rwnd(Http2WindowSize new_size)
- {
- this->_client_rwnd = new_size;
- }
-
- bool
- has_trailing_header() const
- {
- return trailing_header;
- }
-
- void
- set_request_headers(HTTPHdr &h2_headers)
- {
- _req_header.copy(&h2_headers);
- }
-
- // Check entire DATA payload length if content-length: header is exist
- void
- increment_data_length(uint64_t length)
- {
- data_length += length;
- }
-
- bool
- payload_length_is_valid() const
- {
- uint32_t content_length = _req_header.get_content_length();
- return content_length == 0 || content_length == data_length;
- }
+ void destroy() override;
+ void release(IOBufferReader *r) override;
+ void reenable(VIO *vio) override;
+ void transaction_done() override;
- Http2ErrorCode decode_header_blocks(HpackHandle &hpack_handle, uint32_t maximum_table_size);
- void send_request(Http2ConnectionState &cstate);
+ void do_io_shutdown(ShutdownHowTo_t) override {}
VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) override;
VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *abuffer, bool owner = false) override;
void do_io_close(int lerrno = -1) override;
+
+ Http2ErrorCode decode_header_blocks(HpackHandle &hpack_handle, uint32_t maximum_table_size);
+ void send_request(Http2ConnectionState &cstate);
void initiating_close();
void terminate_if_possible();
- void do_io_shutdown(ShutdownHowTo_t) override {}
void update_read_request(int64_t read_len, bool send_update, bool check_eos = false);
void update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool send_update);
void signal_write_event(bool call_update);
- void reenable(VIO *vio) override;
- void transaction_done() override;
-
void restart_sending();
void push_promise(URL &url, const MIMEField *accept_encoding);
@@ -177,6 +86,44 @@ public:
Http2ErrorCode increment_server_rwnd(size_t amount);
Http2ErrorCode decrement_server_rwnd(size_t amount);
+ /////////////////
+ // Accessors
+ void set_active_timeout(ink_hrtime timeout_in) override;
+ void set_inactivity_timeout(ink_hrtime timeout_in) override;
+ void cancel_inactivity_timeout() override;
+
+ bool allow_half_open() const override;
+ bool is_first_transaction() const override;
+ void increment_client_transactions_stat() override;
+ void decrement_client_transactions_stat() override;
+ int get_transaction_id() const override;
+
+ void clear_inactive_timer();
+ void clear_active_timer();
+ void clear_timers();
+ void clear_io_events();
+
+ bool is_client_state_writeable() const;
+ bool is_closed() const;
+ bool response_is_chunked() const;
+ IOBufferReader *response_get_data_reader() const;
+
+ void mark_milestone(Http2StreamMilestone type);
+
+ void increment_data_length(uint64_t length);
+ bool payload_length_is_valid() const;
+ bool is_body_done() const;
+ void mark_body_done();
+ void update_sent_count(unsigned num_bytes);
+ Http2StreamId get_id() const;
+ Http2StreamState get_state() const;
+ bool change_state(uint8_t type, uint8_t flags);
+ void update_initial_rwnd(Http2WindowSize new_size);
+ bool has_trailing_header() const;
+ void set_request_headers(HTTPHdr &h2_headers);
+
+ //////////////////
+ // Variables
uint8_t *header_blocks = nullptr;
uint32_t header_blocks_length = 0; // total length of header blocks (not include
// Padding or other fields)
@@ -196,53 +143,6 @@ public:
MIOBuffer request_buffer = CLIENT_CONNECTION_FIRST_READ_BUFFER_SIZE_INDEX;
Http2DependencyTree::Node *priority_node = nullptr;
- IOBufferReader *response_get_data_reader() const;
- bool
- response_is_chunked() const
- {
- return chunked;
- }
-
- void release(IOBufferReader *r) override;
-
- bool
- allow_half_open() const override
- {
- return false;
- }
-
- void set_active_timeout(ink_hrtime timeout_in) override;
- void set_inactivity_timeout(ink_hrtime timeout_in) override;
- void cancel_inactivity_timeout() override;
- void clear_inactive_timer();
- void clear_active_timer();
- void clear_timers();
- void clear_io_events();
- bool
- is_client_state_writeable() const
- {
- return _state == Http2StreamState::HTTP2_STREAM_STATE_OPEN ||
- _state == Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_REMOTE ||
- _state == Http2StreamState::HTTP2_STREAM_STATE_RESERVED_LOCAL;
- }
-
- bool
- is_closed() const
- {
- return closed;
- }
-
- bool
- is_first_transaction() const override
- {
- return is_first_transaction_flag;
- }
-
- void increment_client_transactions_stat() override;
- void decrement_client_transactions_stat() override;
-
- void mark_milestone(Http2StreamMilestone type);
-
private:
void response_initialize_data_handling(bool &is_done);
void response_process_data(bool &is_done);