mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Move BwuHandler creation into medium.
PiperOrigin-RevId: 919149551
This commit is contained in:
committed by
Copybara-Service
parent
bc4cb39dc5
commit
97ea469006
@@ -32,20 +32,10 @@
|
||||
#include "connections/implementation/endpoint_channel_manager.h"
|
||||
#include "connections/implementation/endpoint_manager.h"
|
||||
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
|
||||
#include "connections/implementation/mediums/awdl_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/bluetooth_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_lan_bwu_handler.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/service_id_constants.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#ifdef NO_WEBRTC
|
||||
#include "connections/implementation/mediums/webrtc_bwu_handler_stub.h"
|
||||
#else
|
||||
#include "connections/implementation/mediums/webrtc_bwu_handler.h"
|
||||
#endif
|
||||
#include "connections/implementation/mediums/wifi_direct_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot_bwu_handler.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
@@ -134,43 +124,37 @@ void BwuManager::InitBwuHandlers() {
|
||||
if (config_.allow_upgrade_to.awdl) {
|
||||
handlers_.emplace(
|
||||
Medium::AWDL,
|
||||
std::make_unique<AwdlBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetAwdl().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
if (config_.allow_upgrade_to.wifi_hotspot) {
|
||||
handlers_.emplace(
|
||||
Medium::WIFI_HOTSPOT,
|
||||
std::make_unique<WifiHotspotBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetWifiHotspot().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
if (config_.allow_upgrade_to.wifi_direct) {
|
||||
handlers_.emplace(
|
||||
Medium::WIFI_DIRECT,
|
||||
std::make_unique<WifiDirectBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetWifiDirect().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
if (config_.allow_upgrade_to.wifi_lan) {
|
||||
handlers_.emplace(
|
||||
Medium::WIFI_LAN,
|
||||
std::make_unique<WifiLanBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetWifiLan().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
if (config_.allow_upgrade_to.web_rtc) {
|
||||
handlers_.emplace(
|
||||
Medium::WEB_RTC,
|
||||
std::make_unique<WebrtcBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetWebRtc().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
if (config_.allow_upgrade_to.bluetooth) {
|
||||
handlers_.emplace(
|
||||
Medium::BLUETOOTH,
|
||||
std::make_unique<BluetoothBwuHandler>(
|
||||
*mediums_,
|
||||
mediums_->GetBluetoothClassic().CreateBwuHandler(
|
||||
absl::bind_front(&BwuManager::OnIncomingConnection, this)));
|
||||
}
|
||||
}
|
||||
@@ -196,8 +180,9 @@ void BwuManager::Shutdown() {
|
||||
medium_ = Medium::UNKNOWN_MEDIUM;
|
||||
endpoint_id_to_bwu_medium_.clear();
|
||||
for (auto& medium_handler_pair : handlers_) {
|
||||
assert(medium_handler_pair.second);
|
||||
medium_handler_pair.second->RevertInitiatorState();
|
||||
if (medium_handler_pair.second != nullptr) {
|
||||
medium_handler_pair.second->RevertInitiatorState();
|
||||
}
|
||||
}
|
||||
handlers_.clear();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ cc_library(
|
||||
"bluetooth_endpoint_channel.cc",
|
||||
"bluetooth_radio.cc",
|
||||
"mediums.cc",
|
||||
"webrtc_bwu_handler.cc",
|
||||
"webrtc_bwu_handler_stub.cc",
|
||||
"webrtc_endpoint_channel.cc",
|
||||
"wifi_direct.cc",
|
||||
"wifi_direct_bwu_handler.cc",
|
||||
@@ -56,8 +54,6 @@ cc_library(
|
||||
"bluetooth_endpoint_channel.h",
|
||||
"bluetooth_radio.h",
|
||||
"mediums.h",
|
||||
"webrtc_bwu_handler.h",
|
||||
"webrtc_bwu_handler_stub.h",
|
||||
"webrtc_endpoint_channel.h",
|
||||
"wifi.h",
|
||||
"wifi_direct.h",
|
||||
@@ -110,6 +106,7 @@ cc_library(
|
||||
"//internal/platform/implementation:platform",
|
||||
"//internal/platform/implementation:wifi_utils",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/base:nullability",
|
||||
"@com_google_absl//absl/container:btree",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
@@ -190,6 +187,7 @@ cc_library(
|
||||
deps = [
|
||||
":webrtc_peer_id",
|
||||
":webrtc_socket",
|
||||
"//connections/implementation:bwu_handler",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:cancellation_flag",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "connections/implementation/mediums/awdl.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -22,6 +23,8 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/awdl_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "internal/platform/awdl.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
@@ -471,5 +474,11 @@ ErrorOr<AwdlSocket> Awdl::InternalConnect(
|
||||
return socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> Awdl::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
return std::make_unique<AwdlBwuHandler>(
|
||||
this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define CORE_INTERNAL_MEDIUMS_AWDL_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -24,6 +25,7 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "internal/platform/awdl.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -129,6 +131,9 @@ class Awdl {
|
||||
AwdlCredential GetCredentials(const std::string& service_id)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
struct AdvertisingInfo {
|
||||
bool Empty() const { return nsd_service_infos.empty(); }
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
@@ -28,7 +29,6 @@
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/awdl.h"
|
||||
#include "connections/implementation/mediums/awdl_endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/service_id_constants.h"
|
||||
@@ -56,9 +56,10 @@ constexpr absl::string_view kAwdlServiceIdSuffixForServiceType = "_AWDL";
|
||||
} // namespace
|
||||
|
||||
AwdlBwuHandler::AwdlBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
Awdl* absl_nonnull awdl_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
awdl_medium_(*awdl_medium) {}
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over AWDL using this info.
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/awdl.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "internal/platform/awdl.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
@@ -35,8 +35,8 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class AwdlBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit AwdlBwuHandler(
|
||||
Mediums& mediums,
|
||||
AwdlBwuHandler(
|
||||
Awdl* absl_nonnull awdl_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
@@ -80,8 +80,7 @@ class AwdlBwuHandler : public BaseBwuHandler {
|
||||
std::string GenerateServiceName();
|
||||
std::string GeneratePassword();
|
||||
|
||||
Mediums& mediums_;
|
||||
Awdl& awdl_medium_{mediums_.GetAwdl()};
|
||||
Awdl& awdl_medium_;
|
||||
NsdServiceInfo nsd_service_info_;
|
||||
};
|
||||
|
||||
|
||||
@@ -127,7 +127,8 @@ constexpr absl::string_view kChannelName{"channel_name"};
|
||||
class AwdlBwuHandlerTest : public ::testing::Test {
|
||||
protected:
|
||||
AwdlBwuHandlerTest()
|
||||
: handler_(mediums_, incoming_connection_callback_.AsStdFunction()) {}
|
||||
: handler_(&mediums_.GetAwdl(),
|
||||
incoming_connection_callback_.AsStdFunction()) {}
|
||||
|
||||
void SetUp() override {
|
||||
// By default, network is connected.
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/bluetooth_classic.h"
|
||||
#include "connections/implementation/mediums/bluetooth_endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
@@ -43,9 +45,12 @@ using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
BluetoothBwuHandler::BluetoothBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
BluetoothRadio* absl_nonnull bluetooth_radio,
|
||||
BluetoothClassic* absl_nonnull bluetooth_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
bluetooth_radio_(*bluetooth_radio),
|
||||
bluetooth_medium_(*bluetooth_medium) {}
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over BT using this info.
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/bluetooth_classic.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -35,8 +36,9 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class BluetoothBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit BluetoothBwuHandler(
|
||||
Mediums& mediums,
|
||||
BluetoothBwuHandler(
|
||||
BluetoothRadio* absl_nonnull bluetooth_radio,
|
||||
BluetoothClassic* absl_nonnull bluetooth_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
@@ -75,9 +77,8 @@ class BluetoothBwuHandler : public BaseBwuHandler {
|
||||
const std::string& upgrade_service_id,
|
||||
BluetoothSocket socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
BluetoothRadio& bluetooth_radio_{mediums_.GetBluetoothRadio()};
|
||||
BluetoothClassic& bluetooth_medium_{mediums_.GetBluetoothClassic()};
|
||||
BluetoothRadio& bluetooth_radio_;
|
||||
BluetoothClassic& bluetooth_medium_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -54,7 +54,8 @@ TEST_F(BluetoothBwuTest, CanCreateBwuHandler) {
|
||||
ClientProxy client;
|
||||
Mediums mediums;
|
||||
|
||||
auto handler = std::make_unique<BluetoothBwuHandler>(mediums, nullptr);
|
||||
auto handler = std::make_unique<BluetoothBwuHandler>(
|
||||
&mediums.GetBluetoothRadio(), &mediums.GetBluetoothClassic(), nullptr);
|
||||
|
||||
handler->InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"B",
|
||||
/*endpoint_id=*/"2");
|
||||
@@ -73,9 +74,10 @@ TEST_F(BluetoothBwuTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
ExceptionOr<OfflineFrame> upgrade_frame;
|
||||
|
||||
auto handler_1 = std::make_unique<BluetoothBwuHandler>(
|
||||
mediums_1, [&](ClientProxy* client,
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection>
|
||||
mutable_connection) {
|
||||
&mediums_1.GetBluetoothRadio(), &mediums_1.GetBluetoothClassic(),
|
||||
[&](ClientProxy* client,
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection>
|
||||
mutable_connection) {
|
||||
LOG(WARNING) << "Server socket connection accept call back";
|
||||
accept_latch.CountDown();
|
||||
EXPECT_TRUE(end_latch.Await(kWaitDuration).result());
|
||||
@@ -99,7 +101,9 @@ TEST_F(BluetoothBwuTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
// Wait till client_1 started as Bluetooth and then connect to it
|
||||
EXPECT_TRUE(start_latch.Await(kWaitDuration).result());
|
||||
std::unique_ptr<BwuHandler> handler_2 =
|
||||
std::make_unique<BluetoothBwuHandler>(mediums_2, nullptr);
|
||||
std::make_unique<BluetoothBwuHandler>(
|
||||
&mediums_2.GetBluetoothRadio(), &mediums_2.GetBluetoothClassic(),
|
||||
nullptr);
|
||||
|
||||
client_executor.Execute([&]() {
|
||||
auto bwu_frame =
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/implementation/mediums/bluetooth_bwu_handler.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
@@ -565,5 +567,12 @@ std::string BluetoothClassic::GenerateUuidFromString(const std::string& data) {
|
||||
return std::string(Uuid(data));
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> BluetoothClassic::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
return std::make_unique<BluetoothBwuHandler>(
|
||||
&radio_, this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
@@ -126,6 +127,9 @@ class BluetoothClassic {
|
||||
bool IsDiscovering(const std::string& serviceId) const
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
protected:
|
||||
// Use for unit tests only to inject a BluetoothClassicMedium.
|
||||
BluetoothClassic(BluetoothRadio& radio,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/webrtc_peer_id.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "connections/implementation/proto/offline_wire_formats.pb.h"
|
||||
@@ -79,6 +80,11 @@ class WebRtc {
|
||||
}
|
||||
|
||||
virtual bool IsUsingCellular() { return false; }
|
||||
|
||||
virtual std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mediums
|
||||
|
||||
@@ -103,8 +103,14 @@ cc_library(
|
||||
|
||||
cc_library(
|
||||
name = "webrtc_impl",
|
||||
srcs = ["webrtc_impl.cc"],
|
||||
hdrs = ["webrtc_impl.h"],
|
||||
srcs = [
|
||||
"webrtc_bwu_handler.cc",
|
||||
"webrtc_impl.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"webrtc_bwu_handler.h",
|
||||
"webrtc_impl.h",
|
||||
],
|
||||
visibility = [
|
||||
"//connections/implementation/mediums:__pkg__",
|
||||
],
|
||||
@@ -113,18 +119,25 @@ cc_library(
|
||||
":signaling_frames",
|
||||
":webrtc",
|
||||
":webrtc_medium",
|
||||
"//connections:core_types",
|
||||
"//connections/implementation:bwu_handler",
|
||||
"//connections/implementation:client_proxy",
|
||||
"//connections/implementation:endpoint_channel",
|
||||
"//connections/implementation:offline_frames",
|
||||
"//connections/implementation/mediums",
|
||||
"//connections/implementation/mediums:webrtc",
|
||||
"//connections/implementation/mediums:webrtc_peer_id",
|
||||
"//connections/implementation/mediums:webrtc_socket",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:cancellation_flag",
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:types",
|
||||
"//proto/mediums:web_rtc_signaling_frames_cc_proto",
|
||||
# "//third_party/webrtc/files/stable/webrtc/api:jsep",
|
||||
"//third_party/webrtc/files/stable/webrtc/rtc_base:network_constants",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/base:nullability",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/functional:bind_front",
|
||||
|
||||
+6
-8
@@ -12,9 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef NO_WEBRTC
|
||||
|
||||
#include "connections/implementation/mediums/webrtc_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/webrtc/webrtc_bwu_handler.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -24,7 +22,8 @@
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/mediums/webrtc.h"
|
||||
#include "connections/implementation/mediums/webrtc_endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/webrtc_peer_id.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
@@ -68,9 +67,10 @@ void WebrtcBwuHandler::WebrtcIncomingSocket::Close() { socket_->Close(); }
|
||||
std::string WebrtcBwuHandler::WebrtcIncomingSocket::ToString() { return name_; }
|
||||
|
||||
WebrtcBwuHandler::WebrtcBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
mediums::WebRtc* absl_nonnull webrtc_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
webrtc_(*webrtc_medium) {}
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WebRTC using this info.
|
||||
@@ -179,5 +179,3 @@ void WebrtcBwuHandler::OnIncomingWebrtcConnection(
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
+7
-12
@@ -12,19 +12,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_H_
|
||||
|
||||
#ifndef NO_WEBRTC
|
||||
#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_BWU_HANDLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/webrtc.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "connections/medium_selector.h"
|
||||
@@ -37,8 +35,8 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit WebrtcBwuHandler(
|
||||
Mediums& mediums,
|
||||
WebrtcBwuHandler(
|
||||
mediums::WebRtc* absl_nonnull webrtc_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
@@ -78,13 +76,10 @@ class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
std::shared_ptr<mediums::WebRtcSocket> socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
mediums::WebRtc& webrtc_{mediums_.GetWebRtc()};
|
||||
mediums::WebRtc& webrtc_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_H_
|
||||
#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_WEBRTC_BWU_HANDLER_H_
|
||||
@@ -23,10 +23,12 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/webrtc/connection_flow.h"
|
||||
#include "connections/implementation/mediums/webrtc/session_description_wrapper.h"
|
||||
#include "connections/implementation/mediums/webrtc/signaling_frames.h"
|
||||
#include "connections/implementation/mediums/webrtc/webrtc.h"
|
||||
#include "connections/implementation/mediums/webrtc/webrtc_bwu_handler.h"
|
||||
#include "connections/implementation/mediums/webrtc_peer_id.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
@@ -784,6 +786,12 @@ bool WebRtcImpl::IsUsingCellular() {
|
||||
return is_using_cellular_;
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> WebRtcImpl::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
return std::make_unique<WebrtcBwuHandler>(
|
||||
this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace mediums
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/webrtc.h"
|
||||
#include "connections/implementation/mediums/webrtc/connection_flow.h"
|
||||
#include "connections/implementation/mediums/webrtc/session_description_wrapper.h"
|
||||
@@ -68,6 +69,9 @@ class WebRtcImpl : public WebRtc {
|
||||
CancellationFlag* cancellation_flag, bool non_cellular) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool IsUsingCellular() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback)
|
||||
override;
|
||||
|
||||
protected:
|
||||
// Use for unit tests only to inject a WebRtcMedium.
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifdef NO_WEBRTC
|
||||
|
||||
#include "connections/implementation/mediums/webrtc_bwu_handler_stub.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
WebrtcBwuHandler::WebrtcIncomingSocket::WebrtcIncomingSocket(
|
||||
const std::string& name, std::shared_ptr<mediums::WebRtcSocket> socket)
|
||||
: name_(name), socket_(std::move(socket)) {}
|
||||
|
||||
void WebrtcBwuHandler::WebrtcIncomingSocket::Close() {}
|
||||
|
||||
std::string WebrtcBwuHandler::WebrtcIncomingSocket::ToString() { return ""; }
|
||||
|
||||
WebrtcBwuHandler::WebrtcBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WebRTC using this info.
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WebrtcBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
|
||||
upgrade_path_info) {
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
void WebrtcBwuHandler::HandleRevertInitiatorStateForService(
|
||||
const std::string& upgrade_service_id) {}
|
||||
|
||||
// Called by BWU initiator. Set up WebRTC upgraded medium for this endpoint,
|
||||
// and returns a upgrade path info (PeerId, LocationHint) for remote party to
|
||||
// perform discovery.
|
||||
std::string WebrtcBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Accept Connection Callback.
|
||||
// Notifies that the remote party called WebRtc::Connect()
|
||||
// for this socket.
|
||||
void WebrtcBwuHandler::OnIncomingWebrtcConnection(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
std::shared_ptr<mediums::WebRtcSocket> socket) {}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
@@ -1,86 +0,0 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_STUB_H_
|
||||
#define CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_STUB_H_
|
||||
|
||||
#ifdef NO_WEBRTC
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel_manager.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
// Defines the set of methods that need to be implemented to handle the
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit WebrtcBwuHandler(
|
||||
Mediums& mediums,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
class WebrtcIncomingSocket : public BwuHandler::IncomingSocket {
|
||||
public:
|
||||
explicit WebrtcIncomingSocket(
|
||||
const std::string& name, std::shared_ptr<mediums::WebRtcSocket> socket);
|
||||
|
||||
std::string ToString() override;
|
||||
void Close() override;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::shared_ptr<mediums::WebRtcSocket> socket_;
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
|
||||
UpgradePathInfo& upgrade_path_info) final;
|
||||
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
|
||||
return Medium::WEB_RTC;
|
||||
}
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
const std::string& upgrade_service_id) final;
|
||||
|
||||
void OnIncomingWebrtcConnection(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
std::shared_ptr<mediums::WebRtcSocket> socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
mediums::WebRtc& webrtc_{mediums_.GetWebRtc()};
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CORE_INTERNAL_MEDIUMS_WEBRTC_BWU_HANDLER_STUB_H_
|
||||
@@ -14,12 +14,15 @@
|
||||
|
||||
#include "connections/implementation/mediums/wifi_direct.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/wifi_direct_bwu_handler.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -307,5 +310,12 @@ bool WifiDirect::SetPreferredWifiDirectAuthType(WifiDirectAuthType auth_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> WifiDirect::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
return std::make_unique<WifiDirectBwuHandler>(
|
||||
this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -110,6 +111,9 @@ class WifiDirect {
|
||||
// Sets the preferred WifiDirect auth type.
|
||||
bool SetPreferredWifiDirectAuthType(WifiDirectAuthType auth_type);
|
||||
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
mutable Mutex mutex_;
|
||||
static constexpr int kMaxConcurrentAcceptLoops = 5;
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/mediums/wifi_direct.h"
|
||||
#include "connections/implementation/mediums/wifi_direct_endpoint_channel.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/strategy.h"
|
||||
@@ -41,9 +42,10 @@ using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
WifiDirectBwuHandler::WifiDirectBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
WifiDirect* absl_nonnull wifi_direct_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
wifi_direct_medium_(*wifi_direct_medium) {}
|
||||
|
||||
// Called by BWU initiator. Set up WifiDirect upgraded medium for this
|
||||
// endpoint, and returns an upgrade path info (ServiceName, Pin for Wifi WPS,
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_direct.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_direct.h"
|
||||
@@ -34,8 +34,8 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class WifiDirectBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit WifiDirectBwuHandler(
|
||||
Mediums& mediums,
|
||||
WifiDirectBwuHandler(
|
||||
WifiDirect* absl_nonnull wifi_direct_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
@@ -85,8 +85,7 @@ class WifiDirectBwuHandler : public BaseBwuHandler {
|
||||
const std::string& upgrade_service_id,
|
||||
WifiDirectSocket socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
WifiDirect& wifi_direct_medium_ = mediums_.GetWifiDirect();
|
||||
WifiDirect& wifi_direct_medium_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -68,7 +68,8 @@ TEST_F(WifiDirectTest, CanCreateBwuHandler) {
|
||||
ClientProxy client;
|
||||
Mediums mediums;
|
||||
|
||||
auto handler = std::make_unique<WifiDirectBwuHandler>(mediums, nullptr);
|
||||
auto handler =
|
||||
std::make_unique<WifiDirectBwuHandler>(&mediums.GetWifiDirect(), nullptr);
|
||||
|
||||
handler->InitializeUpgradedMediumForEndpoint(&client, std::string(kServiceID),
|
||||
std::string(kEndpointID));
|
||||
@@ -87,7 +88,7 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) {
|
||||
ExceptionOr<OfflineFrame> upgrade_frame;
|
||||
|
||||
auto wfd_go_bwu_handler = std::make_unique<WifiDirectBwuHandler>(
|
||||
mediums_wfd_go, [&](ClientProxy* client,
|
||||
&mediums_wfd_go.GetWifiDirect(), [&](ClientProxy* client,
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection>
|
||||
mutable_connection) {
|
||||
LOG(INFO) << "Server socket connection accept call back, Socket name: "
|
||||
@@ -113,7 +114,8 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) {
|
||||
EXPECT_TRUE(start_latch.Await(kWaitDuration).result());
|
||||
EXPECT_FALSE(mediums_wfd_gc.GetWifiDirect().IsConnectedToGO());
|
||||
std::unique_ptr<BwuHandler> wfd_gc_bwu_handler =
|
||||
std::make_unique<WifiDirectBwuHandler>(mediums_wfd_gc, nullptr);
|
||||
std::make_unique<WifiDirectBwuHandler>(&mediums_wfd_gc.GetWifiDirect(),
|
||||
nullptr);
|
||||
|
||||
wfd_gc_executor.Execute([&]() {
|
||||
UpgradePathInfo upgrade_path_info;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "connections/implementation/mediums/wifi_hotspot.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -22,12 +23,15 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot_bwu_handler.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
#include "internal/platform/wifi_hotspot.h"
|
||||
|
||||
@@ -325,5 +329,12 @@ ErrorOr<WifiHotspotSocket> WifiHotspot::Connect(
|
||||
return socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> WifiHotspot::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
return std::make_unique<WifiHotspotBwuHandler>(
|
||||
this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/multi_thread_executor.h"
|
||||
@@ -86,6 +87,9 @@ class WifiHotspot {
|
||||
HotspotCredentials* GetCredentials(absl::string_view service_id)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
mutable Mutex mutex_;
|
||||
static constexpr int kMaxConcurrentAcceptLoops = 5;
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot_endpoint_channel.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/proto/offline_wire_formats.pb.h"
|
||||
@@ -66,9 +67,10 @@ std::vector<char> GatewayToAddressBytes(const std::string& gateway) {
|
||||
} // namespace
|
||||
|
||||
WifiHotspotBwuHandler::WifiHotspotBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
WifiHotspot* absl_nonnull wifi_hotspot_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
wifi_hotspot_medium_(*wifi_hotspot_medium) {}
|
||||
|
||||
// Called by BWU initiator. Set up WifiHotspot upgraded medium for this
|
||||
// endpoint, and returns a upgrade path info (SSID, Password, Gateway used as
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_hotspot.h"
|
||||
@@ -34,8 +34,8 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class WifiHotspotBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit WifiHotspotBwuHandler(
|
||||
Mediums& mediums,
|
||||
WifiHotspotBwuHandler(
|
||||
WifiHotspot* absl_nonnull wifi_hotspot_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
// BwuHandler implementation:
|
||||
@@ -77,8 +77,7 @@ class WifiHotspotBwuHandler : public BaseBwuHandler {
|
||||
const std::string& upgrade_service_id,
|
||||
WifiHotspotSocket socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
WifiHotspot& wifi_hotspot_medium_{mediums_.GetWifiHotspot()};
|
||||
WifiHotspot& wifi_hotspot_medium_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -69,7 +69,8 @@ TEST_F(WifiHotspotTest, CanCreateBwuHandler) {
|
||||
ClientProxy client;
|
||||
Mediums mediums;
|
||||
|
||||
auto handler = std::make_unique<WifiHotspotBwuHandler>(mediums, nullptr);
|
||||
auto handler = std::make_unique<WifiHotspotBwuHandler>(
|
||||
&mediums.GetWifiHotspot(), nullptr);
|
||||
|
||||
handler->InitializeUpgradedMediumForEndpoint(&client, std::string(kServiceID),
|
||||
std::string(kEndpointID));
|
||||
@@ -88,7 +89,7 @@ TEST_F(WifiHotspotTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
ExceptionOr<OfflineFrame> upgrade_frame;
|
||||
|
||||
auto handler_1 = std::make_unique<WifiHotspotBwuHandler>(
|
||||
mediums_HS_ap, [&](ClientProxy* client,
|
||||
&mediums_HS_ap.GetWifiHotspot(), [&](ClientProxy* client,
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection>
|
||||
mutable_connection) {
|
||||
LOG(INFO) << "Server socket connection accept call back, Socket name: "
|
||||
@@ -117,7 +118,8 @@ TEST_F(WifiHotspotTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
// Wait till client_hotspot_ap started as hotspot and then connect to it
|
||||
EXPECT_TRUE(start_latch.Await(kWaitDuration).result());
|
||||
std::unique_ptr<BwuHandler> handler_2 =
|
||||
std::make_unique<WifiHotspotBwuHandler>(mediums_HS_sta, nullptr);
|
||||
std::make_unique<WifiHotspotBwuHandler>(&mediums_HS_sta.GetWifiHotspot(),
|
||||
nullptr);
|
||||
|
||||
client_executor.Execute([&]() {
|
||||
UpgradePathInfo upgrade_path_info;
|
||||
|
||||
@@ -15,13 +15,16 @@
|
||||
#include "connections/implementation/mediums/wifi_lan.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "connections/implementation/mediums/wifi_lan_bwu_handler.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
@@ -517,5 +520,12 @@ int WifiLan::GeneratePort(const std::string& service_id,
|
||||
(uint_of_service_id_hash % (port_range.second - port_range.first));
|
||||
}
|
||||
|
||||
std::unique_ptr<BwuHandler> WifiLan::CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
return std::make_unique<WifiLanBwuHandler>(
|
||||
this, std::move(incoming_connection_callback));
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define CORE_INTERNAL_MEDIUMS_WIFI_LAN_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -114,6 +116,9 @@ class WifiLan {
|
||||
api::UpgradeAddressInfo GetUpgradeAddressCandidates(
|
||||
const std::string& service_id) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<BwuHandler> CreateBwuHandler(
|
||||
BwuHandler::IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
private:
|
||||
struct AdvertisingInfo {
|
||||
bool Empty() const { return nsd_service_infos.empty(); }
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/mediums/wifi_lan.h"
|
||||
#include "connections/implementation/mediums/wifi_lan_endpoint_channel.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -42,9 +43,10 @@ using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
WifiLanBwuHandler::WifiLanBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
WifiLan* absl_nonnull wifi_lan_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
mediums_(mediums) {}
|
||||
wifi_lan_medium_(*wifi_lan_medium) {}
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WifiLan using this info.
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_lan.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_lan.h"
|
||||
@@ -34,8 +34,8 @@ namespace connections {
|
||||
// per-Medium-specific operations needed to upgrade an EndpointChannel.
|
||||
class WifiLanBwuHandler : public BaseBwuHandler {
|
||||
public:
|
||||
explicit WifiLanBwuHandler(
|
||||
Mediums& mediums,
|
||||
WifiLanBwuHandler(
|
||||
WifiLan* absl_nonnull wifi_lan_medium,
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
// BwuHandler implementation:
|
||||
@@ -77,8 +77,7 @@ class WifiLanBwuHandler : public BaseBwuHandler {
|
||||
const std::string& upgrade_service_id,
|
||||
WifiLanSocket socket);
|
||||
|
||||
Mediums& mediums_;
|
||||
WifiLan& wifi_lan_medium_{mediums_.GetWifiLan()};
|
||||
WifiLan& wifi_lan_medium_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -72,7 +72,8 @@ constexpr absl::string_view kEndpointId{"endpoint_id"};
|
||||
class WifiLanBwuHandlerTest : public ::testing::Test {
|
||||
protected:
|
||||
WifiLanBwuHandlerTest()
|
||||
: handler_(mediums_, incoming_connection_callback_.AsStdFunction()) {}
|
||||
: handler_(&mediums_.GetWifiLan(),
|
||||
incoming_connection_callback_.AsStdFunction()) {}
|
||||
|
||||
Mediums mediums_;
|
||||
MockFunction<void(ClientProxy*,
|
||||
|
||||
Reference in New Issue
Block a user