Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeInclusiveMap more suitable? #1

Open
jeffparsons opened this issue Aug 23, 2021 · 0 comments
Open

RangeInclusiveMap more suitable? #1

jeffparsons opened this issue Aug 23, 2021 · 0 comments

Comments

@jeffparsons
Copy link

jeffparsons commented Aug 23, 2021

Hi there,

In this code:

geph4-exit/src/asn.rs

Lines 11 to 38 in a91fda6

static IPV4_MAP: Lazy<RangeMap<Ipv4Addr, u32>> = Lazy::new(|| {
use std::io::prelude::*;
let resp = ureq::get("https://iptoasn.com/data/ip2asn-v4.tsv.gz").call();
if resp.status() != 200 {
panic!("iptoasn.com failed")
}
let reader = resp.into_reader();
let reader = BufReader::new(GzDecoder::new(BufReader::new(reader)));
let mut toret = RangeMap::new();
for (idx, line) in reader.lines().enumerate() {
let line = line.expect("I/O error while downloading ASN database");
if idx % 1000 == 0 {
log::debug!("loading line {} of ASN database...", idx);
}
let elems: Vec<&str> = line.split_ascii_whitespace().collect();
if elems.len() < 3 {
log::warn!("skipping line in ASN database: {}", line)
} else {
let start: Ipv4Addr = elems[0].parse().unwrap();
let end: Ipv4Addr = next_ip(elems[1].parse().unwrap());
let asn: u32 = elems[2].parse().unwrap();
if end > start {
toret.insert(start..end, asn);
}
}
}
toret
});

It looks like the ASN database you're importing works with inclusive ranges. Might it therefore be more natural to use RangeInclusiveMap to store/query this, and not need the next_ip function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant