Skip to content
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

network: rename SocketAddressProvider as ConnectionInfoProvider #17717

Merged
merged 4 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions envoy/network/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class Connection : public Event::DeferredDeletable,
/**
* @return the address provider backing this connection.
*/
virtual const SocketAddressProvider& addressProvider() const PURE;
virtual SocketAddressProviderSharedPtr addressProviderSharedPtr() const PURE;
virtual const ConnectionInfoProvider& addressProvider() const PURE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your plan is to rename the function name and other things in follow ups, right?

/wait-any

Copy link
Member Author

@soulxu soulxu Aug 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if we do that in one pr, it will be thousand lines. It is hard to review #17717 (comment)

I will have one PR for rename the function name, and another PR for rename the variable name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sounds good, thanks.

virtual ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const PURE;

/**
* Credentials of the peer of a socket as decided by SO_PEERCRED.
Expand Down
18 changes: 9 additions & 9 deletions envoy/network/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct SocketOptionName {
* TODO(soulxu): Since there are more than address information inside the provider, this will be
* renamed as ConnectionInfoProvider. Ref https://github.com/envoyproxy/envoy/issues/17168
*/
class SocketAddressProvider {
class ConnectionInfoProvider {
public:
virtual ~SocketAddressProvider() = default;
virtual ~ConnectionInfoProvider() = default;

/**
* @return the local address of the socket.
Expand Down Expand Up @@ -87,7 +87,7 @@ class SocketAddressProvider {
virtual absl::optional<uint64_t> connectionID() const PURE;

/**
* Dumps the state of the SocketAddressProvider to the given ostream.
* Dumps the state of the ConnectionInfoProvider to the given ostream.
*
* @param os the std::ostream to dump to.
* @param indent_level the level of indentation.
Expand All @@ -101,7 +101,7 @@ class SocketAddressProvider {
virtual Ssl::ConnectionInfoConstSharedPtr sslConnection() const PURE;
};

class SocketAddressSetter : public SocketAddressProvider {
class ConnectionInfoSetter : public ConnectionInfoProvider {
public:
/**
* Set the local address of the socket. On accepted sockets the local address defaults to the
Expand Down Expand Up @@ -145,8 +145,8 @@ class SocketAddressSetter : public SocketAddressProvider {
virtual void setSslConnection(const Ssl::ConnectionInfoConstSharedPtr& ssl_connection_info) PURE;
};

using SocketAddressSetterSharedPtr = std::shared_ptr<SocketAddressSetter>;
using SocketAddressProviderSharedPtr = std::shared_ptr<const SocketAddressProvider>;
using ConnectionInfoSetterSharedPtr = std::shared_ptr<ConnectionInfoSetter>;
using ConnectionInfoProviderSharedPtr = std::shared_ptr<const ConnectionInfoProvider>;

/**
* Base class for Sockets
Expand All @@ -163,9 +163,9 @@ class Socket {
/**
* @return the address provider backing this socket.
*/
virtual SocketAddressSetter& addressProvider() PURE;
virtual const SocketAddressProvider& addressProvider() const PURE;
virtual SocketAddressProviderSharedPtr addressProviderSharedPtr() const PURE;
virtual ConnectionInfoSetter& addressProvider() PURE;
virtual const ConnectionInfoProvider& addressProvider() const PURE;
virtual ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const PURE;

/**
* @return IoHandle for the underlying connection
Expand Down
2 changes: 1 addition & 1 deletion envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class StreamInfo {
/**
* @return the downstream address provider.
*/
virtual const Network::SocketAddressProvider& downstreamAddressProvider() const PURE;
virtual const Network::ConnectionInfoProvider& downstreamAddressProvider() const PURE;

/**
* @param connection_info sets the upstream ssl connection.
Expand Down
16 changes: 9 additions & 7 deletions source/common/http/filter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,11 @@ class FilterManagerCallbacks {
/**
* This class allows the remote address to be overridden for HTTP stream info. This is used for
* XFF handling. This is required to avoid providing stream info with a non-const address provider.
* Private inheritance from SocketAddressProvider is used to make sure users get the address
* Private inheritance from ConnectionInfoProvider is used to make sure users get the address
* provider via the normal getter.
*/
class OverridableRemoteSocketAddressSetterStreamInfo : public StreamInfo::StreamInfoImpl,
private Network::SocketAddressProvider {
class OverridableRemoteConnectionInfoSetterStreamInfo : public StreamInfo::StreamInfoImpl,
private Network::ConnectionInfoProvider {
public:
using StreamInfoImpl::StreamInfoImpl;

Expand All @@ -603,9 +603,11 @@ class OverridableRemoteSocketAddressSetterStreamInfo : public StreamInfo::Stream
}

// StreamInfo::StreamInfo
const Network::SocketAddressProvider& downstreamAddressProvider() const override { return *this; }
const Network::ConnectionInfoProvider& downstreamAddressProvider() const override {
return *this;
}

// Network::SocketAddressProvider
// Network::ConnectionInfoProvider
const Network::Address::InstanceConstSharedPtr& localAddress() const override {
return StreamInfoImpl::downstreamAddressProvider().localAddress();
}
Expand Down Expand Up @@ -636,7 +638,7 @@ class OverridableRemoteSocketAddressSetterStreamInfo : public StreamInfo::Stream
StreamInfoImpl::dumpState(os, indent_level);

const char* spaces = spacesForLevel(indent_level);
os << spaces << "OverridableRemoteSocketAddressSetterStreamInfo " << this
os << spaces << "OverridableRemoteConnectionInfoSetterStreamInfo " << this
<< DUMP_MEMBER_AS(remoteAddress(), remoteAddress()->asStringView())
<< DUMP_MEMBER_AS(directRemoteAddress(), directRemoteAddress()->asStringView())
<< DUMP_MEMBER_AS(localAddress(), localAddress()->asStringView()) << "\n";
Expand Down Expand Up @@ -1025,7 +1027,7 @@ class FilterManager : public ScopeTrackedObject,

FilterChainFactory& filter_chain_factory_;
const LocalReply::LocalReply& local_reply_;
OverridableRemoteSocketAddressSetterStreamInfo stream_info_;
OverridableRemoteConnectionInfoSetterStreamInfo stream_info_;
// TODO(snowp): Once FM has been moved to its own file we'll make these private classes of FM,
// at which point they no longer need to be friends.
friend ActiveStreamFilterBase;
Expand Down
4 changes: 2 additions & 2 deletions source/common/network/connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class ConnectionImpl : public ConnectionImplBase, public TransportSocketCallback
void readDisable(bool disable) override;
void detectEarlyCloseWhenReadDisabled(bool value) override { detect_early_close_ = value; }
bool readEnabled() const override;
const SocketAddressProvider& addressProvider() const override {
const ConnectionInfoProvider& addressProvider() const override {
return socket_->addressProvider();
}
SocketAddressProviderSharedPtr addressProviderSharedPtr() const override {
ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const override {
return socket_->addressProviderSharedPtr();
}
absl::optional<UnixDomainSocketPeerCredentials> unixSocketPeerCredentials() const override;
Expand Down
4 changes: 2 additions & 2 deletions source/common/network/happy_eyeballs_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ bool HappyEyeballsConnectionImpl::readEnabled() const {
return connections_[0]->readEnabled();
}

const SocketAddressProvider& HappyEyeballsConnectionImpl::addressProvider() const {
const ConnectionInfoProvider& HappyEyeballsConnectionImpl::addressProvider() const {
return connections_[0]->addressProvider();
}

SocketAddressProviderSharedPtr HappyEyeballsConnectionImpl::addressProviderSharedPtr() const {
ConnectionInfoProviderSharedPtr HappyEyeballsConnectionImpl::addressProviderSharedPtr() const {
return connections_[0]->addressProviderSharedPtr();
}

Expand Down
4 changes: 2 additions & 2 deletions source/common/network/happy_eyeballs_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class HappyEyeballsConnectionImpl : public ClientConnection {
bool isHalfCloseEnabled() override;
std::string nextProtocol() const override;
// Note, this might change before connect finishes.
const SocketAddressProvider& addressProvider() const override;
const ConnectionInfoProvider& addressProvider() const override;
// Note, this might change before connect finishes.
SocketAddressProviderSharedPtr addressProviderSharedPtr() const override;
ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const override;
// Note, this might change before connect finishes.
absl::optional<UnixDomainSocketPeerCredentials> unixSocketPeerCredentials() const override;
// Note, this might change before connect finishes.
Expand Down
4 changes: 2 additions & 2 deletions source/common/network/socket_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ SocketImpl::SocketImpl(Socket::Type sock_type,
const Address::InstanceConstSharedPtr& address_for_io_handle,
const Address::InstanceConstSharedPtr& remote_address)
: io_handle_(ioHandleForAddr(sock_type, address_for_io_handle)),
address_provider_(std::make_shared<SocketAddressSetterImpl>(nullptr, remote_address)),
address_provider_(std::make_shared<ConnectionInfoSetterImpl>(nullptr, remote_address)),
sock_type_(sock_type), addr_type_(address_for_io_handle->type()) {}

SocketImpl::SocketImpl(IoHandlePtr&& io_handle,
const Address::InstanceConstSharedPtr& local_address,
const Address::InstanceConstSharedPtr& remote_address)
: io_handle_(std::move(io_handle)),
address_provider_(std::make_shared<SocketAddressSetterImpl>(local_address, remote_address)) {
address_provider_(std::make_shared<ConnectionInfoSetterImpl>(local_address, remote_address)) {

if (address_provider_->localAddress() != nullptr) {
addr_type_ = address_provider_->localAddress()->type();
Expand Down
18 changes: 9 additions & 9 deletions source/common/network/socket_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace Envoy {
namespace Network {

class SocketAddressSetterImpl : public SocketAddressSetter {
class ConnectionInfoSetterImpl : public ConnectionInfoSetter {
public:
SocketAddressSetterImpl(const Address::InstanceConstSharedPtr& local_address,
const Address::InstanceConstSharedPtr& remote_address)
ConnectionInfoSetterImpl(const Address::InstanceConstSharedPtr& local_address,
const Address::InstanceConstSharedPtr& remote_address)
: local_address_(local_address), remote_address_(remote_address),
direct_remote_address_(remote_address) {}

Expand All @@ -21,14 +21,14 @@ class SocketAddressSetterImpl : public SocketAddressSetter {

void dumpState(std::ostream& os, int indent_level) const override {
const char* spaces = spacesForLevel(indent_level);
os << spaces << "SocketAddressSetterImpl " << this
os << spaces << "ConnectionInfoSetterImpl " << this
<< DUMP_NULLABLE_MEMBER(remote_address_, remote_address_->asStringView())
<< DUMP_NULLABLE_MEMBER(direct_remote_address_, direct_remote_address_->asStringView())
<< DUMP_NULLABLE_MEMBER(local_address_, local_address_->asStringView())
<< DUMP_MEMBER(server_name_) << "\n";
}

// SocketAddressSetter
// ConnectionInfoSetter
const Address::InstanceConstSharedPtr& localAddress() const override { return local_address_; }
void setLocalAddress(const Address::InstanceConstSharedPtr& local_address) override {
local_address_ = local_address;
Expand Down Expand Up @@ -72,9 +72,9 @@ class SocketImpl : public virtual Socket {
const Address::InstanceConstSharedPtr& remote_address);

// Network::Socket
SocketAddressSetter& addressProvider() override { return *address_provider_; }
const SocketAddressProvider& addressProvider() const override { return *address_provider_; }
SocketAddressProviderSharedPtr addressProviderSharedPtr() const override {
ConnectionInfoSetter& addressProvider() override { return *address_provider_; }
const ConnectionInfoProvider& addressProvider() const override { return *address_provider_; }
ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const override {
return address_provider_;
}
SocketPtr duplicate() override {
Expand Down Expand Up @@ -128,7 +128,7 @@ class SocketImpl : public virtual Socket {
const Address::InstanceConstSharedPtr& remote_address);

const IoHandlePtr io_handle_;
const std::shared_ptr<SocketAddressSetterImpl> address_provider_;
const std::shared_ptr<ConnectionInfoSetterImpl> address_provider_;
OptionsSharedPtr options_;
Socket::Type sock_type_;
Address::Type addr_type_;
Expand Down
4 changes: 2 additions & 2 deletions source/common/quic/quic_filter_manager_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class QuicFilterManagerConnectionImpl : public Network::ConnectionImplBase,
void readDisable(bool /*disable*/) override { ASSERT(false); }
void detectEarlyCloseWhenReadDisabled(bool /*value*/) override { ASSERT(false); }
bool readEnabled() const override { return true; }
const Network::SocketAddressSetter& addressProvider() const override {
const Network::ConnectionInfoSetter& addressProvider() const override {
return network_connection_->connectionSocket()->addressProvider();
}
Network::SocketAddressProviderSharedPtr addressProviderSharedPtr() const override {
Network::ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const override {
return network_connection_->connectionSocket()->addressProviderSharedPtr();
}
absl::optional<Network::Connection::UnixDomainSocketPeerCredentials>
Expand Down
18 changes: 9 additions & 9 deletions source/common/stream_info/stream_info_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ const ReplacementMap& emptySpaceReplacement() {

struct StreamInfoImpl : public StreamInfo {
StreamInfoImpl(TimeSource& time_source,
const Network::SocketAddressProviderSharedPtr& downstream_address_provider,
const Network::ConnectionInfoProviderSharedPtr& downstream_address_provider,
FilterState::LifeSpan life_span = FilterState::LifeSpan::FilterChain)
: StreamInfoImpl(absl::nullopt, time_source, downstream_address_provider,
std::make_shared<FilterStateImpl>(life_span)) {}

StreamInfoImpl(Http::Protocol protocol, TimeSource& time_source,
const Network::SocketAddressProviderSharedPtr& downstream_address_provider)
const Network::ConnectionInfoProviderSharedPtr& downstream_address_provider)
: StreamInfoImpl(protocol, time_source, downstream_address_provider,
std::make_shared<FilterStateImpl>(FilterState::LifeSpan::FilterChain)) {}

StreamInfoImpl(Http::Protocol protocol, TimeSource& time_source,
const Network::SocketAddressProviderSharedPtr& downstream_address_provider,
const Network::ConnectionInfoProviderSharedPtr& downstream_address_provider,
FilterStateSharedPtr parent_filter_state, FilterState::LifeSpan life_span)
: StreamInfoImpl(
protocol, time_source, downstream_address_provider,
Expand Down Expand Up @@ -197,7 +197,7 @@ struct StreamInfoImpl : public StreamInfo {

void healthCheck(bool is_health_check) override { health_check_request_ = is_health_check; }

const Network::SocketAddressProvider& downstreamAddressProvider() const override {
const Network::ConnectionInfoProvider& downstreamAddressProvider() const override {
return *downstream_address_provider_;
}

Expand Down Expand Up @@ -305,14 +305,14 @@ struct StreamInfoImpl : public StreamInfo {
absl::optional<uint32_t> attempt_count_;

private:
static Network::SocketAddressProviderSharedPtr emptyDownstreamAddressProvider() {
static Network::ConnectionInfoProviderSharedPtr emptyDownstreamAddressProvider() {
MUTABLE_CONSTRUCT_ON_FIRST_USE(
Network::SocketAddressProviderSharedPtr,
std::make_shared<Network::SocketAddressSetterImpl>(nullptr, nullptr));
Network::ConnectionInfoProviderSharedPtr,
std::make_shared<Network::ConnectionInfoSetterImpl>(nullptr, nullptr));
}

StreamInfoImpl(absl::optional<Http::Protocol> protocol, TimeSource& time_source,
const Network::SocketAddressProviderSharedPtr& downstream_address_provider,
const Network::ConnectionInfoProviderSharedPtr& downstream_address_provider,
FilterStateSharedPtr filter_state)
: time_source_(time_source), start_time_(time_source.systemTime()),
start_time_monotonic_(time_source.monotonicTime()), protocol_(protocol),
Expand All @@ -325,7 +325,7 @@ struct StreamInfoImpl : public StreamInfo {
uint64_t bytes_received_{};
uint64_t bytes_sent_{};
Network::Address::InstanceConstSharedPtr upstream_local_address_;
const Network::SocketAddressProviderSharedPtr downstream_address_provider_;
const Network::ConnectionInfoProviderSharedPtr downstream_address_provider_;
Ssl::ConnectionInfoConstSharedPtr upstream_ssl_info_;
std::string requested_server_name_;
const Http::RequestHeaderMap* request_headers_{};
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/health_checker_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ HttpHealthCheckerImpl::HttpActiveHealthCheckSession::HttpActiveHealthCheckSessio
: ActiveHealthCheckSession(parent, host), parent_(parent),
hostname_(getHostname(host, parent_.host_value_, parent_.cluster_.info())),
protocol_(codecClientTypeToProtocol(parent_.codec_client_type_)),
local_address_provider_(std::make_shared<Network::SocketAddressSetterImpl>(
local_address_provider_(std::make_shared<Network::ConnectionInfoSetterImpl>(
Network::Utility::getCanonicalIpv4LoopbackAddress(),
Network::Utility::getCanonicalIpv4LoopbackAddress())) {}

Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/health_checker_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class HttpHealthCheckerImpl : public HealthCheckerImplBase {
Http::ResponseHeaderMapPtr response_headers_;
const std::string& hostname_;
const Http::Protocol protocol_;
Network::SocketAddressProviderSharedPtr local_address_provider_;
Network::ConnectionInfoProviderSharedPtr local_address_provider_;
bool expect_reset_{};
bool reuse_connection_ = false;
bool request_in_flight_ = false;
Expand Down
8 changes: 4 additions & 4 deletions source/server/api_listener_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ApiListenerImplBase : public ApiListener,
class SyntheticConnection : public Network::Connection {
public:
SyntheticConnection(SyntheticReadCallbacks& parent)
: parent_(parent), address_provider_(std::make_shared<Network::SocketAddressSetterImpl>(
: parent_(parent), address_provider_(std::make_shared<Network::ConnectionInfoSetterImpl>(
parent.parent_.address_, parent.parent_.address_)),
stream_info_(parent_.parent_.factory_context_.timeSource(), address_provider_),
options_(std::make_shared<std::vector<Network::Socket::OptionConstSharedPtr>>()) {}
Expand Down Expand Up @@ -120,10 +120,10 @@ class ApiListenerImplBase : public ApiListener,
void readDisable(bool) override {}
void detectEarlyCloseWhenReadDisabled(bool) override { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; }
bool readEnabled() const override { return true; }
const Network::SocketAddressSetter& addressProvider() const override {
const Network::ConnectionInfoSetter& addressProvider() const override {
return *address_provider_;
}
Network::SocketAddressProviderSharedPtr addressProviderSharedPtr() const override {
Network::ConnectionInfoProviderSharedPtr addressProviderSharedPtr() const override {
return address_provider_;
}
absl::optional<Network::Connection::UnixDomainSocketPeerCredentials>
Expand Down Expand Up @@ -152,7 +152,7 @@ class ApiListenerImplBase : public ApiListener,
void dumpState(std::ostream& os, int) const override { os << "SyntheticConnection"; }

SyntheticReadCallbacks& parent_;
Network::SocketAddressSetterSharedPtr address_provider_;
Network::ConnectionInfoSetterSharedPtr address_provider_;
StreamInfo::StreamInfoImpl stream_info_;
Network::ConnectionSocket::OptionsSharedPtr options_;
std::list<Network::ConnectionCallbacks*> callbacks_;
Expand Down
2 changes: 1 addition & 1 deletion test/common/grpc/async_client_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST_F(EnvoyAsyncClientImplTest, MetadataIsInitialized) {
.WillOnce(Invoke([&http_callbacks](Http::HeaderMap&, bool) { http_callbacks->onReset(); }));

// Prepare the parent context of this call.
auto address_provider = std::make_shared<Network::SocketAddressSetterImpl>(
auto address_provider = std::make_shared<Network::ConnectionInfoSetterImpl>(
std::make_shared<Network::Address::Ipv4Instance>(expected_downstream_local_address), nullptr);
StreamInfo::StreamInfoImpl stream_info{test_time_.timeSystem(), address_provider};
Http::AsyncClient::ParentContext parent_context{&stream_info};
Expand Down
2 changes: 1 addition & 1 deletion test/common/grpc/google_async_client_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ TEST_F(EnvoyGoogleAsyncClientImplTest, MetadataIsInitialized) {
EXPECT_CALL(grpc_callbacks, onRemoteClose(Status::WellKnownGrpcStatus::Unavailable, ""));

// Prepare the parent context of this call.
auto address_provider = std::make_shared<Network::SocketAddressSetterImpl>(
auto address_provider = std::make_shared<Network::ConnectionInfoSetterImpl>(
std::make_shared<Network::Address::Ipv4Instance>(expected_downstream_local_address), nullptr);
StreamInfo::StreamInfoImpl stream_info{test_time_.timeSystem(), address_provider};
Http::AsyncClient::ParentContext parent_context{&stream_info};
Expand Down
Loading