| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -322,23 +322,14 @@ function onStreamRead(nread, buf, handle) { | |||
| 322 | 322 | ||
| 323 | 323 | // Called when the remote peer settings have been updated. | |
| 324 | 324 | // Resets the cached settings. | |
| 325 | - function onSettings(ack) { | ||
| 325 | + function onSettings() { | ||
| 326 | 326 | const session = this[kOwner]; | |
| 327 | 327 | if (session.destroyed) | |
| 328 | 328 | return; | |
| 329 | 329 | session[kUpdateTimer](); | |
| 330 | - let event = 'remoteSettings'; | ||
| 331 | - if (ack) { | ||
| 332 | - debug(`Http2Session ${sessionName(session[kType])}: settings acknowledged`); | ||
| 333 | - if (session[kState].pendingAck > 0) | ||
| 334 | - session[kState].pendingAck--; | ||
| 335 | - session[kLocalSettings] = undefined; | ||
| 336 | - event = 'localSettings'; | ||
| 337 | - } else { | ||
| 338 | - debug(`Http2Session ${sessionName(session[kType])}: new settings received`); | ||
| 339 | - session[kRemoteSettings] = undefined; | ||
| 340 | - } | ||
| 341 | - process.nextTick(emit, session, event, session[event]); | ||
| 330 | + debug(`Http2Session ${sessionName(session[kType])}: new settings received`); | ||
| 331 | + session[kRemoteSettings] = undefined; | ||
| 332 | + process.nextTick(emit, session, 'remoteSettings', session.remoteSettings); | ||
| 342 | 333 | } | |
| 343 | 334 | ||
| 344 | 335 | // If the stream exists, an attempt will be made to emit an event | |
@@ -538,15 +529,32 @@ function onSessionInternalError(code) { | |||
| 538 | 529 | this[kOwner].destroy(new NghttpError(code)); | |
| 539 | 530 | } | |
| 540 | 531 | ||
| 532 | + function settingsCallback(cb, ack, duration) { | ||
| 533 | + this[kState].pendingAck--; | ||
| 534 | + this[kLocalSettings] = undefined; | ||
| 535 | + if (ack) { | ||
| 536 | + debug(`Http2Session ${sessionName(this[kType])}: settings received`); | ||
| 537 | + const settings = this.localSettings; | ||
| 538 | + if (typeof cb === 'function') | ||
| 539 | + cb(null, settings, duration); | ||
| 540 | + this.emit('localSettings', settings); | ||
| 541 | + } else { | ||
| 542 | + debug(`Http2Session ${sessionName(this[kType])}: settings canceled`); | ||
| 543 | + if (typeof cb === 'function') | ||
| 544 | + cb(new errors.Error('ERR_HTTP2_SETTINGS_CANCEL')); | ||
| 545 | + } | ||
| 546 | + } | ||
| 547 | + | ||
| 541 | 548 | // Submits a SETTINGS frame to be sent to the remote peer. | |
| 542 | - function submitSettings(settings) { | ||
| 549 | + function submitSettings(settings, callback) { | ||
| 543 | 550 | if (this.destroyed) | |
| 544 | 551 | return; | |
| 545 | 552 | debug(`Http2Session ${sessionName(this[kType])}: submitting settings`); | |
| 546 | 553 | this[kUpdateTimer](); | |
| 547 | - this[kLocalSettings] = undefined; | ||
| 548 | 554 | updateSettingsBuffer(settings); | |
| 549 | - this[kHandle].settings(); | ||
| 555 | + if (!this[kHandle].settings(settingsCallback.bind(this, callback))) { | ||
| 556 | + this.destroy(new errors.Error('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK')); | ||
| 557 | + } | ||
| 550 | 558 | } | |
| 551 | 559 | ||
| 552 | 560 | // Submits a PRIORITY frame to be sent to the remote peer | |
@@ -781,7 +789,6 @@ class Http2Session extends EventEmitter { | |||
| 781 | 789 | streams: new Map(), | |
| 782 | 790 | pendingStreams: new Set(), | |
| 783 | 791 | pendingAck: 0, | |
| 784 | - maxPendingAck: Math.max(1, (options.maxPendingAck | 0) || 10), | ||
| 785 | 792 | writeQueueSize: 0 | |
| 786 | 793 | }; | |
| 787 | 794 | ||
@@ -948,21 +955,19 @@ class Http2Session extends EventEmitter { | |||
| 948 | 955 | } | |
| 949 | 956 | ||
| 950 | 957 | // Submits a SETTINGS frame to be sent to the remote peer. | |
| 951 | - settings(settings) { | ||
| 958 | + settings(settings, callback) { | ||
| 952 | 959 | if (this.destroyed) | |
| 953 | 960 | throw new errors.Error('ERR_HTTP2_INVALID_SESSION'); | |
| 954 | - | ||
| 955 | 961 | assertIsObject(settings, 'settings'); | |
| 956 | 962 | settings = validateSettings(settings); | |
| 957 | - const state = this[kState]; | ||
| 958 | - if (state.pendingAck === state.maxPendingAck) { | ||
| 959 | - throw new errors.Error('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK', | ||
| 960 | - this[kState].pendingAck); | ||
| 961 | - } | ||
| 963 | + | ||
| 964 | + if (callback && typeof callback !== 'function') | ||
| 965 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 962 | 966 | debug(`Http2Session ${sessionName(this[kType])}: sending settings`); | |
| 963 | 967 | ||
| 964 | - state.pendingAck++; | ||
| 965 | - const settingsFn = submitSettings.bind(this, settings); | ||
| 968 | + this[kState].pendingAck++; | ||
| 969 | + | ||
| 970 | + const settingsFn = submitSettings.bind(this, settings, callback); | ||
| 966 | 971 | if (this.connecting) { | |
| 967 | 972 | this.once('connect', settingsFn); | |
| 968 | 973 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,8 @@ const IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS = 3; | |||
| 174 | 174 | const IDX_OPTIONS_PADDING_STRATEGY = 4; | |
| 175 | 175 | const IDX_OPTIONS_MAX_HEADER_LIST_PAIRS = 5; | |
| 176 | 176 | const IDX_OPTIONS_MAX_OUTSTANDING_PINGS = 6; | |
| 177 | - const IDX_OPTIONS_FLAGS = 7; | ||
| 177 | + const IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS = 7; | ||
| 178 | + const IDX_OPTIONS_FLAGS = 8; | ||
| 178 | 179 | ||
| 179 | 180 | function updateOptionsBuffer(options) { | |
| 180 | 181 | var flags = 0; | |
@@ -213,6 +214,11 @@ function updateOptionsBuffer(options) { | |||
| 213 | 214 | optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_PINGS] = | |
| 214 | 215 | options.maxOutstandingPings; | |
| 215 | 216 | } | |
| 217 | + if (typeof options.maxOutstandingSettings === 'number') { | ||
| 218 | + flags |= (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS); | ||
| 219 | + optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS] = | ||
| 220 | + Math.max(1, options.maxOutstandingSettings); | ||
| 221 | + } | ||
| 216 | 222 | optionsBuffer[IDX_OPTIONS_FLAGS] = flags; | |
| 217 | 223 | } | |
| 218 | 224 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ namespace node { | |||
| 44 | 44 | V(HTTP2SESSION) \ | |
| 45 | 45 | V(HTTP2STREAM) \ | |
| 46 | 46 | V(HTTP2PING) \ | |
| 47 | + V(HTTP2SETTINGS) \ | ||
| 47 | 48 | V(HTTPPARSER) \ | |
| 48 | 49 | V(JSSTREAM) \ | |
| 49 | 50 | V(PIPECONNECTWRAP) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -317,6 +317,7 @@ class ModuleWrap; | |||
| 317 | 317 | V(domains_stack_array, v8::Array) \ | |
| 318 | 318 | V(http2ping_constructor_template, v8::ObjectTemplate) \ | |
| 319 | 319 | V(http2stream_constructor_template, v8::ObjectTemplate) \ | |
| 320 | + V(http2settings_constructor_template, v8::ObjectTemplate) \ | ||
| 320 | 321 | V(inspector_console_api_object, v8::Object) \ | |
| 321 | 322 | V(module_load_list_array, v8::Array) \ | |
| 322 | 323 | V(pbkdf2_constructor_template, v8::ObjectTemplate) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments