mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Make Wi-Fi LAN and AWDL could coexist
PiperOrigin-RevId: 784242267
This commit is contained in:
committed by
Copybara-Service
parent
b5ae01cf2d
commit
771904b707
@@ -50,6 +50,7 @@ constexpr absl::Duration kAwdlDiscoveryTimeout = absl::Seconds(5);
|
||||
constexpr int kServiceNameLength = 8;
|
||||
constexpr int kPasswordLength = 16;
|
||||
constexpr absl::string_view kPskIdentity = "AwdlUpgradeMedium";
|
||||
constexpr absl::string_view kAwdlServiceIdSuffixForServiceType = "_AWDL";
|
||||
} // namespace
|
||||
|
||||
AwdlBwuHandler::AwdlBwuHandler(
|
||||
@@ -205,7 +206,8 @@ ByteArray AwdlBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
// Need to advertise the service.
|
||||
nsd_service_info_ = NsdServiceInfo();
|
||||
nsd_service_info_.SetServiceName(GenerateServiceName());
|
||||
nsd_service_info_.SetServiceType(GenerateServiceType(upgrade_service_id));
|
||||
nsd_service_info_.SetServiceType(GenerateServiceType(
|
||||
absl::StrCat(upgrade_service_id, kAwdlServiceIdSuffixForServiceType)));
|
||||
|
||||
if (!awdl_medium_.StartAdvertising(upgrade_service_id, nsd_service_info_)) {
|
||||
LOG(ERROR) << "Failed to initiate the AWDL upgrade for "
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/mediums/multiplex/multiplex_socket.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "connections/medium_selector.h"
|
||||
@@ -41,10 +42,12 @@
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
|
||||
using MultiplexSocket = mediums::multiplex::MultiplexSocket;
|
||||
using location::nearby::proto::connections::OperationResultCode;
|
||||
constexpr absl::string_view kAwdlServiceIdSuffixForServiceType = "_AWDL";
|
||||
|
||||
} // namespace
|
||||
|
||||
Awdl::~Awdl() {
|
||||
@@ -104,7 +107,8 @@ ErrorOr<bool> Awdl::StartAdvertising(const std::string& service_id,
|
||||
CLIENT_DUPLICATE_ACCEPTING_LAN_CONNECTION_REQUEST)};
|
||||
}
|
||||
|
||||
nsd_service_info.SetServiceType(GenerateServiceType(service_id));
|
||||
nsd_service_info.SetServiceType(GenerateServiceType(
|
||||
absl::StrCat(service_id, kAwdlServiceIdSuffixForServiceType)));
|
||||
const auto& it = server_sockets_.find(service_id);
|
||||
if (it != server_sockets_.end()) {
|
||||
nsd_service_info.SetIPAddress(it->second.GetIPAddress());
|
||||
@@ -175,7 +179,8 @@ ErrorOr<bool> Awdl::StartDiscovery(const std::string& service_id,
|
||||
return {Error(OperationResultCode::CLIENT_WIFI_LAN_DUPLICATE_DISCOVERING)};
|
||||
}
|
||||
|
||||
std::string service_type = GenerateServiceType(service_id);
|
||||
std::string service_type = GenerateServiceType(
|
||||
absl::StrCat(service_id, kAwdlServiceIdSuffixForServiceType));
|
||||
bool ret =
|
||||
medium_.StartDiscovery(service_id, service_type, std::move(callback));
|
||||
if (!ret) {
|
||||
@@ -199,7 +204,8 @@ bool Awdl::StopDiscovery(const std::string& service_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string service_type = GenerateServiceType(service_id);
|
||||
std::string service_type = GenerateServiceType(
|
||||
absl::StrCat(service_id, kAwdlServiceIdSuffixForServiceType));
|
||||
LOG(INFO) << "Turned off Awdl discovering with service_id=" << service_id
|
||||
<< ", service_type=" << service_type;
|
||||
bool ret = medium_.StopDiscovery(service_type);
|
||||
|
||||
@@ -33,9 +33,6 @@ typedef void (^ServiceUpdateHandler)(NSString *_Nonnull serviceName,
|
||||
/** Whether to include peer-to-peer services. */
|
||||
@property(atomic, readonly) BOOL includePeerToPeer;
|
||||
|
||||
/** The shared instance of the @c GNCNWFramework object. */
|
||||
+ (nonnull instancetype)sharedInstance;
|
||||
|
||||
/**
|
||||
* Listens for incoming connections on a given port.
|
||||
*
|
||||
|
||||
@@ -99,21 +99,6 @@ NSDictionary<NSString *, NSString *> *GNCTXTRecordForBrowseResult(nw_browse_resu
|
||||
return self;
|
||||
}
|
||||
|
||||
static GNCNWFramework *gInstance = nil;
|
||||
|
||||
+ (GNCNWFramework *)sharedInstance {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
@synchronized([GNCNWFramework class]) {
|
||||
if (!gInstance) {
|
||||
gInstance = [[self alloc] init];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return gInstance;
|
||||
}
|
||||
|
||||
- (BOOL)isListeningForAnyService {
|
||||
return _serverSockets.count > 0;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class AwdlServerSocket : public api::AwdlServerSocket {
|
||||
*/
|
||||
class AwdlMedium : public api::AwdlMedium {
|
||||
public:
|
||||
explicit AwdlMedium(bool include_peer_to_peer = false);
|
||||
AwdlMedium();
|
||||
~AwdlMedium() override = default;
|
||||
|
||||
AwdlMedium(const AwdlMedium&) = delete;
|
||||
|
||||
@@ -122,7 +122,7 @@ Exception AwdlServerSocket::Close() {
|
||||
|
||||
#pragma mark - AwdlMedium
|
||||
|
||||
AwdlMedium::AwdlMedium(bool include_peer_to_peer) : medium_([GNCNWFramework sharedInstance]) {}
|
||||
AwdlMedium::AwdlMedium() { medium_ = [[GNCNWFramework alloc] init]; }
|
||||
|
||||
bool AwdlMedium::StartAdvertising(const NsdServiceInfo& nsd_service_info) {
|
||||
return network_utils::StartAdvertising(medium_, nsd_service_info);
|
||||
|
||||
@@ -102,7 +102,7 @@ class WifiLanServerSocket : public api::WifiLanServerSocket {
|
||||
*/
|
||||
class WifiLanMedium : public api::WifiLanMedium {
|
||||
public:
|
||||
explicit WifiLanMedium(bool include_peer_to_peer = false);
|
||||
WifiLanMedium();
|
||||
~WifiLanMedium() override = default;
|
||||
|
||||
WifiLanMedium(const WifiLanMedium&) = delete;
|
||||
|
||||
@@ -122,8 +122,7 @@ Exception WifiLanServerSocket::Close() {
|
||||
|
||||
#pragma mark - WifiLanMedium
|
||||
|
||||
WifiLanMedium::WifiLanMedium(bool include_peer_to_peer)
|
||||
: medium_([GNCNWFramework sharedInstance]) {}
|
||||
WifiLanMedium::WifiLanMedium() { medium_ = [[GNCNWFramework alloc] init]; }
|
||||
|
||||
bool WifiLanMedium::StartAdvertising(const NsdServiceInfo& nsd_service_info) {
|
||||
return network_utils::StartAdvertising(medium_, nsd_service_info);
|
||||
|
||||
Reference in New Issue
Block a user