mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Process FileSync messages.
PiperOrigin-RevId: 879237616
This commit is contained in:
committed by
Copybara-Service
parent
79f9436ed0
commit
0191c50e2a
@@ -232,6 +232,8 @@ cc_library(
|
|||||||
"//internal/base:file_path",
|
"//internal/base:file_path",
|
||||||
"//internal/base:files",
|
"//internal/base:files",
|
||||||
"//internal/platform:types",
|
"//internal/platform:types",
|
||||||
|
"//location/nearby/sharing/lib/sync:sync_config_prefs_cc_proto",
|
||||||
|
"//location/nearby/sharing/lib/sync:sync_manager",
|
||||||
"//proto:sharing_enums_cc_proto",
|
"//proto:sharing_enums_cc_proto",
|
||||||
"//sharing/analytics",
|
"//sharing/analytics",
|
||||||
"//sharing/certificates",
|
"//sharing/certificates",
|
||||||
@@ -384,6 +386,7 @@ cc_library(
|
|||||||
"//internal/platform/implementation:types",
|
"//internal/platform/implementation:types",
|
||||||
"//location/nearby/sharing/lib/rpc:grpc_async_client_factory",
|
"//location/nearby/sharing/lib/rpc:grpc_async_client_factory",
|
||||||
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
|
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
|
||||||
|
"//location/nearby/sharing/lib/sync:sync_manager",
|
||||||
"//proto:sharing_enums_cc_proto",
|
"//proto:sharing_enums_cc_proto",
|
||||||
"//sharing/analytics",
|
"//sharing/analytics",
|
||||||
"//sharing/certificates",
|
"//sharing/certificates",
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "location/nearby/sharing/lib/sync/sync_config_prefs.pb.h"
|
||||||
|
#include "location/nearby/sharing/lib/sync/sync_manager.h"
|
||||||
#include "absl/container/flat_hash_map.h"
|
#include "absl/container/flat_hash_map.h"
|
||||||
#include "absl/functional/any_invocable.h"
|
#include "absl/functional/any_invocable.h"
|
||||||
#include "absl/time/time.h"
|
#include "absl/time/time.h"
|
||||||
@@ -38,7 +40,6 @@
|
|||||||
#include "sharing/nearby_connection.h"
|
#include "sharing/nearby_connection.h"
|
||||||
#include "sharing/nearby_connections_manager.h"
|
#include "sharing/nearby_connections_manager.h"
|
||||||
#include "sharing/nearby_connections_types.h"
|
#include "sharing/nearby_connections_types.h"
|
||||||
#include "sharing/paired_key_verification_runner.h"
|
|
||||||
#include "sharing/payload_tracker.h"
|
#include "sharing/payload_tracker.h"
|
||||||
#include "sharing/proto/wire_format.pb.h"
|
#include "sharing/proto/wire_format.pb.h"
|
||||||
#include "sharing/share_session.h"
|
#include "sharing/share_session.h"
|
||||||
@@ -56,9 +57,12 @@ using ::location::nearby::proto::sharing::OSType;
|
|||||||
using ::location::nearby::proto::sharing::ResponseToIntroduction;
|
using ::location::nearby::proto::sharing::ResponseToIntroduction;
|
||||||
using ::nearby::sharing::service::proto::AppMetadata;
|
using ::nearby::sharing::service::proto::AppMetadata;
|
||||||
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
||||||
|
using ::nearby::sharing::service::proto::Frame;
|
||||||
using ::nearby::sharing::service::proto::IntroductionFrame;
|
using ::nearby::sharing::service::proto::IntroductionFrame;
|
||||||
|
using ::nearby::sharing::service::proto::SyncConfig;
|
||||||
using ::nearby::sharing::service::proto::V1Frame;
|
using ::nearby::sharing::service::proto::V1Frame;
|
||||||
using ::nearby::sharing::service::proto::WifiCredentials;
|
using ::nearby::sharing::service::proto::WifiCredentials;
|
||||||
|
using ::nearby::sharing::sync::SyncConfigPrefs;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@@ -85,6 +89,7 @@ void IncomingShareSession::InvokeTransferUpdateCallback(
|
|||||||
std::optional<TransferMetadata::Status>
|
std::optional<TransferMetadata::Status>
|
||||||
IncomingShareSession::ProcessIntroduction(
|
IncomingShareSession::ProcessIntroduction(
|
||||||
const IntroductionFrame& introduction_frame) {
|
const IntroductionFrame& introduction_frame) {
|
||||||
|
session_phase_ = SessionPhase::kTransfer;
|
||||||
int64_t file_size_sum = 0;
|
int64_t file_size_sum = 0;
|
||||||
int app_file_count = 0;
|
int app_file_count = 0;
|
||||||
for (const AppMetadata& apk : introduction_frame.app_metadata()) {
|
for (const AppMetadata& apk : introduction_frame.app_metadata()) {
|
||||||
@@ -494,4 +499,43 @@ void IncomingShareSession::PushPayloadTransferUpdateForTest(
|
|||||||
payload_updates_queue()->Queue(std::move(update));
|
payload_updates_queue()->Queue(std::move(update));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncomingShareSession::ProcessSyncFrame(
|
||||||
|
SyncManager& sync_manager,
|
||||||
|
const nearby::sharing::service::proto::SyncFrame& sync_frame) {
|
||||||
|
if (session_phase_ != SessionPhase::kUninitialized) {
|
||||||
|
LOG(WARNING) << "Ignore SyncFrame received in unexpected session phase: "
|
||||||
|
<< static_cast<int>(session_phase_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: b/485304482 - Check that the connected device is authenticated and is
|
||||||
|
// part of a sync pairing.
|
||||||
|
if (!certificate().has_value()) {
|
||||||
|
LOG(WARNING) << "Ignore SyncFrame received from unauthenticated device.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (false &&
|
||||||
|
!sync_manager.IsFileSyncBinding(certificate()->binding_id())) {
|
||||||
|
LOG(WARNING) << "Ignore SyncFrame received in unexpected binding id: "
|
||||||
|
<< certificate()->binding_id();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session_phase_ = SessionPhase::kSync;
|
||||||
|
if (sync_frame.has_handshake()) {
|
||||||
|
VLOG(1) << __func__ << ": Received FileSync Handshake";
|
||||||
|
WriteSyncConfigFrame(
|
||||||
|
sync_manager.GetSyncConfig(certificate()->binding_id())
|
||||||
|
.value_or(SyncConfigPrefs())
|
||||||
|
.sync_config());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IncomingShareSession::WriteSyncConfigFrame(const SyncConfig& config) {
|
||||||
|
Frame frame;
|
||||||
|
frame.set_version(Frame::V1);
|
||||||
|
V1Frame* v1_frame = frame.mutable_v1();
|
||||||
|
v1_frame->set_type(V1Frame::FILE_SYNC);
|
||||||
|
*v1_frame->mutable_file_sync()->mutable_config() = config;
|
||||||
|
WriteFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nearby::sharing
|
} // namespace nearby::sharing
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "location/nearby/sharing/lib/sync/sync_manager.h"
|
||||||
#include "absl/functional/any_invocable.h"
|
#include "absl/functional/any_invocable.h"
|
||||||
#include "internal/base/file_path.h"
|
#include "internal/base/file_path.h"
|
||||||
#include "internal/platform/clock.h"
|
#include "internal/platform/clock.h"
|
||||||
@@ -29,7 +30,6 @@
|
|||||||
#include "sharing/nearby_connection.h"
|
#include "sharing/nearby_connection.h"
|
||||||
#include "sharing/nearby_connections_manager.h"
|
#include "sharing/nearby_connections_manager.h"
|
||||||
#include "sharing/nearby_connections_types.h"
|
#include "sharing/nearby_connections_types.h"
|
||||||
#include "sharing/paired_key_verification_runner.h"
|
|
||||||
#include "sharing/proto/wire_format.pb.h"
|
#include "sharing/proto/wire_format.pb.h"
|
||||||
#include "sharing/share_session.h"
|
#include "sharing/share_session.h"
|
||||||
#include "sharing/share_target.h"
|
#include "sharing/share_target.h"
|
||||||
@@ -104,10 +104,19 @@ class IncomingShareSession : public ShareSession {
|
|||||||
// Called when an incoming connection is established.
|
// Called when an incoming connection is established.
|
||||||
void OnConnected(NearbyConnection* connection);
|
void OnConnected(NearbyConnection* connection);
|
||||||
|
|
||||||
|
void ProcessSyncFrame(nearby::sharing::SyncManager& sync_manager,
|
||||||
|
const nearby::sharing::service::proto::SyncFrame& sync_frame);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InvokeTransferUpdateCallback(const TransferMetadata& metadata) override;
|
void InvokeTransferUpdateCallback(const TransferMetadata& metadata) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class SessionPhase {
|
||||||
|
kUninitialized,
|
||||||
|
kTransfer,
|
||||||
|
kSync,
|
||||||
|
};
|
||||||
|
|
||||||
// Update file attachment paths with payload paths.
|
// Update file attachment paths with payload paths.
|
||||||
bool UpdateFilePayloadPaths();
|
bool UpdateFilePayloadPaths();
|
||||||
|
|
||||||
@@ -119,6 +128,9 @@ class IncomingShareSession : public ShareSession {
|
|||||||
// Returns true if all payloads were successfully finalized.
|
// Returns true if all payloads were successfully finalized.
|
||||||
bool FinalizePayloads();
|
bool FinalizePayloads();
|
||||||
|
|
||||||
|
void WriteSyncConfigFrame(
|
||||||
|
const nearby::sharing::service::proto::SyncConfig& config);
|
||||||
|
|
||||||
std::function<void(const IncomingShareSession&, const TransferMetadata&)>
|
std::function<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||||
transfer_update_callback_;
|
transfer_update_callback_;
|
||||||
|
|
||||||
@@ -127,6 +139,8 @@ class IncomingShareSession : public ShareSession {
|
|||||||
// This alarm is used to disconnect the sharing connection if both sides do
|
// This alarm is used to disconnect the sharing connection if both sides do
|
||||||
// not press accept within the timeout.
|
// not press accept within the timeout.
|
||||||
std::unique_ptr<ThreadTimer> mutual_acceptance_timeout_;
|
std::unique_ptr<ThreadTimer> mutual_acceptance_timeout_;
|
||||||
|
|
||||||
|
SessionPhase session_phase_ = SessionPhase::kUninitialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nearby::sharing
|
} // namespace nearby::sharing
|
||||||
|
|||||||
@@ -273,7 +273,8 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
|||||||
absl::bind_front(&NearbySharingServiceImpl::NotifyShareTargetLost,
|
absl::bind_front(&NearbySharingServiceImpl::NotifyShareTargetLost,
|
||||||
this),
|
this),
|
||||||
absl::bind_front(&NearbySharingServiceImpl::OnOutgoingTransferUpdate,
|
absl::bind_front(&NearbySharingServiceImpl::OnOutgoingTransferUpdate,
|
||||||
this)) {
|
this)),
|
||||||
|
sync_manager_(&preference_manager_) {
|
||||||
CHECK(nearby_connections_manager_);
|
CHECK(nearby_connections_manager_);
|
||||||
CHECK(analytics_recorder);
|
CHECK(analytics_recorder);
|
||||||
|
|
||||||
@@ -2479,6 +2480,12 @@ void NearbySharingServiceImpl::OnIncomingSessionFrameRead(
|
|||||||
OnReceivedIntroduction(*session, frame->introduction());
|
OnReceivedIntroduction(*session, frame->introduction());
|
||||||
// OnReceivedIntroduction will schedule the next ReadFrame.
|
// OnReceivedIntroduction will schedule the next ReadFrame.
|
||||||
return;
|
return;
|
||||||
|
case service::proto::V1Frame::FILE_SYNC:
|
||||||
|
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||||
|
config_package_nearby::nearby_sharing_feature::kEnableFileSync)) {
|
||||||
|
session->ProcessSyncFrame(sync_manager_, frame->file_sync());
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LOG(ERROR) << __func__ << ": Discarding unknown frame of type: "
|
LOG(ERROR) << __func__ << ": Discarding unknown frame of type: "
|
||||||
<< static_cast<int>(frame->type());
|
<< static_cast<int>(frame->type());
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
|
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
|
||||||
|
#include "location/nearby/sharing/lib/sync/sync_manager.h"
|
||||||
#include "absl/base/nullability.h"
|
#include "absl/base/nullability.h"
|
||||||
#include "absl/container/flat_hash_map.h"
|
#include "absl/container/flat_hash_map.h"
|
||||||
#include "absl/container/flat_hash_set.h"
|
#include "absl/container/flat_hash_set.h"
|
||||||
@@ -529,6 +530,7 @@ class NearbySharingServiceImpl
|
|||||||
// If true, a new endpoint id will be generated at the next advertisement.
|
// If true, a new endpoint id will be generated at the next advertisement.
|
||||||
bool force_new_endpoint_id_ = false;
|
bool force_new_endpoint_id_ = false;
|
||||||
OutgoingTargetsManager outgoing_targets_manager_;
|
OutgoingTargetsManager outgoing_targets_manager_;
|
||||||
|
nearby::sharing::SyncManager sync_manager_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nearby::sharing
|
} // namespace nearby::sharing
|
||||||
|
|||||||
Reference in New Issue
Block a user