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
impl GoshTransferEngine
Sourcepub fn new(config: EngineConfig, event_handler: Arc<dyn EventHandler>) -> Self
pub fn new(config: EngineConfig, event_handler: Arc<dyn EventHandler>) -> Self
Create a new engine with the given configuration and event handler
Sourcepub fn with_history(
config: EngineConfig,
event_handler: Arc<dyn EventHandler>,
history: Arc<dyn HistoryPersistence>,
) -> Self
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.
Sourcepub fn with_channel_events(
config: EngineConfig,
) -> (Self, Receiver<EngineEvent>)
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.
Sourcepub fn with_channel_events_and_history(
config: EngineConfig,
history: Arc<dyn HistoryPersistence>,
) -> (Self, Receiver<EngineEvent>)
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.
Sourcepub fn history(&self) -> Option<&Arc<dyn HistoryPersistence>>
pub fn history(&self) -> Option<&Arc<dyn HistoryPersistence>>
Get the history persistence (if configured)
Sourcepub async fn start_server(&mut self) -> EngineResult<()>
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.
Sourcepub async fn stop_server(&mut self) -> EngineResult<()>
pub async fn stop_server(&mut self) -> EngineResult<()>
Stop the HTTP server
Sourcepub fn is_server_running(&self) -> bool
pub fn is_server_running(&self) -> bool
Check if the server is running
Sourcepub fn server_state(&self) -> &Arc<ServerState>
pub fn server_state(&self) -> &Arc<ServerState>
Get the server state for advanced operations
Sourcepub async fn change_port(&mut self, new_port: u16) -> EngineResult<()>
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::InvalidConfigif the port is invalid (e.g., port 0)EngineError::Networkif binding to the new port fails
Sourcepub async fn change_port_with_options(
&mut self,
new_port: u16,
rollback_on_failure: bool,
) -> EngineResult<()>
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 torollback_on_failure- If true, attempt to restore the old port if new binding fails
§Behavior
- Validates the new port
- If server is running, stops it gracefully
- Attempts to bind to the new port
- On success: updates config, emits
PortChangedandServerStartedevents - On failure with rollback: attempts to restore old port
- On failure without rollback: leaves server stopped
Sourcepub async fn send_files(
&self,
address: &str,
port: u16,
file_paths: Vec<PathBuf>,
) -> EngineResult<()>
pub async fn send_files( &self, address: &str, port: u16, file_paths: Vec<PathBuf>, ) -> EngineResult<()>
Send files to a peer
This will:
- Request permission from the peer
- Wait for approval (or auto-accept if trusted)
- Stream the files to the peer
- Emit progress events during transfer
Sourcepub async fn send_directory(
&self,
address: &str,
port: u16,
dir_path: impl AsRef<Path>,
) -> EngineResult<()>
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.
Sourcepub async fn accept_transfer(&self, transfer_id: &str) -> EngineResult<String>
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.
Sourcepub async fn reject_transfer(&self, transfer_id: &str) -> EngineResult<()>
pub async fn reject_transfer(&self, transfer_id: &str) -> EngineResult<()>
Reject a pending transfer
Requires the server to be running.
Sourcepub async fn get_pending_transfers(&self) -> Vec<PendingTransfer>
pub async fn get_pending_transfers(&self) -> Vec<PendingTransfer>
Get all pending transfers awaiting approval
Sourcepub async fn cancel_transfer(&self, transfer_id: &str) -> EngineResult<()>
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.
Sourcepub async fn accept_all_transfers(&self) -> Vec<(String, EngineResult<String>)>
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.
Sourcepub async fn reject_all_transfers(&self) -> Vec<(String, EngineResult<()>)>
pub async fn reject_all_transfers(&self) -> Vec<(String, EngineResult<()>)>
Reject all pending transfers
Returns a list of (transfer_id, result) pairs.
Sourcepub fn resolve_address(address: &str) -> ResolveResult
pub fn resolve_address(address: &str) -> ResolveResult
Resolve a hostname or IP to all available addresses
Sourcepub fn resolve_address_or_err(address: &str) -> EngineResult<Vec<String>>
pub fn resolve_address_or_err(address: &str) -> EngineResult<Vec<String>>
Resolve a hostname or IP, returning an error if resolution fails
Sourcepub fn get_network_interfaces() -> Vec<NetworkInterface>
pub fn get_network_interfaces() -> Vec<NetworkInterface>
Get all network interfaces with their IP addresses
Sourcepub async fn check_peer(&self, address: &str, port: u16) -> EngineResult<bool>
pub async fn check_peer(&self, address: &str, port: u16) -> EngineResult<bool>
Check if a peer is reachable
Sourcepub async fn get_peer_info(
&self,
address: &str,
port: u16,
) -> EngineResult<Value>
pub async fn get_peer_info( &self, address: &str, port: u16, ) -> EngineResult<Value>
Get peer device information
Sourcepub async fn update_config(&mut self, config: EngineConfig)
pub async fn update_config(&mut self, config: EngineConfig)
Update the engine configuration
This updates the engine config, client config, and server state config.
Sourcepub fn config(&self) -> &EngineConfig
pub fn config(&self) -> &EngineConfig
Get the current configuration
Sourcepub async fn add_trusted_host(&mut self, host: String)
pub async fn add_trusted_host(&mut self, host: String)
Add a trusted host for auto-accepting transfers
Sourcepub async fn remove_trusted_host(&mut self, host: &str)
pub async fn remove_trusted_host(&mut self, host: &str)
Remove a trusted host
Sourcepub fn trusted_hosts(&self) -> &[String]
pub fn trusted_hosts(&self) -> &[String]
Get the list of trusted hosts