Commit 18f450fd authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Port shrpx to nghttp2 use

parent 459a2690
......@@ -35,11 +35,7 @@ AM_CXXFLAGS = -std=c++11
LDADD = $(top_builddir)/lib/libnghttp2.la
bin_PROGRAMS += nghttp nghttpd
if HAVE_LIBEVENT_OPENSSL
# bin_PROGRAMS += shrpx
endif # HAVE_LIBEVENT_OPENSSL
bin_PROGRAMS += nghttp nghttpd shrpx
HELPER_OBJECTS = util.cc timegm.c app_helper.cc
HELPER_HFILES = util.h timegm.h app_helper.h nghttp2_config.h
......@@ -72,31 +68,31 @@ nghttpd_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} nghttpd.cc \
HttpServer.cc HttpServer.h
if HAVE_LIBEVENT_OPENSSL
# SHRPX_SRCS = \
# util.cc util.h timegm.c timegm.h base64.h \
# shrpx_config.cc shrpx_config.h \
# shrpx_error.h \
# shrpx_listen_handler.cc shrpx_listen_handler.h \
# shrpx_client_handler.cc shrpx_client_handler.h \
# shrpx_upstream.h \
# shrpx_spdy_upstream.cc shrpx_spdy_upstream.h \
# shrpx_https_upstream.cc shrpx_https_upstream.h \
# shrpx_downstream_queue.cc shrpx_downstream_queue.h \
# shrpx_downstream.cc shrpx_downstream.h \
# shrpx_downstream_connection.cc shrpx_downstream_connection.h \
# shrpx_http_downstream_connection.cc shrpx_http_downstream_connection.h \
# shrpx_spdy_downstream_connection.cc shrpx_spdy_downstream_connection.h \
# shrpx_spdy_session.cc shrpx_spdy_session.h \
# shrpx_log.cc shrpx_log.h \
# shrpx_http.cc shrpx_http.h \
# shrpx_io_control.cc shrpx_io_control.h \
# shrpx_ssl.cc shrpx_ssl.h \
# shrpx_thread_event_receiver.cc shrpx_thread_event_receiver.h \
# shrpx_worker.cc shrpx_worker.h \
# shrpx_accesslog.cc shrpx_accesslog.h\
# http-parser/http_parser.c http-parser/http_parser.h
# shrpx_SOURCES = ${SHRPX_SRCS} shrpx.cc shrpx.h
SHRPX_SRCS = \
util.cc util.h timegm.c timegm.h base64.h \
shrpx_config.cc shrpx_config.h \
shrpx_error.h \
shrpx_listen_handler.cc shrpx_listen_handler.h \
shrpx_client_handler.cc shrpx_client_handler.h \
shrpx_upstream.h \
shrpx_spdy_upstream.cc shrpx_spdy_upstream.h \
shrpx_https_upstream.cc shrpx_https_upstream.h \
shrpx_downstream_queue.cc shrpx_downstream_queue.h \
shrpx_downstream.cc shrpx_downstream.h \
shrpx_downstream_connection.cc shrpx_downstream_connection.h \
shrpx_http_downstream_connection.cc shrpx_http_downstream_connection.h \
shrpx_spdy_downstream_connection.cc shrpx_spdy_downstream_connection.h \
shrpx_spdy_session.cc shrpx_spdy_session.h \
shrpx_log.cc shrpx_log.h \
shrpx_http.cc shrpx_http.h \
shrpx_io_control.cc shrpx_io_control.h \
shrpx_ssl.cc shrpx_ssl.h \
shrpx_thread_event_receiver.cc shrpx_thread_event_receiver.h \
shrpx_worker.cc shrpx_worker.h \
shrpx_accesslog.cc shrpx_accesslog.h\
http-parser/http_parser.c http-parser/http_parser.h
shrpx_SOURCES = ${SHRPX_SRCS} shrpx.cc shrpx.h
# if HAVE_CUNIT
# check_PROGRAMS += shrpx-unittest
......
......@@ -358,9 +358,7 @@ void fill_default_config()
mod_config()->spdy_downstream_window_bits = 16;
mod_config()->spdy_upstream_no_tls = false;
mod_config()->spdy_upstream_version = 3;
mod_config()->spdy_downstream_no_tls = false;
mod_config()->spdy_downstream_version = 3;
set_config_str(&mod_config()->downstream_host, "127.0.0.1");
mod_config()->downstream_port = 80;
......@@ -543,14 +541,8 @@ void print_help(std::ostream& out)
<< get_config()->spdy_upstream_window_bits << "\n"
<< " --frontend-spdy-no-tls\n"
<< " Disable SSL/TLS on frontend SPDY\n"
<< " connections. SPDY protocol must be specified\n"
<< " using --frontend-spdy-proto. This option\n"
<< " also disables frontend HTTP/1.1.\n"
<< " --frontend-spdy-proto\n"
<< " Specify SPDY protocol used in frontend\n"
<< " connection if --frontend-spdy-no-tls is\n"
<< " used. Default: spdy/"
<< get_config()->spdy_upstream_version << "\n"
<< " connections.This option also disables\n"
<< " frontend HTTP/1.1.\n"
<< " --backend-spdy-window-bits=<N>\n"
<< " Sets the initial window size of SPDY\n"
<< " backend connection to 2**<N>.\n"
......@@ -558,13 +550,6 @@ void print_help(std::ostream& out)
<< get_config()->spdy_downstream_window_bits << "\n"
<< " --backend-spdy-no-tls\n"
<< " Disable SSL/TLS on backend SPDY connections.\n"
<< " SPDY protocol must be specified using\n"
<< " --backend-spdy-proto\n"
<< " --backend-spdy-proto\n"
<< " Specify SPDY protocol used in backend\n"
<< " connection if --backend-spdy-no-tls is used.\n"
<< " Default: spdy/"
<< get_config()->spdy_downstream_version << "\n"
<< "\n"
<< " Mode:\n"
<< " -s, --spdy-proxy Enable secure SPDY proxy mode.\n"
......@@ -664,9 +649,7 @@ int main(int argc, char **argv)
{"spdy-bridge", no_argument, &flag, 25},
{"backend-http-proxy-uri", required_argument, &flag, 26},
{"backend-spdy-no-tls", no_argument, &flag, 27},
{"backend-spdy-proto", required_argument, &flag, 28},
{"frontend-spdy-no-tls", no_argument, &flag, 29},
{"frontend-spdy-proto", required_argument, &flag, 30},
{"backend-tls-sni-field", required_argument, &flag, 31},
{"honor-cipher-order", no_argument, &flag, 32},
{0, 0, 0, 0 }
......@@ -833,21 +816,11 @@ int main(int argc, char **argv)
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_SPDY_NO_TLS,
"yes"));
break;
case 28:
// --backend-spdy-proto
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_SPDY_PROTO,
optarg));
break;
case 29:
// --frontend-spdy-no-tls
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_SPDY_NO_TLS,
"yes"));
break;
case 30:
// --frontend-spdy-proto
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_SPDY_PROTO,
optarg));
break;
case 31:
// --backend-tls-sni-field
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_TLS_SNI_FIELD,
......
......@@ -123,24 +123,24 @@ ClientHandler::ClientHandler(bufferevent *bev, int fd, SSL *ssl,
: bev_(bev),
fd_(fd),
ssl_(ssl),
upstream_(0),
upstream_(nullptr),
ipaddr_(ipaddr),
should_close_after_write_(false),
spdy_(0)
spdy_(nullptr)
{
bufferevent_enable(bev_, EV_READ | EV_WRITE);
bufferevent_setwatermark(bev_, EV_READ, 0, SHRPX_READ_WARTER_MARK);
set_upstream_timeouts(&get_config()->upstream_read_timeout,
&get_config()->upstream_write_timeout);
if(ssl_) {
set_bev_cb(0, upstream_writecb, upstream_eventcb);
set_bev_cb(nullptr, upstream_writecb, upstream_eventcb);
} else {
if(get_config()->client_mode) {
// Client mode
upstream_ = new HttpsUpstream(this);
} else {
// no-TLS SPDY
upstream_ = new SpdyUpstream(get_config()->spdy_upstream_version, this);
upstream_ = new SpdyUpstream(this);
}
set_bev_cb(upstream_readcb, upstream_writecb, upstream_eventcb);
}
......@@ -201,18 +201,16 @@ void ClientHandler::set_upstream_timeouts(const timeval *read_timeout,
int ClientHandler::validate_next_proto()
{
const unsigned char *next_proto = 0;
const unsigned char *next_proto = nullptr;
unsigned int next_proto_len;
SSL_get0_next_proto_negotiated(ssl_, &next_proto, &next_proto_len);
if(next_proto) {
std::string proto(next_proto, next_proto+next_proto_len);
if(LOG_ENABLED(INFO)) {
std::string proto(next_proto, next_proto+next_proto_len);
CLOG(INFO, this) << "The negotiated next protocol: " << proto;
}
uint16_t version = nghttp2_npn_get_version(next_proto, next_proto_len);
if(version) {
SpdyUpstream *spdy_upstream = new SpdyUpstream(version, this);
upstream_ = spdy_upstream;
if(proto == NGHTTP2_PROTO_VERSION_ID) {
upstream_ = new SpdyUpstream(this);
return 0;
}
} else {
......@@ -223,8 +221,7 @@ int ClientHandler::validate_next_proto()
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Use HTTP/1.1";
}
HttpsUpstream *https_upstream = new HttpsUpstream(this);
upstream_ = https_upstream;
upstream_ = new HttpsUpstream(this);
return 0;
}
......
......@@ -76,9 +76,7 @@ SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT[] = "backend-keep-alive-timeout";
const char SHRPX_OPT_FRONTEND_SPDY_WINDOW_BITS[] = "frontend-spdy-window-bits";
const char SHRPX_OPT_BACKEND_SPDY_WINDOW_BITS[] = "backend-spdy-window-bits";
const char SHRPX_OPT_FRONTEND_SPDY_NO_TLS[] = "frontend-spdy-no-tls";
const char SHRPX_OPT_FRONTEND_SPDY_PROTO[] = "frontend-spdy-proto";
const char SHRPX_OPT_BACKEND_SPDY_NO_TLS[] = "backend-spdy-no-tls";
const char SHRPX_OPT_BACKEND_SPDY_PROTO[] = "backend-spdy-proto";
const char SHRPX_OPT_BACKEND_TLS_SNI_FIELD[] = "backend-tls-sni-field";
const char SHRPX_OPT_PID_FILE[] = "pid-file";
const char SHRPX_OPT_USER[] = "user";
......@@ -188,23 +186,6 @@ void set_config_str(char **destp, const char *val)
*destp = strdup(val);
}
namespace {
// Parses |optarg| as SPDY NPN protocol string and returns SPDY
// protocol version number. This function returns -1 on error.
int parse_spdy_proto(const char *optarg)
{
size_t len = strlen(optarg);
const unsigned char *proto;
proto = reinterpret_cast<const unsigned char*>(optarg);
uint16_t version = nghttp2_npn_get_version(proto, len);
if(!version) {
LOG(ERROR) << "Unsupported SPDY version: " << optarg;
return -1;
}
return version;
}
} // namespace
int parse_config(const char *opt, const char *optarg)
{
char host[NI_MAXHOST];
......@@ -286,22 +267,8 @@ int parse_config(const char *opt, const char *optarg)
}
} else if(util::strieq(opt, SHRPX_OPT_FRONTEND_SPDY_NO_TLS)) {
mod_config()->spdy_upstream_no_tls = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_FRONTEND_SPDY_PROTO)) {
int version = parse_spdy_proto(optarg);
if(version == -1) {
return -1;
} else {
mod_config()->spdy_upstream_version = version;
}
} else if(util::strieq(opt, SHRPX_OPT_BACKEND_SPDY_NO_TLS)) {
mod_config()->spdy_downstream_no_tls = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_BACKEND_SPDY_PROTO)) {
int version = parse_spdy_proto(optarg);
if(version == -1) {
return -1;
} else {
mod_config()->spdy_downstream_version = version;
}
} else if(util::strieq(opt, SHRPX_OPT_BACKEND_TLS_SNI_FIELD)) {
set_config_str(&mod_config()->backend_tls_sni_name, optarg);
} else if(util::strieq(opt, SHRPX_OPT_PID_FILE)) {
......
......@@ -69,9 +69,7 @@ extern const char SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT[];
extern const char SHRPX_OPT_FRONTEND_SPDY_WINDOW_BITS[];
extern const char SHRPX_OPT_BACKEND_SPDY_WINDOW_BITS[];
extern const char SHRPX_OPT_FRONTEND_SPDY_NO_TLS[];
extern const char SHRPX_OPT_FRONTEND_SPDY_PROTO[];
extern const char SHRPX_OPT_BACKEND_SPDY_NO_TLS[];
extern const char SHRPX_OPT_BACKEND_SPDY_PROTO[];
extern const char SHRPX_OPT_PID_FILE[];
extern const char SHRPX_OPT_USER[];
extern const char SHRPX_OPT_SYSLOG[];
......@@ -133,9 +131,7 @@ struct Config {
size_t spdy_upstream_window_bits;
size_t spdy_downstream_window_bits;
bool spdy_upstream_no_tls;
uint16_t spdy_upstream_version;
bool spdy_downstream_no_tls;
uint16_t spdy_downstream_version;
char *backend_tls_sni_name;
char *pid_file;
uid_t uid;
......
......@@ -39,7 +39,7 @@ namespace shrpx {
Downstream::Downstream(Upstream *upstream, int stream_id, int priority)
: upstream_(upstream),
dconn_(0),
dconn_(nullptr),
stream_id_(stream_id),
priority_(priority),
downstream_stream_id_(-1),
......@@ -57,7 +57,8 @@ Downstream::Downstream(Upstream *upstream, int stream_id, int priority)
chunked_response_(false),
response_connection_close_(false),
response_header_key_prev_(false),
response_body_buf_(0),
response_body_buf_(nullptr),
response_rst_stream_error_code_(NGHTTP2_NO_ERROR),
recv_window_size_(0)
{}
......@@ -489,14 +490,15 @@ int32_t Downstream::get_downstream_stream_id() const
return downstream_stream_id_;
}
uint32_t Downstream::get_response_rst_stream_status_code() const
nghttp2_error_code Downstream::get_response_rst_stream_error_code() const
{
return response_rst_stream_status_code_;
return response_rst_stream_error_code_;
}
void Downstream::set_response_rst_stream_status_code(uint32_t status_code)
void Downstream::set_response_rst_stream_error_code
(nghttp2_error_code error_code)
{
response_rst_stream_status_code_ = status_code;
response_rst_stream_error_code_ = error_code;
}
} // namespace shrpx
......@@ -35,6 +35,8 @@
#include <event.h>
#include <event2/bufferevent.h>
#include <nghttp2/nghttp2.h>
#include "shrpx_io_control.h"
namespace shrpx {
......@@ -128,8 +130,8 @@ public:
int get_response_state() const;
int init_response_body_buf();
evbuffer* get_response_body_buf();
uint32_t get_response_rst_stream_status_code() const;
void set_response_rst_stream_status_code(uint32_t status_code);
nghttp2_error_code get_response_rst_stream_error_code() const;
void set_response_rst_stream_error_code(nghttp2_error_code error_code);
// Call this method when there is incoming data in downstream
// connection.
......@@ -166,8 +168,8 @@ private:
// This buffer is used to temporarily store downstream response
// body. Spdylay reads data from this in the callback.
evbuffer *response_body_buf_;
// RST_STREAM status_code from downstream SPDY connection
uint32_t response_rst_stream_status_code_;
// RST_STREAM error_code from downstream SPDY connection
nghttp2_error_code response_rst_stream_error_code_;
int32_t recv_window_size_;
};
......
This diff is collapsed.
......@@ -68,7 +68,7 @@ public:
const nghttp2_data_provider *data_prd);
int submit_rst_stream(SpdyDownstreamConnection *dconn,
int32_t stream_id, uint32_t status_code);
int32_t stream_id, nghttp2_error_code error_code);
int submit_window_update(SpdyDownstreamConnection *dconn, int32_t amount);
......
This diff is collapsed.
......@@ -38,7 +38,7 @@ class ClientHandler;
class SpdyUpstream : public Upstream {
public:
SpdyUpstream(uint16_t version, ClientHandler *handler);
SpdyUpstream(ClientHandler *handler);
virtual ~SpdyUpstream();
virtual int on_read();
virtual int on_write();
......@@ -54,7 +54,7 @@ public:
nghttp2_session* get_spdy_session();
int rst_stream(Downstream *downstream, int status_code);
int rst_stream(Downstream *downstream, nghttp2_error_code error_code);
int window_update(Downstream *downstream);
int error_reply(Downstream *downstream, int status_code);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment