summaryrefslogtreecommitdiff
path: root/src/node_http2_state.h
blob: 64a0942f7ffa6775c9573ded0f63b0e52bfe6c32 (plain)
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
154
155
156
157
#ifndef SRC_NODE_HTTP2_STATE_H_
#define SRC_NODE_HTTP2_STATE_H_

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "aliased_buffer.h"

namespace node {
namespace http2 {

  enum Http2SettingsIndex {
    IDX_SETTINGS_HEADER_TABLE_SIZE,
    IDX_SETTINGS_ENABLE_PUSH,
    IDX_SETTINGS_INITIAL_WINDOW_SIZE,
    IDX_SETTINGS_MAX_FRAME_SIZE,
    IDX_SETTINGS_MAX_CONCURRENT_STREAMS,
    IDX_SETTINGS_MAX_HEADER_LIST_SIZE,
    IDX_SETTINGS_COUNT
  };

  enum Http2SessionStateIndex {
    IDX_SESSION_STATE_EFFECTIVE_LOCAL_WINDOW_SIZE,
    IDX_SESSION_STATE_EFFECTIVE_RECV_DATA_LENGTH,
    IDX_SESSION_STATE_NEXT_STREAM_ID,
    IDX_SESSION_STATE_LOCAL_WINDOW_SIZE,
    IDX_SESSION_STATE_LAST_PROC_STREAM_ID,
    IDX_SESSION_STATE_REMOTE_WINDOW_SIZE,
    IDX_SESSION_STATE_OUTBOUND_QUEUE_SIZE,
    IDX_SESSION_STATE_HD_DEFLATE_DYNAMIC_TABLE_SIZE,
    IDX_SESSION_STATE_HD_INFLATE_DYNAMIC_TABLE_SIZE,
    IDX_SESSION_STATE_COUNT
  };

  enum Http2StreamStateIndex {
    IDX_STREAM_STATE,
    IDX_STREAM_STATE_WEIGHT,
    IDX_STREAM_STATE_SUM_DEPENDENCY_WEIGHT,
    IDX_STREAM_STATE_LOCAL_CLOSE,
    IDX_STREAM_STATE_REMOTE_CLOSE,
    IDX_STREAM_STATE_LOCAL_WINDOW_SIZE,
    IDX_STREAM_STATE_COUNT
  };

  enum Http2OptionsIndex {
    IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE,
    IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS,
    IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH,
    IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS,
    IDX_OPTIONS_PADDING_STRATEGY,
    IDX_OPTIONS_MAX_HEADER_LIST_PAIRS,
    IDX_OPTIONS_MAX_OUTSTANDING_PINGS,
    IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS,
    IDX_OPTIONS_MAX_SESSION_MEMORY,
    IDX_OPTIONS_FLAGS
  };

  enum Http2PaddingBufferFields {
    PADDING_BUF_FRAME_LENGTH,
    PADDING_BUF_MAX_PAYLOAD_LENGTH,
    PADDING_BUF_RETURN_VALUE,
    PADDING_BUF_FIELD_COUNT
  };

  enum Http2StreamStatisticsIndex {
    IDX_STREAM_STATS_ID,
    IDX_STREAM_STATS_TIMETOFIRSTBYTE,
    IDX_STREAM_STATS_TIMETOFIRSTHEADER,
    IDX_STREAM_STATS_TIMETOFIRSTBYTESENT,
    IDX_STREAM_STATS_SENTBYTES,
    IDX_STREAM_STATS_RECEIVEDBYTES,
    IDX_STREAM_STATS_COUNT
  };

  enum Http2SessionStatisticsIndex {
    IDX_SESSION_STATS_TYPE,
    IDX_SESSION_STATS_PINGRTT,
    IDX_SESSION_STATS_FRAMESRECEIVED,
    IDX_SESSION_STATS_FRAMESSENT,
    IDX_SESSION_STATS_STREAMCOUNT,
    IDX_SESSION_STATS_STREAMAVERAGEDURATION,
    IDX_SESSION_STATS_DATA_SENT,
    IDX_SESSION_STATS_DATA_RECEIVED,
    IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS,
    IDX_SESSION_STATS_COUNT
  };

class Http2State {
 public:
  explicit Http2State(v8::Isolate* isolate) :
    root_buffer(
      isolate,
      sizeof(http2_state_internal)),
    session_state_buffer(
      isolate,
      offsetof(http2_state_internal, session_state_buffer),
      IDX_SESSION_STATE_COUNT,
      root_buffer),
    stream_state_buffer(
      isolate,
      offsetof(http2_state_internal, stream_state_buffer),
      IDX_STREAM_STATE_COUNT,
      root_buffer),
    stream_stats_buffer(
      isolate,
      offsetof(http2_state_internal, stream_stats_buffer),
      IDX_STREAM_STATS_COUNT,
      root_buffer),
    session_stats_buffer(
      isolate,
      offsetof(http2_state_internal, session_stats_buffer),
      IDX_SESSION_STATS_COUNT,
      root_buffer),
    padding_buffer(
      isolate,
      offsetof(http2_state_internal, padding_buffer),
      PADDING_BUF_FIELD_COUNT,
      root_buffer),
    options_buffer(
      isolate,
      offsetof(http2_state_internal, options_buffer),
      IDX_OPTIONS_FLAGS + 1,
      root_buffer),
    settings_buffer(
      isolate,
      offsetof(http2_state_internal, settings_buffer),
      IDX_SETTINGS_COUNT + 1,
      root_buffer) {
  }

  AliasedBuffer<uint8_t, v8::Uint8Array> root_buffer;
  AliasedBuffer<double, v8::Float64Array> session_state_buffer;
  AliasedBuffer<double, v8::Float64Array> stream_state_buffer;
  AliasedBuffer<double, v8::Float64Array> stream_stats_buffer;
  AliasedBuffer<double, v8::Float64Array> session_stats_buffer;
  AliasedBuffer<uint32_t, v8::Uint32Array> padding_buffer;
  AliasedBuffer<uint32_t, v8::Uint32Array> options_buffer;
  AliasedBuffer<uint32_t, v8::Uint32Array> settings_buffer;

 private:
  struct http2_state_internal {
    // doubles first so that they are always sizeof(double)-aligned
    double session_state_buffer[IDX_SESSION_STATE_COUNT];
    double stream_state_buffer[IDX_STREAM_STATE_COUNT];
    double stream_stats_buffer[IDX_STREAM_STATS_COUNT];
    double session_stats_buffer[IDX_SESSION_STATS_COUNT];
    uint32_t padding_buffer[PADDING_BUF_FIELD_COUNT];
    uint32_t options_buffer[IDX_OPTIONS_FLAGS + 1];
    uint32_t settings_buffer[IDX_SETTINGS_COUNT + 1];
  };
};

}  // namespace http2
}  // namespace node

#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#endif  // SRC_NODE_HTTP2_STATE_H_