[−][src]Struct file_protocol::protocol::Protocol
File protocol information structure
Methods
impl Protocol
[src]
impl Protocol
pub fn new(host_ip: &str, remote_addr: &str, config: ProtocolConfig) -> Self
[src]
pub fn new(host_ip: &str, remote_addr: &str, config: ProtocolConfig) -> Self
Create a new file protocol instance using an automatically assigned UDP socket
Arguments
- host_ip - The local IP address
- remote_addr - The remote IP and port to communicate with
- prefix - Temporary storage directory prefix
Errors
If this function encounters any errors, it will panic
Examples
use file_protocol::*; let config = FileProtocolConfig::new(Some("my/file/storage".to_owned()), 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "192.168.0.1:7000", config);
pub fn send(&self, vec: &[u8]) -> Result<(), ProtocolError>
[src]
pub fn send(&self, vec: &[u8]) -> Result<(), ProtocolError>
Send CBOR packet to the destination port
Arguments
- vec - CBOR packet to send
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; use serde_cbor::ser; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let message = ser::to_vec_packed(&"ping").unwrap(); f_protocol.send(&message);
pub fn recv(&self, timeout: Option<Duration>) -> Result<Value, ProtocolError>
[src]
pub fn recv(&self, timeout: Option<Duration>) -> Result<Value, ProtocolError>
Receive a file protocol message
Arguments
- timeout - Maximum time to wait for a reply. If
None
, will block indefinitely
Errors
- If this function times out, it will return
Err(None)
- If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; use std::time::Duration; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let message = match f_protocol.recv(Some(Duration::from_secs(1))) { Ok(data) => data, Err(ProtocolError::ReceiveTimeout) => { println!("Timeout waiting for message"); return; } Err(err) => panic!("Failed to receive message: {}", err), };
pub fn generate_channel(&self) -> Result<u32, ProtocolError>
[src]
pub fn generate_channel(&self) -> Result<u32, ProtocolError>
Generates a new random channel ID for use when initiating a file transfer.
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; 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();
pub fn send_metadata(
&self,
channel_id: u32,
hash: &str,
num_chunks: u32
) -> Result<(), ProtocolError>
[src]
pub fn send_metadata(
&self,
channel_id: u32,
hash: &str,
num_chunks: u32
) -> Result<(), ProtocolError>
Send a file's metadata information to the remote target
Arguments
- channel_id - Channel ID for transaction
- hash - BLAKE2s hash of file
- num_chunks - Number of data chunks needed for file
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let (hash, num_chunks, _mode) = f_protocol.initialize_file("client.txt").unwrap(); let channel_id = f_protocol.generate_channel().unwrap(); f_protocol.send_metadata(channel_id, &hash, num_chunks);
pub fn send_cleanup(
&self,
channel_id: u32,
hash: Option<String>
) -> Result<(), ProtocolError>
[src]
pub fn send_cleanup(
&self,
channel_id: u32,
hash: Option<String>
) -> Result<(), ProtocolError>
Send a request to cleanup the remote storage folder
pub fn send_export(
&self,
channel_id: u32,
hash: &str,
target_path: &str,
mode: u32
) -> Result<(), ProtocolError>
[src]
pub fn send_export(
&self,
channel_id: u32,
hash: &str,
target_path: &str,
mode: u32
) -> Result<(), ProtocolError>
Request remote target to receive file from host
Arguments
- channel_id - Channel ID used for transaction
- hash - BLAKE2s hash of file
- target_path - Destination file path
- mode - File mode
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let (hash, _num_chunks, mode) = f_protocol.initialize_file("client.txt").unwrap(); let channel_id = f_protocol.generate_channel().unwrap(); f_protocol.send_export(channel_id, &hash, "final/dir/service.txt", mode);
pub fn send_import(
&self,
channel_id: u32,
source_path: &str
) -> Result<(), ProtocolError>
[src]
pub fn send_import(
&self,
channel_id: u32,
source_path: &str
) -> Result<(), ProtocolError>
Request a file from a remote target
Arguments
- source_path - File remote target should send
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; 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().unwrap(); f_protocol.send_import(channel_id, "service.txt");
pub fn initialize_file(
&self,
source_path: &str
) -> Result<(String, u32, u32), ProtocolError>
[src]
pub fn initialize_file(
&self,
source_path: &str
) -> Result<(String, u32, u32), ProtocolError>
Prepare a file for transfer
Imports the file into temporary storage and calculates the BLAKE2s hash
Arguments
- source_path - File to initialize for transfer
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); let (_hash, _num_chunks, _mode) = f_protocol.initialize_file("client.txt").unwrap();
pub fn message_engine<F>(
&self,
pump: F,
timeout: Duration,
start_state: &State
) -> Result<(), ProtocolError> where
F: Fn(Duration) -> Result<Value, ProtocolError>,
[src]
pub fn message_engine<F>(
&self,
pump: F,
timeout: Duration,
start_state: &State
) -> Result<(), ProtocolError> where
F: Fn(Duration) -> Result<Value, ProtocolError>,
Listen for and process file protocol messages
Arguments
- pump - Function which returns the next message for processing
- timeout - Maximum time to listen for a single message
- start_state - Current transaction state
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; use std::time::Duration; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); f_protocol.message_engine( |d| f_protocol.recv(Some(d)), Duration::from_millis(10), &State::Transmitting );
pub fn process_message(
&self,
message: Value,
state: &State
) -> Result<State, ProtocolError>
[src]
pub fn process_message(
&self,
message: Value,
state: &State
) -> Result<State, ProtocolError>
Process a file protocol message
Returns the new transaction state
Arguments
- message - File protocol message to process
- state - Current transaction state
Errors
If this function encounters any errors, it will return an error message string
Examples
use file_protocol::*; use std::time::Duration; let config = FileProtocolConfig::new(None, 4096, 5); let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", config); if let Ok(message) = f_protocol.recv(Some(Duration::from_millis(100))) { let _state = f_protocol.process_message( message, &State::StartReceive { path: "target/dir/file.bin".to_owned() } ); }
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more