analytics: Add exact OperationResultCode for WebRtc - BwuHandler

PiperOrigin-RevId: 704943200
This commit is contained in:
Edwin Wu
2024-12-10 20:20:39 -08:00
committed by Copybara-Service
parent 1cdef6c391
commit d9b2f1aaa9
6 changed files with 106 additions and 82 deletions
+30 -18
View File
@@ -35,10 +35,12 @@
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/cancellation_flag_listener.h"
#include "internal/platform/exception.h"
#include "internal/platform/expected.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/future.h"
#include "internal/platform/logging.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/runnable.h"
#include "internal/platform/webrtc.h"
#include "webrtc/api/jsep.h"
@@ -48,6 +50,7 @@ namespace mediums {
namespace {
using ::location::nearby::connections::LocationHint;
using ::location::nearby::proto::connections::OperationResultCode;
// The maximum amount of time to wait to connect to a data channel via WebRTC.
constexpr absl::Duration kDataChannelTimeout = absl::Seconds(10);
@@ -206,13 +209,14 @@ void WebRtc::StopAcceptingConnections(const std::string& service_id) {
<< service_id;
}
WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id,
const WebrtcPeerId& remote_peer_id,
const LocationHint& location_hint,
CancellationFlag* cancellation_flag,
bool non_cellular) {
ErrorOr<WebRtcSocketWrapper> WebRtc::Connect(
const std::string& service_id, const WebrtcPeerId& remote_peer_id,
const LocationHint& location_hint, CancellationFlag* cancellation_flag,
bool non_cellular) {
service_id_to_connect_attempts_count_map_[service_id] = 1;
medium_->SetNonCellular(non_cellular);
ErrorOr<WebRtcSocketWrapper> wrapper_result = {
Error(OperationResultCode::DETAIL_UNKNOWN)};
while (service_id_to_connect_attempts_count_map_[service_id] <=
kConnectAttemptsLimit) {
if (cancellation_flag->Cancelled()) {
@@ -220,16 +224,18 @@ WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id,
<< "Attempt #"
<< service_id_to_connect_attempts_count_map_[service_id]
<< ": Cannot Connect with WebRtc due to cancel.";
return WebRtcSocketWrapper();
return {
Error(OperationResultCode::
CLIENT_CANCELLATION_CANCEL_WEB_RTC_OUTGOING_CONNECTION)};
}
NEARBY_LOGS(INFO) << "Attempt #"
<< service_id_to_connect_attempts_count_map_[service_id]
<< ": Beginning connection.";
auto wrapper_result = AttemptToConnect(service_id, remote_peer_id,
location_hint, cancellation_flag);
if (wrapper_result.IsValid()) {
return wrapper_result;
wrapper_result = AttemptToConnect(service_id, remote_peer_id, location_hint,
cancellation_flag);
if (wrapper_result.has_value()) {
return std::move(wrapper_result.value());
}
service_id_to_connect_attempts_count_map_[service_id]++;
@@ -237,10 +243,10 @@ WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id,
NEARBY_LOGS(WARNING) << "Giving up after " << kConnectAttemptsLimit
<< " attempts";
return WebRtcSocketWrapper();
return {Error(wrapper_result.error().operation_result_code().value())};
}
WebRtcSocketWrapper WebRtc::AttemptToConnect(
ErrorOr<WebRtcSocketWrapper> WebRtc::AttemptToConnect(
const std::string& service_id, const WebrtcPeerId& remote_peer_id,
const LocationHint& location_hint, CancellationFlag* cancellation_flag) {
ConnectionRequestInfo info = ConnectionRequestInfo();
@@ -266,7 +272,8 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
NEARBY_LOGS(WARNING) << "Cannot connect to WebRTC peer "
<< remote_peer_id.GetId()
<< " because WebRTC is not available.";
return WebRtcSocketWrapper();
return {
Error(OperationResultCode::MEDIUM_UNAVAILABLE_WEB_RTC_NOT_AVAILABLE)};
}
// Create a new ConnectionFlow for this connection attempt.
@@ -276,7 +283,7 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
NEARBY_LOGS(INFO) << "Cannot connect to WebRTC peer "
<< remote_peer_id.GetId()
<< " because we failed to create a ConnectionFlow.";
return WebRtcSocketWrapper();
return {Error(OperationResultCode::NEARBY_WEB_RTC_CONNECTION_FLOW_NULL)};
}
// Create a new SignalingMessenger so that we can communicate over Tachyon.
@@ -286,7 +293,9 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
NEARBY_LOGS(INFO) << "Cannot connect to WebRTC peer "
<< remote_peer_id.GetId()
<< " because we failed to create a SignalingMessenger.";
return WebRtcSocketWrapper();
return {
Error(OperationResultCode::
MISCELLEANEOUS_WEB_RTC_TACHYON_SIGNALING_MESSENGER_NULL)};
}
// This registers ourselves w/ Tachyon, creating a room from the PeerId.
@@ -303,7 +312,8 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
<< "Cannot connect to WebRTC peer " << remote_peer_id.GetId()
<< " because we failed to start receiving messages over Tachyon.";
info.signaling_messenger.reset();
return WebRtcSocketWrapper();
return {Error(OperationResultCode::
MISCELLEANEOUS_WEB_RTC_FAILED_TO_RECEIVE_MESSAGE)};
}
// Poke the remote device. This will cause them to send us an Offer.
@@ -314,7 +324,8 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
<< remote_peer_id.GetId()
<< " because we failed to poke the peer over Tachyon.";
info.signaling_messenger.reset();
return WebRtcSocketWrapper();
return {Error(OperationResultCode::
CONNECTIVITY_WEB_RTC_CONNECT_TO_TACHYON_FAILURE)};
}
// Create a new ConnectionRequest entry. This map will be used later to look
@@ -345,7 +356,8 @@ WebRtcSocketWrapper WebRtc::AttemptToConnect(
RemoveConnectionFlow(remote_peer_id);
info.signaling_messenger.reset();
requesting_connections_info_.erase(remote_peer_id.GetId());
return WebRtcSocketWrapper();
return {Error(OperationResultCode::
CONNECTIVITY_WEB_RTC_CLIENT_SOCKET_CREATION_FAILURE)};
}
// Clean up our ConnectionRequest.
+3 -2
View File
@@ -32,6 +32,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/expected.h"
#include "internal/platform/future.h"
#include "internal/platform/mutex.h"
#include "internal/platform/runnable.h"
@@ -84,7 +85,7 @@ class WebRtc {
// Initiates a WebRtc connection with peer device identified by |peer_id|
// with internal retry for maximum attempts of kConnectAttemptsLimit.
// Runs on @MainThread.
WebRtcSocketWrapper Connect(
ErrorOr<WebRtcSocketWrapper> Connect(
const std::string& service_id, const WebrtcPeerId& peer_id,
const location::nearby::connections::LocationHint& location_hint,
CancellationFlag* cancellation_flag, bool non_cellular)
@@ -150,7 +151,7 @@ class WebRtc {
// Attempt to initiates a WebRtc connection with peer device identified by
// |peer_id|.
// Runs on @MainThread.
WebRtcSocketWrapper AttemptToConnect(
ErrorOr<WebRtcSocketWrapper> AttemptToConnect(
const std::string& service_id, const WebrtcPeerId& peer_id,
const location::nearby::connections::LocationHint& location_hint,
CancellationFlag* cancellation_flag) ABSL_LOCKS_EXCLUDED(mutex_);
@@ -20,14 +20,16 @@
#include <memory>
#include "connections/implementation/mediums/webrtc_socket_stub.h"
#include "internal/platform/listeners.h"
#include "internal/platform/cancelable_alarm.h"
#include "internal/platform/expected.h"
#include "internal/platform/future.h"
#include "internal/platform/listeners.h"
namespace nearby {
namespace connections {
namespace mediums {
using ::location::nearby::connections::LocationHint;
using ::location::nearby::proto::connections::OperationResultCode;
WebRtc::WebRtc() = default;
@@ -50,11 +52,10 @@ bool WebRtc::StartAcceptingConnections(const std::string& service_id,
void WebRtc::StopAcceptingConnections(const std::string& service_id) {}
WebRtcSocketWrapper WebRtc::Connect(const std::string& service_id,
const WebrtcPeerId& remote_peer_id,
const LocationHint& location_hint,
CancellationFlag* cancellation_flag) {
return WebRtcSocketWrapper();
ErrorOr<WebRtcSocketWrapper> WebRtc::Connect(
const std::string& service_id, const WebrtcPeerId& remote_peer_id,
const LocationHint& location_hint, CancellationFlag* cancellation_flag) {
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
}
bool WebRtc::IsUsingCellular() { return false; }
@@ -26,6 +26,7 @@
#include "connections/implementation/mediums/webrtc_socket_stub.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/expected.h"
#include "internal/platform/listeners.h"
namespace nearby {
@@ -68,7 +69,7 @@ class WebRtc {
// Initiates a WebRtc connection with peer device identified by |peer_id|
// with internal retry for maximum attempts of kConnectAttemptsLimit.
// Runs on @MainThread.
WebRtcSocketWrapper Connect(
ErrorOr<WebRtcSocketWrapper> Connect(
const std::string& service_id, const WebrtcPeerId& peer_id,
const location::nearby::connections::LocationHint& location_hint,
CancellationFlag* cancellation_flag);
@@ -26,6 +26,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/exception.h"
#include "internal/platform/expected.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/future.h"
#include "internal/platform/medium_environment.h"
@@ -71,7 +72,7 @@ TEST_P(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
WebRtcTestParams params = GetParam();
env_.SetFeatureFlags(params.feature_flags);
WebRtc receiver, sender;
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
const WebrtcPeerId self_id("self_id");
const std::string service_id("NearbySharing");
LocationHint location_hint;
@@ -88,9 +89,10 @@ TEST_P(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
params.non_cellular);
CancellationFlag flag;
sender_socket = sender.Connect(service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_TRUE(sender_socket.IsValid());
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender.Connect(
service_id, self_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
ExceptionOr<bool> devices_connected = connected.Get();
ASSERT_TRUE(devices_connected.ok());
@@ -99,7 +101,7 @@ TEST_P(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
// Only shuts down signaling channel.
receiver.StopAcceptingConnections(service_id);
sender_socket.GetOutputStream().Write(message);
sender_socket_result.value().GetOutputStream().Write(message);
ExceptionOr<ByteArray> received_msg =
receiver_socket.GetInputStream().Read(/*size=*/32);
ASSERT_TRUE(received_msg.ok());
@@ -112,7 +114,7 @@ TEST_P(WebRtcTest, CanCancelConnect) {
WebRtcTestParams params = GetParam();
env_.SetFeatureFlags(params.feature_flags);
WebRtc receiver, sender;
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
const WebrtcPeerId self_id("self_id");
const std::string service_id("NearbySharing");
LocationHint location_hint;
@@ -129,17 +131,18 @@ TEST_P(WebRtcTest, CanCancelConnect) {
params.non_cellular);
CancellationFlag flag(true);
sender_socket = sender.Connect(service_id, self_id, location_hint, &flag,
params.non_cellular);
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender.Connect(
service_id, self_id, location_hint, &flag, params.non_cellular);
// If FeatureFlag is disabled, Cancelled is false as no-op.
if (!params.feature_flags.enable_cancellation_flag) {
EXPECT_TRUE(sender_socket.IsValid());
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
ExceptionOr<bool> devices_connected = connected.Get();
ASSERT_TRUE(devices_connected.ok());
EXPECT_TRUE(devices_connected.result());
sender_socket.GetOutputStream().Write(message);
sender_socket_result.value().GetOutputStream().Write(message);
ExceptionOr<ByteArray> received_msg =
receiver_socket.GetInputStream().Read(/*size=*/32);
ASSERT_TRUE(received_msg.ok());
@@ -147,7 +150,7 @@ TEST_P(WebRtcTest, CanCancelConnect) {
receiver_socket.Close();
} else {
EXPECT_FALSE(sender_socket.IsValid());
EXPECT_TRUE(sender_socket_result.has_error());
}
env_.Stop();
}
@@ -196,9 +199,9 @@ TEST_P(WebRtcTest, Connect_NoPeer) {
ASSERT_TRUE(webrtc.IsAvailable());
CancellationFlag flag;
WebRtcSocketWrapper wrapper_1 = webrtc.Connect(
ErrorOr<WebRtcSocketWrapper> wrapper_1_result = webrtc.Connect(
service_id, peer_id, location_hint, &flag, params.non_cellular);
EXPECT_FALSE(wrapper_1.IsValid());
EXPECT_TRUE(wrapper_1_result.has_error());
EXPECT_TRUE(webrtc.StartAcceptingConnections(
service_id, peer_id, location_hint, nullptr, params.non_cellular));
@@ -221,11 +224,11 @@ TEST_P(WebRtcTest, StartAcceptingConnection_ThenConnect) {
service_id, self_id, location_hint,
mock_accepted_callback_.AsStdFunction(), params.non_cellular));
CancellationFlag flag;
WebRtcSocketWrapper wrapper =
ErrorOr<WebRtcSocketWrapper> wrapper_result =
webrtc.Connect(service_id, WebrtcPeerId("random_peer_id"), location_hint,
&flag, params.non_cellular);
EXPECT_TRUE(webrtc.IsAcceptingConnections(service_id));
EXPECT_FALSE(wrapper.IsValid());
EXPECT_TRUE(wrapper_result.has_error());
EXPECT_FALSE(webrtc.StartAcceptingConnections(
service_id, self_id, location_hint,
mock_accepted_callback_.AsStdFunction(), params.non_cellular));
@@ -258,7 +261,7 @@ TEST_P(WebRtcTest, StartAndStopAcceptingConnections) {
TEST_P(WebRtcTest, ConnectTwice) {
env_.Start({.webrtc_enabled = true});
WebRtc receiver, sender, device_c;
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
WebRtcTestParams params = GetParam();
const WebrtcPeerId self_id("self_id"), other_id("other_id");
const std::string service_id("NearbySharing");
@@ -281,23 +284,26 @@ TEST_P(WebRtcTest, ConnectTwice) {
params.non_cellular);
CancellationFlag flag;
sender_socket = sender.Connect(service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_TRUE(sender_socket.IsValid());
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender.Connect(
service_id, self_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
ExceptionOr<bool> devices_connected = connected.Get();
ASSERT_TRUE(devices_connected.ok());
EXPECT_TRUE(devices_connected.result());
WebRtcSocketWrapper socket = sender.Connect(
ErrorOr<WebRtcSocketWrapper> socket_result = sender.Connect(
service_id, other_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(socket.IsValid());
socket.Close();
EXPECT_TRUE(socket_result.has_value());
EXPECT_TRUE(socket_result.value().IsValid());
socket_result.value().Close();
EXPECT_TRUE(receiver_socket.IsValid());
EXPECT_TRUE(sender_socket.IsValid());
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
sender_socket.GetOutputStream().Write(message);
sender_socket_result.value().GetOutputStream().Write(message);
ExceptionOr<ByteArray> received_msg =
receiver_socket.GetInputStream().Read(/*size=*/32);
ASSERT_TRUE(received_msg.ok());
@@ -330,9 +336,10 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndAbort) {
params.non_cellular);
CancellationFlag flag;
sender_socket = sender.Connect(service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_TRUE(sender_socket.IsValid());
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender.Connect(
service_id, self_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
ExceptionOr<bool> devices_connected = connected.Get();
ASSERT_TRUE(devices_connected.ok());
@@ -347,7 +354,7 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndAbort) {
TEST_P(WebRtcTest, ConnectBothDevicesAndSendData) {
env_.Start({.webrtc_enabled = true});
WebRtc receiver, sender;
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
WebRtcTestParams params = GetParam();
const WebrtcPeerId self_id("self_id");
const std::string service_id("NearbySharing");
@@ -365,15 +372,16 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndSendData) {
params.non_cellular);
CancellationFlag flag;
sender_socket = sender.Connect(service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_TRUE(sender_socket.IsValid());
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender.Connect(
service_id, self_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
ExceptionOr<bool> devices_connected = connected.Get();
ASSERT_TRUE(devices_connected.ok());
EXPECT_TRUE(devices_connected.result());
sender_socket.GetOutputStream().Write(message);
sender_socket_result.value().GetOutputStream().Write(message);
ExceptionOr<ByteArray> received_msg =
receiver_socket.GetInputStream().Read(/*size=*/32);
ASSERT_TRUE(received_msg.ok());
@@ -397,10 +405,10 @@ TEST_P(WebRtcTest, Connect_NullPeerConnection) {
ASSERT_TRUE(webrtc.IsAvailable());
CancellationFlag flag;
WebRtcSocketWrapper wrapper =
ErrorOr<WebRtcSocketWrapper> wrapper_result =
webrtc.Connect(service_id, WebrtcPeerId("random_peer_id"), location_hint,
&flag, params.non_cellular);
EXPECT_FALSE(wrapper.IsValid());
EXPECT_TRUE(wrapper_result.has_error());
env_.Stop();
}
@@ -479,8 +487,8 @@ TEST_P(WebRtcTest, CancelDuringConnect) {
},
params.non_cellular);
sender_socket = sender->Connect(service_id, self_id, location_hint,
&sender_flag, params.non_cellular);
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender->Connect(
service_id, self_id, location_hint, &sender_flag, params.non_cellular);
// Since the flag was cancelled during the initial `AttemptToConnect`, except
// only one attempt instead of the usual three, because the cancellation flag
@@ -488,7 +496,7 @@ TEST_P(WebRtcTest, CancelDuringConnect) {
// Because of the way the iteration happens, the check for is cancelled
// happens after the counter has already been incremented, but before the
// attempt actually occurs.
EXPECT_FALSE(sender_socket.IsValid());
EXPECT_TRUE(sender_socket_result.has_error());
EXPECT_EQ(2, sender->connect_attempts_count(service_id));
env_.Stop();
@@ -505,7 +513,7 @@ TEST_P(WebRtcTest, CancelBeforeConnect) {
.enable_cancellation_flag = true,
});
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
const WebrtcPeerId self_id("self_id");
const std::string service_id("NearbySharing");
LocationHint location_hint;
@@ -529,12 +537,12 @@ TEST_P(WebRtcTest, CancelBeforeConnect) {
},
params.non_cellular);
sender_socket = sender->Connect(service_id, self_id, location_hint,
&sender_flag, params.non_cellular);
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender->Connect(
service_id, self_id, location_hint, &sender_flag, params.non_cellular);
// Expect an invalid socket from stopping during the first attempt to connect,
// because `Connect` returned immediatley when it checked for cancellation.
EXPECT_FALSE(sender_socket.IsValid());
EXPECT_TRUE(sender_socket_result.has_error());
EXPECT_EQ(1, sender->connect_attempts_count(service_id));
env_.Stop();
@@ -552,7 +560,7 @@ TEST_P(WebRtcTest, CancelDuringConnect_MultipleConnect) {
.enable_cancellation_flag = true,
});
WebRtcSocketWrapper receiver_socket, sender_socket;
WebRtcSocketWrapper receiver_socket;
const WebrtcPeerId self_id("self_id");
const std::string ns_service_id("NearbySharing");
const std::string ph_service_id("PhoneHub");
@@ -579,17 +587,18 @@ TEST_P(WebRtcTest, CancelDuringConnect_MultipleConnect) {
params.non_cellular);
// Simulate a successful connect for the endpoint of NearbySharing.
sender_socket = sender->Connect(ns_service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_TRUE(sender_socket.IsValid());
ErrorOr<WebRtcSocketWrapper> sender_socket_result = sender->Connect(
ns_service_id, self_id, location_hint, &flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_value());
EXPECT_TRUE(sender_socket_result.value().IsValid());
// Calls `CancellationFlag::Cancel` during a call to `GetSignalingMessenger`
// to simulate the cancellation occuring during an `AttemptToConnect` for the
// endpoint of Phone Hub.
fake_sender_medium->TriggerCancellationDuringGetSignalingMessenger();
sender_socket = sender->Connect(ph_service_id, self_id, location_hint, &flag,
params.non_cellular);
EXPECT_FALSE(sender_socket.IsValid());
sender_socket_result = sender->Connect(ph_service_id, self_id, location_hint,
&flag, params.non_cellular);
EXPECT_TRUE(sender_socket_result.has_error());
// Since the flag was cancelled during the initial `AttemptToConnect`, except
// only one attempt instead of the usual three, because the cancellation flag
@@ -44,7 +44,6 @@ using ::location::nearby::connections::LocationStandard;
using ::location::nearby::proto::connections::OperationResultCode;
} // namespace
// TODO(edwinwu): Add exact OperationResultCode for WebrtcBwuHandler.
WebrtcBwuHandler::WebrtcIncomingSocket::WebrtcIncomingSocket(
const std::string& name, mediums::WebRtcSocketWrapper socket)
: name_(name), socket_(socket) {}
@@ -78,14 +77,14 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel(
<< peer_id.GetId() << ", location hint "
<< absl::StrCat(location_hint.location());
mediums::WebRtcSocketWrapper socket = webrtc_.Connect(
ErrorOr<mediums::WebRtcSocketWrapper> socket_result = webrtc_.Connect(
service_id, peer_id, location_hint,
client->GetCancellationFlag(endpoint_id), client->GetWebRtcNonCellular());
if (!socket.IsValid()) {
if (socket_result.has_error()) {
NEARBY_LOGS(ERROR) << "WebRtcBwuHandler failed to connect to remote peer ("
<< peer_id.GetId() << ") on endpoint " << endpoint_id
<< ", aborting upgrade.";
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
return {Error(socket_result.error().operation_result_code().value())};
}
NEARBY_LOGS(INFO) << "WebRtcBwuHandler successfully connected to remote "
@@ -95,13 +94,14 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel(
// Create a new WebRtcEndpointChannel.
auto channel = std::make_unique<WebRtcEndpointChannel>(
service_id, /*channel_name=*/service_id, socket);
service_id, /*channel_name=*/service_id, socket_result.value());
if (channel == nullptr) {
socket.Close();
socket_result.value().Close();
NEARBY_LOGS(ERROR)
<< "WebRtcBwuHandler failed to create new EndpointChannel for "
"outgoing socket, aborting upgrade.";
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
return {Error(
OperationResultCode::NEARBY_WEB_RTC_ENDPOINT_CHANNEL_CREATION_FAILURE)};
}
return {std::move(channel)};