chore: i am become speed
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
f930bd37ec
commit
ce5f8bab99
1 changed files with 12 additions and 14 deletions
26
src/main.rs
26
src/main.rs
|
@ -90,15 +90,12 @@ mod nix {
|
||||||
mod net {
|
mod net {
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use reqwest::StatusCode;
|
use reqwest::{StatusCode, ClientBuilder, Client};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
|
|
||||||
#[async_recursion]
|
#[async_recursion]
|
||||||
pub async fn nar_exists(domain: &str, domain_addr: SocketAddr, hash: &str) -> usize {
|
pub async fn nar_exists(client: Client, domain: &str, hash: &str) -> usize {
|
||||||
let response = reqwest::Client::builder()
|
let response = client
|
||||||
.resolve(domain, domain_addr)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
.get(format!("https://{domain}/{hash}.narinfo"))
|
.get(format!("https://{domain}/{hash}.narinfo"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
@ -107,27 +104,27 @@ mod net {
|
||||||
match response.status().as_u16() {
|
match response.status().as_u16() {
|
||||||
200 => 1,
|
200 => 1,
|
||||||
// Retry on ConnectionReset
|
// Retry on ConnectionReset
|
||||||
104 => nar_exists(domain, domain_addr, hash).await,
|
104 => nar_exists(client, domain, hash).await,
|
||||||
_ => 0
|
_ => 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[tokio::main(flavor = "multi_thread", worker_threads = 100)]
|
// #[tokio::main(flavor = "multi_thread", worker_threads = 100)]
|
||||||
|
// #[tokio::main(flavor = "multi_thread", worker_threads = 500)]
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
let matches = cli::build_cli().get_matches();
|
let matches = cli::build_cli().get_matches();
|
||||||
|
|
||||||
let hostname = "cache.nixos.org";
|
let domain = "cache.nixos.org";
|
||||||
let ips: Vec<std::net::IpAddr> = lookup_host(hostname).unwrap();
|
let ips: Vec<std::net::IpAddr> = lookup_host(domain).unwrap();
|
||||||
|
|
||||||
debug!("{:#?}", &ips);
|
debug!("{:#?}", &ips);
|
||||||
|
|
||||||
let ip = ips[0];
|
let domain_addr = SocketAddr::new(ips[0], 443);
|
||||||
|
|
||||||
//let connection_buffer = stream::iter(binding.lines().map(|line| line.to_owned()).collect::<Vec<_>>()); //.buffer_unordered(20);
|
let client = reqwest::Client::builder().resolve(domain, domain_addr).build().unwrap();
|
||||||
//let connection_buffer = stream::iter(binding.lines().map(|line| line.to_owned()).collect::<Vec<_>>()); //.buffer_unordered(20);
|
|
||||||
|
|
||||||
let binding = get_requisites("DBCAC");
|
let binding = get_requisites("DBCAC");
|
||||||
let connection_buffer = binding.lines().map(|line| line.to_owned()).collect::<Vec<_>>();
|
let connection_buffer = binding.lines().map(|line| line.to_owned()).collect::<Vec<_>>();
|
||||||
|
@ -137,9 +134,10 @@ async fn main() -> io::Result<()> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
//.take(1000)
|
//.take(1000)
|
||||||
.map(|hash| {
|
.map(|hash| {
|
||||||
|
let client = client.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
info!("connecting to {hostname} {ip:#?} for {hash}");
|
info!("connecting to {domain} {domain_addr:#?} for {hash}");
|
||||||
net::nar_exists(hostname, SocketAddr::new(ip.clone(), 443), &hash).await
|
net::nar_exists(client, domain, &hash).await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
Loading…
Reference in a new issue