Commit 32bd1425 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

shrpx: SPDY support in upstream connection

parent 41b21f79
......@@ -174,6 +174,17 @@ if test "x$with_libxml2" != "xno"; then
fi
AM_CONDITIONAL([HAVE_LIBXML2], [ test "x${have_libxml2}" = "xyes" ])
# spdylay (for shrpx)
PKG_CHECK_MODULES([LIBSPDYLAY], [libspdylay >= 1.0.0],
[have_spdylay=yes], [have_spdylay=no])
if test "x${have_spdylay}" = "xyes"; then
AC_DEFINE([HAVE_SPDYLAY], [1], [Define to 1 if you have `spdylay` library.])
else
AC_MSG_NOTICE($LIBSPDYLAY_PKG_ERRORS)
AC_MSG_NOTICE([The SPDY support in shrpx will be disabled.])
fi
AM_CONDITIONAL([HAVE_SPDYLAY], [ test "x${have_spdylay}" = "xyes" ])
# The src programs depend on OpenSSL
enable_src=no
if test "x${request_src}" = "xyes" &&
......
......@@ -29,8 +29,10 @@ if ENABLE_SRC
AM_CFLAGS = -Wall
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@ @LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@
@LIBSPDYLAY_CFLAGS@ @OPENSSL_CFLAGS@ @XML_CPPFLAGS@ \
@LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
AM_LDFLAGS = @LIBSPDYLAY_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ \
@LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@
AM_CXXFLAGS = -std=c++11
LDADD = $(top_builddir)/lib/libnghttp2.la
......@@ -92,6 +94,10 @@ SHRPX_SRCS = \
shrpx_accesslog.cc shrpx_accesslog.h\
http-parser/http_parser.c http-parser/http_parser.h
if HAVE_SPDYLAY
SHRPX_SRCS += shrpx_spdy_upstream.cc shrpx_spdy_upstream.h
endif # HAVE_SPDYLAY
shrpx_SOURCES = ${SHRPX_SRCS} shrpx.cc shrpx.h
# if HAVE_CUNIT
......
......@@ -35,6 +35,10 @@
#include "shrpx_spdy_downstream_connection.h"
#include "shrpx_accesslog.h"
#ifdef HAVE_SPDYLAY
#include "shrpx_spdy_upstream.h"
#endif // HAVE_SPDYLAY
namespace shrpx {
namespace {
......@@ -212,6 +216,14 @@ int ClientHandler::validate_next_proto()
if(proto == NGHTTP2_PROTO_VERSION_ID) {
upstream_ = new Http2Upstream(this);
return 0;
} else {
#ifdef HAVE_SPDYLAY
uint16_t version = spdylay_npn_get_version(next_proto, next_proto_len);
if(version) {
upstream_ = new SpdyUpstream(version, this);
return 0;
}
#endif // HAVE_SPDYLAY
}
} else {
if(LOG_ENABLED(INFO)) {
......
......@@ -22,8 +22,8 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SHRPX_SPDY_UPSTREAM_H
#define SHRPX_SPDY_UPSTREAM_H
#ifndef SHRPX_HTTP2_UPSTREAM_H
#define SHRPX_HTTP2_UPSTREAM_H
#include "shrpx.h"
......@@ -78,4 +78,4 @@ private:
} // namespace shrpx
#endif // SHRPX_SPDY_UPSTREAM_H
#endif // SHRPX_HTTP2_UPSTREAM_H
This diff is collapsed.
/*
* Spdylay - SPDY Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SHRPX_SPDY_UPSTREAM_H
#define SHRPX_SPDY_UPSTREAM_H
#include "shrpx.h"
#include <spdylay/spdylay.h>
#include "shrpx_upstream.h"
#include "shrpx_downstream_queue.h"
namespace shrpx {
class ClientHandler;
class SpdyUpstream : public Upstream {
public:
SpdyUpstream(uint16_t version, ClientHandler *handler);
virtual ~SpdyUpstream();
virtual int on_read();
virtual int on_write();
virtual int on_event();
int send();
virtual ClientHandler* get_client_handler() const;
virtual bufferevent_data_cb get_downstream_readcb();
virtual bufferevent_data_cb get_downstream_writecb();
virtual bufferevent_event_cb get_downstream_eventcb();
void add_downstream(Downstream *downstream);
void remove_downstream(Downstream *downstream);
Downstream* find_downstream(int32_t stream_id);
spdylay_session* get_spdy_session();
int rst_stream(Downstream *downstream, int status_code);
int window_update(Downstream *downstream);
int error_reply(Downstream *downstream, int status_code);
virtual void pause_read(IOCtrlReason reason);
virtual int resume_read(IOCtrlReason reason, Downstream *downstream);
virtual int on_downstream_header_complete(Downstream *downstream);
virtual int on_downstream_body(Downstream *downstream,
const uint8_t *data, size_t len);
virtual int on_downstream_body_complete(Downstream *downstream);
bool get_flow_control() const;
int32_t get_initial_window_size() const;
private:
ClientHandler *handler_;
spdylay_session *session_;
bool flow_control_;
int32_t initial_window_size_;
DownstreamQueue downstream_queue_;
};
} // namespace shrpx
#endif // SHRPX_SPDY_UPSTREAM_H
......@@ -55,7 +55,7 @@ namespace ssl {
namespace {
std::pair<unsigned char*, size_t> next_proto;
unsigned char proto_list[23];
unsigned char proto_list[256];
} // namespace
namespace {
......@@ -80,14 +80,18 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
} // namespace
namespace {
void set_npn_prefs(unsigned char *out, const char **protos, size_t len)
size_t set_npn_prefs(unsigned char *out, const char **protos, size_t len)
{
unsigned char *ptr = out;
size_t listlen = 0;
for(size_t i = 0; i < len; ++i) {
*ptr = strlen(protos[i]);
size_t plen = strlen(protos[i]);
*ptr = plen;
memcpy(ptr+1, protos[i], *ptr);
ptr += *ptr+1;
listlen += 1 + plen;
}
return listlen;
}
} // namespace
......@@ -182,12 +186,16 @@ SSL_CTX* create_ssl_context(const char *private_key_file,
}
SSL_CTX_set_tlsext_servername_callback(ssl_ctx, servername_callback);
// We speak "http/1.1", "spdy/2" and "spdy/3".
const char *protos[] = { "spdy/3", "spdy/2", "http/1.1" };
set_npn_prefs(proto_list, protos, 3);
const char *protos[] = { NGHTTP2_PROTO_VERSION_ID,
#ifdef HAVE_SPDYLAY
"spdy/3", "spdy/2",
#endif // HAVE_SPDYLAY
"http/1.1" };
auto proto_list_len = set_npn_prefs(proto_list, protos,
sizeof(protos)/sizeof(protos[0]));
next_proto.first = proto_list;
next_proto.second = sizeof(proto_list);
next_proto.second = proto_list_len;
SSL_CTX_set_next_protos_advertised_cb(ssl_ctx, next_proto_cb, &next_proto);
return ssl_ctx;
}
......@@ -199,8 +207,8 @@ int select_next_proto_cb(SSL* ssl,
void *arg)
{
if(nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) {
*out = (unsigned char*)"spdy/3";
*outlen = 6;
*out = (unsigned char*)NGHTTP2_PROTO_VERSION_ID;
*outlen = NGHTTP2_PROTO_VERSION_ID_LEN;
}
return SSL_TLSEXT_ERR_OK;
}
......
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