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 7, 2018
2 parents e700804 + a9a39f2 commit 57fb512
Show file tree
Hide file tree
Showing 59 changed files with 2,546 additions and 579 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ before_install:
- which diesel || cargo install diesel_cli --no-default-features --features sqlite
- sudo cp $(which diesel) /usr/bin
env:
- TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo +nightly fmt --all -- --check"
- TEST_COMMAND="cargo build --verbose --all"
- TEST_COMMAND="cargo test --verbose --all" RUST_TEST_THREADS=1
- TEST_COMMAND="rustup component add rustfmt-preview --toolchain stable && cargo fmt --all && git status && if ! git diff-index --quiet HEAD --; then exit 1; fi"
- TEST_COMMAND="cargo build --locked --verbose --all"
- TEST_COMMAND="cargo test --locked --verbose --all" RUST_TEST_THREADS=1
rust:
- stable
- beta
Expand All @@ -21,14 +21,14 @@ matrix:
allow_failures:
- rust: beta
- rust: nightly
env: TEST_COMMAND="cargo build --verbose --all"
env: TEST_COMMAND="cargo build --locked --verbose --all"
- rust: nightly
env: TEST_COMMAND="cargo test --verbose --all" RUST_TEST_THREADS=1
env: TEST_COMMAND="cargo test --locked --verbose --all" RUST_TEST_THREADS=1
exclude:
- rust: beta
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo +nightly fmt --all -- --check"
- rust: stable
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain nightly && cargo +nightly fmt --all -- --check"
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain stable && cargo fmt --all && git status && if ! git diff-index --quiet HEAD --; then exit 1; fi"
- rust: nightly
env: TEST_COMMAND="rustup component add rustfmt-preview --toolchain stable && cargo fmt --all && git status && if ! git diff-index --quiet HEAD --; then exit 1; fi"
include:
- name: "Cross compile on MIPS"
script: ./integration-tests/cross-build.sh
Expand Down
133 changes: 56 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

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

[features]
Expand All @@ -19,6 +19,4 @@ codegen-units = 1
incremental = false

[patch.crates-io]
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" }
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This contains many (although confusingly not all) of the Rust components for the Althea firmware. The only separated component is [guac_rs](https://github.com/althea-mesh/guac_rs) which we want to be easily used externally as a Rust Ethereum light client.

The primary binary crate in this repo is 'rita' which produces two binaries 'rita' and 'rita_exit'
see the file headers for descriptions.

This is primarily an infrastructure repo, to get a working version of Althea you should look at [installer](https://github.com/althea-mesh/installer) for desktop linux and [althea-firmware](https://github.com/althea-mesh/althea-firmware) for OpenWRT.

## Building
Expand Down Expand Up @@ -51,7 +54,7 @@ cd .git/hooks && ln -s ../../scripts/.git-hooks/pre-commit
The only binary output of this repo that ends up on routers and the 'main' Crate. The Rita binary is run as a daemon on the mesh nodes as well as the exit nodes in an Althea network.

Status:
- Discovering Peers: done (should maybe have a proper discovery packet instead of ebtables)
- Discovering Peers: done
- Opening Wireguard tunnels with Peers: done
- Contacting the Exit server to negotiate credentials: done
- Opening a Wireguard tunnel to the exit: done
Expand Down Expand Up @@ -83,9 +86,6 @@ Manages things like exit tunnel setup, key generation, and other more using faci

Status: Feature complete

### kv-store
No longer used, should be removed

### num256

A 256bit number implementation for EVM compatibility.
Expand Down
212 changes: 210 additions & 2 deletions althea_kernel_interface/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,41 @@ impl FilterTarget {
}
}

#[test]
fn test_filter_target_interface() {
assert_eq!(FilterTarget::Input.interface(), "src");
assert_eq!(FilterTarget::ForwardInput.interface(), "src");
assert_eq!(FilterTarget::Output.interface(), "dst");
assert_eq!(FilterTarget::ForwardOutput.interface(), "dst");
}

#[test]
fn test_filter_table_set_name() {
assert_eq!(FilterTarget::Input.set_name(), "rita_input");
assert_eq!(FilterTarget::Output.set_name(), "rita_output");
assert_eq!(FilterTarget::ForwardInput.set_name(), "rita_fwd_input");
assert_eq!(FilterTarget::ForwardOutput.set_name(), "rita_fwd_output");
}

#[test]
fn test_filter_table_table() {
assert_eq!(FilterTarget::Input.table(), "INPUT");
assert_eq!(FilterTarget::Output.table(), "OUTPUT");
assert_eq!(FilterTarget::ForwardOutput.table(), "FORWARD");
assert_eq!(FilterTarget::ForwardInput.table(), "FORWARD");
}

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");
}
let mut map = HashMap::new();

