feat: RsProcess

This commit is contained in:
2024-04-16 22:34:50 +08:00
parent 90ff0025d6
commit 603ef46f10
16 changed files with 1456 additions and 226 deletions

View File

@ -1,15 +1,15 @@
use hickory_resolver::config::{NameServerConfigGroup, ResolverConfig, ResolverOpts};
use hickory_resolver::{lookup_ip::LookupIpIntoIter, TokioAsyncResolver};
use lazy_static::lazy_static;
use once_cell::sync::OnceCell;
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
use std::collections::HashMap;
use std::io;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::{Arc, RwLock};
use lazy_static::lazy_static;
lazy_static! {
pub static ref MY_HOSTS_MAP: RwLock<HashMap<String, IpAddr>> = RwLock::from(HashMap::new());
pub static ref MY_HOSTS_MAP: RwLock<HashMap<String, IpAddr>> = RwLock::from(HashMap::new());
}
/// Wrapper around an `AsyncResolver`, which implements the `Resolve` trait.
@ -60,10 +60,7 @@ impl MyHickoryDnsResolver {
pub(crate) async fn lookup_ips(&self, name: String) -> anyhow::Result<Vec<String>> {
let resolver = self.state.get_or_try_init(new_resolver)?;
let ips = resolver.ipv4_lookup(name).await?;
let t = ips
.iter()
.map(|ip| ip.to_string())
.collect::<Vec<_>>();
let t = ips.iter().map(|ip| ip.to_string()).collect::<Vec<_>>();
Ok(t)
}
}
@ -88,7 +85,9 @@ fn new_resolver() -> io::Result<TokioAsyncResolver> {
IpAddr::V4(Ipv4Addr::new(166, 111, 8, 28)),
IpAddr::V4(Ipv4Addr::new(101, 226, 4, 6)),
IpAddr::V4(Ipv4Addr::new(114, 114, 114, 114)),
], 53, false,
],
53,
false,
);
let cfg = ResolverConfig::from_parts(None, vec![], group);
let mut opts = ResolverOpts::default();

View File

@ -1,9 +1,9 @@
pub mod dns;
use scopeguard::defer;
use lazy_static::lazy_static;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use reqwest::{Method, RequestBuilder};
use scopeguard::defer;
use std::collections::HashMap;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
@ -45,7 +45,8 @@ fn _hyper_version_to_my_version(v: reqwest::Version) -> MyHttpVersion {
lazy_static! {
static ref DEFAULT_HEADER: RwLock<HeaderMap> = RwLock::from(HeaderMap::new());
static ref DNS_CLIENT: Arc<dns::MyHickoryDnsResolver> = Arc::from(dns::MyHickoryDnsResolver::default());
static ref DNS_CLIENT: Arc<dns::MyHickoryDnsResolver> =
Arc::from(dns::MyHickoryDnsResolver::default());
static ref HTTP_CLIENT: reqwest::Client = new_http_client(true);
}
@ -88,7 +89,11 @@ pub async fn fetch(
if address_clone.is_some() {
let addr = std::net::IpAddr::from_str(with_ip_address.unwrap().as_str()).unwrap();
let mut hosts = dns::MY_HOSTS_MAP.write().unwrap();
let url_host = Url::from_str(url.as_str()).unwrap().host().unwrap().to_string();
let url_host = Url::from_str(url.as_str())
.unwrap()
.host()
.unwrap()
.to_string();
hosts.insert(url_host, addr);
}