Skip to main content

FileTransfer

Struct FileTransfer 

Source
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>

Source

pub fn subscribe(&self) -> Receiver<FileTransferEvent>

Subscribe to file transfer events.

Returns a broadcast receiver that yields FileTransferEvents. Multiple subscribers are supported.

Source

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.

Source

pub fn max_transfer_size(&self) -> u64

Get the current maximum transfer size in bytes.

Source

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.

Source

pub fn overwrite_policy(&self) -> OverwritePolicy

Get the current overwrite policy.

Source

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.

Source

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).

Source

pub fn clear_pull_roots(&self)

Remove all registered pull roots, disabling pull serving entirely (returns to the deny-by-default state).

Source

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.

Source

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}.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, N> !RefUnwindSafe for FileTransfer<'a, N>

§

impl<'a, N> !UnwindSafe for FileTransfer<'a, N>

§

impl<'a, N> Freeze for FileTransfer<'a, N>

§

impl<'a, N> Send for FileTransfer<'a, N>

§

impl<'a, N> Sync for FileTransfer<'a, N>

§

impl<'a, N> Unpin for FileTransfer<'a, N>

§

impl<'a, N> UnsafeUnpin for FileTransfer<'a, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more