// example line `add aa fd00::1,wg0 packets 28 bytes 2212`
let reg = Regex::new(r"(?m)^add \S+ ([a-f0-9:]+),(wg\d+) packets (\d+) bytes (\d+)")?;
for caps in reg.captures_iter(input) {

for caps in RE.captures_iter(input) {
map.insert(
(IpAddr::from_str(&caps[1])?, String::from(&caps[2])),
caps[4].parse::<u64>()? + caps[3].parse::<u64>()? * 40,
Expand All @@ -56,6 +85,39 @@ fn parse_ipset(input: &str) -> Result<HashMap<(IpAddr, String), u64>, Error> {
Ok(map)
}

#[test]
fn test_parse_ipset() {
use std::net::Ipv6Addr;
let data = r#"
add asdf 1234:5678:9801:2345:6789:0123:4567:8901,wg42 packets 123456789 bytes 987654321
add zxcv 1234:5678:9801:2345:6789:0123:4567:8902,wg0 packets 123456789 bytes 987654320
"#;
let result = parse_ipset(data);
match result {
Ok(result) => {
let addr1 = Ipv6Addr::new(
0x1234, 0x5678, 0x9801, 0x2345, 0x6789, 0x0123, 0x4567, 0x8901,
);
assert_eq!(result.len(), 2);
let value1 = result
.get(&(IpAddr::V6(addr1), "wg42".into()))
.expect("Unable to find key");
assert_eq!(value1, &(987654321u64 + 123456789u64 * 40));

let addr2 = Ipv6Addr::new(
0x1234, 0x5678, 0x9801, 0x2345, 0x6789, 0x0123, 0x4567, 0x8902,
);
let value2 = result
.get(&(IpAddr::V6(addr2), "wg0".into()))
.expect("Unable to find key");
assert_eq!(value2, &(987654320u64 + 123456789u64 * 40));
}
Err(e) => {
panic!("Unexpected error {:?}", e);
}
}
}

impl KernelInterface {
pub fn init_counter(&self, target: &FilterTarget) -> Result<(), Error> {
self.run_command(
Expand Down Expand Up @@ -124,3 +186,149 @@ impl KernelInterface {
res
}
}

#[test]
fn test_init_counter() {
use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use std::process::Output;

use KI;

let mut counter = 0;

KI.set_mock(Box::new(move |program, args| {
counter += 1;
match counter {
1 => {
assert_eq!(program, "ipset");
assert_eq!(
args,
vec![
"create",
"rita_input",
"hash:net,iface",
"family",
"inet6",
"counters",
]
);
Ok(Output {
stdout: b"".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
2 => {
assert_eq!(program, "ip6tables");
assert_eq!(
args,
vec![
"-w",
"-C",
"INPUT",
"-m",
"set",
"!",
"--match-set",
"rita_input",
"dst,src",
"-j",
"SET",
"--add-set",
"rita_input",
"dst,src",
]
);
Ok(Output {
stdout: b"".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}

_ => panic!("Unexpected call {} {:?} {:?}", counter, program, args),
}
}));
KI.init_counter(&FilterTarget::Input)
.expect("Unable to init counter");
}
#[test]
fn test_read_counters() {
use std::net::Ipv6Addr;
use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use std::process::Output;

use KI;

let mut counter = 0;

KI.set_mock(Box::new(move |program, args| {
counter += 1;
match counter {
1 => {
assert_eq!(program, "ipset");
assert_eq!(
args,
vec![
"create",
"tmp_rita_input",
"hash:net,iface",
"family",
"inet6",
"counters",
]
);
Ok(Output {
stdout: b"".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
2 => {
assert_eq!(program, "ipset");
assert_eq!(args, vec!["swap", "tmp_rita_input", "rita_input"]);
Ok(Output {
stdout: b"".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
3 => {
assert_eq!(program, "ipset");
assert_eq!(args, vec!["save", "tmp_rita_input"]);
Ok(Output {
stdout: b"
add xxx fd00::dead:beef,wg42 packets 111 bytes 222
"
.to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
4 => {
assert_eq!(program, "ipset");
assert_eq!(args, vec!["destroy", "tmp_rita_input"]);
Ok(Output {
stdout: b"".to_vec(),
stderr: b"".to_vec(),
status: ExitStatus::from_raw(0),
})
}
_ => panic!("Unexpected call {} {:?} {:?}", counter, program, args),
}
}));
let result = KI
.read_counters(&FilterTarget::Input)
.expect("Unable to read values");
assert_eq!(result.len(), 1);

let value = result
.get(&(
IpAddr::V6(Ipv6Addr::new(0xfd00, 0, 0, 0, 0, 0, 0xdead, 0xbeef)),
"wg42".into(),
))
.expect("Unable to find key");
assert_eq!(value, &(222u64 + 111u64 * 40));
}
2 changes: 1 addition & 1 deletion althea_kernel_interface/src/delete_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl KernelInterface {
let output = self.run_command("ip", &["link", "del", &interface])?;
if !output.stderr.is_empty() {
return Err(KernelInterfaceError::RuntimeError(format!(
"recieved error deleting wireguard interface: {}",
"received error deleting wireguard interface: {}",
String::from_utf8(output.stderr)?
)).into());
}
Expand Down
Loading

0 comments on commit 57fb512

Please sign in to comment.