Initial project snapshot
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rdp_worker/dataplane/token_validator.hpp"
|
||||
#include "rdp_worker/runtime/models.hpp"
|
||||
|
||||
namespace rdp_worker::runtime {
|
||||
|
||||
struct DirectBindValidationResult {
|
||||
bool ok{false};
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
DirectBindValidationResult ValidateDirectDataPlaneBind(const Assignment& assignment,
|
||||
const dataplane::DataPlaneTokenClaims& claims);
|
||||
|
||||
} // namespace rdp_worker::runtime
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rdp_worker/runtime/models.hpp"
|
||||
|
||||
namespace rdp_worker::runtime {
|
||||
|
||||
class DirectEventSink {
|
||||
public:
|
||||
virtual ~DirectEventSink() = default;
|
||||
virtual std::string AttachmentId() const = 0;
|
||||
virtual void EnqueueEvent(const WorkerEvent& event) = 0;
|
||||
};
|
||||
|
||||
} // namespace rdp_worker::runtime
|
||||
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rdp_worker/common/json.hpp"
|
||||
|
||||
namespace rdp_worker::runtime {
|
||||
|
||||
enum class SessionState {
|
||||
kStarting,
|
||||
kActive,
|
||||
kDetached,
|
||||
kReconnecting,
|
||||
kTerminated,
|
||||
kFailed
|
||||
};
|
||||
|
||||
struct ConnectionSpec {
|
||||
std::string resource_id;
|
||||
std::string resource_name;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string domain;
|
||||
std::string certificate_verification_mode{"strict"};
|
||||
std::string render_quality_profile{"balanced"};
|
||||
std::string redirected_drive_name;
|
||||
std::string redirected_drive_path;
|
||||
bool insecure_skip_verify{false};
|
||||
};
|
||||
|
||||
struct SessionPolicy {
|
||||
std::chrono::seconds detach_grace_period{1800};
|
||||
std::string clipboard_mode{"disabled"};
|
||||
std::string file_transfer_mode{"disabled"};
|
||||
};
|
||||
|
||||
struct Assignment {
|
||||
std::string session_id;
|
||||
std::string worker_id;
|
||||
std::string attachment_id;
|
||||
std::string user_id;
|
||||
std::string organization_id;
|
||||
std::string device_id;
|
||||
std::optional<std::string> takeover_of;
|
||||
SessionState state{SessionState::kStarting};
|
||||
ConnectionSpec connection;
|
||||
SessionPolicy policy;
|
||||
};
|
||||
|
||||
struct WorkerLease {
|
||||
std::string lease_id;
|
||||
std::string worker_id;
|
||||
std::string session_id;
|
||||
std::string resource_id;
|
||||
std::string control_stream;
|
||||
std::vector<std::string> capabilities;
|
||||
std::string expires_at;
|
||||
};
|
||||
|
||||
struct WorkerEvent {
|
||||
std::string type;
|
||||
std::string session_id;
|
||||
std::string worker_id;
|
||||
std::string reason;
|
||||
int width{0};
|
||||
int height{0};
|
||||
common::JsonObject payload;
|
||||
std::vector<std::uint8_t> raw_frame_bytes;
|
||||
};
|
||||
|
||||
struct RenderNotification {
|
||||
std::string type;
|
||||
common::JsonObject payload;
|
||||
std::vector<std::uint8_t> raw_frame_bytes;
|
||||
};
|
||||
|
||||
struct ClipboardNotification {
|
||||
std::string text;
|
||||
std::string origin;
|
||||
std::string content_hash;
|
||||
std::uint64_t sequence_id{0};
|
||||
};
|
||||
|
||||
} // namespace rdp_worker::runtime
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "rdp_worker/common/logger.hpp"
|
||||
#include "rdp_worker/coordination/control_plane.hpp"
|
||||
#include "rdp_worker/dataplane/token_validator.hpp"
|
||||
#include "rdp_worker/runtime/models.hpp"
|
||||
#include "rdp_worker/runtime/session_runtime.hpp"
|
||||
|
||||
namespace rdp_worker::runtime {
|
||||
|
||||
class SessionManager {
|
||||
public:
|
||||
SessionManager(std::shared_ptr<coordination::ControlPlane> control_plane,
|
||||
std::shared_ptr<common::Logger> logger);
|
||||
|
||||
void ApplyAssignment(const Assignment& assignment);
|
||||
void StopAll();
|
||||
bool BindDirectDataPlaneAttachment(const dataplane::DataPlaneTokenClaims& claims, std::string& reason);
|
||||
std::shared_ptr<SessionRuntime> BindDirectDataPlaneRuntime(const dataplane::DataPlaneTokenClaims& claims, std::string& reason);
|
||||
|
||||
private:
|
||||
std::shared_ptr<coordination::ControlPlane> control_plane_;
|
||||
std::shared_ptr<common::Logger> logger_;
|
||||
std::mutex mutex_;
|
||||
std::map<std::string, std::shared_ptr<SessionRuntime>> sessions_;
|
||||
};
|
||||
|
||||
} // namespace rdp_worker::runtime
|
||||
@@ -0,0 +1,134 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "rdp_worker/adapter/rdp_adapter_runtime.hpp"
|
||||
#include "rdp_worker/coordination/control_plane.hpp"
|
||||
#include "rdp_worker/runtime/direct_event_sink.hpp"
|
||||
#include "rdp_worker/runtime/models.hpp"
|
||||
|
||||
namespace rdp_worker::common {
|
||||
class Logger;
|
||||
}
|
||||
|
||||
namespace rdp_worker::runtime {
|
||||
|
||||
class SessionRuntime {
|
||||
public:
|
||||
SessionRuntime(Assignment assignment,
|
||||
std::shared_ptr<coordination::ControlPlane> control_plane,
|
||||
std::shared_ptr<common::Logger> logger);
|
||||
~SessionRuntime();
|
||||
|
||||
void Start();
|
||||
void ApplyAssignment(const Assignment& assignment);
|
||||
void Stop(bool terminate, const std::string& reason);
|
||||
std::string SessionId() const;
|
||||
Assignment Snapshot() const;
|
||||
bool EnqueueDirectEnvelope(common::JsonObject envelope);
|
||||
void AddDirectEventSink(std::weak_ptr<DirectEventSink> sink);
|
||||
void RequestDirectFullFrameRepair(std::string reason);
|
||||
|
||||
private:
|
||||
void Run();
|
||||
void DrainAndHandleEnvelopes(const std::string& session_id);
|
||||
std::vector<common::JsonObject> DrainDirectEnvelopes(std::size_t max_count);
|
||||
void HandleEnvelopeBatch(const std::vector<common::JsonObject>& envelopes);
|
||||
void HandleEnvelope(const common::JsonObject& envelope);
|
||||
void HandleFileUpload(const common::JsonObject& payload);
|
||||
void HandleFileDownload(const common::JsonObject& payload);
|
||||
void ScanOutboundDownloadDirectory(const std::string& session_id);
|
||||
void PublishFileDownloadBlocked(const std::string& transfer_id, const std::string& file_id, const std::string& reason);
|
||||
std::filesystem::path PrepareVisibleTransferDirectory(const std::string& session_id);
|
||||
void CleanupVisibleTransferDirectory(const std::string& session_id);
|
||||
void CleanupSessionTransferDirectory(const std::string& session_id);
|
||||
void PublishDirectAttachBaselineIfRequested(const std::string& session_id);
|
||||
void DrainAndPublishRenderNotifications(const std::string& session_id);
|
||||
void PublishEvent(const std::string& type, const std::string& reason = {});
|
||||
void PublishEvent(const std::string& type, const std::string& reason, common::JsonObject payload);
|
||||
void DispatchDirectEvent(const WorkerEvent& event);
|
||||
bool HasCurrentDirectEventSink();
|
||||
|
||||
struct FileUploadState {
|
||||
std::string transfer_id;
|
||||
std::string file_name;
|
||||
std::filesystem::path temp_path;
|
||||
std::filesystem::path final_path;
|
||||
std::int64_t file_size{0};
|
||||
std::int64_t total_chunks{0};
|
||||
std::int64_t received{0};
|
||||
std::int64_t next_index{0};
|
||||
std::uint64_t hash{1469598103934665603ULL};
|
||||
std::string expected_hash;
|
||||
};
|
||||
|
||||
struct FileDownloadCandidate {
|
||||
std::string file_id;
|
||||
std::string file_name;
|
||||
std::filesystem::path path;
|
||||
std::filesystem::file_time_type modified_at{};
|
||||
std::int64_t file_size{0};
|
||||
std::uint64_t content_hash_value{1469598103934665603ULL};
|
||||
std::string content_hash;
|
||||
std::int64_t last_observed_size{-1};
|
||||
std::filesystem::file_time_type last_observed_modified_at{};
|
||||
int stable_observations{0};
|
||||
bool available_published{false};
|
||||
};
|
||||
|
||||
struct FileDownloadState {
|
||||
std::string transfer_id;
|
||||
std::string file_id;
|
||||
std::string file_name;
|
||||
std::filesystem::path path;
|
||||
std::filesystem::file_time_type modified_at{};
|
||||
std::int64_t file_size{0};
|
||||
std::int64_t sent{0};
|
||||
std::int64_t next_sequence{0};
|
||||
std::string content_hash;
|
||||
bool active{false};
|
||||
};
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
Assignment assignment_;
|
||||
std::shared_ptr<coordination::ControlPlane> control_plane_;
|
||||
std::shared_ptr<common::Logger> logger_;
|
||||
adapter::RdpAdapterRuntime rdp_adapter_;
|
||||
std::thread thread_;
|
||||
std::atomic<bool> stop_requested_;
|
||||
std::atomic<bool> attached_;
|
||||
std::atomic<bool> direct_attach_baseline_requested_{false};
|
||||
bool focus_forward_logged_{false};
|
||||
bool keyboard_forward_logged_{false};
|
||||
bool mouse_forward_logged_{false};
|
||||
std::string last_input_correlation_id_;
|
||||
std::chrono::steady_clock::time_point last_input_applied_at_{};
|
||||
std::deque<RenderNotification> pending_render_frames_;
|
||||
std::optional<WorkerEvent> last_direct_render_frame_;
|
||||
bool direct_full_repair_requested_{false};
|
||||
std::string direct_full_repair_reason_;
|
||||
std::chrono::steady_clock::time_point last_frame_published_at_{};
|
||||
std::chrono::steady_clock::time_point last_region_loss_full_repair_at_{};
|
||||
std::chrono::steady_clock::time_point last_render_rate_logged_at_{};
|
||||
std::size_t render_frames_seen_since_log_{0};
|
||||
std::size_t render_frames_published_since_log_{0};
|
||||
std::size_t render_frames_dropped_since_log_{0};
|
||||
std::unordered_map<std::string, FileUploadState> uploads_;
|
||||
std::unordered_map<std::string, FileDownloadCandidate> download_candidates_;
|
||||
std::unordered_map<std::string, FileDownloadState> downloads_;
|
||||
std::chrono::steady_clock::time_point last_download_scan_at_{};
|
||||
std::int64_t file_download_event_sequence_{0};
|
||||
std::deque<common::JsonObject> direct_envelopes_;
|
||||
std::vector<std::weak_ptr<DirectEventSink>> direct_event_sinks_;
|
||||
};
|
||||
|
||||
} // namespace rdp_worker::runtime
|
||||
Reference in New Issue
Block a user