mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Merge branch 'release' into github to roll forward to cl/343785060.
This commit is contained in:
@@ -53,6 +53,7 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
"//platform/base",
|
||||
"//platform/base:util",
|
||||
"//platform/public:comm",
|
||||
"//platform/public:logging",
|
||||
"//platform/public:types",
|
||||
|
||||
@@ -34,14 +34,13 @@ bool WifiLan::IsAvailable() const {
|
||||
bool WifiLan::IsAvailableLocked() const { return medium_.IsValid(); }
|
||||
|
||||
bool WifiLan::StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name) {
|
||||
const NsdServiceInfo& nsd_service_info) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (service_info_name.empty()) {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Refusing to turn on WifiLan advertising. Empty service info name.");
|
||||
if (!nsd_service_info.IsValid()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Refusing to turn on WifiLan advertising. nsd_service_info is not "
|
||||
"valid.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,16 +50,19 @@ bool WifiLan::StartAdvertising(const std::string& service_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!medium_.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name)) {
|
||||
NEARBY_LOG(
|
||||
INFO, "Failed to turn on WifiLan advertising with service info name=%s",
|
||||
service_info_name.c_str());
|
||||
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_id=" << service_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << "Turned on WifiLan advertising with service info name="
|
||||
<< service_info_name << ", service id=" << service_id;
|
||||
NEARBY_LOGS(INFO) << "Turned on WifiLan advertising with wifi_lan_service="
|
||||
<< &nsd_service_info << ", service_info_name="
|
||||
<< nsd_service_info.GetServiceInfoName()
|
||||
<< ", service_id=" << service_id;
|
||||
advertising_info_.Add(service_id);
|
||||
return true;
|
||||
}
|
||||
@@ -73,7 +75,7 @@ bool WifiLan::StopAdvertising(const std::string& service_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "Turned off WifiLan advertising with service id=%s",
|
||||
NEARBY_LOG(INFO, "Turned off WifiLan advertising with service_id=%s",
|
||||
service_id.c_str());
|
||||
bool ret = medium_.StopAdvertising(service_id);
|
||||
// Reset our bundle of advertising state to mark that we're no longer
|
||||
@@ -98,7 +100,7 @@ bool WifiLan::StartDiscovery(const std::string& service_id,
|
||||
|
||||
if (service_id.empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Refusing to start WifiLan discovering with empty service id.");
|
||||
"Refusing to start WifiLan discovering with empty service_id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -122,7 +124,7 @@ bool WifiLan::StartDiscovery(const std::string& service_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "Turned on WifiLan discovering with service id=%s",
|
||||
NEARBY_LOG(INFO, "Turned on WifiLan discovering with service_id=%s",
|
||||
service_id.c_str());
|
||||
// Mark the fact that we're currently performing a WifiLan discovering.
|
||||
discovering_info_.Add(service_id);
|
||||
@@ -139,7 +141,7 @@ bool WifiLan::StopDiscovery(const std::string& service_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "Turned off WifiLan discovering with service id=%s",
|
||||
NEARBY_LOG(INFO, "Turned off WifiLan discovering with service_id=%s",
|
||||
service_id.c_str());
|
||||
bool ret = medium_.StopDiscovery(service_id);
|
||||
discovering_info_.Clear();
|
||||
@@ -163,7 +165,7 @@ bool WifiLan::StartAcceptingConnections(const std::string& service_id,
|
||||
if (service_id.empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Refusing to start accepting WifiLan connections with empty "
|
||||
"service id.");
|
||||
"service_id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -223,8 +225,10 @@ bool WifiLan::IsAcceptingConnectionsLocked(const std::string& service_id) {
|
||||
WifiLanSocket WifiLan::Connect(WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
NEARBY_LOG(INFO, "WifiLan::Connect: service=%p, service_info_name=%s",
|
||||
&wifi_lan_service, wifi_lan_service.GetServiceName().c_str());
|
||||
NEARBY_LOGS(INFO) << "WifiLan::Connect: wifi_lan_service="
|
||||
<< &wifi_lan_service << ", service_info_name="
|
||||
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
|
||||
<< ", service_id=" << service_id;
|
||||
// Socket to return. To allow for NRVO to work, it has to be a single object.
|
||||
WifiLanSocket socket;
|
||||
|
||||
@@ -254,7 +258,7 @@ WifiLanSocket WifiLan::Connect(WifiLanService& wifi_lan_service,
|
||||
WifiLanService WifiLan::GetRemoteWifiLanService(const std::string& ip_address,
|
||||
int port) {
|
||||
MutexLock lock(&mutex_);
|
||||
return medium_.FindRemoteService(ip_address, port);
|
||||
return medium_.GetRemoteService(ip_address, port);
|
||||
}
|
||||
|
||||
std::pair<std::string, int> WifiLan::GetServiceAddress(
|
||||
|
||||
@@ -37,12 +37,11 @@ class WifiLan {
|
||||
// Returns true, if WifiLan communications are supported by a platform.
|
||||
bool IsAvailable() const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Sets custom service info name, endpoint info name and then enables WifiLan
|
||||
// advertising.
|
||||
// Sets custom service info name, endpoint info name in NsdServiceInfo and
|
||||
// then enables WifiLan advertising.
|
||||
// Returns true, if name is successfully set, and false otherwise.
|
||||
bool StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name)
|
||||
const NsdServiceInfo& nsd_service_info)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Disables WifiLan advertising, and restores service info name to
|
||||
|
||||
@@ -34,6 +34,7 @@ constexpr absl::string_view kServiceID{"com.google.location.nearby.apps.test"};
|
||||
constexpr absl::string_view kServiceInfoName{
|
||||
"Simulated WifiLan service encrypted string #1"};
|
||||
constexpr absl::string_view kEndpointName{"Simulated endpoint name"};
|
||||
constexpr absl::string_view kEndpointInfoKey{"n"};
|
||||
|
||||
class WifiLanTest : public ::testing::Test {
|
||||
protected:
|
||||
@@ -73,8 +74,11 @@ TEST_F(WifiLanTest, CanStartAdvertising) {
|
||||
},
|
||||
});
|
||||
|
||||
EXPECT_TRUE(wifi_lan_a.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name));
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
EXPECT_TRUE(wifi_lan_a.StartAdvertising(service_id, nsd_service_info));
|
||||
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
|
||||
EXPECT_TRUE(wifi_lan_a.StopAdvertising(service_id));
|
||||
EXPECT_TRUE(wifi_lan_b.StopDiscovery(service_id));
|
||||
@@ -91,8 +95,11 @@ TEST_F(WifiLanTest, CanStartDiscovery) {
|
||||
CountDownLatch accept_latch(1);
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
wifi_lan_b.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name);
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
wifi_lan_b.StartAdvertising(service_id, nsd_service_info);
|
||||
|
||||
EXPECT_TRUE(wifi_lan_a.StartDiscovery(
|
||||
service_id, {
|
||||
@@ -124,8 +131,11 @@ TEST_F(WifiLanTest, CanStartAcceptingConnectionsAndConnect) {
|
||||
CountDownLatch found_latch(1);
|
||||
CountDownLatch accept_latch(1);
|
||||
|
||||
wifi_lan_a.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name);
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
wifi_lan_a.StartAdvertising(service_id, nsd_service_info);
|
||||
wifi_lan_a.StartAcceptingConnections(
|
||||
service_id,
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
|
||||
#include "core/internal/webrtc_endpoint_channel.h"
|
||||
#include "core/internal/wifi_lan_endpoint_channel.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/base/types.h"
|
||||
#include "platform/public/crypto.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
@@ -470,9 +471,9 @@ bool P2pClusterPcpHandler::IsRecognizedWifiLanEndpoint(
|
||||
}
|
||||
|
||||
void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
|
||||
ClientProxy* client, WifiLanService& service,
|
||||
ClientProxy* client, WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
RunOnPcpHandlerThread([this, client, service_id, &service]() {
|
||||
RunOnPcpHandlerThread([this, client, service_id, &wifi_lan_service]() {
|
||||
// Make sure we are still discovering before proceeding.
|
||||
if (!client->IsDiscovering()) {
|
||||
NEARBY_LOG(
|
||||
@@ -483,10 +484,8 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the WifiLan service name.
|
||||
WifiLanServiceInfo service_info(service.GetServiceName(),
|
||||
service.GetTxtRecord(std::string{
|
||||
WifiLanServiceInfo::kKeyEndpointInfo}));
|
||||
// Parse the WifiLanServiceInfo.
|
||||
WifiLanServiceInfo service_info(wifi_lan_service.GetServiceInfo());
|
||||
|
||||
// Make sure the WifiLan service name points to a valid
|
||||
// endpoint we're discovering.
|
||||
@@ -496,7 +495,7 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Invoking BasePcpHandler::OnEndpointFound() for WifiLan "
|
||||
"service=%s; id=%s; name=%s",
|
||||
"service_id=%s; endpoint_id=%s; endpoint_info=%s",
|
||||
service_id.c_str(), service_info.GetEndpointId().c_str(),
|
||||
absl::BytesToHexString(service_info.GetEndpointInfo().data()).c_str());
|
||||
OnEndpointFound(client, std::make_shared<WifiLanEndpoint>(WifiLanEndpoint{
|
||||
@@ -507,22 +506,19 @@ void P2pClusterPcpHandler::WifiLanServiceDiscoveredHandler(
|
||||
proto::connections::Medium::WIFI_LAN,
|
||||
service_info.GetWebRtcState(),
|
||||
},
|
||||
service,
|
||||
wifi_lan_service,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
void P2pClusterPcpHandler::WifiLanServiceLostHandler(
|
||||
ClientProxy* client, WifiLanService& service,
|
||||
ClientProxy* client, WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
std::string service_info_name = service.GetServiceName();
|
||||
std::string endpoint_info_name =
|
||||
service.GetTxtRecord(std::string{WifiLanServiceInfo::kKeyEndpointInfo});
|
||||
NEARBY_LOG(
|
||||
INFO, "WifiLan: [LOST, SCHED] service_info_name=%s, endpoint_info_name=%",
|
||||
service_info_name.c_str(), endpoint_info_name.c_str());
|
||||
RunOnPcpHandlerThread([this, client, service_id, service_info_name,
|
||||
endpoint_info_name]() {
|
||||
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());
|
||||
RunOnPcpHandlerThread([this, client, service_id, nsd_service_info]() {
|
||||
// Make sure we are still discovering before proceeding.
|
||||
if (!client->IsDiscovering()) {
|
||||
NEARBY_LOG(
|
||||
@@ -533,8 +529,8 @@ void P2pClusterPcpHandler::WifiLanServiceLostHandler(
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the WifiLan service name.
|
||||
WifiLanServiceInfo service_info(service_info_name, endpoint_info_name);
|
||||
// Parse the WifiLanServiceInfo.
|
||||
WifiLanServiceInfo service_info(nsd_service_info);
|
||||
|
||||
// Make sure the WifiLan service name points to a valid
|
||||
// endpoint we're discovering.
|
||||
@@ -1057,7 +1053,9 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
|
||||
RunOnPcpHandlerThread([this, client, local_endpoint_info,
|
||||
socket = std::move(socket)]() mutable {
|
||||
std::string remote_service_info_name =
|
||||
socket.GetRemoteWifiLanService().GetServiceName();
|
||||
socket.GetRemoteWifiLanService()
|
||||
.GetServiceInfo()
|
||||
.GetServiceInfoName();
|
||||
auto channel = absl::make_unique<WifiLanEndpointChannel>(
|
||||
remote_service_info_name, socket);
|
||||
ByteArray remote_service_info{remote_service_info_name};
|
||||
@@ -1088,32 +1086,30 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
|
||||
local_endpoint_info,
|
||||
ByteArray{},
|
||||
web_rtc_state};
|
||||
std::string service_info_name(service_info);
|
||||
if (service_info_name.empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"P2pClusterPcpHandler::StartWifiLanAdvertising: generate "
|
||||
"WifiLanServiceInfo failed");
|
||||
NsdServiceInfo nsd_service_info{service_info};
|
||||
if (!nsd_service_info.IsValid()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "P2pClusterPcpHandler::StartWifiLanAdvertising: generate "
|
||||
"NsdServiceInfo failed";
|
||||
wifi_lan_medium_.StopAcceptingConnections(service_id);
|
||||
return proto::connections::UNKNOWN_MEDIUM;
|
||||
} else {
|
||||
NEARBY_LOG(INFO,
|
||||
"P2pClusterPcpHandler::StartWifiLanAdvertising: generate "
|
||||
"WifiLanServiceInfo succeeded; service_info_name=%s",
|
||||
service_info_name.c_str());
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "P2pClusterPcpHandler::StartWifiLanAdvertising: generate "
|
||||
"NsdServiceInfo succeeded; service_info_name="
|
||||
<< nsd_service_info.GetServiceInfoName();
|
||||
}
|
||||
auto local_endpoint_info_name = service_info.GetEndpointInfoName();
|
||||
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"P2pClusterPcpHandler::StartWifiLanAdvertising: service=%s: come up",
|
||||
service_id.c_str());
|
||||
|
||||
if (!wifi_lan_medium_.StartAdvertising(service_id, service_info_name,
|
||||
local_endpoint_info_name)) {
|
||||
if (!wifi_lan_medium_.StartAdvertising(service_id, nsd_service_info)) {
|
||||
NEARBY_LOG(INFO,
|
||||
"P2pClusterPcpHandler::StartWifiLanAdvertising: failed to "
|
||||
"start advertising, service_info_name=%s",
|
||||
service_info_name.c_str());
|
||||
nsd_service_info.GetServiceInfoName().c_str());
|
||||
wifi_lan_medium_.StopAcceptingConnections(service_id);
|
||||
return proto::connections::UNKNOWN_MEDIUM;
|
||||
}
|
||||
@@ -1137,10 +1133,10 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanDiscovery(
|
||||
|
||||
BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::WifiLanConnectImpl(
|
||||
ClientProxy* client, WifiLanEndpoint* endpoint) {
|
||||
WifiLanService& service = endpoint->wifi_lan_service;
|
||||
WifiLanService& wifi_lan_service = endpoint->wifi_lan_service;
|
||||
|
||||
WifiLanSocket wifi_lan_socket =
|
||||
wifi_lan_medium_.Connect(service, endpoint->service_id);
|
||||
wifi_lan_medium_.Connect(wifi_lan_service, endpoint->service_id);
|
||||
if (!wifi_lan_socket.IsValid()) {
|
||||
return BasePcpHandler::ConnectImplResult{
|
||||
.status = {Status::kWifiLanError},
|
||||
|
||||
@@ -48,6 +48,7 @@ const std::size_t kMaxEndpointInfoLength = 131u;
|
||||
ServiceControllerRouter::~ServiceControllerRouter() {
|
||||
NEARBY_LOG(INFO, "ServiceControllerRouter going down.");
|
||||
|
||||
service_controller_.reset();
|
||||
// And make sure that cleanup is the last thing we do.
|
||||
serializer_.Shutdown();
|
||||
}
|
||||
@@ -404,8 +405,8 @@ void ServiceControllerRouter::ReleaseServiceControllerForClient(
|
||||
ClientProxy* client) {
|
||||
clients_.erase(client);
|
||||
|
||||
// service_controller_ won't be released here. Instead, in desctructor.
|
||||
if (clients_.empty()) {
|
||||
service_controller_.reset();
|
||||
current_strategy_ = Strategy{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,18 +63,22 @@ WifiLanServiceInfo::WifiLanServiceInfo(Version version, Pcp pcp,
|
||||
web_rtc_state_ = web_rtc_state;
|
||||
}
|
||||
|
||||
WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_name,
|
||||
absl::string_view endpoint_info_name) {
|
||||
ByteArray service_info_bytes = Base64Utils::Decode(service_info_name);
|
||||
endpoint_info_ = Base64Utils::Decode(endpoint_info_name);
|
||||
if (endpoint_info_.size() > kMaxEndpointInfoLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize EndpointInfo: expecting endpoint info "
|
||||
"max %d raw bytes, got %" PRIu64,
|
||||
kMaxEndpointInfoLength, endpoint_info_.size());
|
||||
return;
|
||||
WifiLanServiceInfo::WifiLanServiceInfo(const NsdServiceInfo& nsd_service_info) {
|
||||
auto txt_endpoint_info_name =
|
||||
nsd_service_info.GetTxtRecord(std::string(kKeyEndpointInfo));
|
||||
if (!txt_endpoint_info_name.empty()) {
|
||||
endpoint_info_ = Base64Utils::Decode(txt_endpoint_info_name);
|
||||
if (endpoint_info_.size() > kMaxEndpointInfoLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize EndpointInfo: expecting endpoint info "
|
||||
"max %d raw bytes, got %" PRIu64,
|
||||
kMaxEndpointInfoLength, endpoint_info_.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto service_info_name = nsd_service_info.GetServiceInfoName();
|
||||
ByteArray service_info_bytes = Base64Utils::Decode(service_info_name);
|
||||
if (service_info_bytes.Empty()) {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
@@ -153,9 +157,9 @@ WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_name,
|
||||
}
|
||||
}
|
||||
|
||||
WifiLanServiceInfo::operator std::string() const {
|
||||
WifiLanServiceInfo::operator NsdServiceInfo() const {
|
||||
if (!IsValid()) {
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
// The upper 3 bits are the Version.
|
||||
@@ -188,11 +192,12 @@ WifiLanServiceInfo::operator std::string() const {
|
||||
absl::StrAppend(&out, std::string(1, field_byte));
|
||||
}
|
||||
|
||||
return Base64Utils::Encode(ByteArray{std::move(out)});
|
||||
}
|
||||
|
||||
std::string WifiLanServiceInfo::GetEndpointInfoName() const {
|
||||
return Base64Utils::Encode(endpoint_info_);
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(
|
||||
Base64Utils::Encode(ByteArray{std::move(out)}));
|
||||
nsd_service_info.SetTxtRecord(std::string(kKeyEndpointInfo),
|
||||
Base64Utils::Encode(endpoint_info_));
|
||||
return nsd_service_info;
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "core/internal/base_pcp_handler.h"
|
||||
#include "core/internal/pcp.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
@@ -50,23 +51,15 @@ class WifiLanServiceInfo {
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state);
|
||||
|
||||
// Constructs WifiLanService through packed string of WifiLanServiceInfo and
|
||||
// EndpointInfo.
|
||||
//
|
||||
// service_info_name - A packed string of |WifiLanServiceInfo|. It does
|
||||
// not include endpoint_info which should be stored
|
||||
// in next param bleow.
|
||||
// endpoint_info_name - The endpoint info packed string.
|
||||
WifiLanServiceInfo(absl::string_view service_info_name,
|
||||
absl::string_view endpoint_info_name);
|
||||
// Constructs WifiLanServiceInfo through NsdServiceInfo.
|
||||
explicit WifiLanServiceInfo(const NsdServiceInfo& nsd_service_info);
|
||||
WifiLanServiceInfo(const WifiLanServiceInfo&) = default;
|
||||
WifiLanServiceInfo& operator=(const WifiLanServiceInfo&) = default;
|
||||
WifiLanServiceInfo(WifiLanServiceInfo&&) = default;
|
||||
WifiLanServiceInfo& operator=(WifiLanServiceInfo&&) = default;
|
||||
~WifiLanServiceInfo() = default;
|
||||
|
||||
explicit operator std::string() const;
|
||||
std::string GetEndpointInfoName() const;
|
||||
explicit operator NsdServiceInfo() const;
|
||||
|
||||
bool IsValid() const { return !endpoint_id_.empty(); }
|
||||
Version GetVersion() const { return version_; }
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "platform/base/base64_utils.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace location {
|
||||
@@ -63,11 +64,9 @@ TEST(WifiLanServiceInfoTest, ConstructionFromSerializedStringWorks) {
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
std::string wifi_lan_service_info_string{org_wifi_lan_service_info};
|
||||
auto endpoint_info_name = org_wifi_lan_service_info.GetEndpointInfoName();
|
||||
NsdServiceInfo nsd_service_info{org_wifi_lan_service_info};
|
||||
|
||||
WifiLanServiceInfo wifi_lan_service_info{wifi_lan_service_info_string,
|
||||
endpoint_info_name};
|
||||
WifiLanServiceInfo wifi_lan_service_info{nsd_service_info};
|
||||
|
||||
EXPECT_TRUE(wifi_lan_service_info.IsValid());
|
||||
EXPECT_EQ(kPcp, wifi_lan_service_info.GetPcp());
|
||||
@@ -174,14 +173,15 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithLongServiceIdHash) {
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
|
||||
TEST(WifiLanServiceInfoTest, ConstructionFailsWithShortStringLength) {
|
||||
char wifi_lan_service_info_string[] = {'X', '\0'};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
TEST(WifiLanServiceInfoTest, ConstructionFailsWithShortServiceNameLength) {
|
||||
char wifi_lan_service_info_name[] = {'X', '\0'};
|
||||
ByteArray wifi_lan_service_info_bytes{wifi_lan_service_info_name};
|
||||
|
||||
ByteArray wifi_lan_service_info_bytes{wifi_lan_service_info_string};
|
||||
WifiLanServiceInfo wifi_lan_service_info{
|
||||
Base64Utils::Encode(wifi_lan_service_info_bytes),
|
||||
Base64Utils::Encode(endpoint_info)};
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(
|
||||
Base64Utils::Encode(wifi_lan_service_info_bytes));
|
||||
|
||||
WifiLanServiceInfo wifi_lan_service_info{nsd_service_info};
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "core/payload.h"
|
||||
#include "core/status.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/byte_utils.h"
|
||||
#include "platform/base/listeners.h"
|
||||
|
||||
namespace location {
|
||||
@@ -50,6 +51,10 @@ struct ResultCallback {
|
||||
};
|
||||
|
||||
struct ConnectionResponseInfo {
|
||||
std::string GetAuthenticationDigits() {
|
||||
return ByteUtils::ToFourDigitString(raw_authentication_token);
|
||||
}
|
||||
|
||||
ByteArray remote_endpoint_info;
|
||||
std::string authentication_token;
|
||||
ByteArray raw_authentication_token;
|
||||
|
||||
+13
-20
@@ -20,6 +20,7 @@
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/input_stream.h"
|
||||
#include "platform/base/listeners.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/base/output_stream.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
@@ -27,23 +28,17 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
// Opaque wrapper over a WifiLan service which contains packed
|
||||
// |WifiLanServiceInfo| string name.
|
||||
// Opaque wrapper over a WifiLan service which contains |NsdServiceInfo|.
|
||||
class WifiLanService {
|
||||
public:
|
||||
virtual ~WifiLanService() = default;
|
||||
|
||||
// Returns the packed string of |WifiLanServiceInfo|. Note that the packed
|
||||
// string would not include TXTRecord, which inheritor should save it in
|
||||
// another store.
|
||||
virtual std::string GetServiceName() const = 0;
|
||||
|
||||
// Returns the packed string of endpoint info with named key.
|
||||
virtual std::string GetTxtRecord(const std::string& key) const = 0;
|
||||
|
||||
// Returns the local device's <IP address, port> as a pair.
|
||||
// IP address is in byte sequence, in network order.
|
||||
virtual std::pair<std::string, int> GetServiceAddress() const = 0;
|
||||
// Returns the |NsdServiceInfo| which contains the packed string of
|
||||
// |WifiLanServiceInfo| and the endpoint info with named key in a TXTRecord
|
||||
// map.
|
||||
// The details refer to
|
||||
// https://developer.android.com/reference/android/net/nsd/NsdServiceInfo.html.
|
||||
virtual NsdServiceInfo GetServiceInfo() const = 0;
|
||||
};
|
||||
|
||||
class WifiLanSocket {
|
||||
@@ -77,10 +72,8 @@ class WifiLanMedium {
|
||||
public:
|
||||
virtual ~WifiLanMedium() = default;
|
||||
|
||||
virtual bool StartAdvertising(
|
||||
const std::string& service_id,
|
||||
const std::string& wifi_lan_service_info_name,
|
||||
const std::string& endpoint_info_name) = 0;
|
||||
virtual bool StartAdvertising(const std::string& service_id,
|
||||
const NsdServiceInfo& nsd_service_info) = 0;
|
||||
virtual bool StopAdvertising(const std::string& service_id) = 0;
|
||||
|
||||
// Callback that is invoked when a discovered service is found or lost.
|
||||
@@ -120,10 +113,10 @@ class WifiLanMedium {
|
||||
// On success, returns a new WifiLanSocket.
|
||||
// On error, returns nullptr.
|
||||
virtual std::unique_ptr<WifiLanSocket> Connect(
|
||||
WifiLanService& service, const std::string& service_id) = 0;
|
||||
WifiLanService& wifi_lan_service, const std::string& service_id) = 0;
|
||||
|
||||
virtual WifiLanService* FindRemoteService(const std::string& ip_address,
|
||||
int port) = 0;
|
||||
virtual WifiLanService* GetRemoteService(const std::string& ip_address,
|
||||
int port) = 0;
|
||||
|
||||
virtual std::pair<std::string, int> GetServiceAddress(
|
||||
const std::string& service_id) = 0;
|
||||
|
||||
@@ -29,6 +29,7 @@ cc_library(
|
||||
"exception.h",
|
||||
"input_stream.h",
|
||||
"listeners.h",
|
||||
"nsd_service_info.h",
|
||||
"output_stream.h",
|
||||
"payload_id.h",
|
||||
"prng.h",
|
||||
@@ -43,6 +44,7 @@ cc_library(
|
||||
"//platform/api:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//absl/container:flat_hash_map",
|
||||
"//absl/meta:type_traits",
|
||||
"//absl/strings",
|
||||
"//absl/strings:str_format",
|
||||
@@ -55,11 +57,13 @@ cc_library(
|
||||
srcs = [
|
||||
"base_input_stream.cc",
|
||||
"base_pipe.cc",
|
||||
"byte_utils.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"base_input_stream.h",
|
||||
"base_mutex_lock.h",
|
||||
"base_pipe.h",
|
||||
"byte_utils.h",
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
@@ -71,6 +75,7 @@ cc_library(
|
||||
":base",
|
||||
"//platform/api:types",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/strings:str_format",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -126,6 +131,18 @@ cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "platform_util_test",
|
||||
srcs = [
|
||||
"byte_utils_test.cc",
|
||||
],
|
||||
deps = [
|
||||
":base",
|
||||
":util",
|
||||
"//testing/base/public:gunit_main",
|
||||
],
|
||||
)
|
||||
|
||||
cc_with_non_compile_test(
|
||||
name = "exception_test",
|
||||
srcs = [
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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 "platform/base/byte_utils.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "platform/base/base_input_stream.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
std::string ByteUtils::ToFourDigitString(ByteArray& bytes) {
|
||||
int multiplier = 1;
|
||||
int hashCode = 0;
|
||||
|
||||
BaseInputStream base_input_stream{bytes};
|
||||
while (base_input_stream.IsAvailable(1)) {
|
||||
auto byte = static_cast<int>(base_input_stream.ReadUint8());
|
||||
hashCode = (hashCode + byte * multiplier) % kHashBasePrime;
|
||||
multiplier = multiplier * kHashBaseMultiplier % kHashBasePrime;
|
||||
}
|
||||
return absl::StrFormat("%04d", abs(hashCode));
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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 PLATFORM_BASE_BYTE_UTILS_H_
|
||||
#define PLATFORM_BASE_BYTE_UTILS_H_
|
||||
|
||||
#include "platform/base/byte_array.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class ByteUtils {
|
||||
public:
|
||||
static std::string ToFourDigitString(ByteArray& bytes);
|
||||
|
||||
private:
|
||||
// The biggest prime number under 10000, used as a mod base to trim integers
|
||||
// into 4 digits.
|
||||
static constexpr int kHashBasePrime = 9973;
|
||||
// The hash multiplier.
|
||||
static constexpr int kHashBaseMultiplier = 31;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_BASE_BYTE_UTILS_H_
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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 "platform/base/byte_utils.h"
|
||||
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
constexpr absl::string_view kFooBytes{"rawABCDE"};
|
||||
constexpr absl::string_view kFooFourDigitsToken{"0392"};
|
||||
constexpr absl::string_view kEmptyFourDigitsToken{"0000"};
|
||||
|
||||
TEST(ByteUtilsTest, ToFourDigitStringCorrect) {
|
||||
ByteArray bytes{std::string(kFooBytes)};
|
||||
|
||||
auto four_digit_string = ByteUtils::ToFourDigitString(bytes);
|
||||
|
||||
EXPECT_EQ(std::string(kFooFourDigitsToken), four_digit_string);
|
||||
}
|
||||
|
||||
TEST(ByteUtilsTest, TestEmptyByteArrayCorrect) {
|
||||
ByteArray bytes;
|
||||
|
||||
auto four_digit_string = ByteUtils::ToFourDigitString(bytes);
|
||||
|
||||
EXPECT_EQ(std::string(kEmptyFourDigitsToken), four_digit_string);
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -215,28 +215,32 @@ void MediumEnvironment::OnBlePeripheralStateChanged(
|
||||
}
|
||||
|
||||
void MediumEnvironment::OnWifiLanServiceStateChanged(
|
||||
WifiLanMediumContext& info, api::WifiLanService& service,
|
||||
WifiLanMediumContext& info, api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id, bool enabled) {
|
||||
if (!enabled_) return;
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 OnWifiLanServiceStateChanged [service impl=%p]; context=%p; "
|
||||
"service_id=%s; notify=%d",
|
||||
&service, &info, service_id.c_str(), enable_notifications_.load());
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"G3 OnWifiLanServiceStateChanged [wifi_lan_service impl=%p]; context=%p; "
|
||||
"service_id=%s; notify=%d",
|
||||
&wifi_lan_service, &info, service_id.c_str(),
|
||||
enable_notifications_.load());
|
||||
if (!enable_notifications_) return;
|
||||
RunOnMediumEnvironmentThread([&info, enabled, &service, service_id]() {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 [Run] OnWifiLanServiceStateChanged [service impl=%p]; "
|
||||
"context=%p; service_id=%s; enabled=%d",
|
||||
&service, &info, service_id.c_str(), enabled);
|
||||
RunOnMediumEnvironmentThread([&info, enabled, &wifi_lan_service,
|
||||
service_id]() {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"G3 [Run] OnWifiLanServiceStateChanged [wifi_lan_service impl=%p]; "
|
||||
"context=%p; service_id=%s; enabled=%d",
|
||||
&wifi_lan_service, &info, service_id.c_str(), enabled);
|
||||
auto service_id_context = info.services.find(service_id);
|
||||
if (service_id_context == info.services.end()) return;
|
||||
|
||||
if (enabled) {
|
||||
service_id_context->second.discovery_callback.service_discovered_cb(
|
||||
service, service_id);
|
||||
wifi_lan_service, service_id);
|
||||
} else {
|
||||
service_id_context->second.discovery_callback.service_lost_cb(service,
|
||||
service_id);
|
||||
service_id_context->second.discovery_callback.service_lost_cb(
|
||||
wifi_lan_service, service_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -491,10 +495,10 @@ void MediumEnvironment::RegisterWifiLanMedium(api::WifiLanMedium& medium) {
|
||||
}
|
||||
|
||||
void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
|
||||
api::WifiLanMedium& medium, api::WifiLanService& service,
|
||||
api::WifiLanMedium& medium, api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id, bool enabled) {
|
||||
if (!enabled_) return;
|
||||
RunOnMediumEnvironmentThread([this, &medium, &service, service_id,
|
||||
RunOnMediumEnvironmentThread([this, &medium, &wifi_lan_service, service_id,
|
||||
enabled]() {
|
||||
auto item = wifi_lan_mediums_.find(&medium);
|
||||
if (item == wifi_lan_mediums_.end()) {
|
||||
@@ -504,7 +508,7 @@ void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
context.wifi_lan_service = &service;
|
||||
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{
|
||||
@@ -514,17 +518,19 @@ void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
|
||||
} else {
|
||||
service_id_context->second.advertising = enabled;
|
||||
}
|
||||
NEARBY_LOG(INFO,
|
||||
"Update WifiLan medium for advertising: this=%p; medium=%p; "
|
||||
"service_id=%s; name=%s; enabled=%d",
|
||||
this, &medium, service_id.c_str(),
|
||||
service.GetServiceName().c_str(), enabled);
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Update WifiLan medium for advertising: this=%p; medium=%p; "
|
||||
"service_id=%s; wifi_lan_service=%p, service_info_name=%s; enabled=%d",
|
||||
this, &medium, service_id.c_str(), &wifi_lan_service,
|
||||
wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str(),
|
||||
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, service, service_id, enabled);
|
||||
OnWifiLanServiceStateChanged(info, wifi_lan_service, service_id, enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -634,25 +640,26 @@ void MediumEnvironment::CallWifiLanAcceptedConnectionCallback(
|
||||
});
|
||||
}
|
||||
|
||||
api::WifiLanService* MediumEnvironment::FindWifiLanService(
|
||||
api::WifiLanService* MediumEnvironment::GetWifiLanService(
|
||||
const std::string& ip_address, int port) {
|
||||
api::WifiLanService* remote_service = nullptr;
|
||||
api::WifiLanService* remote_wifi_lan_service = nullptr;
|
||||
CountDownLatch latch(1);
|
||||
RunOnMediumEnvironmentThread(
|
||||
[this, &remote_service, &ip_address, port, &latch]() {
|
||||
[this, &remote_wifi_lan_service, &ip_address, port, &latch]() {
|
||||
for (auto& item : wifi_lan_mediums_) {
|
||||
auto* service = item.second.wifi_lan_service;
|
||||
if (!service) continue;
|
||||
auto addr = remote_service->GetServiceAddress();
|
||||
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_service = service;
|
||||
remote_wifi_lan_service = wifi_lan_service;
|
||||
break;
|
||||
}
|
||||
}
|
||||
latch.CountDown();
|
||||
});
|
||||
latch.Await();
|
||||
return remote_service;
|
||||
return remote_wifi_lan_service;
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "platform/api/webrtc.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/listeners.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/public/single_thread_executor.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -193,7 +194,7 @@ class MediumEnvironment {
|
||||
// Updates advertising info to indicate the current medium is exposing
|
||||
// advertising event.
|
||||
void UpdateWifiLanMediumForAdvertising(api::WifiLanMedium& medium,
|
||||
api::WifiLanService& service,
|
||||
api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id,
|
||||
bool enabled);
|
||||
|
||||
@@ -226,8 +227,8 @@ class MediumEnvironment {
|
||||
const std::string& service_id);
|
||||
|
||||
// Returns WiFi LAN service matching IP address and port, or nullptr.
|
||||
api::WifiLanService* FindWifiLanService(const std::string& ip_address,
|
||||
int port);
|
||||
api::WifiLanService* GetWifiLanService(const std::string& ip_address,
|
||||
int port);
|
||||
|
||||
private:
|
||||
struct BluetoothMediumContext {
|
||||
@@ -275,7 +276,7 @@ class MediumEnvironment {
|
||||
bool fast_advertisement, bool enabled);
|
||||
|
||||
void OnWifiLanServiceStateChanged(WifiLanMediumContext& info,
|
||||
api::WifiLanService& service,
|
||||
api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id,
|
||||
bool enabled);
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// 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 PLATFORM_BASE_NSD_SERVICE_INFO_H_
|
||||
#define PLATFORM_BASE_NSD_SERVICE_INFO_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
// https://developer.android.com/reference/android/net/nsd/NsdServiceInfo.html.
|
||||
class NsdServiceInfo {
|
||||
public:
|
||||
NsdServiceInfo() = default;
|
||||
NsdServiceInfo(const NsdServiceInfo&) = default;
|
||||
NsdServiceInfo& operator=(const NsdServiceInfo&) = default;
|
||||
NsdServiceInfo(NsdServiceInfo&&) = default;
|
||||
NsdServiceInfo& operator=(NsdServiceInfo&&) = default;
|
||||
~NsdServiceInfo() = default;
|
||||
|
||||
// Returns the packed string of |WifiLanServiceInfo|.
|
||||
std::string GetServiceInfoName() const { return service_info_name_; }
|
||||
|
||||
// Sets the packed string of |WifiLanServiceInfo|.
|
||||
void SetServiceInfoName(std::string service_info_name) {
|
||||
service_info_name_ = std::move(service_info_name);
|
||||
}
|
||||
|
||||
// Gets the TXTRecord value of the specified TXTRecord key assigned.
|
||||
std::string GetTxtRecord(const std::string& txt_record_key) const {
|
||||
if (txt_records_.empty()) return {};
|
||||
auto record = txt_records_.find(txt_record_key);
|
||||
if (record == txt_records_.end()) return {};
|
||||
return record->second;
|
||||
}
|
||||
|
||||
// Adds the TXTRecord with a pair of key and value.
|
||||
void SetTxtRecord(const std::string& txt_record_key,
|
||||
const std::string& txt_record_value) {
|
||||
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_);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
bool IsValid() const { return !service_info_name_.empty(); }
|
||||
|
||||
private:
|
||||
std::string service_info_name_;
|
||||
absl::flat_hash_map<std::string, std::string> txt_records_;
|
||||
std::string ip_address_;
|
||||
int port_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_BASE_NSD_SERVICE_INFO_H_
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "platform/api/wifi_lan.h"
|
||||
#include "platform/base/logging.h"
|
||||
#include "platform/base/medium_environment.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/base/prng.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
|
||||
@@ -72,7 +73,7 @@ Exception WifiLanSocket::Close() {
|
||||
|
||||
WifiLanService* WifiLanSocket::GetRemoteWifiLanService() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
return service_;
|
||||
return wifi_lan_service_;
|
||||
}
|
||||
|
||||
void WifiLanSocket::DoClose() {
|
||||
@@ -101,7 +102,7 @@ OutputStream& WifiLanSocket::GetLocalOutputStream() {
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WifiLanSocket> WifiLanServerSocket::Accept(
|
||||
WifiLanService* service) {
|
||||
WifiLanService* wifi_lan_service) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (closed_) return {};
|
||||
while (pending_sockets_.empty()) {
|
||||
@@ -112,7 +113,7 @@ std::unique_ptr<api::WifiLanSocket> WifiLanServerSocket::Accept(
|
||||
auto* remote_socket =
|
||||
pending_sockets_.extract(pending_sockets_.begin()).value();
|
||||
CHECK(remote_socket);
|
||||
auto local_socket = std::make_unique<WifiLanSocket>(service);
|
||||
auto local_socket = std::make_unique<WifiLanSocket>(wifi_lan_service);
|
||||
local_socket->Connect(*remote_socket);
|
||||
remote_socket->Connect(*local_socket);
|
||||
cond_.SignalAll();
|
||||
@@ -170,22 +171,13 @@ Exception WifiLanServerSocket::DoClose() {
|
||||
}
|
||||
|
||||
WifiLanMedium::WifiLanMedium() {
|
||||
service_.SetMedium(this);
|
||||
std::string ip_address;
|
||||
ip_address.resize(4);
|
||||
uint32_t raw_ip_addr = Prng().NextUint32();
|
||||
uint16_t port = Prng().NextUint32();
|
||||
ip_address[0] = static_cast<char>(raw_ip_addr >> 24);
|
||||
ip_address[1] = static_cast<char>(raw_ip_addr >> 16);
|
||||
ip_address[2] = static_cast<char>(raw_ip_addr >> 8);
|
||||
ip_address[3] = static_cast<char>(raw_ip_addr >> 0);
|
||||
service_.SetServiceAddress(ip_address, port);
|
||||
wifi_lan_service_.SetMedium(this);
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.RegisterWifiLanMedium(*this);
|
||||
}
|
||||
|
||||
WifiLanMedium::~WifiLanMedium() {
|
||||
service_.SetMedium(nullptr);
|
||||
wifi_lan_service_.SetMedium(nullptr);
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UnregisterWifiLanMedium(*this);
|
||||
|
||||
@@ -205,15 +197,17 @@ WifiLanMedium::~WifiLanMedium() {
|
||||
}
|
||||
|
||||
bool WifiLanMedium::StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name) {
|
||||
const NsdServiceInfo& nsd_service_info) {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 WifiLan StartAdvertising: service_id=%s, service_info_name=%s",
|
||||
service_id.c_str(), service_info_name.c_str());
|
||||
"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());
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
service_.SetServiceName(service_info_name);
|
||||
service_.SetTxtRecord("n", endpoint_info_name);
|
||||
env.UpdateWifiLanMediumForAdvertising(*this, service_, service_id, true);
|
||||
NsdServiceInfo local_nsd_service_info{nsd_service_info};
|
||||
SetWifiLanService(nsd_service_info);
|
||||
env.UpdateWifiLanMediumForAdvertising(*this, wifi_lan_service_, service_id,
|
||||
true);
|
||||
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (server_socket_ != nullptr) server_socket_.release();
|
||||
@@ -223,7 +217,7 @@ bool WifiLanMedium::StartAdvertising(const std::string& service_id,
|
||||
accept_loops_runner_.Execute([&env, this, service_id]() mutable {
|
||||
if (!accept_loops_runner_.InShutdown()) {
|
||||
while (true) {
|
||||
auto client_socket = server_socket_->Accept(&service_);
|
||||
auto client_socket = server_socket_->Accept(&wifi_lan_service_);
|
||||
if (client_socket == nullptr) break;
|
||||
env.CallWifiLanAcceptedConnectionCallback(
|
||||
*this, *(client_socket.release()), service_id);
|
||||
@@ -250,7 +244,8 @@ bool WifiLanMedium::StopAdvertising(const std::string& service_id) {
|
||||
}
|
||||
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UpdateWifiLanMediumForAdvertising(*this, service_, service_id, false);
|
||||
env.UpdateWifiLanMediumForAdvertising(*this, wifi_lan_service_, service_id,
|
||||
false);
|
||||
accept_loops_runner_.Shutdown();
|
||||
if (server_socket_ == nullptr) {
|
||||
NEARBY_LOGS(ERROR) << "G3 WifiLan StopAdvertising: failed to find WifiLan "
|
||||
@@ -322,39 +317,46 @@ bool WifiLanMedium::StopAcceptingConnections(const std::string& service_id) {
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
|
||||
api::WifiLanService& remote_service, const std::string& service_id) {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 WifiLan Connect: medium=%p, service=%p, service_info_name=%s, "
|
||||
"service_id=%s",
|
||||
this, &service_, remote_service.GetServiceName().c_str(),
|
||||
service_id.c_str());
|
||||
api::WifiLanService& remote_wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
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());
|
||||
// First, find an instance of remote medium, that exposed this service.
|
||||
auto* medium = static_cast<WifiLanService&>(remote_service).GetMedium();
|
||||
auto* remote_medium =
|
||||
static_cast<WifiLanService&>(remote_wifi_lan_service).GetMedium();
|
||||
|
||||
if (!medium) return {}; // Can't find medium. Bail out.
|
||||
if (!remote_medium) return {}; // Can't find medium. Bail out.
|
||||
|
||||
WifiLanServerSocket* remote_server_socket = nullptr;
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 WifiLan Connect [peer]: medium=%p, service=%p, "
|
||||
"service_info_name=%s, service_id=%s",
|
||||
medium, &remote_service, remote_service.GetServiceName().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().GetServiceInfoName().c_str(),
|
||||
service_id.c_str());
|
||||
// Then, find our server socket context in this medium.
|
||||
{
|
||||
absl::MutexLock medium_lock(&medium->mutex_);
|
||||
remote_server_socket = medium->server_socket_.get();
|
||||
absl::MutexLock medium_lock(&remote_medium->mutex_);
|
||||
remote_server_socket = remote_medium->server_socket_.get();
|
||||
if (remote_server_socket == nullptr) {
|
||||
NEARBY_LOG(ERROR,
|
||||
"G3 WifiLan Connect: Failed to find WifiLan Server socket: "
|
||||
"service_id=%s",
|
||||
service_id.c_str());
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "G3 WifiLan Connect: Failed to find remote WifiLan Server socket: "
|
||||
"service_id="
|
||||
<< service_id;
|
||||
// Fall through for server socket not found.
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
WifiLanService service = static_cast<WifiLanService&>(remote_service);
|
||||
auto socket = std::make_unique<WifiLanSocket>(&service);
|
||||
WifiLanService wifi_lan_service =
|
||||
static_cast<WifiLanService&>(remote_wifi_lan_service);
|
||||
auto socket = std::make_unique<WifiLanSocket>(&wifi_lan_service);
|
||||
// Finally, Request to connect to this socket.
|
||||
if (!remote_server_socket->Connect(*socket)) {
|
||||
NEARBY_LOG(ERROR,
|
||||
@@ -368,17 +370,38 @@ std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
|
||||
return socket;
|
||||
}
|
||||
|
||||
api::WifiLanService* WifiLanMedium::FindRemoteService(
|
||||
api::WifiLanService* WifiLanMedium::GetRemoteService(
|
||||
const std::string& ip_address, int port) {
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
return env.FindWifiLanService(ip_address, port);
|
||||
return env.GetWifiLanService(ip_address, port);
|
||||
}
|
||||
|
||||
std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
|
||||
const std::string& service_id) {
|
||||
NEARBY_LOGS(INFO) << "G3 WifiLan GetServiceAddress: service_id="
|
||||
<< service_id;
|
||||
return service_.GetServiceAddress();
|
||||
return wifi_lan_service_.GetServiceInfo().GetServiceAddress();
|
||||
}
|
||||
|
||||
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);
|
||||
wifi_lan_service_.SetServiceInfo(local_nsd_service_info);
|
||||
}
|
||||
|
||||
std::pair<std::string, int> WifiLanMedium::GetFakeServiceAddress() const {
|
||||
std::string ip_address;
|
||||
ip_address.resize(4);
|
||||
uint32_t raw_ip_addr = Prng().NextUint32();
|
||||
uint16_t port = Prng().NextUint32();
|
||||
ip_address[0] = static_cast<char>(raw_ip_addr >> 24);
|
||||
ip_address[1] = static_cast<char>(raw_ip_addr >> 16);
|
||||
ip_address[2] = static_cast<char>(raw_ip_addr >> 8);
|
||||
ip_address[3] = static_cast<char>(raw_ip_addr >> 0);
|
||||
|
||||
return std::make_pair(ip_address, port);
|
||||
}
|
||||
|
||||
} // namespace g3
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "platform/api/wifi_lan.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/input_stream.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/base/output_stream.h"
|
||||
#include "platform/impl/g3/multi_thread_executor.h"
|
||||
#include "platform/impl/g3/pipe.h"
|
||||
@@ -35,39 +36,18 @@ namespace g3 {
|
||||
|
||||
class WifiLanMedium;
|
||||
|
||||
// Opaque wrapper over a WifiLan service which contains packed
|
||||
// |WifiLanServiceInfo| string name.
|
||||
// Opaque wrapper over a WifiLan service which contains |NsdServiceInfo|.
|
||||
class WifiLanService : public api::WifiLanService {
|
||||
public:
|
||||
explicit WifiLanService(std::string service_info_name)
|
||||
: service_info_name_(std::move(service_info_name)) {}
|
||||
WifiLanService() = default;
|
||||
explicit WifiLanService(NsdServiceInfo nsd_service_info)
|
||||
: nsd_service_info_(std::move(nsd_service_info)) {}
|
||||
~WifiLanService() override = default;
|
||||
|
||||
std::string GetServiceName() const override { return service_info_name_; }
|
||||
NsdServiceInfo GetServiceInfo() const override { return nsd_service_info_; }
|
||||
|
||||
void SetServiceName(std::string service_info_name) {
|
||||
service_info_name_ = std::move(service_info_name);
|
||||
}
|
||||
|
||||
std::string GetTxtRecord(const std::string& txt_record_key) const override {
|
||||
if (txt_records_.empty()) return {};
|
||||
auto record = txt_records_.find(txt_record_key);
|
||||
if (record == txt_records_.end()) return {};
|
||||
return record->second;
|
||||
}
|
||||
|
||||
void SetTxtRecord(const std::string& txt_record_key,
|
||||
const std::string& txt_record_value) {
|
||||
txt_records_.emplace(txt_record_key, txt_record_value);
|
||||
}
|
||||
|
||||
std::pair<std::string, int> GetServiceAddress() const override {
|
||||
return std::make_pair(ip_address_, port_);
|
||||
}
|
||||
|
||||
void SetServiceAddress(const std::string& ip_address, int port) {
|
||||
ip_address_ = ip_address;
|
||||
port_ = port;
|
||||
void SetServiceInfo(NsdServiceInfo nsd_service_info) {
|
||||
nsd_service_info_ = std::move(nsd_service_info);
|
||||
}
|
||||
|
||||
WifiLanMedium* GetMedium() { return medium_; }
|
||||
@@ -75,17 +55,15 @@ class WifiLanService : public api::WifiLanService {
|
||||
void SetMedium(WifiLanMedium* medium) { medium_ = medium; }
|
||||
|
||||
private:
|
||||
std::string service_info_name_;
|
||||
absl::flat_hash_map<std::string, std::string> txt_records_;
|
||||
NsdServiceInfo nsd_service_info_;
|
||||
WifiLanMedium* medium_ = nullptr;
|
||||
std::string ip_address_;
|
||||
int port_;
|
||||
};
|
||||
|
||||
class WifiLanSocket : public api::WifiLanSocket {
|
||||
public:
|
||||
WifiLanSocket() = default;
|
||||
explicit WifiLanSocket(WifiLanService* service) : service_(service) {}
|
||||
explicit WifiLanSocket(WifiLanService* wifi_lan_service)
|
||||
: wifi_lan_service_(wifi_lan_service) {}
|
||||
~WifiLanSocket() override;
|
||||
|
||||
// Connect to another WifiLanSocket, to form a functional low-level channel.
|
||||
@@ -138,7 +116,7 @@ class WifiLanSocket : public api::WifiLanSocket {
|
||||
std::shared_ptr<Pipe> output_{new Pipe};
|
||||
std::shared_ptr<Pipe> input_;
|
||||
mutable absl::Mutex mutex_;
|
||||
WifiLanService* service_;
|
||||
WifiLanService* wifi_lan_service_;
|
||||
WifiLanSocket* remote_socket_ ABSL_GUARDED_BY(mutex_) = nullptr;
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
@@ -196,8 +174,7 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
~WifiLanMedium() override;
|
||||
|
||||
bool StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name) override
|
||||
const NsdServiceInfo& nsd_service_info) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopAdvertising(const std::string& service_id) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
@@ -226,11 +203,11 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
// On success, returns a new WifiLanSocket.
|
||||
// On error, returns nullptr.
|
||||
std::unique_ptr<api::WifiLanSocket> Connect(
|
||||
api::WifiLanService& remote_service,
|
||||
api::WifiLanService& remote_wifi_lan_service,
|
||||
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
api::WifiLanService* FindRemoteService(const std::string& ip_address,
|
||||
int port) override;
|
||||
api::WifiLanService* GetRemoteService(const std::string& ip_address,
|
||||
int port) override;
|
||||
|
||||
std::pair<std::string, int> GetServiceAddress(
|
||||
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
@@ -252,8 +229,11 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
std::string service_id;
|
||||
};
|
||||
|
||||
void SetWifiLanService(const NsdServiceInfo& nsd_service_info);
|
||||
std::pair<std::string, int> GetFakeServiceAddress() const;
|
||||
|
||||
absl::Mutex mutex_;
|
||||
WifiLanService service_{"unknown G3 WifiLan service"};
|
||||
WifiLanService wifi_lan_service_;
|
||||
|
||||
// A thread pool dedicated to running all the accept loops from
|
||||
// StartAdvertising().
|
||||
|
||||
@@ -21,10 +21,8 @@ namespace location {
|
||||
namespace nearby {
|
||||
|
||||
bool WifiLanMedium::StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name) {
|
||||
return impl_->StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name);
|
||||
const NsdServiceInfo& nsd_service_info) {
|
||||
return impl_->StartAdvertising(service_id, nsd_service_info);
|
||||
}
|
||||
|
||||
bool WifiLanMedium::StopAdvertising(const std::string& service_id) {
|
||||
@@ -42,40 +40,46 @@ bool WifiLanMedium::StartDiscovery(const std::string& service_id,
|
||||
service_id,
|
||||
{
|
||||
.service_discovered_cb =
|
||||
[this](api::WifiLanService& service,
|
||||
[this](api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
auto pair = services_.emplace(
|
||||
&service, absl::make_unique<ServiceDiscoveryInfo>());
|
||||
&wifi_lan_service,
|
||||
absl::make_unique<ServiceDiscoveryInfo>());
|
||||
auto& context = *pair.first->second;
|
||||
if (!pair.second) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Discovering (again) service=%p, impl=%p, "
|
||||
"service_info_name=%s",
|
||||
&context.service, &service,
|
||||
service.GetServiceName().c_str());
|
||||
&context.wifi_lan_service, &wifi_lan_service,
|
||||
wifi_lan_service.GetServiceInfo()
|
||||
.GetServiceInfoName()
|
||||
.c_str());
|
||||
} else {
|
||||
context.service = WifiLanService(&service);
|
||||
NEARBY_LOG(INFO,
|
||||
"Discovering service=%p, impl=%p, "
|
||||
"service_info_name=%s",
|
||||
&context.service, &service,
|
||||
service.GetServiceName().c_str());
|
||||
context.wifi_lan_service = WifiLanService(&wifi_lan_service);
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Discovering wifi_lan_service=%p, service_info_name=%s",
|
||||
&wifi_lan_service,
|
||||
wifi_lan_service.GetServiceInfo()
|
||||
.GetServiceInfoName()
|
||||
.c_str());
|
||||
}
|
||||
discovered_service_callback_.service_discovered_cb(
|
||||
context.service, service_id);
|
||||
context.wifi_lan_service, service_id);
|
||||
},
|
||||
.service_lost_cb =
|
||||
[this](api::WifiLanService& service,
|
||||
[this](api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (services_.empty()) return;
|
||||
auto context = services_.find(&service);
|
||||
auto context = services_.find(&wifi_lan_service);
|
||||
if (context == services_.end()) return;
|
||||
NEARBY_LOG(INFO, "Removing service=%p, impl=%p",
|
||||
&(context->second->service), &service);
|
||||
NEARBY_LOG(INFO, "Removing wifi_lan_service=%p, impl=%p",
|
||||
&(context->second->wifi_lan_service),
|
||||
&wifi_lan_service);
|
||||
discovered_service_callback_.service_lost_cb(
|
||||
context->second->service, service_id);
|
||||
context->second->wifi_lan_service, service_id);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -131,18 +135,19 @@ bool WifiLanMedium::StopAcceptingConnections(const std::string& service_id) {
|
||||
return impl_->StopAcceptingConnections(service_id);
|
||||
}
|
||||
|
||||
WifiLanSocket WifiLanMedium::Connect(WifiLanService& service,
|
||||
WifiLanSocket WifiLanMedium::Connect(WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id) {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"WifiLanMedium::Connect: service=%p [impl=%p, service_info_name=%s]",
|
||||
&service, &service.GetImpl(), service.GetServiceName().c_str());
|
||||
return WifiLanSocket(impl_->Connect(service.GetImpl(), service_id));
|
||||
&wifi_lan_service, &wifi_lan_service.GetImpl(),
|
||||
wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str());
|
||||
return WifiLanSocket(impl_->Connect(wifi_lan_service.GetImpl(), service_id));
|
||||
}
|
||||
|
||||
WifiLanService WifiLanMedium::FindRemoteService(const std::string& ip_address,
|
||||
WifiLanService WifiLanMedium::GetRemoteService(const std::string& ip_address,
|
||||
int port) {
|
||||
return WifiLanService(impl_->FindRemoteService(ip_address, port));
|
||||
return WifiLanService(impl_->GetRemoteService(ip_address, port));
|
||||
}
|
||||
|
||||
std::pair<std::string, int> WifiLanMedium::GetServiceAddress(
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "platform/api/wifi_lan.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/input_stream.h"
|
||||
#include "platform/base/nsd_service_info.h"
|
||||
#include "platform/base/output_stream.h"
|
||||
#include "platform/public/mutex.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
@@ -26,8 +27,7 @@
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
// Opaque wrapper over a WifiLan service which contains packed
|
||||
// |WifiLanServiceInfo| string name and the TXT Record.
|
||||
// Opaque wrapper over a WifiLan service which contains |NsdServiceInfo|.
|
||||
class WifiLanService final {
|
||||
public:
|
||||
WifiLanService() = default;
|
||||
@@ -36,12 +36,7 @@ class WifiLanService final {
|
||||
explicit WifiLanService(api::WifiLanService* service) : impl_(service) {}
|
||||
~WifiLanService() = default;
|
||||
|
||||
std::string GetServiceName() const { return impl_->GetServiceName(); }
|
||||
|
||||
std::string GetTxtRecord(const std::string& key) const {
|
||||
return impl_->GetTxtRecord(key);
|
||||
}
|
||||
|
||||
NsdServiceInfo GetServiceInfo() const { return impl_->GetServiceInfo(); }
|
||||
api::WifiLanService& GetImpl() { return *impl_; }
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
|
||||
@@ -119,7 +114,7 @@ class WifiLanMedium final {
|
||||
};
|
||||
|
||||
struct ServiceDiscoveryInfo {
|
||||
WifiLanService service;
|
||||
WifiLanService wifi_lan_service;
|
||||
};
|
||||
|
||||
struct AcceptedConnectionCallback {
|
||||
@@ -135,8 +130,7 @@ class WifiLanMedium final {
|
||||
~WifiLanMedium() = default;
|
||||
|
||||
bool StartAdvertising(const std::string& service_id,
|
||||
const std::string& service_info_name,
|
||||
const std::string& endpoint_info_name);
|
||||
const NsdServiceInfo& nsd_service_info);
|
||||
bool StopAdvertising(const std::string& service_id);
|
||||
|
||||
// Returns true once the WifiLan discovery has been initiated.
|
||||
@@ -156,13 +150,14 @@ class WifiLanMedium final {
|
||||
|
||||
// Returns a new WifiLanSocket. On Success, WifiLanSocket::IsValid()
|
||||
// returns true.
|
||||
WifiLanSocket Connect(WifiLanService& service, const std::string& service_id);
|
||||
WifiLanSocket Connect(WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id);
|
||||
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
|
||||
api::WifiLanMedium& GetImpl() { return *impl_; }
|
||||
|
||||
WifiLanService FindRemoteService(const std::string& ip_address, int port);
|
||||
WifiLanService GetRemoteService(const std::string& ip_address, int port);
|
||||
|
||||
std::pair<std::string, int> GetServiceAddress(const std::string& service_id);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace {
|
||||
constexpr absl::string_view kServiceID{"com.google.location.nearby.apps.test"};
|
||||
constexpr absl::string_view kServiceInfoName{"Simulated service info name"};
|
||||
constexpr absl::string_view kEndpointName{"Simulated endpoint name"};
|
||||
constexpr absl::string_view kEndpointInfoKey{"n"};
|
||||
|
||||
class WifiLanMediumTest : public ::testing::Test {
|
||||
protected:
|
||||
@@ -64,7 +65,11 @@ TEST_F(WifiLanMediumTest, CanStartAdvertising) {
|
||||
std::string endpoint_info_name{kEndpointName};
|
||||
CountDownLatch found_latch(1);
|
||||
|
||||
wifi_a.StartAdvertising(service_id, service_info_name, endpoint_info_name);
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
wifi_a.StartAdvertising(service_id, nsd_service_info);
|
||||
|
||||
EXPECT_TRUE(wifi_b.StartDiscovery(
|
||||
service_id, DiscoveredServiceCallback{
|
||||
@@ -103,8 +108,12 @@ TEST_F(WifiLanMediumTest, CanStartDiscovery) {
|
||||
lost_latch.CountDown();
|
||||
},
|
||||
});
|
||||
EXPECT_TRUE(wifi_b.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name));
|
||||
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
EXPECT_TRUE(wifi_b.StartAdvertising(service_id, nsd_service_info));
|
||||
EXPECT_TRUE(found_latch.Await(absl::Milliseconds(1000)).result());
|
||||
EXPECT_TRUE(wifi_b.StopAdvertising(service_id));
|
||||
EXPECT_TRUE(lost_latch.Await(absl::Milliseconds(1000)).result());
|
||||
@@ -135,8 +144,13 @@ TEST_F(WifiLanMediumTest, CanStopDiscovery) {
|
||||
lost_latch.CountDown();
|
||||
},
|
||||
});
|
||||
EXPECT_TRUE(wifi_b.StartAdvertising(service_id, service_info_name,
|
||||
endpoint_info_name));
|
||||
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
|
||||
EXPECT_TRUE(wifi_b.StartAdvertising(service_id, nsd_service_info));
|
||||
EXPECT_TRUE(found_latch.Await(absl::Milliseconds(1000)).result());
|
||||
EXPECT_TRUE(wifi_a.StopDiscovery(service_id));
|
||||
EXPECT_TRUE(wifi_b.StopAdvertising(service_id));
|
||||
@@ -161,13 +175,20 @@ TEST_F(WifiLanMediumTest, CanStartAcceptingConnectionsAndConnect) {
|
||||
.service_discovered_cb =
|
||||
[&found_latch, &discovered_service](
|
||||
WifiLanService& service, const std::string& service_id) {
|
||||
NEARBY_LOG(INFO, "Service discovered: %s, %p",
|
||||
service.GetServiceName().c_str(), &service);
|
||||
NEARBY_LOG(
|
||||
INFO, "Service discovered: %s, %p",
|
||||
service.GetServiceInfo().GetServiceInfoName().c_str(),
|
||||
&service);
|
||||
discovered_service = &service;
|
||||
found_latch.CountDown();
|
||||
},
|
||||
});
|
||||
wifi_b.StartAdvertising(service_id, service_info_name, endpoint_info_name);
|
||||
|
||||
NsdServiceInfo nsd_service_info;
|
||||
nsd_service_info.SetServiceInfoName(service_info_name);
|
||||
nsd_service_info.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
endpoint_info_name);
|
||||
wifi_b.StartAdvertising(service_id, nsd_service_info);
|
||||
wifi_b.StartAcceptingConnections(
|
||||
service_id,
|
||||
AcceptedConnectionCallback{
|
||||
|
||||
-15
@@ -54,21 +54,6 @@ java_proto_library(
|
||||
deps = [":discovery_enums_proto"],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "error_code_enums_proto",
|
||||
srcs = ["error_code_enums.proto"],
|
||||
cc_api_version = 2,
|
||||
compatible_with = ["//buildenv/target:appengine"],
|
||||
deps = [
|
||||
"//logs/proto/logs_annotations",
|
||||
],
|
||||
)
|
||||
|
||||
java_lite_proto_library(
|
||||
name = "error_code_enums_java_proto_lite",
|
||||
deps = [":error_code_enums_proto"],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "connections_enums_proto",
|
||||
srcs = ["connections_enums.proto"],
|
||||
|
||||
@@ -276,6 +276,8 @@ message MediumMetadata {
|
||||
optional bool supports_5_ghz = 1;
|
||||
// WiFi Lan BSSID
|
||||
optional string bssid = 2;
|
||||
// IP address
|
||||
optional bytes ip_address = 3;
|
||||
}
|
||||
|
||||
// LocationHint is used to specify a location as well as format.
|
||||
|
||||
@@ -42,6 +42,9 @@ enum EventType {
|
||||
|
||||
// Corresponds to the end of a StrategySession.
|
||||
STOP_STRATEGY_SESSION = 5;
|
||||
|
||||
// Logs when the error happen.
|
||||
ERROR_CODE = 6;
|
||||
}
|
||||
|
||||
// The strategy used for a session of Nearby.Connections.
|
||||
|
||||
@@ -1,448 +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.
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package location.nearby.proto;
|
||||
|
||||
import "logs/proto/logs_annotations/logs_annotations.proto";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
option (logs_proto.file_not_used_for_logging_except_enums) = true;
|
||||
option java_api_version = 2;
|
||||
option java_package = "com.google.location.nearby.proto";
|
||||
option java_outer_classname = "ErrorCodeEnums";
|
||||
option objc_class_prefix = "GNCP";
|
||||
|
||||
// The type of the error.
|
||||
// It help to sort error codes to different types to analyze and also impact the
|
||||
// logcat print it as Warning or Severe.
|
||||
enum ErrorType {
|
||||
UNKNOWN_TYPE = 0;
|
||||
|
||||
// The error should not happen on production, it's like the input is null or
|
||||
// not invalid or it's a unexpected API call. For example, start advertising
|
||||
// with empty service ID or start advertising with the same service ID twice.
|
||||
DEVELOPING = 1;
|
||||
|
||||
// It’s about the device's capabilities, some devices may not support the
|
||||
// feature Nearby used. E.g. The device not support BLE advertising
|
||||
DEVICE = 2;
|
||||
|
||||
// The failure return from the system or library API we used to communicate
|
||||
// with the medium. E.g. get null OS objects or call the API but get a
|
||||
// negative return value which indicates that the system does not allow to do
|
||||
// that now.
|
||||
SYSTEM = 3;
|
||||
|
||||
// The network related failure. E.g. get an EOF exception while reading pipe
|
||||
// or fail to create connection.
|
||||
NETWORK = 4;
|
||||
|
||||
// This may not be a failure, it can be the things we are interested in, like
|
||||
// to count how many BLE advertisements the device received in a specified
|
||||
// period and how many different advertisements in it, it can help us to know
|
||||
// the user under a clean or dirty environment.
|
||||
OTHERS = 5;
|
||||
}
|
||||
|
||||
// The event which the error occurs on.
|
||||
enum Event {
|
||||
UNKNOWN_EVENT = 0;
|
||||
START_ADVERTISING = 1;
|
||||
STOP_ADVERTISING = 2;
|
||||
START_LISTENING_INCOMING_CONNECTION = 3;
|
||||
STOP_LISTENING_INCOMING_CONNECTION = 4;
|
||||
START_DISCOVERING = 5;
|
||||
STOP_DISCOVERING = 6;
|
||||
CONNECT = 7;
|
||||
DISCONNECT = 8;
|
||||
ACCEPT_CONNECTION = 9;
|
||||
REJECT_CONNECTION = 10;
|
||||
SEND_PAYLOAD = 11;
|
||||
CANCEL_PAYLOAD = 12;
|
||||
RECEIVE_PAYLOAD = 13;
|
||||
}
|
||||
|
||||
// The error to identify the common failure for all mediums. The range between 0
|
||||
// and 30.
|
||||
enum CommonError {
|
||||
UNKNOWN_ERROR = 0;
|
||||
|
||||
// The common error for all mediums, the range between 0 and 30.
|
||||
|
||||
// Developing error, the input with invalid format or empty.
|
||||
INVALID_PARAMETER = 1;
|
||||
// Device error, the medium not available on this device.
|
||||
MEDIUM_NOT_AVAILABLE = 2;
|
||||
// System error, the medium in the unexpected state, e.g. we have check the
|
||||
// medium is on, after then it suddently off and cause Nearby
|
||||
// Connection failed.
|
||||
UNEXPECTED_MEDIUM_STATE = 3;
|
||||
// System error, the medim not available because the resource ran out. e.g.
|
||||
// the Wi-Fi Direct initialized cause Wi-Fi Aware not available, or BLE
|
||||
// connections hit the maximan number, or Wi-Fi Hotstop already created.
|
||||
OUT_OF_RESOURCE = 4;
|
||||
// Others error, the error happens when user cancel the flow, it's not a
|
||||
// real failure.
|
||||
FLOW_CANCELED = 5;
|
||||
// Developing error, an unexpect call that the medium not ready, need to do
|
||||
// something before this call. e.g. call WifiAwareImpli#connectToSocket but
|
||||
// never join network before this call.
|
||||
UNEXPECTED_CALL = 6;
|
||||
|
||||
// Reserved 7 to 30
|
||||
}
|
||||
|
||||
// The error for event START_ADVERTISING. The range between 31 and 99.
|
||||
enum StartAdvertisingError {
|
||||
reserved 37, 39;
|
||||
|
||||
// Developing error, not allow to advertising fast pair model id and sharing
|
||||
// fast advertisement at the same time, they are both use fast
|
||||
// advertisement, and only allow 1 fast advertisement at the same time.
|
||||
MULTIPLE_FAST_ADVERTISEMENT_NOT_ALLOWED = 31;
|
||||
// System error, there's already someone advertising fast advertisement, not
|
||||
// allow to start another one.
|
||||
FAST_ADVERTISEMENT_ALREADY_ADVERTISED = 32;
|
||||
// Developing error, this service ID already requested, should not request
|
||||
// it again without stop advertising.
|
||||
DUPLICATE_ADVERTISING_REQUESTED = 33;
|
||||
// System error, failed to start GATT server
|
||||
START_GATT_SERVER_FAILED = 34;
|
||||
// System error, all advertising slot ran out, can't available for new
|
||||
// regular advertisement.
|
||||
BLE_MAX_GATT_ADVERTISEMENT_SLOT_REACHED = 35;
|
||||
// System error, failed to start advertising for legacy advertisements on BLE
|
||||
START_LEGACY_ADVERTISING_FAILED = 36;
|
||||
// System error, failed to start advertising for extended advertisements on
|
||||
// BLE
|
||||
START_EXTENDED_ADVERTISING_FAILED = 38;
|
||||
// System error, there's already someone advertising on Bluetooth, not allow
|
||||
// to start another one.
|
||||
BLUETOOTH_ALREADY_ADVERTISED = 40;
|
||||
// System error, failed to modify the Bluetooth name.
|
||||
MODIFY_BLUETOOTH_NAME_FAILED = 41;
|
||||
// System error, failed to persist the original Bluetooth name into shared
|
||||
// preference.
|
||||
PERSIST_ORIGINAL_BLUETOOTH_NAME_FAILED = 42;
|
||||
// System error, failed to start advertising.
|
||||
START_ADVERTISING_FAILED = 43;
|
||||
|
||||
// Developing error, not allow to advertising on Wi-Fi Lan(TDLS) without
|
||||
// accetpting connections. The connection may comes in very quickly, so need
|
||||
// to accetpt connections before advertising.
|
||||
SHOULD_ACCEPT_CONNECTIONS_BEFORE_ADVERTISING_ON_WIFI_LAN = 44;
|
||||
// System error, failed to acquire WifiAwareSession
|
||||
ACQUIRE_WIFI_AWARE_SESSION_FAILED = 45;
|
||||
|
||||
// Next ID :46
|
||||
}
|
||||
|
||||
// The error for event STOP_ADVERTISING. The range between 31 and 99.
|
||||
enum StopAdvertisingError {
|
||||
// System error, failed to stop advertising.
|
||||
STOP_ADVERTISING_FAILED = 31;
|
||||
// System error, failed to modify the Bluetooth name.
|
||||
RESTORE_BLUETOOTH_NAME_FAILED = 32;
|
||||
// System error, failed to stop advertising for BLE legacy advertisements.
|
||||
STOP_LEGACY_ADVERTISING_FAILED = 33;
|
||||
// System error, failed to stop advertising for BLE extended advertisements.
|
||||
STOP_EXTENDED_ADVERTISING_FAILED = 34;
|
||||
|
||||
// Next ID :35
|
||||
}
|
||||
|
||||
// The error for event START_DISCOVERING. The range between 31 and 99.
|
||||
enum StartDiscoveringError {
|
||||
// Developing error, this service ID already requested, should not request it
|
||||
// again without stop discovering.
|
||||
DUPLICATE_DISCOVERING_REQUESTED = 31;
|
||||
// System error, failed to start discovering for legacy advertisements on BLE
|
||||
START_LEGACY_DISCOVERING_FAILED = 32;
|
||||
// System error, failed to start discovering for extended advertisements on
|
||||
// BLE
|
||||
START_EXTENDED_DISCOVERING_FAILED = 33;
|
||||
// System error, failed to start discovering.
|
||||
START_DISCOVERING_FAILED = 34;
|
||||
// Network error, invalid remote target info, discover the nearby devices but
|
||||
// the information not valid.
|
||||
INVALID_TARGET_INFO = 35;
|
||||
// Network error, failed to fetch the advertisement from the remote devices.
|
||||
FETCH_ADVERTISEMENT_FAILED = 36;
|
||||
// Network error, failed to fetch the advertisement via GATT from the remote
|
||||
// devices.
|
||||
GATT_FETCH_ADVERTISEMENT_FAILED = 37;
|
||||
// Network error, failed to fetch the advertisement via L2CAP from the remote
|
||||
// devices.
|
||||
L2CAP_FETCH_ADVERTISEMENT_FAILED = 38;
|
||||
// System error, the medium not available when trying to fetch advertisements.
|
||||
// e.g. fetch advertisements but BT disabled unexpectedly.
|
||||
NOT_AVAILABLE_TO_FETCH_ADVERTISEMENT = 39;
|
||||
// System error, failed to acquire WifiAwareSession
|
||||
ACQUIRE_WIFI_AWARE_SESSION_FOR_DISCOVERING_FAILED = 40;
|
||||
|
||||
// Next ID :41
|
||||
}
|
||||
|
||||
// The error for event STOP_DISCOVERING. The range between 31 and 99.
|
||||
enum StopDiscoveringError {
|
||||
// System error, failed to stop discovering.
|
||||
STOP_DISCOVERING_FAILED = 31;
|
||||
// System error, failed to stop discovering for BLE legacy scanning.
|
||||
STOP_LEGACY_DISCOVERING_FAILED = 32;
|
||||
// System error, failed to stop discovering for BLE extended scanning.
|
||||
STOP_EXTENDED_DISCOVERING_FAILED = 33;
|
||||
|
||||
// Next ID :34
|
||||
}
|
||||
|
||||
// The error for event START_LISTENING_INCOMING_CONNECTION. The range between 31
|
||||
// and 99.
|
||||
enum StartListeningIncomingConnectionError {
|
||||
// Developing error, this service ID already requested, should not request it
|
||||
// again without stop accepting.
|
||||
DUPLICATE_ACCEPTING_CONNECTION_REQUESTED = 31;
|
||||
// System error, failed to open a GATT server for listening incoming GATT
|
||||
// connection.
|
||||
OPEN_GATT_SERVER_FAILED = 32;
|
||||
// System error, failed to accept the incoming GATT connection
|
||||
ACCEPT_GATT_CONNECTION_FAILED = 33;
|
||||
// System error, failed to accept the incoming L2CAP connection
|
||||
ACCEPT_L2CAP_CONNECTION_FAILED = 34;
|
||||
// Network error, wait the GATT connection ready after the connection
|
||||
// established but never.
|
||||
CREATE_GATT_SERVER_SOCKET_NOT_READY = 35;
|
||||
// System error, failed to accept the incoming connection
|
||||
ACCEPT_CONNECTION_FAILED = 36;
|
||||
// System error, failed to create a server socket for listening incoming
|
||||
// connection.
|
||||
CREATE_SERVER_SOCKET_FAILED = 37;
|
||||
|
||||
// Next ID :36
|
||||
}
|
||||
|
||||
// The error for event STOP_LISTENING_INCOMING_CONNECTION. The range between 31
|
||||
// and 99.
|
||||
enum StopListeningIncomingConnectionError {
|
||||
// System error, failed to stop accepting the incoming connection
|
||||
STOP_ACCEPTING_CONNECTION_FAILED = 31;
|
||||
|
||||
// Next ID :32
|
||||
}
|
||||
|
||||
// The error for event CONNECT. The range between 31 and 99.
|
||||
enum ConnectError {
|
||||
// Network error, failed to connect to remote device because we lost the
|
||||
// target without MAC address to connect to. e.g. BLE cache MAC address in
|
||||
// medium, it may lost when just try to connect.
|
||||
UNEXPECT_TARGET_LOST = 31;
|
||||
// System error, failed to establish connection on GATT
|
||||
ESTABLISH_GATT_CONNECTION_FAILED = 32;
|
||||
// System error, failed to establish connection on L2CAP
|
||||
ESTABLISH_L2CAP_CONNECTION_FAILED = 33;
|
||||
// Developing error, the MAC address not valid for connecting
|
||||
INVALID_MAC_ADDRESS = 34;
|
||||
// Others error, unexpected interrupt when sleep before connect GATT for
|
||||
// waiting GATT server ready. Should not hapepen, it may be the process be
|
||||
// killed.
|
||||
SLEEP_BEFORE_CONNECT_GATT_INTERRUPTED = 35;
|
||||
// Others error, unexpected interrupt when sleep after GATT connect to wait
|
||||
// GATT connection ready to transfer data. Should not hapepen, it may be
|
||||
// the process be killed.
|
||||
SLEEP_AFTER_GATT_CONNECTED_INTERRUPTED = 36;
|
||||
// Network error, failed to configure the GATT connection priority, it may
|
||||
// failed when the connection still wait for the status update from network or
|
||||
// just a RemoteException.
|
||||
REQUEST_GATT_CONNECTION_PRIORITY_FAILED = 37;
|
||||
// Network error, failed to change connection for data transferring on L2CAP
|
||||
// connection.
|
||||
L2CAP_SWITCH_TO_DATA_TRANSFERRING_FAILED = 38;
|
||||
// Network error, failed to change connection for data transferring on GATT
|
||||
// connection.
|
||||
GATT_SWITCH_TO_DATA_TRANSFERRING_FAILED = 39;
|
||||
// System error, failed to establish connection
|
||||
ESTABLISH_CONNECTION_FAILED = 40;
|
||||
// Developing error, this connection already established, should not request
|
||||
// it again.
|
||||
DUPLICATE_CONNECTION_REQUESTED = 41;
|
||||
// Network error, the connection lost.
|
||||
CONNECTION_LOST = 42;
|
||||
// Network error, failed to connect to the network. e.g. an aware network,
|
||||
// hotspot or a direct network.
|
||||
CONNECT_TO_NETWORK_FAILED = 43;
|
||||
|
||||
// Next ID :44
|
||||
}
|
||||
|
||||
// The error for event DISCONNECT. The range between 31 and 99.
|
||||
enum DisconnectError {
|
||||
// System error, failed to disconnect the network.
|
||||
DISCONNECT_NETWORK_FAILED = 31;
|
||||
|
||||
// Next ID :32
|
||||
}
|
||||
|
||||
enum Description {
|
||||
reserved 28, 29;
|
||||
|
||||
UNKNOWN = 0;
|
||||
NULL_SERVICE_ID = 1;
|
||||
NULL_ADVERTISEMENT_BYTES = 2;
|
||||
CONNECTIONS_FEATURE_DISABLED = 3;
|
||||
STALE_SDK_VERSION = 4;
|
||||
FEATURE_BLUETOOTH_NOT_SUPPORTED = 5;
|
||||
FEATURE_BLUETOOTH_LE_NOT_SUPPORTED = 6;
|
||||
NULL_BLUETOOTH_MANAGER = 7;
|
||||
NULL_BLUETOOTH_ADAPTER = 8;
|
||||
INVALID_FAST_PAIR_MODEL_ID = 9;
|
||||
INVALID_FAST_ADVERTISEMENT_DATA = 10;
|
||||
INVALID_ADVERTISEMENT_HEADER_DATA = 11;
|
||||
INVALID_REGULAR_ADVERTISEMENT_DATA = 12;
|
||||
NULL_BLUETOOTH_LE_ADVERTISER_COMPAT = 13;
|
||||
ADVERTISE_FAILED_ALREADY_STARTED = 14;
|
||||
ADVERTISE_FAILED_DATA_TOO_LARGE = 15;
|
||||
ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 16;
|
||||
ADVERTISE_FAILED_INTERNAL_ERROR = 17;
|
||||
ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 18;
|
||||
INTERRUPTED_EXCEPTION = 19;
|
||||
EXECUTION_EXCEPTION = 20;
|
||||
NULL_BLUETOOTH_DEVICE_NAME = 21;
|
||||
SET_SCAN_MODE_FAILED = 22;
|
||||
INVOKE_API_FAILED = 23;
|
||||
TIMEOUT = 24;
|
||||
NULL_NFC_TAG = 25;
|
||||
FEATURE_NFC_NOT_SUPPORTED = 26;
|
||||
FEATURE_NFC_HOST_CARD_EMULATION_NOT_SUPPORTED = 27;
|
||||
MULTICAST_NOT_SUPPORTED = 30;
|
||||
NSD_NOT_ENABLED = 31;
|
||||
INVALID_PORT_NUMBER = 32;
|
||||
NULL_SERVICE_NAME = 33;
|
||||
NULL_SERVICE_TYPE = 34;
|
||||
WITHOUT_CONNECTED_WIFI_NETWORK = 35;
|
||||
FEATURE_WIFI_AWARE_NOT_SUPPORTED = 36;
|
||||
NULL_CONNECTIVITY_MANAGER = 37;
|
||||
NULL_WIFI_AWARE_MANAGER = 38;
|
||||
STALE_ANDROID_VERSION = 39;
|
||||
NULL_SERVICE_INFO = 40;
|
||||
NULL_WORK_SOURCE = 41;
|
||||
NULL_CALLBACK = 42;
|
||||
NULL_BLUETOOTH_LE_SCANNER_COMPAT = 43;
|
||||
EMPTY_WORK_SOURCE_CACHE = 44;
|
||||
SCAN_FAILED_ALREADY_STARTED = 45;
|
||||
SCAN_FAILED_APPLICATION_REGISTRATION_FAILED = 46;
|
||||
SCAN_FAILED_INTERNAL_ERROR = 47;
|
||||
SCAN_FAILED_FEATURE_UNSUPPORTED = 48;
|
||||
SCAN_FAILED_BLUETOOTH_DISABLED = 49;
|
||||
SCAN_FILTERS_NOT_ALLOWED_FOR_LOCATION = 50;
|
||||
BLUETOOTH_SCAN_REJUVENATE_FAILED = 51;
|
||||
NULL_BLE_PERIPHERAL = 52;
|
||||
NULL_BLUETOOTH_GATT = 53;
|
||||
UNEXPECTED_BLUETOOTH_STATE = 54;
|
||||
REMOTE_EXCEPTION = 55;
|
||||
INVALID_BLUETOOTH_SOCKET_STATE_BEFORE_CONNECT = 56;
|
||||
BLUETOOTH_SOCKET_CLOSED_AFTER_CONNECTED = 57;
|
||||
INVALID_BLUETOOTH_CHANNEL = 58;
|
||||
NULL_BLUETOOTH_DEVICE = 59;
|
||||
NULL_BLUETOOTH_PROXY = 60;
|
||||
INVALID_PACKET_LENGTH = 61;
|
||||
INVALID_PACKET_BYTES = 62;
|
||||
UNEXPECTED_EOF_EXCEPTION = 63;
|
||||
SOCKET_CLOSED_OR_TIMEOUT = 64;
|
||||
INVALID_IPV4_ADDRESS = 65;
|
||||
INVALID_IPV6_ADDRESS = 66;
|
||||
NULL_ADDRESS = 67;
|
||||
INVALID_VERSION = 68;
|
||||
SET_CONNECTION_PRIORITY_FAILED = 69;
|
||||
SET_CONNECTION_PRIORITY_INTERRUPTED = 70;
|
||||
UNKNOWN_IO_EXCEPTION = 71;
|
||||
READ_CHARACTERISTIC_FAILED = 72;
|
||||
WIFI_HOTSPOT_ENABLED = 73;
|
||||
AWARE_UNAVAILABLE = 74;
|
||||
IN_BLACK_LIST = 75;
|
||||
FEATURE_WIFI_NOT_SUPPORTED = 76;
|
||||
NULL_WIFI_MANAGER = 77;
|
||||
SOCKET_CLOSED = 78;
|
||||
SOCKET_ALREADY_CONNECTED = 79;
|
||||
NFC_TECH_NOT_SUPPORTED = 80;
|
||||
NFC_SERVICE_DIED = 81;
|
||||
BIND_NFC_SERVICE_FAILED = 82;
|
||||
NFC_CREATE_SOCKET_FAILED = 83;
|
||||
NULL_WIFI_AWARE_PEER = 84;
|
||||
NETWORK_ALREADY_JOINED = 85;
|
||||
JOIN_AWARE_NETWORK_CANCELLED = 86;
|
||||
NETWORK_UNAVAILABLE = 87;
|
||||
WITHOUT_ACTIVE_AWARE_NETWORK = 88;
|
||||
WITHOUT_JOINED_AWARE_NETWORK = 89;
|
||||
CONNET_TO_SOCKET_CANCELLED = 90;
|
||||
NULL_SSID = 91;
|
||||
NULL_PASSWORD = 92;
|
||||
FEATURE_WIFI_DIRECT_NOT_SUPPORTED = 93;
|
||||
NULL_WIFI_P2P_MANAGER = 94;
|
||||
P2P_GROUP_FORMED = 95;
|
||||
ACQUIRE_P2P_CHANNEL_FAILED = 96;
|
||||
P2P_UNSUPPORTED = 97;
|
||||
INTERNAL_ERROR = 98;
|
||||
BUSY = 99;
|
||||
REFLECTION_ERROR = 100;
|
||||
NETWORK_ERROR_EHOSTUNREACH = 101;
|
||||
NETWORK_ERROR_ENETUNREACH = 102;
|
||||
ADD_NETWORK_FAILED = 103;
|
||||
UPDATE_NETWORK_FAILED = 104;
|
||||
ALREADY_IN_PROGRESS = 105;
|
||||
INVALID_ARGS = 106;
|
||||
NOT_AUTHORIZED = 107;
|
||||
INVALID_NETWORK_ID = 108;
|
||||
WIFI_MANAGER_ENABLE_NETWORK_FAILED = 109;
|
||||
WIFI_MANAGER_RECONNECT_FAILED = 110;
|
||||
WITHOUT_ACTIVE_NETWORK = 111;
|
||||
WEBRTC_CONNECTION_FLOW_EXIST = 112;
|
||||
NULL_DROID_GUARD_RESULT = 113;
|
||||
TACHYON_SIGNALING_MESSENGER_EXIST = 114;
|
||||
TACHYON_ALREADY_START_RECEIVE_MESSAGE = 115;
|
||||
TACHYON_RECEIVE_MESSAGE_FAILED = 116;
|
||||
TACHYON_RECEIVE_MESSAGE_INTERRUPTED = 117;
|
||||
TACHYON_RECEIVE_MESSAGE_EXECUTION_EXCEPTION = 118;
|
||||
TACHYON_RECEIVE_MESSAGE_TIMEOUT = 119;
|
||||
TACHYON_RECEIVE_MESSAGE_AUTH_EXCEPTION = 120;
|
||||
TACHYON_RECEIVE_MESSAGE_STATUS_EXCEPTION = 121;
|
||||
TACHYON_SEND_MESSAGE_AUTH_EXCEPTION = 122;
|
||||
TACHYON_SEND_MESSAGE_STATUS_EXCEPTION = 123;
|
||||
TACHYON_GET_ICE_SERVER_AUTH_EXCEPTION = 124;
|
||||
TACHYON_GET_ICE_SERVER_STATUS_EXCEPTION = 125;
|
||||
EMPTY_TACHYON_ICE_SERVER = 126;
|
||||
POTENTIAL_WEBRTC_LIB_LOADING_FAILURE = 127;
|
||||
UNEXPECTED_GATT_DESCRIPTOR = 128;
|
||||
FAIL_TO_RECEIVE_L2CAP_PACKET = 129;
|
||||
WITHOUT_PSM_VALUE = 130;
|
||||
SOCKET_BIND_LISTEN_FAILED = 131;
|
||||
UNEXPECTED_PACKET_CONTENT = 132;
|
||||
UNREGISTER_NSD_MANAGER_FAILED = 133;
|
||||
PUBLISH_EMPTY_ADVERTISEMENT_FAILED = 134;
|
||||
BLUETOOTH_SOCKET_NOT_IN_LISTENING_STATE = 135;
|
||||
INVALID_BLUETOOTH_SOCKET_SIGNAL_SIZE = 136;
|
||||
INVALID_BLUETOOTH_SOCKET_SIGNAL_STATUS = 137;
|
||||
GET_ADDRESS_FAILED = 138;
|
||||
NULL_LOCAL_ADDRESS = 139;
|
||||
IS_LOOPBACK_ADDRESS = 140;
|
||||
SOCKET_NOT_BOUND = 141;
|
||||
INVALID_REMOTE_ADDRESS = 142;
|
||||
SOCKET_ALREADY_BOUND = 143;
|
||||
HOTSPOT_NOT_STARTED = 144;
|
||||
WEBRTC_ALREADY_INITIALIZED = 145;
|
||||
INVALID_WEBRTC_STATE = 146;
|
||||
NULL_DATA_CHANNEL = 147;
|
||||
CREATE_OFFER_FAILED = 148;
|
||||
CLOSE_SERVER_SOCKET_FAILED = 149;
|
||||
}
|
||||
Reference in New Issue
Block a user