Skip to content

Commit

Permalink
Remove all the compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Tricaud committed Apr 14, 2020
1 parent 23f45b4 commit 2ae07b0
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 158 deletions.
20 changes: 0 additions & 20 deletions src/client/attribute.rs

This file was deleted.

38 changes: 0 additions & 38 deletions src/client/db.rs

This file was deleted.

8 changes: 0 additions & 8 deletions src/client/db_read.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/client/db_write.rs

This file was deleted.

35 changes: 12 additions & 23 deletions src/client/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
extern crate rustyline;
extern crate dirs;
// extern crate dirs;
extern crate regex;
//extern crate clap;

mod db_write;
mod db_read;
mod attribute;
mod db;

use rustyline::error::ReadlineError;
use rustyline::Editor;
use regex::Regex;
//use clap::App;

//use attribute::Attribute;



fn main() {
// App::new("Sighting DB")
// .version("0.0.1")
Expand All @@ -26,18 +17,16 @@ fn main() {

println!("Sigthing DB - count attributes at scale\n(c) Devo Inc 2019 - Written by Sebastien Tricaud");

let mut db = db::Database::new();

// let mut histfile = String::from("");
match dirs::home_dir() {
Some(mut dir) => {
dir = dir.join(".sightingdb_history");
// histfile = dir.to_string_lossy().to_string();
}
None => {
// histfile = String::from(".sightingdb_history");
}
}
// match dirs::home_dir() {
// Some(mut dir) => {
// dir = dir.join(".sightingdb_history");
// // histfile = dir.to_string_lossy().to_string();
// }
// None => {
// // histfile = String::from(".sightingdb_history");
// }
// }

let rw_re = Regex::new(r"^(r|w)\s(\S+)\s(.*)").unwrap();

Expand All @@ -55,10 +44,10 @@ fn main() {
let value = caps.get(3).map_or("", |m| m.as_str());

if db_action == "r" {
db_read::read(&mut db, path, value);
println!("read namespace={}; value={}", path, value);
}
if db_action == "w" {
db_write::write(&mut db, path, value);
println!("write namespace={}; value={}", path, value);
}
},
Err(ReadlineError::Interrupted) => {
Expand Down
15 changes: 6 additions & 9 deletions src/daemon/db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde::{Serialize};
use regex::Regex;

use crate::attribute::Attribute;
Expand Down Expand Up @@ -33,15 +33,14 @@ impl Database {
pub fn write(&mut self, path: &str, value: &str, timestamp: i64, write_consensus: bool) -> u128 {
let valuestable = self.hashtable.get_mut(&path.to_string());
let mut new_value_to_path = false;
let mut retval = 0;
let mut consensus_count = 0;
let retval;

match valuestable {
Some(valuestable) => {
//let mut valuestable = self.hashtable.get_mut(&path.to_string()).unwrap();
let attr = valuestable.get(&value.to_string());
match attr {
Some(attr) => {
Some(_attr) => {
let iattr = valuestable.get_mut(&value.to_string()).unwrap();
if timestamp > 0 {
iattr.incr_from_timestamp(timestamp);
Expand Down Expand Up @@ -95,11 +94,10 @@ impl Database {
return retval;
}
pub fn new_consensus(&mut self, path: &str, value: &str, consensus_count: u128) -> u128 {
let count: u32;
let valuestable = self.hashtable.get_mut(&path.to_string()).unwrap();
let attr = valuestable.get_mut(&value.to_string());
match attr {
Some(attr) => {
Some(_attr) => {
let iattr = valuestable.get_mut(&value.to_string()).unwrap();
iattr.set_consensus(consensus_count);
return iattr.consensus;
Expand All @@ -110,7 +108,6 @@ impl Database {
};
}
pub fn get_count(&mut self, path: &str, value: &str) -> u128 {
let count: u128;
let valuestable = self.hashtable.get_mut(&path.to_string()).unwrap();
let attr = valuestable.get_mut(&value.to_string());
match attr {
Expand All @@ -128,8 +125,8 @@ impl Database {
let attr = valuestable.get_mut(&value.to_string());
match attr {
Some(attr) => {
if (attr.ttl > 0) {
println!("{:?}", attr);
if attr.ttl > 0 {
println!("FIXME, IMPLEMENT TTL. {:?}", attr);
}
attr.consensus = consensus_count;

Expand Down
9 changes: 4 additions & 5 deletions src/daemon/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use daemonize::Daemonize;
use ansi_term::Color::Red;
use ini::Ini;

use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder, Error};
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};

use qstring::QString;
Expand Down Expand Up @@ -97,7 +97,6 @@ fn read(data: web::Data<Arc<Mutex<SharedState>>>, _req: HttpRequest) -> impl Res
// fn write(db: web::Data<Mutex<db::Database>>, _req: HttpRequest) -> impl Responder {
fn write(data: web::Data<Arc<Mutex<SharedState>>>, _req: HttpRequest) -> HttpResponse {
let sharedstate = &mut *data.lock().unwrap();
let mut could_write = false;

// println!("{:?}", _req.path());
let (_, path) = _req.path().split_at(3); // We remove '/w/'
Expand All @@ -108,7 +107,7 @@ fn write(data: web::Data<Arc<Mutex<SharedState>>>, _req: HttpRequest) -> HttpRes
Some(v) => {
let timestamp = query_string.get("timestamp").unwrap_or("0");
let timestamp_i = timestamp.parse::<i64>().unwrap_or(0);
could_write = sighting_writer::write(&mut sharedstate.db, path, v, timestamp_i);
let could_write = sighting_writer::write(&mut sharedstate.db, path, v, timestamp_i);
if could_write {
return HttpResponse::Ok().json(Message{message: String::from("ok")});
} else {
Expand Down Expand Up @@ -179,7 +178,7 @@ fn read_bulk_with_stats(data: web::Data<Arc<Mutex<SharedState>>>, postdata: web:
fn write_bulk(data: web::Data<Arc<Mutex<SharedState>>>, postdata: web::Json<PostData>, _req: HttpRequest) -> impl Responder {
let sharedstate = &mut *data.lock().unwrap();
let mut could_write = false;

for i in &postdata.items {
if i.value.len() > 0 { // There is no need to write a value that does not exists
let timestamp = i.timestamp.unwrap_or(0);
Expand Down Expand Up @@ -276,7 +275,7 @@ fn main() {
// }

let configarg = matches.value_of("config");
let mut configstr = String::from("");
let configstr;
match configarg {
Some(_configstr) => { configstr = _configstr.to_string(); },
None => {
Expand Down
66 changes: 33 additions & 33 deletions src/daemon/sighting_configure.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
use std::collections::HashMap;
// use std::collections::HashMap;

#[derive(PartialEq, Eq)]
pub enum ConfigStorage {
IN_MEMORY,
ON_DISK,
}
// #[derive(PartialEq, Eq)]
// pub enum ConfigStorage {
// IN_MEMORY,
// ON_DISK,
// }

pub struct Configuration {
storage: HashMap<String, ConfigStorage>,
}
// pub struct Configuration {
// storage: HashMap<String, ConfigStorage>,
// }

impl Configuration {
pub fn new() -> Configuration {
Configuration {
storage: HashMap::new(),
}
}
pub fn set_storage(&mut self, storage: ConfigStorage, path: String) {
self.storage.insert(path, storage);
}
pub fn get_storage(&mut self, path: String) -> String {
let storageopt = self.storage.get_mut(&path);
match storageopt {
Some(storageopt) => {
match storageopt {
ConfigStorage::IN_MEMORY => { return String::from("IN_MEMORY"); },
ConfigStorage::ON_DISK => { return String::from("ON_DISK"); },
}
},
None => {
return String::from("IN_MEMORY");
}
}
}
// impl Configuration {
// pub fn new() -> Configuration {
// Configuration {
// storage: HashMap::new(),
// }
// }
// pub fn set_storage(&mut self, storage: ConfigStorage, path: String) {
// self.storage.insert(path, storage);
// }
// pub fn get_storage(&mut self, path: String) -> String {
// let storageopt = self.storage.get_mut(&path);
// match storageopt {
// Some(storageopt) => {
// match storageopt {
// ConfigStorage::IN_MEMORY => { return String::from("IN_MEMORY"); },
// ConfigStorage::ON_DISK => { return String::from("ON_DISK"); },
// }
// },
// None => {
// return String::from("IN_MEMORY");
// }
// }
// }

}
// }

// pub fn set(path: &str, value: &str) {
// println!("Configuring path {}", path);
Expand Down
30 changes: 15 additions & 15 deletions src/daemon/sighting_reader.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use crate::db::Database;
use base64::{decode_config, URL_SAFE_NO_PAD};
use serde::{Deserialize, Serialize};
use serde::{Serialize};

#[derive(Serialize)]
pub struct Message {
message: String
}

#[derive(Deserialize)]
struct NotFound {
error: String,
path: String,
value: String
}

//{"error":"Path not found","path":"security_intelligence","value":"MTAuNTIuNjAuNjk"}
//{"value":"MTAuNTIuNjAuNjk","first_seen":1582161107,"last_seen":1582161107,"count":1,"tags":"","ttl":0}
// #[derive(Deserialize)]
// struct NotFound {
// error: String,
// path: String,
// value: String
// }

pub fn read(db: &mut Database, path: &str, value: &str, with_stats: bool) -> String
{
Expand All @@ -36,7 +32,11 @@ pub fn read(db: &mut Database, path: &str, value: &str, with_stats: bool) -> Str
return attr;
}

// Our internal reading does not trigger shadow sightings
pub fn read_internal(db: &mut Database, path: &str, value: &str, with_stats: bool) -> String {
return db.get_attr(path, value, with_stats, 0);
}
// Our internal reading does not trigger shadow sightings.
// USELESS FOR NOW, but will need to reactivate once we have the possibility to skip shadow if we want to
// pub fn read_internal(db: &mut Database, path: &str, value: &str, with_stats: bool) -> String {
// let consensus = db.get_count(&"_all".to_string(), value);
// let attr = db.get_attr(path, value, with_stats, consensus);

// return attr;
// }

0 comments on commit 2ae07b0

Please sign in to comment.