Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
32bd1425
Commit
32bd1425
authored
Jul 26, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrpx: SPDY support in upstream connection
parent
41b21f79
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1038 additions
and
14 deletions
+1038
-14
configure.ac
configure.ac
+11
-0
src/Makefile.am
src/Makefile.am
+8
-2
src/shrpx_client_handler.cc
src/shrpx_client_handler.cc
+12
-0
src/shrpx_http2_upstream.h
src/shrpx_http2_upstream.h
+3
-3
src/shrpx_spdy_upstream.cc
src/shrpx_spdy_upstream.cc
+906
-0
src/shrpx_spdy_upstream.h
src/shrpx_spdy_upstream.h
+81
-0
src/shrpx_ssl.cc
src/shrpx_ssl.cc
+17
-9
No files found.
configure.ac
View file @
32bd1425
...
...
@@ -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" &&
...
...
src/Makefile.am
View file @
32bd1425
...
...
@@ -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
...
...
src/shrpx_client_handler.cc
View file @
32bd1425
...
...
@@ -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
))
{
...
...
src/shrpx_http2_upstream.h
View file @
32bd1425
...
...
@@ -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
src/shrpx_spdy_upstream.cc
0 → 100644
View file @
32bd1425
This diff is collapsed.
Click to expand it.
src/shrpx_spdy_upstream.h
0 → 100644
View file @
32bd1425
/*
* 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
src/shrpx_ssl.cc
View file @
32bd1425
...
...
@@ -55,7 +55,7 @@ namespace ssl {
namespace
{
std
::
pair
<
unsigned
char
*
,
size_t
>
next_proto
;
unsigned
char
proto_list
[
2
3
];
unsigned
char
proto_list
[
2
56
];
}
// 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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment