Struct file_protocol::protocol::Protocol [−][src]
pub struct Protocol { /* fields omitted */ }
File protocol information structure
Methods
impl Protocol
[src]
impl Protocol
pub fn new(host_ip: &str, remote_addr: &str, prefix: Option<String>) -> Self
[src]
pub fn new(host_ip: &str, remote_addr: &str, prefix: Option<String>) -> 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 f_protocol = FileProtocol::new("0.0.0.0", "192.168.0.1:7000", Some("my/file/storage".to_owned()));
pub fn new_from_socket(
socket: UdpSocket,
remote_addr: &str,
prefix: Option<String>
) -> Self
[src]
pub fn new_from_socket(
socket: UdpSocket,
remote_addr: &str,
prefix: Option<String>
) -> Self
Create a new file protocol instance using a specific UDP socket
Arguments
- socket - The local socket to use for communication
- 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::*; use std::net::UdpSocket; let socket = UdpSocket::bind("0.0.0.0:8000").unwrap(); let f_protocol = FileProtocol::new_from_socket(socket, "192.168.0.1:7000", None);
pub fn send(&self, vec: Vec<u8>) -> Result<(), String>
[src]
pub fn send(&self, vec: Vec<u8>) -> Result<(), String>
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
extern crate file_protocol; extern crate serde_cbor; use file_protocol::*; use serde_cbor::ser; let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); let message = ser::to_vec_packed(&"ping").unwrap(); f_protocol.send(message);
pub fn recv(
&self,
timeout: Option<Duration>
) -> Result<Option<Value>, Option<String>>
[src]
pub fn recv(
&self,
timeout: Option<Duration>
) -> Result<Option<Value>, Option<String>>
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
extern crate file_protocol; use file_protocol::*; use std::time::Duration; let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); let message = match f_protocol.recv(Some(Duration::from_secs(1))) { Ok(data) => data, Err(None) => { println!("Timeout waiting for message"); return; } Err(Some(err)) => panic!("Failed to receive message: {}", err), };
pub fn send_metadata(&self, hash: &str, num_chunks: u32) -> Result<(), String>
[src]
pub fn send_metadata(&self, hash: &str, num_chunks: u32) -> Result<(), String>
Send a file's metadata information to the remote target
Arguments
- 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 f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); let (hash, num_chunks, _mode) = f_protocol.initialize_file("client.txt").unwrap(); f_protocol.send_metadata(&hash, num_chunks);
pub fn send_export(
&self,
hash: &str,
target_path: &str,
mode: u32
) -> Result<(), String>
[src]
pub fn send_export(
&self,
hash: &str,
target_path: &str,
mode: u32
) -> Result<(), String>
Request remote target to receive file from host
Arguments
- 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 f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); let (hash, _num_chunks, mode) = f_protocol.initialize_file("client.txt").unwrap(); f_protocol.send_export(&hash, "final/dir/service.txt", mode);
pub fn send_import(&self, source_path: &str) -> Result<(), String>
[src]
pub fn send_import(&self, source_path: &str) -> Result<(), String>
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 f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); f_protocol.send_import("service.txt");
pub fn initialize_file(
&self,
source_path: &str
) -> Result<(String, u32, u32), String>
[src]
pub fn initialize_file(
&self,
source_path: &str
) -> Result<(String, u32, u32), String>
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 f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); let (_hash, _num_chunks, _mode) = f_protocol.initialize_file("client.txt").unwrap();
pub fn message_engine(
&self,
timeout: Duration,
start_state: State
) -> Result<(), String>
[src]
pub fn message_engine(
&self,
timeout: Duration,
start_state: State
) -> Result<(), String>
Listen for and process file protocol messages
Arguments
- 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
extern crate file_protocol; use file_protocol::*; use std::time::Duration; let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); f_protocol.message_engine(Duration::from_millis(10), State::Transmitting);
pub fn process_message(
&self,
message: Value,
state: State
) -> Result<State, String>
[src]
pub fn process_message(
&self,
message: Value,
state: State
) -> Result<State, String>
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
extern crate file_protocol; use file_protocol::*; use std::time::Duration; let f_protocol = FileProtocol::new("0.0.0.0", "0.0.0.0:7000", None); if let Ok(Some(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() } ); }