mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Use a reverse-DNS prefix for Wi-Fi Direct service names.
PiperOrigin-RevId: 882102213
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
@@ -41,6 +42,15 @@ namespace nearby {
|
||||
namespace windows {
|
||||
namespace {
|
||||
constexpr int kWaitingForConnectionTimeoutSeconds = 90; // seconds
|
||||
// The prefix of the service name.
|
||||
// Fully Qualified Service Name (FQSN) must follow reverse-DNS notation to
|
||||
// ensure uniqueness and cross-platform compatibility. Otherwise, Windows
|
||||
// prefixes the service name with "org.wi-fi.wfds.", which prevents Android
|
||||
// devices from discovering the service.
|
||||
// https://www.wi-fi.org/file-member/wi-fi-peer-to-peer-services-technical-specification-package
|
||||
// Wi-Fi_Peer-to-Peer_Services_Technical_Specification_v1.2.pdf chapter 3.2
|
||||
constexpr absl::string_view kServiceNamePrefix =
|
||||
"com.google.nearby.connection.";
|
||||
} // namespace
|
||||
|
||||
WifiDirectMedium::WifiDirectMedium() {
|
||||
@@ -294,7 +304,8 @@ bool WifiDirectMedium::StartWifiDirect(
|
||||
std::string pin = absl::StrFormat("%04x", prng.NextUint32());
|
||||
credentials_go_->SetPin(pin);
|
||||
|
||||
std::string service_name = "NC-" + std::to_string(prng.NextUint32());
|
||||
std::string service_name =
|
||||
absl::StrCat(kServiceNamePrefix, std::to_string(prng.NextUint32()));
|
||||
credentials_go_->SetServiceName(service_name);
|
||||
LOG(INFO) << "service_name:pin " << service_name << ":" << pin;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
@@ -28,7 +30,13 @@
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
namespace {
|
||||
|
||||
constexpr absl::string_view kServiceNamePrefix =
|
||||
"com.google.nearby.connection.";
|
||||
// Tests are prefixed with DISABLED_ for several reasons: 1. They require user
|
||||
// interaction, 2. They have access to Windows APIs and physical WiFi hardware.
|
||||
// These tests are intended for validation on actual Windows machines, 3. By
|
||||
// using the DISABLED_ prefix, we can Keep the code in the repo and prevent CI
|
||||
// failures.
|
||||
TEST(WifiDirectMedium, DISABLED_StartWifiDirect) {
|
||||
int run_test;
|
||||
LOG(INFO) << "Run StartWifiDirect test case? input 0 or 1:";
|
||||
@@ -72,7 +80,9 @@ TEST(WifiDirectMedium, DISABLED_ConnectWifiDirect) {
|
||||
LOG(INFO) << "Enter pin: ";
|
||||
std::string pin;
|
||||
std::cin >> pin;
|
||||
credentials.SetServiceName(service_name);
|
||||
std::string service_name_with_prefix =
|
||||
absl::StrCat(kServiceNamePrefix, service_name);
|
||||
credentials.SetServiceName(service_name_with_prefix);
|
||||
credentials.SetPin(pin);
|
||||
|
||||
EXPECT_TRUE(wifi_direct_medium.ConnectWifiDirect(credentials));
|
||||
@@ -147,7 +157,9 @@ TEST(WifiDirectMedium, DISABLED_WifiDirectConnectToServiceServer) {
|
||||
LOG(INFO) << "Enter pin: ";
|
||||
std::string pin;
|
||||
std::cin >> pin;
|
||||
credentials.SetServiceName(service_name);
|
||||
std::string service_name_with_prefix =
|
||||
absl::StrCat(kServiceNamePrefix, service_name);
|
||||
credentials.SetServiceName(service_name_with_prefix);
|
||||
credentials.SetPin(pin);
|
||||
|
||||
EXPECT_TRUE(wifi_direct_medium.ConnectWifiDirect(credentials));
|
||||
|
||||
Reference in New Issue
Block a user