Back to Site
Loading...
Searching...
No Matches
librats::FileTransferManager Class Reference

File transfer manager class Handles efficient chunked file transfers with resume capability. More...

#include <file_transfer.h>

Public Member Functions

 FileTransferManager (RatsClient &client, const FileTransferConfig &config=FileTransferConfig())
 Constructor.
 
 ~FileTransferManager ()
 Destructor.
 
void set_config (const FileTransferConfig &config)
 Update transfer configuration.
 
const FileTransferConfigget_config () const
 Get current configuration.
 
bool handle_binary_data (const std::string &peer_id, const std::vector< uint8_t > &binary_data)
 Handle binary data that might be file transfer chunks.
 
void set_progress_callback (FileTransferProgressCallback callback)
 Set progress callback for transfer updates.
 
void set_completion_callback (FileTransferCompletedCallback callback)
 Set completion callback for transfer completion.
 
void set_request_callback (FileTransferRequestCallback callback)
 Set incoming transfer request callback.
 
void set_directory_progress_callback (DirectoryTransferProgressCallback callback)
 Set directory transfer progress callback.
 
void set_file_request_callback (FileRequestCallback callback)
 Set file request callback (called when receiving file requests)
 
void set_directory_request_callback (DirectoryRequestCallback callback)
 Set directory request callback (called when receiving directory requests)
 
std::string send_file (const std::string &peer_id, const std::string &file_path, const std::string &remote_filename="")
 Send a file to a peer.
 
std::string send_file_with_metadata (const std::string &peer_id, const std::string &file_path, const FileMetadata &metadata)
 Send a file with custom metadata.
 
std::string send_directory (const std::string &peer_id, const std::string &directory_path, const std::string &remote_directory_name="", bool recursive=true)
 Send an entire directory to a peer.
 
std::string request_file (const std::string &peer_id, const std::string &remote_file_path, const std::string &local_path)
 Request a file from a remote peer.
 
std::string request_directory (const std::string &peer_id, const std::string &remote_directory_path, const std::string &local_directory_path, bool recursive=true)
 Request a directory from a remote peer.
 
bool accept_file_transfer (const std::string &transfer_id, const std::string &local_path)
 Accept an incoming file transfer.
 
bool reject_file_transfer (const std::string &transfer_id, const std::string &reason="")
 Reject an incoming file transfer.
 
bool accept_directory_transfer (const std::string &transfer_id, const std::string &local_path)
 Accept an incoming directory transfer.
 
bool reject_directory_transfer (const std::string &transfer_id, const std::string &reason="")
 Reject an incoming directory transfer.
 
bool pause_transfer (const std::string &transfer_id)
 Pause an active transfer.
 
bool resume_transfer (const std::string &transfer_id)
 Resume a paused transfer.
 
bool cancel_transfer (const std::string &transfer_id)
 Cancel an active or paused transfer.
 
bool retry_transfer (const std::string &transfer_id)
 Retry a failed transfer.
 
std::shared_ptr< FileTransferProgressget_transfer_progress (const std::string &transfer_id) const
 Get progress information for a transfer.
 
std::vector< std::shared_ptr< FileTransferProgress > > get_active_transfers () const
 Get all active transfers.
 
std::vector< std::shared_ptr< FileTransferProgress > > get_transfer_history (size_t limit=0) const
 Get transfer history.
 
void clear_transfer_history ()
 Clear transfer history.
 
nlohmann::json get_transfer_statistics () const
 Get statistics about transfers.
 

Static Public Member Functions

static std::string calculate_file_checksum (const std::string &file_path, const std::string &algorithm="sha256")
 Calculate file checksum.
 
static FileMetadata get_file_metadata (const std::string &file_path)
 Get file metadata.
 
static DirectoryMetadata get_directory_metadata (const std::string &directory_path, bool recursive=true)
 Get directory metadata.
 
static bool validate_file_path (const std::string &file_path, bool check_write=false)
 Validate file path and permissions.
 

Detailed Description

File transfer manager class Handles efficient chunked file transfers with resume capability.

Definition at line 185 of file file_transfer.h.

Constructor & Destructor Documentation

◆ FileTransferManager()

librats::FileTransferManager::FileTransferManager ( RatsClient client,
const FileTransferConfig config = FileTransferConfig() 
)

Constructor.

