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 2018/04/13 06:58:34 UTC
[trafficserver] 03/03: Add HTTP/0.9 exchange support on quic client
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
commit 6212927aa508e8c365a405e7e0e2db47547f54a5
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Fri Apr 13 15:55:58 2018 +0900
Add HTTP/0.9 exchange support on quic client
Out of scope: starting session or transaction of HTTP/QUIC
---
cmd/traffic_quic/quic_client.cc | 80 +++++++++++++++++++++++++++++++++++++++-
cmd/traffic_quic/quic_client.h | 19 ++++++++--
cmd/traffic_quic/traffic_quic.cc | 6 ++-
3 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/cmd/traffic_quic/quic_client.cc b/cmd/traffic_quic/quic_client.cc
index 3a2e661..2396414 100644
--- a/cmd/traffic_quic/quic_client.cc
+++ b/cmd/traffic_quic/quic_client.cc
@@ -72,8 +72,12 @@ QUICClient::state_http_server_open(int event, void *data)
switch (event) {
case NET_EVENT_OPEN: {
// TODO: create ProxyServerSession / ProxyServerTransaction
- // TODO: send HTTP/0.9 message
Debug("quic_client", "start proxy server ssn/txn");
+
+ QUICNetVConnection *conn = static_cast<QUICNetVConnection *>(data);
+ QUICClientApp *app = new QUICClientApp(conn);
+ app->start(this->_path);
+
break;
}
case NET_EVENT_OPEN_FAILED: {
@@ -90,3 +94,77 @@ QUICClient::state_http_server_open(int event, void *data)
return 0;
}
+
+//
+// QUICClientApp
+//
+#define QUICClientAppDebug(fmt, ...) \
+ Debug("quic_client_app", "[%" PRIx64 "] " fmt, static_cast<uint64_t>(this->_qc->connection_id()), ##__VA_ARGS__)
+
+QUICClientApp::QUICClientApp(QUICNetVConnection *qvc) : QUICApplication(qvc)
+{
+ this->_qc->stream_manager()->set_default_application(this);
+
+ SET_HANDLER(&QUICClientApp::main_event_handler);
+}
+
+void
+QUICClientApp::start(const char *path)
+{
+ QUICStreamId stream_id;
+ QUICErrorUPtr error = this->_qc->stream_manager()->create_bidi_stream(stream_id);
+
+ if (error->cls != QUICErrorClass::NONE) {
+ Error("%s", error->msg);
+ ink_assert(abort);
+ }
+
+ // TODO: move to transaction
+ char request[1024] = {0};
+ int request_len = snprintf(request, sizeof(request), "GET %s\r\n", path);
+
+ QUICClientAppDebug("\n%s", request);
+
+ QUICStreamIO *stream_io = this->_find_stream_io(stream_id);
+
+ stream_io->write(reinterpret_cast<uint8_t *>(request), request_len);
+ stream_io->write_reenable();
+}
+
+int
+QUICClientApp::main_event_handler(int event, Event *data)
+{
+ QUICClientAppDebug("%s (%d)", get_vc_event_name(event), event);
+
+ VIO *vio = reinterpret_cast<VIO *>(data);
+ QUICStreamIO *stream_io = this->_find_stream_io(vio);
+
+ if (stream_io == nullptr) {
+ QUICClientAppDebug("Unknown Stream");
+ return -1;
+ }
+
+ switch (event) {
+ case VC_EVENT_READ_READY:
+ case VC_EVENT_READ_COMPLETE:
+ if (stream_io->is_read_avail_more_than(0)) {
+ uint8_t response[1024] = {0};
+ stream_io->read(response, sizeof(response));
+ QUICClientAppDebug("\n%s", response);
+ }
+ break;
+ case VC_EVENT_WRITE_READY:
+ case VC_EVENT_WRITE_COMPLETE:
+ 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/cmd/traffic_quic/quic_client.h b/cmd/traffic_quic/quic_client.h
index ea71739..15071c3 100644
--- a/cmd/traffic_quic/quic_client.h
+++ b/cmd/traffic_quic/quic_client.h
@@ -28,10 +28,13 @@
#include "I_NetVConnection.h"
#include "P_QUICNetProcessor.h"
+#include "QUICApplication.h"
+
class QUICClient : public Continuation
{
public:
- QUICClient(const char *addr, const char *port) : Continuation(new_ProxyMutex()), _remote_addr(addr), _remote_port(port)
+ QUICClient(const char *addr, const char *port, const char *path)
+ : Continuation(new_ProxyMutex()), _remote_addr(addr), _remote_port(port), _path(path)
{
SET_HANDLER(&QUICClient::start);
};
@@ -41,7 +44,17 @@ public:
int state_http_server_open(int event, void *data);
private:
- const char *_remote_addr;
- const char *_remote_port;
+ const char *_remote_addr = nullptr;
+ const char *_remote_port = nullptr;
struct addrinfo *_remote_addr_info = nullptr;
+ const char *_path = nullptr;
+};
+
+class QUICClientApp : public QUICApplication
+{
+public:
+ QUICClientApp(QUICNetVConnection *qvc);
+
+ void start(const char *path);
+ int main_event_handler(int event, Event *data);
};
diff --git a/cmd/traffic_quic/traffic_quic.cc b/cmd/traffic_quic/traffic_quic.cc
index c46e80f..2098d49 100644
--- a/cmd/traffic_quic/traffic_quic.cc
+++ b/cmd/traffic_quic/traffic_quic.cc
@@ -51,11 +51,13 @@ main(int argc, const char **argv)
char addr[1024] = "127.0.0.1";
char port[16] = "4433";
- char debug_tags[1024] = "quic|udp";
+ char path[1018] = "/";
+ char debug_tags[1024] = "quic";
const ArgumentDescription argument_descriptions[] = {
{"addr", 'a', "Address", "S1023", addr, nullptr, nullptr},
{"port", 'p', "Port", "S15", port, nullptr, nullptr},
+ {"path", 'P', "Path", "S1017", path, nullptr, nullptr},
{"debug", 'T', "Vertical-bar-separated Debug Tags", "S1023", debug_tags, nullptr, nullptr},
HELP_ARGUMENT_DESCRIPTION(),
VERSION_ARGUMENT_DESCRIPTION(),
@@ -87,7 +89,7 @@ main(int argc, const char **argv)
udpNet.start(1, stacksize);
quic_NetProcessor.start(-1, stacksize);
- QUICClient client(addr, port);
+ QUICClient client(addr, port, path);
eventProcessor.schedule_in(&client, 1, ET_NET);
this_thread()->execute();
--
To stop receiving notification emails like this one, please contact
masaori@apache.org.