Merge branch 'master' into test_403438989

This commit is contained in:
Will
2021-10-18 14:10:21 -07:00
committed by GitHub
26 changed files with 525 additions and 418 deletions
+1
View File
@@ -43,6 +43,7 @@ cc_library(
cc_library(
name = "core_types",
srcs = [
"options.cc",
"strategy.cc",
],
hdrs = [
+1
View File
@@ -47,6 +47,7 @@ cc_library(
"//absl/functional:bind_front",
"//absl/numeric:int128",
"//absl/strings",
"//absl/strings:str_format",
"//absl/time",
"//core:core_types",
"//core/internal/mediums/ble_v2",
+22 -6
View File
@@ -18,6 +18,8 @@
#include <string>
#include <utility>
#include "absl/strings/str_format.h"
#include "core/internal/mediums/utils.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
@@ -34,7 +36,7 @@ bool WifiLan::IsAvailable() const {
bool WifiLan::IsAvailableLocked() const { return medium_.IsValid(); }
bool WifiLan::StartAdvertising(const std::string& service_id,
const NsdServiceInfo& nsd_service_info) {
NsdServiceInfo& nsd_service_info) {
MutexLock lock(&mutex_);
if (!nsd_service_info.IsValid()) {
@@ -56,18 +58,19 @@ bool WifiLan::StartAdvertising(const std::string& service_id,
return false;
}
nsd_service_info.SetServiceType(GenerateServiceType(service_id));
if (!medium_.StartAdvertising(service_id, nsd_service_info)) {
NEARBY_LOGS(INFO)
<< "Failed to turn on WifiLan advertising with wifi_lan_service="
<< &nsd_service_info
<< ", service_info_name=" << nsd_service_info.GetServiceInfoName()
<< ", service_info_name=" << nsd_service_info.GetServiceName()
<< ", service_id=" << service_id;
return false;
}
NEARBY_LOGS(INFO) << "Turned on WifiLan advertising with wifi_lan_service="
<< &nsd_service_info << ", service_info_name="
<< nsd_service_info.GetServiceInfoName()
<< nsd_service_info.GetServiceName()
<< ", service_id=" << service_id;
advertising_info_.Add(service_id);
return true;
@@ -234,7 +237,7 @@ WifiLanSocket WifiLan::Connect(WifiLanService& wifi_lan_service,
MutexLock lock(&mutex_);
NEARBY_LOGS(INFO) << "WifiLan::Connect: wifi_lan_service="
<< &wifi_lan_service << ", service_info_name="
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
<< wifi_lan_service.GetServiceInfo().GetServiceName()
<< ", service_id=" << service_id;
// Socket to return. To allow for NRVO to work, it has to be a single object.
WifiLanSocket socket;
@@ -273,10 +276,23 @@ WifiLanService WifiLan::GetRemoteWifiLanService(const std::string& ip_address,
return medium_.GetRemoteService(ip_address, port);
}
std::pair<std::string, int> WifiLan::GetServiceAddress(
std::pair<std::string, int> WifiLan::GetCredentials(
const std::string& service_id) {
MutexLock lock(&mutex_);
return medium_.GetServiceAddress(service_id);
return medium_.GetCredentials(service_id);
}
std::string WifiLan::GenerateServiceType(const std::string& service_id) {
std::string service_id_hash_string;
const ByteArray service_id_hash = Utils::Sha256Hash(
service_id, NsdServiceInfo::kTypeFromServiceIdHashLength);
for (auto byte : std::string(service_id_hash)) {
absl::StrAppend(&service_id_hash_string, absl::StrFormat("%02X", byte));
}
return absl::StrFormat(NsdServiceInfo::kNsdTypeFormat,
service_id_hash_string);
}
} // namespace connections
+5 -2
View File
@@ -42,7 +42,7 @@ class WifiLan {
// then enables WifiLan advertising.
// Returns true, if name is successfully set, and false otherwise.
bool StartAdvertising(const std::string& service_id,
const NsdServiceInfo& nsd_service_info)
NsdServiceInfo& nsd_service_info)
ABSL_LOCKS_EXCLUDED(mutex_);
// Disables WifiLan advertising, and restores service info name to
@@ -89,7 +89,7 @@ class WifiLan {
WifiLanService GetRemoteWifiLanService(const std::string& ip_address,
int port) ABSL_LOCKS_EXCLUDED(mutex_);
std::pair<std::string, int> GetServiceAddress(const std::string& service_id)
std::pair<std::string, int> GetCredentials(const std::string& service_id)
ABSL_LOCKS_EXCLUDED(mutex_);
private:
@@ -150,6 +150,9 @@ class WifiLan {
bool IsAcceptingConnectionsLocked(const std::string& service_id)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Generates mDNS type.
std::string GenerateServiceType(const std::string& service_id);
mutable Mutex mutex_;
WifiLanMedium medium_ ABSL_GUARDED_BY(mutex_);
AdvertisingInfo advertising_info_ ABSL_GUARDED_BY(mutex_);
+4 -4
View File
@@ -69,7 +69,7 @@ TEST_P(WifiLanTest, CanStartAcceptingConnectionsAndConnect) {
CountDownLatch accept_latch(1);
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_lan_a.StartAdvertising(service_id, nsd_service_info);
@@ -120,7 +120,7 @@ TEST_P(WifiLanTest, CanCancelConnect) {
CountDownLatch accept_latch(1);
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_lan_a.StartAdvertising(service_id, nsd_service_info);
@@ -197,7 +197,7 @@ TEST_F(WifiLanTest, CanStartAdvertising) {
});
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
EXPECT_TRUE(wifi_lan_a.StartAdvertising(service_id, nsd_service_info));
@@ -218,7 +218,7 @@ TEST_F(WifiLanTest, CanStartDiscovery) {
CountDownLatch lost_latch(1);
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_lan_b.StartAdvertising(service_id, nsd_service_info);
+10 -11
View File
@@ -578,7 +578,7 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
if (!client->IsDiscovering()) {
NEARBY_LOGS(WARNING)
<< "Skipping discovery of NsdServiceInfo "
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
<< wifi_lan_service.GetServiceInfo().GetServiceName()
<< " because we are no longer discovering.";
return;
}
@@ -593,7 +593,7 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
// Report the discovered endpoint to the client.
NEARBY_LOGS(INFO)
<< "Found NsdServiceInfo "
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
<< wifi_lan_service.GetServiceInfo().GetServiceName()
<< " (with endpoint_id=" << service_info.GetEndpointId()
<< "and endpoint_info="
<< absl::BytesToHexString(service_info.GetEndpointInfo().data())
@@ -618,7 +618,7 @@ void P2pClusterPcpHandler::WifiLanServiceLostHandler(
NsdServiceInfo nsd_service_info = wifi_lan_service.GetServiceInfo();
NEARBY_LOG(INFO,
"WifiLan: [LOST, SCHED] wifi_lan_service=%p, service_info_name=%s",
&wifi_lan_service, nsd_service_info.GetServiceInfoName().c_str());
&wifi_lan_service, nsd_service_info.GetServiceName().c_str());
RunOnPcpHandlerThread(
"p2p-wifi-service-lost",
[this, client, service_id, nsd_service_info]()
@@ -626,7 +626,7 @@ void P2pClusterPcpHandler::WifiLanServiceLostHandler(
// Make sure we are still discovering before proceeding.
if (!client->IsDiscovering()) {
NEARBY_LOGS(WARNING) << "Ignoring lost NsdServiceInfo "
<< nsd_service_info.GetServiceInfoName()
<< nsd_service_info.GetServiceName()
<< " because we are no longer "
"discovering.";
return;
@@ -641,8 +641,7 @@ void P2pClusterPcpHandler::WifiLanServiceLostHandler(
// Report the lost endpoint to the client.
NEARBY_LOGS(INFO)
<< "Lost NsdServiceInfo "
<< nsd_service_info.GetServiceInfoName()
<< "Lost NsdServiceInfo " << nsd_service_info.GetServiceName()
<< " (with endpoint_id=" << service_info.GetEndpointId()
<< " and endpoint_info="
<< absl::BytesToHexString(service_info.GetEndpointInfo().data())
@@ -1234,7 +1233,7 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
std::string remote_service_info_name =
socket.GetRemoteWifiLanService()
.GetServiceInfo()
.GetServiceInfoName();
.GetServiceName();
auto channel =
absl::make_unique<WifiLanEndpointChannel>(
remote_service_info_name, socket);
@@ -1288,7 +1287,7 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
}
NEARBY_LOGS(INFO) << "In StartWifiLanAdvertising(%s), client="
<< client->GetClientId() << " generated WifiLanServiceInfo "
<< nsd_service_info.GetServiceInfoName()
<< nsd_service_info.GetServiceName()
<< " with service_id=" << service_id;
if (!wifi_lan_medium_.StartAdvertising(service_id, nsd_service_info)) {
@@ -1296,7 +1295,7 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " couldn't advertise with WifiLanServiceInfo "
<< nsd_service_info.GetServiceInfoName();
<< nsd_service_info.GetServiceName();
wifi_lan_medium_.StopAcceptingConnections(service_id);
return proto::connections::UNKNOWN_MEDIUM;
}
@@ -1304,7 +1303,7 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " advertised with WifiLanServiceInfo "
<< nsd_service_info.GetServiceInfoName();
<< nsd_service_info.GetServiceName();
return proto::connections::WIFI_LAN;
}
@@ -1339,7 +1338,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::WifiLanConnectImpl(
if (!wifi_lan_socket.IsValid()) {
NEARBY_LOGS(ERROR)
<< "In WifiLanConnectImpl(), failed to connect to service "
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
<< wifi_lan_service.GetServiceInfo().GetServiceName()
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
return BasePcpHandler::ConnectImplResult{
.status = {Status::kWifiLanError},
+3 -3
View File
@@ -70,9 +70,9 @@ ByteArray WifiLanBwuHandler::InitializeUpgradedMediumForEndpoint(
// cache service ID to revert
active_service_ids_.emplace(upgrade_service_id);
auto service_address = wifi_lan_medium_.GetServiceAddress(upgrade_service_id);
auto ip_address = service_address.first;
auto port = service_address.second;
auto credential = wifi_lan_medium_.GetCredentials(upgrade_service_id);
auto ip_address = credential.first;
auto port = credential.second;
if (ip_address.empty()) {
NEARBY_LOGS(INFO)
<< "WifiLanBwuHandler couldn't initiate the wifi_lan upgrade for "
+2 -2
View File
@@ -77,7 +77,7 @@ WifiLanServiceInfo::WifiLanServiceInfo(const NsdServiceInfo& nsd_service_info) {
}
}
auto service_info_name = nsd_service_info.GetServiceInfoName();
auto service_info_name = nsd_service_info.GetServiceName();
ByteArray service_info_bytes = Base64Utils::Decode(service_info_name);
if (service_info_bytes.Empty()) {
NEARBY_LOG(
@@ -193,7 +193,7 @@ WifiLanServiceInfo::operator NsdServiceInfo() const {
}
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(
nsd_service_info.SetServiceName(
Base64Utils::Encode(ByteArray{std::move(out)}));
nsd_service_info.SetTxtRecord(std::string(kKeyEndpointInfo),
Base64Utils::Encode(endpoint_info_));
@@ -146,7 +146,7 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithShortServiceNameLength) {
ByteArray wifi_lan_service_info_bytes{wifi_lan_service_info_name};
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(
nsd_service_info.SetServiceName(
Base64Utils::Encode(wifi_lan_service_info_bytes));
WifiLanServiceInfo wifi_lan_service_info{nsd_service_info};
+89
View File
@@ -0,0 +1,89 @@
// 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.
#include "core/options.h"
#include <string>
namespace location {
namespace nearby {
namespace connections {
// Verify if ConnectionOptions is in a not-initialized (Empty) state.
bool ConnectionOptions::Empty() const { return strategy.IsNone(); }
// Bring ConnectionOptions to a not-initialized (Empty) state.
void ConnectionOptions::Clear() { strategy.Clear(); }
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
// medium allowed, defaulting to only Bluetooth if unspecified.
// (2) If no mediums are allowed, allow all mediums.
ConnectionOptions ConnectionOptions::CompatibleOptions() const {
ConnectionOptions result = *this;
// Out-of-band connections initiate connections via an injected endpoint
// rather than through the normal discovery flow. These types of connections
// can only be injected via a single medium.
if (is_out_of_band_connection) {
int num_enabled = result.allowed.Count(true);
// Default to allow only Bluetooth if no single medium is specified.
if (num_enabled != 1) {
result.allowed.SetAll(false);
result.allowed.bluetooth = true;
}
return result;
}
// Normal connections (i.e., not out-of-band) connections can specify
// multiple mediums. If none are specified, default to allowing all mediums.
if (!allowed.Any(true)) result.allowed.SetAll(true);
return result;
}
std::vector<Medium> ConnectionOptions::GetMediums() const {
return allowed.GetMediums(true);
}
// This call follows the standard Microsoft calling pattern of calling first
// to get the size of the array. Caller then allocates memory for the array,
// and makes this call again to copy the array into the provided location.
void ConnectionOptions::GetMediums(
location::nearby::proto::connections::Medium* mediums,
uint32_t* mediumsSize) {
auto size = GetMediums().size();
// Caller is seeking the size of mediums
if (mediums == nullptr) {
*mediumsSize = size;
return;
}
// Caller has not specified enough memory
if (*mediumsSize < size) {
mediums = nullptr; // ensure nullptr return
*mediumsSize = size; // update the size to indicate the correct size
return;
}
for (uint32_t i = 0; i < size; i++) {
// Construct an array at the given location
mediums[i] = GetMediums().at(i);
}
}
} // namespace connections
} // namespace nearby
} // namespace location
+6 -46
View File
@@ -103,67 +103,27 @@ struct DLL_API ConnectionOptions {
int keep_alive_timeout_millis = 0;
// Verify if ConnectionOptions is in a not-initialized (Empty) state.
bool Empty() const { return strategy.IsNone(); }
bool Empty() const;
// Bring ConnectionOptions to a not-initialized (Empty) state.
void Clear() { strategy.Clear(); }
void Clear();
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
// medium allowed, defaulting to only Bluetooth if unspecified.
// (2) If no mediums are allowed, allow all mediums.
ConnectionOptions CompatibleOptions() const {
ConnectionOptions result = *this;
ConnectionOptions CompatibleOptions() const;
// Out-of-band connections initiate connections via an injected endpoint
// rather than through the normal discovery flow. These types of connections
// can only be injected via a single medium.
if (is_out_of_band_connection) {
int num_enabled = result.allowed.Count(true);
// Default to allow only Bluetooth if no single medium is specified.
if (num_enabled != 1) {
result.allowed.SetAll(false);
result.allowed.bluetooth = true;
}
return result;
}
// Normal connections (i.e., not out-of-band) connections can specify
// multiple mediums. If none are specified, default to allowing all mediums.
if (!allowed.Any(true)) result.allowed.SetAll(true);
return result;
}
std::vector<Medium> GetMediums() const { return allowed.GetMediums(true); }
std::vector<Medium> GetMediums() const;
// This call follows the standard Microsoft calling pattern of calling first
// to get the size of the array. Caller then allocates memory for the array,
// and makes this call again to copy the array into the provided location.
void GetMediums(location::nearby::proto::connections::Medium* mediums,
uint32_t* mediumsSize) {
auto size = GetMediums().size();
// Caller is seeking the size of mediums
if (mediums == nullptr) {
*mediumsSize = size;
return;
}
// Caller has not specified enough memory
if (*mediumsSize < size) {
mediums = nullptr; // ensure nullptr return
*mediumsSize = size; // update the size to indicate the correct size
return;
}
for (uint32_t i = 0; i < size; i++) {
// Construct an array at the given location
mediums[i] = GetMediums().at(i);
}
}
uint32_t* mediumsSize);
};
// Metadata injected to facilitate out-of-band connections. The medium field is
// required, and the other fields are only specified for a specific medium.
// Currently, Bluetooth is the only supported medium for out-of-band
+5 -1
View File
@@ -120,7 +120,11 @@ class WifiLanMedium {
virtual WifiLanService* GetRemoteService(const std::string& ip_address,
int port) = 0;
virtual std::pair<std::string, int> GetServiceAddress(
// Gets ip address + port for remote services on the network to identify and
// connect to this service.
//
// Credential is for the currently-hosted Wifi ServerSocket (if any).
virtual std::pair<std::string, int> GetCredentials(
const std::string& service_id) = 0;
};
+192 -183
View File
@@ -291,27 +291,27 @@ void MediumEnvironment::RegisterBluetoothMedium(
void MediumEnvironment::UpdateBluetoothMedium(
api::BluetoothClassicMedium& medium, BluetoothDiscoveryCallback callback) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium,
callback = std::move(callback)]() {
auto item = bluetooth_mediums_.find(&medium);
if (item == bluetooth_mediums_.end()) return;
auto& context = item->second;
context.callback = std::move(callback);
auto* owned_adapter = context.adapter;
NEARBY_LOGS(INFO) << "Updated: this=" << this << "; medium=" << &medium
<< "; adapter=" << owned_adapter
<< "; name=" << owned_adapter->GetName()
<< "; enabled=" << owned_adapter->IsEnabled()
<< "; mode=" << int32_t(owned_adapter->GetScanMode());
for (auto& adapter_device : bluetooth_adapters_) {
auto& adapter = adapter_device.first;
auto& device = adapter_device.second;
if (adapter == nullptr) continue;
OnBluetoothDeviceStateChanged(context, *device, adapter->GetName(),
adapter->GetScanMode(),
adapter->IsEnabled());
}
});
RunOnMediumEnvironmentThread(
[this, &medium, callback = std::move(callback)]() {
auto item = bluetooth_mediums_.find(&medium);
if (item == bluetooth_mediums_.end()) return;
auto& context = item->second;
context.callback = std::move(callback);
auto* owned_adapter = context.adapter;
NEARBY_LOGS(INFO) << "Updated: this=" << this << "; medium=" << &medium
<< "; adapter=" << owned_adapter
<< "; name=" << owned_adapter->GetName()
<< "; enabled=" << owned_adapter->IsEnabled()
<< "; mode=" << int32_t(owned_adapter->GetScanMode());
for (auto& adapter_device : bluetooth_adapters_) {
auto& adapter = adapter_device.first;
auto& device = adapter_device.second;
if (adapter == nullptr) continue;
OnBluetoothDeviceStateChanged(context, *device, adapter->GetName(),
adapter->GetScanMode(),
adapter->IsEnabled());
}
});
}
void MediumEnvironment::UnregisterBluetoothMedium(
@@ -369,35 +369,37 @@ void MediumEnvironment::UpdateBleMediumForScanning(
const std::string& fast_advertisement_service_uuid,
BleDiscoveredPeripheralCallback callback, bool enabled) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, service_id,
fast_advertisement_service_uuid,
callback = std::move(callback), enabled]() {
auto item = ble_mediums_.find(&medium);
if (item == ble_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateBleMediumFoScanning failed. There is no medium "
"registered.";
return;
}
auto& context = item->second;
context.discovery_callback = std::move(callback);
NEARBY_LOGS(INFO) << "Update Ble medium for scanning: this=" << this
<< "; medium=" << &medium << "; service_id=" << service_id
<< "; fast_advertisement_service_uuid="
<< fast_advertisement_service_uuid
<< "; enabled=" << enabled;
for (auto& medium_info : ble_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
// Search advertising mediums and send notification.
if (info.advertising && enabled) {
OnBlePeripheralStateChanged(context, *(info.ble_peripheral), service_id,
info.fast_advertisement, enabled);
}
}
});
RunOnMediumEnvironmentThread(
[this, &medium, service_id, fast_advertisement_service_uuid,
callback = std::move(callback), enabled]() {
auto item = ble_mediums_.find(&medium);
if (item == ble_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateBleMediumFoScanning failed. There is no medium "
"registered.";
return;
}
auto& context = item->second;
context.discovery_callback = std::move(callback);
NEARBY_LOGS(INFO) << "Update Ble medium for scanning: this=" << this
<< "; medium=" << &medium
<< "; service_id=" << service_id
<< "; fast_advertisement_service_uuid="
<< fast_advertisement_service_uuid
<< "; enabled=" << enabled;
for (auto& medium_info : ble_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
// Search advertising mediums and send notification.
if (info.advertising && enabled) {
OnBlePeripheralStateChanged(context, *(info.ble_peripheral),
service_id, info.fast_advertisement,
enabled);
}
}
});
}
void MediumEnvironment::UpdateBleMediumForAcceptedConnection(
@@ -433,17 +435,18 @@ void MediumEnvironment::CallBleAcceptedConnectionCallback(
api::BleMedium& medium, api::BleSocket& socket,
const std::string& service_id) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, &socket, service_id]() {
auto item = ble_mediums_.find(&medium);
if (item == ble_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Call AcceptedConnectionCallback failed. There is no medium "
"registered.";
return;
}
auto& info = item->second;
info.accepted_connection_callback.accepted_cb(socket, service_id);
});
RunOnMediumEnvironmentThread(
[this, &medium, &socket, service_id]() {
auto item = ble_mediums_.find(&medium);
if (item == ble_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Call AcceptedConnectionCallback failed. There is no medium "
"registered.";
return;
}
auto& info = item->second;
info.accepted_connection_callback.accepted_cb(socket, service_id);
});
}
void MediumEnvironment::RegisterWebRtcSignalingMessenger(
@@ -536,113 +539,116 @@ void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
api::WifiLanMedium& medium, api::WifiLanService& wifi_lan_service,
const std::string& service_id, bool enabled) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, &wifi_lan_service, service_id,
enabled]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateWifiLanMediumForAdvertising failed. There is no medium "
"registered.";
return;
}
auto& context = item->second;
context.wifi_lan_service = &wifi_lan_service;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.advertising = enabled,
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.advertising = enabled;
}
NEARBY_LOGS(INFO) << "Update WifiLan medium for advertising: this=" << this
<< "; medium=" << &medium << "; service_id=" << service_id
<< "; wifi_lan_service=" << &wifi_lan_service
<< ", service_info_name="
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
<< "; enabled=" << enabled;
for (auto& medium_info : wifi_lan_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
OnWifiLanServiceStateChanged(info, wifi_lan_service, service_id, enabled);
}
});
RunOnMediumEnvironmentThread(
[this, &medium, &wifi_lan_service, service_id, enabled]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateWifiLanMediumForAdvertising failed. There is no medium "
"registered.";
return;
}
auto& context = item->second;
context.wifi_lan_service = &wifi_lan_service;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.advertising = enabled,
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.advertising = enabled;
}
NEARBY_LOGS(INFO) << "Update WifiLan medium for advertising: this="
<< this << "; medium=" << &medium
<< "; service_id=" << service_id
<< "; wifi_lan_service=" << &wifi_lan_service
<< ", service_info_name="
<< wifi_lan_service.GetServiceInfo().GetServiceName()
<< "; enabled=" << enabled;
for (auto& medium_info : wifi_lan_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
OnWifiLanServiceStateChanged(info, wifi_lan_service, service_id,
enabled);
}
});
}
void MediumEnvironment::UpdateWifiLanMediumForDiscovery(
api::WifiLanMedium& medium, const std::string& service_id,
WifiLanDiscoveredServiceCallback callback, bool enabled) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, service_id,
callback = std::move(callback), enabled]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateWifiLanMediumForDiscovery failed. There is no medium "
"registered.";
return;
}
auto& context = item->second;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.discovery_callback = std::move(callback),
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.discovery_callback = std::move(callback);
}
NEARBY_LOGS(INFO) << "Update WifiLan medium for discovery: this=" << this
<< "; medium=" << &medium << "; service_id=" << service_id
<< "; enabled=" << enabled;
for (auto& medium_info : wifi_lan_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
// Search advertising mediums and send notification.
for (auto& service_id_context : info.services) {
auto& service_id = service_id_context.first;
auto& id_context = service_id_context.second;
if (id_context.advertising && enabled) {
OnWifiLanServiceStateChanged(context, *(info.wifi_lan_service),
service_id, enabled);
RunOnMediumEnvironmentThread(
[this, &medium, service_id, callback = std::move(callback), enabled]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "UpdateWifiLanMediumForDiscovery failed. There is no medium "
"registered.";
return;
}
}
}
});
auto& context = item->second;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.discovery_callback = std::move(callback),
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.discovery_callback = std::move(callback);
}
NEARBY_LOGS(INFO) << "Update WifiLan medium for discovery: this="
<< this << "; medium=" << &medium
<< "; service_id=" << service_id
<< "; enabled=" << enabled;
for (auto& medium_info : wifi_lan_mediums_) {
auto& local_medium = medium_info.first;
auto& info = medium_info.second;
// Do not send notification to the same medium.
if (local_medium == &medium) continue;
// Search advertising mediums and send notification.
for (auto& service_id_context : info.services) {
auto& service_id = service_id_context.first;
auto& id_context = service_id_context.second;
if (id_context.advertising && enabled) {
OnWifiLanServiceStateChanged(context, *(info.wifi_lan_service),
service_id, enabled);
}
}
}
});
}
void MediumEnvironment::UpdateWifiLanMediumForAcceptedConnection(
api::WifiLanMedium& medium, const std::string& service_id,
WifiLanAcceptedConnectionCallback callback) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, service_id,
callback = std::move(callback)]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Update WifiLan medium failed. There is no medium registered.";
return;
}
auto& context = item->second;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.accepted_connection_callback = std::move(callback),
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.accepted_connection_callback =
std::move(callback);
}
NEARBY_LOGS(INFO) << "Update WifiLan medium for accepted callback: this="
<< this << "; medium=" << &medium
<< "; service_id=" << service_id;
});
RunOnMediumEnvironmentThread(
[this, &medium, service_id, callback = std::move(callback)]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Update WifiLan medium failed. There is no medium registered.";
return;
}
auto& context = item->second;
auto service_id_context = context.services.find(service_id);
if (service_id_context == context.services.end()) {
WifiLanServiceIdContext id_context{
.accepted_connection_callback = std::move(callback),
};
context.services.emplace(service_id, std::move(id_context));
} else {
service_id_context->second.accepted_connection_callback =
std::move(callback);
}
NEARBY_LOGS(INFO)
<< "Update WifiLan medium for accepted callback: this=" << this
<< "; medium=" << &medium << "; service_id=" << service_id;
});
}
void MediumEnvironment::UnregisterWifiLanMedium(api::WifiLanMedium& medium) {
@@ -658,40 +664,43 @@ void MediumEnvironment::CallWifiLanAcceptedConnectionCallback(
api::WifiLanMedium& medium, api::WifiLanSocket& socket,
const std::string& service_id) {
if (!enabled_) return;
RunOnMediumEnvironmentThread([this, &medium, &socket, service_id]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Call AcceptedConnectionCallback failed.. There is no medium "
"registered.";
return;
}
auto& info = item->second;
auto service_id_context = info.services.find(service_id);
if (service_id_context != info.services.end()) {
service_id_context->second.accepted_connection_callback.accepted_cb(
socket, service_id);
}
});
RunOnMediumEnvironmentThread(
[this, &medium, &socket, service_id]() {
auto item = wifi_lan_mediums_.find(&medium);
if (item == wifi_lan_mediums_.end()) {
NEARBY_LOGS(INFO)
<< "Call AcceptedConnectionCallback failed.. There is no medium "
"registered.";
return;
}
auto& info = item->second;
auto service_id_context = info.services.find(service_id);
if (service_id_context != info.services.end()) {
service_id_context->second.accepted_connection_callback.accepted_cb(
socket, service_id);
}
});
}
api::WifiLanService* MediumEnvironment::GetWifiLanService(
const std::string& ip_address, int port) {
api::WifiLanService* remote_wifi_lan_service = nullptr;
CountDownLatch latch(1);
RunOnMediumEnvironmentThread([this, &remote_wifi_lan_service, &ip_address,
port, &latch]() {
for (auto& item : wifi_lan_mediums_) {
auto* wifi_lan_service = item.second.wifi_lan_service;
if (!wifi_lan_service) continue;
auto addr = remote_wifi_lan_service->GetServiceInfo().GetServiceAddress();
if (addr.first == ip_address && addr.second == port) {
remote_wifi_lan_service = wifi_lan_service;
break;
}
}
latch.CountDown();
});
RunOnMediumEnvironmentThread(
[this, &remote_wifi_lan_service, &ip_address, port, &latch]() {
for (auto& item : wifi_lan_mediums_) {
auto* wifi_lan_service = item.second.wifi_lan_service;
if (!wifi_lan_service) continue;
std::string remote_ip_address =
remote_wifi_lan_service->GetServiceInfo().GetIPAddress();
int remote_port = remote_wifi_lan_service->GetServiceInfo().GetPort();
if (remote_ip_address == ip_address && remote_port == port) {
remote_wifi_lan_service = wifi_lan_service;
break;
}
}
latch.CountDown();
});
latch.Await();
return remote_wifi_lan_service;
}
+38 -15
View File
@@ -25,6 +25,9 @@ namespace nearby {
// https://developer.android.com/reference/android/net/nsd/NsdServiceInfo.html.
class NsdServiceInfo {
public:
static constexpr int kTypeFromServiceIdHashLength = 6;
static constexpr absl::string_view kNsdTypeFormat{"_%s._tcp."};
NsdServiceInfo() = default;
NsdServiceInfo(const NsdServiceInfo&) = default;
NsdServiceInfo& operator=(const NsdServiceInfo&) = default;
@@ -32,12 +35,12 @@ class NsdServiceInfo {
NsdServiceInfo& operator=(NsdServiceInfo&&) = default;
~NsdServiceInfo() = default;
// Returns the packed string of |WifiLanServiceInfo|.
std::string GetServiceInfoName() const { return service_info_name_; }
// Gets the service name.
std::string GetServiceName() const { return service_name_; }
// Sets the packed string of |WifiLanServiceInfo|.
void SetServiceInfoName(std::string service_info_name) {
service_info_name_ = std::move(service_info_name);
// Sets the service name.
void SetServiceName(std::string service_name) {
service_name_ = std::move(service_name);
}
// Gets the TXTRecord value of the specified TXTRecord key assigned.
@@ -54,25 +57,45 @@ class NsdServiceInfo {
txt_records_.emplace(txt_record_key, txt_record_value);
}
// Returns the advertising device's <IP address, port> as a pair.
// IP address is in byte sequence, in network order.
std::pair<std::string, int> GetServiceAddress() const {
return std::make_pair(ip_address_, port_);
// Gets all TXTRecord.
absl::flat_hash_map<std::string, std::string> GetTxtRecords() const {
return txt_records_;
}
// Sets the ip address and port of the local device.
void SetServiceAddress(const std::string& ip_address, int port) {
ip_address_ = ip_address;
port_ = port;
// Sets all TXTRecord.
void SetTxtRecords(
absl::flat_hash_map<std::string, std::string>& txt_records) {
txt_records_ = txt_records;
}
bool IsValid() const { return !service_info_name_.empty(); }
// Gets IP Address, which is in byte sequence, in network order.
std::string GetIPAddress() const { return ip_address_; }
// Sets IP Address.
void SetIPAddress(const std::string& ip_address) { ip_address_ = ip_address; }
// Gets the port number
int GetPort() const { return port_; }
// Sets the port number.
void SetPort(int port) { port_ = port; }
// Gets the service type.
std::string GetServiceType() const { return service_type_; }
// Sets the service type.
void SetServiceType(const std::string& service_type) {
service_type_ = service_type;
}
bool IsValid() const { return !service_name_.empty(); }
private:
std::string service_info_name_;
std::string service_name_;
absl::flat_hash_map<std::string, std::string> txt_records_;
std::string ip_address_;
int port_;
std::string service_type_;
};
} // namespace nearby
+22 -23
View File
@@ -17,6 +17,7 @@
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include "absl/synchronization/mutex.h"
#include "platform/api/wifi_lan.h"
@@ -203,7 +204,7 @@ bool WifiLanMedium::StartAdvertising(const std::string& service_id,
"G3 WifiLan StartAdvertising: service_id=%s, nsd_service_info=%p, "
"service_info_name=%s",
service_id.c_str(), &nsd_service_info,
nsd_service_info.GetServiceInfoName().c_str());
nsd_service_info.GetServiceName().c_str());
auto& env = MediumEnvironment::Instance();
NsdServiceInfo local_nsd_service_info{nsd_service_info};
SetWifiLanService(nsd_service_info);
@@ -320,13 +321,12 @@ bool WifiLanMedium::StopAcceptingConnections(const std::string& service_id) {
std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
api::WifiLanService& remote_wifi_lan_service, const std::string& service_id,
CancellationFlag* cancellation_flag) {
NEARBY_LOG(
INFO,
"G3 WifiLan Connect: medium=%p, wifi_lan_service=%p, "
"service_info_name=%s, service_id=%s",
this, &wifi_lan_service_,
remote_wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str(),
service_id.c_str());
NEARBY_LOG(INFO,
"G3 WifiLan Connect: medium=%p, wifi_lan_service=%p, "
"service_info_name=%s, service_id=%s",
this, &wifi_lan_service_,
remote_wifi_lan_service.GetServiceInfo().GetServiceName().c_str(),
service_id.c_str());
// First, find an instance of remote medium, that exposed this service.
auto* remote_medium =
static_cast<WifiLanService&>(remote_wifi_lan_service).GetMedium();
@@ -334,13 +334,12 @@ std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
if (!remote_medium) return {}; // Can't find medium. Bail out.
WifiLanServerSocket* remote_server_socket = nullptr;
NEARBY_LOG(
INFO,
"G3 WifiLan Connect [peer]: remote_wifi_lan_service=%p, "
"remote_service_info_name=%s, service_id=%s",
&remote_wifi_lan_service,
remote_wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str(),
service_id.c_str());
NEARBY_LOG(INFO,
"G3 WifiLan Connect [peer]: remote_wifi_lan_service=%p, "
"remote_service_info_name=%s, service_id=%s",
&remote_wifi_lan_service,
remote_wifi_lan_service.GetServiceInfo().GetServiceName().c_str(),
service_id.c_str());
// Then, find our server socket context in this medium.
{
absl::MutexLock medium_lock(&remote_medium->mutex_);
@@ -389,22 +388,22 @@ api::WifiLanService* WifiLanMedium::GetRemoteService(
return env.GetWifiLanService(ip_address, port);
}
std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
std::pair<std::string, int> WifiLanMedium::GetCredentials(
const std::string& service_id) {
NEARBY_LOGS(INFO) << "G3 WifiLan GetServiceAddress: service_id="
<< service_id;
return wifi_lan_service_.GetServiceInfo().GetServiceAddress();
NEARBY_LOGS(INFO) << "G3 WifiLan GetCredential: service_id=" << service_id;
return std::make_pair(wifi_lan_service_.GetServiceInfo().GetIPAddress(),
wifi_lan_service_.GetServiceInfo().GetPort());
}
void WifiLanMedium::SetWifiLanService(const NsdServiceInfo& nsd_service_info) {
NsdServiceInfo local_nsd_service_info{nsd_service_info};
auto service_address = GetFakeServiceAddress();
local_nsd_service_info.SetServiceAddress(service_address.first,
service_address.second);
auto credential = GetFakeCredentials();
local_nsd_service_info.SetIPAddress(credential.first);
local_nsd_service_info.SetPort(credential.second);
wifi_lan_service_.SetServiceInfo(local_nsd_service_info);
}
std::pair<std::string, int> WifiLanMedium::GetFakeServiceAddress() const {
std::pair<std::string, int> WifiLanMedium::GetFakeCredentials() const {
std::string ip_address;
ip_address.resize(4);
uint32_t raw_ip_addr = Prng().NextUint32();
+2 -2
View File
@@ -210,7 +210,7 @@ class WifiLanMedium : public api::WifiLanMedium {
api::WifiLanService* GetRemoteService(const std::string& ip_address,
int port) override;
std::pair<std::string, int> GetServiceAddress(
std::pair<std::string, int> GetCredentials(
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
private:
@@ -231,7 +231,7 @@ class WifiLanMedium : public api::WifiLanMedium {
};
void SetWifiLanService(const NsdServiceInfo& nsd_service_info);
std::pair<std::string, int> GetFakeServiceAddress() const;
std::pair<std::string, int> GetFakeCredentials() const;
absl::Mutex mutex_;
WifiLanService wifi_lan_service_;
+4 -4
View File
@@ -220,7 +220,7 @@ class WifiLanNsd {
// A pair of IP Address and Port. A remote device can use this information
// to connect to us. This is non-null while IsAccepting is true.
std::pair<std::string, int> GetServiceAddress();
std::pair<std::string, int> GetCredentials();
// DnsServiceDeRegister is a async process, after operation finish, callback
// will call this method to notify the waiting method StopAdvertising to
@@ -263,9 +263,9 @@ class WifiLanNsd {
// Private methods
//
// Generates prefered listening port. If cannot bind to this port,
// Generates preferred listening port. If cannot bind to this port,
// NSD will assign a random port for the service.
// TODO: Windows firewall may break the solution, need to futher solution to
// TODO: Windows firewall may break the solution, need to further solution to
// resolve the potential issue
uint16 GenerateSocketPort(const std::string& service_id);
@@ -384,7 +384,7 @@ class WifiLanMedium : public api::WifiLanMedium {
int port) override;
// returns advertising service address
std::pair<std::string, int> GetServiceAddress(
std::pair<std::string, int> GetCredentials(
const std::string& service_id) override;
// for internal to clean closed connection.
+7 -6
View File
@@ -160,14 +160,15 @@ std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
api::WifiLanService& wifi_lan_service, const std::string& service_id,
CancellationFlag* cancellation_flag) {
try {
auto address = wifi_lan_service.GetServiceInfo().GetServiceAddress();
if (address.first.empty() || address.second == 0) {
std::string ip_address = wifi_lan_service.GetServiceInfo().GetIPAddress();
int port = wifi_lan_service.GetServiceInfo().GetPort();
if (ip_address.empty() || port == 0) {
NEARBY_LOGS(ERROR) << "no valid service address and port to connect.";
return nullptr;
}
HostName host_name{string_to_wstring(address.first)};
winrt::hstring service_name{winrt::to_hstring(address.second)};
HostName host_name{string_to_wstring(ip_address)};
winrt::hstring service_name{winrt::to_hstring(port)};
StreamSocket socket{};
@@ -232,7 +233,7 @@ api::WifiLanService* WifiLanMedium::GetRemoteService(
}
}
std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
std::pair<std::string, int> WifiLanMedium::GetCredentials(
const std::string& service_id) {
try {
WifiLanNsd* nsd = GetNsd(service_id, true);
@@ -242,7 +243,7 @@ std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
return std::pair<std::string, int>{"", 0};
}
return nsd->GetServiceAddress();
return nsd->GetCredentials();
} catch (...) {
NEARBY_LOGS(ERROR) << "failed to get service address due to "
<< GetErrorMessage(std::current_exception());
+15 -12
View File
@@ -43,7 +43,7 @@ bool WifiLanNsd::StartAcceptingConnections(
if (ip_addresses_.empty()) {
NEARBY_LOGS(WARNING) << "failed to start accepting connection without IP "
"addreses configured on computer.";
"addresses configured on computer.";
return false;
}
@@ -121,7 +121,7 @@ bool WifiLanNsd::StartAdvertising(const NsdServiceInfo& nsd_service_info) {
return false;
}
if (nsd_service_info.GetServiceInfoName().empty()) {
if (nsd_service_info.GetServiceName().empty()) {
NEARBY_LOGS(ERROR) << "cannot start advertising without service name.";
return false;
}
@@ -131,13 +131,14 @@ bool WifiLanNsd::StartAdvertising(const NsdServiceInfo& nsd_service_info) {
std::stoi(stream_socket_listener_.Information().LocalPort().c_str());
NsdServiceInfo new_nsd_servcie_info = nsd_service_info;
// TODO: need feature enhancement to support multiple network interfaces
new_nsd_servcie_info.SetServiceAddress(ip_addresses_[0], port);
new_nsd_servcie_info.SetIPAddress(ip_addresses_[0]);
new_nsd_servcie_info.SetPort(port);
wifi_lan_service_ = WifiLanService(new_nsd_servcie_info);
wifi_lan_service_.SetMedium(medium_);
std::string instance_name = absl::StrFormat(
MDNS_INSTANCE_NAME_FORMAT.data(),
wifi_lan_service_.GetServiceInfo().GetServiceInfoName(), service_type_);
wifi_lan_service_.GetServiceInfo().GetServiceName(), service_type_);
NEARBY_LOGS(INFO) << "mDNS instance name is " << instance_name;
@@ -212,8 +213,8 @@ bool WifiLanNsd::StopAdvertising() {
// Init DNS service instance
std::string instance_name = absl::StrFormat(
MDNS_INSTANCE_NAME_FORMAT.data(),
wifi_lan_service_.GetServiceInfo().GetServiceInfoName(), service_type_);
int port = wifi_lan_service_.GetServiceInfo().GetServiceAddress().second;
wifi_lan_service_.GetServiceInfo().GetServiceName(), service_type_);
int port = wifi_lan_service_.GetServiceInfo().GetPort();
dns_service_instance_name_ =
std::make_unique<std::wstring>(string_to_wstring(instance_name));
@@ -311,14 +312,15 @@ bool WifiLanNsd::StopDiscovery() {
return true;
}
std::pair<std::string, int> WifiLanNsd::GetServiceAddress() {
std::pair<std::string, int> WifiLanNsd::GetCredentials() {
if (!IsAdvertising()) {
// no advertising is running
NEARBY_LOGS(WARNING) << "no advertising for service id " << service_id_;
return std::pair<std::string, int>{"", 0};
}
return wifi_lan_service_.GetServiceInfo().GetServiceAddress();
return std::make_pair(wifi_lan_service_.GetServiceInfo().GetIPAddress(),
wifi_lan_service_.GetServiceInfo().GetPort());
}
std::vector<std::string> WifiLanNsd::GetIpAddresses() {
@@ -361,7 +363,7 @@ NsdServiceInfo WifiLanNsd::GetNsdServiceInformation(
<< "no service name information in device information.";
return nsd_service_info;
}
nsd_service_info.SetServiceInfoName(
nsd_service_info.SetServiceName(
InspectableReader::ReadString(inspectable));
// IP Address information
@@ -387,7 +389,8 @@ NsdServiceInfo WifiLanNsd::GetNsdServiceInformation(
}
int port = InspectableReader::ReadUint16(inspectable);
nsd_service_info.SetServiceAddress(ip_address, port);
nsd_service_info.SetIPAddress(ip_address);
nsd_service_info.SetPort(port);
// read text record
inspectable = properties.TryLookup(L"System.Devices.Dnssd.TextAttributes");
@@ -418,7 +421,7 @@ fire_and_forget WifiLanNsd::Watcher_DeviceAdded(DeviceWatcher sender,
DeviceInformation deviceInfo) {
NEARBY_LOGS(INFO) << "device added for service " << service_id_;
// need to read IP address and port informaiton from deviceInfo
// need to read IP address and port information from deviceInfo
NsdServiceInfo nsd_service_info =
GetNsdServiceInformation(deviceInfo.Properties());
@@ -447,7 +450,7 @@ fire_and_forget WifiLanNsd::Watcher_DeviceUpdated(
fire_and_forget WifiLanNsd::Watcher_DeviceRemoved(
DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate) {
NEARBY_LOGS(INFO) << "device removed for service " << service_id_;
// need to read IP address and port informaiton from deviceInfo
// need to read IP address and port information from deviceInfo
NsdServiceInfo nsd_service_info =
GetNsdServiceInformation(deviceInfoUpdate.Properties());
+5 -5
View File
@@ -53,7 +53,7 @@ bool WifiLanMedium::StartDiscovery(const std::string& service_id,
"service_info_name=%s",
&context.wifi_lan_service, &wifi_lan_service,
wifi_lan_service.GetServiceInfo()
.GetServiceInfoName()
.GetServiceName()
.c_str());
return;
} else {
@@ -63,7 +63,7 @@ bool WifiLanMedium::StartDiscovery(const std::string& service_id,
"Discovering wifi_lan_service=%p, service_info_name=%s",
&wifi_lan_service,
wifi_lan_service.GetServiceInfo()
.GetServiceInfoName()
.GetServiceName()
.c_str());
}
discovered_service_callback_.service_discovered_cb(
@@ -143,7 +143,7 @@ WifiLanSocket WifiLanMedium::Connect(WifiLanService& wifi_lan_service,
INFO,
"WifiLanMedium::Connect: service=%p [impl=%p, service_info_name=%s]",
&wifi_lan_service, &wifi_lan_service.GetImpl(),
wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str());
wifi_lan_service.GetServiceInfo().GetServiceName().c_str());
return WifiLanSocket(impl_->Connect(wifi_lan_service.GetImpl(), service_id,
cancellation_flag));
}
@@ -153,9 +153,9 @@ WifiLanService WifiLanMedium::GetRemoteService(const std::string& ip_address,
return WifiLanService(impl_->GetRemoteService(ip_address, port));
}
std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
std::pair<std::string, int> WifiLanMedium::GetCredentials(
const std::string& service_id) {
return impl_->GetServiceAddress(service_id);
return impl_->GetCredentials(service_id);
}
} // namespace nearby
+1 -1
View File
@@ -161,7 +161,7 @@ class WifiLanMedium final {
WifiLanService GetRemoteService(const std::string& ip_address, int port);
std::pair<std::string, int> GetServiceAddress(const std::string& service_id);
std::pair<std::string, int> GetCredentials(const std::string& service_id);
private:
Mutex mutex_;
+11 -13
View File
@@ -73,17 +73,16 @@ TEST_P(WifiLanMediumTest, CanStartAcceptingConnectionsAndConnect) {
.service_discovered_cb =
[&found_latch, &discovered_service](
WifiLanService& service, const std::string& service_id) {
NEARBY_LOG(
INFO, "Service discovered: %s, %p",
service.GetServiceInfo().GetServiceInfoName().c_str(),
&service);
NEARBY_LOG(INFO, "Service discovered: %s, %p",
service.GetServiceInfo().GetServiceName().c_str(),
&service);
discovered_service = &service;
found_latch.CountDown();
},
});
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_b.StartAdvertising(service_id, nsd_service_info);
@@ -135,17 +134,16 @@ TEST_P(WifiLanMediumTest, CanCancelConnect) {
.service_discovered_cb =
[&found_latch, &discovered_service](
WifiLanService& service, const std::string& service_id) {
NEARBY_LOG(
INFO, "Service discovered: %s, %p",
service.GetServiceInfo().GetServiceInfoName().c_str(),
&service);
NEARBY_LOG(INFO, "Service discovered: %s, %p",
service.GetServiceInfo().GetServiceName().c_str(),
&service);
discovered_service = &service;
found_latch.CountDown();
},
});
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_b.StartAdvertising(service_id, nsd_service_info);
@@ -212,7 +210,7 @@ TEST_F(WifiLanMediumTest, CanStartAdvertising) {
CountDownLatch found_latch(1);
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
wifi_a.StartAdvertising(service_id, nsd_service_info);
@@ -256,7 +254,7 @@ TEST_F(WifiLanMediumTest, CanStartDiscovery) {
});
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
EXPECT_TRUE(wifi_b.StartAdvertising(service_id, nsd_service_info));
@@ -292,7 +290,7 @@ TEST_F(WifiLanMediumTest, CanStopDiscovery) {
});
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceInfoName(service_info_name);
nsd_service_info.SetServiceName(service_info_name);
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
endpoint_info_name);
+18 -18
View File
@@ -20,11 +20,11 @@ namespace location {
namespace nearby {
namespace connections {
DLL_API Core* InitCore(ServiceControllerRouter* router) {
Core* InitCore(ServiceControllerRouter* router) {
return new Core(router);
}
DLL_API void CloseCore(Core* pCore) {
void CloseCore(Core* pCore) {
if (pCore) {
pCore->StopAllEndpoints(
{.result_cb =
@@ -34,7 +34,7 @@ DLL_API void CloseCore(Core* pCore) {
}
}
DLL_API void StartAdvertising(Core* pCore, const char* service_id,
void StartAdvertising(Core* pCore, const char* service_id,
ConnectionOptions options,
ConnectionRequestInfo info,
ResultCallback callback) {
@@ -43,13 +43,13 @@ DLL_API void StartAdvertising(Core* pCore, const char* service_id,
}
}
DLL_API void StopAdvertising(Core* pCore, ResultCallback callback) {
void StopAdvertising(Core* pCore, ResultCallback callback) {
if (pCore) {
pCore->StopAdvertising(callback);
}
}
DLL_API void StartDiscovery(Core* pCore, const char* service_id,
void StartDiscovery(Core* pCore, const char* service_id,
ConnectionOptions options,
DiscoveryListener listener,
ResultCallback callback) {
@@ -58,13 +58,13 @@ DLL_API void StartDiscovery(Core* pCore, const char* service_id,
}
}
DLL_API void StopDiscovery(Core* pCore, ResultCallback callback) {
void StopDiscovery(Core* pCore, ResultCallback callback) {
if (pCore) {
pCore->StopDiscovery(callback);
}
}
DLL_API void InjectEndpoint(Core* pCore, char* service_id,
void InjectEndpoint(Core* pCore, char* service_id,
OutOfBandConnectionMetadata metadata,
ResultCallback callback) {
if (pCore) {
@@ -72,7 +72,7 @@ DLL_API void InjectEndpoint(Core* pCore, char* service_id,
}
}
DLL_API void RequestConnection(Core* pCore, const char* endpoint_id,
void RequestConnection(Core* pCore, const char* endpoint_id,
ConnectionRequestInfo info,
ConnectionOptions options,
ResultCallback callback) {
@@ -81,7 +81,7 @@ DLL_API void RequestConnection(Core* pCore, const char* endpoint_id,
}
}
DLL_API void AcceptConnection(Core* pCore, const char* endpoint_id,
void AcceptConnection(Core* pCore, const char* endpoint_id,
PayloadListener listener,
ResultCallback callback) {
if (pCore) {
@@ -89,14 +89,14 @@ DLL_API void AcceptConnection(Core* pCore, const char* endpoint_id,
}
}
DLL_API void RejectConnection(Core* pCore, const char* endpoint_id,
void RejectConnection(Core* pCore, const char* endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->RejectConnection(endpoint_id, callback);
}
}
DLL_API void SendPayload(Core* pCore,
void SendPayload(Core* pCore,
// todo(jfcarroll) this is being exported, needs to be
// refactored to return a plain old c type
absl::Span<const std::string> endpoint_ids,
@@ -106,34 +106,34 @@ DLL_API void SendPayload(Core* pCore,
}
}
DLL_API void CancelPayload(Core* pCore, std::int64_t payload_id,
void CancelPayload(Core* pCore, std::int64_t payload_id,
ResultCallback callback) {
if (pCore) {
pCore->CancelPayload(payload_id, callback);
}
}
DLL_API void DisconnectFromEndpoint(Core* pCore, char* endpoint_id,
void DisconnectFromEndpoint(Core* pCore, char* endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->DisconnectFromEndpoint(endpoint_id, callback);
}
}
DLL_API void StopAllEndpoints(Core* pCore, ResultCallback callback) {
void StopAllEndpoints(Core* pCore, ResultCallback callback) {
if (pCore) {
pCore->StopAllEndpoints(callback);
}
}
DLL_API void InitiateBandwidthUpgrade(Core* pCore, char* endpoint_id,
void InitiateBandwidthUpgrade(Core* pCore, char* endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->InitiateBandwidthUpgrade(endpoint_id, callback);
}
}
DLL_API const char* GetLocalEndpointId(Core* pCore) {
const char* GetLocalEndpointId(Core* pCore) {
if (pCore) {
std::string endpoint_id = pCore->GetLocalEndpointId();
char* result = new char[endpoint_id.length() + 1];
@@ -143,11 +143,11 @@ DLL_API const char* GetLocalEndpointId(Core* pCore) {
return "Null-Core";
}
DLL_API ServiceControllerRouter* InitServiceControllerRouter() {
ServiceControllerRouter* InitServiceControllerRouter() {
return new ServiceControllerRouter();
}
DLL_API void CloseServiceControllerRouter(ServiceControllerRouter* pRouter) {
void CloseServiceControllerRouter(ServiceControllerRouter* pRouter) {
if (pRouter) {
delete pRouter;
}
+33 -27
View File
@@ -18,9 +18,11 @@
#include "absl/types/span.h"
// todo(jfcarroll) This cannot remain. It exposes stuff the client doesn't need.
#include "core/internal/offline_service_controller.h"
#include \
"third_party/nearby_connections/cpp/core/internal/offline_service_controller.h"
#define DLL_EXPORT extern "C" __declspec(dllexport)
#define DLL_API extern "C" __declspec(dllexport)
namespace location {
namespace nearby {
namespace connections {
@@ -32,17 +34,17 @@ class ServiceControllerRouter;
// app side. If no factory is provided, it will initialize a new
// factory creating OffilineServiceController.
// Returns the instance handle to c# client.
DLL_API Core* __stdcall InitCoreWithServiceControllerFactory(
DLL_EXPORT Core* __stdcall InitCoreWithServiceControllerFactory(
std::function<ServiceController*()> factory = []() {
return new OfflineServiceController;
});
// Initializes a default Core instance.
// Returns the instance handle to c# client.
DLL_API Core* __stdcall InitCore(ServiceControllerRouter* router);
DLL_EXPORT Core* __stdcall InitCore(ServiceControllerRouter* router);
// Closes the core with stopping all endpoints, then free the memory.
DLL_API void __stdcall CloseCore(Core* pCore);
DLL_EXPORT void __stdcall CloseCore(Core* pCore);
// Starts advertising an endpoint for a local app.
//
@@ -62,7 +64,7 @@ DLL_API void __stdcall CloseCore(Core* pCore);
// Status::STATUS_ALREADY_ADVERTISING if the app is already advertising.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartAdvertising(Core* pCore, const char* service_id,
DLL_EXPORT void __stdcall StartAdvertising(Core* pCore, const char* service_id,
ConnectionOptions options,
ConnectionRequestInfo info,
ResultCallback callback);
@@ -75,7 +77,7 @@ DLL_API void __stdcall StartAdvertising(Core* pCore, const char* service_id,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopAdvertising(Core* pCore, ResultCallback callback);
DLL_EXPORT void __stdcall StopAdvertising(Core* pCore, ResultCallback callback);
// Starts discovery for remote endpoints with the specified service ID.
//
@@ -90,7 +92,7 @@ DLL_API void __stdcall StopAdvertising(Core* pCore, ResultCallback callback);
// discovering the specified service.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartDiscovery(Core* pCore, const char* service_id,
DLL_EXPORT void __stdcall StartDiscovery(Core* pCore, const char* service_id,
ConnectionOptions options,
DiscoveryListener listener,
ResultCallback callback);
@@ -103,7 +105,7 @@ DLL_API void __stdcall StartDiscovery(Core* pCore, const char* service_id,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopDiscovery(Core* pCore, ResultCallback callback);
DLL_EXPORT void __stdcall StopDiscovery(Core* pCore, ResultCallback callback);
// Invokes the discovery callback from a previous call to StartDiscovery()
// with the given endpoint info. The previous call to StartDiscovery() must
@@ -120,7 +122,7 @@ DLL_API void __stdcall StopDiscovery(Core* pCore, ResultCallback callback);
// Status::kError if endpoint_id, endpoint_info, or
// remote_bluetooth_mac_address are malformed.
// Status::kOutOfOrderApiCall if the app is not discovering.
DLL_API void __stdcall InjectEndpoint(Core* pCore, char* service_id,
DLL_EXPORT void __stdcall InjectEndpoint(Core* pCore, char* service_id,
OutOfBandConnectionMetadata metadata,
ResultCallback callback);
@@ -143,10 +145,11 @@ DLL_API void __stdcall InjectEndpoint(Core* pCore, char* service_id,
// Status::STATUS_RADIO_ERROR if we failed to connect because of an
// issue with Bluetooth/WiFi.
// Status::STATUS_ERROR if we failed to connect for any other reason.
DLL_API void __stdcall RequestConnection(Core* pCore, const char* endpoint_id,
ConnectionRequestInfo info,
ConnectionOptions options,
ResultCallback callback);
DLL_EXPORT void __stdcall RequestConnection(Core* pCore,
const char* endpoint_id,
ConnectionRequestInfo info,
ConnectionOptions options,
ResultCallback callback);
// Accepts a connection to a remote endpoint. This method must be called
// before Payloads can be exchanged with the remote endpoint.
@@ -160,9 +163,10 @@ DLL_API void __stdcall RequestConnection(Core* pCore, const char* endpoint_id,
// Status::STATUS_OK if the connection request was accepted.
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already.
// has a connection to the specified endpoint.
DLL_API void __stdcall AcceptConnection(Core* pCore, const char* endpoint_id,
PayloadListener listener,
ResultCallback callback);
DLL_EXPORT void __stdcall AcceptConnection(Core* pCore,
const char* endpoint_id,
PayloadListener listener,
ResultCallback callback);
// Rejects a connection to a remote endpoint.
//
@@ -174,7 +178,7 @@ DLL_API void __stdcall AcceptConnection(Core* pCore, const char* endpoint_id,
// Status::STATUS_OK} if the connection request was rejected.
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT} if the app already
// has a connection to the specified endpoint.
DLL_API void __stdcall RejectConnection(Core* pCore, const char* endpoint_id,
DLL_EXPORT void __stdcall RejectConnection(Core* pCore, const char* endpoint_id,
ResultCallback callback);
// Sends a Payload to a remote endpoint. Payloads can only be sent to remote
@@ -196,7 +200,7 @@ DLL_API void __stdcall RejectConnection(Core* pCore, const char* endpoint_id,
// still occur during transmission (and at different times for
// different endpoints), and will be delivered via
// PayloadCallback#onPayloadTransferUpdate.
DLL_API void __stdcall SendPayload(Core* pCore,
DLL_EXPORT void __stdcall SendPayload(Core* pCore,
absl::Span<const std::string> endpoint_ids,
Payload payload, ResultCallback callback);
@@ -206,7 +210,7 @@ DLL_API void __stdcall SendPayload(Core* pCore,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall CancelPayload(Core* pCore, int64_t payload_id,
DLL_EXPORT void __stdcall CancelPayload(Core* pCore, int64_t payload_id,
ResultCallback callback);
// Disconnects from a remote endpoint. {@link Payload}s can no longer be sent
@@ -216,7 +220,7 @@ DLL_API void __stdcall CancelPayload(Core* pCore, int64_t payload_id,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall DisconnectFromEndpoint(Core* pCore, char* endpoint_id,
DLL_EXPORT void __stdcall DisconnectFromEndpoint(Core* pCore, char* endpoint_id,
ResultCallback callback);
// Disconnects from, and removes all traces of, all connected and/or
@@ -228,7 +232,8 @@ DLL_API void __stdcall DisconnectFromEndpoint(Core* pCore, char* endpoint_id,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall StopAllEndpoints(Core* pCore, ResultCallback callback);
DLL_EXPORT void __stdcall StopAllEndpoints(Core* pCore,
ResultCallback callback);
// Sends a request to initiate connection bandwidth upgrade.
//
@@ -239,19 +244,20 @@ DLL_API void __stdcall StopAllEndpoints(Core* pCore, ResultCallback callback);
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall InitiateBandwidthUpgrade(Core* pCore, char* endpoint_id,
ResultCallback callback);
DLL_EXPORT void __stdcall InitiateBandwidthUpgrade(Core* pCore,
char* endpoint_id,
ResultCallback callback);
// Gets the local endpoint generated by Nearby Connections.
// DLL_API std::string __stdcall GetLocalEndpointId(Core* pCore);
DLL_API const char* __stdcall GetLocalEndpointId(Core* pCore);
DLL_EXPORT const char* __stdcall GetLocalEndpointId(Core* pCore);
// Initializes a default ServiceControllerRouter instance.
// Returns the instance handle to c# client.
DLL_API ServiceControllerRouter* __stdcall InitServiceControllerRouter();
DLL_EXPORT ServiceControllerRouter* __stdcall InitServiceControllerRouter();
// Close a ServiceControllerRouter instance.
DLL_API void __stdcall CloseServiceControllerRouter(
DLL_EXPORT void __stdcall CloseServiceControllerRouter(
ServiceControllerRouter* pRouter);
} // namespace connections
+23 -13
View File
@@ -12,20 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "core/core.h"
#include "core/internal/client_proxy.h"
#include "core/internal/offline_service_controller.h"
#include "core/internal/service_controller.h"
#include "core/internal/service_controller_router.h"
#include "core/listeners.h"
#include "core/options.h"
#include "core/params.h"
#include "third_party/dart_lang/v2/runtime/include/dart_api_dl.h"
#include "third_party/nearby_connections/windows/core_adapter.h"
#include "third_party/nearby_connections/windows/dart/core_adapter_dart.h"
#include "absl/strings/str_format.h"
namespace location {
namespace nearby {
@@ -195,7 +183,18 @@ void StartAdvertisingDart(Core* pCore,
void StopAdvertisingDart(Core* pCore, Dart_Port result_cb) {
if (pCore) {
ResultCallback callback;
pCore->StopAdvertising(callback);
callback.result_cb = [result_cb](Status status) {
NEARBY_LOG(INFO, "Result callback called. %d.", status.value);
Dart_CObject dart_object_result_callback;
dart_object_result_callback.type = Dart_CObject_kInt64;
dart_object_result_callback.value.as_int64 = status.value;
const bool result = Dart_PostCObject_DL(result_cb,
&dart_object_result_callback);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
};
StopAdvertising(pCore, callback);
}
}
@@ -306,6 +305,17 @@ void StartDiscoveryDart(Core* pCore,
void StopDiscoveryDart(Core* pCore, Dart_Port result_cb) {
if (pCore) {
ResultCallback callback;
callback.result_cb = [result_cb](Status status) {
NEARBY_LOG(INFO, "Result callback called. %d.", status.value);
Dart_CObject dart_object_result_callback;
dart_object_result_callback.type = Dart_CObject_kInt64;
dart_object_result_callback.value.as_int64 = status.value;
const bool result = Dart_PostCObject_DL(result_cb,
&dart_object_result_callback);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
};
StopDiscovery(pCore, callback);
}
}
+5 -20
View File
@@ -15,7 +15,8 @@
#ifndef LOCATION_NEARBY_CONNECTIONS_WINDOWS_DART_CORE_ADAPTER_DART_H_
#define LOCATION_NEARBY_CONNECTIONS_WINDOWS_DART_CORE_ADAPTER_DART_H_
#define DLL_API extern "C" __declspec(dllexport)
#include "third_party/nearby_connections/windows/core_adapter.h"
namespace location {
namespace nearby {
namespace connections {
@@ -26,22 +27,6 @@ enum StrategyDart {
P2P_POINT_TO_POINT,
};
// TODO(b/203093770) Replace below with the one that defined in common
struct DartConnectionOptions {
std::string strategy;
bool auto_upgrade_bandwidth;
bool enforce_topology_constraints;
bool low_power;
bool enable_bluetooth_listening;
bool enable_webrtc_listening;
// Whether this is intended to be used in conjunction with InjectEndpoint().
bool is_out_of_band_connection = false;
ByteArray remote_bluetooth_mac_address;
std::string fast_advertisement_service_uuid;
int keep_alive_interval_millis = 0;
int keep_alive_timeout_millis = 0;
};
// Starts advertising an endpoint for a local app.
//
// service_id - An identifier to advertise your app to other endpoints.
@@ -89,7 +74,7 @@ DLL_API void __stdcall StartAdvertisingDart(Core* pCore,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopAdvertisingDart(Core* pCore,
DLL_EXPORT void __stdcall StopAdvertisingDart(Core* pCore,
Dart_Port result_cb);
// Starts discovery for remote endpoints with the specified service ID.
@@ -105,7 +90,7 @@ DLL_API void __stdcall StopAdvertisingDart(Core* pCore,
// discovering the specified service.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartDiscoveryDart(Core* pCore,
DLL_EXPORT void __stdcall StartDiscoveryDart(Core* pCore,
const char* service_id,
StrategyDart strategy,
int forward_unrecognized_bluetooth_devices,
@@ -129,7 +114,7 @@ DLL_API void __stdcall StartDiscoveryDart(Core* pCore,
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopDiscoveryDart(Core* pCore,
DLL_EXPORT void __stdcall StopDiscoveryDart(Core* pCore,
Dart_Port result_cb);
} // namespace connections
} // namespace nearby