~jpastuszek/asn-db

2d917052fccd350c03a79e6d9c2103c540535dd5 — Jakub Pastuszek 8 months ago 83c70b7 master
better test
2 files changed, 24 insertions(+), 1 deletions(-)

M ip2asn-v4.tsv
M src/lib.rs
M ip2asn-v4.tsv => ip2asn-v4.tsv +3 -1
@@ 1,4 1,6 @@
1.1.1.0	1.1.1.255	13335	US	CLOUDFLARENET - Cloudflare, Inc.
1.1.1.0	1.1.1.0	13335	US	CLOUDFLARENET - Cloudflare, Inc.
1.1.1.1	1.1.1.1	7497	CN	CSTNET-AS-AP Computer Network Information Center
1.1.1.2	1.1.1.255	13335	US	CLOUDFLARENET - Cloudflare, Inc.
8.8.4.0	8.8.4.255	15169	US	GOOGLE - Google LLC
8.8.8.0	8.8.8.255	15169	US	GOOGLE - Google LLC
8.34.208.0	8.34.215.255	15169	US	GOOGLE - Google LLC

M src/lib.rs => src/lib.rs +21 -0
@@ 264,6 264,7 @@ impl From<ErrorContext<bincode::Error, &'static str>> for DbError {
//TODO: Use eytzinger layout - requires non exact search support.
//TODO: Support for mmap'ed files to reduce memory usage?
//TODO: IPv6 support.
//TODO: Support providing all subnets of matched range.
/// ASN record database that is optimized for lookup by an IP address.
pub struct Db(Vec<Record>);



@@ 351,9 352,19 @@ mod tests {
        let db = Db::form_tsv(BufReader::new(File::open("ip2asn-v4.tsv").unwrap())).unwrap();

        assert!(db
            .lookup("1.1.1.0".parse().unwrap())
            .unwrap()
            .owner
            .contains("CLOUDFLARENET"));
        assert!(db
            .lookup("1.1.1.1".parse().unwrap())
            .unwrap()
            .owner
            .contains("CSTNET-AS-AP Computer Network Information Center"));
        assert!(db
            .lookup("1.1.1.2".parse().unwrap())
            .unwrap()
            .owner
            .contains("CLOUDFLARENET"));
        assert!(db
            .lookup("8.8.8.8".parse().unwrap())


@@ 378,9 389,19 @@ mod tests {
        drop(temp_dir);

        assert!(db
            .lookup("1.1.1.0".parse().unwrap())
            .unwrap()
            .owner
            .contains("CLOUDFLARENET"));
        assert!(db
            .lookup("1.1.1.1".parse().unwrap())
            .unwrap()
            .owner
            .contains("CSTNET-AS-AP Computer Network Information Center"));
        assert!(db
            .lookup("1.1.1.2".parse().unwrap())
            .unwrap()
            .owner
            .contains("CLOUDFLARENET"));
        assert!(db
            .lookup("8.8.8.8".parse().unwrap())