pub struct FileTransfer<'a, N: NetworkProvider + 'static> { /* private fields */ }Expand description
File transfer handle — the public API for file transfers.
This is a borrowed reference to a Node that provides file transfer
operations. Obtained via Node::file_transfer().
Generic over N: NetworkProvider to match the Node it wraps.
Implementations§
Source§impl<'a, N: NetworkProvider + 'static> FileTransfer<'a, N>
impl<'a, N: NetworkProvider + 'static> FileTransfer<'a, N>
Sourcepub fn subscribe(&self) -> Receiver<FileTransferEvent>
pub fn subscribe(&self) -> Receiver<FileTransferEvent>
Subscribe to file transfer events.
Returns a broadcast receiver that yields FileTransferEvents.
Multiple subscribers are supported.
Sourcepub fn set_max_transfer_size(&self, bytes: u64)
pub fn set_max_transfer_size(&self, bytes: u64)
Set the maximum allowed transfer size in bytes.
Transfers exceeding this size will be rejected. Default is 1 GB.
Sourcepub fn max_transfer_size(&self) -> u64
pub fn max_transfer_size(&self) -> u64
Get the current maximum transfer size in bytes.
Sourcepub fn set_overwrite_policy(&self, policy: OverwritePolicy)
pub fn set_overwrite_policy(&self, policy: OverwritePolicy)
Set the policy for destinations that already exist.
Default is OverwritePolicy::Reject: a transfer to an existing
path fails instead of silently replacing the file.
Sourcepub fn overwrite_policy(&self) -> OverwritePolicy
pub fn overwrite_policy(&self) -> OverwritePolicy
Get the current overwrite policy.
Sourcepub fn add_pull_root(&self, root: &str) -> Result<()>
pub fn add_pull_root(&self, root: &str) -> Result<()>
Register a directory that incoming PULL_REQUESTs may be served from.
Pull serving is deny-by-default: with no roots registered every
incoming PULL_REQUEST is rejected. The root is canonicalized at
registration time (so it must already exist, and symlinked roots
compare correctly against canonicalized request paths); a requested
file is only served if its canonical path lives inside one of these
roots.
Sourcepub fn pull_roots(&self) -> Vec<PathBuf>
pub fn pull_roots(&self) -> Vec<PathBuf>
Return the currently registered (canonicalized) pull roots.
An empty list means pull serving is disabled (deny-by-default).
Sourcepub fn clear_pull_roots(&self)
pub fn clear_pull_roots(&self)
Remove all registered pull roots, disabling pull serving entirely (returns to the deny-by-default state).
Sourcepub async fn offer_channel(
&self,
node: Arc<Node<N>>,
) -> Receiver<(FileOffer, OfferResponder)>
pub async fn offer_channel( &self, node: Arc<Node<N>>, ) -> Receiver<(FileOffer, OfferResponder)>
Get a channel for receiving incoming file offers.
Each offer comes with an OfferResponder that must be used to
accept or reject the transfer. Calling this starts the background
receiver listener (lazy start, idempotent).
Only one offer channel can be active at a time. Calling this again replaces the previous channel (the old receiver will stop getting offers).
The channel is bounded: when the application stops polling and the queue fills, further incoming offers are rejected (the sender gets a fail-fast REJECT) rather than buffered without limit.
Important: The returned receiver must be polled. The node reference
used here must remain valid — store the Node in an Arc and pass it
to spawned tasks as needed.
Sourcepub async fn auto_accept(&self, node: Arc<Node<N>>, output_dir: &str)
pub async fn auto_accept(&self, node: Arc<Node<N>>, output_dir: &str)
Convenience: auto-accept all incoming offers, saving files to
output_dir.
This starts the receiver listener (lazy start) and spawns a task
that automatically accepts every offer with the save path set to
{output_dir}/{file_name}.
Sourcepub async fn auto_reject(&self, node: Arc<Node<N>>)
pub async fn auto_reject(&self, node: Arc<Node<N>>)
Convenience: auto-reject all incoming offers.
This starts the receiver listener (lazy start) and spawns a task that automatically rejects every offer.
Sourcepub async fn send_file(
&self,
peer_id: &str,
local_path: &str,
remote_path: &str,
) -> Result<TransferResult, TransferError>
pub async fn send_file( &self, peer_id: &str, local_path: &str, remote_path: &str, ) -> Result<TransferResult, TransferError>
Send a file to a peer.
Hashes the local file, sends an OFFER via the "ft" namespace,
waits for ACCEPT, then streams the file over TCP.
§Errors
Returns TransferError on I/O failure, rejection, timeout, or
integrity check failure.
Sourcepub async fn pull_file(
&self,
peer_id: &str,
remote_path: &str,
local_path: &str,
) -> Result<TransferResult, TransferError>
pub async fn pull_file( &self, peer_id: &str, remote_path: &str, local_path: &str, ) -> Result<TransferResult, TransferError>
Pull a file from a remote peer.
Sends a PULL_REQUEST, waits for the peer’s OFFER, accepts it, then receives the file over TCP.
§Errors
Returns TransferError on I/O failure, rejection, timeout, or
integrity check failure.