-
Notifications
You must be signed in to change notification settings - Fork 5.5k
dispatcher: add the client connection factory to support connecting to internal listener #18105
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c00cc79
wip
lambdai e037f8e
stash client conn fac
lambdai 9ede26a
make it build
lambdai 14ae9dc
format
lambdai 3758571
adding int conn factory test
lambdai ac32344
basic internal connection factory test
lambdai d8907d1
Merge branch 'main' into privintfactory
lambdai 3eb8f16
add default client connection factory
lambdai b94abcb
adding getFactoryByAddressType
lambdai 85e3a73
Revert "adding getFactoryByAddressType"
lambdai 2adc021
client connection factory follows UntypedFactory
lambdai c22906c
Merge branch 'main' into privintfactory
lambdai bcb375b
fix after merge
lambdai 83c193d
fix gcc switch enum
lambdai a932479
clang-tidy and better name
lambdai a42efa6
renaming
lambdai 4caa42b
tidy
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
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 @@ | ||
| // NOLINT(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,26 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/network/address.h" | ||
| #include "envoy/network/connection.h" | ||
| #include "envoy/network/listen_socket.h" | ||
| #include "envoy/network/transport_socket.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| class ClientConnectionFactory { | ||
|
lambdai marked this conversation as resolved.
Outdated
|
||
| public: | ||
| virtual ~ClientConnectionFactory() = default; | ||
| std::string category() { return "network.connection"; } | ||
| virtual std::string name() PURE; | ||
|
|
||
| virtual Network::ClientConnectionPtr | ||
| createClientConnection(Event::Dispatcher& dispatcher, | ||
| Network::Address::InstanceConstSharedPtr address, | ||
| Network::Address::InstanceConstSharedPtr source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options) PURE; | ||
| }; | ||
|
|
||
| } // namespace Network | ||
| } // 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
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
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
70 changes: 70 additions & 0 deletions
70
source/extensions/io_socket/user_space/client_connection_factory.cc
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,70 @@ | ||
| #include "source/extensions/io_socket/user_space/client_connection_factory.h" | ||
|
|
||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "source/common/network/address_impl.h" | ||
| #include "source/common/network/connection_impl.h" | ||
| #include "source/common/network/listen_socket_impl.h" | ||
| #include "source/extensions/io_socket/user_space/io_handle_impl.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
||
| namespace Extensions { | ||
| namespace IoSocket { | ||
| namespace UserSpace { | ||
|
|
||
| Network::ClientConnectionPtr InternalClientConnectionFactory::createClientConnection( | ||
| Event::Dispatcher& dispatcher, Network::Address::InstanceConstSharedPtr address, | ||
| Network::Address::InstanceConstSharedPtr source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options) { | ||
|
|
||
| Network::IoHandlePtr io_handle_client; | ||
| Network::IoHandlePtr io_handle_server; | ||
|
|
||
| std::tie(io_handle_client, io_handle_server) = | ||
| Extensions::IoSocket::UserSpace::IoHandleFactory::createIoHandlePair(); | ||
|
|
||
| auto client_conn = std::make_unique<Network::ClientConnectionImpl>( | ||
| dispatcher, | ||
| std::make_unique<Network::ConnectionSocketImpl>(std::move(io_handle_client), source_address, | ||
| address), | ||
| source_address, std::move(transport_socket), options); | ||
| // TODO(lambdai): refactor nested if. | ||
| auto internal_listener_manager = dispatcher.getInternalListenerManager(); | ||
| if (internal_listener_manager.has_value()) { | ||
| // It's either in main thread or the worker is not yet started. | ||
| auto internal_listener = internal_listener_manager.value().get().findByAddress(address); | ||
| if (internal_listener.has_value()) { | ||
| auto original_address = address; | ||
| // if (options != nullptr) { | ||
| // for (const auto& opt : *options) { | ||
| // auto* internal_opt = dynamic_cast<const Network::InternalSocketOptionImpl*>(opt.get()); | ||
| // if (internal_opt != nullptr) { | ||
| // original_address = internal_opt->original_remote_address_; | ||
| // } | ||
| // } | ||
| // } | ||
| auto accepted_socket = std::make_unique<Network::AcceptedSocketImpl>( | ||
| std::move(io_handle_server), original_address, source_address); | ||
| // TODO: also check if disabled | ||
| internal_listener.value().get().onAccept(std::move(accepted_socket)); | ||
| FANCY_LOG(debug, "lambdai: find internal listener {} ", address->asStringView()); | ||
| } else { | ||
| FANCY_LOG(debug, "lambdai: cannot find internal listener {} ", address->asStringView()); | ||
| // injected error into client_conn; | ||
| io_handle_server->close(); | ||
| } | ||
| } else { | ||
| FANCY_LOG(debug, "lambdai: cannot find internal listener {} ", address->asStringView()); | ||
| // injected error into client_conn; | ||
| io_handle_server->close(); | ||
| } | ||
| return client_conn; | ||
| } | ||
| REGISTER_FACTORY(InternalClientConnectionFactory, Network::ClientConnectionFactory); | ||
|
|
||
| } // namespace UserSpace | ||
| } // namespace IoSocket | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
30 changes: 30 additions & 0 deletions
30
source/extensions/io_socket/user_space/client_connection_factory.h
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,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
| #include "envoy/network/client_connection_manager.h" | ||
| #include "envoy/network/connection.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
||
| namespace Extensions { | ||
| namespace IoSocket { | ||
| namespace UserSpace { | ||
|
|
||
| class InternalClientConnectionFactory : public Network::ClientConnectionFactory { | ||
| public: | ||
| std::string name() override { return "EnvoyInternal"; } | ||
| Network::ClientConnectionPtr | ||
| createClientConnection(Event::Dispatcher& dispatcher, | ||
| Network::Address::InstanceConstSharedPtr address, | ||
| Network::Address::InstanceConstSharedPtr source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options) override; | ||
| }; | ||
|
|
||
| } // namespace UserSpace | ||
| } // namespace IoSocket | ||
| } // namespace Extensions | ||
| } // 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
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
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.