Craig Tiller | 640d3bd | 2015-06-12 07:51:51 -0700 | [diff] [blame] | 1 | /* |
| 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 Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 34 | #ifndef GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H |
| 35 | #define GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H |
| 36 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 37 | #include "src/core/iomgr/endpoint.h" |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 38 | #include "src/core/transport/chttp2/frame.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 39 | #include "src/core/transport/chttp2/frame_data.h" |
| 40 | #include "src/core/transport/chttp2/frame_goaway.h" |
| 41 | #include "src/core/transport/chttp2/frame_ping.h" |
| 42 | #include "src/core/transport/chttp2/frame_rst_stream.h" |
| 43 | #include "src/core/transport/chttp2/frame_settings.h" |
| 44 | #include "src/core/transport/chttp2/frame_window_update.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 45 | #include "src/core/transport/chttp2/hpack_parser.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 46 | #include "src/core/transport/chttp2/incoming_metadata.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 47 | #include "src/core/transport/chttp2/stream_encoder.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 48 | #include "src/core/transport/chttp2/stream_map.h" |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame] | 49 | #include "src/core/transport/connectivity_state.h" |
| 50 | #include "src/core/transport/transport_impl.h" |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 51 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 52 | typedef struct grpc_chttp2_transport grpc_chttp2_transport; |
| 53 | typedef struct grpc_chttp2_stream grpc_chttp2_stream; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 54 | |
| 55 | /* streams are kept in various linked lists depending on what things need to |
| 56 | happen to them... this enum labels each list */ |
| 57 | typedef enum { |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 58 | GRPC_CHTTP2_LIST_ALL_STREAMS, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 59 | GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 60 | GRPC_CHTTP2_LIST_WRITABLE, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 61 | GRPC_CHTTP2_LIST_WRITING, |
| 62 | GRPC_CHTTP2_LIST_WRITTEN, |
| 63 | GRPC_CHTTP2_LIST_WRITABLE_WINDOW_UPDATE, |
| 64 | GRPC_CHTTP2_LIST_PARSING_SEEN, |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 65 | GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING, |
Craig Tiller | 17be5dc | 2015-07-01 10:36:27 -0700 | [diff] [blame] | 66 | GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING, |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 67 | GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 68 | /** streams that are waiting to start because there are too many concurrent |
| 69 | streams on the connection */ |
| 70 | GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 71 | STREAM_LIST_COUNT /* must be last */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 72 | } grpc_chttp2_stream_list_id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 73 | |
| 74 | /* deframer state for the overall http2 stream of bytes */ |
| 75 | typedef enum { |
| 76 | /* prefix: one entry per http2 connection prefix byte */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 77 | GRPC_DTS_CLIENT_PREFIX_0 = 0, |
| 78 | GRPC_DTS_CLIENT_PREFIX_1, |
| 79 | GRPC_DTS_CLIENT_PREFIX_2, |
| 80 | GRPC_DTS_CLIENT_PREFIX_3, |
| 81 | GRPC_DTS_CLIENT_PREFIX_4, |
| 82 | GRPC_DTS_CLIENT_PREFIX_5, |
| 83 | GRPC_DTS_CLIENT_PREFIX_6, |
| 84 | GRPC_DTS_CLIENT_PREFIX_7, |
| 85 | GRPC_DTS_CLIENT_PREFIX_8, |
| 86 | GRPC_DTS_CLIENT_PREFIX_9, |
| 87 | GRPC_DTS_CLIENT_PREFIX_10, |
| 88 | GRPC_DTS_CLIENT_PREFIX_11, |
| 89 | GRPC_DTS_CLIENT_PREFIX_12, |
| 90 | GRPC_DTS_CLIENT_PREFIX_13, |
| 91 | GRPC_DTS_CLIENT_PREFIX_14, |
| 92 | GRPC_DTS_CLIENT_PREFIX_15, |
| 93 | GRPC_DTS_CLIENT_PREFIX_16, |
| 94 | GRPC_DTS_CLIENT_PREFIX_17, |
| 95 | GRPC_DTS_CLIENT_PREFIX_18, |
| 96 | GRPC_DTS_CLIENT_PREFIX_19, |
| 97 | GRPC_DTS_CLIENT_PREFIX_20, |
| 98 | GRPC_DTS_CLIENT_PREFIX_21, |
| 99 | GRPC_DTS_CLIENT_PREFIX_22, |
| 100 | GRPC_DTS_CLIENT_PREFIX_23, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 101 | /* frame header byte 0... */ |
| 102 | /* must follow from the prefix states */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 103 | GRPC_DTS_FH_0, |
| 104 | GRPC_DTS_FH_1, |
| 105 | GRPC_DTS_FH_2, |
| 106 | GRPC_DTS_FH_3, |
| 107 | GRPC_DTS_FH_4, |
| 108 | GRPC_DTS_FH_5, |
| 109 | GRPC_DTS_FH_6, |
| 110 | GRPC_DTS_FH_7, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 111 | /* ... frame header byte 8 */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 112 | GRPC_DTS_FH_8, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 113 | /* inside a http2 frame */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 114 | GRPC_DTS_FRAME |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 115 | } grpc_chttp2_deframe_transport_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 116 | |
| 117 | typedef enum { |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 118 | GRPC_WRITE_STATE_OPEN, |
| 119 | GRPC_WRITE_STATE_QUEUED_CLOSE, |
| 120 | GRPC_WRITE_STATE_SENT_CLOSE |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 121 | } grpc_chttp2_write_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 122 | |
| 123 | typedef enum { |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 124 | GRPC_DONT_SEND_CLOSED = 0, |
| 125 | GRPC_SEND_CLOSED, |
| 126 | GRPC_SEND_CLOSED_WITH_RST_STREAM |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 127 | } grpc_chttp2_send_closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 128 | |
| 129 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 130 | grpc_chttp2_stream *head; |
| 131 | grpc_chttp2_stream *tail; |
| 132 | } grpc_chttp2_stream_list; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 133 | |
| 134 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 135 | grpc_chttp2_stream *next; |
| 136 | grpc_chttp2_stream *prev; |
| 137 | } grpc_chttp2_stream_link; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 138 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 139 | /* We keep several sets of connection wide parameters */ |
| 140 | typedef enum { |
| 141 | /* The settings our peer has asked for (and we have acked) */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 142 | GRPC_PEER_SETTINGS = 0, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 143 | /* The settings we'd like to have */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 144 | GRPC_LOCAL_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 145 | /* The settings we've published to our peer */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 146 | GRPC_SENT_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 147 | /* The settings the peer has acked */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 148 | GRPC_ACKED_SETTINGS, |
| 149 | GRPC_NUM_SETTING_SETS |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 150 | } grpc_chttp2_setting_set; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 151 | |
| 152 | /* Outstanding ping request data */ |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 153 | typedef struct grpc_chttp2_outstanding_ping { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 154 | gpr_uint8 id[8]; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 155 | grpc_iomgr_closure *on_recv; |
| 156 | struct grpc_chttp2_outstanding_ping *next; |
| 157 | struct grpc_chttp2_outstanding_ping *prev; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 158 | } grpc_chttp2_outstanding_ping; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 159 | |
| 160 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 161 | /** data to write next write */ |
| 162 | gpr_slice_buffer qbuf; |
| 163 | /** queued callbacks */ |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 164 | grpc_iomgr_closure *pending_closures_head; |
| 165 | grpc_iomgr_closure *pending_closures_tail; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 166 | |
| 167 | /** window available for us to send to peer */ |
| 168 | gpr_uint32 outgoing_window; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 169 | /** window available for peer to send to us - updated after parse */ |
| 170 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 171 | /** how much window would we like to have for incoming_window */ |
| 172 | gpr_uint32 connection_window_target; |
| 173 | |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 174 | /** have we seen a goaway */ |
| 175 | gpr_uint8 seen_goaway; |
Craig Tiller | 9188d7a | 2015-07-05 12:44:37 -0700 | [diff] [blame] | 176 | /** have we sent a goaway */ |
| 177 | gpr_uint8 sent_goaway; |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 178 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 179 | /** is this transport a client? */ |
| 180 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 181 | /** are the local settings dirty and need to be sent? */ |
| 182 | gpr_uint8 dirtied_local_settings; |
| 183 | /** have local settings been sent? */ |
| 184 | gpr_uint8 sent_local_settings; |
| 185 | /** bitmask of setting indexes to send out */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 186 | gpr_uint32 force_send_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 187 | /** settings values */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 188 | gpr_uint32 settings[GRPC_NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS]; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 189 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 190 | /** what is the next stream id to be allocated by this peer? |
| 191 | copied to next_stream_id in parsing when parsing commences */ |
| 192 | gpr_uint32 next_stream_id; |
| 193 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 194 | /** last received stream id */ |
| 195 | gpr_uint32 last_incoming_stream_id; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 196 | |
| 197 | /** pings awaiting responses */ |
| 198 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 199 | /** next payload for an outgoing ping */ |
| 200 | gpr_uint64 ping_counter; |
| 201 | |
| 202 | /** concurrent stream count: updated when not parsing, |
| 203 | so this is a strict over-estimation on the client */ |
| 204 | gpr_uint32 concurrent_stream_count; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 205 | } grpc_chttp2_transport_global; |
| 206 | |
| 207 | typedef struct { |
| 208 | /** data to write now */ |
| 209 | gpr_slice_buffer outbuf; |
| 210 | /** hpack encoding */ |
| 211 | grpc_chttp2_hpack_compressor hpack_compressor; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 212 | /** is this a client? */ |
| 213 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 214 | } grpc_chttp2_transport_writing; |
| 215 | |
| 216 | struct grpc_chttp2_transport_parsing { |
| 217 | /** is this transport a client? (boolean) */ |
| 218 | gpr_uint8 is_client; |
| 219 | |
| 220 | /** were settings updated? */ |
| 221 | gpr_uint8 settings_updated; |
| 222 | /** was a settings ack received? */ |
| 223 | gpr_uint8 settings_ack_received; |
| 224 | /** was a goaway frame received? */ |
| 225 | gpr_uint8 goaway_received; |
| 226 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 227 | /** initial window change */ |
| 228 | gpr_int64 initial_window_update; |
| 229 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 230 | /** data to write later - after parsing */ |
| 231 | gpr_slice_buffer qbuf; |
| 232 | /* metadata object cache */ |
| 233 | grpc_mdstr *str_grpc_timeout; |
| 234 | /** parser for headers */ |
| 235 | grpc_chttp2_hpack_parser hpack_parser; |
| 236 | /** simple one shot parsers */ |
| 237 | union { |
| 238 | grpc_chttp2_window_update_parser window_update; |
| 239 | grpc_chttp2_settings_parser settings; |
| 240 | grpc_chttp2_ping_parser ping; |
| 241 | grpc_chttp2_rst_stream_parser rst_stream; |
| 242 | } simple; |
| 243 | /** parser for goaway frames */ |
| 244 | grpc_chttp2_goaway_parser goaway_parser; |
| 245 | |
| 246 | /** window available for peer to send to us */ |
| 247 | gpr_uint32 incoming_window; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 248 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 249 | |
| 250 | /** next stream id available at the time of beginning parsing */ |
| 251 | gpr_uint32 next_stream_id; |
| 252 | gpr_uint32 last_incoming_stream_id; |
| 253 | |
| 254 | /* deframing */ |
| 255 | grpc_chttp2_deframe_transport_state deframe_state; |
| 256 | gpr_uint8 incoming_frame_type; |
| 257 | gpr_uint8 incoming_frame_flags; |
| 258 | gpr_uint8 header_eof; |
| 259 | gpr_uint32 expect_continuation_stream_id; |
| 260 | gpr_uint32 incoming_frame_size; |
| 261 | gpr_uint32 incoming_stream_id; |
| 262 | |
| 263 | /* active parser */ |
| 264 | void *parser_data; |
| 265 | grpc_chttp2_stream_parsing *incoming_stream; |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 266 | grpc_chttp2_parse_error (*parser)( |
| 267 | void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing, |
| 268 | grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 269 | |
| 270 | /* received settings */ |
| 271 | gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS]; |
| 272 | |
| 273 | /* goaway data */ |
| 274 | grpc_status_code goaway_error; |
| 275 | gpr_uint32 goaway_last_stream_index; |
| 276 | gpr_slice goaway_text; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 277 | |
| 278 | gpr_uint64 outgoing_window_update; |
| 279 | |
| 280 | /** pings awaiting responses */ |
| 281 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 284 | struct grpc_chttp2_transport { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 285 | grpc_transport base; /* must be first */ |
| 286 | grpc_endpoint *ep; |
| 287 | grpc_mdctx *metadata_context; |
| 288 | gpr_refcount refs; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 289 | |
| 290 | gpr_mu mu; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 291 | |
| 292 | /** is the transport destroying itself? */ |
| 293 | gpr_uint8 destroying; |
| 294 | /** has the upper layer closed the transport? */ |
| 295 | gpr_uint8 closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 296 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 297 | /** is a thread currently writing */ |
| 298 | gpr_uint8 writing_active; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 299 | /** is a thread currently parsing */ |
| 300 | gpr_uint8 parsing_active; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 301 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 302 | /** is there a read request to the endpoint outstanding? */ |
| 303 | gpr_uint8 endpoint_reading; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 304 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 305 | /** various lists of streams */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 306 | grpc_chttp2_stream_list lists[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 307 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 308 | /** global state for reading/writing */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 309 | grpc_chttp2_transport_global global; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 310 | /** state only accessible by the chain of execution that |
| 311 | set writing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 312 | grpc_chttp2_transport_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 313 | /** state only accessible by the chain of execution that |
| 314 | set parsing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 315 | grpc_chttp2_transport_parsing parsing; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 316 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 317 | /** maps stream id to grpc_chttp2_stream objects; |
| 318 | owned by the parsing thread when parsing */ |
| 319 | grpc_chttp2_stream_map parsing_stream_map; |
| 320 | |
| 321 | /** streams created by the client (possibly during parsing); |
| 322 | merged with parsing_stream_map during unlock when no |
| 323 | parsing is occurring */ |
| 324 | grpc_chttp2_stream_map new_stream_map; |
| 325 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 326 | /** closure to execute writing */ |
| 327 | grpc_iomgr_closure writing_action; |
Craig Tiller | 8b2f1d7 | 2015-06-18 13:38:38 -0700 | [diff] [blame] | 328 | /** closure to start reading from the endpoint */ |
| 329 | grpc_iomgr_closure reading_action; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 330 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 331 | /** address to place a newly accepted stream - set and unset by |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 332 | grpc_chttp2_parsing_accept_stream; used by init_stream to |
| 333 | publish the accepted server stream */ |
| 334 | grpc_chttp2_stream **accepting_stream; |
| 335 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 336 | struct { |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 337 | /* accept stream callback */ |
| 338 | void (*accept_stream)(void *user_data, grpc_transport *transport, |
| 339 | const void *server_data); |
| 340 | void *accept_stream_user_data; |
| 341 | |
| 342 | /** connectivity tracking */ |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame] | 343 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 344 | } channel_callback; |
| 345 | }; |
| 346 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 347 | typedef struct { |
| 348 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 349 | gpr_uint32 id; |
| 350 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 351 | grpc_iomgr_closure *send_done_closure; |
| 352 | grpc_iomgr_closure *recv_done_closure; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 353 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 354 | /** window available for us to send to peer */ |
| 355 | gpr_int64 outgoing_window; |
Craig Tiller | 27166a6 | 2015-07-05 21:08:33 -0700 | [diff] [blame] | 356 | /** The number of bytes the upper layers have offered to receive. |
| 357 | As the upper layer offers more bytes, this value increases. |
| 358 | As bytes are read, this value decreases. */ |
| 359 | gpr_uint32 max_recv_bytes; |
| 360 | /** The number of bytes the upper layer has offered to read but we have |
| 361 | not yet announced to HTTP2 flow control. |
| 362 | As the upper layers offer to read more bytes, this value increases. |
| 363 | As we advertise incoming flow control window, this value decreases. */ |
| 364 | gpr_uint32 unannounced_incoming_window; |
| 365 | /** The number of bytes of HTTP2 flow control we have advertised. |
| 366 | As we advertise incoming flow control window, this value increases. |
| 367 | As bytes are read, this value decreases. |
| 368 | Updated after parse. */ |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 369 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 370 | /** stream ops the transport user would like to send */ |
| 371 | grpc_stream_op_buffer *outgoing_sopb; |
| 372 | /** when the application requests writes be closed, the write_closed is |
| 373 | 'queued'; when the close is flow controlled into the send path, we are |
| 374 | 'sending' it; when the write has been performed it is 'sent' */ |
| 375 | grpc_chttp2_write_state write_state; |
| 376 | /** is this stream closed (boolean) */ |
| 377 | gpr_uint8 read_closed; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 378 | /** has this stream been cancelled? (boolean) */ |
| 379 | gpr_uint8 cancelled; |
Craig Tiller | cec9eb9 | 2015-06-17 17:16:48 -0700 | [diff] [blame] | 380 | grpc_status_code cancelled_status; |
| 381 | /** have we told the upper layer that this stream is cancelled? */ |
| 382 | gpr_uint8 published_cancelled; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 383 | /** is this stream in the stream map? (boolean) */ |
| 384 | gpr_uint8 in_stream_map; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 385 | |
| 386 | /** stream state already published to the upper layer */ |
| 387 | grpc_stream_state published_state; |
| 388 | /** address to publish next stream state to */ |
| 389 | grpc_stream_state *publish_state; |
| 390 | /** pointer to sop buffer to fill in with new stream ops */ |
Craig Tiller | 6905b7c | 2015-06-16 15:33:33 -0700 | [diff] [blame] | 391 | grpc_stream_op_buffer *publish_sopb; |
| 392 | grpc_stream_op_buffer incoming_sopb; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 393 | |
| 394 | /** incoming metadata */ |
| 395 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
Craig Tiller | b787c50 | 2015-06-15 16:14:52 -0700 | [diff] [blame] | 396 | grpc_chttp2_incoming_metadata_live_op_buffer outstanding_metadata; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 397 | } grpc_chttp2_stream_global; |
| 398 | |
| 399 | typedef struct { |
| 400 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 401 | gpr_uint32 id; |
| 402 | /** sops that have passed flow control to be written */ |
| 403 | grpc_stream_op_buffer sopb; |
| 404 | /** how strongly should we indicate closure with the next write */ |
| 405 | grpc_chttp2_send_closed send_closed; |
Craig Tiller | 8631652 | 2015-07-15 11:35:07 -0700 | [diff] [blame^] | 406 | /** how much window should we announce? */ |
| 407 | gpr_uint32 announce_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 408 | } grpc_chttp2_stream_writing; |
| 409 | |
| 410 | struct grpc_chttp2_stream_parsing { |
| 411 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 412 | gpr_uint32 id; |
| 413 | /** has this stream received a close */ |
| 414 | gpr_uint8 received_close; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 415 | /** saw a rst_stream */ |
| 416 | gpr_uint8 saw_rst_stream; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 417 | /** incoming_window has been reduced by this much during parsing */ |
| 418 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 419 | /** window available for peer to send to us */ |
| 420 | gpr_uint32 incoming_window; |
| 421 | /** parsing state for data frames */ |
| 422 | grpc_chttp2_data_parser data_parser; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 423 | /** reason give to rst_stream */ |
| 424 | gpr_uint32 rst_stream_reason; |
| 425 | /* amount of window given */ |
| 426 | gpr_uint64 outgoing_window_update; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 427 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 428 | /** incoming metadata */ |
| 429 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | struct grpc_chttp2_stream { |
| 433 | grpc_chttp2_stream_global global; |
| 434 | grpc_chttp2_stream_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 435 | grpc_chttp2_stream_parsing parsing; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 436 | |
| 437 | grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; |
| 438 | gpr_uint8 included[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 439 | }; |
| 440 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 441 | /** Transport writing call flow: |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 442 | chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes |
| 443 | are required; |
| 444 | if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the |
| 445 | writes. |
| 446 | Once writes have been completed (meaning another write could potentially be |
| 447 | started), |
| 448 | grpc_chttp2_terminate_writing is called. This will call |
| 449 | grpc_chttp2_cleanup_writing, at which |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 450 | point the write phase is complete. */ |
| 451 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 452 | /** Someone is unlocking the transport mutex: check to see if writes |
| 453 | are required, and schedule them if so */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 454 | int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, |
| 455 | grpc_chttp2_transport_writing *writing); |
| 456 | void grpc_chttp2_perform_writes( |
| 457 | grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint); |
| 458 | void grpc_chttp2_terminate_writing( |
| 459 | grpc_chttp2_transport_writing *transport_writing, int success); |
| 460 | void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, |
| 461 | grpc_chttp2_transport_writing *writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 462 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 463 | void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, |
| 464 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 465 | /** Process one slice of incoming data; return 1 if the connection is still |
| 466 | viable after reading, or 0 if the connection should be torn down */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 467 | int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, |
| 468 | gpr_slice slice); |
| 469 | void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, |
| 470 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 471 | |
| 472 | /** Get a writable stream |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 473 | returns non-zero if there was a stream available */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 474 | void grpc_chttp2_list_add_writable_stream( |
| 475 | grpc_chttp2_transport_global *transport_global, |
| 476 | grpc_chttp2_stream_global *stream_global); |
| 477 | int grpc_chttp2_list_pop_writable_stream( |
| 478 | grpc_chttp2_transport_global *transport_global, |
| 479 | grpc_chttp2_transport_writing *transport_writing, |
| 480 | grpc_chttp2_stream_global **stream_global, |
| 481 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 482 | |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 483 | void grpc_chttp2_list_add_incoming_window_updated( |
| 484 | grpc_chttp2_transport_global *transport_global, |
| 485 | grpc_chttp2_stream_global *stream_global); |
| 486 | int grpc_chttp2_list_pop_incoming_window_updated( |
| 487 | grpc_chttp2_transport_global *transport_global, |
| 488 | grpc_chttp2_transport_parsing *transport_parsing, |
| 489 | grpc_chttp2_stream_global **stream_global, |
| 490 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | 759eb32 | 2015-06-16 22:41:18 -0700 | [diff] [blame] | 491 | void grpc_chttp2_list_remove_incoming_window_updated( |
| 492 | grpc_chttp2_transport_global *transport_global, |
| 493 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 494 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 495 | void grpc_chttp2_list_add_writing_stream( |
| 496 | grpc_chttp2_transport_writing *transport_writing, |
| 497 | grpc_chttp2_stream_writing *stream_writing); |
| 498 | int grpc_chttp2_list_have_writing_streams( |
| 499 | grpc_chttp2_transport_writing *transport_writing); |
| 500 | int grpc_chttp2_list_pop_writing_stream( |
| 501 | grpc_chttp2_transport_writing *transport_writing, |
| 502 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 503 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 504 | void grpc_chttp2_list_add_written_stream( |
| 505 | grpc_chttp2_transport_writing *transport_writing, |
| 506 | grpc_chttp2_stream_writing *stream_writing); |
| 507 | int grpc_chttp2_list_pop_written_stream( |
| 508 | grpc_chttp2_transport_global *transport_global, |
| 509 | grpc_chttp2_transport_writing *transport_writing, |
| 510 | grpc_chttp2_stream_global **stream_global, |
| 511 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 512 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 513 | void grpc_chttp2_list_add_writable_window_update_stream( |
| 514 | grpc_chttp2_transport_global *transport_global, |
| 515 | grpc_chttp2_stream_global *stream_global); |
| 516 | int grpc_chttp2_list_pop_writable_window_update_stream( |
| 517 | grpc_chttp2_transport_global *transport_global, |
Craig Tiller | 8631652 | 2015-07-15 11:35:07 -0700 | [diff] [blame^] | 518 | grpc_chttp2_transport_writing *transport_writing, |
| 519 | grpc_chttp2_stream_global **stream_global, |
| 520 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | b951df1 | 2015-06-18 15:46:58 -0700 | [diff] [blame] | 521 | void grpc_chttp2_list_remove_writable_window_update_stream( |
| 522 | grpc_chttp2_transport_global *transport_global, |
| 523 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 524 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 525 | void grpc_chttp2_list_add_parsing_seen_stream( |
| 526 | grpc_chttp2_transport_parsing *transport_parsing, |
| 527 | grpc_chttp2_stream_parsing *stream_parsing); |
| 528 | int grpc_chttp2_list_pop_parsing_seen_stream( |
| 529 | grpc_chttp2_transport_global *transport_global, |
| 530 | grpc_chttp2_transport_parsing *transport_parsing, |
| 531 | grpc_chttp2_stream_global **stream_global, |
| 532 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 533 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 534 | void grpc_chttp2_list_add_waiting_for_concurrency( |
| 535 | grpc_chttp2_transport_global *transport_global, |
| 536 | grpc_chttp2_stream_global *stream_global); |
| 537 | int grpc_chttp2_list_pop_waiting_for_concurrency( |
| 538 | grpc_chttp2_transport_global *transport_global, |
| 539 | grpc_chttp2_stream_global **stream_global); |
| 540 | |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 541 | void grpc_chttp2_list_add_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 542 | grpc_chttp2_transport_global *transport_global, |
| 543 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 544 | int grpc_chttp2_list_pop_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 545 | grpc_chttp2_transport_global *transport_global, |
| 546 | grpc_chttp2_stream_global **stream_global); |
| 547 | |
Craig Tiller | 17be5dc | 2015-07-01 10:36:27 -0700 | [diff] [blame] | 548 | void grpc_chttp2_list_add_cancelled_waiting_for_writing( |
| 549 | grpc_chttp2_transport_global *transport_global, |
| 550 | grpc_chttp2_stream_global *stream_global); |
| 551 | int grpc_chttp2_list_pop_cancelled_waiting_for_writing( |
| 552 | grpc_chttp2_transport_global *transport_global, |
| 553 | grpc_chttp2_stream_global **stream_global); |
| 554 | |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 555 | void grpc_chttp2_list_add_read_write_state_changed( |
| 556 | grpc_chttp2_transport_global *transport_global, |
| 557 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | f73fcd1 | 2015-06-16 16:25:26 -0700 | [diff] [blame] | 558 | int grpc_chttp2_list_pop_read_write_state_changed( |
| 559 | grpc_chttp2_transport_global *transport_global, |
| 560 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 561 | |
Craig Tiller | 1937b06 | 2015-06-16 08:47:38 -0700 | [diff] [blame] | 562 | /** schedule a closure to run without the transport lock taken */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 563 | void grpc_chttp2_schedule_closure( |
| 564 | grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure, |
| 565 | int success); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 566 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 567 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream( |
| 568 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
| 569 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream( |
| 570 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 571 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 572 | void grpc_chttp2_add_incoming_goaway( |
| 573 | grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error, |
| 574 | gpr_slice goaway_text); |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 575 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 576 | void grpc_chttp2_register_stream(grpc_chttp2_transport *t, |
| 577 | grpc_chttp2_stream *s); |
Craig Tiller | 9188d7a | 2015-07-05 12:44:37 -0700 | [diff] [blame] | 578 | /* returns 1 if this is the last stream, 0 otherwise */ |
| 579 | int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, |
| 580 | grpc_chttp2_stream *s) GRPC_MUST_USE_RESULT; |
| 581 | int grpc_chttp2_has_streams(grpc_chttp2_transport *t); |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 582 | void grpc_chttp2_for_all_streams( |
| 583 | grpc_chttp2_transport_global *transport_global, void *user_data, |
| 584 | void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, |
| 585 | grpc_chttp2_stream_global *stream_global)); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 586 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 587 | void grpc_chttp2_parsing_become_skip_parser( |
| 588 | grpc_chttp2_transport_parsing *transport_parsing); |
Craig Tiller | 66abdaa | 2015-06-17 08:00:39 -0700 | [diff] [blame] | 589 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 590 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 591 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ |
| 592 | (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 593 | |
| 594 | extern int grpc_http_trace; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 595 | extern int grpc_flowctl_trace; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 596 | |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 597 | #define GRPC_CHTTP2_IF_TRACING(stmt) \ |
| 598 | if (!(grpc_http_trace)) \ |
| 599 | ; \ |
| 600 | else \ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 601 | stmt |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 602 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 603 | #define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \ |
| 604 | delta) \ |
| 605 | if (!(grpc_flowctl_trace)) { \ |
| 606 | } else { \ |
| 607 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 608 | transport->is_client, context->id, context->var, \ |
| 609 | delta); \ |
| 610 | } |
| 611 | |
| 612 | #define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \ |
| 613 | if (!(grpc_flowctl_trace)) { \ |
| 614 | } else { \ |
| 615 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 616 | context->is_client, 0, context->var, delta); \ |
| 617 | } |
| 618 | |
| 619 | void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason, |
| 620 | const char *context, const char *var, |
| 621 | int is_client, gpr_uint32 stream_id, |
| 622 | gpr_int64 current_value, gpr_int64 delta); |
| 623 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 624 | #endif |