blob: 9e8172a1f1569e0f4fd6fdb5e163203e713119d5 [file] [log] [blame]
Craig Tiller640d3bd2015-06-12 07:51:51 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller9b8671c2015-06-12 07:41:54 -070034#ifndef GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H
35#define GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H
36
37#include "src/core/transport/transport_impl.h"
Craig Tiller3208e392015-06-12 08:17:02 -070038#include "src/core/iomgr/endpoint.h"
Craig Tillerd20efd22015-06-12 16:17:09 -070039#include "src/core/transport/chttp2/frame.h"
Craig Tiller3208e392015-06-12 08:17:02 -070040#include "src/core/transport/chttp2/frame_data.h"
41#include "src/core/transport/chttp2/frame_goaway.h"
42#include "src/core/transport/chttp2/frame_ping.h"
43#include "src/core/transport/chttp2/frame_rst_stream.h"
44#include "src/core/transport/chttp2/frame_settings.h"
45#include "src/core/transport/chttp2/frame_window_update.h"
Craig Tiller3208e392015-06-12 08:17:02 -070046#include "src/core/transport/chttp2/hpack_parser.h"
Craig Tiller5dc3b302015-06-15 16:06:50 -070047#include "src/core/transport/chttp2/incoming_metadata.h"
Craig Tiller3208e392015-06-12 08:17:02 -070048#include "src/core/transport/chttp2/stream_encoder.h"
Craig Tiller5dc3b302015-06-15 16:06:50 -070049#include "src/core/transport/chttp2/stream_map.h"
Craig Tiller9b8671c2015-06-12 07:41:54 -070050
Craig Tillerb084d902015-06-12 07:50:02 -070051typedef struct grpc_chttp2_transport grpc_chttp2_transport;
52typedef struct grpc_chttp2_stream grpc_chttp2_stream;
Craig Tiller9b8671c2015-06-12 07:41:54 -070053
54/* streams are kept in various linked lists depending on what things need to
55 happen to them... this enum labels each list */
56typedef enum {
Craig Tiller5dc3b302015-06-15 16:06:50 -070057 GRPC_CHTTP2_LIST_ALL_STREAMS,
58 GRPC_CHTTP2_LIST_WRITABLE,
59 /** streams that are waiting to start because there are too many concurrent
60 streams on the connection */
61 GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY,
62#if 0
Craig Tiller9b8671c2015-06-12 07:41:54 -070063 /* streams that have pending writes */
64 WRITABLE = 0,
65 /* streams that have been selected to be written */
66 WRITING,
67 /* streams that have just been written, and included a close */
68 WRITTEN_CLOSED,
69 /* streams that have been cancelled and have some pending state updates
70 to perform */
71 CANCELLED,
72 /* streams that want to send window updates */
73 WINDOW_UPDATE,
74 /* streams that are waiting to start because there are too many concurrent
75 streams on the connection */
76 WAITING_FOR_CONCURRENCY,
77 /* streams that have finished reading: we wait until unlock to coalesce
78 all changes into one callback */
79 FINISHED_READ_OP,
80 MAYBE_FINISH_READ_AFTER_PARSE,
81 PARSER_CHECK_WINDOW_UPDATES_AFTER_PARSE,
82 OTHER_CHECK_WINDOW_UPDATES_AFTER_PARSE,
83 NEW_OUTGOING_WINDOW,
Craig Tiller5dc3b302015-06-15 16:06:50 -070084#endif
Craig Tiller9b8671c2015-06-12 07:41:54 -070085 STREAM_LIST_COUNT /* must be last */
Craig Tillerb084d902015-06-12 07:50:02 -070086} grpc_chttp2_stream_list_id;
Craig Tiller9b8671c2015-06-12 07:41:54 -070087
88/* deframer state for the overall http2 stream of bytes */
89typedef enum {
90 /* prefix: one entry per http2 connection prefix byte */
91 DTS_CLIENT_PREFIX_0 = 0,
92 DTS_CLIENT_PREFIX_1,
93 DTS_CLIENT_PREFIX_2,
94 DTS_CLIENT_PREFIX_3,
95 DTS_CLIENT_PREFIX_4,
96 DTS_CLIENT_PREFIX_5,
97 DTS_CLIENT_PREFIX_6,
98 DTS_CLIENT_PREFIX_7,
99 DTS_CLIENT_PREFIX_8,
100 DTS_CLIENT_PREFIX_9,
101 DTS_CLIENT_PREFIX_10,
102 DTS_CLIENT_PREFIX_11,
103 DTS_CLIENT_PREFIX_12,
104 DTS_CLIENT_PREFIX_13,
105 DTS_CLIENT_PREFIX_14,
106 DTS_CLIENT_PREFIX_15,
107 DTS_CLIENT_PREFIX_16,
108 DTS_CLIENT_PREFIX_17,
109 DTS_CLIENT_PREFIX_18,
110 DTS_CLIENT_PREFIX_19,
111 DTS_CLIENT_PREFIX_20,
112 DTS_CLIENT_PREFIX_21,
113 DTS_CLIENT_PREFIX_22,
114 DTS_CLIENT_PREFIX_23,
115 /* frame header byte 0... */
116 /* must follow from the prefix states */
117 DTS_FH_0,
118 DTS_FH_1,
119 DTS_FH_2,
120 DTS_FH_3,
121 DTS_FH_4,
122 DTS_FH_5,
123 DTS_FH_6,
124 DTS_FH_7,
125 /* ... frame header byte 8 */
126 DTS_FH_8,
127 /* inside a http2 frame */
128 DTS_FRAME
Craig Tillerb084d902015-06-12 07:50:02 -0700129} grpc_chttp2_deframe_transport_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700130
131typedef enum {
132 WRITE_STATE_OPEN,
133 WRITE_STATE_QUEUED_CLOSE,
134 WRITE_STATE_SENT_CLOSE
Craig Tillerb084d902015-06-12 07:50:02 -0700135} grpc_chttp2_write_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700136
137typedef enum {
138 DONT_SEND_CLOSED = 0,
139 SEND_CLOSED,
140 SEND_CLOSED_WITH_RST_STREAM
Craig Tillerb084d902015-06-12 07:50:02 -0700141} grpc_chttp2_send_closed;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700142
143typedef struct {
Craig Tillerb084d902015-06-12 07:50:02 -0700144 grpc_chttp2_stream *head;
145 grpc_chttp2_stream *tail;
146} grpc_chttp2_stream_list;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700147
148typedef struct {
Craig Tillerb084d902015-06-12 07:50:02 -0700149 grpc_chttp2_stream *next;
150 grpc_chttp2_stream *prev;
151} grpc_chttp2_stream_link;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700152
153typedef enum {
Craig Tiller606d8742015-06-15 06:58:50 -0700154 GRPC_CHTTP2_ERROR_STATE_NONE,
155 GRPC_CHTTP2_ERROR_STATE_SEEN,
156 GRPC_CHTTP2_ERROR_STATE_NOTIFIED
Craig Tillerb084d902015-06-12 07:50:02 -0700157} grpc_chttp2_error_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700158
159/* We keep several sets of connection wide parameters */
160typedef enum {
161 /* The settings our peer has asked for (and we have acked) */
162 PEER_SETTINGS = 0,
163 /* The settings we'd like to have */
164 LOCAL_SETTINGS,
165 /* The settings we've published to our peer */
166 SENT_SETTINGS,
167 /* The settings the peer has acked */
168 ACKED_SETTINGS,
169 NUM_SETTING_SETS
Craig Tillerb084d902015-06-12 07:50:02 -0700170} grpc_chttp2_setting_set;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700171
172/* Outstanding ping request data */
Craig Tiller3719f072015-06-12 17:19:51 -0700173typedef struct grpc_chttp2_outstanding_ping {
Craig Tiller9b8671c2015-06-12 07:41:54 -0700174 gpr_uint8 id[8];
Craig Tiller3719f072015-06-12 17:19:51 -0700175 grpc_iomgr_closure *on_recv;
176 struct grpc_chttp2_outstanding_ping *next;
177 struct grpc_chttp2_outstanding_ping *prev;
Craig Tillerb084d902015-06-12 07:50:02 -0700178} grpc_chttp2_outstanding_ping;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700179
180typedef struct {
Craig Tillerd20efd22015-06-12 16:17:09 -0700181 /** data to write next write */
182 gpr_slice_buffer qbuf;
183 /** queued callbacks */
184 grpc_iomgr_closure *pending_closures;
185
186 /** window available for us to send to peer */
187 gpr_uint32 outgoing_window;
Craig Tiller3719f072015-06-12 17:19:51 -0700188 /** window available for peer to send to us - updated after parse */
189 gpr_uint32 incoming_window;
Craig Tillerd20efd22015-06-12 16:17:09 -0700190 /** how much window would we like to have for incoming_window */
191 gpr_uint32 connection_window_target;
192
Craig Tiller3719f072015-06-12 17:19:51 -0700193 /** is this transport a client? */
194 gpr_uint8 is_client;
Craig Tillerd20efd22015-06-12 16:17:09 -0700195 /** are the local settings dirty and need to be sent? */
196 gpr_uint8 dirtied_local_settings;
197 /** have local settings been sent? */
198 gpr_uint8 sent_local_settings;
199 /** bitmask of setting indexes to send out */
Craig Tiller4aa71a12015-06-15 13:00:55 -0700200 gpr_uint32 force_send_settings;
Craig Tillerd20efd22015-06-12 16:17:09 -0700201 /** settings values */
202 gpr_uint32 settings[NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS];
203
Craig Tiller606d8742015-06-15 06:58:50 -0700204 /** has there been a connection level error, and have we notified
205 anyone about it? */
206 grpc_chttp2_error_state error_state;
207
208 /** what is the next stream id to be allocated by this peer?
209 copied to next_stream_id in parsing when parsing commences */
210 gpr_uint32 next_stream_id;
211
Craig Tillerd20efd22015-06-12 16:17:09 -0700212 /** last received stream id */
213 gpr_uint32 last_incoming_stream_id;
Craig Tiller3719f072015-06-12 17:19:51 -0700214
215 /** pings awaiting responses */
216 grpc_chttp2_outstanding_ping pings;
Craig Tiller606d8742015-06-15 06:58:50 -0700217 /** next payload for an outgoing ping */
218 gpr_uint64 ping_counter;
219
220 /** concurrent stream count: updated when not parsing,
221 so this is a strict over-estimation on the client */
222 gpr_uint32 concurrent_stream_count;
223
Craig Tiller4aa71a12015-06-15 13:00:55 -0700224 /** is there a goaway available? (boolean) */
225 grpc_chttp2_error_state goaway_state;
Craig Tiller606d8742015-06-15 06:58:50 -0700226 /** what is the debug text of the goaway? */
227 gpr_slice goaway_text;
228 /** what is the status code of the goaway? */
229 grpc_status_code goaway_error;
Craig Tillerd20efd22015-06-12 16:17:09 -0700230} grpc_chttp2_transport_global;
231
232typedef struct {
233 /** data to write now */
234 gpr_slice_buffer outbuf;
235 /** hpack encoding */
236 grpc_chttp2_hpack_compressor hpack_compressor;
237} grpc_chttp2_transport_writing;
238
239struct grpc_chttp2_transport_parsing {
240 /** is this transport a client? (boolean) */
241 gpr_uint8 is_client;
242
243 /** were settings updated? */
244 gpr_uint8 settings_updated;
245 /** was a settings ack received? */
246 gpr_uint8 settings_ack_received;
247 /** was a goaway frame received? */
248 gpr_uint8 goaway_received;
249
Craig Tiller3719f072015-06-12 17:19:51 -0700250 /** initial window change */
251 gpr_int64 initial_window_update;
252
Craig Tillerd20efd22015-06-12 16:17:09 -0700253 /** data to write later - after parsing */
254 gpr_slice_buffer qbuf;
255 /* metadata object cache */
256 grpc_mdstr *str_grpc_timeout;
257 /** parser for headers */
258 grpc_chttp2_hpack_parser hpack_parser;
259 /** simple one shot parsers */
260 union {
261 grpc_chttp2_window_update_parser window_update;
262 grpc_chttp2_settings_parser settings;
263 grpc_chttp2_ping_parser ping;
264 grpc_chttp2_rst_stream_parser rst_stream;
265 } simple;
266 /** parser for goaway frames */
267 grpc_chttp2_goaway_parser goaway_parser;
268
269 /** window available for peer to send to us */
270 gpr_uint32 incoming_window;
271
272 /** next stream id available at the time of beginning parsing */
273 gpr_uint32 next_stream_id;
274 gpr_uint32 last_incoming_stream_id;
275
276 /* deframing */
277 grpc_chttp2_deframe_transport_state deframe_state;
278 gpr_uint8 incoming_frame_type;
279 gpr_uint8 incoming_frame_flags;
280 gpr_uint8 header_eof;
281 gpr_uint32 expect_continuation_stream_id;
282 gpr_uint32 incoming_frame_size;
283 gpr_uint32 incoming_stream_id;
284
285 /* active parser */
286 void *parser_data;
287 grpc_chttp2_stream_parsing *incoming_stream;
Craig Tiller4aa71a12015-06-15 13:00:55 -0700288 grpc_chttp2_parse_error (*parser)(
289 void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing,
290 grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last);
Craig Tillerd20efd22015-06-12 16:17:09 -0700291
292 /* received settings */
293 gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS];
294
295 /* goaway data */
296 grpc_status_code goaway_error;
297 gpr_uint32 goaway_last_stream_index;
298 gpr_slice goaway_text;
Craig Tiller3719f072015-06-12 17:19:51 -0700299
300 gpr_uint64 outgoing_window_update;
301
302 /** pings awaiting responses */
303 grpc_chttp2_outstanding_ping pings;
Craig Tillerd20efd22015-06-12 16:17:09 -0700304};
305
Craig Tillerb084d902015-06-12 07:50:02 -0700306struct grpc_chttp2_transport {
Craig Tiller9b8671c2015-06-12 07:41:54 -0700307 grpc_transport base; /* must be first */
308 grpc_endpoint *ep;
309 grpc_mdctx *metadata_context;
310 gpr_refcount refs;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700311
312 gpr_mu mu;
Craig Tiller606d8742015-06-15 06:58:50 -0700313
314 /** is the transport destroying itself? */
315 gpr_uint8 destroying;
316 /** has the upper layer closed the transport? */
317 gpr_uint8 closed;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700318
Craig Tillerd20efd22015-06-12 16:17:09 -0700319 /** is a thread currently writing */
320 gpr_uint8 writing_active;
Craig Tiller606d8742015-06-15 06:58:50 -0700321 /** is a thread currently parsing */
322 gpr_uint8 parsing_active;
Craig Tillerd20efd22015-06-12 16:17:09 -0700323
Craig Tiller606d8742015-06-15 06:58:50 -0700324 /** is there a read request to the endpoint outstanding? */
325 gpr_uint8 endpoint_reading;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700326
Craig Tiller606d8742015-06-15 06:58:50 -0700327 /** various lists of streams */
Craig Tillerb084d902015-06-12 07:50:02 -0700328 grpc_chttp2_stream_list lists[STREAM_LIST_COUNT];
Craig Tiller9b8671c2015-06-12 07:41:54 -0700329
Craig Tiller606d8742015-06-15 06:58:50 -0700330 /** global state for reading/writing */
Craig Tillerd20efd22015-06-12 16:17:09 -0700331 grpc_chttp2_transport_global global;
Craig Tiller606d8742015-06-15 06:58:50 -0700332 /** state only accessible by the chain of execution that
333 set writing_active=1 */
Craig Tillerd20efd22015-06-12 16:17:09 -0700334 grpc_chttp2_transport_writing writing;
Craig Tiller606d8742015-06-15 06:58:50 -0700335 /** state only accessible by the chain of execution that
336 set parsing_active=1 */
Craig Tillerd20efd22015-06-12 16:17:09 -0700337 grpc_chttp2_transport_parsing parsing;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700338
Craig Tiller606d8742015-06-15 06:58:50 -0700339 /** maps stream id to grpc_chttp2_stream objects;
340 owned by the parsing thread when parsing */
341 grpc_chttp2_stream_map parsing_stream_map;
342
343 /** streams created by the client (possibly during parsing);
344 merged with parsing_stream_map during unlock when no
345 parsing is occurring */
346 grpc_chttp2_stream_map new_stream_map;
347
Craig Tillerd20efd22015-06-12 16:17:09 -0700348 /** closure to execute writing */
349 grpc_iomgr_closure writing_action;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700350
Craig Tiller4aa71a12015-06-15 13:00:55 -0700351 /** address to place a newly accepted stream - set and unset by
Craig Tiller606d8742015-06-15 06:58:50 -0700352 grpc_chttp2_parsing_accept_stream; used by init_stream to
353 publish the accepted server stream */
354 grpc_chttp2_stream **accepting_stream;
355
Craig Tiller9b8671c2015-06-12 07:41:54 -0700356 struct {
357 /** is a thread currently performing channel callbacks */
358 gpr_uint8 executing;
359 /** transport channel-level callback */
360 const grpc_transport_callbacks *cb;
361 /** user data for cb calls */
362 void *cb_user_data;
363 /** closure for notifying transport closure */
364 grpc_iomgr_closure notify_closed;
365 } channel_callback;
Craig Tiller606d8742015-06-15 06:58:50 -0700366
367#if 0
368 /* basic state management - what are we doing at the moment? */
369 gpr_uint8 reading;
370 /** are we calling back any grpc_transport_op completion events */
371 gpr_uint8 calling_back_ops;
372 gpr_uint8 destroying;
373 gpr_uint8 closed;
374
375 /* stream indexing */
376 gpr_uint32 next_stream_id;
377
378 /* window management */
379 gpr_uint32 outgoing_window_update;
380
381 /* state for a stream that's not yet been created */
382 grpc_stream_op_buffer new_stream_sopb;
383
384 /* stream ops that need to be destroyed, but outside of the lock */
385 grpc_stream_op_buffer nuke_later_sopb;
386
387 /* pings */
388 gpr_int64 ping_counter;
389
390
391 grpc_chttp2_stream **accepting_stream;
392
393#endif
Craig Tiller9b8671c2015-06-12 07:41:54 -0700394};
395
Craig Tillerd20efd22015-06-12 16:17:09 -0700396typedef struct {
397 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
Craig Tiller9b8671c2015-06-12 07:41:54 -0700398 gpr_uint32 id;
399
Craig Tillerd20efd22015-06-12 16:17:09 -0700400 grpc_iomgr_closure *send_done_closure;
401 grpc_iomgr_closure *recv_done_closure;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700402
Craig Tillerd20efd22015-06-12 16:17:09 -0700403 /** window available for us to send to peer */
404 gpr_int64 outgoing_window;
Craig Tiller3719f072015-06-12 17:19:51 -0700405 /** window available for peer to send to us - updated after parse */
406 gpr_uint32 incoming_window;
Craig Tillerd20efd22015-06-12 16:17:09 -0700407 /** stream ops the transport user would like to send */
408 grpc_stream_op_buffer *outgoing_sopb;
409 /** when the application requests writes be closed, the write_closed is
410 'queued'; when the close is flow controlled into the send path, we are
411 'sending' it; when the write has been performed it is 'sent' */
412 grpc_chttp2_write_state write_state;
413 /** is this stream closed (boolean) */
414 gpr_uint8 read_closed;
Craig Tiller5dc3b302015-06-15 16:06:50 -0700415 /** has this stream been cancelled? (boolean) */
416 gpr_uint8 cancelled;
417 /** is this stream in the stream map? (boolean) */
418 gpr_uint8 in_stream_map;
Craig Tiller606d8742015-06-15 06:58:50 -0700419
420 /** stream state already published to the upper layer */
421 grpc_stream_state published_state;
422 /** address to publish next stream state to */
423 grpc_stream_state *publish_state;
424 /** pointer to sop buffer to fill in with new stream ops */
425 grpc_stream_op_buffer *incoming_sopb;
Craig Tiller5dc3b302015-06-15 16:06:50 -0700426
427 /** incoming metadata */
428 grpc_chttp2_incoming_metadata_buffer incoming_metadata;
Craig Tillerd20efd22015-06-12 16:17:09 -0700429} grpc_chttp2_stream_global;
430
431typedef struct {
432 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
433 gpr_uint32 id;
434 /** sops that have passed flow control to be written */
435 grpc_stream_op_buffer sopb;
436 /** how strongly should we indicate closure with the next write */
437 grpc_chttp2_send_closed send_closed;
438} grpc_chttp2_stream_writing;
439
440struct grpc_chttp2_stream_parsing {
441 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
442 gpr_uint32 id;
443 /** has this stream received a close */
444 gpr_uint8 received_close;
Craig Tiller3719f072015-06-12 17:19:51 -0700445 /** saw a rst_stream */
446 gpr_uint8 saw_rst_stream;
Craig Tiller606d8742015-06-15 06:58:50 -0700447 /** incoming_window has been reduced by this much during parsing */
448 gpr_uint32 incoming_window_delta;
Craig Tillerd20efd22015-06-12 16:17:09 -0700449 /** window available for peer to send to us */
450 gpr_uint32 incoming_window;
451 /** parsing state for data frames */
452 grpc_chttp2_data_parser data_parser;
Craig Tiller3719f072015-06-12 17:19:51 -0700453 /** reason give to rst_stream */
454 gpr_uint32 rst_stream_reason;
455 /* amount of window given */
456 gpr_uint64 outgoing_window_update;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700457
Craig Tiller5dc3b302015-06-15 16:06:50 -0700458 /** incoming metadata */
459 grpc_chttp2_incoming_metadata_buffer incoming_metadata;
460
461/*
Craig Tiller9b8671c2015-06-12 07:41:54 -0700462 grpc_linked_mdelem *incoming_metadata;
463 size_t incoming_metadata_count;
464 size_t incoming_metadata_capacity;
465 grpc_linked_mdelem *old_incoming_metadata;
466 gpr_timespec incoming_deadline;
Craig Tiller5dc3b302015-06-15 16:06:50 -0700467*/
Craig Tillerd20efd22015-06-12 16:17:09 -0700468};
469
470struct grpc_chttp2_stream {
471 grpc_chttp2_stream_global global;
472 grpc_chttp2_stream_writing writing;
Craig Tiller606d8742015-06-15 06:58:50 -0700473 grpc_chttp2_stream_parsing parsing;
Craig Tillerd20efd22015-06-12 16:17:09 -0700474
475 grpc_chttp2_stream_link links[STREAM_LIST_COUNT];
476 gpr_uint8 included[STREAM_LIST_COUNT];
Craig Tiller9b8671c2015-06-12 07:41:54 -0700477
Craig Tiller606d8742015-06-15 06:58:50 -0700478#if 0
479 gpr_uint32 outgoing_window_update;
480 gpr_uint8 cancelled;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700481
Craig Tiller9b8671c2015-06-12 07:41:54 -0700482 grpc_stream_state callback_state;
483 grpc_stream_op_buffer callback_sopb;
Craig Tiller606d8742015-06-15 06:58:50 -0700484#endif
Craig Tiller9b8671c2015-06-12 07:41:54 -0700485};
486
Craig Tillerd20efd22015-06-12 16:17:09 -0700487/** Transport writing call flow:
Craig Tiller4aa71a12015-06-15 13:00:55 -0700488 chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes
489 are required;
490 if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the
491 writes.
492 Once writes have been completed (meaning another write could potentially be
493 started),
494 grpc_chttp2_terminate_writing is called. This will call
495 grpc_chttp2_cleanup_writing, at which
Craig Tillerd20efd22015-06-12 16:17:09 -0700496 point the write phase is complete. */
497
Craig Tiller3208e392015-06-12 08:17:02 -0700498/** Someone is unlocking the transport mutex: check to see if writes
499 are required, and schedule them if so */
Craig Tiller4aa71a12015-06-15 13:00:55 -0700500int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global,
501 grpc_chttp2_transport_writing *writing);
502void grpc_chttp2_perform_writes(
503 grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint);
504void grpc_chttp2_terminate_writing(
505 grpc_chttp2_transport_writing *transport_writing, int success);
506void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global,
507 grpc_chttp2_transport_writing *writing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700508
509/** Process one slice of incoming data */
Craig Tiller4aa71a12015-06-15 13:00:55 -0700510void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global,
511 grpc_chttp2_transport_parsing *parsing);
512int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
513 gpr_slice slice);
514void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global,
515 grpc_chttp2_transport_parsing *parsing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700516
517/** Get a writable stream
518 \return non-zero if there was a stream available */
Craig Tiller4aa71a12015-06-15 13:00:55 -0700519void grpc_chttp2_list_add_writable_stream(
520 grpc_chttp2_transport_global *transport_global,
521 grpc_chttp2_stream_global *stream_global);
522int grpc_chttp2_list_pop_writable_stream(
523 grpc_chttp2_transport_global *transport_global,
524 grpc_chttp2_transport_writing *transport_writing,
525 grpc_chttp2_stream_global **stream_global,
526 grpc_chttp2_stream_writing **stream_writing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700527
Craig Tiller4aa71a12015-06-15 13:00:55 -0700528void grpc_chttp2_list_add_writing_stream(
529 grpc_chttp2_transport_writing *transport_writing,
530 grpc_chttp2_stream_writing *stream_writing);
531int grpc_chttp2_list_have_writing_streams(
532 grpc_chttp2_transport_writing *transport_writing);
533int grpc_chttp2_list_pop_writing_stream(
534 grpc_chttp2_transport_writing *transport_writing,
535 grpc_chttp2_stream_writing **stream_writing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700536
Craig Tiller4aa71a12015-06-15 13:00:55 -0700537void grpc_chttp2_list_add_written_stream(
538 grpc_chttp2_transport_writing *transport_writing,
539 grpc_chttp2_stream_writing *stream_writing);
540int grpc_chttp2_list_pop_written_stream(
541 grpc_chttp2_transport_global *transport_global,
542 grpc_chttp2_transport_writing *transport_writing,
543 grpc_chttp2_stream_global **stream_global,
544 grpc_chttp2_stream_writing **stream_writing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700545
Craig Tiller4aa71a12015-06-15 13:00:55 -0700546void grpc_chttp2_list_add_writable_window_update_stream(
547 grpc_chttp2_transport_global *transport_global,
548 grpc_chttp2_stream_global *stream_global);
549int grpc_chttp2_list_pop_writable_window_update_stream(
550 grpc_chttp2_transport_global *transport_global,
551 grpc_chttp2_stream_global **stream_global);
Craig Tillerd20efd22015-06-12 16:17:09 -0700552
Craig Tiller4aa71a12015-06-15 13:00:55 -0700553void grpc_chttp2_list_add_parsing_seen_stream(
554 grpc_chttp2_transport_parsing *transport_parsing,
555 grpc_chttp2_stream_parsing *stream_parsing);
556int grpc_chttp2_list_pop_parsing_seen_stream(
557 grpc_chttp2_transport_global *transport_global,
558 grpc_chttp2_transport_parsing *transport_parsing,
559 grpc_chttp2_stream_global **stream_global,
560 grpc_chttp2_stream_parsing **stream_parsing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700561
Craig Tiller5dc3b302015-06-15 16:06:50 -0700562void grpc_chttp2_list_add_waiting_for_concurrency(
563 grpc_chttp2_transport_global *transport_global,
564 grpc_chttp2_stream_global *stream_global);
565int grpc_chttp2_list_pop_waiting_for_concurrency(
566 grpc_chttp2_transport_global *transport_global,
567 grpc_chttp2_stream_global **stream_global);
568
569void grpc_chttp2_list_add_cancelled_waiting_for_parsing(
570 grpc_chttp2_transport_global *transport_global,
571 grpc_chttp2_stream_global *stream_global);
572int grpc_chttp2_list_pop_cancelled_waiting_for_parsing(
573 grpc_chttp2_transport_global *transport_global,
574 grpc_chttp2_stream_global **stream_global);
575
Craig Tiller4aa71a12015-06-15 13:00:55 -0700576void grpc_chttp2_schedule_closure(
577 grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure,
578 int success);
579void grpc_chttp2_read_write_state_changed(
580 grpc_chttp2_transport_global *transport_global,
581 grpc_chttp2_stream_global *stream_global);
Craig Tiller5dc3b302015-06-15 16:06:50 -0700582void grpc_chttp2_incoming_window_state_changed(
583 grpc_chttp2_transport_global *transport_global,
584 grpc_chttp2_stream_global *stream_global);
Craig Tillerd20efd22015-06-12 16:17:09 -0700585
Craig Tiller4aa71a12015-06-15 13:00:55 -0700586grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream(
587 grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
588grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(
589 grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
Craig Tillerd20efd22015-06-12 16:17:09 -0700590
Craig Tiller4aa71a12015-06-15 13:00:55 -0700591void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error,
592 gpr_slice goaway_text);
593
Craig Tiller5dc3b302015-06-15 16:06:50 -0700594void grpc_chttp2_remove_from_stream_map(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global);
595
596void grpc_chttp2_for_all_streams(grpc_chttp2_transport_global *transport_global, void *user_data, void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, grpc_chttp2_stream_global *stream_global));
597
598void grpc_chttp2_flowctl_trace(grpc_chttp2_transport *t, const char *flow,
599 gpr_int32 window, gpr_uint32 id, gpr_int32 delta);
Craig Tillerd20efd22015-06-12 16:17:09 -0700600
601#define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
Craig Tiller4aa71a12015-06-15 13:00:55 -0700602#define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \
603 (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1)
Craig Tillerd20efd22015-06-12 16:17:09 -0700604
605extern int grpc_http_trace;
606
607#define IF_TRACING(stmt) \
608 if (!(grpc_http_trace)) \
609 ; \
610 else \
611 stmt
Craig Tiller3208e392015-06-12 08:17:02 -0700612
Craig Tiller9b8671c2015-06-12 07:41:54 -0700613#endif