use rand::{
distributions::{Alphanumeric, DistString},
thread_rng,
};
use std::{fmt, time::Duration};
pub(crate) const SAMV3_UDP_PORT: u16 = 7655;
pub(crate) const SAMV3_TCP_PORT: u16 = 7656;
#[derive(Clone, PartialEq, Eq)]
pub enum DestinationKind {
Transient,
Persistent {
private_key: String,
},
}
impl fmt::Debug for DestinationKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Transient => f.debug_struct("DestinationKind::Transient").finish(),
Self::Persistent { .. } =>
f.debug_struct("DestinationKind::Persistent").finish_non_exhaustive(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionOptions {
pub nickname: String,
pub destination: DestinationKind,
pub signature_type: u16,
pub datagram_port: u16,
pub from_port: u16,
pub to_port: u16,
pub protocol: u8,
pub header: bool,
pub publish: bool,
pub crypto_low_tag_threshold: usize,
pub crypto_ratchet_inbound_tags: usize,
pub crypto_ratchet_outbound_tags: usize,
pub crypto_tags_to_send: usize,
pub username: Option<String>,
pub password: Option<String>,
pub inbound_allow_zero_hop: bool,
pub inbound_len: usize,
pub inbound_len_variance: isize,
pub inbound_quantity: usize,
pub inbound_backup_quantity: usize,
pub inbound_ip_restriction: Option<std::num::NonZeroUsize>,
pub inbound_random_key: Option<String>,
pub inbound_nickname: Option<String>,
pub outbound_allow_zero_hop: bool,
pub outbound_len: usize,
pub outbound_len_variance: isize,
pub outbound_quantity: usize,
pub outbound_backup_quantity: usize,
pub outbound_ip_restriction: Option<std::num::NonZeroUsize>,
pub outbound_random_key: Option<String>,
pub outbound_nickname: Option<String>,
pub outbound_priority: isize,
pub should_bundle_reply_info: bool,
pub reduce_on_idle: bool,
pub reduce_idle_time: Duration,
pub reduce_quantity: usize,
pub close_on_idle: bool,
pub close_idle_time: Duration,
pub lease_set_auth_type: usize,
pub lease_set_blinded_type: usize,
pub lease_set_enc_type: Option<String>,
pub lease_set_key: Option<String>,
pub lease_set_private_key: Option<String>,
pub lease_set_secret: Option<String>,
pub lease_set_signing_private_key: Option<String>,
pub lease_set_type: usize,
pub encrypt_lease_set: bool,
pub gzip: bool,
pub ssl: bool,
pub samv3_tcp_port: u16,
pub samv3_udp_port: u16,
pub silent_forward: bool,
}
impl Default for SessionOptions {
fn default() -> Self {
Self {
nickname: Alphanumeric.sample_string(&mut thread_rng(), 16),
destination: DestinationKind::Transient,
signature_type: 7u16,
datagram_port: 0u16,
from_port: 0u16,
to_port: 0u16,
protocol: 18u8,
header: false,
publish: true,
crypto_low_tag_threshold: 30usize,
crypto_ratchet_inbound_tags: 160usize,
crypto_ratchet_outbound_tags: 160usize,
crypto_tags_to_send: 40usize,
username: None,
password: None,
inbound_allow_zero_hop: false,
inbound_len: 3usize,
inbound_len_variance: 0isize,
inbound_quantity: 2usize,
inbound_backup_quantity: 0usize,
inbound_ip_restriction: None,
inbound_random_key: None,
inbound_nickname: None,
outbound_allow_zero_hop: false,
outbound_len: 3usize,
outbound_len_variance: 0isize,
outbound_quantity: 2usize,
outbound_backup_quantity: 0usize,
outbound_ip_restriction: None,
outbound_random_key: None,
outbound_nickname: None,
outbound_priority: 0isize,
should_bundle_reply_info: true,
reduce_on_idle: false,
reduce_idle_time: Duration::from_millis(1200000),
reduce_quantity: 1usize,
close_on_idle: false,
close_idle_time: Duration::from_millis(1800000),
lease_set_auth_type: 0usize,
lease_set_blinded_type: 0usize,
lease_set_enc_type: None,
lease_set_key: None,
lease_set_private_key: None,
lease_set_secret: None,
lease_set_signing_private_key: None,
lease_set_type: 1usize,
encrypt_lease_set: false,
gzip: true,
ssl: false,
samv3_tcp_port: SAMV3_TCP_PORT,
samv3_udp_port: SAMV3_UDP_PORT,
silent_forward: false,
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct StreamOptions {
pub dst_port: u16,
pub src_port: u16,
}
#[derive(Default)]
pub struct DatagramOptions {
pub from_port: u16,
pub to_port: u16,
pub protocol: u8,
pub send_tags: usize,
pub tag_threshold: usize,
pub send_lease_set: bool,
}