Parameters
clientReference to RatsClient for communication
configTransfer configuration settings

◆ ~FileTransferManager()

librats::FileTransferManager::~FileTransferManager ( )

Destructor.

Member Function Documentation

◆ accept_directory_transfer()

bool librats::FileTransferManager::accept_directory_transfer ( const std::string &  transfer_id,
const std::string &  local_path 
)

Accept an incoming directory transfer.

Parameters
transfer_idTransfer identifier from request
local_pathLocal path where directory should be saved
Returns
true if accepted successfully

◆ accept_file_transfer()

bool librats::FileTransferManager::accept_file_transfer ( const std::string &  transfer_id,
const std::string &  local_path 
)

Accept an incoming file transfer.

Parameters
transfer_idTransfer identifier from request
local_pathLocal path where file should be saved
Returns
true if accepted successfully

◆ calculate_file_checksum()

static std::string librats::FileTransferManager::calculate_file_checksum ( const std::string &  file_path,
const std::string &  algorithm = "sha256" 
)
static

Calculate file checksum.

Parameters
file_pathPath to file
algorithmHash algorithm ("md5", "sha256")
Returns
Checksum string or empty if failed

◆ cancel_transfer()

bool librats::FileTransferManager::cancel_transfer ( const std::string &  transfer_id)

Cancel an active or paused transfer.

Parameters
transfer_idTransfer to cancel
Returns
true if cancelled successfully

◆ clear_transfer_history()

void librats::FileTransferManager::clear_transfer_history ( )

Clear transfer history.

◆ get_active_transfers()

std::vector< std::shared_ptr< FileTransferProgress > > librats::FileTransferManager::get_active_transfers ( ) const

Get all active transfers.

Returns
Vector of transfer progress objects

◆ get_config()

const FileTransferConfig & librats::FileTransferManager::get_config ( ) const

Get current configuration.

Returns
Current configuration settings

◆ get_directory_metadata()

static DirectoryMetadata librats::FileTransferManager::get_directory_metadata ( const std::string &  directory_path,
bool  recursive = true 
)
static

Get directory metadata.

Parameters
directory_pathPath to directory
recursiveWhether to scan recursively
Returns
Directory metadata structure

◆ get_file_metadata()

static FileMetadata librats::FileTransferManager::get_file_metadata ( const std::string &  file_path)
static

Get file metadata.

Parameters
file_pathPath to file
Returns
File metadata structure

◆ get_transfer_history()

std::vector< std::shared_ptr< FileTransferProgress > > librats::FileTransferManager::get_transfer_history ( size_t  limit = 0) const

Get transfer history.

Parameters
limitMaximum number of entries to return (0 for all)
Returns
Vector of completed transfer progress objects

◆ get_transfer_progress()

std::shared_ptr< FileTransferProgress > librats::FileTransferManager::get_transfer_progress ( const std::string &  transfer_id) const

Get progress information for a transfer.

Parameters
transfer_idTransfer to query
Returns
Progress information or nullptr if not found

◆ get_transfer_statistics()

nlohmann::json librats::FileTransferManager::get_transfer_statistics ( ) const

Get statistics about transfers.

Returns
JSON object with transfer statistics

◆ handle_binary_data()

bool librats::FileTransferManager::handle_binary_data ( const std::string &  peer_id,
const std::vector< uint8_t > &  binary_data 
)

Handle binary data that might be file transfer chunks.

Parameters
peer_idSource peer ID
binary_dataBinary data received
Returns
true if this was a file transfer chunk, false otherwise

◆ pause_transfer()

bool librats::FileTransferManager::pause_transfer ( const std::string &  transfer_id)

Pause an active transfer.

Parameters
transfer_idTransfer to pause
Returns
true if paused successfully

◆ reject_directory_transfer()

bool librats::FileTransferManager::reject_directory_transfer ( const std::string &  transfer_id,
const std::string &  reason = "" 
)

Reject an incoming directory transfer.

Parameters
transfer_idTransfer identifier from request
reasonOptional reason for rejection
Returns
true if rejected successfully

◆ reject_file_transfer()

bool librats::FileTransferManager::reject_file_transfer ( const std::string &  transfer_id,
const std::string &  reason = "" 
)

Reject an incoming file transfer.

Parameters
transfer_idTransfer identifier from request
reasonOptional reason for rejection
Returns
true if rejected successfully

