Spaces:
Build error
Build error
File size: 1,165 Bytes
0ca462b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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)
}
}
|