Skip to content

Commit

Permalink
http2: name padding buffer fields
Browse files Browse the repository at this point in the history
PR-URL: #14744
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax committed Aug 14, 2017
1 parent 8a0d101 commit c5740f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
20 changes: 13 additions & 7 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ const kType = Symbol('type');
const kDefaultSocketTimeout = 2 * 60 * 1000;
const kRenegTest = /TLS session renegotiation disabled for this socket/;

const { paddingBuffer } = binding;
const {
paddingBuffer,
PADDING_BUF_FRAME_LENGTH,
PADDING_BUF_MAX_PAYLOAD_LENGTH,
PADDING_BUF_RETURN_VALUE
} = binding;

const {
NGHTTP2_CANCEL,
Expand Down Expand Up @@ -393,12 +398,13 @@ function onSelectPadding(fn) {
'bug in Node.js');
return function getPadding() {
debug('fetching padding for frame');
const frameLen = paddingBuffer[0];
const maxFramePayloadLen = paddingBuffer[1];
paddingBuffer[2] = Math.min(maxFramePayloadLen,
Math.max(frameLen,
fn(frameLen,
maxFramePayloadLen) | 0));
const frameLen = paddingBuffer[PADDING_BUF_FRAME_LENGTH];
const maxFramePayloadLen = paddingBuffer[PADDING_BUF_MAX_PAYLOAD_LENGTH];
paddingBuffer[PADDING_BUF_RETURN_VALUE] =
Math.min(maxFramePayloadLen,
Math.max(frameLen,
fn(frameLen,
maxFramePayloadLen) | 0));
};
}

Expand Down
19 changes: 15 additions & 4 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ enum Http2OptionsIndex {
IDX_OPTIONS_FLAGS
};

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

struct http2_state {
uint32_t padding_buffer[3];
uint32_t padding_buffer[PADDING_BUF_FIELD_COUNT];
uint32_t options_buffer[IDX_OPTIONS_FLAGS + 1];
uint32_t settings_buffer[IDX_SETTINGS_COUNT + 1];
double session_state_buffer[IDX_SESSION_STATE_COUNT];
Expand Down Expand Up @@ -120,10 +127,10 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,

if (object()->Has(context, env()->ongetpadding_string()).FromJust()) {
uint32_t* buffer = env()->http2_state_buffer()->padding_buffer;
buffer[0] = frameLen;
buffer[1] = maxPayloadLen;
buffer[PADDING_BUF_FRAME_LENGTH] = frameLen;
buffer[PADDING_BUF_MAX_PAYLOAD_LENGTH] = maxPayloadLen;
MakeCallback(env()->ongetpadding_string(), 0, nullptr);
uint32_t retval = buffer[2];
uint32_t retval = buffer[PADDING_BUF_RETURN_VALUE];
retval = retval <= maxPayloadLen ? retval : maxPayloadLen;
retval = retval >= frameLen ? retval : frameLen;
CHECK_GE(retval, frameLen);
Expand Down Expand Up @@ -1167,6 +1174,10 @@ void Initialize(Local<Object> target,
SET_STATE_TYPEDARRAY("optionsBuffer", Uint32Array, options_buffer);
#undef SET_STATE_TYPEDARRAY

NODE_DEFINE_CONSTANT(target, PADDING_BUF_FRAME_LENGTH);
NODE_DEFINE_CONSTANT(target, PADDING_BUF_MAX_PAYLOAD_LENGTH);
NODE_DEFINE_CONSTANT(target, PADDING_BUF_RETURN_VALUE);

// Method to fetch the nghttp2 string description of an nghttp2 error code
env->SetMethod(target, "nghttp2ErrorString", HttpErrorString);

Expand Down

0 comments on commit c5740f9

Please sign in to comment.