Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
drozdziak1 committed Sep 19, 2018
2 parents 57fb512 + 1b9e244 commit 262bd2e
Show file tree
Hide file tree
Showing 27 changed files with 406 additions and 154 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "althea_rs"
version = "0.1.6"
version = "0.1.7"
authors = ["Stan Drozd <[email protected]>"]

[features]
Expand Down
12 changes: 5 additions & 7 deletions althea_kernel_interface/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ fn test_filter_table_table() {

fn parse_ipset(input: &str) -> Result<HashMap<(IpAddr, String), u64>, Error> {
lazy_static! {
static ref RE: Regex = Regex::new(
r"(?m)^add \S+ ([a-f0-9:]+),(wg\d+) packets (\d+) bytes (\d+)"
).expect("Unable to compile regular expression");
static ref RE: Regex =
Regex::new(r"(?m)^add \S+ ([a-f0-9:]+),(wg\d+) packets (\d+) bytes (\d+)")
.expect("Unable to compile regular expression");
}
let mut map = HashMap::new();

Expand Down Expand Up @@ -301,8 +301,7 @@ fn test_read_counters() {
Ok(Output {
stdout: b"
add xxx fd00::dead:beef,wg42 packets 111 bytes 222
"
.to_vec(),
".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
Expand All @@ -328,7 +327,6 @@ add xxx fd00::dead:beef,wg42 packets 111 bytes 222
.get(&(
IpAddr::V6(Ipv6Addr::new(0xfd00, 0, 0, 0, 0, 0, 0xdead, 0xbeef)),
"wg42".into(),
))
.expect("Unable to find key");
)).expect("Unable to find key");
assert_eq!(value, &(222u64 + 111u64 * 40));
}
4 changes: 2 additions & 2 deletions althea_kernel_interface/src/exit_client_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{KernelInterface, KernelInterfaceError};

use failure::Error;

use std::net::{IpAddr, SocketAddr};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

impl KernelInterface {
pub fn set_client_exit_tunnel_config(
Expand Down Expand Up @@ -58,7 +58,7 @@ impl KernelInterface {
],
)?;

let prev_ip = self.get_global_device_ip("wg_exit");
let prev_ip: Result<Ipv4Addr, Error> = self.get_global_device_ip_v4("wg_exit");

match prev_ip {
Ok(prev_ip) => {
Expand Down
12 changes: 5 additions & 7 deletions althea_kernel_interface/src/exit_server_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn test_exit_filter_target_output() {

fn parse_exit_ipset(input: &str) -> Result<HashMap<IpAddr, u64>, Error> {
lazy_static! {
static ref RE: Regex = Regex::new(
r"(?m)^add \S+ (fd00::[a-f0-9:]+) packets (\d+) bytes (\d+)"
).expect("Unable to compile regular expression");
static ref RE: Regex =
Regex::new(r"(?m)^add \S+ (fd00::[a-f0-9:]+) packets (\d+) bytes (\d+)")
.expect("Unable to compile regular expression");
}
let mut map = HashMap::new();

Expand Down Expand Up @@ -301,8 +301,7 @@ fn test_read_exit_server_counters() {
Ok(Output {
stdout: b"
add asdf fd00::dead:beef packets 100 bytes 200
"
.to_vec(),
".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
Expand All @@ -327,7 +326,6 @@ add asdf fd00::dead:beef packets 100 bytes 200
let value = result
.get(&IpAddr::V6(Ipv6Addr::new(
0xfd00, 0, 0, 0, 0, 0, 0xdead, 0xbeef,
)))
.expect("Unable to find key");
))).expect("Unable to find key");
assert_eq!(value, &(200u64 + 100u64 * 80));
}
3 changes: 1 addition & 2 deletions althea_kernel_interface/src/interface_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ fn test_get_wg_remote_ip() {
assert_eq!(args, &["show", "wg0", "endpoints"]);
Ok(Output {
stdout: b"fvLYbeMV+RYbzJEc4lNEPuK8ulva/5wcSJBz0W5t3hM= 71.8.186.226:60000\
"
.to_vec(),
".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
Expand Down
51 changes: 42 additions & 9 deletions althea_kernel_interface/src/link_local_tools.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{KernelInterface, KernelInterfaceError};

use std::net::{IpAddr, Ipv6Addr};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

use regex::Regex;

Expand All @@ -12,9 +12,13 @@ impl KernelInterface {
let output = self.run_command("ip", &["addr", "show", "dev", dev, "scope", "link"])?;
trace!("Got {:?} from `ip addr`", output);

let re = Regex::new(r"inet6 (\S*?)(/[0-9]+)? scope link").unwrap();
let str = String::from_utf8(output.stdout)?;
let cap = re.captures(&str);
lazy_static! {
static ref RE: Regex = Regex::new(r"inet6 (\S*?)(/[0-9]+)? scope link")
.expect("Unable to compile regular expression");
}

let cap_str = String::from_utf8(output.stdout)?;
let cap = RE.captures(&cap_str);
if let Some(cap) = cap {
trace!("got link local IP of {} from device {}", &cap[1], &dev);
Ok(cap[1].parse::<Ipv6Addr>()?)
Expand All @@ -30,9 +34,13 @@ impl KernelInterface {
let output = self.run_command("ip", &["addr", "show", "dev", dev, "scope", "global"])?;
trace!("Got {:?} from `ip addr`", output);

let re = Regex::new(r"inet (\S*?)(/[0-9]+)? scope global").unwrap();
let str = String::from_utf8(output.stdout)?;
let cap = re.captures(&str);
lazy_static! {
static ref RE: Regex = Regex::new(r"inet (\S*?)(/[0-9]+)? scope global")
.expect("Unable to compile regular expression");
}

let cap_str = String::from_utf8(output.stdout)?;
let cap = RE.captures(&cap_str);
if let Some(cap) = cap {
trace!("got global IP of {} from device {}", &cap[1], &dev);
Ok(cap[1].parse::<Ipv6Addr>()?)
Expand All @@ -43,6 +51,27 @@ impl KernelInterface {
}
}

pub fn get_global_device_ip_v4(&self, dev: &str) -> Result<Ipv4Addr, Error> {
let output = self.run_command("ip", &["addr", "show", "dev", dev, "scope", "global"])?;
trace!("Got {:?} from `ip addr`", output);

lazy_static! {
static ref RE: Regex = Regex::new(r"inet (\S*?)(/[0-9]+)? scope global")
.expect("Unable to compile regular expression");
}

let cap_str = String::from_utf8(output.stdout)?;
let cap = RE.captures(&cap_str);
if let Some(cap) = cap {
trace!("got global IP of {} from device {}", &cap[1], &dev);
Ok(cap[1].parse::<Ipv4Addr>()?)
} else {
Err(KernelInterfaceError::RuntimeError(
"No global found or no interface found".to_string(),
).into())
}
}

/// Given a neighboring link local ip, return the device name
pub fn get_device_name(&self, their_ip: IpAddr) -> Result<String, Error> {
let neigh = self.get_neighbors()?;
Expand Down Expand Up @@ -91,8 +120,12 @@ impl KernelInterface {
pub fn get_iface_index(&self, name: &str) -> Result<u32, Error> {
let links = String::from_utf8(self.run_command("ip", &["link"])?.stdout)?;

let re = Regex::new(r"([0-9]+): (.*?)(:|@)").unwrap();
for caps in re.captures_iter(&links) {
lazy_static! {
static ref RE: Regex =
Regex::new(r"([0-9]+): (.*?)(:|@)").expect("Unable to compile regular expression");
}

for caps in RE.captures_iter(&links) {
if name == &caps[2] {
return Ok(caps[1].parse()?);
}
Expand Down
54 changes: 54 additions & 0 deletions althea_kernel_interface/src/setup_wg_if.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::{KernelInterface, KernelInterfaceError};
use failure::err_msg;
use std::str::from_utf8;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use failure::Error;

Expand Down Expand Up @@ -49,6 +51,27 @@ impl KernelInterface {
}
Ok(())
}

/// Returns the number of clients that are active on the wg_exit tunnel
pub fn get_wg_exit_clients_online(&self) -> Result<u32, Error> {
let output = self.run_command("wg", &["show", "wg_exit", "latest-handshakes"])?;
let mut num: u32 = 0;
let out = String::from_utf8(output.stdout)?;
for line in out.lines() {
let content: Vec<&str> = line.split("\t").collect();
let mut itr = content.iter();
itr.next();
let timestamp = itr
.next()
.ok_or(err_msg("Option did not contain a value."))?;
let d = UNIX_EPOCH + Duration::from_secs(timestamp.parse()?);

if SystemTime::now().duration_since(d)? < Duration::new(600, 0) {
num += 1;
}
}
Ok(num)
}
}

#[test]
Expand Down Expand Up @@ -90,3 +113,34 @@ fn test_setup_wg_if_linux() {

KI.setup_wg_if().unwrap();
}

#[test]
fn test_get_wg_exit_clients_online() {
use KI;

use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use std::process::Output;

let mut counter = 0;

let link_args = &["show", "wg_exit", "latest-handshakes"];
KI.set_mock(Box::new(move |program, args| {
assert_eq!(program, "wg");
counter += 1;

match counter {
1 => {
assert_eq!(args, link_args);
Ok(Output{
stdout: format!("88gbNAZx7NoNK9hatYuDkeZOjQ8EBmJ8VBpcFhXPqHs= {}\nW1BwNSC9ulTutCg53KIlo+z2ihkXao3sXHaBBpaCXEw= 1536936247\n9jRr6euMHu3tBIsZyqxUmjbuKVVFZCBOYApOR2pLNkQ= 0", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()).as_bytes().to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
_ => panic!("command called too many times"),
}
}));

assert_eq!(KI.get_wg_exit_clients_online().unwrap(), 1);
}
2 changes: 1 addition & 1 deletion althea_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate actix;
pub mod interop;
pub mod rtt;

pub use ethereum_types::{Address, H160, Public, Secret, Signature, U256};
pub use ethereum_types::{Address, Public, Secret, Signature, H160, U256};

pub use interop::*;
pub use rtt::RTTimestamps;
Expand Down
5 changes: 4 additions & 1 deletion bounty_hunter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![cfg_attr(feature = "system_alloc", feature(alloc_system, global_allocator, allocator_api))]
#![cfg_attr(
feature = "system_alloc",
feature(alloc_system, global_allocator, allocator_api)
)]

#[cfg(feature = "system_alloc")]
extern crate alloc_system;
Expand Down
2 changes: 1 addition & 1 deletion rita/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rita"
version = "0.1.6"
version = "0.1.7"
authors = ["Jehan <[email protected]>", "Ben <[email protected]>"]
build = "build.rs"

Expand Down
29 changes: 15 additions & 14 deletions rita/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//! This file initilizes the dashboard endpoints for the client as well as the common and client
//! specific actors.

#![cfg_attr(feature = "system_alloc", feature(alloc_system, allocator_api))]
#![cfg_attr(
feature = "system_alloc",
feature(alloc_system, allocator_api)
)]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]

Expand Down Expand Up @@ -208,10 +211,10 @@ fn main() {
r.method(Method::POST).with(make_payments)
})
}).workers(1)
.bind(format!("[::0]:{}", SETTING.get_network().rita_contact_port))
.unwrap()
.shutdown_timeout(0)
.start();
.bind(format!("[::0]:{}", SETTING.get_network().rita_contact_port))
.unwrap()
.shutdown_timeout(0)
.start();

// dashboard
server::new(|| {
Expand All @@ -233,8 +236,7 @@ fn main() {
"/exits/{name}/verify/{code}",
Method::POST,
verify_on_exit_with_code,
)
.route("/info", Method::GET, get_own_info)
).route("/info", Method::GET, get_own_info)
.route("/version", Method::GET, version)
.route("/wipe", Method::POST, wipe)
.route("/debts", Method::GET, get_debts)
Expand All @@ -246,13 +248,12 @@ fn main() {
remove_from_dao_list,
)
}).workers(1)
.bind(format!(
"[::0]:{}",
SETTING.get_network().rita_dashboard_port
))
.unwrap()
.shutdown_timeout(0)
.start();
.bind(format!(
"[::0]:{}",
SETTING.get_network().rita_dashboard_port
)).unwrap()
.shutdown_timeout(0)
.start();

let common = rita_common::rita_loop::RitaLoop::new();
let _: Addr<_> = common.start();
Expand Down
Loading

0 comments on commit 262bd2e

Please sign in to comment.