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 Jul 27, 2018
2 parents a165ddc + 056bd0a commit dd85e7c
Show file tree
Hide file tree
Showing 62 changed files with 2,439 additions and 1,031 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
target-mac
**/*.rs.bk
.idea
**/test.db
**/*.db
test.db-journal
*.log
/scripts/staging_dir/
integration-tests/private-key*
integration-tests/rita-settings*
integration-tests/staging*
integration-tests/althea_rs_*
integration-tests/target*
integration-tests/target*
integration-tests/mail/*
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libsqlite3-dev iperf3 python3-pip bridge-utils wireguard linux-source linux-headers-$(uname -r) curl git libssl-dev pkg-config build-essential ipset
- which diesel || cargo install diesel_cli --no-default-features --features sqlite
- sudo cp $(which diesel) /usr/bin
env:
- TEST_COMMAND="cargo install rustfmt-nightly --force && cargo fmt --all -- --check"
- TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo fmt --all -- --check"
- TEST_COMMAND="cargo build --verbose --all"
- TEST_COMMAND="./integration-tests/cross-build.sh"
- TEST_COMMAND="cargo test --verbose --all" RUST_TEST_THREADS=1
- TEST_COMMAND="./integration-tests/rita.sh" BUILD_BABELD=1 INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- TEST_COMMAND="./integration-tests/rita.sh" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=release COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=master COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
rust:
- stable
- beta
Expand All @@ -21,10 +24,18 @@ script:
matrix:
exclude:
- rust: stable
env: TEST_COMMAND="cargo install rustfmt-nightly --force && cargo fmt --all -- --check"
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo fmt --all -- --check"
- rust: beta
env: TEST_COMMAND="cargo install rustfmt-nightly --force && cargo fmt --all -- --check"
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo fmt --all -- --check"
- rust: stable
env: TEST_COMMAND="./integration-tests/cross-build.sh"
- rust: beta
env: TEST_COMMAND="./integration-tests/cross-build.sh"
- rust: stable
env: TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=release COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- rust: beta
env: TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=release COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- rust: stable
env: TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=master COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
- rust: beta
env: TEST_COMMAND="./integration-tests/rita.sh" REVISION_B=master COMPAT_LAYOUT="inner_ring_old" INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR="1.5" VERBOSE=1
977 changes: 612 additions & 365 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "althea_rs"
version = "0.1.3"
version = "0.1.4"
authors = ["Stan Drozd <[email protected]>"]

[dependencies]
Expand All @@ -11,9 +11,12 @@ members = ["althea_kernel_interface", "bounty_hunter", "settings", "clu", "exit_

[profile.release]
opt-level = "z"
debug=true
lto = true
codegen-units = 1
incremental = false

[patch.crates-io]
actix = { git = "https://github.com/kingoflolz/actix", branch = "custom-resolver" }
actix = { git = "https://github.com/kingoflolz/actix.git", branch = "althea-mesh" }
actix-web = { git = "https://github.com/actix/actix-web.git", branch = "fix-missing-content-length" }
trust-dns-resolver = { git = "https://github.com/kingoflolz/trust-dns.git", branch = "lower-max-ttl" }
2 changes: 1 addition & 1 deletion althea_kernel_interface/src/iface_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ impl KernelInterface {
let caps = re.captures(&stdout).unwrap();
let input_traffic = (caps[2].parse::<u64>()?, caps[1].parse::<u64>()?);

return Ok((input_traffic, output_traffic));
Ok((input_traffic, output_traffic))
}
}
82 changes: 81 additions & 1 deletion althea_kernel_interface/src/interface_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::KernelInterface;
use regex::Regex;

use failure::Error;
use std::net::IpAddr;
use std::str::from_utf8;

impl KernelInterface {
Expand Down Expand Up @@ -32,7 +33,44 @@ impl KernelInterface {

let output = from_utf8(&output.stdout)?;

return Ok(output.trim_right().to_string());
Ok(output.trim_right().to_string())
}

pub fn get_wg_remote_ip(&self, name: &str) -> Result<IpAddr, Error> {
let output = self.run_command("wg", &["show", name, "endpoints"])?;
let stdout = String::from_utf8(output.stdout)?;

let reg = Regex::new(r"(?:([0-9a-f:]+)%)|(?:([0-9\.]+):)")?;
let cap = reg.captures(&stdout);

match cap {
Some(cap) => {
let ip_str = match cap.get(1) {
// ipv6
Some(cap) => cap.as_str(),
None => {
match cap.get(2) {
Some(cap) => {
// ipv4
cap.as_str()
}
None => {
bail!("Cannot parse `wg show {} endpoints` output, got {}, captured {:?}", name, stdout, cap);
}
}
}
};

Ok(ip_str.parse()?)
}
None => {
bail!(
"Cannot parse `wg show {} endpoints` output, got {}, nothing captured",
name,
stdout
);
}
}
}
}

Expand Down Expand Up @@ -71,3 +109,45 @@ fn test_get_interfaces_linux() {
assert_eq!(format!("{}", interfaces[2]), "wg0");
assert_eq!(format!("{}", interfaces[3]), "veth-1-6");
}

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

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

KI.set_mock(Box::new(move |program, args| {
assert_eq!(program, "wg");
assert_eq!(args, &["show", "wg0", "endpoints"]);
Ok(Output {
stdout: b"fvLYbeMV+RYbzJEc4lNEPuK8ulva/5wcSJBz0W5t3hM= 71.8.186.226:60000\
"
.to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}));

assert_eq!(
KI.get_wg_remote_ip("wg0").unwrap(),
"71.8.186.226".parse::<IpAddr>().unwrap()
);

KI.set_mock(Box::new(move |program, args| {
assert_eq!(program, "wg");
assert_eq!(args, &["show", "wg0", "endpoints"]);
Ok(Output{
stdout: b"v5yFYZVfl98N/LRVDK3hbyt5/dK/00VnEGHRBikHHXs= [fe80::78e4:1cff:fe61:560d%veth-1-6]:60000\
".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}));

assert_eq!(
KI.get_wg_remote_ip("wg0").unwrap(),
"fe80::78e4:1cff:fe61:560d".parse::<IpAddr>().unwrap()
);
}
17 changes: 4 additions & 13 deletions althea_kernel_interface/src/ip_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ impl KernelInterface {

let mut def_route = Vec::new();

let mut found = false;

// find all lines
for i in stdout.lines() {
// starting with default
Expand All @@ -25,16 +23,11 @@ impl KernelInterface {
def_route.push(String::from(j));
}
}
found = true;
break;
return Some(def_route);
}
}

if found {
Some(def_route)
} else {
None
}
None
}

fn set_route(&self, to: &IpAddr, route: &Vec<String>) -> Result<(), Error> {
Expand All @@ -53,9 +46,7 @@ impl KernelInterface {
}

fn set_default_route(&self, route: &Vec<String>) -> Result<(), Error> {
let mut def_route_ref: Vec<&str> = vec!["route", "add"];

def_route_ref.push("default");
let mut def_route_ref: Vec<&str> = vec!["route", "add", "default"];

for i in 1..route.len() {
def_route_ref.push(route[i].as_str())
Expand All @@ -77,7 +68,7 @@ impl KernelInterface {
if !def_route.contains(&String::from("wg_exit")) {
// update the default route if default route is not wg exit
*settings_default_route = def_route.clone();
};
}
Ok(())
}

Expand Down
14 changes: 7 additions & 7 deletions althea_kernel_interface/src/link_local_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ impl KernelInterface {
let cap = re.captures(&str);
if let Some(cap) = cap {
trace!("got link local IP of {} from device {}", &cap[1], &dev);
return Ok(cap[1].parse()?);
Ok(cap[1].parse()?)
} else {
return Err(KernelInterfaceError::RuntimeError(
Err(KernelInterfaceError::RuntimeError(
"No link local addresses found or no interface found".to_string(),
).into());
).into())
}
}

Expand All @@ -35,11 +35,11 @@ impl KernelInterface {
let cap = re.captures(&str);
if let Some(cap) = cap {
trace!("got global IP of {} from device {}", &cap[1], &dev);
return Ok(cap[1].parse()?);
Ok(cap[1].parse()?)
} else {
return Err(KernelInterfaceError::RuntimeError(
Err(KernelInterfaceError::RuntimeError(
"No global found or no interface found".to_string(),
).into());
).into())
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ impl KernelInterface {
return Ok(caps[1].parse()?);
}
}
return Err(KernelInterfaceError::RuntimeError("Interface not found".to_string()).into());
Err(KernelInterfaceError::RuntimeError("Interface not found".to_string()).into())
}
}

Expand Down
32 changes: 14 additions & 18 deletions althea_kernel_interface/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,58 @@ use std::fs::File;
use std::io::Read;

impl KernelInterface {
fn read_file(&self, path_str: &str) -> Result<String, Error> {
let mut f = File::open(path_str)?;
let mut contents = String::new();
f.read_to_string(&mut contents)?;

Ok(contents)
}

pub fn get_proc_stat(&self) -> Result<String, Error> {
debug!("getting proc stat");
let mut f = File::open("/proc/stat")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/stat")?;

Ok(contents)
}

pub fn get_proc_load_avg(&self) -> Result<String, Error> {
debug!("getting proc loadavg");
let mut f = File::open("/proc/loadavg")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/loadavg")?;

Ok(contents)
}

pub fn get_device_stats(&self) -> Result<String, Error> {
debug!("getting device stats");
let mut f = File::open("/proc/net/dev")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/net/dev")?;

Ok(contents)
}

pub fn get_meminfo_stats(&self) -> Result<String, Error> {
debug!("getting meminfo");
let mut f = File::open("/proc/meminfo")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/meminfo")?;

Ok(contents)
}

pub fn get_cpuinfo_stats(&self) -> Result<String, Error> {
debug!("getting cpuinfo");
let mut f = File::open("/proc/cpuinfo")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/cpuinfo")?;

Ok(contents)
}

pub fn get_route_stats(&self) -> Result<String, Error> {
debug!("getting route stats");
let mut f = File::open("/proc/net/route")?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
let contents = self.read_file("/proc/net/route")?;

Ok(contents)
}
Expand Down
2 changes: 1 addition & 1 deletion althea_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ serde = "1.0.24"
serde_json = "1.0.8"
hex = "0.3.1"
eui48 = { git = "https://github.com/althea-mesh/eui48", features = ["serde"] }
actix = {version="0.5.7" , optional=true}
actix = { git = "https://github.com/kingoflolz/actix", branch = "althea-mesh", optional=true}
ethereum-types = {git="https://github.com/paritytech/primitives.git"}
Loading

0 comments on commit dd85e7c

Please sign in to comment.