pub struct Proxy {Show 23 fields
pub proxy_type: ProxyType,
pub address: IpAddr,
pub port: u16,
pub username: Option<String>,
pub password: Option<String>,
pub anonymity: AnonymityLevel,
pub country: Option<String>,
pub organization: Option<String>,
pub asn: Option<String>,
pub hostname: Option<String>,
pub latency_ms: Option<u128>,
pub added_at: DateTime<Utc>,
pub last_checked_at: Option<DateTime<Utc>>,
pub check_count: usize,
pub check_failure_count: usize,
pub last_used_at: Option<DateTime<Utc>>,
pub use_count: usize,
pub use_failure_count: usize,
pub ip_metadata: Option<IpMetadata>,
pub cidr: Option<String>,
pub location: Option<Location>,
pub network: Option<NetworkInfo>,
pub organization_info: Option<Organization>,
}Expand description
Represents a proxy server with its connection details and metadata.
This struct is used throughout the application to manage and interact with proxy servers. It includes fields for the proxy’s type, address, port, and anonymity level, as well as methods for managing its state and statistics.
§Examples
use gooty_proxy::definitions::Proxy;
use gooty_proxy::definitions::enums::{ProxyType, AnonymityLevel};
use std::net::{IpAddr, Ipv4Addr};
let proxy = Proxy::new(
ProxyType::Http,
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
8080,
AnonymityLevel::Elite,
);
assert_eq!(proxy.proxy_type, ProxyType::Http);
assert_eq!(proxy.port, 8080);Fields§
§proxy_type: ProxyTypeThe type of the proxy (e.g., HTTP, HTTPS, SOCKS4, SOCKS5).
address: IpAddrThe IP address of the proxy server.
port: u16The port number of the proxy server.
username: Option<String>Optional username for authentication.
password: Option<String>Optional password for authentication.
anonymity: AnonymityLevelThe anonymity level of the proxy.
country: Option<String>The country associated with the proxy, if available.
organization: Option<String>The organization associated with the proxy, if available.
asn: Option<String>The ASN (Autonomous System Number) of the proxy, if available.
hostname: Option<String>The hostname of the proxy, if available.
latency_ms: Option<u128>The latency of the proxy in milliseconds, if measured.
added_at: DateTime<Utc>When the proxy was added to the system.
last_checked_at: Option<DateTime<Utc>>When the proxy was last checked for availability.
check_count: usizeThe total number of checks performed on the proxy.
check_failure_count: usizeThe number of failed checks for the proxy.
last_used_at: Option<DateTime<Utc>>When the proxy was last used for a connection.
use_count: usizeNumber of times the proxy has been used for connections.
use_failure_count: usizeNumber of times connections through this proxy have failed.
ip_metadata: Option<IpMetadata>Extended network metadata for the proxy IP address.
cidr: Option<String>CIDR notation for the network the proxy belongs to.
location: Option<Location>Optional location information for the proxy IP address.
network: Option<NetworkInfo>Optional network information for the proxy IP address.
organization_info: Option<Organization>Optional organization information for the proxy IP address.
Implementations§
Source§impl Proxy
impl Proxy
Sourcepub fn new(
proxy_type: ProxyType,
address: IpAddr,
port: u16,
anonymity: AnonymityLevel,
) -> Self
pub fn new( proxy_type: ProxyType, address: IpAddr, port: u16, anonymity: AnonymityLevel, ) -> Self
Creates a new proxy with mandatory fields and default values for statistics.
§Arguments
proxy_type- The type of proxy protocol to use (HTTP, HTTPS, SOCKS4, SOCKS5)address- The IP address of the proxy serverport- The port number the proxy server listens onanonymity- The level of anonymity provided by the proxy
§Returns
A new Proxy instance with default values for non-specified fields
§Examples
use spiderling_proxy::definitions::{
enums::{AnonymityLevel, ProxyType},
proxy::Proxy,
};
use std::net::{IpAddr, Ipv4Addr};
let proxy = Proxy::new(
ProxyType::Http,
IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1)),
8080,
AnonymityLevel::Anonymous,
);Sourcepub fn with_auth(self, username: String, password: String) -> Self
pub fn with_auth(self, username: String, password: String) -> Self
Sets authentication credentials for the proxy.
§Arguments
username- Username for proxy authenticationpassword- Password for proxy authentication
§Returns
Self with authentication credentials set
§Examples
let proxy = Proxy::new(
ProxyType::Http,
IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1)),
8080,
AnonymityLevel::Anonymous
).with_auth("username".to_string(), "password".to_string());Sourcepub fn with_country(self, country: String) -> Self
pub fn with_country(self, country: String) -> Self
Sourcepub fn with_hostname(self, hostname: String) -> Self
pub fn with_hostname(self, hostname: String) -> Self
Sourcepub fn with_organization(self, organization: String) -> Self
pub fn with_organization(self, organization: String) -> Self
Sourcepub fn validate(&self) -> Result<(), ProxyError>
pub fn validate(&self) -> Result<(), ProxyError>
Validates that the proxy configuration is correct.
§Returns
Ok(())- If the proxy configuration is validErr(ProxyError)- If the proxy configuration is invalid
§Errors
This function will return an error if:
- The port is set to 0
- Authentication is missing required fields (e.g., password is missing when username is provided for SOCKS5)
Sourcepub fn record_check(&mut self, latency: u128)
pub fn record_check(&mut self, latency: u128)
Records a successful check of the proxy
Sourcepub fn record_check_failure(&mut self)
pub fn record_check_failure(&mut self)
Records a failed check of the proxy
Sourcepub fn record_use(&mut self)
pub fn record_use(&mut self)
Records a successful use of the proxy
Sourcepub fn record_use_failure(&mut self)
pub fn record_use_failure(&mut self)
Records a failed use of the proxy
Sourcepub fn check_success_rate(&self) -> usize
pub fn check_success_rate(&self) -> usize
Calculates the success rate of the proxy based on check history
Sourcepub fn use_success_rate(&self) -> usize
pub fn use_success_rate(&self) -> usize
Calculates the success rate of the proxy based on usage history
Sourcepub fn to_connection_string(&self) -> String
pub fn to_connection_string(&self) -> String
Returns a connection string representation of the proxy
Sourcepub fn update_metadata(
&mut self,
country: Option<String>,
organization: Option<String>,
hostname: Option<String>,
anonymity: Option<AnonymityLevel>,
)
pub fn update_metadata( &mut self, country: Option<String>, organization: Option<String>, hostname: Option<String>, anonymity: Option<AnonymityLevel>, )
Updates the proxy with new information from a check
Sourcepub fn update_with_ip_metadata(&mut self, metadata: IpMetadata)
pub fn update_with_ip_metadata(&mut self, metadata: IpMetadata)
Updates the proxy with network metadata from a sleuth lookup
Sourcepub fn get_ip_metadata(&self) -> Option<&IpMetadata>
pub fn get_ip_metadata(&self) -> Option<&IpMetadata>
Gets the full IP metadata if available
Source§impl Proxy
Helper functions for serialization and deserialization
impl Proxy
Helper functions for serialization and deserialization
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Proxy
impl<'de> Deserialize<'de> for Proxy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Proxy
impl StructuralPartialEq for Proxy
Auto Trait Implementations§
impl Freeze for Proxy
impl RefUnwindSafe for Proxy
impl Send for Proxy
impl Sync for Proxy
impl Unpin for Proxy
impl UnsafeUnpin for Proxy
impl UnwindSafe for Proxy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.