You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2017/09/22 01:52:05 UTC
[trafficserver] branch quic-latest updated: Add simple
multi-streamed application
This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push:
new 53afc1e Add simple multi-streamed application
53afc1e is described below
commit 53afc1ece0adfaff27a30e8b6189b0ce9ec08fa9
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Fri Sep 22 10:47:12 2017 +0900
Add simple multi-streamed application
Also add HQClientSession and HQClientTransaction to connect to HttpSM
from QUICSimpleApp. HQClientTransaction convert HTTP/0.9 GETs to HTTP/1.1.
This will be changed to HTTP over QUIC eventually.
---
iocore/net/P_QUICNetVConnection.h | 2 +
iocore/net/P_UnixNetVConnection.h | 4 +-
iocore/net/QUICNetVConnection.cc | 9 +-
iocore/net/UnixNetVConnection.cc | 1 -
iocore/net/quic/Makefile.am | 6 +-
iocore/net/quic/QUICApplication.cc | 17 +++
iocore/net/quic/QUICApplication.h | 2 +
iocore/net/quic/QUICSimpleApp.cc | 92 +++++++++++++
iocore/net/quic/QUICSimpleApp.h | 46 +++++++
iocore/net/quic/QUICStream.h | 1 +
proxy/hq/HQClientSession.cc | 131 ++++++++++++++++++
proxy/hq/HQClientSession.h | 58 ++++++++
proxy/hq/HQClientTransaction.cc | 271 +++++++++++++++++++++++++++++++++++++
proxy/hq/HQClientTransaction.h | 67 +++++++++
proxy/hq/Makefile.am | 3 +-
15 files changed, 701 insertions(+), 9 deletions(-)
diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h
index 9bb2b1a..ae11bf2 100644
--- a/iocore/net/P_QUICNetVConnection.h
+++ b/iocore/net/P_QUICNetVConnection.h
@@ -147,9 +147,11 @@ public:
void init(UDPConnection *, QUICPacketHandler *);
+ // UnixNetVConnection
void reenable(VIO *vio) override;
VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) override;
VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false) override;
+
int startEvent(int event, Event *e);
int state_pre_handshake(int event, Event *data);
int state_handshake(int event, Event *data);
diff --git a/iocore/net/P_UnixNetVConnection.h b/iocore/net/P_UnixNetVConnection.h
index 91b8d2c..be3fbd0 100644
--- a/iocore/net/P_UnixNetVConnection.h
+++ b/iocore/net/P_UnixNetVConnection.h
@@ -281,8 +281,8 @@ public:
ink_hrtime get_inactivity_timeout() override;
ink_hrtime get_active_timeout() override;
- void set_local_addr() override;
- void set_remote_addr() override;
+ virtual void set_local_addr() override;
+ virtual void set_remote_addr() override;
int set_tcp_init_cwnd(int init_cwnd) override;
int set_tcp_congestion_control(int side) override;
void apply_options() override;
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index 56246df..978ea10 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -36,6 +36,7 @@
#include "P_SSLNextProtocolSet.h"
#include "QUICEchoApp.h"
+#include "QUICSimpleApp.h"
#include "QUICDebugNames.h"
#include "QUICEvents.h"
#include "QUICConfig.h"
@@ -76,13 +77,15 @@ QUICNetVConnection::init(UDPConnection *udp_con, QUICPacketHandler *packet_handl
VIO *
QUICNetVConnection::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
{
- return super::do_io_read(c, nbytes, buf);
+ ink_assert(false);
+ return nullptr;
}
VIO *
QUICNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
{
- return super::do_io_write(c, nbytes, buf, owner);
+ ink_assert(false);
+ return nullptr;
}
int
@@ -796,7 +799,7 @@ QUICNetVConnection::_create_application()
if (app_name) {
DebugQUICCon("ALPN: %.*s", app_name_len, app_name);
if (memcmp(TS_ALPN_PROTOCOL_HTTP_QUIC, app_name, app_name_len) == 0) {
- return new QUICEchoApp(this);
+ return new QUICSimpleApp(this, this);
} else {
DebugQUICCon("Negotiated application is not available");
ink_assert(false);
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index c974667..8b0f740 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -33,7 +33,6 @@
// Global
ClassAllocator<UnixNetVConnection> netVCAllocator("netVCAllocator");
-
//
// Reschedule a UnixNetVConnection by moving it
// onto or off of the ready_list
diff --git a/iocore/net/quic/Makefile.am b/iocore/net/quic/Makefile.am
index 40d7638..34463d7 100644
--- a/iocore/net/quic/Makefile.am
+++ b/iocore/net/quic/Makefile.am
@@ -26,9 +26,10 @@ AM_CPPFLAGS += \
-I$(abs_top_srcdir)/proxy/hdrs \
-I$(abs_top_srcdir)/proxy/shared \
-I$(abs_top_srcdir)/proxy/logging \
+ -I$(abs_top_srcdir)/proxy/http \
+ -I$(abs_top_srcdir)/proxy/hq \
-I$(abs_top_srcdir)/mgmt \
-I$(abs_top_srcdir)/mgmt/utils \
- -I$(abs_top_srcdir)/proxy/http \
@OPENSSL_INCLUDES@
noinst_LIBRARIES = libquic.a
@@ -61,7 +62,8 @@ libquic_a_SOURCES = \
QUICDebugNames.cc \
QUICApplication.cc \
QUICApplicationMap.cc \
- QUICEchoApp.cc
+ QUICEchoApp.cc \
+ QUICSimpleApp.cc
include $(top_srcdir)/build/tidy.mk
diff --git a/iocore/net/quic/QUICApplication.cc b/iocore/net/quic/QUICApplication.cc
index b65b89c..dbb832b 100644
--- a/iocore/net/quic/QUICApplication.cc
+++ b/iocore/net/quic/QUICApplication.cc
@@ -68,6 +68,17 @@ QUICStreamIO::write(const uint8_t *buf, int64_t len)
return bytes_add;
}
+int64_t
+QUICStreamIO::write(IOBufferReader *r, int64_t alen, int64_t offset)
+{
+ SCOPED_MUTEX_LOCK(lock, this->_write_vio->mutex, this_ethread());
+
+ int64_t bytes_add = this->_write_buffer->write(r, alen, offset);
+ this->_write_vio->nbytes += bytes_add;
+
+ return bytes_add;
+}
+
void
QUICStreamIO::read_reenable()
{
@@ -80,6 +91,12 @@ QUICStreamIO::write_reenable()
return this->_write_vio->reenable();
}
+IOBufferReader *
+QUICStreamIO::get_read_buffer_reader()
+{
+ return this->_read_buffer_reader;
+}
+
//
// QUICApplication
//
diff --git a/iocore/net/quic/QUICApplication.h b/iocore/net/quic/QUICApplication.h
index 25df608..1d6a3de 100644
--- a/iocore/net/quic/QUICApplication.h
+++ b/iocore/net/quic/QUICApplication.h
@@ -42,8 +42,10 @@ public:
int64_t read_avail();
int64_t read(uint8_t *buf, int64_t len);
int64_t write(const uint8_t *buf, int64_t len);
+ int64_t write(IOBufferReader *r, int64_t len = INT64_MAX, int64_t offset = 0);
void read_reenable();
void write_reenable();
+ IOBufferReader *get_read_buffer_reader();
private:
MIOBuffer *_read_buffer = nullptr;
diff --git a/iocore/net/quic/QUICSimpleApp.cc b/iocore/net/quic/QUICSimpleApp.cc
new file mode 100644
index 0000000..82dc21d
--- /dev/null
+++ b/iocore/net/quic/QUICSimpleApp.cc
@@ -0,0 +1,92 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @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.
+ */
+
+#include "QUICSimpleApp.h"
+
+#include "P_Net.h"
+#include "QUICDebugNames.h"
+
+#include "HQClientSession.h"
+#include "HQClientTransaction.h"
+#include "../IPAllow.h"
+
+static constexpr char tag[] = "quic_simple_app";
+
+QUICSimpleApp::QUICSimpleApp(QUICNetVConnection *client_vc, QUICConnection *qc) : QUICApplication(qc)
+{
+ // FIXME: initialize on HQSessionAccept
+ sockaddr const *client_ip = client_vc->get_remote_addr();
+ const AclRecord *session_acl_record = SessionAccept::testIpAllowPolicy(client_ip);
+
+ this->_client_session = new HQClientSession(client_vc);
+ this->_client_session->acl_record = session_acl_record;
+
+ SET_HANDLER(&QUICSimpleApp::main_event_handler);
+}
+
+QUICSimpleApp::~QUICSimpleApp()
+{
+ delete this->_client_session;
+}
+
+int
+QUICSimpleApp::main_event_handler(int event, Event *data)
+{
+ Debug(tag, "%s", QUICDebugNames::vc_event(event));
+
+ QUICStream *stream = reinterpret_cast<QUICStream *>(data->cookie);
+ QUICStreamIO *stream_io = this->_find_stream_io(stream->id());
+ if (stream_io == nullptr) {
+ Debug(tag, "Unknown Stream, id: %d", stream->id());
+ return -1;
+ }
+
+ switch (event) {
+ case VC_EVENT_READ_READY:
+ case VC_EVENT_READ_COMPLETE: {
+ if (stream_io->read_avail()) {
+ HQClientTransaction *trans = new HQClientTransaction(this->_client_session, stream_io);
+ trans->new_transaction();
+ } else {
+ Debug(tag, "No MSG");
+ }
+ break;
+ }
+ case VC_EVENT_WRITE_READY:
+ case VC_EVENT_WRITE_COMPLETE: {
+ // Nothing to do
+ break;
+ }
+ case VC_EVENT_EOS:
+ case VC_EVENT_ERROR:
+ case VC_EVENT_INACTIVITY_TIMEOUT:
+ case VC_EVENT_ACTIVE_TIMEOUT: {
+ ink_assert(false);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return EVENT_CONT;
+}
diff --git a/iocore/net/quic/QUICSimpleApp.h b/iocore/net/quic/QUICSimpleApp.h
new file mode 100644
index 0000000..c658133
--- /dev/null
+++ b/iocore/net/quic/QUICSimpleApp.h
@@ -0,0 +1,46 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @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 "QUICApplication.h"
+
+class QUICNetVConnection;
+class HQClientSession;
+
+/**
+ * @brief A simple multi-streamed application.
+ * @detail Response to simple HTTP/0.9 GETs
+ *
+ */
+class QUICSimpleApp : public QUICApplication
+{
+public:
+ QUICSimpleApp(QUICNetVConnection *client_vc, QUICConnection *qc);
+ ~QUICSimpleApp();
+
+ int main_event_handler(int event, Event *data);
+
+private:
+ HQClientSession *_client_session = nullptr;
+};
diff --git a/iocore/net/quic/QUICStream.h b/iocore/net/quic/QUICStream.h
index 1a1fe71..77731a6 100644
--- a/iocore/net/quic/QUICStream.h
+++ b/iocore/net/quic/QUICStream.h
@@ -32,6 +32,7 @@
#include "QUICStreamState.h"
#include "QUICFlowController.h"
+class QUICNetVConnection;
class QUICFrameTransmitter;
class QUICStreamState;
class QUICStreamManager;
diff --git a/proxy/hq/HQClientSession.cc b/proxy/hq/HQClientSession.cc
new file mode 100644
index 0000000..e38d086
--- /dev/null
+++ b/proxy/hq/HQClientSession.cc
@@ -0,0 +1,131 @@
+/** @file
+
+ A brief file description
+
+ @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.
+ */
+
+#include "HQClientSession.h"
+
+HQClientSession::HQClientSession(NetVConnection *vc) : _client_vc(vc)
+{
+}
+
+HQClientSession::~HQClientSession()
+{
+ this->_client_vc = nullptr;
+ for (HQClientTransaction *t = this->_transaction_list.head; t; t = static_cast<HQClientTransaction *>(t->link.next)) {
+ delete t;
+ }
+}
+
+VIO *
+HQClientSession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
+{
+ ink_assert(false);
+ return nullptr;
+}
+
+VIO *
+HQClientSession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
+{
+ ink_assert(false);
+ return nullptr;
+}
+
+void
+HQClientSession::do_io_close(int lerrno)
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::do_io_shutdown(ShutdownHowTo_t howto)
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::reenable(VIO *vio)
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::destroy()
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::start()
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader, bool backdoor)
+{
+ ink_assert(false);
+ return;
+}
+
+NetVConnection *
+HQClientSession::get_netvc() const
+{
+ return this->_client_vc;
+}
+
+void
+HQClientSession::release_netvc()
+{
+ ink_assert(false);
+ return;
+}
+
+int
+HQClientSession::get_transact_count() const
+{
+ return 0;
+}
+
+const char *
+HQClientSession::get_protocol_string() const
+{
+ return "hq";
+}
+
+void
+HQClientSession::release(ProxyClientTransaction *trans)
+{
+ ink_assert(false);
+ return;
+}
+
+void
+HQClientSession::add_transaction(HQClientTransaction *trans)
+{
+ this->_transaction_list.enqueue(trans);
+ return;
+}
diff --git a/proxy/hq/HQClientSession.h b/proxy/hq/HQClientSession.h
new file mode 100644
index 0000000..b3a4ce4
--- /dev/null
+++ b/proxy/hq/HQClientSession.h
@@ -0,0 +1,58 @@
+/** @file
+
+ A brief file description
+
+ @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 "ProxyClientSession.h"
+#include "HQClientTransaction.h"
+
+class HQClientSession : public ProxyClientSession
+{
+public:
+ HQClientSession(NetVConnection *vc);
+ ~HQClientSession();
+
+ // 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 ProxyClienSession interface
+ void start() override;
+ void destroy() override;
+ void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader, bool backdoor) override;
+ NetVConnection *get_netvc() const override;
+ void release_netvc() override;
+ int get_transact_count() const override;
+ const char *get_protocol_string() const override;
+ void release(ProxyClientTransaction *trans) override;
+
+ // HQClientSession specific methods
+ void add_transaction(HQClientTransaction *);
+
+private:
+ NetVConnection *_client_vc = nullptr;
+ Queue<HQClientTransaction> _transaction_list;
+};
diff --git a/proxy/hq/HQClientTransaction.cc b/proxy/hq/HQClientTransaction.cc
new file mode 100644
index 0000000..e217ce2
--- /dev/null
+++ b/proxy/hq/HQClientTransaction.cc
@@ -0,0 +1,271 @@
+/** @file
+
+ A brief file description
+
+ @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.
+ */
+
+#include "HQClientTransaction.h"
+
+#include "QUICDebugNames.h"
+
+#include "HQClientSession.h"
+#include "HttpSM.h"
+
+static void
+dump_io_buffer(IOBufferReader *reader)
+{
+ IOBufferReader *debug_reader = reader->clone();
+ uint8_t msg[1024] = {0};
+ int64_t msg_len = 1024;
+ int64_t read_len = debug_reader->read(msg, msg_len);
+ Debug("hq_trans", "len=%" PRId64 "\n%s\n", read_len, msg);
+}
+
+HQClientTransaction::HQClientTransaction(HQClientSession *session, QUICStreamIO *stream_io) : super(), _stream_io(stream_io)
+
+{
+ this->mutex = new_ProxyMutex();
+ this->parent = session; // trans.set_parent();
+ this->sm_reader = this->_read_vio_buf.alloc_reader();
+ static_cast<HQClientSession *>(this->parent)->add_transaction(this);
+
+ SET_HANDLER(&HQClientTransaction::main_event_handler);
+}
+
+void
+HQClientTransaction::set_active_timeout(ink_hrtime timeout_in)
+{
+ if (parent) {
+ parent->set_active_timeout(timeout_in);
+ }
+}
+
+void
+HQClientTransaction::set_inactivity_timeout(ink_hrtime timeout_in)
+{
+ if (parent) {
+ parent->set_inactivity_timeout(timeout_in);
+ }
+}
+
+void
+HQClientTransaction::cancel_inactivity_timeout()
+{
+ if (parent) {
+ parent->cancel_inactivity_timeout();
+ }
+}
+
+void
+HQClientTransaction::release(IOBufferReader *r)
+{
+ super::release(r);
+ this->current_reader = nullptr;
+}
+
+bool
+HQClientTransaction::allow_half_open() const
+{
+ return false;
+}
+
+int
+HQClientTransaction::main_event_handler(int event, void *edata)
+{
+ Debug("hq_trans", "%s", QUICDebugNames::vc_event(event));
+
+ switch (event) {
+ case VC_EVENT_READ_READY:
+ case VC_EVENT_READ_COMPLETE: {
+ if (edata == this->_read_event) {
+ this->_read_event = nullptr;
+ }
+ if (this->_stream_io->read_avail()) {
+ this->_read_request();
+ }
+ break;
+ }
+ case VC_EVENT_WRITE_READY:
+ case VC_EVENT_WRITE_COMPLETE: {
+ if (edata == this->_write_event) {
+ this->_write_event = nullptr;
+ }
+ if (this->_write_vio.get_reader()->read_avail()) {
+ this->_write_response();
+ }
+ break;
+ }
+ default:
+ Debug("hq_trans", "Unknown event %d", event);
+ ink_assert(false);
+ }
+
+ return EVENT_CONT;
+}
+
+void
+HQClientTransaction::reenable(VIO *vio)
+{
+ if (vio->op == VIO::READ) {
+ SCOPED_MUTEX_LOCK(lock, this->_read_vio.mutex, this_ethread());
+
+ if (this->_read_vio.nbytes > 0) {
+ int event = (this->_read_vio.ntodo() == 0) ? VC_EVENT_READ_COMPLETE : VC_EVENT_READ_READY;
+
+ if (this->_read_event == nullptr) {
+ this->_read_event = this_ethread()->schedule_imm_local(this, event);
+ }
+ }
+ } else if (vio->op == VIO::WRITE) {
+ SCOPED_MUTEX_LOCK(lock, this->_write_vio.mutex, this_ethread());
+
+ if (this->_write_vio.nbytes > 0) {
+ int event = (this->_write_vio.ntodo() == 0) ? VC_EVENT_WRITE_COMPLETE : VC_EVENT_WRITE_READY;
+
+ if (this->_write_event == nullptr) {
+ this->_write_event = this_ethread()->schedule_imm_local(this, event);
+ }
+ }
+ }
+}
+
+VIO *
+HQClientTransaction::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
+{
+ if (buf) {
+ this->_read_vio.buffer.writer_for(buf);
+ } else {
+ this->_read_vio.buffer.clear();
+ }
+
+ this->_read_vio.mutex = c ? c->mutex : this->mutex;
+ this->_read_vio._cont = c;
+ this->_read_vio.nbytes = nbytes;
+ this->_read_vio.ndone = 0;
+ this->_read_vio.vc_server = this;
+ this->_read_vio.op = VIO::READ;
+
+ this->_read_vio.reenable();
+
+ return &this->_read_vio;
+}
+
+VIO *
+HQClientTransaction::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
+{
+ if (buf) {
+ this->_write_vio.buffer.reader_for(buf);
+ } else {
+ this->_write_vio.buffer.clear();
+ }
+
+ this->_write_vio.mutex = c ? c->mutex : this->mutex;
+ this->_write_vio._cont = c;
+ this->_write_vio.nbytes = nbytes;
+ this->_write_vio.ndone = 0;
+ this->_write_vio.vc_server = this;
+ this->_write_vio.op = VIO::WRITE;
+
+ this->_write_vio.reenable();
+
+ return &this->_write_vio;
+}
+
+void
+HQClientTransaction::do_io_close(int lerrno)
+{
+ parent->do_io_close(lerrno);
+}
+
+void
+HQClientTransaction::destroy()
+{
+ current_reader = nullptr;
+}
+
+void
+HQClientTransaction::do_io_shutdown(ShutdownHowTo_t howto)
+{
+ if (parent) {
+ parent->do_io_shutdown(howto);
+ }
+}
+
+// Convert HTTP/0.9 to HTTP/1.1
+void
+HQClientTransaction::_read_request()
+{
+ IOBufferReader *client_vio_reader = this->_stream_io->get_read_buffer_reader();
+ int64_t bytes_avail = client_vio_reader->read_avail();
+
+ // Copy only "GET /path/"
+ // Check CRLF or LF
+ int n = 2;
+ if (bytes_avail > 2 && client_vio_reader->start()[bytes_avail - 2] != '\r') {
+ n = 1;
+ }
+
+ MIOBuffer *writer = this->_read_vio.get_writer();
+ writer->write(client_vio_reader, bytes_avail - n);
+
+ // FIXME: Get hostname from SNI?
+ const char version[] = " HTTP/1.1\r\nHost: localhost\r\n\r\n";
+ writer->write(version, sizeof(version));
+
+ dump_io_buffer(this->sm_reader);
+
+ this->_read_vio._cont->handleEvent(VC_EVENT_READ_READY, &this->_read_vio);
+}
+
+// FIXME: already defined somewhere?
+static constexpr char http_1_1_version[] = "HTTP/1.1";
+
+// Convert HTTP/1.1 to HTTP/0.9
+void
+HQClientTransaction::_write_response()
+{
+ IOBufferReader *reader = this->_write_vio.get_reader();
+
+ if (memcmp(reader->start(), http_1_1_version, sizeof(http_1_1_version)) == 0) {
+ // Skip HTTP/1.1 response headers
+ IOBufferBlock *headers = reader->get_current_block();
+ int64_t headers_size = headers->read_avail();
+ reader->consume(headers_size);
+ }
+
+ // Write HTTP/1.1 response body
+ int64_t bytes_avail = reader->read_avail();
+ int64_t total_written = 0;
+ while (total_written < bytes_avail) {
+ int64_t bytes_written = this->_stream_io->write(reader, bytes_avail);
+ reader->consume(bytes_written);
+ this->_write_vio.ndone += bytes_written;
+ total_written += bytes_written;
+ }
+
+ this->_stream_io->write_reenable();
+}
+
+void
+HQClientTransaction::transaction_done()
+{
+ // TODO: set FIN flag
+ return;
+}
diff --git a/proxy/hq/HQClientTransaction.h b/proxy/hq/HQClientTransaction.h
new file mode 100644
index 0000000..fc56a5e
--- /dev/null
+++ b/proxy/hq/HQClientTransaction.h
@@ -0,0 +1,67 @@
+/** @file
+
+ A brief file description
+
+ @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 "ProxyClientTransaction.h"
+
+class QUICStreamIO;
+class HQClientSession;
+
+class HQClientTransaction : public ProxyClientTransaction
+{
+public:
+ using super = ProxyClientTransaction;
+
+ HQClientTransaction(HQClientSession *session, QUICStreamIO *stream_io);
+
+ // Implement VConnection interface.
+ VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = 0) 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;
+
+ // Implement ProxyClienTransaction interface
+ 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;
+ bool allow_half_open() const override;
+ void destroy() override;
+ void do_io_shutdown(ShutdownHowTo_t howto) override;
+ void reenable(VIO *vio) override;
+ void release(IOBufferReader *r) override;
+
+ // HQClientTransaction specific methods
+ int main_event_handler(int event, void *edata);
+
+private:
+ void _read_request();
+ void _write_response();
+
+ MIOBuffer _read_vio_buf = CLIENT_CONNECTION_FIRST_READ_BUFFER_SIZE_INDEX;
+ VIO _read_vio;
+ VIO _write_vio;
+ QUICStreamIO *_stream_io = nullptr;
+ Event *_read_event = nullptr;
+ Event *_write_event = nullptr;
+};
diff --git a/proxy/hq/Makefile.am b/proxy/hq/Makefile.am
index dc545e1..da9e2ff 100644
--- a/proxy/hq/Makefile.am
+++ b/proxy/hq/Makefile.am
@@ -37,7 +37,8 @@ noinst_LIBRARIES = libhq.a
libhq_a_SOURCES = \
HQ.cc \
HQSessionAccept.cc \
- HQSessionAccept.h
+ HQClientSession.cc \
+ HQClientTransaction.cc
tidy-local: $(libhq_a_SOURCES) \
$(CXX_Clang_Tidy)
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].