Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions proxy/ProxySession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

ProxySession::ProxySession() : VConnection(nullptr) {}

ProxySession::ProxySession(NetVConnection *vc) : VConnection(nullptr), _vc(vc) {}

void
ProxySession::set_session_active()
{
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
19 changes: 17 additions & 2 deletions proxy/ProxySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
{
public:
ProxySession();
ProxySession(NetVConnection *vc);

// noncopyable
ProxySession(ProxySession &) = delete;
Expand All @@ -99,7 +100,7 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
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;

Expand Down Expand Up @@ -139,14 +140,20 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
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;

// 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

Expand Down Expand Up @@ -175,6 +182,8 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
// 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);
Expand Down Expand Up @@ -267,3 +276,9 @@ ProxySession::ssl() const
{
return _ssl.get();
}

inline NetVConnection *
ProxySession::get_netvc() const
{
return _vc;
}
106 changes: 23 additions & 83 deletions proxy/http/Http1ClientSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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;
}
Loading