mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Separate ConnectionOptions into AdvertisingOptions, ConnectionOptions and DiscoveryOptions everywhere in the core.
PiperOrigin-RevId: 422626306
This commit is contained in:
committed by
Copybara-Service
parent
04ec681865
commit
56eb46db06
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Google LLC
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "core/internal/pcp.h"
|
||||
#include "core/internal/pcp_handler.h"
|
||||
#include "core/listeners.h"
|
||||
#include "core/options.h"
|
||||
#include "core/status.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/prng.h"
|
||||
@@ -91,7 +90,7 @@ class BasePcpHandler : public PcpHandler,
|
||||
// See
|
||||
// cpp/core/listeners.h
|
||||
Status StartAdvertising(ClientProxy* client, const std::string& service_id,
|
||||
const ConnectionOptions& options,
|
||||
const AdvertisingOptions& advertising_options,
|
||||
const ConnectionRequestInfo& info) override;
|
||||
|
||||
// Stops Advertising is active, and changes CLientProxy state,
|
||||
@@ -102,7 +101,7 @@ class BasePcpHandler : public PcpHandler,
|
||||
// Updates ClientProxy state once discovery started.
|
||||
// DiscoveryListener will get called in case of any event.
|
||||
Status StartDiscovery(ClientProxy* client, const std::string& service_id,
|
||||
const ConnectionOptions& options,
|
||||
const DiscoveryOptions& discovery_options,
|
||||
const DiscoveryListener& listener) override;
|
||||
|
||||
// Stops Discovery if it is active, and changes CLientProxy state,
|
||||
@@ -114,9 +113,10 @@ class BasePcpHandler : public PcpHandler,
|
||||
|
||||
// Requests a newly discovered remote endpoint it to form a connection.
|
||||
// Updates state on ClientProxy.
|
||||
Status RequestConnection(ClientProxy* client, const std::string& endpoint_id,
|
||||
const ConnectionRequestInfo& info,
|
||||
const ConnectionOptions& options) override;
|
||||
Status RequestConnection(
|
||||
ClientProxy* client, const std::string& endpoint_id,
|
||||
const ConnectionRequestInfo& info,
|
||||
const ConnectionOptions& connection_options) override;
|
||||
|
||||
// Called by either party to accept connection on their part.
|
||||
// Until both parties call it, connection will not reach a data phase.
|
||||
@@ -230,9 +230,6 @@ class BasePcpHandler : public PcpHandler,
|
||||
BluetoothDevice GetRemoteBluetoothDevice(
|
||||
const std::string& remote_bluetooth_mac_address);
|
||||
|
||||
ConnectionOptions GetConnectionOptions() const;
|
||||
ConnectionOptions GetDiscoveryOptions() const;
|
||||
|
||||
void OnEndpointFound(ClientProxy* client,
|
||||
std::shared_ptr<DiscoveredEndpoint> endpoint)
|
||||
RUN_ON_PCP_HANDLER_THREAD();
|
||||
@@ -254,7 +251,8 @@ class BasePcpHandler : public PcpHandler,
|
||||
virtual StartOperationResult StartAdvertisingImpl(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& local_endpoint_id,
|
||||
const ByteArray& local_endpoint_info, const ConnectionOptions& options)
|
||||
const ByteArray& local_endpoint_info,
|
||||
const AdvertisingOptions& advertising_options)
|
||||
RUN_ON_PCP_HANDLER_THREAD() = 0;
|
||||
|
||||
virtual Status StopAdvertisingImpl(ClientProxy* client)
|
||||
@@ -262,7 +260,8 @@ class BasePcpHandler : public PcpHandler,
|
||||
|
||||
virtual StartOperationResult StartDiscoveryImpl(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const ConnectionOptions& options) RUN_ON_PCP_HANDLER_THREAD() = 0;
|
||||
const DiscoveryOptions& discovery_options)
|
||||
RUN_ON_PCP_HANDLER_THREAD() = 0;
|
||||
|
||||
virtual Status StopDiscoveryImpl(ClientProxy* client)
|
||||
RUN_ON_PCP_HANDLER_THREAD() = 0;
|
||||
@@ -333,7 +332,7 @@ class BasePcpHandler : public PcpHandler,
|
||||
absl::Time start_time{absl::InfinitePast()};
|
||||
// Client callbacks. Always valid.
|
||||
ConnectionListener listener;
|
||||
ConnectionOptions options;
|
||||
ConnectionOptions connection_options;
|
||||
|
||||
// Only set for outgoing connections. If set, we must call
|
||||
// result->Set() when connection is established, or rejected.
|
||||
@@ -391,21 +390,18 @@ class BasePcpHandler : public PcpHandler,
|
||||
absl::Seconds(2);
|
||||
static constexpr int kConnectionTokenLength = 8;
|
||||
|
||||
void OnConnectionResponse(ClientProxy* client, const std::string& endpoint_id,
|
||||
const OfflineFrame& frame);
|
||||
|
||||
// Returns true if the new endpoint is preferred over the old endpoint.
|
||||
bool IsPreferred(const BasePcpHandler::DiscoveredEndpoint& new_endpoint,
|
||||
const BasePcpHandler::DiscoveredEndpoint& old_endpoint);
|
||||
|
||||
// Returns true, if connection party should respect the specified topology.
|
||||
bool ShouldEnforceTopologyConstraints(
|
||||
const ConnectionOptions& local_advertising_options) const;
|
||||
const AdvertisingOptions& local_advertising_options) const;
|
||||
|
||||
// Returns true, if connection party should attempt to upgrade itself to
|
||||
// use a higher bandwidth medium, if it is available.
|
||||
bool AutoUpgradeBandwidth(
|
||||
const ConnectionOptions& local_advertising_options) const;
|
||||
const AdvertisingOptions& local_advertising_options) const;
|
||||
|
||||
// Returns true if the incoming connection should be killed. This only
|
||||
// happens when an incoming connection arrives while we have an outgoing
|
||||
@@ -424,12 +420,12 @@ class BasePcpHandler : public PcpHandler,
|
||||
bool AppendRemoteBluetoothMacAddressEndpoint(
|
||||
const std::string& endpoint_id,
|
||||
const std::string& remote_bluetooth_mac_address,
|
||||
const ConnectionOptions& local_discovery_options);
|
||||
const DiscoveryOptions& local_discovery_options);
|
||||
|
||||
// Returns true if the webrtc endpoint is created and appended into
|
||||
// discovered_endpoints_ with key endpoint_id.
|
||||
bool AppendWebRTCEndpoint(const std::string& endpoint_id,
|
||||
const ConnectionOptions& local_discovery_options);
|
||||
const DiscoveryOptions& local_discovery_options);
|
||||
|
||||
void ProcessPreConnectionInitiationFailure(
|
||||
ClientProxy* client, Medium medium, const std::string& endpoint_id,
|
||||
@@ -477,24 +473,32 @@ class BasePcpHandler : public PcpHandler,
|
||||
Future<Status>* future);
|
||||
bool MediumSupportedByClientOptions(
|
||||
const proto::connections::Medium& medium,
|
||||
const ConnectionOptions& client_options) const;
|
||||
const ConnectionOptions& connection_options) const;
|
||||
std::vector<proto::connections::Medium>
|
||||
GetSupportedConnectionMediumsByPriority(
|
||||
const ConnectionOptions& local_option);
|
||||
std::string GetStringValueOfSupportedMediums(
|
||||
const ConnectionOptions& options) const;
|
||||
const ConnectionOptions& connection_options) const;
|
||||
std::string GetStringValueOfSupportedMediums(
|
||||
const AdvertisingOptions& advertising_options) const;
|
||||
std::string GetStringValueOfSupportedMediums(
|
||||
const DiscoveryOptions& discovery_options) const;
|
||||
|
||||
// The endpoint id in high visibility mode is stable for 30 seconds, while in
|
||||
// low visibility mode it always rotates. We assume a client is trying to
|
||||
// rotate endpoint id when the options is "low power" (3P) or "disable
|
||||
// Bluetooth classic" (1P).
|
||||
bool ShouldEnterHighVisibilityMode(const ConnectionOptions& options);
|
||||
// rotate endpoint id when the advertising options is "low power" (3P) or
|
||||
// "disable Bluetooth classic" (1P).
|
||||
bool ShouldEnterHighVisibilityMode(
|
||||
const AdvertisingOptions& advertising_options);
|
||||
|
||||
// Returns the intersection of supported mediums based on the mediums reported
|
||||
// by the remote client and the local client's advertising options.
|
||||
BooleanMediumSelector ComputeIntersectionOfSupportedMediums(
|
||||
const PendingConnectionInfo& connection_info);
|
||||
|
||||
void OptionsAllowed(const BooleanMediumSelector& allowed,
|
||||
std::ostringstream& result) const;
|
||||
|
||||
ScheduledExecutor alarm_executor_;
|
||||
SingleThreadExecutor serial_executor_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user