mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Fix a crash in BasePcpHandler::BreakTie.
PiperOrigin-RevId: 638412219
This commit is contained in:
committed by
Copybara-Service
parent
f15f7ecc24
commit
51dcfe807d
@@ -576,16 +576,20 @@ void BasePcpHandler::OnEncryptionSuccessRunnableV3(
|
||||
}
|
||||
|
||||
BasePcpHandler::PendingConnectionInfo& connection_info = it->second;
|
||||
Medium medium = connection_info.channel->GetMedium();
|
||||
|
||||
// TODO(b/300149127): Add test coverage.
|
||||
if (!ukey2) {
|
||||
// Fail early, if there is no crypto context.
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
connection_info.client, medium, remote_device.GetEndpointId(),
|
||||
connection_info.channel.get(), connection_info.is_incoming,
|
||||
connection_info.start_time, {Status::kEndpointIoError},
|
||||
connection_info.result.lock().get());
|
||||
connection_info.client,
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? connection_info.medium
|
||||
: connection_info.channel->GetMedium(),
|
||||
remote_device.GetEndpointId(), connection_info.channel.get(),
|
||||
connection_info.is_incoming, connection_info.start_time,
|
||||
{Status::kEndpointIoError}, connection_info.result.lock().get());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -640,13 +644,17 @@ void BasePcpHandler::OnEncryptionSuccessRunnable(
|
||||
}
|
||||
|
||||
BasePcpHandler::PendingConnectionInfo& connection_info = it->second;
|
||||
Medium medium = connection_info.channel->GetMedium();
|
||||
|
||||
if (!ukey2) {
|
||||
// Fail early, if there is no crypto context.
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
connection_info.client, medium, endpoint_id,
|
||||
connection_info.channel.get(), connection_info.is_incoming,
|
||||
connection_info.client,
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? connection_info.medium
|
||||
: connection_info.channel->GetMedium(),
|
||||
endpoint_id, connection_info.channel.get(), connection_info.is_incoming,
|
||||
connection_info.start_time, {Status::kEndpointIoError},
|
||||
connection_info.result.lock().get());
|
||||
return;
|
||||
@@ -724,9 +732,14 @@ void BasePcpHandler::OnEncryptionFailureRunnable(
|
||||
}
|
||||
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
info.client, info.channel->GetMedium(), endpoint_id, info.channel.get(),
|
||||
info.is_incoming, info.start_time, {Status::kEndpointIoError},
|
||||
info.result.lock().get());
|
||||
info.client,
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? info.medium
|
||||
: info.channel->GetMedium(),
|
||||
endpoint_id, info.channel.get(), info.is_incoming, info.start_time,
|
||||
{Status::kEndpointIoError}, info.result.lock().get());
|
||||
}
|
||||
|
||||
ConnectionInfo BasePcpHandler::FillConnectionInfo(
|
||||
@@ -864,6 +877,7 @@ Status BasePcpHandler::RequestConnection(
|
||||
pendingConnectionInfo.listener = info.listener;
|
||||
pendingConnectionInfo.connection_options = connection_options;
|
||||
pendingConnectionInfo.result = result;
|
||||
pendingConnectionInfo.medium = channel->GetMedium();
|
||||
pendingConnectionInfo.channel = std::move(channel);
|
||||
|
||||
EndpointChannel* endpoint_channel =
|
||||
@@ -1009,6 +1023,7 @@ Status BasePcpHandler::RequestConnectionV3(
|
||||
pendingConnectionInfo.listener = info.listener;
|
||||
pendingConnectionInfo.connection_options = connection_options;
|
||||
pendingConnectionInfo.result = result;
|
||||
pendingConnectionInfo.medium = channel->GetMedium();
|
||||
pendingConnectionInfo.channel = std::move(channel);
|
||||
|
||||
EndpointChannel* endpoint_channel =
|
||||
@@ -1757,8 +1772,8 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
<< "; device=" << absl::BytesToHexString(remote_endpoint_info.data())
|
||||
<< "with error: " << wrapped_frame.exception();
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
client, medium, "", channel.get(),
|
||||
/* is_incoming= */ true, start_time, {Status::kError}, nullptr);
|
||||
client, medium, /*endpoint_id=*/"", channel.get(),
|
||||
/*is_incoming=*/true, start_time, {Status::kError}, nullptr);
|
||||
}
|
||||
return wrapped_frame.GetException();
|
||||
}
|
||||
@@ -1880,6 +1895,7 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
pendingConnectionInfo.connection_options = connection_options;
|
||||
pendingConnectionInfo.supported_mediums =
|
||||
parser::ConnectionRequestMediumsToMediums(connection_request);
|
||||
pendingConnectionInfo.medium = channel->GetMedium();
|
||||
pendingConnectionInfo.channel = std::move(channel);
|
||||
|
||||
auto* owned_channel = pending_connections_
|
||||
@@ -1939,7 +1955,6 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
|
||||
// Oh. Huh. We both lost. Well, that's awkward. We'll clean up both and
|
||||
// just force the devices to retry.
|
||||
endpoint_channel->Close();
|
||||
|
||||
ProcessTieBreakLoss(client, endpoint_id, &info);
|
||||
|
||||
NEARBY_LOGS(INFO)
|
||||
@@ -1988,9 +2003,14 @@ void BasePcpHandler::ProcessTieBreakLoss(
|
||||
ClientProxy* client, const std::string& endpoint_id,
|
||||
BasePcpHandler::PendingConnectionInfo* info) {
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
client, info->channel->GetMedium(), endpoint_id, info->channel.get(),
|
||||
info->is_incoming, info->start_time, {Status::kEndpointIoError},
|
||||
info->result.lock().get());
|
||||
client,
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? info->medium
|
||||
: info->channel->GetMedium(),
|
||||
endpoint_id, info->channel.get(), info->is_incoming, info->start_time,
|
||||
{Status::kEndpointIoError}, info->result.lock().get());
|
||||
ProcessPreConnectionResultFailure(client, endpoint_id,
|
||||
/* should_call_disconnect_endpoint= */ true,
|
||||
DisconnectionReason::IO_ERROR);
|
||||
@@ -2268,10 +2288,15 @@ void BasePcpHandler::LogConnectionAttemptSuccess(
|
||||
"LogConnectionAttemptSuccess. Bail out.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (connection_info.is_incoming) {
|
||||
connection_info.client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
|
||||
location::nearby::proto::connections::INITIAL,
|
||||
connection_info.channel->GetMedium(),
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? connection_info.medium
|
||||
: connection_info.channel->GetMedium(),
|
||||
location::nearby::proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token,
|
||||
@@ -2279,7 +2304,11 @@ void BasePcpHandler::LogConnectionAttemptSuccess(
|
||||
} else {
|
||||
connection_info.client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
|
||||
endpoint_id, location::nearby::proto::connections::INITIAL,
|
||||
connection_info.channel->GetMedium(),
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kUseMediumInConnectionInfo)
|
||||
? connection_info.medium
|
||||
: connection_info.channel->GetMedium(),
|
||||
location::nearby::proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token,
|
||||
|
||||
@@ -441,7 +441,10 @@ class BasePcpHandler : public PcpHandler,
|
||||
// Only (possibly) vector for incoming connections.
|
||||
std::vector<location::nearby::proto::connections::Medium> supported_mediums;
|
||||
|
||||
// Keep track of a channel before we pass it to EndpointChannelManager.
|
||||
// Keep track of a channel before we pass it to EndpointChannelManager. This
|
||||
// is owned until the call to OnEncryptionSuccessRunnableV3 or
|
||||
// OnEncryptionSuccessRunnable when ownership is transferred to the
|
||||
// EndpointManager.
|
||||
std::unique_ptr<EndpointChannel> channel;
|
||||
|
||||
// Crypto context; initially empty; established first thing after channel
|
||||
@@ -454,6 +457,9 @@ class BasePcpHandler : public PcpHandler,
|
||||
|
||||
// Used in AnalyticsRecorder for devices connection tracking.
|
||||
std::string connection_token;
|
||||
|
||||
// The medium that the connection was established on.
|
||||
location::nearby::proto::connections::Medium medium;
|
||||
};
|
||||
|
||||
// @EncryptionRunnerThread
|
||||
|
||||
@@ -78,6 +78,10 @@ constexpr auto kEnableMultiplex =
|
||||
constexpr auto kIgnoreUpgradePathAvailableFrameForAdvertiser =
|
||||
flags::Flag<bool>(kConfigPackage, "45633895", false);
|
||||
|
||||
// When true, use the medium in connection info.
|
||||
constexpr auto kUseMediumInConnectionInfo =
|
||||
flags::Flag<bool>(kConfigPackage, "45635058", false);
|
||||
|
||||
} // namespace nearby_connections_feature
|
||||
} // namespace config_package_nearby
|
||||
} // namespace connections
|
||||
|
||||
Reference in New Issue
Block a user