Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 3598d44 | 2016-03-15 14:53:05 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_SETTINGS_H |
| 35 | #define GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_SETTINGS_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | #include <grpc/support/port_platform.h> |
| 38 | #include <grpc/support/slice.h> |
Craig Tiller | 298751c | 2015-09-22 09:41:05 -0700 | [diff] [blame] | 39 | #include "src/core/iomgr/exec_ctx.h" |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 40 | #include "src/core/transport/chttp2/frame.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 42 | typedef enum { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 43 | GRPC_CHTTP2_SPS_ID0, |
| 44 | GRPC_CHTTP2_SPS_ID1, |
| 45 | GRPC_CHTTP2_SPS_VAL0, |
| 46 | GRPC_CHTTP2_SPS_VAL1, |
| 47 | GRPC_CHTTP2_SPS_VAL2, |
| 48 | GRPC_CHTTP2_SPS_VAL3 |
| 49 | } grpc_chttp2_settings_parse_state; |
| 50 | |
| 51 | /* The things HTTP/2 defines as connection level settings */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 52 | typedef enum { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 53 | GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE = 1, |
| 54 | GRPC_CHTTP2_SETTINGS_ENABLE_PUSH = 2, |
| 55 | GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3, |
| 56 | GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 4, |
| 57 | GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE = 5, |
| 58 | GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 6, |
| 59 | GRPC_CHTTP2_NUM_SETTINGS |
| 60 | } grpc_chttp2_setting_id; |
| 61 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 62 | typedef struct { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 63 | grpc_chttp2_settings_parse_state state; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 64 | uint32_t *target_settings; |
| 65 | uint8_t is_ack; |
| 66 | uint16_t id; |
| 67 | uint32_t value; |
| 68 | uint32_t incoming_settings[GRPC_CHTTP2_NUM_SETTINGS]; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 69 | } grpc_chttp2_settings_parser; |
| 70 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 71 | typedef enum { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 72 | GRPC_CHTTP2_CLAMP_INVALID_VALUE, |
| 73 | GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE |
| 74 | } grpc_chttp2_invalid_value_behavior; |
| 75 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 76 | typedef struct { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 77 | const char *name; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 78 | uint32_t default_value; |
| 79 | uint32_t min_value; |
| 80 | uint32_t max_value; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 81 | grpc_chttp2_invalid_value_behavior invalid_value_behavior; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 82 | uint32_t error_value; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 83 | } grpc_chttp2_setting_parameters; |
| 84 | |
| 85 | /* HTTP/2 mandated connection setting parameters */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 86 | extern const grpc_chttp2_setting_parameters |
| 87 | grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS]; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 88 | |
| 89 | /* Create a settings frame by diffing old & new, and updating old to be new */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 90 | gpr_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *new, |
| 91 | uint32_t force_mask, size_t count); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 92 | /* Create an ack settings frame */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 93 | gpr_slice grpc_chttp2_settings_ack_create(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 94 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 95 | grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame( |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 96 | grpc_chttp2_settings_parser *parser, uint32_t length, uint8_t flags, |
| 97 | uint32_t *settings); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 98 | grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( |
| 99 | grpc_exec_ctx *exec_ctx, void *parser, |
| 100 | grpc_chttp2_transport_parsing *transport_parsing, |
| 101 | grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 102 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 103 | #endif /* GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_SETTINGS_H */ |