Skip to main content

Proxy

Struct Proxy 

Source
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: ProxyType

The type of the proxy (e.g., HTTP, HTTPS, SOCKS4, SOCKS5).

§address: IpAddr

The IP address of the proxy server.

§port: u16

The port number of the proxy server.

§username: Option<String>

Optional username for authentication.

§password: Option<String>

Optional password for authentication.

§anonymity: AnonymityLevel

The 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: usize

The total number of checks performed on the proxy.

§check_failure_count: usize

The number of failed checks for the proxy.

§last_used_at: Option<DateTime<Utc>>

When the proxy was last used for a connection.

§use_count: usize

Number of times the proxy has been used for connections.

§use_failure_count: usize

Number 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

Source

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 server
  • port - The port number the proxy server listens on
  • anonymity - 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,
);
Source

pub fn with_auth(self, username: String, password: String) -> Self

Sets authentication credentials for the proxy.

§Arguments
  • username - Username for proxy authentication
  • password - 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());
Source

pub fn with_country(self, country: String) -> Self

Sets the country for the proxy.

§Arguments
  • country - The country where the proxy server is located
§Returns

Self with country information set

Source

pub fn with_hostname(self, hostname: String) -> Self

Sets the hostname for the proxy.

§Arguments
  • hostname - The hostname of the proxy server
§Returns

Self with hostname information set

Source

pub fn with_organization(self, organization: String) -> Self

Sets the organization for the proxy.

§Arguments
  • organization - The organization or ISP operating the proxy
§Returns

Self with organization information set

Source

pub fn validate(&self) -> Result<(), ProxyError>

Validates that the proxy configuration is correct.

§Returns
  • Ok(()) - If the proxy configuration is valid
  • Err(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)
Source

pub fn record_check(&mut self, latency: u128)

Records a successful check of the proxy

Source

pub fn record_check_failure(&mut self)

Records a failed check of the proxy

Source

pub fn record_use(&mut self)

Records a successful use of the proxy

Source

pub fn record_use_failure(&mut self)

Records a failed use of the proxy

Source

pub fn check_success_rate(&self) -> usize

Calculates the success rate of the proxy based on check history

Source

pub fn use_success_rate(&self) -> usize

Calculates the success rate of the proxy based on usage history

Source

pub fn to_connection_string(&self) -> String

Returns a connection string representation of the proxy

Source

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

Source

pub fn update_with_ip_metadata(&mut self, metadata: IpMetadata)

Updates the proxy with network metadata from a sleuth lookup

Source

pub fn get_ip_metadata(&self) -> Option<&IpMetadata>

Gets the full IP metadata if available

Source§

impl Proxy

Helper functions for serialization and deserialization

Source

pub fn to_json(&self) -> Result<String, Error>

Serializes the proxy to a JSON string

§Errors

This function will return an error if the serialization fails, such as when the proxy contains data that cannot be represented in JSON.

Source

pub fn from_json(json: &str) -> Result<Self, Error>

Deserializes a proxy from a JSON string

§Errors

This function will return an error if the provided string is not valid JSON or if it doesn’t match the expected structure for a Proxy object.

Trait Implementations§

Source§

impl Clone for Proxy

Source§

fn clone(&self) -> Proxy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Proxy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Proxy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Proxy

Source§

impl PartialEq for Proxy

Source§

fn eq(&self, other: &Proxy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Proxy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more