Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

zonemaster-core

  • Clone with SSH
  • Clone with HTTPS
  • Gaël Berthaud-Müller's avatar
    Gaël authored
    15769984
    History
    Name Last commit Last update
    src
    .gitignore
    Cargo.lock
    Cargo.toml
    README.md

    Zonemaster Core

    Example:

    use chrono::Utc;
    use tokio::runtime;
    use trust_dns_client::rr::{Name, RecordType};
    
    use zonemaster_core::clients::{DnsClient, MemoryCache, Lookup};
    use zonemaster_core::question::{Question, Protocol};
    
    fn main() -> Result<(), Box<dyn std::error::Error>> {
        let rt  = runtime::Runtime::new()?;
        let dns_client = DnsClient {
            bind_addr6: None,
            bind_addr4: None,
            timeout: 2000,
            retry: 2,
            retrans: 1000,
        };
    
        let question = Question {
            qname: Name::from_utf8("bksp.space").unwrap(),
            qtype: RecordType::AAAA,
            proto: Protocol::Udp,
            recursion_desired: false,
            edns_config: None,
        };
    
        let cache = MemoryCache::new().chain_lookup_client(Box::new(MemoryCache::new().chain_lookup_client(Box::new(dns_client))));
    
        rt.block_on(async {
            for _ in 0..2 {
                let started = Utc::now().timestamp_millis();
                let res = cache.lookup_many(question.clone(), &vec![
                    "142.4.213.71".parse().unwrap(),
                    "163.172.102.220".parse().unwrap(),
                    "135.181.62.83".parse().unwrap(),
                    "2607:5300:60:1247::1".parse().unwrap(),
                    "2001:bc8:24d8::".parse().unwrap(),
                    "2a01:4f9:4b:415d::1".parse().unwrap(),
                ]).await;
                let finished = Utc::now().timestamp_millis();
                let mut cum = 0;
                for (server, (response, source)) in &res {
                    cum += response.duration;
                    println!("{} -> {} {}", server, response.duration, source);
                }
                println!("tot = {}, cum = {}", finished - started, cum);
                //cache.lookup_one(question.clone(), "142.4.213.71".parse().unwrap()).await;
            }
        });
        Ok(())
    }