Skip to content

Commit

Permalink
Bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcyrd committed Dec 10, 2018
1 parent 699c242 commit d8923f4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
37 changes: 27 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ members = ["sn0int-registry/sn0int-common",

[dependencies]
sn0int-common = { version="0.3.0", path="sn0int-registry/sn0int-common" }
rustyline = "2"
rustyline = "3"
log = "0.4"
env_logger = "0.6"
hlua-badtouch = "0.4"
Expand Down Expand Up @@ -48,7 +48,7 @@ maplit = "1.0.1"
sloppy-rfc4880 = "0.1.2"
regex = "1.0"
toml = "0.4"
maxminddb = "0.10.0"
maxminddb = "0.12"
tar = "0.4.17"
libflate = "0.1.14"
threadpool = "1.7"
Expand Down
6 changes: 4 additions & 2 deletions src/engine/isolation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::errors::*;
use chrootable_https::dns::Resolver;
use crate::engine::{Environment, Module, Reporter};
use crate::geoip::{GeoIP, AsnDB};
use crate::geoip::{GeoIP, AsnDB, Maxmind};
use crate::psl::Psl;
use serde_json;
use crate::worker::{Event, Event2, LogEvent, ExitEvent, EventSender, EventWithCallback};
Expand Down Expand Up @@ -188,10 +188,12 @@ pub fn spawn_module(module: Module, tx: &EventSender, arg: serde_json::Value, ve
Ok(())
}

pub fn run_worker(geoip: GeoIP, asn: AsnDB, psl: String) -> Result<()> {
pub fn run_worker(geoip: Vec<u8>, asn: Vec<u8>, psl: String) -> Result<()> {
let mut reporter = StdioReporter::setup();
let start = reporter.recv_start()?;

let geoip = GeoIP::from_buf(geoip)?;
let asn = AsnDB::from_buf(asn)?;
let psl = Psl::from_str(&psl)
.context("Failed to load public suffix list")?;

Expand Down
37 changes: 24 additions & 13 deletions src/geoip/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::errors::*;
use crate::archive;
use chrootable_https::Client;
use crate::archive;
use crate::errors::*;
use crate::paths;
use crate::worker;
use maxminddb::{self, geoip2};
use std::fmt;
use std::fs::File;
use std::fs::{self, File};
use std::net::IpAddr;
use std::path::Path;
use crate::paths;
use crate::worker;

pub static GEOIP_CITY_URL: &str = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz";
pub static GEOIP_ASN_URL: &str = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz";
Expand All @@ -22,7 +22,7 @@ pub trait Maxmind: Sized {

fn archive_url() -> &'static str;

fn new(reader: maxminddb::Reader) -> Self;
fn new(reader: maxminddb::Reader<Vec<u8>>) -> Self;

// TODO: refactor this to return Path
fn cache_path() -> Result<String> {
Expand All @@ -44,12 +44,23 @@ pub trait Maxmind: Sized {
Ok(path.to_string())
}

fn open(path: &str) -> Result<Self> {
let reader = maxminddb::Reader::open(path)
.context("Failed to open geoip database")?;
fn from_buf(buf: Vec<u8>) -> Result<Self> {
let reader = maxminddb::Reader::from_source(buf)
.context("Failed to read geoip database")?;
Ok(Self::new(reader))
}

fn open(path: &str) -> Result<Self> {
let buf = fs::read(path)?;
Self::from_buf(buf)
}

fn open_into_buf() -> Result<Vec<u8>> {
let path = Self::cache_path()?;
let buf = fs::read(path)?;
Ok(buf)
}

fn open_or_download() -> Result<Self> {
let path = Self::cache_path()?;

Expand All @@ -73,7 +84,7 @@ pub trait Maxmind: Sized {
}

pub struct GeoIP {
reader: maxminddb::Reader,
reader: maxminddb::Reader<Vec<u8>>,
}

impl fmt::Debug for GeoIP {
Expand All @@ -94,7 +105,7 @@ impl Maxmind for GeoIP {
}

#[inline]
fn new(reader: maxminddb::Reader) -> Self {
fn new(reader: maxminddb::Reader<Vec<u8>>) -> Self {
GeoIP {
reader
}
Expand All @@ -110,7 +121,7 @@ impl GeoIP {
}

pub struct AsnDB {
reader: maxminddb::Reader,
reader: maxminddb::Reader<Vec<u8>>,
}

impl fmt::Debug for AsnDB {
Expand All @@ -131,7 +142,7 @@ impl Maxmind for AsnDB {
}

#[inline]
fn new(reader: maxminddb::Reader) -> Self {
fn new(reader: maxminddb::Reader<Vec<u8>>) -> Self {
AsnDB {
reader
}
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ fn run_run(gargs: &Args, args: &args::Run, config: Config) -> Result<()> {
}

fn run_sandbox() -> Result<()> {
// TODO: this file should be processed after the sandbox is up
let path = GeoIP::cache_path()?;
let geoip = GeoIP::open(&path)?;

let path = AsnDB::cache_path()?;
let asn = AsnDB::open(&path)?;
let geoip = GeoIP::open_into_buf()?;
let asn = AsnDB::open_into_buf()?;
let psl = Psl::open_into_string()?;

sandbox::init()
Expand Down

0 comments on commit d8923f4

Please sign in to comment.