This commit is contained in:
Frank Denis 2019-02-18 14:41:52 +01:00
parent 39ee8bc5bd
commit 60e4052d65
5 changed files with 10 additions and 36 deletions

20
Cargo.lock generated
View File

@ -87,14 +87,6 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "clippy"
version = "0.0.302"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
@ -235,7 +227,6 @@ name = "iptoasn-webservice"
version = "0.2.2"
dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.302 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"horrorshow 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)",
@ -667,15 +658,6 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
@ -817,7 +799,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum clippy 0.0.302 (registry+https://github.com/rust-lang/crates.io-index)" = "d911ee15579a3f50880d8c1d59ef6e79f9533127a3bd342462f5d584f5e8c294"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum conduit-mime-types 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95ca30253581af809925ef68c2641cc140d6183f43e12e0af4992d53768bd7b8"
"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
@ -886,7 +867,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a"
"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"

View File

@ -18,7 +18,6 @@ iron = "0.5"
log = "0.4"
router = "0.5"
serde_json = "1.0"
clippy = {version = "0", optional = true}
unicase = "1"
[features]

View File

@ -1,6 +1,6 @@
use flate2::read::GzDecoder;
use hyper::{self, Client};
use hyper::net::HttpsConnector;
use hyper::{self, Client};
use hyper_native_tls::NativeTlsClient;
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use std::collections::BTreeSet;
@ -67,9 +67,7 @@ impl ASNs {
}
assert_eq!(res.status, hyper::Ok);
let mut data = String::new();
GzDecoder::new(res)
.read_to_string(&mut data)
.unwrap();
GzDecoder::new(res).read_to_string(&mut data).unwrap();
let mut asns = BTreeSet::new();
for line in data.split_terminator('\n') {
let mut parts = line.split('\t');
@ -79,16 +77,16 @@ impl ASNs {
let country = parts.next().unwrap().to_owned();
let description = parts.next().unwrap().to_owned();
let asn = ASN {
first_ip: first_ip,
last_ip: last_ip,
number: number,
country: country,
description: description,
first_ip,
last_ip,
number,
country,
description,
};
asns.insert(asn);
}
info!("Database loaded");
Ok(ASNs { asns: asns })
Ok(ASNs { asns })
}
pub fn lookup_by_ip(&self, ip: IpAddr) -> Option<&ASN> {

View File

@ -1,6 +1,3 @@
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
extern crate clap;
extern crate flate2;
#[macro_use]

View File

@ -1,11 +1,11 @@
use asns::*;
use horrorshow::prelude::*;
use iron::{typemap, BeforeMiddleware};
use iron::headers::{Accept, CacheControl, CacheDirective, Vary};
use iron::mime::*;
use iron::modifiers::Header;
use iron::prelude::*;
use iron::status;
use iron::{typemap, BeforeMiddleware};
use router::Router;
use serde_json;
use std::net::IpAddr;
@ -25,7 +25,7 @@ impl typemap::Key for ASNsMiddleware {
impl ASNsMiddleware {
fn new(asns_arc: Arc<RwLock<Arc<ASNs>>>) -> ASNsMiddleware {
ASNsMiddleware { asns_arc: asns_arc }
ASNsMiddleware { asns_arc }
}
}