Remove location namespace in third_party/nearby.

PiperOrigin-RevId: 500023196
This commit is contained in:
Suet-Fei Li
2023-01-06 02:53:57 -08:00
committed by Copybara-Service
parent 7afea00649
commit 084f7ebd88
714 changed files with 2710 additions and 3738 deletions
-2
View File
@@ -16,7 +16,6 @@
#include <string>
namespace location {
namespace nearby {
namespace connections {
@@ -49,4 +48,3 @@ AdvertisingOptions AdvertisingOptions::CompatibleOptions() const {
} // namespace connections
} // namespace nearby
} // namespace location
-2
View File
@@ -22,7 +22,6 @@
#include "internal/platform/byte_array.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace connections {
@@ -54,6 +53,5 @@ struct AdvertisingOptions : public OptionsBase {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_ADVERTISING_OPTIONS_H_
@@ -33,17 +33,17 @@
NS_ASSUME_NONNULL_BEGIN
using ::location::nearby::ByteArrayFromNSData;
using ::location::nearby::CppStringFromObjCString;
using ::location::nearby::ObjCStringFromCppString;
using ::location::nearby::connections::ConnectionListener;
using ::location::nearby::connections::AdvertisingOptions;
using ::location::nearby::connections::ConnectionRequestInfo;
using ::location::nearby::connections::ConnectionResponseInfo;
using ::location::nearby::connections::GNCStrategyToStrategy;
using ::location::nearby::connections::Medium;
using ResultListener = ::location::nearby::connections::ResultCallback;
using ::location::nearby::connections::Status;
using ::nearby::ByteArrayFromNSData;
using ::nearby::CppStringFromObjCString;
using ::nearby::ObjCStringFromCppString;
using ::nearby::connections::AdvertisingOptions;
using ::nearby::connections::ConnectionListener;
using ::nearby::connections::ConnectionRequestInfo;
using ::nearby::connections::ConnectionResponseInfo;
using ::nearby::connections::GNCStrategyToStrategy;
using ::nearby::connections::Medium;
using ResultListener = ::nearby::connections::ResultCallback;
using ::nearby::connections::Status;
/** This is a GNCAdvertiserConnectionInfo that provides storage for its properties. */
@interface GNCAdvertiserConnectionInfo : NSObject
@@ -108,7 +108,7 @@ using ::location::nearby::connections::Status;
@end
/** C++ classes passed to the core library by GNCAdvertiser. */
namespace location {
namespace nearby {
namespace connections {
@@ -268,9 +268,8 @@ class GNCAdvertiserConnectionListener {
} // namespace connections
} // namespace nearby
} // namespace location
using ::location::nearby::connections::GNCAdvertiserConnectionListener;
using ::nearby::connections::GNCAdvertiserConnectionListener;
@interface GNCAdvertiser () {
std::unique_ptr<GNCAdvertiserConnectionListener> advertiserListener;
@@ -304,7 +303,7 @@ using ::location::nearby::connections::GNCAdvertiserConnectionListener;
AdvertisingOptions advertising_options;
advertising_options.strategy = GNCStrategyToStrategy(strategy);
advertising_options.allowed = location::nearby::connections::BooleanMediumSelector();
advertising_options.allowed = nearby::connections::BooleanMediumSelector();
advertising_options.auto_upgrade_bandwidth = true;
advertising_options.enforce_topology_constraints = true;
+2 -3
View File
@@ -26,9 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
/** This class contains the C++ Core object. */
@interface GNCCore : NSObject {
@public
std::unique_ptr<::location::nearby::connections::Core> _core;
std::unique_ptr<::location::nearby::connections::ServiceControllerRouter>
_service_controller_router;
std::unique_ptr<::nearby::connections::Core> _core;
std::unique_ptr<::nearby::connections::ServiceControllerRouter> _service_controller_router;
}
@end
+2 -2
View File
@@ -21,8 +21,8 @@
#include "connections/implementation/service_controller_router.h"
#import "GoogleToolboxForMac/GTMLogger.h"
using ::location::nearby::connections::Core;
using ::location::nearby::connections::ServiceControllerRouter;
using ::nearby::connections::Core;
using ::nearby::connections::ServiceControllerRouter;
@implementation GNCCore {
}
@@ -28,15 +28,14 @@
#import "connections/clients/ios/Public/NearbyConnections/GNCPayload.h"
#import "internal/platform/implementation/apple/utils.h"
using ::location::nearby::ByteArrayFromNSData;
using ::location::nearby::CppStringFromObjCString;
using ::location::nearby::InputFile;
using ::location::nearby::InputStream;
using ::location::nearby::connections::Payload;
using ::location::nearby::PayloadId;
using ResultListener = ::location::nearby::connections::ResultCallback;
using ::nearby::ByteArrayFromNSData;
using ::nearby::CppStringFromObjCString;
using ::nearby::InputFile;
using ::nearby::InputStream;
using ::nearby::PayloadId;
using ::nearby::connections::Payload;
using ResultListener = ::nearby::connections::ResultCallback;
namespace location {
namespace nearby {
namespace connections {
@@ -83,7 +82,6 @@ class GNCInputStreamFromNSStream : public InputStream {
} // namespace connections
} // namespace nearby
} // namespace location
@implementation GNCPayloadInfo
@@ -142,8 +140,8 @@ class GNCInputStreamFromNSStream : public InputStream {
PayloadId payloadId = payload.identifier;
Payload corePayload(payloadId, [payload]() -> InputStream & {
location::nearby::connections::GNCInputStreamFromNSStream *stream =
new location::nearby::connections::GNCInputStreamFromNSStream(payload.stream);
nearby::connections::GNCInputStreamFromNSStream *stream =
new nearby::connections::GNCInputStreamFromNSStream(payload.stream);
return *stream;
});
return [self sendPayload:std::move(corePayload) size:-1 progress:progress completion:completion];
@@ -34,12 +34,12 @@
NS_ASSUME_NONNULL_BEGIN
using ::location::nearby::CppStringFromObjCString;
using ::location::nearby::connections::DiscoveryOptions;
using ::location::nearby::connections::DiscoveryListener;
using ::location::nearby::connections::GNCStrategyToStrategy;
using ResultListener = ::location::nearby::connections::ResultCallback;
using ::location::nearby::connections::Status;
using ::nearby::CppStringFromObjCString;
using ::nearby::connections::DiscoveryListener;
using ::nearby::connections::DiscoveryOptions;
using ::nearby::connections::GNCStrategyToStrategy;
using ResultListener = ::nearby::connections::ResultCallback;
using ::nearby::connections::Status;
/** This is a GNCDiscovererConnectionInfo that provides storage for its properties. */
@interface GNCDiscovererConnectionInfo : NSObject <GNCDiscovererConnectionInfo>
@@ -123,7 +123,7 @@ using ::location::nearby::connections::Status;
@end
/** C++ classes passed to the core library by GNCDiscoverer. */
namespace location {
namespace nearby {
namespace connections {
@@ -349,9 +349,8 @@ class GNCDiscoveryListener {
} // namespace connections
} // namespace nearby
} // namespace location
using ::location::nearby::connections::GNCDiscoveryListener;
using ::nearby::connections::GNCDiscoveryListener;
@interface GNCDiscoverer () {
std::unique_ptr<GNCDiscoveryListener> discoveryListener;
@@ -19,8 +19,8 @@
#include <stdlib.h>
using ::location::nearby::connections::Payload;
using ::location::nearby::PayloadId;
using ::nearby::PayloadId;
using ::nearby::connections::Payload;
NS_ASSUME_NONNULL_BEGIN
@@ -25,7 +25,6 @@ NS_ASSUME_NONNULL_BEGIN
@class GNCPayloadInfo;
namespace location {
namespace nearby {
namespace connections {
@@ -53,7 +52,6 @@ class GNCPayloadListener : public PayloadListener {
} // namespace connections
} // namespace nearby
} // namespace location
NS_ASSUME_NONNULL_END
@@ -32,7 +32,6 @@
NS_ASSUME_NONNULL_BEGIN
namespace location {
namespace nearby {
namespace connections {
@@ -213,6 +212,5 @@ void GNCPayloadListener::OnPayloadProgress(const std::string &endpoint_id,
} // namespace connections
} // namespace nearby
} // namespace location
NS_ASSUME_NONNULL_END
@@ -24,7 +24,6 @@
NS_ASSUME_NONNULL_BEGIN
namespace location {
namespace nearby {
namespace connections {
@@ -33,7 +32,6 @@ const Strategy& GNCStrategyToStrategy(GNCStrategy strategy);
} // namespace connections
} // namespace nearby
} // namespace location
/** Internal-only properties of the connection result handlers class. */
@interface GNCConnectionResultHandlers ()
@@ -20,7 +20,6 @@
NS_ASSUME_NONNULL_BEGIN
namespace location {
namespace nearby {
namespace connections {
@@ -37,7 +36,6 @@ const Strategy& GNCStrategyToStrategy(GNCStrategy strategy) {
} // namespace connections
} // namespace nearby
} // namespace location
@implementation GNCConnectionHandlers
@@ -15,11 +15,11 @@
#import <Foundation/Foundation.h>
#ifdef __cplusplus
namespace location {
namespace nearby {
class InputStream;
}
} // namespace location
#endif
@interface CPPInputStreamBinding : NSObject
@@ -44,7 +44,7 @@ class InputStream;
*
* @param stream The stream that has a c++ pointer associated with it.
*/
+ (location::nearby::InputStream &)getRefFromStream:(NSInputStream *)stream;
+ (nearby::InputStream &)getRefFromStream:(NSInputStream *)stream;
#endif
@end
@@ -23,10 +23,10 @@
// TODO(b/239758418): Change this to the non-internal version when available.
#include "internal/platform/input_stream.h"
using ::location::nearby::ByteArray;
using ::location::nearby::Exception;
using ::location::nearby::ExceptionOr;
using ::location::nearby::InputStream;
using ::nearby::ByteArray;
using ::nearby::Exception;
using ::nearby::ExceptionOr;
using ::nearby::InputStream;
class CPPInputStream : public InputStream {
public:
@@ -17,19 +17,19 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCAdvertisingOptions.h"
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class AdvertisingOptions;
}
} // namespace nearby
} // namespace location
#endif
@interface GNCAdvertisingOptions (CppConversions)
#ifdef __cplusplus
- (location::nearby::connections::AdvertisingOptions)toCpp;
- (nearby::connections::AdvertisingOptions)toCpp;
#endif
@end
@@ -21,8 +21,8 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCAdvertisingOptions+CppConversions.h"
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
using ::location::nearby::connections::AdvertisingOptions;
using ::location::nearby::connections::CppStrategyFromGNCStrategy;
using ::nearby::connections::AdvertisingOptions;
using ::nearby::connections::CppStrategyFromGNCStrategy;
@implementation GNCAdvertisingOptions (CppConversions)
@@ -17,19 +17,19 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCConnectionOptions.h"
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class ConnectionOptions;
}
} // namespace nearby
} // namespace location
#endif
@interface GNCConnectionOptions (CppConversions)
#ifdef __cplusplus
- (location::nearby::connections::ConnectionOptions)toCpp;
- (nearby::connections::ConnectionOptions)toCpp;
#endif
@end
@@ -20,7 +20,7 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCConnectionOptions+CppConversions.h"
using ::location::nearby::connections::ConnectionOptions;
using ::nearby::connections::ConnectionOptions;
@implementation GNCConnectionOptions (CppConversions)
@@ -37,21 +37,21 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCPayload.h"
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCPayloadDelegate.h"
using ::location::nearby::ByteArray;
using ::location::nearby::connections::AdvertisingOptions;
using ::location::nearby::connections::ConnectionListener;
using ::location::nearby::connections::ConnectionOptions;
using ::location::nearby::connections::ConnectionRequestInfo;
using ::location::nearby::connections::ConnectionResponseInfo;
using ::location::nearby::connections::Core;
using ::location::nearby::connections::DiscoveryListener;
using ::location::nearby::connections::DiscoveryOptions;
using ::location::nearby::connections::Payload;
using ::location::nearby::connections::PayloadListener;
using ::location::nearby::connections::PayloadProgressInfo;
using ResultListener = ::location::nearby::connections::ResultCallback;
using ::location::nearby::connections::ServiceControllerRouter;
using ::location::nearby::connections::Status;
using ::nearby::ByteArray;
using ::nearby::connections::AdvertisingOptions;
using ::nearby::connections::ConnectionListener;
using ::nearby::connections::ConnectionOptions;
using ::nearby::connections::ConnectionRequestInfo;
using ::nearby::connections::ConnectionResponseInfo;
using ::nearby::connections::Core;
using ::nearby::connections::DiscoveryListener;
using ::nearby::connections::DiscoveryOptions;
using ::nearby::connections::Payload;
using ::nearby::connections::PayloadListener;
using ::nearby::connections::PayloadProgressInfo;
using ResultListener = ::nearby::connections::ResultCallback;
using ::nearby::connections::ServiceControllerRouter;
using ::nearby::connections::Status;
GNCStatus GNCStatusFromCppStatus(Status status) {
switch (status.value) {
@@ -17,19 +17,19 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCDiscoveryOptions.h"
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class DiscoveryOptions;
}
} // namespace nearby
} // namespace location
#endif
@interface GNCDiscoveryOptions (CppConversions)
#ifdef __cplusplus
- (location::nearby::connections::DiscoveryOptions)toCpp;
- (nearby::connections::DiscoveryOptions)toCpp;
#endif
@end
@@ -21,8 +21,8 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCDiscoveryOptions+CppConversions.h"
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
using ::location::nearby::connections::CppStrategyFromGNCStrategy;
using ::location::nearby::connections::DiscoveryOptions;
using ::nearby::connections::CppStrategyFromGNCStrategy;
using ::nearby::connections::DiscoveryOptions;
@implementation GNCDiscoveryOptions (CppConversions)
@@ -15,12 +15,12 @@
#import <Foundation/Foundation.h>
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class Status;
NSError *NSErrorFromCppStatus(Status status);
} // namespace connections
} // namespace nearby
} // namespace location
#endif
@@ -22,7 +22,6 @@
extern NSErrorDomain const GNCErrorDomain = @"com.google.nearby.connections.error";
namespace location {
namespace nearby {
namespace connections {
@@ -69,4 +68,3 @@ NSError *NSErrorFromCppStatus(Status status) {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -15,12 +15,12 @@
#import <Foundation/Foundation.h>
#ifdef __cplusplus
namespace location {
namespace nearby {
class Exception;
namespace connections {
NSError *NSErrorFromCppException(Exception exception);
} // namespace connections
} // namespace nearby
} // namespace location
#endif
@@ -23,7 +23,6 @@
extern NSErrorDomain const GNCExceptionDomain = @"com.google.nearby.connections.exception";
namespace location {
namespace nearby {
namespace connections {
@@ -54,4 +53,3 @@ NSError *NSErrorFromCppException(Exception exception) {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -15,11 +15,11 @@
#import <Foundation/Foundation.h>
#ifdef __cplusplus
namespace location {
namespace nearby {
class InputStream;
}
} // namespace location
#endif
@interface GNCInputStream : NSInputStream <NSStreamDelegate>
@@ -29,7 +29,7 @@ class InputStream;
- (nonnull instancetype)initWithURL:(nonnull NSURL *)url NS_UNAVAILABLE;
#ifdef __cplusplus
- (nonnull instancetype)initWithCppInputStream:(nonnull location::nearby::InputStream *)stream
- (nonnull instancetype)initWithCppInputStream:(nonnull nearby::InputStream *)stream
NS_DESIGNATED_INITIALIZER;
#endif
@@ -24,10 +24,10 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCException+Internal.h"
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCException.h"
using ::location::nearby::ByteArray;
using ::location::nearby::ExceptionOr;
using ::location::nearby::InputStream;
using ::location::nearby::connections::NSErrorFromCppException;
using ::nearby::ByteArray;
using ::nearby::ExceptionOr;
using ::nearby::InputStream;
using ::nearby::connections::NSErrorFromCppException;
@implementation GNCInputStream {
NSStreamStatus _streamStatus;
@@ -17,23 +17,23 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCPayload.h"
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class Payload;
}
} // namespace nearby
} // namespace location
#endif
@interface GNCPayload (CppConversions)
#ifdef __cplusplus
+ (nonnull GNCPayload *)fromCpp:(location::nearby::connections::Payload)payload;
+ (nonnull GNCPayload *)fromCpp:(nearby::connections::Payload)payload;
#endif
#ifdef __cplusplus
- (location::nearby::connections::Payload)toCpp;
- (nearby::connections::Payload)toCpp;
#endif
@end
@@ -24,22 +24,22 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCInputStream.h"
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCPayload+CppConversions.h"
using ::location::nearby::ByteArray;
using ::location::nearby::InputFile;
using ::location::nearby::InputStream;
using ::location::nearby::connections::Payload;
using ::nearby::ByteArray;
using ::nearby::InputFile;
using ::nearby::InputStream;
using ::nearby::connections::Payload;
@implementation GNCPayload (CppConversions)
+ (GNCPayload *)fromCpp:(Payload)payload {
int64_t payloadId = payload.GetId();
switch (payload.GetType()) {
case location::nearby::connections::PayloadType::kBytes: {
case nearby::connections::PayloadType::kBytes: {
ByteArray bytes = payload.AsBytes();
NSData *payloadData = [NSData dataWithBytes:bytes.data() length:bytes.size()];
return [[GNCBytesPayload alloc] initWithData:payloadData identifier:payloadId];
}
case location::nearby::connections::PayloadType::kFile: {
case nearby::connections::PayloadType::kFile: {
InputFile *inputFile = payload.AsFile();
NSString *filePath = @(inputFile->GetFilePath().c_str());
NSString *parentFolder = @(payload.GetParentFolder().c_str());
@@ -50,11 +50,11 @@ using ::location::nearby::connections::Payload;
fileName:fileName
identifier:payloadId];
}
case location::nearby::connections::PayloadType::kStream: {
case nearby::connections::PayloadType::kStream: {
GNCInputStream *stream = [[GNCInputStream alloc] initWithCppInputStream:payload.AsStream()];
return [[GNCStreamPayload alloc] initWithStream:stream identifier:payloadId];
}
case location::nearby::connections::PayloadType::kUnknown:
case nearby::connections::PayloadType::kUnknown:
return nil;
}
}
@@ -22,7 +22,7 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/CPPInputStreamBinding.h"
using ::location::nearby::connections::Payload;
using ::nearby::connections::Payload;
@implementation GNCPayload
@@ -17,12 +17,12 @@
typedef NS_ENUM(NSInteger, GNCStrategy);
#ifdef __cplusplus
namespace location {
namespace nearby {
namespace connections {
class Strategy;
Strategy CppStrategyFromGNCStrategy(GNCStrategy strategy);
} // namespace connections
} // namespace nearby
} // namespace location
#endif
@@ -20,7 +20,6 @@
#import "connections/clients/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
namespace location {
namespace nearby {
namespace connections {
@@ -37,4 +36,3 @@ Strategy CppStrategyFromGNCStrategy(GNCStrategy strategy) {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -16,7 +16,7 @@
#include <string>
namespace location::nearby::windows {
namespace nearby::windows {
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
@@ -45,4 +45,4 @@ AdvertisingOptionsW AdvertisingOptionsW::CompatibleOptions() const {
return result;
}
} // namespace location::nearby::windows
} // namespace nearby::windows
@@ -16,7 +16,7 @@
#include "connections/clients/windows/options_base_w.h"
namespace location::nearby::windows {
namespace nearby::windows {
extern "C" {
@@ -44,6 +44,6 @@ struct DLL_API AdvertisingOptionsW : public OptionsBaseW {
};
} // extern "C"
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_ADVERTISING_OPTIONS_W_H_
File diff suppressed because it is too large Load Diff
@@ -16,7 +16,7 @@
#include <string>
namespace location::nearby::windows {
namespace nearby::windows {
void ConnectionOptionsW::GetMediums(const MediumW* mediums,
size_t mediums_size) const {
@@ -32,4 +32,4 @@ void ConnectionOptionsW::GetMediums(const MediumW* mediums,
return;
}
} // namespace location::nearby::windows
} // namespace nearby::windows
@@ -18,7 +18,7 @@
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/options_base_w.h"
namespace location::nearby::windows {
namespace nearby::windows {
extern "C" {
@@ -49,6 +49,6 @@ struct DLL_API ConnectionOptionsW : public OptionsBaseW {
};
} // extern "C"
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONNECTION_OPTIONS_W_H_
+2 -2
View File
@@ -19,7 +19,7 @@
#include "internal/platform/bluetooth_utils.h"
#include "internal/platform/logging.h"
namespace location::nearby::windows {
namespace nearby::windows {
Core *InitCore(connections::ServiceControllerRouter *router) {
#if defined(LOG_SEVERITY_VERBOSE)
@@ -293,4 +293,4 @@ void CloseServiceControllerRouter(
}
}
} // namespace location::nearby::windows
} // namespace nearby::windows
+4 -4
View File
@@ -24,13 +24,13 @@
#include "connections/clients/windows/params_w.h"
#include "connections/clients/windows/payload_w.h"
namespace location::nearby::connections {
namespace nearby::connections {
class Core;
class ServiceController;
class ServiceControllerRouter;
class OfflineServiceController;
} // namespace location::nearby::connections
namespace location::nearby::windows {
} // namespace nearby::connections
namespace nearby::windows {
extern "C" {
@@ -255,6 +255,6 @@ DLL_API ServiceControllerRouter* __stdcall InitServiceControllerRouter();
DLL_API void __stdcall CloseServiceControllerRouter(ServiceControllerRouter*);
} // extern "C"
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CORE_ADAPTER_H_
@@ -24,7 +24,7 @@
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
namespace location::nearby::windows {
namespace nearby::windows {
static CountDownLatch *adapter_finished;
@@ -229,7 +229,7 @@ void ListenerPayloadCB(const char *endpoint_id, PayloadW &payload) {
Dart_CObject dart_object_payload_data;
dart_object_offset.type = Dart_CObject_kString;
switch (payload.GetType()) {
case location::nearby::connections::PayloadType::kBytes: {
case nearby::connections::PayloadType::kBytes: {
char *bytes = nullptr;
size_t bytes_size;
@@ -238,7 +238,7 @@ void ListenerPayloadCB(const char *endpoint_id, PayloadW &payload) {
}
dart_object_offset.value.as_string = bytes;
} break;
case location::nearby::connections::PayloadType::kFile: {
case nearby::connections::PayloadType::kFile: {
std::string payload_data(payload.AsFile()->GetFilePath().data());
dart_object_offset.value.as_string =
const_cast<char *>(payload_data.c_str());
@@ -654,4 +654,4 @@ void SendPayloadDart(Core *pCore, const char *endpoint_id,
}
}
} // namespace location::nearby::windows
} // namespace nearby::windows
@@ -19,7 +19,7 @@
#include "third_party/dart_lang/v2/runtime/include/dart_native_api.h"
#include "connections/clients/windows/core_adapter.h"
namespace location::nearby::windows {
namespace nearby::windows {
enum class StrategyDart {
P2P_CLUSTER = 0,
@@ -302,6 +302,6 @@ DLL_API void __stdcall SendPayloadDart(Core *pCore, const char *endpoint_id,
PayloadDart payload_dart,
Dart_Port result_cb);
} // extern "C"
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // LOCATION_NEARBY_CONNECTIONS_WINDOWS_CORE_ADAPTER_DART_H_
@@ -16,7 +16,7 @@
#include <string>
namespace location::nearby::windows {
namespace nearby::windows {
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
@@ -45,4 +45,4 @@ DiscoveryOptionsW DiscoveryOptionsW::CompatibleOptions() const {
return result;
}
} // namespace location::nearby::windows
} // namespace nearby::windows
@@ -17,7 +17,7 @@
#include "connections/clients/windows/options_base_w.h"
namespace location::nearby::windows {
namespace nearby::windows {
extern "C" {
@@ -41,6 +41,6 @@ struct DLL_API DiscoveryOptionsW : public OptionsBaseW {
};
} // extern "C"
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_DISCOVERY_OPTIONS_W_H_
+2 -2
View File
@@ -14,7 +14,7 @@
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
namespace location::nearby::windows {
namespace nearby::windows {
#ifdef _WIN32 // These storage class specifiers only matter to win32 dll
// builds.
@@ -29,6 +29,6 @@ namespace location::nearby::windows {
#define DLL_API // We're not building a win32 dll, leave the source unchanged.
#endif // _WIN32
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
+67 -67
View File
@@ -1,67 +1,67 @@
// Copyright 2022 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 "connections/clients/windows/file_w.h"
#include <string>
#include "internal/platform/file.h"
namespace location::nearby {
void InputFileDeleter::operator()(nearby::InputFile* p) { delete p; }
void OutputFileDeleter::operator()(nearby::OutputFile* p) { delete p; }
namespace windows {
InputFileW::InputFileW(InputFile* input_file)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(std::move(*input_file)))) {}
InputFileW::InputFileW(PayloadId payload_id, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(payload_id, size))) {}
InputFileW::InputFileW(const char* file_path, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(file_path, size))) {}
InputFileW::InputFileW(InputFileW&& other) noexcept
: impl_(std::move(other.impl_)) {}
// Returns a string that uniquely identifies this file.
// Caller allocates buffer[MAX_PATH] and is responsible
// for freeing.
void InputFileW::GetFilePath(char* file_path) const {
std::string fp = impl_->GetFilePath();
strncpy(file_path, fp.c_str(), fp.length());
}
// Returns total size of this file in bytes.
size_t InputFileW::GetTotalSize() const { return impl_->GetTotalSize(); }
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>
InputFileW::GetImpl() {
return std::move(impl_);
}
OutputFileW::OutputFileW(PayloadId payload_id) {}
OutputFileW::OutputFileW(const char* file_path) {}
OutputFileW::OutputFileW(OutputFileW&&) noexcept {}
OutputFileW& OutputFileW::operator=(OutputFileW&& other) noexcept {
impl_ = std::move(other.impl_);
return *this;
}
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter>
OutputFileW::GetImpl() {
return std::move(impl_);
}
} // namespace windows
} // namespace location::nearby
// Copyright 2022 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 "connections/clients/windows/file_w.h"
#include <string>
#include "internal/platform/file.h"
namespace nearby {
void InputFileDeleter::operator()(nearby::InputFile* p) { delete p; }
void OutputFileDeleter::operator()(nearby::OutputFile* p) { delete p; }
namespace windows {
InputFileW::InputFileW(InputFile* input_file)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(std::move(*input_file)))) {}
InputFileW::InputFileW(PayloadId payload_id, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(payload_id, size))) {}
InputFileW::InputFileW(const char* file_path, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(file_path, size))) {}
InputFileW::InputFileW(InputFileW&& other) noexcept
: impl_(std::move(other.impl_)) {}
// Returns a string that uniquely identifies this file.
// Caller allocates buffer[MAX_PATH] and is responsible
// for freeing.
void InputFileW::GetFilePath(char* file_path) const {
std::string fp = impl_->GetFilePath();
strncpy(file_path, fp.c_str(), fp.length());
}
// Returns total size of this file in bytes.
size_t InputFileW::GetTotalSize() const { return impl_->GetTotalSize(); }
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>
InputFileW::GetImpl() {
return std::move(impl_);
}
OutputFileW::OutputFileW(PayloadId payload_id) {}
OutputFileW::OutputFileW(const char* file_path) {}
OutputFileW::OutputFileW(OutputFileW&&) noexcept {}
OutputFileW& OutputFileW::operator=(OutputFileW&& other) noexcept {
impl_ = std::move(other.impl_);
return *this;
}
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter>
OutputFileW::GetImpl() {
return std::move(impl_);
}
} // namespace windows
} // namespace nearby
+7 -19
View File
@@ -20,7 +20,6 @@
#include "connections/clients/windows/dll_config.h"
#include "internal/platform/payload_id.h"
namespace location {
namespace nearby {
class InputFile;
struct DLL_API InputFileDeleter {
@@ -33,16 +32,14 @@ struct DLL_API OutputFileDeleter {
};
} // namespace nearby
} // namespace location
namespace location {
namespace nearby {
namespace windows {
class DLL_API InputFileW {
public:
explicit InputFileW(location::nearby::InputFile* input_file);
InputFileW(location::nearby::PayloadId payload_id, size_t size);
explicit InputFileW(nearby::InputFile* input_file);
InputFileW(nearby::PayloadId payload_id, size_t size);
InputFileW(const char* file_path, size_t size);
InputFileW(InputFileW&&) noexcept;
@@ -52,35 +49,26 @@ class DLL_API InputFileW {
// Returns total size of this file in bytes.
size_t GetTotalSize() const;
std::unique_ptr<location::nearby::InputFile,
location::nearby::InputFileDeleter>
GetImpl();
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> GetImpl();
private:
std::unique_ptr<location::nearby::InputFile,
location::nearby::InputFileDeleter>
impl_;
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> impl_;
};
class DLL_API OutputFileW {
public:
explicit OutputFileW(location::nearby::PayloadId payload_id);
explicit OutputFileW(nearby::PayloadId payload_id);
explicit OutputFileW(const char* file_path);
OutputFileW(OutputFileW&&) noexcept;
OutputFileW& operator=(OutputFileW&&) noexcept;
std::unique_ptr<location::nearby::OutputFile,
location::nearby::OutputFileDeleter>
GetImpl();
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> GetImpl();
private:
std::unique_ptr<location::nearby::OutputFile,
location::nearby::OutputFileDeleter>
impl_;
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> impl_;
};
} // namespace windows
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_FILE_W_H_
@@ -15,11 +15,10 @@
#include "internal/platform/input_stream.h"
namespace location::nearby {
namespace nearby {
void InputStreamDeleter::operator()(nearby::InputStream* p) { delete p; }
} // namespace location::nearby
} // namespace nearby
namespace location {
namespace nearby {
namespace windows {
@@ -49,4 +48,3 @@ int64_t InputStreamW::Close() {
} // namespace windows
} // namespace nearby
} // namespace location
+47 -51
View File
@@ -1,51 +1,47 @@
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
#include <memory>
namespace location {
namespace nearby {
class InputStream;
struct InputStreamDeleter {
void operator()(InputStream* p);
};
} // namespace nearby
} // namespace location
namespace location {
namespace nearby {
namespace windows {
class InputStreamW {
public:
char* Read(size_t size);
// throws Exception::kIo
int64_t Skip(size_t offset);
// throws Exception::kIo
int64_t Close();
private:
std::unique_ptr<nearby::InputStream, nearby::InputStreamDeleter> impl_;
};
} // namespace windows
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
#include <memory>
namespace nearby {
class InputStream;
struct InputStreamDeleter {
void operator()(InputStream* p);
};
} // namespace nearby
namespace nearby {
namespace windows {
class InputStreamW {
public:
char* Read(size_t size);
// throws Exception::kIo
int64_t Skip(size_t offset);
// throws Exception::kIo
int64_t Close();
private:
std::unique_ptr<nearby::InputStream, nearby::InputStreamDeleter> impl_;
};
} // namespace windows
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
+270 -270
View File
@@ -1,270 +1,270 @@
// Copyright 2022 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 "connections/clients/windows/listeners_w.h"
#include "connections/listeners.h"
namespace location::nearby {
// Must implement Deleters, since the connections classes weren't
// fully defined in the header
namespace connections {
void ResultCallbackDeleter::operator()(connections::ResultCallback *p) {
delete p;
}
void ConnectionListenerDeleter::operator()(connections::ConnectionListener *p) {
delete p;
}
void DiscoveryListenerDeleter::operator()(connections::DiscoveryListener *p) {
delete p;
}
void PayloadListenerDeleter::operator()(connections::PayloadListener *p) {
delete p;
}
} // namespace connections
namespace windows {
static ResultCallbackW *ResultCallbackImpl;
void ResultCB(Status status) { ResultCallbackImpl->result_cb(status); }
ResultCallbackW::ResultCallbackW()
: impl_(std::unique_ptr<connections::ResultCallback,
connections::ResultCallbackDeleter>(
new connections::ResultCallback())) {
ResultCallbackImpl = this;
impl_->result_cb = ResultCB;
}
ResultCallbackW::~ResultCallbackW() {}
ResultCallbackW::ResultCallbackW(ResultCallbackW &other) {
impl_ = std::move(other.impl_);
}
ResultCallbackW::ResultCallbackW(ResultCallbackW &&other) noexcept {
impl_ = std::move(other.impl_);
}
ConnectionListenerW::ConnectionListenerW(InitiatedCB initiatedCB,
AcceptedCB acceptedCB,
RejectedCB rejectedCB,
DisconnectedCB disconnectedCB,
BandwidthChangedCB bandwidthChangedCB)
: initiated_cb(initiatedCB),
accepted_cb(acceptedCB),
rejected_cb(rejectedCB),
disconnected_cb(disconnectedCB),
bandwidth_changed_cb(bandwidthChangedCB),
impl_(std::unique_ptr<connections::ConnectionListener,
connections::ConnectionListenerDeleter>(
new connections::ConnectionListener())) {
CHECK(initiated_cb != nullptr);
auto i = initiated_cb;
impl_->initiated_cb =
[i](const std::string &endpoint_id,
const connections::ConnectionResponseInfo connection_response_info) {
ConnectionResponseInfoW connection_response_info_w{
connection_response_info.remote_endpoint_info.data(),
connection_response_info.remote_endpoint_info.size(),
connection_response_info.authentication_token.c_str(),
connection_response_info.raw_authentication_token.data(),
connection_response_info.raw_authentication_token.size(),
connection_response_info.is_incoming_connection,
connection_response_info.is_connection_verified};
i(endpoint_id.c_str(), connection_response_info_w);
};
CHECK(accepted_cb != nullptr);
auto a = accepted_cb;
impl_->accepted_cb = [a](const std::string &endpoint_id) {
a(endpoint_id.c_str());
};
CHECK(rejected_cb != nullptr);
auto r = rejected_cb;
impl_->rejected_cb = [r](const std::string &endpoint_id, Status status) {
r(endpoint_id.c_str(), status);
};
CHECK(disconnected_cb != nullptr);
auto d = disconnected_cb;
impl_->disconnected_cb = [d](const std::string &endpoint_id) {
d(endpoint_id.c_str());
};
CHECK(bandwidth_changed_cb != nullptr);
auto bwc = bandwidth_changed_cb;
impl_->bandwidth_changed_cb = [bwc](const std::string &endpoint_id,
connections::Medium medium) {
bwc(endpoint_id.c_str(), medium);
};
}
ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &other) {
impl_ = std::move(other.impl_);
accepted_cb = other.accepted_cb;
bandwidth_changed_cb = other.bandwidth_changed_cb;
disconnected_cb = other.disconnected_cb;
initiated_cb = other.initiated_cb;
rejected_cb = other.rejected_cb;
}
ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &&other) noexcept =
default;
DiscoveryListenerW::DiscoveryListenerW(
EndpointFoundCB endpointFoundCB, EndpointLostCB endpointLostCB,
EndpointDistanceChangedCB endpointDistanceChangedCB)
: endpoint_found_cb(endpointFoundCB),
endpoint_lost_cb(endpointLostCB),
endpoint_distance_changed_cb(endpointDistanceChangedCB),
impl_(new connections::DiscoveryListener()) {
CHECK(endpoint_distance_changed_cb != nullptr);
auto epdc = endpoint_distance_changed_cb;
impl_->endpoint_distance_changed_cb =
[epdc](const std::string &endpoint_id,
connections::DistanceInfo distance_info) {
DistanceInfoW distanceInfoW = DistanceInfoW::kUnknown;
switch (distance_info) {
case connections::DistanceInfo::kFar:
distanceInfoW = DistanceInfoW::kFar;
break;
case connections::DistanceInfo::kClose:
distanceInfoW = DistanceInfoW::kFar;
break;
case connections::DistanceInfo::kVeryClose:
distanceInfoW = DistanceInfoW::kVeryClose;
break;
case connections::DistanceInfo::kUnknown:
break;
}
epdc(endpoint_id.c_str(), distanceInfoW);
};
CHECK(endpoint_found_cb != nullptr);
auto epf = endpoint_found_cb;
impl_->endpoint_found_cb = [epf](const std::string &endpoint_id,
ByteArray endpoint_info,
const std::string &service_id) {
epf(endpoint_id.c_str(), endpoint_info.data(), endpoint_info.size(),
service_id.c_str());
};
CHECK(endpoint_lost_cb != nullptr);
auto epl = endpoint_lost_cb;
impl_->endpoint_lost_cb = [epl](const std::string &endpoint_id) {
epl(endpoint_id.c_str());
};
}
DiscoveryListenerW::DiscoveryListenerW(DiscoveryListenerW &other) {
endpoint_distance_changed_cb = other.endpoint_distance_changed_cb;
endpoint_found_cb = other.endpoint_found_cb;
endpoint_lost_cb = other.endpoint_lost_cb;
impl_ = std::move(other.impl_);
}
DiscoveryListenerW::DiscoveryListenerW(DiscoveryListenerW &&other) noexcept {
endpoint_distance_changed_cb = other.endpoint_distance_changed_cb;
endpoint_found_cb = other.endpoint_found_cb;
endpoint_lost_cb = other.endpoint_lost_cb;
impl_ = std::move(other.impl_);
}
PayloadListenerW::PayloadListenerW(PayloadCB payloadCB,
PayloadProgressCB payloadProgressCB)
: payload_cb(payloadCB),
payload_progress_cb(payloadProgressCB),
impl_(std::unique_ptr<connections::PayloadListener,
connections::PayloadListenerDeleter>(
new connections::PayloadListener())) {
CHECK(payload_cb != nullptr);
auto pcb = payload_cb;
impl_->payload_cb = [pcb](const std::string &endpoint_id,
connections::Payload payload) {
PayloadW payloadW;
switch (payload.GetType()) {
case connections::PayloadType::kBytes: {
payloadW = PayloadW(payload.GetId(), payload.AsBytes().data(),
payload.AsBytes().size());
break;
}
case connections::PayloadType::kFile: {
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
// TODO(jfcarroll): Figure out how to capture type kStream.
// case connections::PayloadType::kStream: {
// payloadW = PayloadW(payload.AsStream());
//}
case connections::PayloadType::kStream: {
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
case connections::PayloadType::kUnknown: {
// Throw exception here?
break;
}
}
pcb(endpoint_id.c_str(), payloadW);
};
CHECK(payload_progress_cb != nullptr);
auto ppcb = payload_progress_cb;
impl_->payload_progress_cb =
[ppcb](const std::string &endpoint_id,
connections::PayloadProgressInfo payload_progress_info) {
PayloadProgressInfoW payload_progress_info_w;
payload_progress_info_w.payload_id = payload_progress_info.payload_id;
payload_progress_info_w.total_bytes = payload_progress_info.total_bytes;
payload_progress_info_w.bytes_transferred =
payload_progress_info.bytes_transferred;
switch (payload_progress_info.status) {
case connections::PayloadProgressInfo::Status::kCanceled:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kCanceled;
break;
case connections::PayloadProgressInfo::Status::kFailure:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kFailure;
break;
case connections::PayloadProgressInfo::Status::kInProgress:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kInProgress;
break;
case connections::PayloadProgressInfo::Status::kSuccess:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kSuccess;
break;
}
ppcb(endpoint_id.c_str(), payload_progress_info_w);
};
}
PayloadListenerW::PayloadListenerW(PayloadListenerW &other) {
impl_ = std::move(other.impl_);
}
PayloadListenerW::PayloadListenerW(PayloadListenerW &&other) noexcept {
impl_ = std::move(other.impl_);
}
} // namespace windows
} // namespace location::nearby
// Copyright 2022 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 "connections/clients/windows/listeners_w.h"
#include "connections/listeners.h"
namespace nearby {
// Must implement Deleters, since the connections classes weren't
// fully defined in the header
namespace connections {
void ResultCallbackDeleter::operator()(connections::ResultCallback *p) {
delete p;
}
void ConnectionListenerDeleter::operator()(connections::ConnectionListener *p) {
delete p;
}
void DiscoveryListenerDeleter::operator()(connections::DiscoveryListener *p) {
delete p;
}
void PayloadListenerDeleter::operator()(connections::PayloadListener *p) {
delete p;
}
} // namespace connections
namespace windows {
static ResultCallbackW *ResultCallbackImpl;
void ResultCB(Status status) { ResultCallbackImpl->result_cb(status); }
ResultCallbackW::ResultCallbackW()
: impl_(std::unique_ptr<connections::ResultCallback,
connections::ResultCallbackDeleter>(
new connections::ResultCallback())) {
ResultCallbackImpl = this;
impl_->result_cb = ResultCB;
}
ResultCallbackW::~ResultCallbackW() {}
ResultCallbackW::ResultCallbackW(ResultCallbackW &other) {
impl_ = std::move(other.impl_);
}
ResultCallbackW::ResultCallbackW(ResultCallbackW &&other) noexcept {
impl_ = std::move(other.impl_);
}
ConnectionListenerW::ConnectionListenerW(InitiatedCB initiatedCB,
AcceptedCB acceptedCB,
RejectedCB rejectedCB,
DisconnectedCB disconnectedCB,
BandwidthChangedCB bandwidthChangedCB)
: initiated_cb(initiatedCB),
accepted_cb(acceptedCB),
rejected_cb(rejectedCB),
disconnected_cb(disconnectedCB),
bandwidth_changed_cb(bandwidthChangedCB),
impl_(std::unique_ptr<connections::ConnectionListener,
connections::ConnectionListenerDeleter>(
new connections::ConnectionListener())) {
CHECK(initiated_cb != nullptr);
auto i = initiated_cb;
impl_->initiated_cb =
[i](const std::string &endpoint_id,
const connections::ConnectionResponseInfo connection_response_info) {
ConnectionResponseInfoW connection_response_info_w{
connection_response_info.remote_endpoint_info.data(),
connection_response_info.remote_endpoint_info.size(),
connection_response_info.authentication_token.c_str(),
connection_response_info.raw_authentication_token.data(),
connection_response_info.raw_authentication_token.size(),
connection_response_info.is_incoming_connection,
connection_response_info.is_connection_verified};
i(endpoint_id.c_str(), connection_response_info_w);
};
CHECK(accepted_cb != nullptr);
auto a = accepted_cb;
impl_->accepted_cb = [a](const std::string &endpoint_id) {
a(endpoint_id.c_str());
};
CHECK(rejected_cb != nullptr);
auto r = rejected_cb;
impl_->rejected_cb = [r](const std::string &endpoint_id, Status status) {
r(endpoint_id.c_str(), status);
};
CHECK(disconnected_cb != nullptr);
auto d = disconnected_cb;
impl_->disconnected_cb = [d](const std::string &endpoint_id) {
d(endpoint_id.c_str());
};
CHECK(bandwidth_changed_cb != nullptr);
auto bwc = bandwidth_changed_cb;
impl_->bandwidth_changed_cb = [bwc](const std::string &endpoint_id,
connections::Medium medium) {
bwc(endpoint_id.c_str(), medium);
};
}
ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &other) {
impl_ = std::move(other.impl_);
accepted_cb = other.accepted_cb;
bandwidth_changed_cb = other.bandwidth_changed_cb;
disconnected_cb = other.disconnected_cb;
initiated_cb = other.initiated_cb;
rejected_cb = other.rejected_cb;
}
ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &&other) noexcept =
default;
DiscoveryListenerW::DiscoveryListenerW(
EndpointFoundCB endpointFoundCB, EndpointLostCB endpointLostCB,
EndpointDistanceChangedCB endpointDistanceChangedCB)
: endpoint_found_cb(endpointFoundCB),
endpoint_lost_cb(endpointLostCB),
endpoint_distance_changed_cb(endpointDistanceChangedCB),
impl_(new connections::DiscoveryListener()) {
CHECK(endpoint_distance_changed_cb != nullptr);
auto epdc = endpoint_distance_changed_cb;
impl_->endpoint_distance_changed_cb =
[epdc](const std::string &endpoint_id,
connections::DistanceInfo distance_info) {
DistanceInfoW distanceInfoW = DistanceInfoW::kUnknown;
switch (distance_info) {
case connections::DistanceInfo::kFar:
distanceInfoW = DistanceInfoW::kFar;
break;
case connections::DistanceInfo::kClose:
distanceInfoW = DistanceInfoW::kFar;
break;
case connections::DistanceInfo::kVeryClose:
distanceInfoW = DistanceInfoW::kVeryClose;
break;
case connections::DistanceInfo::kUnknown:
break;
}
epdc(endpoint_id.c_str(), distanceInfoW);
};
CHECK(endpoint_found_cb != nullptr);
auto epf = endpoint_found_cb;
impl_->endpoint_found_cb = [epf](const std::string &endpoint_id,
ByteArray endpoint_info,
const std::string &service_id) {
epf(endpoint_id.c_str(), endpoint_info.data(), endpoint_info.size(),
service_id.c_str());
};
CHECK(endpoint_lost_cb != nullptr);
auto epl = endpoint_lost_cb;
impl_->endpoint_lost_cb = [epl](const std::string &endpoint_id) {
epl(endpoint_id.c_str());
};
}
DiscoveryListenerW::DiscoveryListenerW(DiscoveryListenerW &other) {
endpoint_distance_changed_cb = other.endpoint_distance_changed_cb;
endpoint_found_cb = other.endpoint_found_cb;
endpoint_lost_cb = other.endpoint_lost_cb;
impl_ = std::move(other.impl_);
}
DiscoveryListenerW::DiscoveryListenerW(DiscoveryListenerW &&other) noexcept {
endpoint_distance_changed_cb = other.endpoint_distance_changed_cb;
endpoint_found_cb = other.endpoint_found_cb;
endpoint_lost_cb = other.endpoint_lost_cb;
impl_ = std::move(other.impl_);
}
PayloadListenerW::PayloadListenerW(PayloadCB payloadCB,
PayloadProgressCB payloadProgressCB)
: payload_cb(payloadCB),
payload_progress_cb(payloadProgressCB),
impl_(std::unique_ptr<connections::PayloadListener,
connections::PayloadListenerDeleter>(
new connections::PayloadListener())) {
CHECK(payload_cb != nullptr);
auto pcb = payload_cb;
impl_->payload_cb = [pcb](const std::string &endpoint_id,
connections::Payload payload) {
PayloadW payloadW;
switch (payload.GetType()) {
case connections::PayloadType::kBytes: {
payloadW = PayloadW(payload.GetId(), payload.AsBytes().data(),
payload.AsBytes().size());
break;
}
case connections::PayloadType::kFile: {
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
// TODO(jfcarroll): Figure out how to capture type kStream.
// case connections::PayloadType::kStream: {
// payloadW = PayloadW(payload.AsStream());
//}
case connections::PayloadType::kStream: {
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
case connections::PayloadType::kUnknown: {
// Throw exception here?
break;
}
}
pcb(endpoint_id.c_str(), payloadW);
};
CHECK(payload_progress_cb != nullptr);
auto ppcb = payload_progress_cb;
impl_->payload_progress_cb =
[ppcb](const std::string &endpoint_id,
connections::PayloadProgressInfo payload_progress_info) {
PayloadProgressInfoW payload_progress_info_w;
payload_progress_info_w.payload_id = payload_progress_info.payload_id;
payload_progress_info_w.total_bytes = payload_progress_info.total_bytes;
payload_progress_info_w.bytes_transferred =
payload_progress_info.bytes_transferred;
switch (payload_progress_info.status) {
case connections::PayloadProgressInfo::Status::kCanceled:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kCanceled;
break;
case connections::PayloadProgressInfo::Status::kFailure:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kFailure;
break;
case connections::PayloadProgressInfo::Status::kInProgress:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kInProgress;
break;
case connections::PayloadProgressInfo::Status::kSuccess:
payload_progress_info_w.status =
PayloadProgressInfoW::Status::kSuccess;
break;
}
ppcb(endpoint_id.c_str(), payload_progress_info_w);
};
}
PayloadListenerW::PayloadListenerW(PayloadListenerW &other) {
impl_ = std::move(other.impl_);
}
PayloadListenerW::PayloadListenerW(PayloadListenerW &&other) noexcept {
impl_ = std::move(other.impl_);
}
} // namespace windows
} // namespace nearby
+3 -3
View File
@@ -32,7 +32,7 @@
#include "connections/status.h"
#include "internal/platform/payload_id.h"
namespace location::nearby {
namespace nearby {
// Forward declarations
namespace connections {
struct ConnectionListener;
@@ -61,7 +61,7 @@ struct PayloadProgressInfo;
namespace windows {
using ::location::nearby::connections::Status;
using ::nearby::connections::Status;
template <class T>
T DefaultConstructor() {
@@ -295,6 +295,6 @@ struct DLL_API PayloadListenerW {
} // extern "C"
} // namespace windows
} // namespace location::nearby
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_LISTENERS_W_H_
@@ -16,7 +16,7 @@
#include "proto/connections_enums.pb.h"
namespace location::nearby::windows {
namespace nearby::windows {
using MediumW = ::location::nearby::proto::connections::Medium;
@@ -80,6 +80,6 @@ struct MediumSelectorW {
// Feature On/Off switch for mediums.
using BooleanMediumSelectorW = MediumSelectorW<bool>;
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_MEDIUM_SELECTOR_W_H_
+34 -34
View File
@@ -1,34 +1,34 @@
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/strategy_w.h"
namespace location::nearby::windows {
extern "C" {
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct OptionsBaseW {
location::nearby::windows::StrategyW strategy;
BooleanMediumSelectorW allowed{BooleanMediumSelectorW().SetAll(true)};
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/strategy_w.h"
namespace nearby::windows {
extern "C" {
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct OptionsBaseW {
nearby::windows::StrategyW strategy;
BooleanMediumSelectorW allowed{BooleanMediumSelectorW().SetAll(true)};
};
} // extern "C"
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
@@ -1,58 +1,58 @@
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
#include <string>
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/strategy_w.h"
#include "internal/platform/byte_array.h"
#include "proto/connections_enums.pb.h"
namespace location::nearby::windows {
extern "C" {
// 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
// connections.
struct DLL_API OutOfBandConnectionMetadataW {
// Medium to use for the out-of-band connection.
MediumW medium;
// Endpoint ID to use for the injected connection; will be included in the
// endpoint_found_cb callback. Must be exactly 4 bytes and should be randomly-
// generated such that no two IDs are identical.
const char* endpoint_id;
// Endpoint info to use for the injected connection; will be included in the
// endpoint_found_cb callback. Should uniquely identify the InjectEndpoint()
// call so that the client which made the call can verify the endpoint
// that was found is the one that was injected.
//
// Cannot be empty, and must be <131 bytes.
const char* endpoint_info;
size_t endpoint_info_size;
// Used for Bluetooth connections.
const char* remote_bluetooth_mac_address;
size_t remote_bluetooth_mac_address_size;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
#include <string>
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/strategy_w.h"
#include "internal/platform/byte_array.h"
#include "proto/connections_enums.pb.h"
namespace nearby::windows {
extern "C" {
// 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
// connections.
struct DLL_API OutOfBandConnectionMetadataW {
// Medium to use for the out-of-band connection.
MediumW medium;
// Endpoint ID to use for the injected connection; will be included in the
// endpoint_found_cb callback. Must be exactly 4 bytes and should be randomly-
// generated such that no two IDs are identical.
const char* endpoint_id;
// Endpoint info to use for the injected connection; will be included in the
// endpoint_found_cb callback. Should uniquely identify the InjectEndpoint()
// call so that the client which made the call can verify the endpoint
// that was found is the one that was injected.
//
// Cannot be empty, and must be <131 bytes.
const char* endpoint_info;
size_t endpoint_info_size;
// Used for Bluetooth connections.
const char* remote_bluetooth_mac_address;
size_t remote_bluetooth_mac_address_size;
};
} // extern "C"
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
+42 -42
View File
@@ -1,42 +1,42 @@
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
#include <string>
#include "connections/clients/windows/listeners_w.h"
namespace location::nearby::windows {
extern "C" {
// Used by Discovery in Core::RequestConnection().
// Used by Advertising in Core::StartAdvertising().
struct DLL_API ConnectionRequestInfoW {
// endpoint_info - Identifying information about this endpoint (eg. name,
// device type).
// listener - A set of callbacks notified when remote endpoints request a
// connection to this endpoint.
// ByteArray endpoint_info;
const char* endpoint_info;
size_t endpoint_info_size;
ConnectionListenerW& listener;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
// Copyright 2022 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 THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
#include <string>
#include "connections/clients/windows/listeners_w.h"
namespace nearby::windows {
extern "C" {
// Used by Discovery in Core::RequestConnection().
// Used by Advertising in Core::StartAdvertising().
struct DLL_API ConnectionRequestInfoW {
// endpoint_info - Identifying information about this endpoint (eg. name,
// device type).
// listener - A set of callbacks notified when remote endpoints request a
// connection to this endpoint.
// ByteArray endpoint_info;
const char* endpoint_info;
size_t endpoint_info_size;
ConnectionListenerW& listener;
};
} // extern "C"
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
+2 -2
View File
@@ -18,7 +18,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/payload_id.h"
namespace location::nearby {
namespace nearby {
// Must implement Deleter since Payload wasn't fully defined in
// the header
namespace connections {
@@ -129,4 +129,4 @@ PayloadW::GetImpl() {
}
} // namespace windows
} // namespace location::nearby
} // namespace nearby
+1 -7
View File
@@ -25,7 +25,6 @@
#include "connections/payload_type.h"
#include "internal/platform/payload_id.h"
namespace location {
namespace nearby {
namespace connections {
@@ -35,18 +34,14 @@ struct PayloadDeleter {
};
} // namespace connections
} // namespace nearby
} // namespace location
namespace location {
namespace nearby {
class InputFile;
class InputStream;
} // namespace nearby
} // namespace location
namespace location {
namespace nearby {
namespace windows {
@@ -91,7 +86,7 @@ class DLL_API PayloadW {
int64_t GetId() const;
// Returns Payload type.
const location::nearby::connections::PayloadType GetType() const;
const nearby::connections::PayloadType GetType() const;
// Sets the payload offset in bytes
void SetOffset(size_t offset);
@@ -114,6 +109,5 @@ class DLL_API PayloadW {
} // namespace windows
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PAYLOAD_W_H_
+2 -2
View File
@@ -16,7 +16,7 @@
#include <string>
namespace location::nearby::windows {
namespace nearby::windows {
const StrategyW StrategyW::kNone = {StrategyW::ConnectionType::kNone,
StrategyW::TopologyType::kUnknown};
@@ -76,4 +76,4 @@ bool operator!=(const StrategyW& lhs, const StrategyW& rhs) {
return !(lhs == rhs);
}
} // namespace location::nearby::windows
} // namespace nearby::windows
+2 -2
View File
@@ -18,7 +18,7 @@
#include "connections/clients/windows/dll_config.h"
namespace location::nearby::windows {
namespace nearby::windows {
// Defines a copyable, comparable connection strategy type.
// It is one of: kP2pCluster, kP2pStar, kP2pPointToPoint.
@@ -71,6 +71,6 @@ class DLL_API StrategyW {
TopologyType topology_type_;
};
} // namespace location::nearby::windows
} // namespace nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_STRATEGY_W_H_
-2
View File
@@ -16,7 +16,6 @@
#include <string>
namespace location {
namespace nearby {
namespace connections {
@@ -26,4 +25,3 @@ std::vector<Medium> ConnectionOptions::GetMediums() const {
} // namespace connections
} // namespace nearby
} // namespace location
+1 -3
View File
@@ -20,7 +20,6 @@
#include "internal/platform/byte_array.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace connections {
@@ -32,7 +31,7 @@ struct ConnectionInfo {
std::string bssid;
std::int32_t ap_frequency = -1;
std::string ip_address;
std::vector<proto::connections::Medium> supported_mediums;
std::vector<location::nearby::proto::connections::Medium> supported_mediums;
std::int32_t keep_alive_interval_millis;
std::int32_t keep_alive_timeout_millis;
};
@@ -59,6 +58,5 @@ struct ConnectionOptions : public OptionsBase {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_CONNECTION_OPTIONS_H_
-2
View File
@@ -25,7 +25,6 @@
#include "internal/platform/feature_flags.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -177,4 +176,3 @@ std::string Core::Dump() { return client_.Dump(); }
} // namespace connections
} // namespace nearby
} // namespace location
-2
View File
@@ -29,7 +29,6 @@
#include "internal/analytics/event_logger.h"
#include "internal/device.h"
namespace location {
namespace nearby {
namespace connections {
@@ -282,6 +281,5 @@ class Core {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_CORE_H_
-2
View File
@@ -21,7 +21,6 @@
#include "connections/implementation/mock_service_controller_router.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -50,4 +49,3 @@ TEST(CoreTest, DestructorReportsFatalFailure) {
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
+1 -3
View File
@@ -19,11 +19,10 @@
#include "internal/device.h"
namespace location {
namespace nearby {
namespace connections {
using ::location::nearby::NearbyDevice;
using ::nearby::NearbyDevice;
class NearbyDeviceProvider {
virtual ~NearbyDeviceProvider() = default;
@@ -33,6 +32,5 @@ class NearbyDeviceProvider {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
-2
View File
@@ -16,7 +16,6 @@
#include <string>
namespace location {
namespace nearby {
namespace connections {
@@ -49,4 +48,3 @@ DiscoveryOptions DiscoveryOptions::CompatibleOptions() const {
} // namespace connections
} // namespace nearby
} // namespace location
-2
View File
@@ -22,7 +22,6 @@
#include "internal/platform/byte_array.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace connections {
@@ -52,6 +51,5 @@ struct DiscoveryOptions : OptionsBase {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_DISCOVERY_OPTIONS_H_
@@ -30,7 +30,6 @@
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
@@ -627,33 +626,35 @@ void AnalyticsRecorder::OnErrorCode(const ErrorCodeParams &params) {
error_code->set_common_error(params.common_error);
} else {
switch (params.event) {
case errorcode::proto::START_ADVERTISING:
case location::nearby::errorcode::proto::START_ADVERTISING:
error_code->set_start_advertising_error(params.start_advertising_error);
break;
case errorcode::proto::STOP_ADVERTISING:
case location::nearby::errorcode::proto::STOP_ADVERTISING:
error_code->set_stop_advertising_error(params.stop_advertising_error);
break;
case errorcode::proto::START_LISTENING_INCOMING_CONNECTION:
case location::nearby::errorcode::proto::
START_LISTENING_INCOMING_CONNECTION:
error_code->set_start_listening_incoming_connection_error(
params.start_listening_incoming_connection_error);
break;
case errorcode::proto::STOP_LISTENING_INCOMING_CONNECTION:
case location::nearby::errorcode::proto::
STOP_LISTENING_INCOMING_CONNECTION:
error_code->set_stop_listening_incoming_connection_error(
params.stop_listening_incoming_connection_error);
break;
case errorcode::proto::START_DISCOVERING:
case location::nearby::errorcode::proto::START_DISCOVERING:
error_code->set_start_discovering_error(params.start_discovering_error);
break;
case errorcode::proto::STOP_DISCOVERING:
case location::nearby::errorcode::proto::STOP_DISCOVERING:
error_code->set_stop_discovering_error(params.stop_discovering_error);
break;
case errorcode::proto::CONNECT:
case location::nearby::errorcode::proto::CONNECT:
error_code->set_connect_error(params.connect_error);
break;
case errorcode::proto::DISCONNECT:
case location::nearby::errorcode::proto::DISCONNECT:
error_code->set_disconnect_error(params.disconnect_error);
break;
case errorcode::proto::UNKNOWN_EVENT:
case location::nearby::errorcode::proto::UNKNOWN_EVENT:
default:
error_code->set_common_error(params.common_error);
break;
@@ -687,7 +688,7 @@ void AnalyticsRecorder::LogStartSession() {
session_was_logged_ = false;
if (CanRecordAnalyticsLocked(kOnStartClientSession)) {
client_session_ = std::make_unique<proto::ConnectionsLog::ClientSession>();
client_session_ = std::make_unique<ConnectionsLog::ClientSession>();
started_client_session_time_ = SystemClock::ElapsedRealtime();
start_client_session_was_logged_ = true;
LogEvent(START_CLIENT_SESSION);
@@ -1282,4 +1283,3 @@ AnalyticsRecorder::LogicalConnection::ResolvePendingPayloads(
} // namespace analytics
} // namespace nearby
} // namespace location
@@ -31,7 +31,6 @@
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
@@ -190,7 +189,7 @@ class AnalyticsRecorder {
void AddChunk(std::int64_t chunk_size_bytes);
proto::ConnectionsLog::Payload GetProtoPayload(
location::nearby::analytics::proto::ConnectionsLog::Payload GetProtoPayload(
location::nearby::proto::connections::PayloadStatus status);
location::nearby::proto::connections::PayloadType type() const {
@@ -249,23 +248,26 @@ class AnalyticsRecorder {
std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status);
std::vector<proto::ConnectionsLog::EstablishedConnection>
std::vector<location::nearby::analytics::proto::ConnectionsLog::
EstablishedConnection>
GetEstablisedConnections();
private:
void FinishPhysicalConnection(
proto::ConnectionsLog::EstablishedConnection *established_connection,
location::nearby::analytics::proto::ConnectionsLog::
EstablishedConnection *established_connection,
location::nearby::proto::connections::DisconnectionReason reason);
std::vector<proto::ConnectionsLog::Payload> ResolvePendingPayloads(
std::vector<location::nearby::analytics::proto::ConnectionsLog::Payload>
ResolvePendingPayloads(
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
&pending_payloads,
location::nearby::proto::connections::DisconnectionReason reason);
location::nearby::proto::connections::Medium current_medium_ =
location::nearby::proto::connections::UNKNOWN_MEDIUM;
absl::btree_map<
location::nearby::proto::connections::Medium,
std::unique_ptr<proto::ConnectionsLog::EstablishedConnection>>
absl::btree_map<location::nearby::proto::connections::Medium,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::EstablishedConnection>>
physical_connections_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
incoming_payloads_;
@@ -293,14 +295,14 @@ class AnalyticsRecorder {
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishDiscoveryPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool UpdateAdvertiserConnectionRequestLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest
*request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool UpdateDiscovererConnectionRequestLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest
*request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool BothEndpointsRespondedLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest
*request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void LocalEndpointRespondedLocked(
const std::string &remote_endpoint_id,
location::nearby::proto::connections::ConnectionRequestResponse response)
@@ -310,8 +312,8 @@ class AnalyticsRecorder {
location::nearby::proto::connections::ConnectionRequestResponse response)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void MarkConnectionRequestIgnoredLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest
*request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishUpgradeAttemptLocked(
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
@@ -338,7 +340,9 @@ class AnalyticsRecorder {
Mutex mutex_;
// ClientSession
std::unique_ptr<proto::ConnectionsLog::ClientSession> client_session_;
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::ClientSession>
client_session_;
absl::Time started_client_session_time_;
bool session_was_logged_ ABSL_GUARDED_BY(mutex_) = false;
bool start_client_session_was_logged_ ABSL_GUARDED_BY(mutex_) = false;
@@ -346,36 +350,40 @@ class AnalyticsRecorder {
// Current StrategySession
connections::Strategy current_strategy_ ABSL_GUARDED_BY(mutex_) =
connections::Strategy::kNone;
std::unique_ptr<proto::ConnectionsLog::StrategySession>
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::StrategySession>
current_strategy_session_ ABSL_GUARDED_BY(mutex_);
absl::Time started_strategy_session_time_ ABSL_GUARDED_BY(mutex_);
// Current AdvertisingPhase
std::unique_ptr<proto::ConnectionsLog::AdvertisingPhase>
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::AdvertisingPhase>
current_advertising_phase_;
absl::Time started_advertising_phase_time_;
// Current DiscoveryPhase
std::unique_ptr<proto::ConnectionsLog::DiscoveryPhase>
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::DiscoveryPhase>
current_discovery_phase_;
absl::Time started_discovery_phase_time_;
absl::btree_map<std::string,
std::unique_ptr<proto::ConnectionsLog::ConnectionRequest>>
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::ConnectionRequest>>
incoming_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string,
std::unique_ptr<proto::ConnectionsLog::ConnectionRequest>>
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::ConnectionRequest>>
outgoing_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string, std::unique_ptr<LogicalConnection>>
active_connections_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<
std::string,
std::unique_ptr<proto::ConnectionsLog::BandwidthUpgradeAttempt>>
absl::btree_map<std::string,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::BandwidthUpgradeAttempt>>
bandwidth_upgrade_attempts_ ABSL_GUARDED_BY(mutex_);
};
} // namespace analytics
} // namespace nearby
} // namespace location
#endif // ANALYTICS_ANALYTICS_RECORDER_H_
@@ -30,7 +30,6 @@
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
namespace {
@@ -85,7 +84,7 @@ class FakeEventLogger : public EventLogger {
start_client_session_done_latch_ptr) {}
void Log(const ::google::protobuf::MessageLite& message) override {
auto connections_log = dynamic_cast<const proto::ConnectionsLog*>(&message);
auto connections_log = dynamic_cast<const ConnectionsLog*>(&message);
if (connections_log == nullptr) {
return;
}
@@ -1742,4 +1741,3 @@ TEST(AnalyticsRecorderTest,
} // namespace
} // namespace analytics
} // namespace nearby
} // namespace location
@@ -19,7 +19,6 @@
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
// A struct to construct ConnectionAttemptMetadata for the analytics recorder.
@@ -41,6 +40,5 @@ struct ConnectionAttemptMetadataParams {
};
} // namespace nearby
} // namespace location
#endif // ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
@@ -21,7 +21,6 @@
#include "absl/time/time.h"
#include "internal/platform/system_clock.h"
namespace location {
namespace nearby {
namespace analytics {
@@ -99,6 +98,5 @@ struct PacketMetaData {
} // namespace analytics
} // namespace nearby
} // namespace location
#endif // NEARBY_CONNECTIONS_IMPLEMENTATION_ANALYTICS_PACKET_META_DATA_H_
@@ -19,7 +19,7 @@
#include "internal/platform/logging.h"
#include "internal/platform/mutex_lock.h"
namespace location {
namespace nearby {
namespace analytics {
@@ -169,8 +169,8 @@ bool ThroughputRecorder::Throughput::dump() {
(payload_direction_ == PayloadDirection::INCOMING_PAYLOAD) ? "Received"
: "Sent",
ToString(payload_type_), total_byte_size_,
proto::connections::Medium_Name(medium_), total_millis, throughpu_mbps,
throughput_kbps, file_io_time_,
location::nearby::proto::connections::Medium_Name(medium_), total_millis,
throughpu_mbps, throughput_kbps, file_io_time_,
(payload_direction_ == PayloadDirection::INCOMING_PAYLOAD) ? "Decryption"
: "Encryption",
encryption_time_, socket_io_time_, other);
@@ -321,4 +321,3 @@ int ThroughputRecorderContainer::GetSize() {
} // namespace analytics
} // namespace nearby
} // namespace location
@@ -25,15 +25,14 @@
#include "internal/platform/mutex.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
// The following aliases are only for users' convenience.
using ::location::nearby::proto::connections::Medium;
using ::location::nearby::connections::PayloadType;
using ::nearby::connections::PayloadType;
// Enum to represent if a payload is incoming or outgoing.
using ::location::nearby::connections::PayloadDirection;
using ::nearby::connections::PayloadDirection;
class ThroughputRecorder {
public:
@@ -139,6 +138,5 @@ class ThroughputRecorderContainer {
} // namespace analytics
} // namespace nearby
} // namespace location
#endif // NEARBY_CONNECTIONS_IMPLEMENTATION_ANALYTICS_THROUGHPUT_RECORDER_H_
@@ -21,7 +21,6 @@
#include "internal/platform/logging.h"
#include "proto/connections_enums.proto.h"
namespace location {
namespace nearby {
namespace analytics {
namespace {
@@ -83,11 +82,15 @@ TEST_F(ThroughputRecorderTest, OnFrameSentSaveTransferredSize) {
PacketMetaData packet_meta_data;
packet_meta_data.SetPacketSize(kFrameSize);
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
auto throughput = TPRecorder->GetThroughput(proto::connections::BLE, 0);
auto throughput =
TPRecorder->GetThroughput(location::nearby::proto::connections::BLE, 0);
EXPECT_EQ(throughput.GetTotalByteSize(), kFrameSize * 3);
}
@@ -97,11 +100,13 @@ TEST_F(ThroughputRecorderTest, OnIgnoreUnkownPaylaodType) {
TPRecorder->Start(PayloadType::kUnknown, PayloadDirection::OUTGOING_PAYLOAD);
PacketMetaData packet_meta_data;
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
EXPECT_EQ(TPRecorder->GetThroughputsSize(), 0);
TPRecorder->Start(PayloadType::kUnknown, PayloadDirection::INCOMING_PAYLOAD);
TPRecorder->OnFrameReceived(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameReceived(location::nearby::proto::connections::BLE,
packet_meta_data);
EXPECT_EQ(TPRecorder->GetThroughputsSize(), 0);
}
@@ -121,7 +126,8 @@ TEST_P(ThroughputRecorderTest, OnFrameSentStopAndDump) {
packet_meta_data.StartSocketIo();
absl::SleepFor(absl::Milliseconds(7));
packet_meta_data.StopSocketIo();
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
EXPECT_EQ(TPRecorder->GetDurationMillis(),
packet_meta_data.GetEncryptionTimeInMillis() +
packet_meta_data.GetFileIoTimeInMillis() +
@@ -137,7 +143,8 @@ TEST_P(ThroughputRecorderTest, OnFrameSentStopAndDump) {
packet_meta_data.StartSocketIo();
absl::SleepFor(absl::Milliseconds(17));
packet_meta_data.StopSocketIo();
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data);
if (GetParam() == true) {
NEARBY_LOGS(INFO) << "MarkAsSuccess";
@@ -163,7 +170,8 @@ TEST_F(ThroughputRecorderTest, OnFrameSentStopAndDumpForMultiMeadium) {
packet_meta_data1.StartSocketIo();
absl::SleepFor(absl::Milliseconds(7));
packet_meta_data1.StopSocketIo();
TPRecorder->OnFrameSent(proto::connections::BLE, packet_meta_data1);
TPRecorder->OnFrameSent(location::nearby::proto::connections::BLE,
packet_meta_data1);
PacketMetaData packet_meta_data2;
packet_meta_data2.SetPacketSize(kFrameSize);
@@ -176,7 +184,8 @@ TEST_F(ThroughputRecorderTest, OnFrameSentStopAndDumpForMultiMeadium) {
packet_meta_data2.StartSocketIo();
absl::SleepFor(absl::Milliseconds(17));
packet_meta_data2.StopSocketIo();
TPRecorder->OnFrameSent(proto::connections::WIFI_LAN, packet_meta_data2);
TPRecorder->OnFrameSent(location::nearby::proto::connections::WIFI_LAN,
packet_meta_data2);
TPRecorder->MarkAsSuccess();
EXPECT_TRUE(TPRecorder->Stop());
@@ -199,7 +208,8 @@ TEST_F(ThroughputRecorderTest, OnFrameReceivedCheckDurationMillis) {
packet_meta_data.StartSocketIo();
absl::SleepFor(absl::Milliseconds(7));
packet_meta_data.StopSocketIo();
TPRecorder->OnFrameReceived(proto::connections::BLE, packet_meta_data);
TPRecorder->OnFrameReceived(location::nearby::proto::connections::BLE,
packet_meta_data);
EXPECT_EQ(TPRecorder->GetDurationMillis(),
packet_meta_data.GetEncryptionTimeInMillis() +
packet_meta_data.GetFileIoTimeInMillis() +
@@ -209,11 +219,11 @@ TEST_F(ThroughputRecorderTest, OnFrameReceivedCheckDurationMillis) {
TEST_F(ThroughputRecorderTest, OnTPRecorderNotStarted) {
auto TPRecorder = tp_recorder_container_.GetTPRecorder(
kPayloadIdA, PayloadDirection::OUTGOING_PAYLOAD);
auto throughput = TPRecorder->GetThroughput(proto::connections::BLE, 0);
auto throughput =
TPRecorder->GetThroughput(location::nearby::proto::connections::BLE, 0);
EXPECT_FALSE(throughput.dump());
}
} // namespace
} // namespace analytics
} // namespace nearby
} // namespace location
@@ -20,7 +20,6 @@
#include "connections/implementation/service_id_constants.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -81,4 +80,3 @@ void BaseBwuHandler::RevertResponderState(const std::string& service_id) {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -23,7 +23,6 @@
#include "connections/implementation/bwu_handler.h"
#include "connections/implementation/endpoint_channel_manager.h"
namespace location {
namespace nearby {
namespace connections {
@@ -68,6 +67,5 @@ class BaseBwuHandler : public BwuHandler {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BASE_BWU_HANDLER_H_
@@ -20,7 +20,6 @@
#include "absl/strings/string_view.h"
#include "connections/implementation/service_id_constants.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -226,4 +225,3 @@ TEST(BaseBwuHandlerTest, Revert_Failure_CantFindEndpoint) {
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
@@ -27,7 +27,6 @@
#include "internal/platform/mutex.h"
#include "internal/platform/mutex_lock.h"
namespace location {
namespace nearby {
namespace connections {
@@ -103,16 +102,19 @@ BaseEndpointChannel::BaseEndpointChannel(const std::string& service_id,
// derived medium sockets should dervied, and implement the supported
// values and leave the default values in base #MediumSocket.
/*ConnectionTechnology*/
proto::connections::CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY,
/*ConnectionBand*/ proto::connections::CONNECTION_BAND_UNKNOWN_BAND,
location::nearby::proto::connections::
CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY,
/*ConnectionBand*/
location::nearby::proto::connections::CONNECTION_BAND_UNKNOWN_BAND,
/*frequency*/ -1,
/*try_count*/ 0) {}
BaseEndpointChannel::BaseEndpointChannel(
const std::string& service_id, const std::string& channel_name,
InputStream* reader, OutputStream* writer,
proto::connections::ConnectionTechnology technology,
proto::connections::ConnectionBand band, int frequency, int try_count)
location::nearby::proto::connections::ConnectionTechnology technology,
location::nearby::proto::connections::ConnectionBand band, int frequency,
int try_count)
: service_id_(service_id),
channel_name_(channel_name),
reader_(reader),
@@ -174,7 +176,8 @@ ExceptionOr<ByteArray> BaseEndpointChannel::Read(
result = {};
auto parsed = parser::FromBytes(ByteArray(input));
if (parsed.ok()) {
if (parser::GetFrameType(parsed.result()) == V1Frame::KEEP_ALIVE) {
if (parser::GetFrameType(parsed.result()) ==
location::nearby::connections::V1Frame::KEEP_ALIVE) {
NEARBY_LOGS(INFO)
<< __func__
<< ": Read unencrypted KEEP_ALIVE on encrypted channel.";
@@ -323,7 +326,7 @@ void BaseEndpointChannel::SetAnalyticsRecorder(
}
void BaseEndpointChannel::Close(
proto::connections::DisconnectionReason reason) {
location::nearby::proto::connections::DisconnectionReason reason) {
NEARBY_LOGS(INFO) << __func__
<< ": Closing endpoint channel, reason: " << reason;
Close();
@@ -336,12 +339,14 @@ void BaseEndpointChannel::Close(
std::string BaseEndpointChannel::GetType() const {
MutexLock crypto_lock(&crypto_mutex_);
std::string subtype = IsEncryptionEnabledLocked() ? "ENCRYPTED_" : "";
std::string medium = proto::connections::Medium_Name(
proto::connections::Medium::UNKNOWN_MEDIUM);
std::string medium = location::nearby::proto::connections::Medium_Name(
location::nearby::proto::connections::Medium::UNKNOWN_MEDIUM);
if (GetMedium() != proto::connections::Medium::UNKNOWN_MEDIUM) {
medium =
absl::StrCat(subtype, proto::connections::Medium_Name(GetMedium()));
if (GetMedium() !=
location::nearby::proto::connections::Medium::UNKNOWN_MEDIUM) {
medium = absl::StrCat(
subtype,
location::nearby::proto::connections::Medium_Name(GetMedium()));
}
return medium;
}
@@ -392,13 +397,14 @@ absl::Time BaseEndpointChannel::GetLastWriteTimestamp() const {
return last_write_timestamp_;
}
proto::connections::ConnectionTechnology BaseEndpointChannel::GetTechnology()
const {
location::nearby::proto::connections::ConnectionTechnology
BaseEndpointChannel::GetTechnology() const {
return technology_;
}
// Returns the used wifi band of this EndpointChannel.
proto::connections::ConnectionBand BaseEndpointChannel::GetBand() const {
location::nearby::proto::connections::ConnectionBand
BaseEndpointChannel::GetBand() const {
return band_;
}
@@ -434,4 +440,3 @@ void BaseEndpointChannel::UnblockPausedWriter() {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -28,7 +28,6 @@
#include "internal/platform/mutex.h"
#include "internal/platform/output_stream.h"
namespace location {
namespace nearby {
namespace connections {
@@ -39,12 +38,12 @@ class BaseEndpointChannel : public EndpointChannel {
BaseEndpointChannel(const std::string& service_id,
const std::string& channel_name, InputStream* reader,
OutputStream* writer);
BaseEndpointChannel(const std::string& service_id,
const std::string& channel_name, InputStream* reader,
OutputStream* writer,
proto::connections::ConnectionTechnology,
proto::connections::ConnectionBand band, int frequency,
int try_count);
BaseEndpointChannel(
const std::string& service_id, const std::string& channel_name,
InputStream* reader, OutputStream* writer,
location::nearby::proto::connections::ConnectionTechnology,
location::nearby::proto::connections::ConnectionBand band, int frequency,
int try_count);
~BaseEndpointChannel() override = default;
// EndpointChannel:
@@ -56,12 +55,14 @@ class BaseEndpointChannel : public EndpointChannel {
Exception Write(const ByteArray& data, PacketMetaData& packet_meta_data)
ABSL_LOCKS_EXCLUDED(writer_mutex_, crypto_mutex_) override;
void Close() ABSL_LOCKS_EXCLUDED(is_paused_mutex_) override;
void Close(proto::connections::DisconnectionReason reason) override;
void Close(location::nearby::proto::connections::DisconnectionReason reason)
override;
std::string GetType() const override;
std::string GetServiceId() const override;
std::string GetName() const override;
proto::connections::ConnectionTechnology GetTechnology() const override;
proto::connections::ConnectionBand GetBand() const override;
location::nearby::proto::connections::ConnectionTechnology GetTechnology()
const override;
location::nearby::proto::connections::ConnectionBand GetBand() const override;
int GetFrequency() const override;
int GetTryCount() const override;
int GetMaxTransmitPacketSize() const override;
@@ -127,8 +128,8 @@ class BaseEndpointChannel : public EndpointChannel {
bool is_paused_ ABSL_GUARDED_BY(is_paused_mutex_) = false;
// The medium technology information of this endpoint channel.
proto::connections::ConnectionTechnology technology_;
proto::connections::ConnectionBand band_;
location::nearby::proto::connections::ConnectionTechnology technology_;
location::nearby::proto::connections::ConnectionBand band_;
int frequency_;
int try_count_;
@@ -138,6 +139,5 @@ class BaseEndpointChannel : public EndpointChannel {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BASE_ENDPOINT_CHANNEL_H_
@@ -38,7 +38,6 @@
#include "internal/platform/single_thread_executor.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -407,4 +406,3 @@ TEST(BaseEndpointChannelTest, ReadUnencryptedFrameOnEncryptedChannel) {
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
+73 -46
View File
@@ -39,10 +39,14 @@
#include "internal/platform/bluetooth_utils.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
using ::location::nearby::connections::ConnectionRequestFrame;
using ::location::nearby::connections::ConnectionResponseFrame;
using ::location::nearby::connections::MediumMetadata;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::V1Frame;
using ::securegcm::UKey2Handshake;
constexpr absl::Duration BasePcpHandler::kConnectionRequestReadTimeout;
@@ -165,22 +169,32 @@ void BasePcpHandler::OptionsAllowed(const BooleanMediumSelector& allowed,
std::ostringstream& result) const {
result << "{ ";
if (allowed.bluetooth) {
result << proto::connections::Medium_Name(Medium::BLUETOOTH) << " ";
result << location::nearby::proto::connections::Medium_Name(
Medium::BLUETOOTH)
<< " ";
}
if (allowed.ble) {
result << proto::connections::Medium_Name(Medium::BLE) << " ";
result << location::nearby::proto::connections::Medium_Name(Medium::BLE)
<< " ";
}
if (allowed.web_rtc) {
result << proto::connections::Medium_Name(Medium::WEB_RTC) << " ";
result << location::nearby::proto::connections::Medium_Name(Medium::WEB_RTC)
<< " ";
}
if (allowed.wifi_lan) {
result << proto::connections::Medium_Name(Medium::WIFI_LAN) << " ";
result << location::nearby::proto::connections::Medium_Name(
Medium::WIFI_LAN)
<< " ";
}
if (allowed.wifi_hotspot) {
result << proto::connections::Medium_Name(Medium::WIFI_HOTSPOT) << " ";
result << location::nearby::proto::connections::Medium_Name(
Medium::WIFI_HOTSPOT)
<< " ";
}
if (allowed.wifi_direct) {
result << proto::connections::Medium_Name(Medium::WIFI_DIRECT) << " ";
result << location::nearby::proto::connections::Medium_Name(
Medium::WIFI_DIRECT)
<< " ";
}
result << "}";
}
@@ -203,12 +217,14 @@ BooleanMediumSelector BasePcpHandler::ComputeIntersectionOfSupportedMediums(
for (auto medium : their_mediums) {
NEARBY_LOGS(VERBOSE) << "Their supported medium name: "
<< proto::connections::Medium_Name(medium);
<< location::nearby::proto::connections::Medium_Name(
medium);
}
for (Medium my_medium : GetConnectionMediumsByPriority()) {
NEARBY_LOGS(VERBOSE) << "Our supported medium name: "
<< proto::connections::Medium_Name(my_medium);
<< location::nearby::proto::connections::Medium_Name(
my_medium);
if (std::find(their_mediums.begin(), their_mediums.end(), my_medium) !=
their_mediums.end()) {
// We use advertising options as a proxy to whether or not the local
@@ -355,7 +371,8 @@ EncryptionRunner::ResultListener BasePcpHandler::GetResultListener() {
NEARBY_LOGS(ERROR)
<< "Encryption failed for endpoint_id=" << endpoint_id
<< " on medium="
<< proto::connections::Medium_Name(channel->GetMedium());
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium());
OnEncryptionFailureRunnable(endpoint_id, channel);
});
},
@@ -633,7 +650,7 @@ Status BasePcpHandler::RequestConnection(
}
bool BasePcpHandler::MediumSupportedByClientOptions(
const proto::connections::Medium& medium,
const location::nearby::proto::connections::Medium& medium,
const ConnectionOptions& connection_options) const {
for (auto supported_medium : connection_options.GetMediums()) {
if (medium == supported_medium) {
@@ -645,10 +662,11 @@ bool BasePcpHandler::MediumSupportedByClientOptions(
// Get ordered supported connection medium based on local advertising/discovery
// option.
std::vector<proto::connections::Medium>
std::vector<location::nearby::proto::connections::Medium>
BasePcpHandler::GetSupportedConnectionMediumsByPriority(
const ConnectionOptions& local_connection_option) {
std::vector<proto::connections::Medium> supported_mediums_by_priority;
std::vector<location::nearby::proto::connections::Medium>
supported_mediums_by_priority;
for (auto medium_by_priority : GetConnectionMediumsByPriority()) {
if (MediumSupportedByClientOptions(medium_by_priority,
local_connection_option)) {
@@ -685,7 +703,7 @@ BasePcpHandler::GetDiscoveredEndpoints(const std::string& endpoint_id) {
std::vector<BasePcpHandler::DiscoveredEndpoint*>
BasePcpHandler::GetDiscoveredEndpoints(
const proto::connections::Medium medium) {
const location::nearby::proto::connections::Medium medium) {
std::vector<BasePcpHandler::DiscoveredEndpoint*> result;
for (const auto& item : discovered_endpoints_) {
if (item.second->medium == medium) {
@@ -898,11 +916,10 @@ Status BasePcpHandler::RejectConnection(ClientProxy* client,
client->GetClientId(), &response);
}
void BasePcpHandler::OnIncomingFrame(OfflineFrame& frame,
const std::string& endpoint_id,
ClientProxy* client,
proto::connections::Medium medium,
PacketMetaData& packet_meta_data) {
void BasePcpHandler::OnIncomingFrame(
OfflineFrame& frame, const std::string& endpoint_id, ClientProxy* client,
location::nearby::proto::connections::Medium medium,
PacketMetaData& packet_meta_data) {
CountDownLatch latch(1);
RunOnPcpHandlerThread(
"incoming-frame",
@@ -1056,7 +1073,7 @@ void BasePcpHandler::OnEndpointLost(
bool BasePcpHandler::IsPreferred(
const BasePcpHandler::DiscoveredEndpoint& new_endpoint,
const BasePcpHandler::DiscoveredEndpoint& old_endpoint) {
std::vector<proto::connections::Medium> mediums =
std::vector<location::nearby::proto::connections::Medium> mediums =
GetConnectionMediumsByPriority();
// Make sure the comparator is irreflexive, so we have a strict weak ordering.
if (new_endpoint.medium != old_endpoint.medium) {
@@ -1089,7 +1106,7 @@ bool BasePcpHandler::IsPreferred(
Exception BasePcpHandler::OnIncomingConnection(
ClientProxy* client, const ByteArray& remote_endpoint_info,
std::unique_ptr<EndpointChannel> channel,
proto::connections::Medium medium) {
location::nearby::proto::connections::Medium medium) {
absl::Time start_time = SystemClock::ElapsedRealtime();
// Fixes an NPE in ClientProxy.OnConnectionAccepted. The crash happened when
@@ -1097,7 +1114,7 @@ Exception BasePcpHandler::OnIncomingConnection(
// incoming connection where we attempted to check that state.
if (!client->IsAdvertising()) {
NEARBY_LOGS(WARNING) << "Ignoring incoming connection on medium "
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium())
<< " because client=" << client->GetClientId()
<< " is no longer advertising.";
@@ -1126,13 +1143,15 @@ Exception BasePcpHandler::OnIncomingConnection(
const ConnectionRequestFrame& connection_request =
frame.v1().connection_request();
NEARBY_LOGS(INFO) << "In onIncomingConnection("
<< proto::connections::Medium_Name(channel->GetMedium())
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium())
<< ") for client=" << client->GetClientId()
<< ", read ConnectionRequestFrame from endpoint(id="
<< connection_request.endpoint_id() << ")";
if (client->IsConnectedToEndpoint(connection_request.endpoint_id())) {
NEARBY_LOGS(ERROR) << "Incoming connection on medium "
<< proto::connections::Medium_Name(channel->GetMedium())
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium())
<< " was denied because we're "
"already connected to endpoint(id="
<< connection_request.endpoint_id() << ").";
@@ -1243,7 +1262,8 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
NEARBY_LOGS(INFO)
<< "In onIncomingConnection("
<< proto::connections::Medium_Name(endpoint_channel->GetMedium())
<< location::nearby::proto::connections::Medium_Name(
endpoint_channel->GetMedium())
<< ") for client=" << client->GetClientId()
<< ", found a collision with endpoint " << endpoint_id
<< ". We've already sent a connection request to them with nonce "
@@ -1257,7 +1277,7 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
endpoint_channel->Close();
NEARBY_LOGS(INFO) << "In onIncomingConnection("
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
endpoint_channel->GetMedium())
<< ") for client=" << client->GetClientId()
<< ", cleaned up the collision with endpoint "
@@ -1269,7 +1289,8 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
ProcessTieBreakLoss(client, endpoint_id, &info);
NEARBY_LOGS(INFO)
<< "In onIncomingConnection("
<< proto::connections::Medium_Name(endpoint_channel->GetMedium())
<< location::nearby::proto::connections::Medium_Name(
endpoint_channel->GetMedium())
<< ") for client=" << client->GetClientId()
<< ", cleaned up the collision with endpoint " << endpoint_id
<< " by closing our channel and notifying our client of the failure.";
@@ -1282,7 +1303,8 @@ bool BasePcpHandler::BreakTie(ClientProxy* client,
NEARBY_LOGS(INFO)
<< "In onIncomingConnection("
<< proto::connections::Medium_Name(endpoint_channel->GetMedium())
<< location::nearby::proto::connections::Medium_Name(
endpoint_channel->GetMedium())
<< ") for client=" << client->GetClientId()
<< ", cleaned up the collision with endpoint " << endpoint_id
<< " by closing both channels. Our nonces were identical, so we "
@@ -1318,7 +1340,8 @@ bool BasePcpHandler::AppendRemoteBluetoothMacAddressEndpoint(
}
auto endpoint = it.first->second.get();
for (auto item = it.first; item != it.second; item++) {
if (item->second->medium == proto::connections::Medium::BLUETOOTH) {
if (item->second->medium ==
location::nearby::proto::connections::Medium::BLUETOOTH) {
NEARBY_LOGS(INFO)
<< "Cannot append remote Bluetooth MAC Address endpoint, because "
"the endpoint has already been found over Bluetooth ["
@@ -1340,7 +1363,8 @@ bool BasePcpHandler::AppendRemoteBluetoothMacAddressEndpoint(
auto bluetooth_endpoint =
std::make_shared<BluetoothEndpoint>(BluetoothEndpoint{
{endpoint_id, endpoint->endpoint_info, endpoint->service_id,
proto::connections::Medium::BLUETOOTH, WebRtcState::kUnconnectable},
location::nearby::proto::connections::Medium::BLUETOOTH,
WebRtcState::kUnconnectable},
remote_bluetooth_device,
});
@@ -1369,7 +1393,8 @@ bool BasePcpHandler::AppendWebRTCEndpoint(
auto webrtc_endpoint = std::make_shared<WebRtcEndpoint>(WebRtcEndpoint{
{endpoint_id, endpoint->endpoint_info, endpoint->service_id,
proto::connections::Medium::WEB_RTC, WebRtcState::kConnectable},
location::nearby::proto::connections::Medium::WEB_RTC,
WebRtcState::kConnectable},
CreatePeerIdFromAdvertisement(endpoint->service_id, endpoint->endpoint_id,
endpoint->endpoint_info),
});
@@ -1470,7 +1495,8 @@ void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
client->OnBandwidthChanged(endpoint_id, medium);
NEARBY_LOGS(INFO) << "Connection accepted on Medium:"
<< proto::connections::Medium_Name(medium);
<< location::nearby::proto::connections::Medium_Name(
medium);
// Kick off the bandwidth upgrade for incoming connections.
if (connection_info.is_incoming &&
@@ -1517,8 +1543,7 @@ ExceptionOr<OfflineFrame> BasePcpHandler::ReadConnectionRequestFrame(
std::string BasePcpHandler::GetHashedConnectionToken(
const ByteArray& token_bytes) {
auto token = std::string(token_bytes);
return location::nearby::Base64Utils::Encode(
Utils::Sha256Hash(token, token.size()))
return nearby::Base64Utils::Encode(Utils::Sha256Hash(token, token.size()))
.substr(0, kConnectionTokenLength);
}
@@ -1526,9 +1551,10 @@ void BasePcpHandler::LogConnectionAttemptFailure(
ClientProxy* client, Medium medium, const std::string& endpoint_id,
bool is_incoming, absl::Time start_time,
EndpointChannel* endpoint_channel) {
proto::connections::ConnectionAttemptResult result =
Cancelled(client, endpoint_id) ? proto::connections::RESULT_CANCELLED
: proto::connections::RESULT_ERROR;
location::nearby::proto::connections::ConnectionAttemptResult result =
Cancelled(client, endpoint_id)
? location::nearby::proto::connections::RESULT_CANCELLED
: location::nearby::proto::connections::RESULT_ERROR;
std::unique_ptr<ConnectionAttemptMetadataParams>
connections_attempt_metadata_params;
if (endpoint_channel != nullptr) {
@@ -1539,13 +1565,13 @@ void BasePcpHandler::LogConnectionAttemptFailure(
}
if (is_incoming) {
client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
proto::connections::INITIAL, medium, result,
location::nearby::proto::connections::INITIAL, medium, result,
SystemClock::ElapsedRealtime() - start_time,
/* connection_token= */ "", connections_attempt_metadata_params.get());
} else {
client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
endpoint_id, proto::connections::INITIAL, medium, result,
SystemClock::ElapsedRealtime() - start_time,
endpoint_id, location::nearby::proto::connections::INITIAL, medium,
result, SystemClock::ElapsedRealtime() - start_time,
/* connection_token= */ "", connections_attempt_metadata_params.get());
}
}
@@ -1571,16 +1597,17 @@ void BasePcpHandler::LogConnectionAttemptSuccess(
}
if (connection_info.is_incoming) {
connection_info.client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
proto::connections::INITIAL, connection_info.channel->GetMedium(),
proto::connections::RESULT_SUCCESS,
location::nearby::proto::connections::INITIAL,
connection_info.channel->GetMedium(),
location::nearby::proto::connections::RESULT_SUCCESS,
SystemClock::ElapsedRealtime() - connection_info.start_time,
connection_info.connection_token,
connections_attempt_metadata_params.get());
} else {
connection_info.client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
endpoint_id, proto::connections::INITIAL,
endpoint_id, location::nearby::proto::connections::INITIAL,
connection_info.channel->GetMedium(),
proto::connections::RESULT_SUCCESS,
location::nearby::proto::connections::RESULT_SUCCESS,
SystemClock::ElapsedRealtime() - connection_info.start_time,
connection_info.connection_token,
connections_attempt_metadata_params.get());
@@ -1611,7 +1638,8 @@ BasePcpHandler::PendingConnectionInfo::~PendingConnectionInfo() {
}
if (channel != nullptr) {
channel->Close(proto::connections::DisconnectionReason::SHUTDOWN);
channel->Close(
location::nearby::proto::connections::DisconnectionReason::SHUTDOWN);
}
// Destroy crypto context now; for some reason, crypto context destructor
@@ -1631,4 +1659,3 @@ void BasePcpHandler::PendingConnectionInfo::LocalEndpointRejectedConnection(
} // namespace connections
} // namespace nearby
} // namespace location
+19 -19
View File
@@ -48,7 +48,6 @@
#include "internal/platform/scheduled_executor.h"
#include "internal/platform/single_thread_executor.h"
namespace location {
namespace nearby {
namespace connections {
@@ -132,9 +131,9 @@ class BasePcpHandler : public PcpHandler,
const std::string& endpoint_id) override;
// @EndpointManagerReaderThread
void OnIncomingFrame(OfflineFrame& frame, const std::string& endpoint_id,
ClientProxy* client,
proto::connections::Medium medium,
void OnIncomingFrame(location::nearby::connections::OfflineFrame& frame,
const std::string& endpoint_id, ClientProxy* client,
location::nearby::proto::connections::Medium medium,
analytics::PacketMetaData& packet_meta_data) override;
// Called when an endpoint disconnects while we're waiting for both sides to
@@ -154,7 +153,7 @@ class BasePcpHandler : public PcpHandler,
Status status;
// If success, the mediums on which we are now advertising/discovering, for
// analytics.
std::vector<proto::connections::Medium> mediums;
std::vector<location::nearby::proto::connections::Medium> mediums;
};
// Represents an endpoint that we've discovered. Typically, the implementation
@@ -174,7 +173,7 @@ class BasePcpHandler : public PcpHandler,
struct DiscoveredEndpoint {
DiscoveredEndpoint(std::string endpoint_id, ByteArray endpoint_info,
std::string service_id,
proto::connections::Medium medium,
location::nearby::proto::connections::Medium medium,
WebRtcState web_rtc_state)
: endpoint_id(std::move(endpoint_id)),
endpoint_info(std::move(endpoint_info)),
@@ -186,7 +185,7 @@ class BasePcpHandler : public PcpHandler,
std::string endpoint_id;
ByteArray endpoint_info;
std::string service_id;
proto::connections::Medium medium;
location::nearby::proto::connections::Medium medium;
WebRtcState web_rtc_state;
};
@@ -231,8 +230,8 @@ class BasePcpHandler : public PcpHandler,
};
struct ConnectImplResult {
proto::connections::Medium medium =
proto::connections::Medium::UNKNOWN_MEDIUM;
location::nearby::proto::connections::Medium medium =
location::nearby::proto::connections::Medium::UNKNOWN_MEDIUM;
Status status = {Status::kError};
std::unique_ptr<EndpointChannel> endpoint_channel;
};
@@ -252,7 +251,8 @@ class BasePcpHandler : public PcpHandler,
Exception OnIncomingConnection(
ClientProxy* client, const ByteArray& remote_endpoint_info,
std::unique_ptr<EndpointChannel> endpoint_channel,
proto::connections::Medium medium); // throws Exception::IO
location::nearby::proto::connections::Medium
medium); // throws Exception::IO
virtual bool HasOutgoingConnections(ClientProxy* client) const;
virtual bool HasIncomingConnections(ClientProxy* client) const;
@@ -287,9 +287,10 @@ class BasePcpHandler : public PcpHandler,
DiscoveredEndpoint* endpoint)
RUN_ON_PCP_HANDLER_THREAD() = 0;
virtual std::vector<proto::connections::Medium>
virtual std::vector<location::nearby::proto::connections::Medium>
GetConnectionMediumsByPriority() = 0;
virtual proto::connections::Medium GetDefaultUpgradeMedium() = 0;
virtual location::nearby::proto::connections::Medium
GetDefaultUpgradeMedium() = 0;
// Returns the first discovered endpoint for the given endpoint_id.
DiscoveredEndpoint* GetDiscoveredEndpoint(const std::string& endpoint_id);
@@ -301,7 +302,7 @@ class BasePcpHandler : public PcpHandler,
// Returns a vector of discovered endpoints that share a given Medium.
std::vector<BasePcpHandler::DiscoveredEndpoint*> GetDiscoveredEndpoints(
const proto::connections::Medium medium);
const location::nearby::proto::connections::Medium medium);
mediums::WebrtcPeerId CreatePeerIdFromAdvertisement(
const string& service_id, const string& endpoint_id,
@@ -352,7 +353,7 @@ class BasePcpHandler : public PcpHandler,
std::weak_ptr<Future<Status>> result;
// Only (possibly) vector for incoming connections.
std::vector<proto::connections::Medium> supported_mediums;
std::vector<location::nearby::proto::connections::Medium> supported_mediums;
// Keep track of a channel before we pass it to EndpointChannelManager.
std::unique_ptr<EndpointChannel> channel;
@@ -455,8 +456,8 @@ class BasePcpHandler : public PcpHandler,
const std::string& endpoint_id,
bool can_close_immediately);
ExceptionOr<OfflineFrame> ReadConnectionRequestFrame(
EndpointChannel* channel);
ExceptionOr<location::nearby::connections::OfflineFrame>
ReadConnectionRequestFrame(EndpointChannel* channel);
// Returns an 8 characters length hashed string generated via a token byte
// array.
@@ -480,9 +481,9 @@ class BasePcpHandler : public PcpHandler,
Status WaitForResult(const std::string& method_name, std::int64_t client_id,
Future<Status>* future);
bool MediumSupportedByClientOptions(
const proto::connections::Medium& medium,
const location::nearby::proto::connections::Medium& medium,
const ConnectionOptions& connection_options) const;
std::vector<proto::connections::Medium>
std::vector<location::nearby::proto::connections::Medium>
GetSupportedConnectionMediumsByPriority(
const ConnectionOptions& local_connection_option);
std::string GetStringValueOfSupportedMediums(
@@ -540,6 +541,5 @@ class BasePcpHandler : public PcpHandler,
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BASE_PCP_HANDLER_H_
@@ -37,7 +37,6 @@
#include "internal/platform/pipe.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -102,7 +101,8 @@ class MockEndpointChannel : public BaseEndpointChannel {
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (), (override));
MOCK_METHOD(Exception, Write, (const ByteArray& data), (override));
MOCK_METHOD(void, CloseImpl, (), (override));
MOCK_METHOD(proto::connections::Medium, GetMedium, (), (const override));
MOCK_METHOD(location::nearby::proto::connections::Medium, GetMedium, (),
(const override));
MOCK_METHOD(std::string, GetType, (), (const override));
MOCK_METHOD(std::string, GetName, (), (const override));
MOCK_METHOD(bool, IsPaused, (), (const override));
@@ -157,14 +157,16 @@ class MockPcpHandler : public BasePcpHandler {
(override));
MOCK_METHOD(ConnectImplResult, ConnectImpl,
(ClientProxy * client, DiscoveredEndpoint* endpoint), (override));
MOCK_METHOD(proto::connections::Medium, GetDefaultUpgradeMedium, (),
(override));
MOCK_METHOD(location::nearby::proto::connections::Medium,
GetDefaultUpgradeMedium, (), (override));
std::vector<proto::connections::Medium> GetConnectionMediumsByPriority()
override {
return std::vector<proto::connections::Medium>{
proto::connections::WIFI_LAN, proto::connections::WEB_RTC,
proto::connections::BLUETOOTH, proto::connections::BLE};
std::vector<location::nearby::proto::connections::Medium>
GetConnectionMediumsByPriority() override {
return std::vector<location::nearby::proto::connections::Medium>{
location::nearby::proto::connections::WIFI_LAN,
location::nearby::proto::connections::WEB_RTC,
location::nearby::proto::connections::BLUETOOTH,
location::nearby::proto::connections::BLE};
}
// Mock adapters for protected non-virtual methods of a base class.
@@ -182,14 +184,14 @@ class MockPcpHandler : public BasePcpHandler {
return BasePcpHandler::GetDiscoveredEndpoints(endpoint_id);
}
std::vector<proto::connections::Medium> GetDiscoveryMediums(
std::vector<location::nearby::proto::connections::Medium> GetDiscoveryMediums(
ClientProxy* client) {
auto allowed = client->GetDiscoveryOptions().CompatibleOptions().allowed;
return GetMediumsFromSelector(allowed);
}
std::vector<proto::connections::Medium> GetMediumsFromSelector(
BooleanMediumSelector allowed) {
std::vector<location::nearby::proto::connections::Medium>
GetMediumsFromSelector(BooleanMediumSelector allowed) {
return allowed.GetMediums(true);
}
};
@@ -302,8 +304,9 @@ class BasePcpHandlerTest
std::pair<std::unique_ptr<MockEndpointChannel>,
std::unique_ptr<MockEndpointChannel>>
SetupConnection(Pipe& pipe_a, Pipe& pipe_b,
proto::connections::Medium medium) { // NOLINT
SetupConnection(
Pipe& pipe_a, Pipe& pipe_b,
location::nearby::proto::connections::Medium medium) { // NOLINT
auto channel_a = std::make_unique<MockEndpointChannel>(&pipe_b, &pipe_a);
auto channel_b = std::make_unique<MockEndpointChannel>(&pipe_a, &pipe_b);
// On initiator (A) side, we drop the first write, since this is a
@@ -338,13 +341,14 @@ class BasePcpHandlerTest
return std::make_pair(std::move(channel_a), std::move(channel_b));
}
void RequestConnection(const std::string& endpoint_id,
std::unique_ptr<MockEndpointChannel> channel_a,
MockEndpointChannel* channel_b, ClientProxy* client,
MockPcpHandler* pcp_handler,
proto::connections::Medium connect_medium,
std::atomic_int* flag = nullptr,
Status expected_result = {Status::kSuccess}) {
void RequestConnection(
const std::string& endpoint_id,
std::unique_ptr<MockEndpointChannel> channel_a,
MockEndpointChannel* channel_b, ClientProxy* client,
MockPcpHandler* pcp_handler,
location::nearby::proto::connections::Medium connect_medium,
std::atomic_int* flag = nullptr,
Status expected_result = {Status::kSuccess}) {
ConnectionRequestInfo info{
.endpoint_info = ByteArray{"ABCD"},
.listener = connection_listener_,
@@ -811,4 +815,3 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) {
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
@@ -21,7 +21,6 @@
#include "internal/platform/base_input_stream.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -275,4 +274,3 @@ BleAdvertisement::operator ByteArray() const {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -20,7 +20,6 @@
#include "internal/platform/bluetooth_utils.h"
#include "internal/platform/byte_array.h"
namespace location {
namespace nearby {
namespace connections {
@@ -121,6 +120,5 @@ class BleAdvertisement {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BLE_ADVERTISEMENT_H_
@@ -17,7 +17,6 @@
#include "gtest/gtest.h"
#include "connections/implementation/base_pcp_handler.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -433,4 +432,3 @@ TEST(BleAdvertisementTest,
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
@@ -19,7 +19,6 @@
#include "internal/platform/ble.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -45,8 +44,9 @@ BleEndpointChannel::BleEndpointChannel(const std::string& service_id,
GetOutputStreamOrNull(socket)),
ble_socket_(std::move(socket)) {}
proto::connections::Medium BleEndpointChannel::GetMedium() const {
return proto::connections::Medium::BLE;
location::nearby::proto::connections::Medium BleEndpointChannel::GetMedium()
const {
return location::nearby::proto::connections::Medium::BLE;
}
int BleEndpointChannel::GetMaxTransmitPacketSize() const {
@@ -64,4 +64,3 @@ void BleEndpointChannel::CloseImpl() {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -20,7 +20,6 @@
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble.h"
namespace location {
namespace nearby {
namespace connections {
@@ -30,7 +29,7 @@ class BleEndpointChannel final : public BaseEndpointChannel {
BleEndpointChannel(const std::string& service_id,
const std::string& channel_name, BleSocket socket);
proto::connections::Medium GetMedium() const override;
location::nearby::proto::connections::Medium GetMedium() const override;
int GetMaxTransmitPacketSize() const override;
@@ -44,6 +43,5 @@ class BleEndpointChannel final : public BaseEndpointChannel {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BLE_ENDPOINT_CHANNEL_H_
@@ -20,7 +20,6 @@
#include "internal/platform/ble_v2.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -50,8 +49,9 @@ BleV2EndpointChannel::BleV2EndpointChannel(const std::string& service_id,
GetOutputStreamOrNull(socket)),
ble_socket_(std::move(socket)) {}
proto::connections::Medium BleV2EndpointChannel::GetMedium() const {
return proto::connections::Medium::BLE;
location::nearby::proto::connections::Medium BleV2EndpointChannel::GetMedium()
const {
return location::nearby::proto::connections::Medium::BLE;
}
int BleV2EndpointChannel::GetMaxTransmitPacketSize() const {
@@ -69,4 +69,3 @@ void BleV2EndpointChannel::CloseImpl() {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -20,7 +20,6 @@
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble_v2.h"
namespace location {
namespace nearby {
namespace connections {
@@ -30,7 +29,7 @@ class BleV2EndpointChannel final : public BaseEndpointChannel {
BleV2EndpointChannel(const std::string& service_id,
const std::string& channel_name, BleV2Socket socket);
proto::connections::Medium GetMedium() const override;
location::nearby::proto::connections::Medium GetMedium() const override;
int GetMaxTransmitPacketSize() const override;
@@ -44,6 +43,5 @@ class BleV2EndpointChannel final : public BaseEndpointChannel {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CONNECTIONS_IMPLEMENTATION_BLE_V2_ENDPOINT_CHANNEL_H_
@@ -25,7 +25,6 @@
// Manages the Bluetooth-specific methods needed to upgrade an {@link
// EndpointChannel}.
namespace location {
namespace nearby {
namespace connections {
@@ -159,4 +158,3 @@ void BluetoothBwuHandler::OnIncomingBluetoothConnection(
} // namespace connections
} // namespace nearby
} // namespace location
@@ -24,7 +24,6 @@
#include "internal/platform/bluetooth_classic.h"
#include "internal/platform/count_down_latch.h"
namespace location {
namespace nearby {
namespace connections {
@@ -77,6 +76,5 @@ class BluetoothBwuHandler : public BaseBwuHandler {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BLUETOOTH_BWU_HANDLER_H_
@@ -25,7 +25,6 @@
#include "internal/platform/base_input_stream.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -209,4 +208,3 @@ BluetoothDeviceName::operator std::string() const {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -22,7 +22,6 @@
#include "connections/implementation/pcp.h"
#include "internal/platform/byte_array.h"
namespace location {
namespace nearby {
namespace connections {
@@ -88,6 +87,5 @@ class BluetoothDeviceName {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BLUETOOTH_DEVICE_NAME_H_
@@ -20,7 +20,6 @@
#include "gtest/gtest.h"
#include "internal/platform/base64_utils.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
@@ -204,4 +203,3 @@ TEST(BluetoothDeviceNameTest, CanParseGeneratedName) {
} // namespace
} // namespace connections
} // namespace nearby
} // namespace location
@@ -19,7 +19,6 @@
#include "internal/platform/bluetooth_classic.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
@@ -45,8 +44,9 @@ BluetoothEndpointChannel::BluetoothEndpointChannel(
GetOutputStreamOrNull(socket)),
bluetooth_socket_(std::move(socket)) {}
proto::connections::Medium BluetoothEndpointChannel::GetMedium() const {
return proto::connections::Medium::BLUETOOTH;
location::nearby::proto::connections::Medium
BluetoothEndpointChannel::GetMedium() const {
return location::nearby::proto::connections::Medium::BLUETOOTH;
}
int BluetoothEndpointChannel::GetMaxTransmitPacketSize() const {
@@ -64,4 +64,3 @@ void BluetoothEndpointChannel::CloseImpl() {
} // namespace connections
} // namespace nearby
} // namespace location
@@ -20,7 +20,6 @@
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/bluetooth_classic.h"
namespace location {
namespace nearby {
namespace connections {
@@ -31,7 +30,7 @@ class BluetoothEndpointChannel final : public BaseEndpointChannel {
const std::string& channel_name,
BluetoothSocket bluetooth_socket);
proto::connections::Medium GetMedium() const override;
location::nearby::proto::connections::Medium GetMedium() const override;
int GetMaxTransmitPacketSize() const override;
@@ -45,6 +44,5 @@ class BluetoothEndpointChannel final : public BaseEndpointChannel {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BLUETOOTH_ENDPOINT_CHANNEL_H_
+2 -3
View File
@@ -23,11 +23,11 @@
#include "connections/implementation/offline_frames.h"
#include "internal/platform/count_down_latch.h"
namespace location {
namespace nearby {
namespace connections {
using BwuNegotiationFrame = BandwidthUpgradeNegotiationFrame;
using BwuNegotiationFrame =
location::nearby::connections::BandwidthUpgradeNegotiationFrame;
// Defines the set of methods that need to be implemented to handle the
// per-Medium-specific operations needed to upgrade an EndpointChannel.
@@ -98,6 +98,5 @@ class BwuHandler {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BWU_HANDLER_H_
+104 -77
View File
@@ -39,10 +39,12 @@
#include "internal/platform/feature_flags.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace connections {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::V1Frame;
using ::location::nearby::proto::connections::DisconnectionReason;
// Required for C++ 14 support in Chrome
@@ -187,7 +189,8 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
proposed_medium]() {
NEARBY_LOGS(INFO) << "InitiateBwuForEndpoint for endpoint " << endpoint_id
<< " with medium "
<< proto::connections::Medium_Name(proposed_medium);
<< location::nearby::proto::connections::Medium_Name(
proposed_medium);
if (channel_manager_->isWifiLanConnected() &&
(proposed_medium == Medium::WIFI_HOTSPOT)) {
@@ -225,15 +228,16 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
channel ? channel->GetMedium() : Medium::UNKNOWN_MEDIUM;
client->GetAnalyticsRecorder().OnBandwidthUpgradeStarted(
endpoint_id, channel_medium, proposed_medium,
proto::connections::INCOMING, client->GetConnectionToken(endpoint_id));
location::nearby::proto::connections::INCOMING,
client->GetConnectionToken(endpoint_id));
if (channel == nullptr) {
NEARBY_LOGS(INFO)
<< "BwuManager couldn't complete the upgrade for endpoint "
<< endpoint_id
<< " because it couldn't find an existing EndpointChannel for it.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::CHANNEL_ERROR,
proto::connections::NETWORK_AVAILABLE);
endpoint_id, location::nearby::proto::connections::CHANNEL_ERROR,
location::nearby::proto::connections::NETWORK_AVAILABLE);
return;
}
@@ -249,7 +253,8 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
NEARBY_LOGS(INFO) << "BwuManager ignoring the upgrade for endpoint "
<< endpoint_id
<< " because it is already connected over medium "
<< proto::connections::Medium_Name(proposed_medium);
<< location::nearby::proto::connections::Medium_Name(
proposed_medium);
return;
}
@@ -263,7 +268,7 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
NEARBY_LOGS(ERROR)
<< "BwuManager couldn't complete the upgrade for endpoint "
<< endpoint_id << " to medium "
<< proto::connections::Medium_Name(proposed_medium)
<< location::nearby::proto::connections::Medium_Name(proposed_medium)
<< " because it failed to initialize the "
"BWU_NEGOTIATION.UPGRADE_PATH_AVAILABLE OfflineFrame.";
UpgradePathInfo info;
@@ -271,15 +276,15 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
ProcessUpgradeFailureEvent(client, endpoint_id, info);
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::NETWORK_AVAILABLE);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::NETWORK_AVAILABLE);
return;
}
if (!channel->Write(bytes).Ok()) {
NEARBY_LOGS(ERROR)
<< "BwuManager couldn't complete the upgrade for endpoint "
<< endpoint_id << " to medium "
<< proto::connections::Medium_Name(proposed_medium)
<< location::nearby::proto::connections::Medium_Name(proposed_medium)
<< " because it failed to write the "
"BWU_NEGOTIATION.UPGRADE_PATH_AVAILABLE OfflineFrame.";
return;
@@ -290,7 +295,7 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
"BWU_NEGOTIATION.UPGRADE_PATH_AVAILABLE OfflineFrame while "
"upgrading endpoint "
<< endpoint_id << " to medium "
<< proto::connections::Medium_Name(proposed_medium);
<< location::nearby::proto::connections::Medium_Name(proposed_medium);
in_progress_upgrades_.emplace(endpoint_id, client);
});
}
@@ -306,8 +311,9 @@ void BwuManager::OnIncomingFrame(OfflineFrame& frame,
NEARBY_LOGS(INFO) << "OnIncomingFrame: bwu_frame="
<< BandwidthUpgradeNegotiationFrame::EventType_Name(
bwu_frame.event_type())
<< ", endpoint_id=" << endpoint_id
<< ", medium=" << proto::connections::Medium_Name(medium);
<< ", endpoint_id=" << endpoint_id << ", medium="
<< location::nearby::proto::connections::Medium_Name(
medium);
if (FeatureFlags::GetInstance().GetFlags().enable_async_bandwidth_upgrade) {
RunOnBwuManagerThread(
"bwu-on-incoming-frame", [this, client, endpoint_id, bwu_frame]() {
@@ -370,7 +376,8 @@ void BwuManager::RevertBwuMediumForEndpoint(const std::string& service_id,
// approach and revert the handler for _all_ endpoints.
if (!FeatureFlags::GetInstance().GetFlags().support_multiple_bwu_mediums) {
NEARBY_LOGS(INFO) << "Reverting medium "
<< proto::connections::Medium_Name(medium)
<< location::nearby::proto::connections::Medium_Name(
medium)
<< " for all endpoints for service " << service_id;
medium_ = Medium::UNKNOWN_MEDIUM;
BwuHandler* handler = GetHandlerForMedium(medium);
@@ -381,7 +388,7 @@ void BwuManager::RevertBwuMediumForEndpoint(const std::string& service_id,
}
NEARBY_LOGS(INFO) << "Reverting medium "
<< proto::connections::Medium_Name(medium)
<< location::nearby::proto::connections::Medium_Name(medium)
<< " for service ID " << service_id << " and endpoint "
<< endpoint_id;
endpoint_id_to_bwu_medium_.erase(endpoint_id);
@@ -389,7 +396,8 @@ void BwuManager::RevertBwuMediumForEndpoint(const std::string& service_id,
BwuHandler* handler = GetHandlerForMedium(medium);
if (!handler) {
NEARBY_LOGS(INFO) << "No BWU handler can be found for "
<< proto::connections::Medium_Name(medium);
<< location::nearby::proto::connections::Medium_Name(
medium);
return;
}
// If |service_id| isn't of the INITIATOR-upgrade format--for example, if this
@@ -492,8 +500,8 @@ void BwuManager::OnIncomingConnection(
"socket.";
connection->socket->Close();
AttemptToRecordBandwidthUpgradeErrorForUnknownEndpoint(
proto::connections::MEDIUM_ERROR,
proto::connections::SOCKET_CREATION);
location::nearby::proto::connections::MEDIUM_ERROR,
location::nearby::proto::connections::SOCKET_CREATION);
return;
}
@@ -553,8 +561,8 @@ void BwuManager::OnIncomingConnection(
channel->GetFrequency(), channel->GetTryCount());
}
client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
proto::connections::UPGRADE, channel->GetMedium(),
proto::connections::RESULT_SUCCESS,
location::nearby::proto::connections::UPGRADE, channel->GetMedium(),
location::nearby::proto::connections::RESULT_SUCCESS,
SystemClock::ElapsedRealtime() - connection_attempt_start_time,
client->GetConnectionToken(endpoint_id),
connections_attempt_metadata_params.get());
@@ -582,7 +590,7 @@ void BwuManager::RunUpgradeProtocol(
std::unique_ptr<EndpointChannel> new_channel, bool enable_encryption) {
NEARBY_LOGS(INFO) << "RunUpgradeProtocol new channel @" << new_channel.get()
<< " name: " << new_channel->GetName() << ", medium: "
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
new_channel->GetMedium());
// First, register this new EndpointChannel as *the* EndpointChannel to use
// for this endpoint here onwards. NOTE: We pause this new EndpointChannel
@@ -601,8 +609,8 @@ void BwuManager::RunUpgradeProtocol(
<< " when registering the new EndpointChannel, short-circuiting the "
"upgrade protocol.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::CHANNEL_ERROR,
proto::connections::PRIOR_ENDPOINT_CHANNEL);
endpoint_id, location::nearby::proto::connections::CHANNEL_ERROR,
location::nearby::proto::connections::PRIOR_ENDPOINT_CHANNEL);
return;
}
channel_manager_->ReplaceChannelForEndpoint(
@@ -618,8 +626,8 @@ void BwuManager::RunUpgradeProtocol(
"endpoint "
<< endpoint_id << ", short-circuiting the upgrade protocol.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::LAST_WRITE_TO_PRIOR_CHANNEL);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::LAST_WRITE_TO_PRIOR_CHANNEL);
return;
}
NEARBY_LOGS(VERBOSE) << "BwuManager successfully wrote "
@@ -649,7 +657,8 @@ void BwuManager::ProcessBwuPathAvailableEvent(
parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium());
NEARBY_LOGS(INFO) << "ProcessBwuPathAvailableEvent for endpoint "
<< endpoint_id << " medium "
<< proto::connections::Medium_Name(upgrade_medium);
<< location::nearby::proto::connections::Medium_Name(
upgrade_medium);
if (channel_manager_->isWifiLanConnected() &&
(upgrade_medium == Medium::WIFI_HOTSPOT)) {
@@ -700,22 +709,27 @@ void BwuManager::ProcessBwuPathAvailableEvent(
}
client->GetAnalyticsRecorder().OnBandwidthUpgradeStarted(
endpoint_id, current_medium, upgrade_medium, proto::connections::OUTGOING,
endpoint_id, current_medium, upgrade_medium,
location::nearby::proto::connections::OUTGOING,
client->GetConnectionToken(endpoint_id));
absl::Time connection_attempt_start_time = SystemClock::ElapsedRealtime();
auto channel = ProcessBwuPathAvailableEventInternal(client, endpoint_id,
upgrade_path_info);
proto::connections::ConnectionAttemptResult connection_attempt_result;
location::nearby::proto::connections::ConnectionAttemptResult
connection_attempt_result;
if (channel != nullptr) {
connection_attempt_result = proto::connections::RESULT_SUCCESS;
connection_attempt_result =
location::nearby::proto::connections::RESULT_SUCCESS;
} else if (client->GetCancellationFlag(endpoint_id)->Cancelled()) {
connection_attempt_result = proto::connections::RESULT_CANCELLED;
connection_attempt_result =
location::nearby::proto::connections::RESULT_CANCELLED;
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_REMOTE_ERROR,
proto::connections::UPGRADE_CANCEL);
endpoint_id, location::nearby::proto::connections::RESULT_REMOTE_ERROR,
location::nearby::proto::connections::UPGRADE_CANCEL);
} else {
connection_attempt_result = proto::connections::RESULT_ERROR;
connection_attempt_result =
location::nearby::proto::connections::RESULT_ERROR;
}
std::unique_ptr<ConnectionAttemptMetadataParams>
@@ -727,8 +741,8 @@ void BwuManager::ProcessBwuPathAvailableEvent(
channel->GetFrequency(), channel->GetTryCount());
}
client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
endpoint_id, proto::connections::UPGRADE, upgrade_medium,
connection_attempt_result,
endpoint_id, location::nearby::proto::connections::UPGRADE,
upgrade_medium, connection_attempt_result,
SystemClock::ElapsedRealtime() - connection_attempt_start_time,
client->GetConnectionToken(endpoint_id),
connections_attempt_metadata_params.get());
@@ -753,7 +767,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
if (medium != GetBwuMediumForEndpoint(endpoint_id)) {
NEARBY_LOGS(ERROR)
<< "ProcessBwuPathAvailableEventInternal failed for endpoint "
<< endpoint_id << " medium " << proto::connections::Medium_Name(medium)
<< endpoint_id << " medium "
<< location::nearby::proto::connections::Medium_Name(medium)
<< ". Upgrade medium not yet set for endpoint.";
return nullptr;
}
@@ -762,7 +777,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
if (!handler) {
NEARBY_LOGS(ERROR)
<< "ProcessBwuPathAvailableEventInternal failed for endpoint "
<< endpoint_id << " medium " << proto::connections::Medium_Name(medium)
<< endpoint_id << " medium "
<< location::nearby::proto::connections::Medium_Name(medium)
<< ". No handler for medium.";
return nullptr;
}
@@ -770,7 +786,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
NEARBY_LOGS(INFO) << "ProcessBwuPathAvailableEventInternal for "
"endpoint "
<< endpoint_id << " medium "
<< proto::connections::Medium_Name(medium);
<< location::nearby::proto::connections::Medium_Name(
medium);
// Get service ID from the old channel. Don't keep the old channel's shared
// pointer in scope longer than necessary.
@@ -782,7 +799,7 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
NEARBY_LOGS(ERROR)
<< "ProcessBwuPathAvailableEventInternal failed for endpoint "
<< endpoint_id << " medium "
<< proto::connections::Medium_Name(medium)
<< location::nearby::proto::connections::Medium_Name(medium)
<< ". Old endpoint channel is missing.";
return nullptr;
}
@@ -797,8 +814,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
"channel to endpoint"
<< endpoint_id << ", aborting upgrade.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::SOCKET_CREATION);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::SOCKET_CREATION);
return nullptr;
}
@@ -818,8 +835,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
"OfflineFrame to newly-created EndpointChannel "
<< new_channel->GetName() << ", aborting upgrade.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::CLIENT_INTRODUCTION);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::CLIENT_INTRODUCTION);
return {};
}
@@ -854,7 +871,7 @@ void BwuManager::RunUpgradeFailedProtocol(
const UpgradePathInfo& upgrade_path_info) {
NEARBY_LOGS(INFO) << "RunUpgradeFailedProtocol for endpoint " << endpoint_id
<< " medium "
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
parser::UpgradePathInfoMediumToMedium(
upgrade_path_info.medium()));
// We attempted to connect to the new medium that the remote device has set up
@@ -869,8 +886,8 @@ void BwuManager::RunUpgradeFailedProtocol(
<< " when sending an upgrade failure frame, short-circuiting the "
"upgrade protocol.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::CHANNEL_ERROR,
proto::connections::NETWORK_AVAILABLE);
endpoint_id, location::nearby::proto::connections::CHANNEL_ERROR,
location::nearby::proto::connections::NETWORK_AVAILABLE);
return;
}
@@ -883,8 +900,8 @@ void BwuManager::RunUpgradeFailedProtocol(
"OfflineFrame to endpoint "
<< endpoint_id << ", short-circuiting the upgrade protocol.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::NETWORK_AVAILABLE);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::NETWORK_AVAILABLE);
return;
}
@@ -901,7 +918,8 @@ bool BwuManager::ReadClientIntroductionFrame(EndpointChannel* channel,
ClientIntroduction& introduction) {
NEARBY_LOGS(INFO) << "ReadClientIntroductionFrame with channel name: "
<< channel->GetName() << ", medium: "
<< proto::connections::Medium_Name(channel->GetMedium());
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium());
CancelableAlarm timeout_alarm(
"BwuManager::ReadClientIntroductionFrame",
[channel]() {
@@ -952,7 +970,8 @@ bool BwuManager::ReadClientIntroductionFrame(EndpointChannel* channel,
bool BwuManager::ReadClientIntroductionAckFrame(EndpointChannel* channel) {
NEARBY_LOGS(INFO) << "ReadClientIntroductionAckFrame with channel name: "
<< channel->GetName() << ", medium: "
<< proto::connections::Medium_Name(channel->GetMedium());
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium());
CancelableAlarm timeout_alarm(
"BwuManager::ReadClientIntroductionAckFrame",
[channel]() {
@@ -982,7 +1001,8 @@ bool BwuManager::ReadClientIntroductionAckFrame(EndpointChannel* channel) {
bool BwuManager::WriteClientIntroductionAckFrame(EndpointChannel* channel) {
NEARBY_LOGS(INFO) << "WriteClientIntroductionAckFrame channel name: "
<< channel->GetName() << ", medium: "
<< proto::connections::Medium_Name(channel->GetMedium());
<< location::nearby::proto::connections::Medium_Name(
channel->GetMedium());
return channel->Write(parser::ForBwuIntroductionAck()).Ok();
}
@@ -1011,7 +1031,7 @@ void BwuManager::ProcessLastWriteToPriorChannelEvent(
NEARBY_LOGS(INFO) << "ProcessLastWriteToPriorChannelEvent: service_id="
<< previous_endpoint_channel->GetServiceId()
<< ", endpoint_id=" << endpoint_id << ", medium="
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
previous_endpoint_channel->GetMedium());
if (!previous_endpoint_channel->Write(parser::ForBwuSafeToClose()).Ok()) {
@@ -1026,8 +1046,8 @@ void BwuManager::ProcessLastWriteToPriorChannelEvent(
<< endpoint_id
<< ", short-circuiting the upgrade protocol.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::RESULT_IO_ERROR,
proto::connections::SAFE_TO_CLOSE_PRIOR_CHANNEL);
endpoint_id, location::nearby::proto::connections::RESULT_IO_ERROR,
location::nearby::proto::connections::SAFE_TO_CLOSE_PRIOR_CHANNEL);
return;
}
NEARBY_LOGS(VERBOSE) << "BwuManager successfully wrote "
@@ -1124,7 +1144,7 @@ void BwuManager::ProcessUpgradeFailureEvent(
const UpgradePathInfo& upgrade_info) {
NEARBY_LOGS(INFO) << "ProcessUpgradeFailureEvent for endpoint " << endpoint_id
<< " from medium: "
<< proto::connections::Medium_Name(
<< location::nearby::proto::connections::Medium_Name(
parser::UpgradePathInfoMediumToMedium(
upgrade_info.medium()));
// The remote device failed to upgrade to the new medium we set up for them.
@@ -1147,8 +1167,8 @@ void BwuManager::ProcessUpgradeFailureEvent(
<< " because we have other connected endpoints and can't try a new "
"upgrade medium.";
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(
endpoint_id, proto::connections::CHANNEL_ERROR,
proto::connections::NETWORK_AVAILABLE);
endpoint_id, location::nearby::proto::connections::CHANNEL_ERROR,
location::nearby::proto::connections::NETWORK_AVAILABLE);
return;
}
@@ -1187,7 +1207,8 @@ void BwuManager::TryNextBestUpgradeMediums(
Medium next_medium = ChooseBestUpgradeMedium(endpoint_id, upgrade_mediums);
NEARBY_LOGS(INFO) << "Try Next Best Medium for endpoint " << endpoint_id
<< " after ChooseBestUpgradeMedium: "
<< proto::connections::Medium_Name(next_medium);
<< location::nearby::proto::connections::Medium_Name(
next_medium);
// If current medium is not WiFi and we have not succeeded with upgrading yet,
// retry upgrade.
@@ -1196,7 +1217,8 @@ void BwuManager::TryNextBestUpgradeMediums(
Medium current_medium =
channel ? channel->GetMedium() : Medium::UNKNOWN_MEDIUM;
NEARBY_LOGS(VERBOSE) << "current_medium: "
<< proto::connections::Medium_Name(current_medium);
<< location::nearby::proto::connections::Medium_Name(
current_medium);
if (current_medium != Medium::WIFI_LAN &&
(next_medium == current_medium || next_medium == Medium::UNKNOWN_MEDIUM ||
upgrade_mediums.empty())) {
@@ -1298,12 +1320,13 @@ Medium BwuManager::ChooseBestUpgradeMedium(
// switch.
std::string mediums_string;
for (const auto& medium : available_mediums) {
absl::StrAppend(&mediums_string, proto::connections::Medium_Name(medium),
absl::StrAppend(&mediums_string,
location::nearby::proto::connections::Medium_Name(medium),
"; ");
}
NEARBY_LOGS(INFO)
<< "Current upgrade medium "
<< proto::connections::Medium_Name(current_medium)
<< location::nearby::proto::connections::Medium_Name(current_medium)
<< " is not supported by the remote endpoint (supported mediums: "
<< mediums_string << ")";
}
@@ -1338,8 +1361,9 @@ void BwuManager::RetryUpgradesAfterDelay(ClientProxy* client,
}
void BwuManager::AttemptToRecordBandwidthUpgradeErrorForUnknownEndpoint(
proto::connections::BandwidthUpgradeResult result,
proto::connections::BandwidthUpgradeErrorStage error_stage) {
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage) {
if (in_progress_upgrades_.size() == 1) {
auto it = in_progress_upgrades_.begin();
std::string endpoint_id = it->first;
@@ -1351,22 +1375,26 @@ void BwuManager::AttemptToRecordBandwidthUpgradeErrorForUnknownEndpoint(
// make for them.
client->GetAnalyticsRecorder().OnBandwidthUpgradeError(endpoint_id, result,
error_stage);
NEARBY_LOGS(INFO) << "BwuManager got error "
<< proto::connections::BandwidthUpgradeResult_Name(result)
<< " at stage "
<< proto::connections::BandwidthUpgradeErrorStage_Name(
error_stage)
<< " when upgrading endpoint " << endpoint_id;
NEARBY_LOGS(INFO)
<< "BwuManager got error "
<< location::nearby::proto::connections::BandwidthUpgradeResult_Name(
result)
<< " at stage "
<< location::nearby::proto::connections::
BandwidthUpgradeErrorStage_Name(error_stage)
<< " when upgrading endpoint " << endpoint_id;
}
// Otherwise, we have no way of knowing which endpoint was trying to connect
// to us :(
NEARBY_LOGS(INFO) << "BwuManager got error "
<< proto::connections::BandwidthUpgradeResult_Name(result)
<< " at stage "
<< proto::connections::BandwidthUpgradeErrorStage_Name(
error_stage)
<< ", but we don't know which endpoint was trying to "
"connect to us, so skipping analytics for his error.";
NEARBY_LOGS(INFO)
<< "BwuManager got error "
<< location::nearby::proto::connections::BandwidthUpgradeResult_Name(
result)
<< " at stage "
<< location::nearby::proto::connections::BandwidthUpgradeErrorStage_Name(
error_stage)
<< ", but we don't know which endpoint was trying to "
"connect to us, so skipping analytics for his error.";
}
absl::Duration BwuManager::CalculateNextRetryDelay(
@@ -1409,4 +1437,3 @@ void BwuManager::CancelAllRetryUpgradeAlarms() {
} // namespace connections
} // namespace nearby
} // namespace location
+6 -6
View File
@@ -30,7 +30,6 @@
#include "connections/implementation/mediums/mediums.h"
#include "internal/platform/scheduled_executor.h"
namespace location {
namespace nearby {
namespace connections {
@@ -85,8 +84,9 @@ class BwuManager : public EndpointManager::FrameProcessor {
// This is also an entry point for handling messages for both outbound and
// inbound BWU protocol.
// @EndpointManagerReaderThread
void OnIncomingFrame(OfflineFrame& frame, const std::string& endpoint_id,
ClientProxy* client, Medium medium,
void OnIncomingFrame(location::nearby::connections::OfflineFrame& frame,
const std::string& endpoint_id, ClientProxy* client,
Medium medium,
PacketMetaData& packet_meta_data) override;
// Cleans up in-progress upgrades after endpoint disconnection.
@@ -193,8 +193,9 @@ class BwuManager : public EndpointManager::FrameProcessor {
void RetryUpgradesAfterDelay(ClientProxy* client,
const std::string& endpoint_id);
void AttemptToRecordBandwidthUpgradeErrorForUnknownEndpoint(
proto::connections::BandwidthUpgradeResult result,
proto::connections::BandwidthUpgradeErrorStage error_stage);
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage);
bool is_single_threaded_for_testing_ = false;
@@ -239,6 +240,5 @@ class BwuManager : public EndpointManager::FrameProcessor {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_BWU_MANAGER_H_

Some files were not shown because too many files have changed in this diff Show More