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
18f450fd
Commit
18f450fd
authored
Jul 26, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port shrpx to nghttp2 use
parent
459a2690
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
333 additions
and
397 deletions
+333
-397
src/Makefile.am
src/Makefile.am
+26
-30
src/shrpx.cc
src/shrpx.cc
+2
-29
src/shrpx_client_handler.cc
src/shrpx_client_handler.cc
+9
-12
src/shrpx_config.cc
src/shrpx_config.cc
+0
-33
src/shrpx_config.h
src/shrpx_config.h
+0
-4
src/shrpx_downstream.cc
src/shrpx_downstream.cc
+8
-6
src/shrpx_downstream.h
src/shrpx_downstream.h
+6
-4
src/shrpx_spdy_session.cc
src/shrpx_spdy_session.cc
+174
-174
src/shrpx_spdy_session.h
src/shrpx_spdy_session.h
+1
-1
src/shrpx_spdy_upstream.cc
src/shrpx_spdy_upstream.cc
+105
-102
src/shrpx_spdy_upstream.h
src/shrpx_spdy_upstream.h
+2
-2
No files found.
src/Makefile.am
View file @
18f450fd
...
...
@@ -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
...
...
src/shrpx.cc
View file @
18f450fd
...
...
@@ -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
,
...
...
src/shrpx_client_handler.cc
View file @
18f450fd
...
...
@@ -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
;
}
...
...
src/shrpx_config.cc
View file @
18f450fd
...
...
@@ -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
))
{
...
...
src/shrpx_config.h
View file @
18f450fd
...
...
@@ -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
;
...
...
src/shrpx_downstream.cc
View file @
18f450fd
...
...
@@ -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
src/shrpx_downstream.h
View file @
18f450fd
...
...
@@ -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_
;
};
...
...
src/shrpx_spdy_session.cc
View file @
18f450fd
This diff is collapsed.
Click to expand it.
src/shrpx_spdy_session.h
View file @
18f450fd
...
...
@@ -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
);
...
...
src/shrpx_spdy_upstream.cc
View file @
18f450fd
This diff is collapsed.
Click to expand it.
src/shrpx_spdy_upstream.h
View file @
18f450fd
...
...
@@ -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
);
...
...
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