[NC] Track bandwidth upgrade mediums for each endpoint (fix)

Rename RevertInitiatedBwuMediumForEndpointIfNecessary to RevertBwuMediumForEndpoint because this method can be called by RESPONDERs of the bandwidth upgrade request. Also, make sure to remove the endpoint from the endpoint-to-medium map.

PiperOrigin-RevId: 442055611
This commit is contained in:
nohle
2022-04-15 11:13:27 -07:00
committed by Copybara-Service
parent 98a5b9d0ee
commit 0c19f3f279
2 changed files with 18 additions and 20 deletions
+14 -15
View File
@@ -323,14 +323,14 @@ void BwuManager::OnEndpointDisconnect(ClientProxy* client,
// "== 0". Luckily, we will enable the flag by default, and it won't matter.
if (FeatureFlags::GetInstance().GetFlags().support_multiple_bwu_mediums ||
channel_manager_->GetConnectedEndpointsCount() <= 1) {
RevertInitiatedBwuMediumForEndpointIfNecessary(service_id, endpoint_id);
RevertBwuMediumForEndpoint(service_id, endpoint_id);
}
barrier.CountDown();
});
}
void BwuManager::RevertInitiatedBwuMediumForEndpointIfNecessary(
const std::string& upgrade_service_id, const std::string& endpoint_id) {
void BwuManager::RevertBwuMediumForEndpoint(const std::string& service_id,
const std::string& endpoint_id) {
Medium medium = GetBwuMediumForEndpoint(endpoint_id);
// If |support_multiple_bwu_mediums| is disabled, we take a less fine-grained
@@ -338,8 +338,7 @@ void BwuManager::RevertInitiatedBwuMediumForEndpointIfNecessary(
if (!FeatureFlags::GetInstance().GetFlags().support_multiple_bwu_mediums) {
NEARBY_LOGS(INFO) << "Reverting medium "
<< proto::connections::Medium_Name(medium)
<< " for all endpoints for service "
<< upgrade_service_id;
<< " for all endpoints for service " << service_id;
medium_ = Medium::UNKNOWN_MEDIUM;
BwuHandler* handler = GetHandlerForMedium(medium);
if (!handler) return;
@@ -348,19 +347,20 @@ void BwuManager::RevertInitiatedBwuMediumForEndpointIfNecessary(
return;
}
// If |upgrade_service_id| isn't of the INITIATOR-upgrade format, this is a
// no-op, for example, if this is called by the RESPONDER.
if (!IsInitiatorUpgradeServiceId(upgrade_service_id)) return;
NEARBY_LOGS(INFO) << "Reverting medium "
<< proto::connections::Medium_Name(medium)
<< " for service ID " << upgrade_service_id
<< " and endpoint " << endpoint_id;
<< " for service ID " << service_id << " and endpoint "
<< endpoint_id;
endpoint_id_to_bwu_medium_.erase(endpoint_id);
// If |service_id| isn't of the INITIATOR-upgrade format--for example, if this
// is called by the RESPONDER--there is no need to call RevertInitiatorState.
if (!IsInitiatorUpgradeServiceId(service_id)) return;
BwuHandler* handler = GetHandlerForMedium(medium);
if (!handler) return;
handler->RevertInitiatorState(upgrade_service_id, endpoint_id);
handler->RevertInitiatorState(service_id, endpoint_id);
}
Medium BwuManager::GetBwuMediumForEndpoint(
@@ -822,8 +822,7 @@ void BwuManager::RunUpgradeFailedProtocol(
// And lastly, clean up our medium since we failed to utilize it anyways.
if (GetBwuMediumForEndpoint(endpoint_id) != Medium::UNKNOWN_MEDIUM) {
RevertInitiatedBwuMediumForEndpointIfNecessary(channel->GetServiceId(),
endpoint_id);
RevertBwuMediumForEndpoint(channel->GetServiceId(), endpoint_id);
}
in_progress_upgrades_.erase(endpoint_id);
NEARBY_LOGS(INFO) << "BwuManager has informed endpoint " << endpoint_id
@@ -1090,7 +1089,7 @@ void BwuManager::ProcessUpgradeFailureEvent(
channel ? channel->GetServiceId() : std::string(kUnknownServiceId);
// Revert the existing upgrade medium for now.
if (GetBwuMediumForEndpoint(endpoint_id) != Medium::UNKNOWN_MEDIUM) {
RevertInitiatedBwuMediumForEndpointIfNecessary(service_id, endpoint_id);
RevertBwuMediumForEndpoint(service_id, endpoint_id);
}
// Loop through the ordered list of upgrade mediums. One by one, remove the
+4 -5
View File
@@ -129,11 +129,10 @@ class BwuManager : public EndpointManager::FrameProcessor {
const BwuNegotiationFrame frame,
const string& endpoint_id);
// Called to revert any state changed by the INITIATOR in the course of
// setting up the upgraded medium for an endpoint. If |upgrade_service_id|
// isn't of the INITIATOR-upgrade format, this is a no-op.
void RevertInitiatedBwuMediumForEndpointIfNecessary(
const std::string& upgrade_service_id, const std::string& endpoint_id);
// Called to revert any state changed in the course of setting up the upgraded
// medium for an endpoint.
void RevertBwuMediumForEndpoint(const std::string& service_id,
const std::string& endpoint_id);
// Get/Set the currently selected upgrade medium for this endpoint, or
// UNKNOWN_MEDIUM if nothing is selected. This is the medium we are attempting