Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
Browse files Browse the repository at this point in the history
* origin/main:
  Update Envoy (#2403)
  connectivity_manager: rename/refactor from Network::Configurator (#2401)
  test: fixing up build targets to use the extension registry (#2397)
  test: Adds an integration test for SDS (#2395)
  iOS: add `forceIPv6(...)` builder option (#2396)
  api: make iOS Headers and HeadersBuilder case-insensitive (#2383)

Signed-off-by: JP Simard <[email protected]>
  • Loading branch information
jpsim committed Jul 5, 2022
2 parents 4add65d + 2cb23aa commit 586bdad
Show file tree
Hide file tree
Showing 67 changed files with 1,168 additions and 609 deletions.
16 changes: 16 additions & 0 deletions docs/root/api/starting_envoy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ SharedPreferences.
// Coming soon.


~~~~~~~~~~~~~~~~~~~~~~~~~~
``forceIPv6``
~~~~~~~~~~~~~~~~~~~~~~~~~~

Specify whether to remap IPv4 addresses to the IPv6 space and always force connections
to use IPv6. Note this is an experimental option and should be enabled with caution.

**Example**::

// Kotlin
builder.forceIPv6(true)

// Swift
builder.forceIPv6(true)


----------------------
Advanced configuration
----------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Breaking changes:

- api: replace the ``drainConnections()`` method with a broader ``resetConnectivityState()``. (:issue:`#2225 <2225>`).
- api: disallow setting 'host' header directly (:issue:`#2275 <2275>`)
- api: add experimental option to force all connections to use IPv6 (:issue: `#2379 <2379>`, :issue: `#2396 <2396>`)
- android: respect Android's NetworkSecurityPolicy isCleartextTrafficPermitted APIs.
- android: add experimental option to force all connections to use IPv6 (:issue: `#2379 <2379>`)
- net: enable happy eyeballs by default (:issue:`#2272 <2272>`)
- iOS: remove support for installing via CocoaPods, which had not worked since 2020 (:issue:`#2215 <2215>`)
- iOS: enable usage of ``NWPathMonitor`` by default (:issue:`#2329 <2329>`)
Expand All @@ -24,6 +24,7 @@ Bugfixes:
- Android: update Kotlin standard libraries to 1.6.21 (:issue:`#2256 <2256>`)
- fix bug where finalStreamIntel was not consistently set on cancel (:issue:`#2285 <2285>`)
- iOS: fix termination crash in ProvisionalDispatcher (:issue:`#2059 <2059>`)
- iOS: make headers lookup in ``HeadersBuilder`` and ``Headers`` case-insensitive. Rename ``allHeaders`` method to ``caseSensitiveHeaders``. (:issue:`#2383 <2383>`)
- iOS: use correct DNS resolver when using C++ config builder (:issue: `#2378 <2378 >`)

Features:
Expand Down
2 changes: 1 addition & 1 deletion envoy
Submodule envoy updated 137 files
4 changes: 2 additions & 2 deletions examples/objective-c/hello_world/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ - (void)performRequest {
NSString *message = [NSString stringWithFormat:@"received headers with status %i", statusCode];

NSMutableString *headerMessage = [NSMutableString new];
for (NSString *name in headers.allHeaders) {
for (NSString *name in headers.caseSensitiveHeaders) {
if ([self.filteredHeaders containsObject:name]) {
NSArray<NSString *> *values = headers.allHeaders[name];
NSArray<NSString *> *values = headers.caseSensitiveHeaders[name];
NSString *joined = [values componentsJoinedByString:@", "];
NSString *pair = [NSString stringWithFormat:@"%@: %@\n", name, joined];
[headerMessage appendString:pair];
Expand Down
10 changes: 3 additions & 7 deletions examples/swift/async_await/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ private extension StreamClient {
let stream = self
.newStreamPrototype()
.setOnResponseHeaders { headers, _, _ in
let allHeaders = headers.allHeaders()

if allHeaders[":status"]?.first == "200",
// TODO(jpsim): Expose an API that enforces case-insensitive lookups
let contentLengthValue = allHeaders["Content-Length"] ??
allHeaders["content-length"],
if headers.value(forName: ":status")?.first == "200",
let contentLengthValue = headers.value(forName: "content-length"),
let firstContentLength = contentLengthValue.first,
let contentLengthInt = Int64(firstContentLength)
{
Expand All @@ -87,7 +83,7 @@ private extension StreamClient {
return
}

let headerMessage = allHeaders
let headerMessage = headers.caseSensitiveHeaders()
.map { "\($0.key): \($0.value.joined(separator: ", "))" }
.joined(separator: "\n")

Expand Down
2 changes: 1 addition & 1 deletion examples/swift/hello_world/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class ViewController: UITableViewController {
let statusCode = headers.httpStatus.map(String.init) ?? "nil"
let message = "received headers with status \(statusCode)"

let headerMessage = headers.allHeaders()
let headerMessage = headers.caseSensitiveHeaders()
.filter { kFilteredHeaders.contains($0.key) }
.map { "\($0.key): \($0.value.joined(separator: ", "))" }
.joined(separator: "\n")
Expand Down
2 changes: 1 addition & 1 deletion library/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ envoy_cc_library(
"//library/common/event:provisional_dispatcher_lib",
"//library/common/http:client_lib",
"//library/common/http:header_utility_lib",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stats:utility_lib",
"//library/common/types:c_types_lib",
"@envoy//envoy/server:lifecycle_notifier_interface",
Expand Down
6 changes: 3 additions & 3 deletions library/common/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ const char* brotli_config_insert = R"(
// clang-format off
const std::string config_header = R"(
!ignore default_defs:
- &android_force_ipv6 false
- &connect_timeout 30s
- &dns_fail_base_interval 2s
- &dns_fail_max_interval 10s
- &dns_query_timeout 25s
- &dns_lookup_family ALL
- &dns_min_refresh_rate 60s
- &dns_multiple_addresses true
- &dns_preresolve_hostnames []
- &dns_query_timeout 25s
- &dns_refresh_rate 60s
- &force_ipv6 false
)"
#if defined(__APPLE__)
R"(- &dns_resolver_name envoy.network.dns_resolver.apple
Expand Down Expand Up @@ -514,7 +514,7 @@ stats_sinks: *stats_sinks
disallow_global_stats: true
reloadable_features:
allow_multiple_dns_addresses: *dns_multiple_addresses
android_always_use_v6: *android_force_ipv6
always_use_v6: *force_ipv6
http2_delay_keepalive_timeout: *h2_delay_keepalive_timeout
)"
// Needed due to warning in
Expand Down
16 changes: 8 additions & 8 deletions library/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve
Envoy::Server::ServerLifecycleNotifier::Stage::PostInit, [this]() -> void {
ASSERT(Thread::MainThread::isMainOrTestThread());

network_configurator_ =
Network::ConfiguratorFactory{server_->serverFactoryContext()}.get();
connectivity_manager_ =
Network::ConnectivityManagerFactory{server_->serverFactoryContext()}.get();
Envoy::Network::Android::Utility::setAlternateGetifaddrs();
auto v4_interfaces = network_configurator_->enumerateV4Interfaces();
auto v6_interfaces = network_configurator_->enumerateV6Interfaces();
auto v4_interfaces = connectivity_manager_->enumerateV4Interfaces();
auto v6_interfaces = connectivity_manager_->enumerateV6Interfaces();
logInterfaces("netconf_get_v4_interfaces", v4_interfaces);
logInterfaces("netconf_get_v6_interfaces", v6_interfaces);
client_scope_ = server_->serverFactoryContext().scope().createScope("pulse.");
Expand All @@ -141,7 +141,7 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve

// Ensure destructors run on Envoy's main thread.
postinit_callback_handler_.reset(nullptr);
network_configurator_.reset();
connectivity_manager_.reset();
client_scope_.reset();
stat_name_set_.reset();
main_common.reset(nullptr);
Expand Down Expand Up @@ -295,10 +295,10 @@ Http::Client& Engine::httpClient() {
return *http_client_;
}

Network::Configurator& Engine::networkConfigurator() {
Network::ConnectivityManager& Engine::networkConnectivityManager() {
RELEASE_ASSERT(dispatcher_->isThreadSafe(),
"networkConfigurator must be accessed from dispatcher's context");
return *network_configurator_;
"networkConnectivityManager must be accessed from dispatcher's context");
return *connectivity_manager_;
}

void Engine::flushStats() {
Expand Down
8 changes: 4 additions & 4 deletions library/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "library/common/common/lambda_logger_delegate.h"
#include "library/common/engine_common.h"
#include "library/common/http/client.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"
#include "library/common/types/c_types.h"

namespace Envoy {
Expand Down Expand Up @@ -58,9 +58,9 @@ class Engine : public Logger::Loggable<Logger::Id::main> {

/**
* Accessor for the network configuraator. Must be called from the dispatcher's context.
* @return Network::Configurator&, the network configurator.
* @return Network::ConnectivityManager&, the network connectivity_manager.
*/
Network::Configurator& networkConfigurator();
Network::ConnectivityManager& networkConnectivityManager();

/**
* Increment a counter with a given string of elements and by the given count.
Expand Down Expand Up @@ -145,7 +145,7 @@ class Engine : public Logger::Loggable<Logger::Id::main> {
Thread::MutexBasicLockable mutex_;
Thread::CondVar cv_;
Http::ClientPtr http_client_;
Network::ConfiguratorSharedPtr network_configurator_;
Network::ConnectivityManagerSharedPtr connectivity_manager_;
Event::ProvisionalDispatcherPtr dispatcher_;
// Used by the cerr logger to ensure logs don't overwrite each other.
absl::Mutex log_mutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ envoy_cc_extension(
deps = [
":filter_cc_proto",
"//library/common/http:internal_headers_lib",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stream_info:extra_stream_info_lib",
"//library/common/types:c_types_lib",
"@envoy//envoy/http:codes_interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Http::FilterFactoryCb NetworkConfigurationFilterFactory::createFilterFactoryFrom
proto_config,
const std::string&, Server::Configuration::FactoryContext& context) {

auto network_configurator = Network::ConfiguratorFactory{context}.get();
auto connectivity_manager = Network::ConnectivityManagerFactory{context}.get();
bool enable_drain_post_dns_refresh = proto_config.enable_drain_post_dns_refresh();
bool enable_interface_binding = proto_config.enable_interface_binding();

return [network_configurator, enable_drain_post_dns_refresh,
return [connectivity_manager, enable_drain_post_dns_refresh,
enable_interface_binding](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamFilter(std::make_shared<NetworkConfigurationFilter>(
network_configurator, enable_drain_post_dns_refresh, enable_interface_binding));
connectivity_manager, enable_drain_post_dns_refresh, enable_interface_binding));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ void NetworkConfigurationFilter::setDecoderFilterCallbacks(
StreamInfo::FilterState::StateType::Mutable, StreamInfo::FilterState::LifeSpan::Request);

auto options = std::make_shared<Network::Socket::Options>();
network_configurator_->setInterfaceBindingEnabled(enable_interface_binding_);
network_configurator_->setDrainPostDnsRefreshEnabled(enable_drain_post_dns_refresh_);
extra_stream_info_->configuration_key_ = network_configurator_->addUpstreamSocketOptions(options);
connectivity_manager_->setInterfaceBindingEnabled(enable_interface_binding_);
connectivity_manager_->setDrainPostDnsRefreshEnabled(enable_drain_post_dns_refresh_);
extra_stream_info_->configuration_key_ = connectivity_manager_->addUpstreamSocketOptions(options);
decoder_callbacks_->addUpstreamSocketOptions(options);
}

Http::FilterHeadersStatus NetworkConfigurationFilter::encodeHeaders(Http::ResponseHeaderMap&,
bool) {
ENVOY_LOG(debug, "NetworkConfigurationFilter::encodeHeaders");
// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions. Receiving headers from upstream always means some level of
// network transmission was successful, so we unconditionally set network_fault to false.
network_configurator_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions. Receiving headers from upstream always means some level
// of network transmission was successful, so we unconditionally set network_fault to false.
connectivity_manager_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
false /* network_fault */);

return Http::FilterHeadersStatus::Continue;
Expand All @@ -45,16 +45,16 @@ Http::LocalErrorStatus NetworkConfigurationFilter::onLocalReply(const LocalReply
// Envoy uses local replies to report various local errors, including networking failures (which
// Envoy Mobile later surfaces as errors). As a proxy for the many different types of network
// errors, this code interprets any local error where a stream received no bytes from the upstream
// as a network fault. This status is passed to the configurator below when we report network
// usage, where it may be factored into future socket configuration.
// as a network fault. This status is passed to the connectivity_manager below when we report
// network usage, where it may be factored into future socket configuration.
bool network_fault = !success_status && (!decoder_callbacks_->streamInfo().upstreamInfo() ||
!decoder_callbacks_->streamInfo()
.upstreamInfo()
->upstreamTiming()
.first_upstream_rx_byte_received_.has_value());
// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions.
network_configurator_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions.
connectivity_manager_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
network_fault);

return Http::LocalErrorStatus::ContinueAndResetStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "source/extensions/filters/http/common/pass_through_filter.h"

#include "library/common/extensions/filters/http/network_configuration/filter.pb.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"
#include "library/common/stream_info/extra_stream_info.h"
#include "library/common/types/c_types.h"

Expand All @@ -21,9 +21,9 @@ namespace NetworkConfiguration {
class NetworkConfigurationFilter final : public Http::PassThroughFilter,
public Logger::Loggable<Logger::Id::filter> {
public:
NetworkConfigurationFilter(Network::ConfiguratorSharedPtr network_configurator,
NetworkConfigurationFilter(Network::ConnectivityManagerSharedPtr connectivity_manager,
bool enable_drain_post_dns_refresh, bool enable_interface_binding)
: network_configurator_(network_configurator),
: connectivity_manager_(connectivity_manager),
extra_stream_info_(nullptr), // always set in setDecoderFilterCallbacks
enable_drain_post_dns_refresh_(enable_drain_post_dns_refresh),
enable_interface_binding_(enable_interface_binding) {}
Expand All @@ -36,7 +36,7 @@ class NetworkConfigurationFilter final : public Http::PassThroughFilter,
Http::LocalErrorStatus onLocalReply(const LocalReplyData&) override;

private:
Network::ConfiguratorSharedPtr network_configurator_;
Network::ConnectivityManagerSharedPtr connectivity_manager_;
StreamInfo::ExtraStreamInfo* extra_stream_info_;
bool enable_drain_post_dns_refresh_;
bool enable_interface_binding_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ syntax = "proto3";
package envoymobile.extensions.filters.http.network_configuration;

message NetworkConfiguration {
// If set to true, the filter will permit the NetworkConfigurator to provide upstream
// If set to true, the filter will permit the NetworkConnectivityManager to provide upstream
// socket option that MAY bind a connection to a specific network interface.
bool enable_interface_binding = 1;

// If set to true, the filter will permit the NetworkConfigurator to drain connections
// If set to true, the filter will permit the NetworkConnectivityManager to drain connections
// when a DNS refresh is externally triggered.
bool enable_drain_post_dns_refresh = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ envoy_cc_extension(
repository = "@envoy",
deps = [
":predicate_cc_proto",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stream_info:extra_stream_info_lib",
"@envoy//envoy/upstream:retry_interface",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ NetworkConfigurationRetryOptionsPredicate::NetworkConfigurationRetryOptionsPredi
const envoymobile::extensions::retry::options::network_configuration::
NetworkConfigurationOptionsPredicate&,
Upstream::RetryExtensionFactoryContext& context) {
network_configurator_ = Network::ConfiguratorHandle{context.singletonManager()}.get();
RELEASE_ASSERT(network_configurator_ != nullptr, "unexpected nullptr network configurator");
connectivity_manager_ = Network::ConnectivityManagerHandle{context.singletonManager()}.get();
RELEASE_ASSERT(connectivity_manager_ != nullptr,
"unexpected nullptr network connectivity_manager");
}

Upstream::RetryOptionsPredicate::UpdateOptionsReturn
Expand Down Expand Up @@ -53,25 +54,26 @@ NetworkConfigurationRetryOptionsPredicate::updateOptions(

// As a proxy for the many different types of network errors, this code interprets any failure
// where a stream received no bytes from the upstream as a network fault. This status is passed to
// the configurator below when we report network usage, where it may be factored into future
// socket configuration.
// the connectivity_manager below when we report network usage, where it may be factored into
// future socket configuration.
bool network_fault =
!stream_info.upstreamInfo() ||
!stream_info.upstreamInfo()->upstreamTiming().first_upstream_rx_byte_received_.has_value();

// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions.
network_configurator_->reportNetworkUsage(extra_stream_info->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions.
connectivity_manager_->reportNetworkUsage(extra_stream_info->configuration_key_.value(),
network_fault);

// Update socket configuration for next retry attempt.
extra_stream_info->configuration_key_ = network_configurator_->addUpstreamSocketOptions(options);
extra_stream_info->configuration_key_ = connectivity_manager_->addUpstreamSocketOptions(options);

// The options returned here replace any existing socket options used for a prior attempt. At
// present, all socket options set in Envoy Mobile are provided by the NetworkConfigurator, so
// it's safe to simply replace them.
// present, all socket options set in Envoy Mobile are provided by the NetworkConnectivityManager,
// so it's safe to simply replace them.
// TODO(goaway): If additional socket options are ever provided by a source other than the
// NetworkConfigurator, we need to account for the potential presence of those options here.
// NetworkConnectivityManager, we need to account for the potential presence of those options
// here.
return Upstream::RetryOptionsPredicate::UpdateOptionsReturn{options};
}

Expand Down
Loading

0 comments on commit 586bdad

Please sign in to comment.