1 #ifndef SRC_NODE_HTTP2_STATE_H_ 2 #define SRC_NODE_HTTP2_STATE_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "aliased_buffer.h" 7 8 struct nghttp2_rcbuf; 9 10 namespace node { 11 namespace http2 { 12 13 enum Http2SettingsIndex { 14 IDX_SETTINGS_HEADER_TABLE_SIZE, 15 IDX_SETTINGS_ENABLE_PUSH, 16 IDX_SETTINGS_INITIAL_WINDOW_SIZE, 17 IDX_SETTINGS_MAX_FRAME_SIZE, 18 IDX_SETTINGS_MAX_CONCURRENT_STREAMS, 19 IDX_SETTINGS_MAX_HEADER_LIST_SIZE, 20 IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL, 21 IDX_SETTINGS_COUNT 22 }; 23 24 enum Http2SessionStateIndex { 25 IDX_SESSION_STATE_EFFECTIVE_LOCAL_WINDOW_SIZE, 26 IDX_SESSION_STATE_EFFECTIVE_RECV_DATA_LENGTH, 27 IDX_SESSION_STATE_NEXT_STREAM_ID, 28 IDX_SESSION_STATE_LOCAL_WINDOW_SIZE, 29 IDX_SESSION_STATE_LAST_PROC_STREAM_ID, 30 IDX_SESSION_STATE_REMOTE_WINDOW_SIZE, 31 IDX_SESSION_STATE_OUTBOUND_QUEUE_SIZE, 32 IDX_SESSION_STATE_HD_DEFLATE_DYNAMIC_TABLE_SIZE, 33 IDX_SESSION_STATE_HD_INFLATE_DYNAMIC_TABLE_SIZE, 34 IDX_SESSION_STATE_COUNT 35 }; 36 37 enum Http2StreamStateIndex { 38 IDX_STREAM_STATE, 39 IDX_STREAM_STATE_WEIGHT, 40 IDX_STREAM_STATE_SUM_DEPENDENCY_WEIGHT, 41 IDX_STREAM_STATE_LOCAL_CLOSE, 42 IDX_STREAM_STATE_REMOTE_CLOSE, 43 IDX_STREAM_STATE_LOCAL_WINDOW_SIZE, 44 IDX_STREAM_STATE_COUNT 45 }; 46 47 enum Http2OptionsIndex { 48 IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE, 49 IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS, 50 IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH, 51 IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS, 52 IDX_OPTIONS_PADDING_STRATEGY, 53 IDX_OPTIONS_MAX_HEADER_LIST_PAIRS, 54 IDX_OPTIONS_MAX_OUTSTANDING_PINGS, 55 IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS, 56 IDX_OPTIONS_MAX_SESSION_MEMORY, 57 IDX_OPTIONS_MAX_SETTINGS, 58 IDX_OPTIONS_FLAGS 59 }; 60 61 enum Http2StreamStatisticsIndex { 62 IDX_STREAM_STATS_ID, 63 IDX_STREAM_STATS_TIMETOFIRSTBYTE, 64 IDX_STREAM_STATS_TIMETOFIRSTHEADER, 65 IDX_STREAM_STATS_TIMETOFIRSTBYTESENT, 66 IDX_STREAM_STATS_SENTBYTES, 67 IDX_STREAM_STATS_RECEIVEDBYTES, 68 IDX_STREAM_STATS_COUNT 69 }; 70 71 enum Http2SessionStatisticsIndex { 72 IDX_SESSION_STATS_TYPE, 73 IDX_SESSION_STATS_PINGRTT, 74 IDX_SESSION_STATS_FRAMESRECEIVED, 75 IDX_SESSION_STATS_FRAMESSENT, 76 IDX_SESSION_STATS_STREAMCOUNT, 77 IDX_SESSION_STATS_STREAMAVERAGEDURATION, 78 IDX_SESSION_STATS_DATA_SENT, 79 IDX_SESSION_STATS_DATA_RECEIVED, 80 IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS, 81 IDX_SESSION_STATS_COUNT 82 }; 83 84 class Http2State : public BaseObject { 85 public: Http2State(Environment * env,v8::Local<v8::Object> obj)86 Http2State(Environment* env, v8::Local<v8::Object> obj) 87 : BaseObject(env, obj), 88 root_buffer(env->isolate(), sizeof(http2_state_internal)), 89 session_state_buffer( 90 env->isolate(), 91 offsetof(http2_state_internal, session_state_buffer), 92 IDX_SESSION_STATE_COUNT, 93 root_buffer), 94 stream_state_buffer( 95 env->isolate(), 96 offsetof(http2_state_internal, stream_state_buffer), 97 IDX_STREAM_STATE_COUNT, 98 root_buffer), 99 stream_stats_buffer( 100 env->isolate(), 101 offsetof(http2_state_internal, stream_stats_buffer), 102 IDX_STREAM_STATS_COUNT, 103 root_buffer), 104 session_stats_buffer( 105 env->isolate(), 106 offsetof(http2_state_internal, session_stats_buffer), 107 IDX_SESSION_STATS_COUNT, 108 root_buffer), 109 options_buffer(env->isolate(), 110 offsetof(http2_state_internal, options_buffer), 111 IDX_OPTIONS_FLAGS + 1, 112 root_buffer), 113 settings_buffer(env->isolate(), 114 offsetof(http2_state_internal, settings_buffer), 115 IDX_SETTINGS_COUNT + 1, 116 root_buffer) {} 117 118 AliasedUint8Array root_buffer; 119 AliasedFloat64Array session_state_buffer; 120 AliasedFloat64Array stream_state_buffer; 121 AliasedFloat64Array stream_stats_buffer; 122 AliasedFloat64Array session_stats_buffer; 123 AliasedUint32Array options_buffer; 124 AliasedUint32Array settings_buffer; 125 126 void MemoryInfo(MemoryTracker* tracker) const override; 127 SET_SELF_SIZE(Http2State) SET_MEMORY_INFO_NAME(Http2State)128 SET_MEMORY_INFO_NAME(Http2State) 129 130 static constexpr FastStringKey type_name { "http2" }; 131 132 private: 133 struct http2_state_internal { 134 // doubles first so that they are always sizeof(double)-aligned 135 double session_state_buffer[IDX_SESSION_STATE_COUNT]; 136 double stream_state_buffer[IDX_STREAM_STATE_COUNT]; 137 double stream_stats_buffer[IDX_STREAM_STATS_COUNT]; 138 double session_stats_buffer[IDX_SESSION_STATS_COUNT]; 139 uint32_t options_buffer[IDX_OPTIONS_FLAGS + 1]; 140 uint32_t settings_buffer[IDX_SETTINGS_COUNT + 1]; 141 }; 142 }; 143 144 } // namespace http2 145 } // namespace node 146 147 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 148 149 #endif // SRC_NODE_HTTP2_STATE_H_ 150