◆ request_directory()

std::string librats::FileTransferManager::request_directory ( const std::string &  peer_id,
const std::string &  remote_directory_path,
const std::string &  local_directory_path,
bool  recursive = true 
)

Request a directory from a remote peer.

Parameters
peer_idTarget peer ID
remote_directory_pathPath to directory on remote peer
local_directory_pathLocal path where directory should be saved
recursiveWhether to include subdirectories (default: true)
Returns
Transfer ID if successful, empty string if failed

◆ request_file()

std::string librats::FileTransferManager::request_file ( const std::string &  peer_id,
const std::string &  remote_file_path,
const std::string &  local_path 
)

Request a file from a remote peer.

Parameters
peer_idTarget peer ID
remote_file_pathPath to file on remote peer
local_pathLocal path where file should be saved
Returns
Transfer ID if successful, empty string if failed

◆ resume_transfer()

bool librats::FileTransferManager::resume_transfer ( const std::string &  transfer_id)

Resume a paused transfer.

Parameters
transfer_idTransfer to resume
Returns
true if resumed successfully

◆ retry_transfer()

bool librats::FileTransferManager::retry_transfer ( const std::string &  transfer_id)

Retry a failed transfer.

Parameters
transfer_idTransfer to retry
Returns
true if retry initiated successfully

◆ send_directory()

std::string librats::FileTransferManager::send_directory ( const std::string &  peer_id,
const std::string &  directory_path,
const std::string &  remote_directory_name = "",
bool  recursive = true 
)

Send an entire directory to a peer.

Parameters
peer_idTarget peer ID
directory_pathLocal directory path to send
remote_directory_nameOptional remote directory name
recursiveWhether to include subdirectories (default: true)
Returns
Transfer ID if successful, empty string if failed

◆ send_file()

std::string librats::FileTransferManager::send_file ( const std::string &  peer_id,
const std::string &  file_path,
const std::string &  remote_filename = "" 
)

Send a file to a peer.

Parameters
peer_idTarget peer ID
file_pathLocal file path to send
remote_filenameOptional remote filename (default: use local name)
Returns
Transfer ID if successful, empty string if failed

◆ send_file_with_metadata()

std::string librats::FileTransferManager::send_file_with_metadata ( const std::string &  peer_id,
const std::string &  file_path,
const FileMetadata metadata 
)

Send a file with custom metadata.

Parameters
peer_idTarget peer ID
file_pathLocal file path to send
metadataCustom file metadata
Returns
Transfer ID if successful, empty string if failed

◆ set_completion_callback()

void librats::FileTransferManager::set_completion_callback ( FileTransferCompletedCallback  callback)

Set completion callback for transfer completion.

Parameters
callbackFunction to call when transfers complete

◆ set_config()

void librats::FileTransferManager::set_config ( const FileTransferConfig config)

Update transfer configuration.

Parameters
configNew configuration settings

◆ set_directory_progress_callback()

void librats::FileTransferManager::set_directory_progress_callback ( DirectoryTransferProgressCallback  callback)

Set directory transfer progress callback.

Parameters
callbackFunction to call with directory transfer progress

◆ set_directory_request_callback()

void librats::FileTransferManager::set_directory_request_callback ( DirectoryRequestCallback  callback)

Set directory request callback (called when receiving directory requests)

Parameters
callbackFunction to call when receiving directory requests

◆ set_file_request_callback()

void librats::FileTransferManager::set_file_request_callback ( FileRequestCallback  callback)

Set file request callback (called when receiving file requests)

Parameters
callbackFunction to call when receiving file requests

◆ set_progress_callback()

void librats::FileTransferManager::set_progress_callback ( FileTransferProgressCallback  callback)

Set progress callback for transfer updates.

Parameters
callbackFunction to call with progress updates

◆ set_request_callback()

void librats::FileTransferManager::set_request_callback ( FileTransferRequestCallback  callback)

Set incoming transfer request callback.

Parameters
callbackFunction to call when receiving transfer requests

◆ validate_file_path()

static bool librats::FileTransferManager::validate_file_path ( const std::string &  file_path,
bool  check_write = false 
)
static

Validate file path and permissions.

Parameters
file_pathPath to validate
check_writeWhether to check write permissions
Returns
true if valid and accessible

The documentation for this class was generated from the following file: