Likhith Sai Seemala
Deploy IntentForge v2 to HF Spaces
0ca462b
Raw History Blame Contribute Delete
1.17 kB
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
pub enum ProxyProtocol {
Http,
Https,
Socks4,
Socks5,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Proxy {
pub host: String,
pub port: u16,
pub protocol: ProxyProtocol,
pub country: Option<String>,
#[serde(skip)]
pub last_checked: Option<std::time::Instant>,
#[serde(skip)]
pub latency: Option<Duration>,
pub is_working: bool,
}
impl Proxy {
pub fn new(host: String, port: u16, protocol: ProxyProtocol) -> Self {
Self {
host,
port,
protocol,
country: None,
last_checked: None,
latency: None,
is_working: false,
}
}
pub fn to_url(&self) -> String {
let proto = match self.protocol {
ProxyProtocol::Http => "http",
ProxyProtocol::Https => "https",
ProxyProtocol::Socks4 => "socks4",
ProxyProtocol::Socks5 => "socks5",
};
format!("{}://{}:{}", proto, self.host, self.port)
}
}