GoshTransferEngine

Struct GoshTransferEngine 

Source
pub struct GoshTransferEngine { /* private fields */ }
Expand description

The main engine that coordinates all file transfer operations

This is the primary interface for using the library. It manages:

  • The HTTP server for receiving files
  • The HTTP client for sending files
  • Configuration and state

Implementations§

Source§

impl GoshTransferEngine

Source

pub fn new(config: EngineConfig, event_handler: Arc<dyn EventHandler>) -> Self

Create a new engine with the given configuration and event handler

Source

pub fn with_history( config: EngineConfig, event_handler: Arc<dyn EventHandler>, history: Arc<dyn HistoryPersistence>, ) -> Self

Create a new engine with the given configuration, event handler, and history persistence

The history will automatically record completed and failed transfers.

Source

pub fn with_channel_events( config: EngineConfig, ) -> (Self, Receiver<EngineEvent>)

Create a new engine with a channel-based event handler

This is a convenience constructor that returns both the engine and a receiver for events.

Source

pub fn with_channel_events_and_history( config: EngineConfig, history: Arc<dyn HistoryPersistence>, ) -> (Self, Receiver<EngineEvent>)

Create a new engine with a channel-based event handler and history persistence

This is a convenience constructor that returns both the engine and a receiver for events.

Source

pub fn history(&self) -> Option<&Arc<dyn HistoryPersistence>>

Get the history persistence (if configured)

Source

pub async fn start_server(&mut self) -> EngineResult<()>

Start the HTTP server for receiving files

The server binds to all interfaces (0.0.0.0) on the configured port. Returns a handle that can be used to stop the server.

Source

pub async fn stop_server(&mut self) -> EngineResult<()>

Stop the HTTP server

Source

pub fn is_server_running(&self) -> bool

Check if the server is running

Source

pub fn server_state(&self) -> &Arc<ServerState>

Get the server state for advanced operations

Source

pub fn port(&self) -> u16

Get the current server port

Source

pub async fn change_port(&mut self, new_port: u16) -> EngineResult<()>

Change the server port at runtime

This will gracefully stop the current server, bind to the new port, and emit appropriate events. If binding to the new port fails, it will attempt to restore the previous port.

§Arguments
  • new_port - The new port to bind to
§Errors
  • EngineError::InvalidConfig if the port is invalid (e.g., port 0)
  • EngineError::Network if binding to the new port fails
Source

pub async fn change_port_with_options( &mut self, new_port: u16, rollback_on_failure: bool, ) -> EngineResult<()>

Change the server port with configurable rollback behavior

§Arguments
  • new_port - The new port to bind to
  • rollback_on_failure - If true, attempt to restore the old port if new binding fails
§Behavior
  1. Validates the new port
  2. If server is running, stops it gracefully
  3. Attempts to bind to the new port
  4. On success: updates config, emits PortChanged and ServerStarted events
  5. On failure with rollback: attempts to restore old port
  6. On failure without rollback: leaves server stopped
Source

pub async fn send_files( &self, address: &str, port: u16, file_paths: Vec<PathBuf>, ) -> EngineResult<()>

Send files to a peer

This will:

  1. Request permission from the peer
  2. Wait for approval (or auto-accept if trusted)
  3. Stream the files to the peer
  4. Emit progress events during transfer
Source

pub async fn send_directory( &self, address: &str, port: u16, dir_path: impl AsRef<Path>, ) -> EngineResult<()>

Send a directory and all its contents to a peer

The directory structure will be preserved on the receiving end. Files are sent with relative paths from the base directory.

Source

pub async fn accept_transfer(&self, transfer_id: &str) -> EngineResult<String>

Accept a pending transfer

Returns the token that the sender will use to upload files. Requires the server to be running.

Source

pub async fn reject_transfer(&self, transfer_id: &str) -> EngineResult<()>

Reject a pending transfer

Requires the server to be running.

Source

pub async fn get_pending_transfers(&self) -> Vec<PendingTransfer>

Get all pending transfers awaiting approval

Source

pub async fn cancel_transfer(&self, transfer_id: &str) -> EngineResult<()>

Cancel an in-progress transfer

This will stop the transfer and emit a TransferFailed event. Subsequent chunk uploads will be rejected.

Source

pub async fn accept_all_transfers(&self) -> Vec<(String, EngineResult<String>)>

Accept all pending transfers

Returns a list of (transfer_id, result) pairs. Each result contains either the token or the error.

Source

pub async fn reject_all_transfers(&self) -> Vec<(String, EngineResult<()>)>

Reject all pending transfers

Returns a list of (transfer_id, result) pairs.

Source

pub fn resolve_address(address: &str) -> ResolveResult

Resolve a hostname or IP to all available addresses

Source

pub fn resolve_address_or_err(address: &str) -> EngineResult<Vec<String>>

Resolve a hostname or IP, returning an error if resolution fails

Source

pub fn get_network_interfaces() -> Vec<NetworkInterface>

Get all network interfaces with their IP addresses

Source

pub async fn check_peer(&self, address: &str, port: u16) -> EngineResult<bool>

Check if a peer is reachable

Source

pub async fn get_peer_info( &self, address: &str, port: u16, ) -> EngineResult<Value>

Get peer device information

Source

pub async fn update_config(&mut self, config: EngineConfig)

Update the engine configuration

This updates the engine config, client config, and server state config.

Source

pub fn config(&self) -> &EngineConfig

Get the current configuration

Source

pub async fn add_trusted_host(&mut self, host: String)

Add a trusted host for auto-accepting transfers

Source

pub async fn remove_trusted_host(&mut self, host: &str)

Remove a trusted host

Source

pub fn trusted_hosts(&self) -> &[String]

Get the list of trusted hosts

Trait Implementations§

Source§

impl Drop for GoshTransferEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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