Roll forward to cl/343180341.

This commit is contained in:
hai007
2020-11-18 16:28:10 -08:00
parent 038821b7bd
commit 25bf896257
8 changed files with 49 additions and 24 deletions
+2 -2
View File
@@ -54,8 +54,8 @@ bool WebRtc::IsAcceptingConnections(const std::string& service_id) {
return role_ == Role::kOfferer;
}
bool WebRtc::StartAcceptingConnections(const PeerId& self_id,
const std::string& service_id,
bool WebRtc::StartAcceptingConnections(const std::string& service_id,
const PeerId& self_id,
const LocationHint& location_hint,
AcceptedConnectionCallback callback) {
if (!IsAvailable()) {
+2 -2
View File
@@ -61,8 +61,8 @@ class WebRtc {
// Prepares the device to accept incoming WebRtc connections. Returns a
// boolean value indicating if the device has started accepting connections.
// Runs on @MainThread.
bool StartAcceptingConnections(const PeerId& self_id,
const std::string& service_id,
bool StartAcceptingConnections(const std::string& service_id,
const PeerId& self_id,
const LocationHint& location_hint,
AcceptedConnectionCallback callback)
ABSL_LOCKS_EXCLUDED(mutex_);
+12 -12
View File
@@ -43,10 +43,10 @@ TEST_F(WebRtcTest, StartAcceptingConnectionTwice) {
ASSERT_TRUE(webrtc.IsAvailable());
ASSERT_TRUE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
EXPECT_FALSE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
EXPECT_TRUE(webrtc.IsAcceptingConnections(std::string{}));
}
@@ -64,7 +64,7 @@ TEST_F(WebRtcTest, Connect_DataChannelTimeOut) {
EXPECT_FALSE(wrapper_1.IsValid());
EXPECT_TRUE(webrtc.StartAcceptingConnections(
peer_id, service_id, location_hint, AcceptedConnectionCallback()));
service_id, peer_id, location_hint, AcceptedConnectionCallback()));
}
// Tests the flow when the device calls Connect() after calling
@@ -81,14 +81,14 @@ TEST_F(WebRtcTest, StartAcceptingConnection_ThenConnect) {
ASSERT_TRUE(webrtc.IsAvailable());
ASSERT_TRUE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
WebRtcSocketWrapper wrapper =
webrtc.Connect(PeerId("random_peer_id"), location_hint);
EXPECT_TRUE(webrtc.IsAcceptingConnections(std::string{}));
EXPECT_FALSE(wrapper.IsValid());
EXPECT_FALSE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
}
@@ -106,7 +106,7 @@ TEST_F(WebRtcTest, StartAndStopAcceptingConnections) {
ASSERT_TRUE(webrtc.IsAvailable());
ASSERT_TRUE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
webrtc.StopAcceptingConnections(service_id);
EXPECT_FALSE(webrtc.IsAcceptingConnections(std::string{}));
@@ -124,7 +124,7 @@ TEST_F(WebRtcTest, ConnectTwice) {
ByteArray message("message xyz");
receiver.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{[&receiver_socket, connected](WebRtcSocketWrapper wrapper) mutable {
receiver_socket = wrapper;
connected.Set(receiver_socket.IsValid());
@@ -133,7 +133,7 @@ TEST_F(WebRtcTest, ConnectTwice) {
using MockAcceptedCallback =
testing::MockFunction<void(WebRtcSocketWrapper socket)>;
testing::StrictMock<MockAcceptedCallback> mock_accepted_callback_;
device_c.StartAcceptingConnections(other_id, service_id, location_hint,
device_c.StartAcceptingConnections(service_id, other_id, location_hint,
{mock_accepted_callback_.AsStdFunction()});
sender_socket = sender.Connect(self_id, location_hint);
@@ -170,7 +170,7 @@ TEST_F(WebRtcTest, ConnectBothDevicesAndAbort) {
ByteArray message("message xyz");
receiver.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{[&receiver_socket, connected](WebRtcSocketWrapper wrapper) mutable {
receiver_socket = wrapper;
connected.Set(receiver_socket.IsValid());
@@ -198,7 +198,7 @@ TEST_F(WebRtcTest, ConnectBothDevicesAndSendData) {
ByteArray message("message");
receiver.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{[&receiver_socket, connected](WebRtcSocketWrapper wrapper) mutable {
receiver_socket = wrapper;
connected.Set(receiver_socket.IsValid());
@@ -232,7 +232,7 @@ TEST_F(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
ByteArray message("message xyz");
receiver.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{[&receiver_socket, connected](WebRtcSocketWrapper wrapper) mutable {
receiver_socket = wrapper;
connected.Set(receiver_socket.IsValid());
@@ -270,7 +270,7 @@ TEST_F(WebRtcTest, StartAcceptingConnections_NullPeerConnection) {
ASSERT_TRUE(webrtc.IsAvailable());
EXPECT_FALSE(webrtc.StartAcceptingConnections(
self_id, service_id, location_hint,
service_id, self_id, location_hint,
{mock_accepted_callback_.AsStdFunction()}));
}
+21 -7
View File
@@ -37,8 +37,7 @@ bool P2pClusterPcpHandler::ShouldAcceptBluetoothConnections(
P2pClusterPcpHandler::P2pClusterPcpHandler(
Mediums* mediums, EndpointManager* endpoint_manager,
EndpointChannelManager* endpoint_channel_manager, BwuManager* bwu_manager,
InjectedBluetoothDeviceStore& injected_bluetooth_device_store,
Pcp pcp)
InjectedBluetoothDeviceStore& injected_bluetooth_device_store, Pcp pcp)
: BasePcpHandler(mediums, endpoint_manager, endpoint_channel_manager,
bwu_manager, pcp),
bluetooth_radio_(mediums->GetBluetoothRadio()),
@@ -103,6 +102,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
if (bluetooth_medium != proto::connections::UNKNOWN_MEDIUM) {
NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartAdvertisingImpl: BT added");
mediums_started_successfully.push_back(bluetooth_medium);
bluetooth_classic_advertiser_client_id_ = client->GetClientId();
}
}
@@ -134,7 +134,14 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
}
Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
bluetooth_medium_.TurnOffDiscoverability();
if (client->GetClientId() == bluetooth_classic_advertiser_client_id_) {
bluetooth_medium_.TurnOffDiscoverability();
} else {
NEARBY_LOG(INFO,
"Skipped BT TurnOffDiscoverability for client %d, client that "
"turned on discoverability is %d",
client->GetClientId(), bluetooth_classic_advertiser_client_id_);
}
bluetooth_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
ble_medium_.StopAdvertising(client->GetAdvertisingServiceId());
@@ -581,6 +588,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
if (bluetooth_medium != proto::connections::UNKNOWN_MEDIUM) {
NEARBY_LOG(INFO, "P2pClusterPcpHandler::StartDiscoveryImpl: BT added");
mediums_started_successfully.push_back(bluetooth_medium);
bluetooth_classic_discoverer_client_id_ = client->GetClientId();
}
}
@@ -615,7 +623,14 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
wifi_lan_medium_.StopDiscovery(client->GetDiscoveryServiceId());
bluetooth_medium_.StopDiscovery();
if (client->GetClientId() == bluetooth_classic_discoverer_client_id_) {
bluetooth_medium_.StopDiscovery();
} else {
NEARBY_LOG(INFO,
"Skipped BT stopDiscovery for client %d, client that started "
"discovery is %d",
client->GetClientId(), bluetooth_classic_discoverer_client_id_);
}
ble_medium_.StopScanning(client->GetDiscoveryServiceId());
return {Status::kSuccess};
}
@@ -632,8 +647,7 @@ Status P2pClusterPcpHandler::InjectEndpointImpl(
BluetoothDevice remote_bluetooth_device =
injected_bluetooth_device_store_.CreateInjectedBluetoothDevice(
metadata.remote_bluetooth_mac_address,
metadata.endpoint_id,
metadata.remote_bluetooth_mac_address, metadata.endpoint_id,
metadata.endpoint_info,
GenerateHash(service_id, BluetoothDeviceName::kServiceIdHashLength),
GetPcp());
@@ -1143,7 +1157,7 @@ P2pClusterPcpHandler::StartListeningForWebRtcConnections(
service_id, local_endpoint_id, local_endpoint_info);
std::string empty_country_code;
if (!webrtc_medium_.StartAcceptingConnections(
self_id, service_id, Utils::BuildLocationHint(empty_country_code),
service_id, self_id, Utils::BuildLocationHint(empty_country_code),
{[this, client,
local_endpoint_info](mediums::WebRtcSocketWrapper socket) {
if (!socket.IsValid()) {
@@ -207,6 +207,8 @@ class P2pClusterPcpHandler : public BasePcpHandler {
WifiLan& wifi_lan_medium_;
mediums::WebRtc& webrtc_medium_;
InjectedBluetoothDeviceStore& injected_bluetooth_device_store_;
std::int64_t bluetooth_classic_discoverer_client_id_;
std::int64_t bluetooth_classic_advertiser_client_id_;
};
} // namespace connections
+1 -1
View File
@@ -63,7 +63,7 @@ ByteArray WebrtcBwuHandler::InitializeUpgradedMediumForEndpoint(
mediums::PeerId self_id{mediums::PeerId::FromRandom()};
if (!webrtc_.IsAcceptingConnections(service_id)) {
if (!webrtc_.StartAcceptingConnections(
self_id, upgrade_service_id, location_hint,
upgrade_service_id, self_id, location_hint,
{
.accepted_cb = absl::bind_front(
&WebrtcBwuHandler::OnIncomingWebrtcConnection, this, client,
+1
View File
@@ -1,6 +1,7 @@
#ifndef PLATFORM_BASE_BYTE_ARRAY_H_
#define PLATFORM_BASE_BYTE_ARRAY_H_
#include <algorithm>
#include <array>
#include <cstdint>
#include <string>