[−][src]Crate file_protocol
Kubos File Transfer Protocol
Examples
use file_protocol::*; use std::time::Duration; fn upload() -> Result<(), ProtocolError> { let config = FileProtocolConfig::new(Some("storage/dir".to_owned()), 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let source_path = "client.txt"; let target_path = "service.txt"; // Copy file to upload to temp storage. Calculate the hash and chunk info let (hash, num_chunks, mode) = f_protocol.initialize_file(&source_path)?; // Generate channel id let channel_id = f_protocol.generate_channel()?; // Tell our destination the hash and number of chunks to expect f_protocol.send_metadata(channel_id, &hash, num_chunks)?; // Send export command for file f_protocol.send_export(channel_id, &hash, &target_path, mode)?; // Start the engine to send the file data chunks Ok(f_protocol.message_engine(|d| f_protocol.recv(Some(d)), Duration::from_millis(10), &State::Transmitting)?) }
extern crate file_protocol; use file_protocol::*; use std::time::Duration; fn download() -> Result<(), ProtocolError> { let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let channel_id = f_protocol.generate_channel()?; let source_path = "service.txt"; let target_path = "client.txt"; // Send our file request to the remote addr and verify that it's // going to be able to send it f_protocol.send_import(channel_id, source_path)?; // Wait for the request reply let reply = match f_protocol.recv(None) { Ok(message) => message, Err(error) => return Err(error) }; let state = f_protocol.process_message( reply, &State::StartReceive { path: target_path.to_string(), }, )?; Ok(f_protocol.message_engine(|d| f_protocol.recv(Some(d)), Duration::from_millis(10), &state)?) }
Re-exports
pub use crate::protocol::Protocol as FileProtocol; |
pub use crate::protocol::ProtocolConfig as FileProtocolConfig; |
pub use crate::protocol::State; |
Modules
protocol |
File transfer protocol module |
Enums
Message |
File protocol message types |
ProtocolError |
Errors which occur when using FileProtocol |
Functions
parse_channel_id |
Parse out just the channel ID from a message |