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

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> Freeze for FileTransfer<'a, N>

§

impl<'a, N> !RefUnwindSafe 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>

§

impl<'a, N> !UnwindSafe 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