forked from nghttp2/nghttp2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshrpx_http2_session.h
153 lines (116 loc) · 3.94 KB
/
shrpx_http2_session.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* nghttp2 - HTTP/2 C 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_HTTP2_SESSION_H
#define SHRPX_HTTP2_SESSION_H
#include "shrpx.h"
#include <set>
#include <memory>
#include <openssl/ssl.h>
#include <event.h>
#include <event2/bufferevent.h>
#include <nghttp2/nghttp2.h>
#include "http-parser/http_parser.h"
namespace shrpx {
class Http2DownstreamConnection;
struct StreamData {
Http2DownstreamConnection *dconn;
};
class Http2Session {
public:
Http2Session(event_base *evbase, SSL_CTX *ssl_ctx);
~Http2Session();
int init_notification();
int check_cert();
int disconnect();
int initiate_connection();
void add_downstream_connection(Http2DownstreamConnection *dconn);
void remove_downstream_connection(Http2DownstreamConnection *dconn);
void remove_stream_data(StreamData *sd);
int submit_request(Http2DownstreamConnection *dconn,
int32_t pri, const nghttp2_nv *nva, size_t nvlen,
const nghttp2_data_provider *data_prd);
int submit_rst_stream(int32_t stream_id, uint32_t error_code);
int submit_priority(Http2DownstreamConnection *dconn, int32_t pri);
int terminate_session(uint32_t error_code);
nghttp2_session* get_session() const;
bool get_flow_control() const;
int resume_data(Http2DownstreamConnection *dconn);
int on_connect();
int on_read();
int on_write();
int send();
int on_read_proxy();
void clear_notify();
void notify();
bufferevent* get_bev() const;
void unwrap_free_bev();
int get_state() const;
void set_state(int state);
int start_settings_timer();
void stop_settings_timer();
size_t get_outbuf_length() const;
SSL* get_ssl() const;
int consume(int32_t stream_id, size_t len);
void reset_timeouts();
enum {
// Disconnected
DISCONNECTED,
// Connecting proxy and making CONNECT request
PROXY_CONNECTING,
// Tunnel is established with proxy
PROXY_CONNECTED,
// Establishing tunnel is failed
PROXY_FAILED,
// Connecting to downstream and/or performing SSL/TLS handshake
CONNECTING,
// Connected to downstream
CONNECTED
};
static const size_t OUTBUF_MAX_THRES = 64*1024;
private:
std::set<Http2DownstreamConnection*> dconns_;
std::set<StreamData*> streams_;
// Used to parse the response from HTTP proxy
std::unique_ptr<http_parser> proxy_htp_;
event_base *evbase_;
// NULL if no TLS is configured
SSL_CTX *ssl_ctx_;
SSL *ssl_;
nghttp2_session *session_;
bufferevent *bev_;
bufferevent *wrbev_;
bufferevent *rdbev_;
event *settings_timerev_;
// fd_ is used for proxy connection and no TLS connection. For
// direct or TLS connection, it may be -1 even after connection is
// established. Use bufferevent_getfd(bev_) to get file descriptor
// in these cases.
int fd_;
int state_;
bool notified_;
bool flow_control_;
};
} // namespace shrpx
#endif // SHRPX_HTTP2_SESSION_H