diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index d0823c7a..f5c715a4 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -975,15 +975,6 @@ void BasePcpHandler::ProcessPreConnectionResultFailure( client->OnConnectionRejected(endpoint_id, {Status::kError}); } -bool BasePcpHandler::AutoUpgradeBandwidth( - const AdvertisingOptions& local_advertising_options) const { - if (local_advertising_options.strategy.IsNone()) { - return true; - } - - return local_advertising_options.auto_upgrade_bandwidth; -} - Status BasePcpHandler::AcceptConnection(ClientProxy* client, const std::string& endpoint_id, PayloadListener payload_listener) { @@ -1373,7 +1364,8 @@ Exception BasePcpHandler::OnIncomingConnection( NEARBY_LOGS(ERROR) << "Failed to parse incoming connection request; client=" << client->GetClientId() - << "; device=" << absl::BytesToHexString(remote_endpoint_info.data()); + << "; device=" << absl::BytesToHexString(remote_endpoint_info.data()) + << "with error: " << wrapped_frame.exception(); ProcessPreConnectionInitiationFailure( client, medium, "", channel.get(), /* is_incoming= */ false, start_time, {Status::kError}, nullptr); @@ -1743,8 +1735,7 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client, medium); // Kick off the bandwidth upgrade for incoming connections. - if (connection_info.is_incoming && - AutoUpgradeBandwidth(client->GetAdvertisingOptions())) { + if (connection_info.is_incoming && client->AutoUpgradeBandwidth()) { bwu_manager_->InitiateBwuForEndpoint(client, endpoint_id); } } diff --git a/connections/implementation/base_pcp_handler.h b/connections/implementation/base_pcp_handler.h index 416e7fbb..04f9acb2 100644 --- a/connections/implementation/base_pcp_handler.h +++ b/connections/implementation/base_pcp_handler.h @@ -452,11 +452,6 @@ class BasePcpHandler : public PcpHandler, bool IsPreferred(const BasePcpHandler::DiscoveredEndpoint& new_endpoint, const BasePcpHandler::DiscoveredEndpoint& old_endpoint); - // Returns true, if connection party should attempt to upgrade itself to - // use a higher bandwidth medium, if it is available. - bool AutoUpgradeBandwidth( - const AdvertisingOptions& local_advertising_options) const; - // Returns true if the incoming connection should be killed. This only // happens when an incoming connection arrives while we have an outgoing // connection to the same endpoint and we need to stop one connection. diff --git a/connections/implementation/client_proxy.cc b/connections/implementation/client_proxy.cc index 77dab35a..abef015c 100644 --- a/connections/implementation/client_proxy.cc +++ b/connections/implementation/client_proxy.cc @@ -711,6 +711,20 @@ bool ClientProxy::RemoteConnectionIsAccepted(std::string endpoint_id) const { endpoint_id, ClientProxy::Connection::kRemoteEndpointAccepted); } +bool ClientProxy::AutoUpgradeBandwidth() const { + bool result = false; + if (IsAdvertising() && (GetAdvertisingOptions().strategy.IsNone() || + GetAdvertisingOptions().auto_upgrade_bandwidth)) { + result |= true; + } + if (IsListeningForIncomingConnections() && + (GetListeningOptions().strategy.IsNone() || + GetListeningOptions().auto_upgrade_bandwidth)) { + result |= true; + } + return result; +} + bool ClientProxy::ShouldEnforceTopologyConstraints() const { bool result = false; if (IsAdvertising() && diff --git a/connections/implementation/client_proxy.h b/connections/implementation/client_proxy.h index 7f7cee1b..3e0106f2 100644 --- a/connections/implementation/client_proxy.h +++ b/connections/implementation/client_proxy.h @@ -205,6 +205,10 @@ class ClientProxy final { // Returns true if the client should enforce topology constraints. bool ShouldEnforceTopologyConstraints() const; + // Returns true, if connection party should attempt to upgrade itself to + // use a higher bandwidth medium, if it is available. + bool AutoUpgradeBandwidth() const; + // Proxies to the client's PayloadListener::OnPayload() callback. void OnPayload(const std::string& endpoint_id, Payload payload); // Proxies to the client's PayloadListener::OnPayloadProgress() callback. diff --git a/connections/implementation/client_proxy_test.cc b/connections/implementation/client_proxy_test.cc index 716fa8ce..5b21988b 100644 --- a/connections/implementation/client_proxy_test.cc +++ b/connections/implementation/client_proxy_test.cc @@ -31,6 +31,7 @@ #include "connections/listeners.h" #include "connections/strategy.h" #include "connections/v3/bandwidth_info.h" +#include "connections/v3/connection_listening_options.h" #include "connections/v3/connections_device_provider.h" #include "internal/analytics/event_logger.h" #include "internal/interop/device_provider.h" @@ -1106,6 +1107,21 @@ TEST_F(ClientProxyTest, DontEnforceTopologyWhenRequestedWithNoStrategy) { EXPECT_TRUE(client1_.ShouldEnforceTopologyConstraints()); } +TEST_F(ClientProxyTest, TestAutoBwuWhenAdvertisingWithAutoBwu) { + EXPECT_FALSE(client1_.AutoUpgradeBandwidth()); + StartAdvertising(&client1_, advertising_connection_listener_, + {.auto_upgrade_bandwidth = true}); + EXPECT_TRUE(client1_.AutoUpgradeBandwidth()); +} + +TEST_F(ClientProxyTest, TestAutoBwuWhenListeningWithAutoBwu) { + EXPECT_FALSE(client1_.AutoUpgradeBandwidth()); + StartListeningForIncomingConnections(&client1_, + {}, + {.auto_upgrade_bandwidth = true}); + EXPECT_TRUE(client1_.AutoUpgradeBandwidth()); +} + } // namespace } // namespace connections } // namespace nearby