Merge pull request #21 from hai007/cl-343180341

Roll forward to Cl/343180341
This commit is contained in:
hai007
2020-11-18 16:36:15 -08:00
committed by GitHub
8 changed files with 49 additions and 24 deletions
+2 -2
View File
@@ -68,8 +68,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
@@ -75,8 +75,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
@@ -57,10 +57,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{}));
}
@@ -78,7 +78,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
@@ -95,14 +95,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()}));
}
@@ -120,7 +120,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{}));
@@ -138,7 +138,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());
@@ -147,7 +147,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);
@@ -184,7 +184,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());
@@ -212,7 +212,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());
@@ -246,7 +246,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());
@@ -284,7 +284,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
@@ -51,8 +51,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()),
@@ -117,6 +116,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();
}
}
@@ -148,7 +148,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());
@@ -595,6 +602,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();
}
}
@@ -629,7 +637,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};
}
@@ -646,8 +661,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());
@@ -1157,7 +1171,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()) {
@@ -221,6 +221,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
@@ -77,7 +77,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
@@ -15,6 +15,7 @@
#ifndef PLATFORM_BASE_BYTE_ARRAY_H_
#define PLATFORM_BASE_BYTE_ARRAY_H_
#include <algorithm>
#include <array>
#include <cstdint>
#include <string>
+8
View File
@@ -286,6 +286,14 @@ enum ConnectError {
// Next ID :44
}
// The error for event DISCONNECT. The range between 31 and 99.
enum DisconnectError {
// System error, failed to disconnect the network.
DISCONNECT_NETWORK_FAILED = 31;
// Next ID :32
}
enum Description {
reserved 28, 29;