-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[mobile]Create a real dummy socket option to manage network type hashing #38099
Merged
Merged
Changes from 4 commits
Commits
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 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 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
42 changes: 42 additions & 0 deletions
42
mobile/library/common/network/network_type_socket_option_impl.cc
This file contains 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,42 @@ | ||
#include "library/common/network/network_type_socket_option_impl.h" | ||
|
||
#include "envoy/config/core/v3/base.pb.h" | ||
#include "envoy/network/socket.h" | ||
|
||
#include "source/common/common/scalar_to_byte_vector.h" | ||
|
||
#include "absl/types/optional.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
||
NetworkTypeSocketOptionImpl::NetworkTypeSocketOptionImpl(int network_type) | ||
: optname_(0, 0, "network_type"), network_type_(network_type) {} | ||
|
||
bool NetworkTypeSocketOptionImpl::setOption( | ||
Socket& /*socket*/, envoy::config::core::v3::SocketOption::SocketState /*state*/) const { | ||
return true; | ||
} | ||
|
||
void NetworkTypeSocketOptionImpl::hashKey(std::vector<uint8_t>& hash_key) const { | ||
pushScalarToByteVector(network_type_, hash_key); | ||
} | ||
|
||
absl::optional<Socket::Option::Details> NetworkTypeSocketOptionImpl::getOptionDetails( | ||
const Socket&, envoy::config::core::v3::SocketOption::SocketState /*state*/) const { | ||
if (!isSupported()) { | ||
return absl::nullopt; | ||
} | ||
|
||
Socket::Option::Details details; | ||
details.name_ = optname_; | ||
std::vector<uint8_t> data; | ||
pushScalarToByteVector(network_type_, data); | ||
details.value_ = std::string(reinterpret_cast<char*>(data.data()), data.size()); | ||
return absl::make_optional(std::move(details)); | ||
} | ||
|
||
bool NetworkTypeSocketOptionImpl::isSupported() const { return optname_.hasValue(); } | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
36 changes: 36 additions & 0 deletions
36
mobile/library/common/network/network_type_socket_option_impl.h
This file contains 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,36 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/core/v3/base.pb.h" | ||
#include "envoy/network/socket.h" | ||
|
||
#include "absl/types/optional.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
||
/** | ||
* This is a "dummy" socket option implementation, which does not actually | ||
* set any socket option, but rather applies a network type tag to the socket so that requests from | ||
* different network types gets hashed to different connections. | ||
*/ | ||
class NetworkTypeSocketOptionImpl : public Network::Socket::Option { | ||
public: | ||
NetworkTypeSocketOptionImpl(int network_type); | ||
|
||
// Socket::Option | ||
bool setOption(Network::Socket& socket, | ||
envoy::config::core::v3::SocketOption::SocketState state) const override; | ||
void hashKey(std::vector<uint8_t>& hash_key) const override; | ||
absl::optional<Details> | ||
getOptionDetails(const Network::Socket& socket, | ||
envoy::config::core::v3::SocketOption::SocketState state) const override; | ||
bool isSupported() const override; | ||
|
||
private: | ||
const Network::SocketOptionName optname_; | ||
|
||
int network_type_; | ||
}; | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that
optname_
appears to be const, does this method always return true?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I was cargo culting the socket tagging code.
Now it fixed. It should always return true.