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 async fn offer_channel(
&self,
node: Arc<Node<N>>,
) -> UnboundedReceiver<(FileOffer, OfferResponder)>
pub async fn offer_channel( &self, node: Arc<Node<N>>, ) -> UnboundedReceiver<(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).
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.