|
|
|
//! Configuration
|
|
|
|
use super::*;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
pub const DEFAULT_BUFFER_SIZE: usize = 4096;
|
|
|
|
|
|
|
|
/// Configuration for sending
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct SendConfig
|
|
|
|
{
|
|
|
|
encrypt: bool,
|
|
|
|
compress: bool,
|
|
|
|
buffer_size: usize,
|
|
|
|
archive: bool,
|
|
|
|
//oneshot: bool, // Server specific
|
|
|
|
continuation: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SendConfig
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn default() -> Self
|
|
|
|
{
|
|
|
|
Self {
|
|
|
|
encrypt: false,
|
|
|
|
compress: false,
|
|
|
|
buffer_size: DEFAULT_BUFFER_SIZE,
|
|
|
|
archive: false,
|
|
|
|
//oneshot: false,
|
|
|
|
continuation: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Configuration for receiving
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct RecvConfig
|
|
|
|
{
|
|
|
|
interactive: bool,
|
|
|
|
continuation: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RecvConfig
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn default() -> Self
|
|
|
|
{
|
|
|
|
Self {
|
|
|
|
interactive: false,
|
|
|
|
continuation: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Instructions for binding (server) mode
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Server
|
|
|
|
{
|
|
|
|
listen: SocketAddr, //TODO: Allow multiple?
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Instructions for connecting (client) mode
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Client
|
|
|
|
{
|
|
|
|
connect: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A send or recv operation
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub enum Operation
|
|
|
|
{
|
|
|
|
Send(SendConfig),
|
|
|
|
Recv(RecvConfig),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Whether to serve (listen) or connect directly.
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub enum Mode
|
|
|
|
{
|
|
|
|
Server(Server),
|
|
|
|
Client(Client),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Program full configuration
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Config
|
|
|
|
{
|
|
|
|
/// Which operation (send/recv) are we performing?
|
|
|
|
pub op: Operation,
|
|
|
|
/// How are we performing it? (Bind/connect)
|
|
|
|
pub mode: Mode,
|
|
|
|
}
|