diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index cf6355b2fe9..6e8cc209044 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -158,24 +158,24 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame &frame) } // Check whether Window Size is acceptable - if (!this->_server_rwnd_is_shrinking && this->server_rwnd() < payload_length) { + if (!this->_local_rwnd_is_shrinking_in && this->get_local_rwnd_in() < payload_length) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_CONNECTION, Http2ErrorCode::HTTP2_ERROR_FLOW_CONTROL_ERROR, "recv data cstate.server_rwnd < payload_length"); } - if (stream->server_rwnd() < payload_length) { + if (stream->get_local_rwnd() < payload_length) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, Http2ErrorCode::HTTP2_ERROR_FLOW_CONTROL_ERROR, "recv data stream->server_rwnd < payload_length"); } // Update Window size - this->decrement_server_rwnd(payload_length); - stream->decrement_server_rwnd(payload_length); + this->decrement_local_rwnd_in(payload_length); + stream->decrement_local_rwnd(payload_length); if (is_debug_tag_set("http2_con")) { uint32_t const stream_window = this->acknowledged_local_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE); uint32_t const session_window = this->_get_configured_receive_session_window_size_in(); - Http2StreamDebug(this->session, id, "Received DATA frame: rwnd con=%zd/%" PRId32 " stream=%zd/%" PRId32, this->server_rwnd(), - session_window, stream->server_rwnd(), stream_window); + Http2StreamDebug(this->session, id, "Received DATA frame: rwnd con=%zd/%" PRId32 " stream=%zd/%" PRId32, + this->get_local_rwnd_in(), session_window, stream->get_local_rwnd(), stream_window); } const uint32_t unpadded_length = payload_length - pad_length; @@ -494,7 +494,7 @@ Http2ConnectionState::rcv_priority_frame(const Http2Frame &frame) // Restrict number of inactive node in dependency tree smaller than max_concurrent_streams. // Current number of inactive node is size of tree minus active node count. - if (Http2::max_concurrent_streams_in > this->dependency_tree->size() - this->get_client_stream_count() + 1) { + if (Http2::max_concurrent_streams_in > this->dependency_tree->size() - this->get_peer_stream_count() + 1) { this->dependency_tree->add(priority.stream_dependency, stream_id, priority.weight, priority.exclusive_flag, nullptr); } } @@ -650,7 +650,7 @@ Http2ConnectionState::rcv_settings_frame(const Http2Frame &frame) // windows that it maintains by the difference between the new value and // the old value. if (param.id == HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) { - this->update_initial_client_rwnd(param.value); + this->update_initial_peer_rwnd_in(param.value); } this->peer_settings.set(static_cast(param.id), param.value); @@ -803,7 +803,7 @@ Http2ConnectionState::rcv_window_update_frame(const Http2Frame &frame) if (stream_id == HTTP2_CONNECTION_CONTROL_STREAM) { // Connection level window update Http2StreamDebug(this->session, stream_id, "Received WINDOW_UPDATE frame - updated to: %zd delta: %u", - (this->client_rwnd() + size), size); + (this->get_peer_rwnd_in() + size), size); // A sender MUST NOT allow a flow-control window to exceed 2^31-1 // octets. If a sender receives a WINDOW_UPDATE that causes a flow- @@ -812,12 +812,12 @@ Http2ConnectionState::rcv_window_update_frame(const Http2Frame &frame) // sends a RST_STREAM with an error code of FLOW_CONTROL_ERROR; for the // connection, a GOAWAY frame with an error code of FLOW_CONTROL_ERROR // is sent. - if (size > HTTP2_MAX_WINDOW_SIZE - this->client_rwnd()) { + if (size > HTTP2_MAX_WINDOW_SIZE - this->get_peer_rwnd_in()) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_CONNECTION, Http2ErrorCode::HTTP2_ERROR_FLOW_CONTROL_ERROR, "window update too big"); } - auto error = this->increment_client_rwnd(size); + auto error = this->increment_peer_rwnd_in(size); if (error != Http2ErrorCode::HTTP2_ERROR_NO_ERROR) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_CONNECTION, error, "Erroneous client window update"); } @@ -837,7 +837,7 @@ Http2ConnectionState::rcv_window_update_frame(const Http2Frame &frame) } Http2StreamDebug(this->session, stream_id, "Received WINDOW_UPDATE frame - updated to: %zd delta: %u", - (stream->client_rwnd() + size), size); + (stream->get_peer_rwnd() + size), size); // A sender MUST NOT allow a flow-control window to exceed 2^31-1 // octets. If a sender receives a WINDOW_UPDATE that causes a flow- @@ -846,17 +846,17 @@ Http2ConnectionState::rcv_window_update_frame(const Http2Frame &frame) // sends a RST_STREAM with an error code of FLOW_CONTROL_ERROR; for the // connection, a GOAWAY frame with an error code of FLOW_CONTROL_ERROR // is sent. - if (size > HTTP2_MAX_WINDOW_SIZE - stream->client_rwnd()) { + if (size > HTTP2_MAX_WINDOW_SIZE - stream->get_peer_rwnd()) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, Http2ErrorCode::HTTP2_ERROR_FLOW_CONTROL_ERROR, "window update too big 2"); } - auto error = stream->increment_client_rwnd(size); + auto error = stream->increment_peer_rwnd(size); if (error != Http2ErrorCode::HTTP2_ERROR_NO_ERROR) { return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, error); } - ssize_t wnd = std::min(this->client_rwnd(), stream->client_rwnd()); + ssize_t wnd = std::min(this->get_peer_rwnd_in(), stream->get_peer_rwnd()); if (!stream->is_closed() && stream->get_state() == Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_REMOTE && wnd > 0) { SCOPED_MUTEX_LOCK(lock, stream->mutex, this_ethread()); stream->restart_sending(); @@ -1050,15 +1050,15 @@ Http2ConnectionState::init(Http2CommonSession *ssn) // There is no HTTP/2 specified way to shrink the connection window size // other than to receive data and not send WINDOW_UPDATE frames for a // while. - this->_server_rwnd = HTTP2_INITIAL_WINDOW_SIZE; - this->_server_rwnd_is_shrinking = true; + this->_local_rwnd_in = HTTP2_INITIAL_WINDOW_SIZE; + this->_local_rwnd_is_shrinking_in = true; } else { - this->_server_rwnd = configured_session_window; - this->_server_rwnd_is_shrinking = false; + this->_local_rwnd_in = configured_session_window; + this->_local_rwnd_is_shrinking_in = false; } - local_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE); - remote_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE); + local_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE); + peer_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE); if (Http2::stream_priority_enabled) { dependency_tree = new DependencyTree(Http2::max_concurrent_streams_in); } @@ -1125,8 +1125,8 @@ Http2ConnectionState::destroy() delete local_hpack_handle; local_hpack_handle = nullptr; - delete remote_hpack_handle; - remote_hpack_handle = nullptr; + delete peer_hpack_handle; + peer_hpack_handle = nullptr; delete dependency_tree; dependency_tree = nullptr; this->session = nullptr; @@ -1320,7 +1320,7 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) return nullptr; } - bool client_streamid = http2_is_client_streamid(new_id); + bool is_client_streamid = http2_is_client_streamid(new_id); // 5.1.1 The identifier of a newly established stream MUST be numerically // greater than all streams that the initiating endpoint has opened or @@ -1328,7 +1328,7 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) // and streams that are reserved using PUSH_PROMISE. An endpoint that // receives an unexpected stream identifier MUST respond with a // connection error (Section 5.4.1) of type PROTOCOL_ERROR. - if (client_streamid) { + if (is_client_streamid) { if (new_id <= latest_streamid_in) { error = Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_CONNECTION, Http2ErrorCode::HTTP2_ERROR_PROTOCOL_ERROR, "recv headers new client id less than latest stream id"); @@ -1345,15 +1345,15 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) // Endpoints MUST NOT exceed the limit set by their peer. An endpoint // that receives a HEADERS frame that causes their advertised concurrent // stream limit to be exceeded MUST treat this as a stream error. - if (client_streamid) { - if (client_streams_in_count >= acknowledged_local_settings.get(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)) { + if (is_client_streamid) { + if (peer_streams_count_in >= acknowledged_local_settings.get(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)) { HTTP2_INCREMENT_THREAD_DYN_STAT(HTTP2_STAT_MAX_CONCURRENT_STREAMS_EXCEEDED_IN, this_ethread()); error = Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, Http2ErrorCode::HTTP2_ERROR_REFUSED_STREAM, "recv headers creating inbound stream beyond max_concurrent limit"); return nullptr; } } else { - if (client_streams_out_count >= peer_settings.get(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)) { + if (peer_streams_count_out >= peer_settings.get(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)) { HTTP2_INCREMENT_THREAD_DYN_STAT(HTTP2_STAT_MAX_CONCURRENT_STREAMS_EXCEEDED_OUT, this_ethread()); error = Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, Http2ErrorCode::HTTP2_ERROR_REFUSED_STREAM, "recv headers creating outbound stream beyond max_concurrent limit"); @@ -1363,7 +1363,7 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) uint32_t initial_stream_window = this->acknowledged_local_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE); uint32_t initial_stream_window_target = initial_stream_window; - if (client_streamid && this->_has_dynamic_stream_window()) { + if (is_client_streamid && this->_has_dynamic_stream_window()) { // For dynamic stream windows, the peer's idea of what the window size is // may be different than what we are configuring. Our calulated server // receive window is always maintained at what the peer has acknowledged so @@ -1375,7 +1375,7 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) // // The situation of dynamic stream window sizes is described in [RFC 9113] // 6.9.3. - initial_stream_window_target = this->_get_configured_receive_session_window_size_in() / (client_streams_in_count.load() + 1); + initial_stream_window_target = this->_get_configured_receive_session_window_size_in() / (peer_streams_count_in.load() + 1); } Http2Stream *new_stream = THREAD_ALLOC_INIT(http2StreamAllocator, this_ethread(), session->get_proxy_session(), new_id, peer_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE), initial_stream_window); @@ -1387,10 +1387,10 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) new_stream->is_first_transaction_flag = get_stream_requests() == 0; stream_list.enqueue(new_stream); - if (client_streamid) { + if (is_client_streamid) { latest_streamid_in = new_id; - ink_assert(client_streams_in_count < UINT32_MAX); - ++client_streams_in_count; + ink_assert(peer_streams_count_in < UINT32_MAX); + ++peer_streams_count_in; if (this->_has_dynamic_stream_window()) { Http2ConnectionSettings new_settings = local_settings; new_settings.set(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE, initial_stream_window_target); @@ -1398,10 +1398,10 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) } } else { latest_streamid_out = new_id; - ink_assert(client_streams_out_count < UINT32_MAX); - ++client_streams_out_count; + ink_assert(peer_streams_count_out < UINT32_MAX); + ++peer_streams_count_out; } - ++total_client_streams_count; + ++total_peer_streams_count; if (zombie_event != nullptr) { zombie_event->cancel(); @@ -1437,7 +1437,7 @@ Http2ConnectionState::restart_streams() static uint16_t starting_point = 0; // Change the start point randomly - for (int i = starting_point % total_client_streams_count; i >= 0; --i) { + for (int i = starting_point % total_peer_streams_count; i >= 0; --i) { end = static_cast(end->link.next ? end->link.next : stream_list.head); } s = static_cast(end->link.next ? end->link.next : stream_list.head); @@ -1446,7 +1446,7 @@ Http2ConnectionState::restart_streams() while (s != end) { Http2Stream *next = static_cast(s->link.next ? s->link.next : stream_list.head); if (!s->is_closed() && s->get_state() == Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_REMOTE && - std::min(this->client_rwnd(), s->client_rwnd()) > 0) { + std::min(this->get_peer_rwnd_in(), s->get_peer_rwnd()) > 0) { SCOPED_MUTEX_LOCK(lock, s->mutex, this_ethread()); s->restart_sending(); } @@ -1454,7 +1454,7 @@ Http2ConnectionState::restart_streams() s = next; } if (!s->is_closed() && s->get_state() == Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_REMOTE && - std::min(this->client_rwnd(), s->client_rwnd()) > 0) { + std::min(this->get_peer_rwnd_in(), s->get_peer_rwnd()) > 0) { SCOPED_MUTEX_LOCK(lock, s->mutex, this_ethread()); s->restart_sending(); } @@ -1470,17 +1470,17 @@ Http2ConnectionState::restart_receiving(Http2Stream *stream) uint32_t const configured_session_window = this->_get_configured_receive_session_window_size_in(); uint32_t const min_session_window = std::min(configured_session_window, this->acknowledged_local_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE)); - if (this->server_rwnd() < min_session_window) { - Http2WindowSize diff_size = configured_session_window - this->server_rwnd(); + if (this->get_local_rwnd_in() < min_session_window) { + Http2WindowSize diff_size = configured_session_window - this->get_local_rwnd_in(); if (diff_size > 0) { - this->increment_server_rwnd(diff_size); - this->_server_rwnd_is_shrinking = false; + this->increment_local_rwnd_in(diff_size); + this->_local_rwnd_is_shrinking_in = false; this->send_window_update_frame(HTTP2_CONNECTION_CONTROL_STREAM, diff_size); } } // Stream level WINDOW UPDATE - if (stream == nullptr || stream->server_rwnd() >= min_session_window) { + if (stream == nullptr || stream->get_local_rwnd() >= min_session_window) { // There's no need to increase the stream window size if it is already big // enough to hold what the stream/max frame size can receive. return; @@ -1494,21 +1494,21 @@ Http2ConnectionState::restart_receiving(Http2Stream *stream) } Http2WindowSize diff_size = 0; - if (stream->server_rwnd() < 0) { + if (stream->get_local_rwnd() < 0) { // Receive windows can be negative if we sent a SETTINGS frame that // decreased the stream window size mid-stream. This is not a problem: we // simply compute a WINDOW_UPDATE value to bring the window up to the // target initial_stream_window size. - diff_size = initial_stream_window - stream->server_rwnd(); + diff_size = initial_stream_window - stream->get_local_rwnd(); } else { - diff_size = initial_stream_window - std::max(static_cast(stream->server_rwnd()), data_size); + diff_size = initial_stream_window - std::max(static_cast(stream->get_local_rwnd()), data_size); } // Dynamic stream window sizes may result in negative values. In this case, // we'll just be waiting for the peer to send more data until the receive // window decreases to be under the initial window size. if (diff_size > 0) { - stream->increment_server_rwnd(diff_size); + stream->increment_local_rwnd(diff_size); this->send_window_update_frame(stream->get_id(), diff_size); } } @@ -1577,11 +1577,11 @@ Http2ConnectionState::delete_stream(Http2Stream *stream) stream_list.remove(stream); if (http2_is_client_streamid(stream->get_id())) { - ink_assert(client_streams_in_count > 0); - --client_streams_in_count; + ink_assert(peer_streams_count_in > 0); + --peer_streams_count_in; } else { - ink_assert(client_streams_out_count > 0); - --client_streams_out_count; + ink_assert(peer_streams_count_out > 0); + --peer_streams_count_out; } // total_client_streams_count will be decremented in release_stream(), because it's a counter include streams in the process of // shutting down. @@ -1600,7 +1600,7 @@ Http2ConnectionState::release_stream() if (this->session) { ink_assert(this->mutex == session->get_mutex()); - if (total_client_streams_count == 0) { + if (total_peer_streams_count == 0) { if (fini_received) { session->do_clear_session_active(); @@ -1631,7 +1631,7 @@ Http2ConnectionState::release_stream() } void -Http2ConnectionState::update_initial_client_rwnd(Http2WindowSize new_size) +Http2ConnectionState::update_initial_peer_rwnd_in(Http2WindowSize new_size) { // Update stream level window sizes for (Http2Stream *s = stream_list.head; s; s = static_cast(s->link.next)) { @@ -1647,12 +1647,12 @@ Http2ConnectionState::update_initial_client_rwnd(Http2WindowSize new_size) // // Note that if the client reduces the stream window, this may result in // negative receive window values. - s->set_client_rwnd(new_size - (peer_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - s->client_rwnd())); + s->set_peer_rwnd(new_size - (peer_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - s->get_peer_rwnd())); } } void -Http2ConnectionState::update_initial_server_rwnd(Http2WindowSize new_size) +Http2ConnectionState::update_initial_local_rwnd_in(Http2WindowSize new_size) { // Update stream level window sizes for (Http2Stream *s = stream_list.head; s; s = static_cast(s->link.next)) { @@ -1668,7 +1668,7 @@ Http2ConnectionState::update_initial_server_rwnd(Http2WindowSize new_size) // // Note that if ATS reduces the stream window, this may result in negative // receive window values. - s->set_server_rwnd(new_size - (acknowledged_local_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - s->server_rwnd())); + s->set_local_rwnd(new_size - (acknowledged_local_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - s->get_local_rwnd())); } } @@ -1697,7 +1697,7 @@ Http2ConnectionState::send_data_frames_depends_on_priority() Http2DependencyTree::Node *node = dependency_tree->top(); // No node to send or no connection level window left - if (node == nullptr || _client_rwnd <= 0) { + if (node == nullptr || _peer_rwnd_in <= 0) { return; } @@ -1739,7 +1739,7 @@ Http2ConnectionState::send_data_frames_depends_on_priority() Http2SendDataFrameResult Http2ConnectionState::send_a_data_frame(Http2Stream *stream, size_t &payload_length) { - const ssize_t window_size = std::min(this->client_rwnd(), stream->client_rwnd()); + const ssize_t window_size = std::min(this->get_peer_rwnd_in(), stream->get_peer_rwnd()); const size_t buf_len = BUFFER_SIZE_FOR_INDEX(buffer_size_index[HTTP2_FRAME_TYPE_DATA]); const size_t write_available_size = std::min(buf_len, static_cast(window_size)); payload_length = 0; @@ -1794,12 +1794,12 @@ Http2ConnectionState::send_a_data_frame(Http2Stream *stream, size_t &payload_len } // Update window size - this->decrement_client_rwnd(payload_length); - stream->decrement_client_rwnd(payload_length); + this->decrement_peer_rwnd_in(payload_length); + stream->decrement_peer_rwnd(payload_length); // Create frame Http2StreamDebug(session, stream->get_id(), "Send a DATA frame - client window con: %5zd stream: %5zd payload: %5zd", - _client_rwnd, stream->client_rwnd(), payload_length); + _peer_rwnd_in, stream->get_peer_rwnd(), payload_length); Http2DataFrame data(stream->get_id(), flags, resp_reader, payload_length); this->session->xmit(data, flags & HTTP2_FLAGS_DATA_END_STREAM); @@ -1863,7 +1863,7 @@ Http2ConnectionState::send_headers_frame(Http2Stream *stream) uint8_t *buf = local_buffer.data(); stream->mark_milestone(Http2StreamMilestone::START_ENCODE_HEADERS); - Http2ErrorCode result = http2_encode_header_blocks(resp_hdr, buf, buf_len, &header_blocks_size, *(this->remote_hpack_handle), + Http2ErrorCode result = http2_encode_header_blocks(resp_hdr, buf, buf_len, &header_blocks_size, *(this->peer_hpack_handle), peer_settings.get(HTTP2_SETTINGS_HEADER_TABLE_SIZE)); if (result != Http2ErrorCode::HTTP2_ERROR_NO_ERROR) { return; @@ -1953,7 +1953,7 @@ Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, con ts::LocalBuffer local_buffer(buf_len); uint8_t *buf = local_buffer.data(); - Http2ErrorCode result = http2_encode_header_blocks(&hdr, buf, buf_len, &header_blocks_size, *(this->remote_hpack_handle), + Http2ErrorCode result = http2_encode_header_blocks(&hdr, buf, buf_len, &header_blocks_size, *(this->peer_hpack_handle), peer_settings.get(HTTP2_SETTINGS_HEADER_TABLE_SIZE)); if (result != Http2ErrorCode::HTTP2_ERROR_NO_ERROR) { return false; @@ -2078,7 +2078,7 @@ Http2ConnectionState::send_settings_frame(const Http2ConnectionSettings &new_set Http2SettingsFrame settings(stream_id, HTTP2_FRAME_NO_FLAG, params, params_size); - this->_outstanding_settings_frames.emplace(new_settings); + this->_outstanding_settings_frames_in.emplace(new_settings); this->session->xmit(settings); } @@ -2087,12 +2087,12 @@ Http2ConnectionState::_process_incoming_settings_ack_frame() { constexpr Http2StreamId stream_id = HTTP2_CONNECTION_CONTROL_STREAM; Http2StreamDebug(session, stream_id, "Processing SETTINGS ACK frame with a queue size of %zu", - this->_outstanding_settings_frames.size()); + this->_outstanding_settings_frames_in.size()); // Do not update this->acknowledged_local_settings yet as // update_initial_server_rwnd relies upon it still pointing to the old value. Http2ConnectionSettings const &old_settings = this->acknowledged_local_settings; - Http2ConnectionSettings const &new_settings = this->_outstanding_settings_frames.front().get_outstanding_settings(); + Http2ConnectionSettings const &new_settings = this->_outstanding_settings_frames_in.front().get_outstanding_settings(); for (int i = HTTP2_SETTINGS_HEADER_TABLE_SIZE; i < HTTP2_SETTINGS_MAX; ++i) { Http2SettingsIdentifier id = static_cast(i); @@ -2108,11 +2108,11 @@ Http2ConnectionState::_process_incoming_settings_ack_frame() if (id == HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) { // Update all the streams for the newly acknowledged window size. - this->update_initial_server_rwnd(new_value); + this->update_initial_local_rwnd_in(new_value); } } this->acknowledged_local_settings = new_settings; - this->_outstanding_settings_frames.pop(); + this->_outstanding_settings_frames_in.pop(); } void @@ -2272,15 +2272,15 @@ Http2ConnectionState::_has_dynamic_stream_window() const } ssize_t -Http2ConnectionState::client_rwnd() const +Http2ConnectionState::get_peer_rwnd_in() const { - return this->_client_rwnd; + return this->_peer_rwnd_in; } Http2ErrorCode -Http2ConnectionState::increment_client_rwnd(size_t amount) +Http2ConnectionState::increment_peer_rwnd_in(size_t amount) { - this->_client_rwnd += amount; + this->_peer_rwnd_in += amount; this->_recent_rwnd_increment[this->_recent_rwnd_increment_index] = amount; ++this->_recent_rwnd_increment_index; @@ -2295,28 +2295,28 @@ Http2ConnectionState::increment_client_rwnd(size_t amount) } Http2ErrorCode -Http2ConnectionState::decrement_client_rwnd(size_t amount) +Http2ConnectionState::decrement_peer_rwnd_in(size_t amount) { - this->_client_rwnd -= amount; + this->_peer_rwnd_in -= amount; return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; } ssize_t -Http2ConnectionState::server_rwnd() const +Http2ConnectionState::get_local_rwnd_in() const { - return this->_server_rwnd; + return this->_local_rwnd_in; } Http2ErrorCode -Http2ConnectionState::increment_server_rwnd(size_t amount) +Http2ConnectionState::increment_local_rwnd_in(size_t amount) { - this->_server_rwnd += amount; + this->_local_rwnd_in += amount; return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; } Http2ErrorCode -Http2ConnectionState::decrement_server_rwnd(size_t amount) +Http2ConnectionState::decrement_local_rwnd_in(size_t amount) { - this->_server_rwnd -= amount; + this->_local_rwnd_in -= amount; return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; } diff --git a/proxy/http2/Http2ConnectionState.h b/proxy/http2/Http2ConnectionState.h index 24315b4e77e..d1ee37d4409 100644 --- a/proxy/http2/Http2ConnectionState.h +++ b/proxy/http2/Http2ConnectionState.h @@ -81,10 +81,10 @@ class Http2ConnectionState : public Continuation ProxyError rx_error_code; ProxyError tx_error_code; - Http2CommonSession *session = nullptr; - HpackHandle *local_hpack_handle = nullptr; - HpackHandle *remote_hpack_handle = nullptr; - DependencyTree *dependency_tree = nullptr; + Http2CommonSession *session = nullptr; + HpackHandle *local_hpack_handle = nullptr; + HpackHandle *peer_hpack_handle = nullptr; + DependencyTree *dependency_tree = nullptr; ActivityCop _cop; /** The HTTP/2 settings configured by ATS and dictated to the peer via @@ -130,10 +130,10 @@ class Http2ConnectionState : public Continuation void restart_receiving(Http2Stream *stream); /** Update all streams for the peer's newly dictated stream window size. */ - void update_initial_client_rwnd(Http2WindowSize new_size); + void update_initial_peer_rwnd_in(Http2WindowSize new_size); /** Update all streams for our newly dictated stream window size. */ - void update_initial_server_rwnd(Http2WindowSize new_size); + void update_initial_local_rwnd_in(Http2WindowSize new_size); Http2StreamId get_latest_stream_id_in() const; Http2StreamId get_latest_stream_id_out() const; @@ -145,8 +145,8 @@ class Http2ConnectionState : public Continuation void set_continued_stream_id(Http2StreamId stream_id); void clear_continued_stream_id(); - uint32_t get_client_stream_count() const; - void decrement_stream_count(); + uint32_t get_peer_stream_count() const; + void decrement_peer_stream_count(); double get_stream_error_rate() const; Http2ErrorCode get_shutdown_reason() const; @@ -191,12 +191,12 @@ class Http2ConnectionState : public Continuation void increment_received_priority_frame_count(); uint32_t get_received_priority_frame_count(); - ssize_t client_rwnd() const; - Http2ErrorCode increment_client_rwnd(size_t amount); - Http2ErrorCode decrement_client_rwnd(size_t amount); - ssize_t server_rwnd() const; - Http2ErrorCode increment_server_rwnd(size_t amount); - Http2ErrorCode decrement_server_rwnd(size_t amount); + ssize_t get_peer_rwnd_in() const; + Http2ErrorCode increment_peer_rwnd_in(size_t amount); + Http2ErrorCode decrement_peer_rwnd_in(size_t amount); + ssize_t get_local_rwnd_in() const; + Http2ErrorCode increment_local_rwnd_in(size_t amount); + Http2ErrorCode decrement_local_rwnd_in(size_t amount); private: Http2Error rcv_data_frame(const Http2Frame &); @@ -256,22 +256,23 @@ class Http2ConnectionState : public Continuation Http2StreamId latest_streamid_out = 0; std::atomic stream_requests = 0; - // Counter for current active streams which is started by client - std::atomic client_streams_in_count = 0; + // Counter for current active streams which are started by the client. + std::atomic peer_streams_count_in = 0; - // Counter for current active streams which is started by server - std::atomic client_streams_out_count = 0; + // Counter for current active streams which are started by the origin. + std::atomic peer_streams_count_out = 0; - // Counter for current active streams and streams in the process of shutting down - std::atomic total_client_streams_count = 0; + // Counter for current active streams (from either the client or origin side) + // and streams in the process of shutting down + std::atomic total_peer_streams_count = 0; // Counter for stream errors ATS sent uint32_t stream_error_count = 0; // Connection level window size - /** The session level window that we have to respect when we send data to the - * peer. + /** The client-side session level window that we have to respect when we send + * data to the peer. * * This is the session window configured by the peer via WINDOW_UPDATE * frames. Per specification, this defaults to HTTP2_INITIAL_WINDOW_SIZE (see @@ -280,19 +281,20 @@ class Http2ConnectionState : public Continuation * specification. When we receive WINDOW_UPDATE frames, we increment this * value. */ - ssize_t _client_rwnd = HTTP2_INITIAL_WINDOW_SIZE; + ssize_t _peer_rwnd_in = HTTP2_INITIAL_WINDOW_SIZE; - /** The session window we maintain with the peer via WINDOW_UPDATE frames. + /** The session window we maintain with the client-side peer via + * WINDOW_UPDATE frames. * * We maintain the window we expect the peer to respect by sending * WINDOW_UPDATE frames to the peer. As we receive data, we decrement this * value, as we send WINDOW_UPDATE frames, we increment it. If it reaches * zero, we generate a connection-level error. */ - ssize_t _server_rwnd = 0; + ssize_t _local_rwnd_in = 0; - /** Whether the session window is in a shrinking state before we send the - * first WINDOW_UPDATE frame. + /** Whether the client-side session window is in a shrinking state before we + * send the first WINDOW_UPDATE frame. * * Unlike HTTP/2 streams, the HTTP/2 session window has no way to initialize * it to a value lower than 65,535. If the initial value is lower than @@ -301,7 +303,7 @@ class Http2ConnectionState : public Continuation * window gets to the desired size, we start maintaining the window via * WINDOW_UPDATE frames. */ - bool _server_rwnd_is_shrinking = false; + bool _local_rwnd_is_shrinking_in = false; std::vector _recent_rwnd_increment = {SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX}; int _recent_rwnd_increment_index = 0; @@ -357,7 +359,7 @@ class Http2ConnectionState : public Continuation /** The queue of SETTINGS frames that we have sent but have not yet been * acknowledged by the peer. */ - std::queue _outstanding_settings_frames; + std::queue _outstanding_settings_frames_in; // NOTE: Id of stream which MUST receive CONTINUATION frame. // - [RFC 7540] 6.2 HEADERS @@ -425,15 +427,15 @@ Http2ConnectionState::clear_continued_stream_id() } inline uint32_t -Http2ConnectionState::get_client_stream_count() const +Http2ConnectionState::get_peer_stream_count() const { - return client_streams_in_count; + return peer_streams_count_in; } inline void -Http2ConnectionState::decrement_stream_count() +Http2ConnectionState::decrement_peer_stream_count() { - --total_client_streams_count; + --total_peer_streams_count; } inline double diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index a44232c856a..28a18e30b3c 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -40,8 +40,8 @@ ClassAllocator http2StreamAllocator("http2StreamAllocator"); -Http2Stream::Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_client_rwnd, ssize_t initial_server_rwnd) - : super(session), _id(sid), _client_rwnd(initial_client_rwnd), _server_rwnd(initial_server_rwnd) +Http2Stream::Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_peer_rwnd, ssize_t initial_local_rwnd) + : super(session), _id(sid), _peer_rwnd(initial_peer_rwnd), _local_rwnd(initial_local_rwnd) { SET_HANDLER(&Http2Stream::main_event_handler); @@ -80,7 +80,7 @@ Http2Stream::~Http2Stream() // In many cases, this has been called earlier, so this call is a no-op h2_proxy_ssn->connection_state.delete_stream(this); - h2_proxy_ssn->connection_state.decrement_stream_count(); + h2_proxy_ssn->connection_state.decrement_peer_stream_count(); // Update session's stream counts, so it accurately goes into keep-alive state h2_proxy_ssn->connection_state.release_stream(); @@ -914,15 +914,15 @@ Http2Stream::decrement_transactions_stat() } ssize_t -Http2Stream::client_rwnd() const +Http2Stream::get_peer_rwnd() const { - return this->_client_rwnd; + return this->_peer_rwnd; } Http2ErrorCode -Http2Stream::increment_client_rwnd(size_t amount) +Http2Stream::increment_peer_rwnd(size_t amount) { - this->_client_rwnd += amount; + this->_peer_rwnd += amount; this->_recent_rwnd_increment[this->_recent_rwnd_increment_index] = amount; ++this->_recent_rwnd_increment_index; @@ -936,10 +936,10 @@ Http2Stream::increment_client_rwnd(size_t amount) } Http2ErrorCode -Http2Stream::decrement_client_rwnd(size_t amount) +Http2Stream::decrement_peer_rwnd(size_t amount) { - this->_client_rwnd -= amount; - if (this->_client_rwnd < 0) { + this->_peer_rwnd -= amount; + if (this->_peer_rwnd < 0) { return Http2ErrorCode::HTTP2_ERROR_PROTOCOL_ERROR; } else { return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; @@ -947,23 +947,23 @@ Http2Stream::decrement_client_rwnd(size_t amount) } ssize_t -Http2Stream::server_rwnd() const +Http2Stream::get_local_rwnd() const { - return this->_server_rwnd; + return this->_local_rwnd; } Http2ErrorCode -Http2Stream::increment_server_rwnd(size_t amount) +Http2Stream::increment_local_rwnd(size_t amount) { - this->_server_rwnd += amount; + this->_local_rwnd += amount; return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; } Http2ErrorCode -Http2Stream::decrement_server_rwnd(size_t amount) +Http2Stream::decrement_local_rwnd(size_t amount) { - this->_server_rwnd -= amount; - if (this->_server_rwnd < 0) { + this->_local_rwnd -= amount; + if (this->_local_rwnd < 0) { return Http2ErrorCode::HTTP2_ERROR_PROTOCOL_ERROR; } else { return Http2ErrorCode::HTTP2_ERROR_NO_ERROR; diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h index 2ce8454390a..7647818521d 100644 --- a/proxy/http2/Http2Stream.h +++ b/proxy/http2/Http2Stream.h @@ -55,7 +55,7 @@ class Http2Stream : public ProxyTransaction using super = ProxyTransaction; ///< Parent type. Http2Stream() {} // Just to satisfy ClassAllocator - Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_client_rwnd, ssize_t initial_server_rwnd); + Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_peer_rwnd, ssize_t initial_local_rwnd); ~Http2Stream(); int main_event_handler(int event, void *edata); @@ -85,12 +85,21 @@ class Http2Stream : public ProxyTransaction bool push_promise(URL &url, const MIMEField *accept_encoding); // Stream level window size - ssize_t client_rwnd() const; - Http2ErrorCode increment_client_rwnd(size_t amount); - Http2ErrorCode decrement_client_rwnd(size_t amount); - ssize_t server_rwnd() const; - Http2ErrorCode increment_server_rwnd(size_t amount); - Http2ErrorCode decrement_server_rwnd(size_t amount); + // The following peer versions are our accounting of how many bytes we can + // send to the peer in order to respect their advertised receive window. + ssize_t get_peer_rwnd() const; + Http2ErrorCode increment_peer_rwnd(size_t amount); + Http2ErrorCode decrement_peer_rwnd(size_t amount); + + // The following local versions are the accounting of how big our receive + // window is that we have communicated to the peer and which the peer needs + // to respect when sending us data. We use this for calculating whether the + // peer has exceeded the window size by sending us too many bytes and we also + // use this to calculate WINDOW_UPDATE frame increment values to send to the + // peer. + ssize_t get_local_rwnd() const; + Http2ErrorCode increment_local_rwnd(size_t amount); + Http2ErrorCode decrement_local_rwnd(size_t amount); ///////////////// // Accessors @@ -125,8 +134,8 @@ class Http2Stream : public ProxyTransaction Http2StreamId get_id() const; Http2StreamState get_state() const; bool change_state(uint8_t type, uint8_t flags); - void set_client_rwnd(Http2WindowSize new_size); - void set_server_rwnd(Http2WindowSize new_size); + void set_peer_rwnd(Http2WindowSize new_size); + void set_local_rwnd(Http2WindowSize new_size); bool has_trailing_header() const; void set_receive_headers(HTTPHdr &h2_headers); MIOBuffer *read_vio_writer() const; @@ -204,8 +213,8 @@ class Http2Stream : public ProxyTransaction uint64_t data_length = 0; uint64_t bytes_sent = 0; - ssize_t _client_rwnd = 0; - ssize_t _server_rwnd = 0; + ssize_t _peer_rwnd = 0; + ssize_t _local_rwnd = 0; std::vector _recent_rwnd_increment = {SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX}; int _recent_rwnd_increment_index = 0; @@ -260,15 +269,15 @@ Http2Stream::get_state() const } inline void -Http2Stream::set_client_rwnd(Http2WindowSize new_size) +Http2Stream::set_peer_rwnd(Http2WindowSize new_size) { - this->_client_rwnd = new_size; + this->_peer_rwnd = new_size; } inline void -Http2Stream::set_server_rwnd(Http2WindowSize new_size) +Http2Stream::set_local_rwnd(Http2WindowSize new_size) { - this->_server_rwnd = new_size; + this->_local_rwnd = new_size; } inline bool