mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-07-27 20:47:46 +00:00
Merge pull request #52 from floor-licker/fix/remove-unused-dns-cache
chore: remove unused dns cache
This commit is contained in:
Generated
-164
@@ -1458,21 +1458,6 @@ dependencies = [
|
|||||||
"itertools 0.10.5",
|
"itertools 0.10.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "critical-section"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-channel"
|
|
||||||
version = "0.5.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-deque"
|
name = "crossbeam-deque"
|
||||||
version = "0.8.6"
|
version = "0.8.6"
|
||||||
@@ -2209,76 +2194,6 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hickory-net"
|
|
||||||
version = "0.26.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2295ed2f9c31e471e1428a8f88a3f0e1f4b27c15049592138d1eebe9c35b183"
|
|
||||||
dependencies = [
|
|
||||||
"async-trait",
|
|
||||||
"cfg-if",
|
|
||||||
"data-encoding",
|
|
||||||
"futures-channel",
|
|
||||||
"futures-io",
|
|
||||||
"futures-util",
|
|
||||||
"hickory-proto",
|
|
||||||
"idna",
|
|
||||||
"ipnet",
|
|
||||||
"jni",
|
|
||||||
"rand 0.10.1",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"tinyvec",
|
|
||||||
"tokio",
|
|
||||||
"tracing",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hickory-proto"
|
|
||||||
version = "0.26.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0bab31817bfb44672a252e97fe81cd0c18d1b2cf892108922f6818820df8c643"
|
|
||||||
dependencies = [
|
|
||||||
"data-encoding",
|
|
||||||
"idna",
|
|
||||||
"ipnet",
|
|
||||||
"jni",
|
|
||||||
"once_cell",
|
|
||||||
"prefix-trie",
|
|
||||||
"rand 0.10.1",
|
|
||||||
"ring",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"tinyvec",
|
|
||||||
"tracing",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hickory-resolver"
|
|
||||||
version = "0.26.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f0d58d28879ceecde6607729660c2667a081ccdc082e082675042793960f178c"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"futures-util",
|
|
||||||
"hickory-net",
|
|
||||||
"hickory-proto",
|
|
||||||
"ipconfig",
|
|
||||||
"ipnet",
|
|
||||||
"jni",
|
|
||||||
"moka",
|
|
||||||
"ndk-context",
|
|
||||||
"once_cell",
|
|
||||||
"parking_lot",
|
|
||||||
"rand 0.10.1",
|
|
||||||
"resolv-conf",
|
|
||||||
"smallvec",
|
|
||||||
"system-configuration",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"tokio",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hmac"
|
name = "hmac"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -2586,27 +2501,11 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ipconfig"
|
|
||||||
version = "0.3.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222"
|
|
||||||
dependencies = [
|
|
||||||
"socket2",
|
|
||||||
"widestring",
|
|
||||||
"windows-registry",
|
|
||||||
"windows-result",
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.12.0"
|
version = "2.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
|
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is-terminal"
|
name = "is-terminal"
|
||||||
@@ -2966,23 +2865,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "moka"
|
|
||||||
version = "0.12.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "957228ad12042ee839f93c8f257b62b4c0ab5eaae1d4fa60de53b27c9d7c5046"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-channel",
|
|
||||||
"crossbeam-epoch",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"equivalent",
|
|
||||||
"parking_lot",
|
|
||||||
"portable-atomic",
|
|
||||||
"smallvec",
|
|
||||||
"tagptr",
|
|
||||||
"uuid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-tls"
|
name = "native-tls"
|
||||||
version = "0.2.18"
|
version = "0.2.18"
|
||||||
@@ -3000,12 +2882,6 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ndk-context"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.50.3"
|
version = "0.50.3"
|
||||||
@@ -3100,10 +2976,6 @@ name = "once_cell"
|
|||||||
version = "1.21.4"
|
version = "1.21.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
dependencies = [
|
|
||||||
"critical-section",
|
|
||||||
"portable-atomic",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oorandom"
|
name = "oorandom"
|
||||||
@@ -3364,7 +3236,6 @@ dependencies = [
|
|||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hickory-resolver",
|
|
||||||
"hmac",
|
"hmac",
|
||||||
"mockito",
|
"mockito",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
@@ -3420,12 +3291,6 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "portable-atomic"
|
|
||||||
version = "1.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@@ -3450,17 +3315,6 @@ dependencies = [
|
|||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "prefix-trie"
|
|
||||||
version = "0.8.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4cf6e3177f0684016a5c209b00882e15f8bdd3f3bb48f0491df10cd102d0c6e7"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"ipnet",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.37"
|
version = "0.2.37"
|
||||||
@@ -3878,12 +3732,6 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "resolv-conf"
|
|
||||||
version = "0.7.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rfc6979"
|
name = "rfc6979"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@@ -4732,12 +4580,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tagptr"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tap"
|
name = "tap"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -5430,12 +5272,6 @@ dependencies = [
|
|||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "widestring"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-util"
|
name = "winapi-util"
|
||||||
version = "0.1.11"
|
version = "0.1.11"
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ futures-util = "0.3"
|
|||||||
|
|
||||||
# HTTP client
|
# HTTP client
|
||||||
reqwest = { version = "0.13", default-features = false, features = ["json", "query", "stream", "gzip", "rustls", "http2"] }
|
reqwest = { version = "0.13", default-features = false, features = ["json", "query", "stream", "gzip", "rustls", "http2"] }
|
||||||
hickory-resolver = "0.26"
|
|
||||||
|
|
||||||
# Serialization
|
# Serialization
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|||||||
@@ -101,8 +101,6 @@ pub struct ClobClient {
|
|||||||
builder_code: Option<String>,
|
builder_code: Option<String>,
|
||||||
order_builder: Option<crate::orders::OrderBuilder>,
|
order_builder: Option<crate::orders::OrderBuilder>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
dns_cache: Option<std::sync::Arc<crate::dns_cache::DnsCache>>,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
connection_manager: Option<std::sync::Arc<crate::connection_manager::ConnectionManager>>,
|
connection_manager: Option<std::sync::Arc<crate::connection_manager::ConnectionManager>>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
buffer_pool: std::sync::Arc<crate::buffer_pool::BufferPool>,
|
buffer_pool: std::sync::Arc<crate::buffer_pool::BufferPool>,
|
||||||
@@ -160,7 +158,6 @@ impl ClobClient {
|
|||||||
api_creds,
|
api_creds,
|
||||||
builder_code: auth.builder_code,
|
builder_code: auth.builder_code,
|
||||||
order_builder,
|
order_builder,
|
||||||
dns_cache: None,
|
|
||||||
connection_manager,
|
connection_manager,
|
||||||
buffer_pool,
|
buffer_pool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,137 +0,0 @@
|
|||||||
//! DNS caching to reduce lookup latency
|
|
||||||
//!
|
|
||||||
//! This module provides DNS caching functionality to avoid repeated DNS lookups
|
|
||||||
//! which can add 10-20ms per request.
|
|
||||||
|
|
||||||
use hickory_resolver::config::*;
|
|
||||||
use hickory_resolver::net::runtime::TokioRuntimeProvider;
|
|
||||||
use hickory_resolver::TokioResolver;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::net::IpAddr;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
use tokio::sync::RwLock;
|
|
||||||
|
|
||||||
/// DNS cache entry with TTL
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct DnsCacheEntry {
|
|
||||||
ips: Vec<IpAddr>,
|
|
||||||
expires_at: Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// DNS cache for resolving hostnames
|
|
||||||
pub struct DnsCache {
|
|
||||||
resolver: TokioResolver,
|
|
||||||
cache: Arc<RwLock<HashMap<String, DnsCacheEntry>>>,
|
|
||||||
default_ttl: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DnsCache {
|
|
||||||
/// Create a new DNS cache with system configuration
|
|
||||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let mut builder = TokioResolver::builder_with_config(
|
|
||||||
ResolverConfig::default(),
|
|
||||||
TokioRuntimeProvider::default(),
|
|
||||||
);
|
|
||||||
*builder.options_mut() = ResolverOpts::default();
|
|
||||||
let resolver = builder.build()?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
resolver,
|
|
||||||
cache: Arc::new(RwLock::new(HashMap::new())),
|
|
||||||
default_ttl: Duration::from_secs(300), // 5 minutes default TTL
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a DNS cache with custom TTL
|
|
||||||
pub async fn with_ttl(ttl: Duration) -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let mut builder = TokioResolver::builder_with_config(
|
|
||||||
ResolverConfig::default(),
|
|
||||||
TokioRuntimeProvider::default(),
|
|
||||||
);
|
|
||||||
*builder.options_mut() = ResolverOpts::default();
|
|
||||||
let resolver = builder.build()?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
resolver,
|
|
||||||
cache: Arc::new(RwLock::new(HashMap::new())),
|
|
||||||
default_ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resolve a hostname, using cache if available
|
|
||||||
pub async fn resolve(&self, hostname: &str) -> Result<Vec<IpAddr>, Box<dyn std::error::Error>> {
|
|
||||||
// Check cache first
|
|
||||||
{
|
|
||||||
let cache = self.cache.read().await;
|
|
||||||
if let Some(entry) = cache.get(hostname) {
|
|
||||||
if entry.expires_at > Instant::now() {
|
|
||||||
return Ok(entry.ips.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache miss or expired, do actual lookup
|
|
||||||
let lookup = self.resolver.lookup_ip(hostname).await?;
|
|
||||||
let ips: Vec<IpAddr> = lookup.iter().collect();
|
|
||||||
|
|
||||||
// Store in cache
|
|
||||||
let entry = DnsCacheEntry {
|
|
||||||
ips: ips.clone(),
|
|
||||||
expires_at: Instant::now() + self.default_ttl,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut cache = self.cache.write().await;
|
|
||||||
cache.insert(hostname.to_string(), entry);
|
|
||||||
|
|
||||||
Ok(ips)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pre-warm the cache by resolving a hostname
|
|
||||||
pub async fn prewarm(&self, hostname: &str) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
self.resolve(hostname).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear the cache
|
|
||||||
pub async fn clear(&self) {
|
|
||||||
let mut cache = self.cache.write().await;
|
|
||||||
cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get cache size
|
|
||||||
pub async fn cache_size(&self) -> usize {
|
|
||||||
let cache = self.cache.read().await;
|
|
||||||
cache.len()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[ignore = "requires external DNS/network access"]
|
|
||||||
async fn test_dns_cache_resolve() {
|
|
||||||
let cache = DnsCache::new().await.unwrap();
|
|
||||||
let ips = cache.resolve("clob.polymarket.com").await.unwrap();
|
|
||||||
assert!(!ips.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[ignore = "requires external DNS/network access"]
|
|
||||||
async fn test_dns_cache_prewarm() {
|
|
||||||
let cache = DnsCache::new().await.unwrap();
|
|
||||||
cache.prewarm("clob.polymarket.com").await.unwrap();
|
|
||||||
assert_eq!(cache.cache_size().await, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[ignore = "requires external DNS/network access"]
|
|
||||||
async fn test_dns_cache_clear() {
|
|
||||||
let cache = DnsCache::new().await.unwrap();
|
|
||||||
cache.prewarm("clob.polymarket.com").await.unwrap();
|
|
||||||
cache.clear().await;
|
|
||||||
assert_eq!(cache.cache_size().await, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -179,7 +179,6 @@ pub mod buffer_pool;
|
|||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod connection_manager;
|
pub mod connection_manager;
|
||||||
pub mod decode;
|
pub mod decode;
|
||||||
pub mod dns_cache;
|
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod fill;
|
pub mod fill;
|
||||||
pub mod http_config;
|
pub mod http_config;
|
||||||
|
|||||||
Reference in New Issue
Block a user