-
Notifications
You must be signed in to change notification settings - Fork 5.5k
listener: extract active_tcp_socket and active_stream_listener_base #17355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mattklein123
merged 29 commits into
envoyproxy:main
from
lambdai:addinternallistener_pre_2
Jul 22, 2021
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cb82711
initial internal listener
lambdai 4c156ce
for new pr
lambdai 773c75a
merge main
lambdai b6ff892
delete test/integration/internal_tcp_proxy_integration_test.cc
lambdai 635f185
coverage
lambdai 3615512
remove ClientConnectionImpl ctor for internal socket
lambdai efe9ce7
revert dispatcher
lambdai 01ee5bb
merged main
lambdai 1564151
revert internal listener
lambdai 9e5b2b4
pragma once
lambdai e802a6f
test bootstrap
lambdai c8e4e43
comment other than incNumConnections
lambdai aac23c1
rename
lambdai 573cdfe
put cleanup, deferdelete in base
lambdai c1f7921
push down conn collection or active conn op
lambdai 0528d50
Merge branch 'main' into addinternallistener_pre_1
lambdai 0b3c2f0
Merge branch 'addinternallistener_pre_1' of github.com:lambdai/envoy-…
lambdai bbee979
tmpaddinternallistener_pre_1
lambdai 57ca809
fix format
lambdai 4523c99
address comment
lambdai dc08e69
Merge remote-tracking branch 'origin/main' into addinternallistener_p…
lambdai dfe40e4
listener: extract active_tcp_socket and active_stream_listener_base
lambdai a497d0b
add missing files
lambdai ef4fc26
new line at EOF
lambdai feebbc3
address comments
lambdai df6f495
format
lambdai ee35a0f
merge main
lambdai fa60a09
revert flat_hash_map
lambdai 87060fc
base listener: add removeSocket and const socket list accessor
lambdai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #include "source/server/active_stream_listener_base.h" | ||
|
|
||
| #include "envoy/network/filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| ActiveStreamListenerBase::ActiveStreamListenerBase(Network::ConnectionHandler& parent, | ||
| Event::Dispatcher& dispatcher, | ||
| Network::ListenerPtr&& listener, | ||
| Network::ListenerConfig& config) | ||
| : ActiveListenerImplBase(parent, &config), parent_(parent), | ||
| listener_filters_timeout_(config.listenerFiltersTimeout()), | ||
| continue_on_listener_filters_timeout_(config.continueOnListenerFiltersTimeout()), | ||
| dispatcher_(dispatcher), listener_(std::move(listener)) {} | ||
|
|
||
| void ActiveStreamListenerBase::emitLogs(Network::ListenerConfig& config, | ||
| StreamInfo::StreamInfo& stream_info) { | ||
| stream_info.onRequestComplete(); | ||
| for (const auto& access_log : config.accessLogs()) { | ||
| access_log->log(nullptr, nullptr, nullptr, stream_info); | ||
| } | ||
| } | ||
|
|
||
| void ActiveStreamListenerBase::newConnection(Network::ConnectionSocketPtr&& socket, | ||
| std::unique_ptr<StreamInfo::StreamInfo> stream_info) { | ||
| // Find matching filter chain. | ||
| const auto filter_chain = config_->filterChainManager().findFilterChain(*socket); | ||
| if (filter_chain == nullptr) { | ||
| RELEASE_ASSERT(socket->addressProvider().remoteAddress() != nullptr, ""); | ||
| ENVOY_LOG(debug, "closing connection from {}: no matching filter chain found", | ||
| socket->addressProvider().remoteAddress()->asString()); | ||
| stats_.no_filter_chain_match_.inc(); | ||
| stream_info->setResponseFlag(StreamInfo::ResponseFlag::NoRouteFound); | ||
| stream_info->setResponseCodeDetails(StreamInfo::ResponseCodeDetails::get().FilterChainNotFound); | ||
| emitLogs(*config_, *stream_info); | ||
| socket->close(); | ||
| return; | ||
| } | ||
| stream_info->setFilterChainName(filter_chain->name()); | ||
| auto transport_socket = filter_chain->transportSocketFactory().createTransportSocket(nullptr); | ||
| stream_info->setDownstreamSslConnection(transport_socket->ssl()); | ||
| auto server_conn_ptr = dispatcher().createServerConnection( | ||
| std::move(socket), std::move(transport_socket), *stream_info); | ||
| if (const auto timeout = filter_chain->transportSocketConnectTimeout(); | ||
| timeout != std::chrono::milliseconds::zero()) { | ||
| server_conn_ptr->setTransportSocketConnectTimeout(timeout); | ||
| } | ||
| server_conn_ptr->setBufferLimits(config_->perConnectionBufferLimitBytes()); | ||
| RELEASE_ASSERT(server_conn_ptr->addressProvider().remoteAddress() != nullptr, ""); | ||
| const bool empty_filter_chain = !config_->filterChainFactory().createNetworkFilterChain( | ||
| *server_conn_ptr, filter_chain->networkFilterFactories()); | ||
| if (empty_filter_chain) { | ||
| ENVOY_CONN_LOG(debug, "closing connection from {}: no filters", *server_conn_ptr, | ||
| server_conn_ptr->addressProvider().remoteAddress()->asString()); | ||
| server_conn_ptr->close(Network::ConnectionCloseType::NoFlush); | ||
| } | ||
| newActiveConnection(*filter_chain, std::move(server_conn_ptr), std::move(stream_info)); | ||
| } | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #pragma once | ||
|
|
||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <list> | ||
| #include <memory> | ||
|
|
||
| #include "envoy/common/time.h" | ||
| #include "envoy/event/dispatcher.h" | ||
| #include "envoy/network/connection.h" | ||
| #include "envoy/network/connection_handler.h" | ||
| #include "envoy/network/listener.h" | ||
| #include "envoy/stream_info/stream_info.h" | ||
|
|
||
| #include "source/common/common/linked_object.h" | ||
| #include "source/server/active_listener_base.h" | ||
| #include "source/server/active_tcp_socket.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| // The base class of the stream listener. It owns the the active sockets that drive itself through | ||
| // the listener filters. After the active socket passes all the listener filters, a server | ||
|
lambdai marked this conversation as resolved.
Outdated
|
||
| // connection is created. The derived listener must override ``newActiveConnection`` to take the | ||
| // ownership of that server connection. | ||
| class ActiveStreamListenerBase : public ActiveListenerImplBase, | ||
| protected Logger::Loggable<Logger::Id::conn_handler> { | ||
| public: | ||
| ActiveStreamListenerBase(Network::ConnectionHandler& parent, Event::Dispatcher& dispatcher, | ||
| Network::ListenerPtr&& listener, Network::ListenerConfig& config); | ||
| static void emitLogs(Network::ListenerConfig& config, StreamInfo::StreamInfo& stream_info); | ||
|
|
||
| Event::Dispatcher& dispatcher() { return dispatcher_; } | ||
|
|
||
| /** | ||
| * Schedule to remove and destroy the active connections which are not tracked by listener | ||
| * config. Caution: The connection are not destroyed yet when function returns. | ||
| */ | ||
| void | ||
| deferredRemoveFilterChains(const std::list<const Network::FilterChain*>& draining_filter_chains) { | ||
| // Need to recover the original deleting state. | ||
| const bool was_deleting = is_deleting_; | ||
| is_deleting_ = true; | ||
| for (const auto* filter_chain : draining_filter_chains) { | ||
| deferRemoveFilterChain(filter_chain); | ||
| } | ||
| is_deleting_ = was_deleting; | ||
| } | ||
|
|
||
| virtual void incNumConnections() PURE; | ||
| virtual void decNumConnections() PURE; | ||
|
|
||
| /** | ||
| * Create a new connection from a socket accepted by the listener. | ||
| */ | ||
| void newConnection(Network::ConnectionSocketPtr&& socket, | ||
| std::unique_ptr<StreamInfo::StreamInfo> stream_info); | ||
| /** | ||
| * Schedule to remove and destroy the active connections owned by the filter chain. | ||
| */ | ||
| virtual void deferRemoveFilterChain(const Network::FilterChain* filter_chain) PURE; | ||
|
|
||
| virtual Network::BalancedConnectionHandlerOptRef | ||
| getBalancedHandlerByAddress(const Network::Address::Instance& address) PURE; | ||
|
|
||
| void onSocketAccepted(std::unique_ptr<ActiveTcpSocket> active_socket) { | ||
| // Create and run the filters | ||
| config_->filterChainFactory().createListenerFilterChain(*active_socket); | ||
| active_socket->continueFilterChain(true); | ||
|
|
||
| // Move active_socket to the sockets_ list if filter iteration needs to continue later. | ||
| // Otherwise we let active_socket be destructed when it goes out of scope. | ||
| if (active_socket->iter_ != active_socket->accept_filters_.end()) { | ||
| active_socket->startTimer(); | ||
| LinkedList::moveIntoListBack(std::move(active_socket), sockets_); | ||
| } else { | ||
| if (!active_socket->connected_) { | ||
| // If active_socket is about to be destructed, emit logs if a connection is not created. | ||
| if (active_socket->stream_info_ != nullptr) { | ||
| emitLogs(*config_, *active_socket->stream_info_); | ||
| } else { | ||
| // If the active_socket is not connected, this socket is not promoted to active | ||
| // connection. Thus the stream_info_ is owned by this active socket. | ||
| ENVOY_BUG(active_socket->stream_info_ != nullptr, | ||
| "the unconnected active socket must have stream info."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Below members are open to access by ActiveTcpSocket. | ||
| Network::ConnectionHandler& parent_; | ||
| const std::chrono::milliseconds listener_filters_timeout_; | ||
| const bool continue_on_listener_filters_timeout_; | ||
| std::list<std::unique_ptr<ActiveTcpSocket>> sockets_; | ||
|
lambdai marked this conversation as resolved.
Outdated
|
||
|
|
||
| protected: | ||
| /** | ||
| * Create the active connection from server connection. This active listener owns the created | ||
| * active connection. | ||
| * | ||
| * @param filter_chain The network filter chain linking to the connection. | ||
| * @param server_conn_ptr The server connection. | ||
| * @param stream_info The stream info of the active connection. | ||
| */ | ||
| virtual void newActiveConnection(const Network::FilterChain& filter_chain, | ||
| Network::ServerConnectionPtr server_conn_ptr, | ||
| std::unique_ptr<StreamInfo::StreamInfo> stream_info) PURE; | ||
| Event::Dispatcher& dispatcher_; | ||
|
lambdai marked this conversation as resolved.
Outdated
|
||
| Network::ListenerPtr listener_; | ||
| bool is_deleting_{false}; | ||
|
lambdai marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.