Check listening options when checking for bwu possibility

PiperOrigin-RevId: 543509150
This commit is contained in:
Anay Wadhera
2023-06-26 12:22:49 -07:00
committed by Copybara-Service
parent cabad16421
commit 1ddd4d91ea
5 changed files with 37 additions and 17 deletions
+3 -12
View File
@@ -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);
}
}
@@ -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.
@@ -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() &&
@@ -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.
@@ -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