mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 15:16:12 -04:00
Internal change
PiperOrigin-RevId: 370662571
This commit is contained in:
@@ -53,22 +53,22 @@ BasePcpHandler::BasePcpHandler(Mediums* mediums,
|
||||
bwu_manager_(bwu_manager) {}
|
||||
|
||||
BasePcpHandler::~BasePcpHandler() {
|
||||
NEARBY_LOGS(INFO) << "BasePcpHandler: going down; strategy="
|
||||
<< strategy_.GetName();
|
||||
NEARBY_LOG(INFO, "Initiating shutdown of PcpHandler(%s)",
|
||||
strategy_.GetName().c_str());
|
||||
DisconnectFromEndpointManager();
|
||||
// Stop all the ongoing Runnables (as gracefully as possible).
|
||||
NEARBY_LOGS(INFO) << "BasePcpHandler: bringing down executors; strategy="
|
||||
<< strategy_.GetName();
|
||||
NEARBY_LOG(INFO, "BasePcpHandler: bringing down executors; strategy=%s",
|
||||
strategy_.GetName().c_str());
|
||||
serial_executor_.Shutdown();
|
||||
alarm_executor_.Shutdown();
|
||||
NEARBY_LOGS(INFO) << "BasePcpHandler: is down; strategy="
|
||||
<< strategy_.GetName();
|
||||
NEARBY_LOG(INFO, "PcpHandler(%s) has shut down.",
|
||||
strategy_.GetName().c_str());
|
||||
}
|
||||
|
||||
void BasePcpHandler::DisconnectFromEndpointManager() {
|
||||
if (stop_.Set(true)) return;
|
||||
NEARBY_LOGS(INFO) << "BasePcpHandler: Unregister from EPM; strategy="
|
||||
<< strategy_.GetName();
|
||||
NEARBY_LOG(INFO, "BasePcpHandler: Unregister from EPM; strategy=%s",
|
||||
strategy_.GetName().c_str());
|
||||
// Unregister ourselves from EPM message dispatcher.
|
||||
endpoint_manager_->UnregisterFrameProcessor(V1Frame::CONNECTION_RESPONSE,
|
||||
this);
|
||||
@@ -118,7 +118,8 @@ Status BasePcpHandler::StartAdvertising(ClientProxy* client,
|
||||
}
|
||||
|
||||
void BasePcpHandler::StopAdvertising(ClientProxy* client) {
|
||||
NEARBY_LOGS(INFO) << "StopAdvertising id=" << client->GetLocalEndpointId();
|
||||
NEARBY_LOG(INFO, "StopAdvertising local_endpoint_id=%s",
|
||||
client->GetLocalEndpointId().c_str());
|
||||
CountDownLatch latch(1);
|
||||
RunOnPcpHandlerThread("stop-advertising",
|
||||
[this, client, &latch]() RUN_ON_PCP_HANDLER_THREAD() {
|
||||
@@ -310,9 +311,10 @@ void BasePcpHandler::OnEncryptionSuccessRunnable(
|
||||
// busy running UKEY2.
|
||||
auto it = pending_connections_.find(endpoint_id);
|
||||
if (it == pending_connections_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Connection not found on UKEY negotination complete; id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Connection not found on UKEY negotination complete; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,7 +329,8 @@ void BasePcpHandler::OnEncryptionSuccessRunnable(
|
||||
}
|
||||
|
||||
connection_info.SetCryptoContext(std::move(ukey2));
|
||||
NEARBY_LOG(INFO, "Register encrypted connection; wait for response; id=%s",
|
||||
NEARBY_LOG(INFO,
|
||||
"Register encrypted connection; wait for response; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
|
||||
// Set ourselves up so that we receive all acceptance/rejection messages
|
||||
@@ -375,9 +378,10 @@ void BasePcpHandler::OnEncryptionFailureRunnable(
|
||||
const std::string& endpoint_id, EndpointChannel* endpoint_channel) {
|
||||
auto it = pending_connections_.find(endpoint_id);
|
||||
if (it == pending_connections_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Connection not found on UKEY negotination complete; id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Connection not found on UKEY negotination complete; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,7 +418,10 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
// If we already have a pending connection, then we shouldn't allow any
|
||||
// more outgoing connections to this endpoint.
|
||||
if (pending_connections_.count(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "Connection already exists: id=%s",
|
||||
NEARBY_LOG(INFO,
|
||||
"In requestConnection(), connection requested with "
|
||||
"endpoint(id=%s), "
|
||||
"but we already have a pending connection with them.",
|
||||
endpoint_id.c_str());
|
||||
result->Set({Status::kAlreadyConnectedToEndpoint});
|
||||
return;
|
||||
@@ -424,15 +431,19 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
// listen to them.
|
||||
if (ShouldEnforceTopologyConstraints(client->GetAdvertisingOptions()) &&
|
||||
!CanSendOutgoingConnection(client)) {
|
||||
NEARBY_LOG(INFO, "Outgoing connection not allowed: id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"In requestConnection(), client=%" PRIx64
|
||||
" attempted a connection with endpoint(id=%s), but outgoing "
|
||||
"connections are disallowed",
|
||||
client->GetClientId(), endpoint_id.c_str());
|
||||
result->Set({Status::kOutOfOrderApiCall});
|
||||
return;
|
||||
}
|
||||
|
||||
DiscoveredEndpoint* endpoint = GetDiscoveredEndpoint(endpoint_id);
|
||||
if (endpoint == nullptr) {
|
||||
NEARBY_LOG(INFO, "Discovered endpoint not found: id=%s",
|
||||
NEARBY_LOG(INFO, "Discovered endpoint not found: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
result->Set({Status::kEndpointUnknown});
|
||||
return;
|
||||
@@ -444,13 +455,13 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
if (AppendRemoteBluetoothMacAddressEndpoint(
|
||||
endpoint_id, remote_bluetooth_mac_address,
|
||||
client->GetDiscoveryOptions()))
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Appended remote Bluetooth MAC Address endpoint "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
NEARBY_LOG(INFO,
|
||||
"Appended remote Bluetooth MAC Address endpoint [%s]",
|
||||
remote_bluetooth_mac_address.c_str());
|
||||
}
|
||||
|
||||
if (AppendWebRTCEndpoint(endpoint_id, client->GetDiscoveryOptions()))
|
||||
NEARBY_LOGS(INFO) << "Appended Web RTC endpoint.";
|
||||
NEARBY_LOG(INFO, "Appended Web RTC endpoint.");
|
||||
|
||||
auto discovered_endpoints = GetDiscoveredEndpoints(endpoint_id);
|
||||
std::unique_ptr<EndpointChannel> channel;
|
||||
@@ -468,7 +479,7 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
}
|
||||
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOG(INFO, "Endpoint channel not available: id=%s",
|
||||
NEARBY_LOG(INFO, "Endpoint channel not available: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionInitiationFailure(endpoint_id, channel.get(),
|
||||
connect_impl_result.status,
|
||||
@@ -476,7 +487,9 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "Sending connection request: id=%s",
|
||||
NEARBY_LOG(INFO,
|
||||
"In requestConnection(), wrote ConnectionRequestFrame "
|
||||
"to endpoint(id=%s)",
|
||||
endpoint_id.c_str());
|
||||
// Generate the nonce to use for this connection.
|
||||
std::int32_t nonce = prng_.NextInt32();
|
||||
@@ -487,7 +500,7 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
channel.get(), client->GetLocalEndpointId(), info.endpoint_info,
|
||||
nonce, GetSupportedConnectionMediumsByPriority(options));
|
||||
if (!write_exception.Ok()) {
|
||||
NEARBY_LOG(INFO, "Failed to send connection request: id=%s",
|
||||
NEARBY_LOG(INFO, "Failed to send connection request: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionInitiationFailure(endpoint_id, channel.get(),
|
||||
{Status::kEndpointIoError},
|
||||
@@ -495,7 +508,7 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "adding connection to pending set: id=%s",
|
||||
NEARBY_LOG(INFO, "Adding connection to pending set: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
|
||||
// We've successfully connected to the device, and are now about to jump
|
||||
@@ -519,14 +532,14 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
})
|
||||
.first->second.channel.get();
|
||||
|
||||
NEARBY_LOG(INFO, "Initiating secure connection: id=%s",
|
||||
NEARBY_LOG(INFO, "Initiating secure connection: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
// Next, we'll set up encryption. When it's done, our future will return
|
||||
// and RequestConnection() will finish.
|
||||
encryption_runner_.StartClient(client, endpoint_id, endpoint_channel,
|
||||
GetResultListener());
|
||||
});
|
||||
NEARBY_LOG(INFO, "Waiting for connection to complete: id=%s",
|
||||
NEARBY_LOG(INFO, "Waiting for connection to complete: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
auto status =
|
||||
WaitForResult(absl::StrCat("RequestConnection(", endpoint_id, ")"),
|
||||
@@ -692,10 +705,14 @@ Status BasePcpHandler::AcceptConnection(
|
||||
RunOnPcpHandlerThread(
|
||||
"accept-connection", [this, client, endpoint_id, payload_listener,
|
||||
&response]() RUN_ON_PCP_HANDLER_THREAD() {
|
||||
NEARBY_LOG(INFO, "AcceptConnection: id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO, "AcceptConnection: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
if (!pending_connections_.count(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "AcceptConnection: no pending connection for id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"AcceptConnection: no pending connection for endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
|
||||
response.Set({Status::kEndpointUnknown});
|
||||
return;
|
||||
}
|
||||
@@ -709,10 +726,10 @@ Status BasePcpHandler::AcceptConnection(
|
||||
std::shared_ptr<EndpointChannel> channel =
|
||||
channel_manager_->GetChannelForEndpoint(endpoint_id);
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOG(
|
||||
ERROR,
|
||||
"Channel destroyed before Accept; bring down connection: id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(ERROR,
|
||||
"Channel destroyed before Accept; bring down "
|
||||
"connection: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionResultFailure(client, endpoint_id);
|
||||
response.Set({Status::kEndpointUnknown});
|
||||
return;
|
||||
@@ -721,14 +738,15 @@ Status BasePcpHandler::AcceptConnection(
|
||||
Exception write_exception =
|
||||
channel->Write(parser::ForConnectionResponse(Status::kSuccess));
|
||||
if (!write_exception.Ok()) {
|
||||
NEARBY_LOG(INFO, "AcceptConnection: failed to send response: id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO, "AcceptConnection: failed to send response: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionResultFailure(client, endpoint_id);
|
||||
response.Set({Status::kEndpointIoError});
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "AcceptConnection: accepting locally: id=%s",
|
||||
NEARBY_LOG(INFO, "AcceptConnection: accepting locally: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
connection_info.LocalEndpointAcceptedConnection(endpoint_id,
|
||||
payload_listener);
|
||||
@@ -749,8 +767,10 @@ Status BasePcpHandler::RejectConnection(ClientProxy* client,
|
||||
[this, client, endpoint_id, &response]() RUN_ON_PCP_HANDLER_THREAD() {
|
||||
NEARBY_LOG(INFO, "RejectConnection: id=%s", endpoint_id.c_str());
|
||||
if (!pending_connections_.count(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "RejectConnection: no pending connection for id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"RejectConnection: no pending connection for endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
response.Set({Status::kEndpointUnknown});
|
||||
return;
|
||||
}
|
||||
@@ -764,10 +784,10 @@ Status BasePcpHandler::RejectConnection(ClientProxy* client,
|
||||
std::shared_ptr<EndpointChannel> channel =
|
||||
channel_manager_->GetChannelForEndpoint(endpoint_id);
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOG(
|
||||
ERROR,
|
||||
"Channel destroyed before Reject; bring down connection: id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(ERROR,
|
||||
"Channel destroyed before Reject; bring down connection: "
|
||||
"endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionResultFailure(client, endpoint_id);
|
||||
response.Set({Status::kEndpointUnknown});
|
||||
return;
|
||||
@@ -776,14 +796,15 @@ Status BasePcpHandler::RejectConnection(ClientProxy* client,
|
||||
Exception write_exception = channel->Write(
|
||||
parser::ForConnectionResponse(Status::kConnectionRejected));
|
||||
if (!write_exception.Ok()) {
|
||||
NEARBY_LOG(INFO, "RejectConnection: failed to send response: id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO, "RejectConnection: failed to send response: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
ProcessPreConnectionResultFailure(client, endpoint_id);
|
||||
response.Set({Status::kEndpointIoError});
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "RejectConnection: rejecting locally: id=%s",
|
||||
NEARBY_LOG(INFO, "RejectConnection: rejecting locally: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
connection_info.LocalEndpointRejectedConnection(endpoint_id);
|
||||
EvaluateConnectionResult(client, endpoint_id,
|
||||
@@ -803,10 +824,12 @@ void BasePcpHandler::OnIncomingFrame(OfflineFrame& frame,
|
||||
RunOnPcpHandlerThread(
|
||||
"incoming-frame",
|
||||
[this, client, endpoint_id, frame, &latch]() RUN_ON_PCP_HANDLER_THREAD() {
|
||||
NEARBY_LOG(INFO, "OnConnectionResponse: id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO, "OnConnectionResponse: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
|
||||
if (client->HasRemoteEndpointResponded(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "OnConnectionResponse: already handled; id=%s",
|
||||
NEARBY_LOG(INFO,
|
||||
"OnConnectionResponse: already handled; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -825,12 +848,14 @@ void BasePcpHandler::OnIncomingFrame(OfflineFrame& frame,
|
||||
accepted = connection_response.status() == Status::kSuccess;
|
||||
}
|
||||
if (accepted) {
|
||||
NEARBY_LOG(INFO, "OnConnectionResponse: remote accepted; id=%s",
|
||||
NEARBY_LOG(INFO,
|
||||
"OnConnectionResponse: remote accepted; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
client->RemoteEndpointAcceptedConnection(endpoint_id);
|
||||
} else {
|
||||
NEARBY_LOG(INFO,
|
||||
"OnConnectionResponse: remote rejected; id=%s; status=%d",
|
||||
"OnConnectionResponse: remote rejected; endpoint_id=%s; "
|
||||
"status=%d",
|
||||
endpoint_id.c_str(), connection_response.status());
|
||||
client->RemoteEndpointRejectedConnection(endpoint_id);
|
||||
}
|
||||
@@ -905,14 +930,16 @@ void BasePcpHandler::OnEndpointFound(
|
||||
// Range is empty: this is the first endpoint we discovered so far.
|
||||
// Report this endpoint_id to client.
|
||||
if (range.first == range.second) {
|
||||
NEARBY_LOG(INFO, "Adding new endpoint: id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO, "Adding new endpoint: endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
// And, as it's the first time, report it to the client.
|
||||
client->OnEndpointFound(
|
||||
owned_endpoint->service_id, owned_endpoint->endpoint_id,
|
||||
owned_endpoint->endpoint_info, owned_endpoint->medium);
|
||||
} else {
|
||||
NEARBY_LOGS(INFO) << "Adding new medium for endpoint: id=" << endpoint_id
|
||||
<< "; medium=" << owned_endpoint->medium;
|
||||
NEARBY_LOG(INFO,
|
||||
"Adding new medium for endpoint: endpoint_id=%s; medium=%d",
|
||||
endpoint_id.c_str(), owned_endpoint->medium);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,7 +948,7 @@ void BasePcpHandler::OnEndpointLost(
|
||||
// Look up the DiscoveredEndpoint we have in our cache.
|
||||
const auto* discovered_endpoint = GetDiscoveredEndpoint(endpoint.endpoint_id);
|
||||
if (discovered_endpoint == nullptr) {
|
||||
NEARBY_LOG(INFO, "No previous endpoint (nothing to lose): id=%s",
|
||||
NEARBY_LOG(INFO, "No previous endpoint (nothing to lose): endpoint_id=%s",
|
||||
endpoint.endpoint_id.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -967,9 +994,10 @@ bool BasePcpHandler::IsPreferred(
|
||||
absl::StrAppend(&medium_string, medium, "; ");
|
||||
}
|
||||
NEARBY_LOG(FATAL,
|
||||
"Failed to determine preferred medium; bailing out; mediums=%s; "
|
||||
"new=%d; old=%d",
|
||||
medium_string.c_str(), new_endpoint.medium, old_endpoint.medium);
|
||||
"Failed to find either %d or %d in the list of locally supported "
|
||||
"mediums despite expecting to find both, when deciding which "
|
||||
"medium %s is preferred.",
|
||||
new_endpoint.medium, old_endpoint.medium, medium_string.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -983,10 +1011,11 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
// the client stopped advertising and we nulled out state, followed by an
|
||||
// incoming connection where we attempted to check that state.
|
||||
if (!client->IsAdvertising()) {
|
||||
NEARBY_LOG(WARNING,
|
||||
"Ignoring incoming connection because client 0x%" PRIX64
|
||||
" is no longer advertising.",
|
||||
client->GetClientId());
|
||||
NEARBY_LOG(
|
||||
WARNING,
|
||||
"Ignoring incoming connection on medium %d because client=%" PRIX64
|
||||
" is no longer advertising",
|
||||
channel->GetMedium(), client->GetClientId());
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
@@ -996,12 +1025,11 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
|
||||
if (!wrapped_frame.ok()) {
|
||||
if (wrapped_frame.exception()) {
|
||||
NEARBY_LOG(
|
||||
ERROR,
|
||||
"Failed to parse incoming connection request; client_id=0x%" PRIX64
|
||||
"; device=%s",
|
||||
client->GetClientId(),
|
||||
absl::BytesToHexString(remote_endpoint_info.data()).c_str());
|
||||
NEARBY_LOG(ERROR,
|
||||
"Failed to parse incoming connection request; client=%" PRIx64
|
||||
"; device=%s",
|
||||
client->GetClientId(),
|
||||
absl::BytesToHexString(remote_endpoint_info.data()).c_str());
|
||||
ProcessPreConnectionInitiationFailure("", channel.get(), {Status::kError},
|
||||
nullptr);
|
||||
return {Exception::kSuccess};
|
||||
@@ -1013,12 +1041,15 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
const ConnectionRequestFrame& connection_request =
|
||||
frame.v1().connection_request();
|
||||
NEARBY_LOG(INFO,
|
||||
"Incoming connection request; client_id=0x%" PRIX64
|
||||
"; device=%s; id=%s",
|
||||
client->GetClientId(),
|
||||
absl::BytesToHexString(remote_endpoint_info.data()).c_str(),
|
||||
"In onIncomingConnection(%d) for client=%" PRIx64
|
||||
", read ConnectionRequestFrame from endpoint(id=%s)",
|
||||
channel->GetMedium(), client->GetClientId(),
|
||||
connection_request.endpoint_id().c_str());
|
||||
if (client->IsConnectedToEndpoint(connection_request.endpoint_id())) {
|
||||
NEARBY_LOG(ERROR,
|
||||
"Incoming connection on medium %d was denied because we're "
|
||||
"already connected to endpoint(id=%s).",
|
||||
channel->GetMedium(), connection_request.endpoint_id().c_str());
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
@@ -1033,6 +1064,7 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
// listen to them.
|
||||
if (ShouldEnforceTopologyConstraints(client->GetAdvertisingOptions()) &&
|
||||
!CanReceiveIncomingConnection(client)) {
|
||||
NEARBY_LOG(ERROR, "Incoming connections are currently disallowed.");
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
@@ -1079,21 +1111,37 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
|
||||
if (it != pending_connections_.end()) {
|
||||
BasePcpHandler::PendingConnectionInfo& info = it->second;
|
||||
|
||||
NEARBY_LOG(INFO, "BreakTie: id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"In onIncomingConnection(%s) for client %d, found a collision with "
|
||||
"endpoint %s. We've already sent a connection request to them with "
|
||||
"nonce %d, but they're also trying to connect to us with nonce %d.",
|
||||
endpoint_channel->GetMedium(), client->GetClientId(),
|
||||
endpoint_id.c_str(), info.nonce, incoming_nonce);
|
||||
// Break the lowest connection. In the (extremely) rare case of a tie, break
|
||||
// both.
|
||||
if (info.nonce > incoming_nonce) {
|
||||
// Our connection won! Clean up their connection.
|
||||
endpoint_channel->Close();
|
||||
|
||||
NEARBY_LOG(INFO, "BreakTie: We won; id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"In onIncomingConnection(%s) for client=%" PRIx64
|
||||
", cleaned up the collision with endpoint(id=%s) by closing their "
|
||||
"channel.",
|
||||
endpoint_channel->GetMedium(), client->GetClientId(),
|
||||
endpoint_id.c_str());
|
||||
return true;
|
||||
} else if (info.nonce < incoming_nonce) {
|
||||
// Aw, we lost. Clean up our connection, and then we'll let their
|
||||
// connection continue on.
|
||||
ProcessTieBreakLoss(client, endpoint_id, &info);
|
||||
|
||||
NEARBY_LOG(INFO, "BreakTie: We lost; id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO,
|
||||
"In onIncomingConnection(%s) for client=%" PRIx64
|
||||
", cleaned up the collision with endpoint %s by closing our "
|
||||
"channel and notifying our client of the failure.",
|
||||
endpoint_channel->GetMedium(), client->GetClientId(),
|
||||
endpoint_id.c_str());
|
||||
} else {
|
||||
// Oh. Huh. We both lost. Well, that's awkward. We'll clean up both and
|
||||
// just force the devices to retry.
|
||||
@@ -1101,7 +1149,13 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
|
||||
|
||||
ProcessTieBreakLoss(client, endpoint_id, &info);
|
||||
|
||||
NEARBY_LOG(INFO, "BreakTie: Both lost; id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO,
|
||||
"In onIncomingConnection(%d) for client=%" PRIx64
|
||||
", cleaned up the collision with endpoint %s by closing both "
|
||||
"channels. Our nonces were identical, so we couldn't decide "
|
||||
"which channel to use.",
|
||||
endpoint_channel->GetMedium(), client->GetClientId(),
|
||||
endpoint_id.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1133,10 +1187,11 @@ bool BasePcpHandler::AppendRemoteBluetoothMacAddressEndpoint(
|
||||
auto endpoint = it.first->second.get();
|
||||
for (auto item = it.first; item != it.second; item++) {
|
||||
if (item->second->medium == proto::connections::Medium::BLUETOOTH) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Cannot append remote Bluetooth MAC Address endpoint, because the "
|
||||
"endpoint has already been found over Bluetooth "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Cannot append remote Bluetooth MAC Address endpoint, because the "
|
||||
"endpoint has already been found over Bluetooth [%s]",
|
||||
remote_bluetooth_mac_address.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1144,10 +1199,10 @@ bool BasePcpHandler::AppendRemoteBluetoothMacAddressEndpoint(
|
||||
auto remote_bluetooth_device =
|
||||
GetRemoteBluetoothDevice(remote_bluetooth_mac_address);
|
||||
if (!remote_bluetooth_device.IsValid()) {
|
||||
NEARBY_LOGS(INFO) << "Cannot append remote Bluetooth MAC Address endpoint, "
|
||||
"because a valid "
|
||||
"Bluetooth device could not be derived "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot append remote Bluetooth MAC Address endpoint, because a "
|
||||
"valid Bluetooth device could not be derived [%s]",
|
||||
remote_bluetooth_mac_address.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1200,11 +1255,15 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
|
||||
if (!client->IsConnectionAccepted(endpoint_id) &&
|
||||
!client->IsConnectionRejected(endpoint_id)) {
|
||||
if (!client->HasLocalEndpointResponded(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "ConnectionResult: local client did not respond; id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"ConnectionResult: local client did not respond; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
} else if (!client->HasRemoteEndpointResponded(endpoint_id)) {
|
||||
NEARBY_LOG(INFO, "ConnectionResult: remote client did not respond; id=%s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"ConnectionResult: remote client did not respond; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1213,7 +1272,7 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
|
||||
// no longer pending.
|
||||
auto it = pending_connections_.find(endpoint_id);
|
||||
if (it == pending_connections_.end()) {
|
||||
NEARBY_LOG(INFO, "No pending connection to evaluate; id=%s",
|
||||
NEARBY_LOG(INFO, "No pending connection to evaluate; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -1224,7 +1283,8 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
|
||||
|
||||
Status response_code;
|
||||
if (is_connection_accepted) {
|
||||
NEARBY_LOG(INFO, "Pending connection accepted; id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO, "Pending connection accepted; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
response_code = {Status::kSuccess};
|
||||
|
||||
// Both sides have accepted, so we can now start talking over encrypted
|
||||
@@ -1241,7 +1301,8 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
|
||||
channel_manager_->EncryptChannelForEndpoint(endpoint_id,
|
||||
std::move(context));
|
||||
} else {
|
||||
NEARBY_LOG(INFO, "Pending connection rejected; id=%s", endpoint_id.c_str());
|
||||
NEARBY_LOG(INFO, "Pending connection rejected; endpoint_id=%s",
|
||||
endpoint_id.c_str());
|
||||
response_code = {Status::kConnectionRejected};
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,7 @@ class P2pClusterPcpHandlerTest
|
||||
NEARBY_LOG(INFO, "SetUp: BT enabled");
|
||||
}
|
||||
if (options_.allowed.wifi_lan) {
|
||||
NEARBY_LOG(INFO, "SetUp: Wifi LAN enabled");
|
||||
NEARBY_LOG(INFO, "SetUp: WifiLan enabled");
|
||||
}
|
||||
if (options_.allowed.web_rtc) {
|
||||
NEARBY_LOG(INFO, "SetUp: WebRTC enabled");
|
||||
|
||||
@@ -48,7 +48,9 @@ void PcpManager::DisconnectFromEndpointManager() {
|
||||
}
|
||||
|
||||
PcpManager::~PcpManager() {
|
||||
NEARBY_LOG(INFO, "Initiating shutdown of PcpManager.");
|
||||
DisconnectFromEndpointManager();
|
||||
NEARBY_LOG(INFO, "PcpManager has shut down.");
|
||||
}
|
||||
|
||||
Status PcpManager::StartAdvertising(ClientProxy* client,
|
||||
|
||||
Reference in New Issue
Block a user