author
int64
658
755k
date
stringlengths
19
19
timezone
int64
-46,800
43.2k
hash
stringlengths
40
40
message
stringlengths
5
490
mods
list
language
stringclasses
20 values
license
stringclasses
3 values
repo
stringlengths
5
68
original_message
stringlengths
12
491
20,244
04.06.2019 17:02:53
14,400
578fac40bd6bd3db180a72cb967fd620eb515cf0
Handle Geoip being disabled
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/geoip.rs", "new_path": "rita/src/rita_exit/database/geoip.rs", "diff": "@@ -119,8 +119,16 @@ struct CountryDetails {\n/// get ISO country code from ip, consults a in memory cache\npub fn get_country(ip: IpAddr) -> impl Future<Item = String, Error = Error> {\n- // a function local cache for results, reset during every restart\ntrace!(\"get GeoIP country for {}\", ip.to_string());\n+\n+ // if allowed countries is not configured we don't care and will insert\n+ // empty stings into the DB.\n+ if SETTING.get_allowed_countries().is_empty() {\n+ return Either::A(future::ok(String::new()));\n+ }\n+\n+ // on the other hand if there is a configured list of allowed countries\n+ // but no configured api details, we panic\nlet api_user = SETTING\n.get_exit_network()\n.geoip_api_user\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Handle Geoip being disabled
20,244
05.06.2019 15:58:15
14,400
bc930ebf9cb7baba866685dff1761b9dd726cb09
Update exit prices once registered This is a pretty big oversight to go unnoticed for so long, I guess previously people ended up re-registering often enough that we didn't notice
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/exit_manager/mod.rs", "new_path": "rita/src/rita_client/exit_manager/mod.rs", "diff": "@@ -186,6 +186,60 @@ fn exit_general_details_request(exit: String) -> impl Future<Item = (), Error =\nBox::new(r)\n}\n+fn update_exit_price(exit: String) -> impl Future<Item = (), Error = Error> {\n+ let current_exit = match SETTING.get_exits().get(&exit) {\n+ Some(current_exit) => current_exit.clone(),\n+ None => {\n+ return Box::new(future::err(format_err!(\"No valid exit for {}\", exit)))\n+ as Box<dyn Future<Item = (), Error = Error>>;\n+ }\n+ };\n+\n+ let endpoint = SocketAddr::new(current_exit.id.mesh_ip, current_exit.registration_port);\n+\n+ trace!(\"sending exit price request to {}\", exit);\n+\n+ let r = get_exit_info(&endpoint).and_then(move |exit_details| {\n+ let mut exits = SETTING.get_exits_mut();\n+\n+ let current_exit = match exits.get_mut(&exit) {\n+ Some(exit) => exit,\n+ None => bail!(\"Could not find exit {}\", exit),\n+ };\n+\n+ match exit_details {\n+ ExitState::GotInfo { .. } => {\n+ trace!(\"Got exit info response {:?}\", exit_details);\n+ }\n+ _ => bail!(\"got incorrect state from exit details request\"),\n+ }\n+ let new_price = exit_details.general_details().unwrap().exit_price;\n+\n+ match current_exit.info {\n+ ExitState::GotInfo {\n+ ref mut general_details,\n+ ..\n+ } => general_details.exit_price = new_price,\n+ ExitState::Registering {\n+ ref mut general_details,\n+ ..\n+ } => general_details.exit_price = new_price,\n+ ExitState::Pending {\n+ ref mut general_details,\n+ ..\n+ } => general_details.exit_price = new_price,\n+ ExitState::Registered {\n+ ref mut general_details,\n+ ..\n+ } => general_details.exit_price = new_price,\n+ _ => bail!(\"We don't know enough about this exit yet for price to matter?\"),\n+ }\n+ Ok(())\n+ });\n+\n+ Box::new(r)\n+}\n+\npub fn exit_setup_request(\nexit: String,\ncode: Option<String>,\n@@ -439,17 +493,43 @@ impl Handler<Tick> for ExitManager {\n)));\n}\nExitState::Registered { .. } => {\n- futs.push(Box::new(exit_status_request(k.clone()).then(move |res| {\n+ // different values for error printing\n+ let server_a = k.clone();\n+ let server_b = k.clone();\n+ futs.push(Box::new(exit_status_request(server_a.clone()).then(\n+ move |res| {\nmatch res {\nOk(_) => {\n- trace!(\"exit status request to {} was successful\", k);\n+ trace!(\"exit status request to {} was successful\", server_a);\n}\nErr(e) => {\n- trace!(\"exit status request to {} failed with {:?}\", k, e);\n+ trace!(\n+ \"exit status request to {} failed with {:?}\",\n+ server_a,\n+ e\n+ );\n}\n};\nOk(())\n- })));\n+ },\n+ )));\n+ futs.push(Box::new(update_exit_price(server_b.clone()).then(\n+ move |res| {\n+ match res {\n+ Ok(_) => {\n+ trace!(\"exit price request to {} was successful\", server_b);\n+ }\n+ Err(e) => {\n+ trace!(\n+ \"exit price request to {} failed with {:?}\",\n+ server_b,\n+ e\n+ );\n+ }\n+ };\n+ Ok(())\n+ },\n+ )));\n}\nstate => {\ntrace!(\"Waiting on exit state {:?} for {}\", state, k);\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update exit prices once registered This is a pretty big oversight to go unnoticed for so long, I guess previously people ended up re-registering often enough that we didn't notice
20,244
07.06.2019 09:44:11
14,400
116bc0cb277abc18a4656b0c8ef9605aa46231c6
Make connection pool size configurable add db timeout Trying to handle some of the contention issues I saw this morning trying to roll out the new async changes.
[ { "change_type": "MODIFY", "old_path": "rita/src/exit.rs", "new_path": "rita/src/exit.rs", "diff": "@@ -142,7 +142,7 @@ lazy_static! {\nlet manager = ConnectionManager::new(SETTING.get_db_uri());\nArc::new(RwLock::new(\nr2d2::Pool::builder()\n- .max_size(4)\n+ .max_size(SETTING.get_connection_pool_size())\n.build(manager)\n.expect(\"Failed to create pool.\"),\n))\n@@ -216,8 +216,9 @@ fn main() {\ncheck_rita_common_actors();\ncheck_rita_exit_actors();\n- start_core_rita_endpoints(8);\n- start_rita_exit_endpoints(128);\n+ let thread_pool_size = SETTING.get_connection_pool_size();\n+ start_core_rita_endpoints(thread_pool_size as usize);\n+ start_rita_exit_endpoints(thread_pool_size as usize);\nstart_rita_exit_dashboard();\nsystem.run();\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "@@ -53,6 +53,8 @@ use std::net::IpAddr;\nuse std::time::Instant;\nuse std::time::{Duration, SystemTime, UNIX_EPOCH};\nuse tokio::timer::Delay;\n+use actix::ActorFuture;\n+use tokio::util::FutureExt;\nmod database_tools;\npub mod db_client;\n@@ -75,7 +77,11 @@ pub fn get_database_connection(\nBox::new(\nDelay::new(when)\n.map_err(move |e| panic!(\"timer failed; err={:?}\", e))\n- .and_then(move |_| get_database_connection()),\n+ .and_then(move |_| get_database_connection())\n+ .timeout(Duration::from_secs(1)).then(|result| match result {\n+ Ok(v) => Ok(v),\n+ Err(e) => Err(format_err!(\"{:?}\", e))\n+ }),\n)\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "settings/src/exit.rs", "new_path": "settings/src/exit.rs", "diff": "@@ -174,6 +174,8 @@ pub enum ExitVerifSettings {\npub struct RitaExitSettingsStruct {\n// starts with file:// or postgres://username:password@localhost/diesel_demo\ndb_uri: String,\n+ // the size of the exit connection pool, this affects the size of the worker thread pool\n+ connection_pool_size: u32,\ndescription: String,\npayment: PaymentSettings,\ndao: SubnetDAOSettings,\n@@ -195,6 +197,7 @@ impl RitaExitSettingsStruct {\npub fn test_default() -> Self {\nRitaExitSettingsStruct {\ndb_uri: \"\".to_string(),\n+ connection_pool_size: 1,\ndescription: \"\".to_string(),\npayment: PaymentSettings::default(),\ndao: SubnetDAOSettings::default(),\n@@ -216,6 +219,7 @@ pub trait RitaExitSettings {\n&'me self,\n) -> RwLockWriteGuardRefMut<'ret, RitaExitSettingsStruct, Option<ExitVerifSettings>>;\nfn get_db_uri(&self) -> String;\n+ fn get_connection_pool_size(&self) -> u32;\nfn get_description(&self) -> String;\nfn get_allowed_countries<'ret, 'me: 'ret>(\n&'me self,\n@@ -231,6 +235,9 @@ impl RitaExitSettings for Arc<RwLock<RitaExitSettingsStruct>> {\nfn get_db_uri(&self) -> String {\nself.read().unwrap().db_uri.clone()\n}\n+ fn get_connection_pool_size(&self) -> u32 {\n+ self.read().unwrap().connection_pool_size\n+ }\nfn get_description(&self) -> String {\nself.read().unwrap().description.clone()\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Make connection pool size configurable add db timeout Trying to handle some of the contention issues I saw this morning trying to roll out the new async changes.
20,244
07.06.2019 11:46:20
14,400
781e2a5527b3c9ecef0c3af2560137610a6b91d0
Speed up exit loop and promote logging message
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/rita_loop/mod.rs", "new_path": "rita/src/rita_exit/rita_loop/mod.rs", "diff": "@@ -53,7 +53,9 @@ use std::net::IpAddr;\nuse std::time::Duration;\nuse tokio::util::FutureExt;\n-pub const EXIT_LOOP_TIMEOUT: Duration = Duration::from_secs(15);\n+// the speed in seconds for the exit loop\n+pub const EXIT_LOOP_SPEED: u64 = 5;\n+pub const EXIT_LOOP_TIMEOUT: Duration = Duration::from_secs(3);\n#[derive(Default)]\npub struct RitaLoop {}\n@@ -66,9 +68,6 @@ pub struct RitaSyncLoop {\npub wg_clients: HashSet<ExitClient>,\n}\n-// the speed in seconds for the exit loop\n-pub const EXIT_LOOP_SPEED: u64 = 30;\n-\nimpl Actor for RitaLoop {\ntype Context = Context<Self>;\n@@ -139,7 +138,7 @@ impl Handler<Tick> for RitaSyncLoop {\nfn handle(&mut self, msg: Tick, _ctx: &mut SyncContext<Self>) -> Self::Result {\nuse exit_db::schema::clients::dsl::clients;\nlet babel_port = SETTING.get_network().babel_port;\n- trace!(\"Exit tick!\");\n+ info!(\"Exit tick!\");\n// opening a database connection takes at least several milliseconds, as the database server\n// may be across the country, so to save on back and forth we open on and reuse it as much\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Speed up exit loop and promote logging message
20,244
07.06.2019 11:46:34
14,400
d6b464ebc6f186e0168d9d753ae9c488fef8e450
Update default settings with connection pool
[ { "change_type": "MODIFY", "old_path": "settings/default_exit.toml", "new_path": "settings/default_exit.toml", "diff": "db_uri = \"postgres://postgres@localhost/test\"\n+connection_pool_size = 1\ndescription = \"just a normal althea exit\"\n[payment]\n" }, { "change_type": "MODIFY", "old_path": "settings/example_exit.toml", "new_path": "settings/example_exit.toml", "diff": "db_uri = \"postgres://postgres@localhost/test\"\n+connection_pool_size = 1\ndescription = \"just a normal althea exit\"\n[payment]\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update default settings with connection pool
20,244
07.06.2019 16:15:50
14,400
5cd0aa0d09c730c5bf766c5866b47d0469debe3e
Lets try with one more worker
[ { "change_type": "ADD", "old_path": null, "new_path": "rita/.vscode/settings.json", "diff": "+{\n+}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "rita/src/exit.rs", "new_path": "rita/src/exit.rs", "diff": "@@ -142,7 +142,7 @@ lazy_static! {\nlet manager = ConnectionManager::new(SETTING.get_db_uri());\nArc::new(RwLock::new(\nr2d2::Pool::builder()\n- .max_size(SETTING.get_connection_pool_size())\n+ .max_size(SETTING.get_connection_pool_size() + 1)\n.build(manager)\n.expect(\"Failed to create pool.\"),\n))\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "@@ -30,7 +30,6 @@ use crate::DB_POOL;\nuse crate::KI;\nuse crate::SETTING;\nuse ::actix::SystemService;\n-use actix::ActorFuture;\nuse althea_kernel_interface::ExitClient;\nuse althea_types::{ExitClientDetails, ExitClientIdentity, ExitDetails, ExitState, ExitVerifMode};\nuse diesel;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Lets try with one more worker
20,244
09.06.2019 08:37:47
14,400
a81cdf12a9eb661234435fdab56eeb4c7127aaf3
Add depth limit to Babel monitor reads If you are on a cpu starved system this can get out of control, probably not going to happen on prod exits but we may as well add the change
[ { "change_type": "MODIFY", "old_path": "babel_monitor/src/lib.rs", "new_path": "babel_monitor/src/lib.rs", "diff": "@@ -110,6 +110,7 @@ pub fn open_babel_stream(babel_port: u16) -> ConnectFuture {\nfn read_babel(\nstream: TcpStream,\nprevious_contents: String,\n+ depth: usize,\n) -> impl Future<Item = (TcpStream, String), Error = Error> {\n// 100kbyte\nlet buffer: [u8; 100000] = [0; 100000];\n@@ -134,19 +135,24 @@ fn read_babel(\n// it's possible we caught babel in the middle of writing to the socket\n// if we don't see a terminator we either have an error in Babel or an error\n// in our code for expecting one. So it's safe for us to keep trying and building\n- // a larger response until we see one.\n+ // a larger response until we see one. We termiante after 5 tries\nlet babel_data = read_babel_sync(&output);\n- if let Err(NoTerminator(_)) = babel_data {\n+ if depth > 5 {\n+ warn!(\"Babel read timed out! {}\", output);\n+ return Box::new(future::err(ReadFailed(format!(\"Babel read timed out!\")).into()))\n+ as Box<Future<Item = (TcpStream, String), Error = Error>>;\n+ }\n+ else if let Err(NoTerminator(_)) = babel_data {\nlet when = Instant::now() + Duration::from_millis(100);\ntrace!(\"we didn't get the whole message yet, trying again\");\nlet full_message = format!(\"{}{}\", previous_contents, output);\nreturn Box::new(\nDelay::new(when)\n.map_err(move |e| panic!(\"timer failed; err={:?}\", e))\n- .and_then(move |_| read_babel(stream, full_message)),\n+ .and_then(move |_| read_babel(stream, full_message, depth + 1)),\n) as Box<Future<Item = (TcpStream, String), Error = Error>>;\n}\n- if let Err(e) = babel_data {\n+ else if let Err(e) = babel_data {\nwarn!(\"Babel read failed! {} {:?}\", output, e);\nreturn Box::new(future::err(ReadFailed(format!(\"{:?}\", e)).into()))\nas Box<Future<Item = (TcpStream, String), Error = Error>>;\n@@ -205,14 +211,14 @@ pub fn run_command(\n}\nlet (stream, _res) = out.unwrap();\ntrace!(\"Command write succeeded, returning output\");\n- Box::new(Either::B(read_babel(stream, String::new())))\n+ Box::new(Either::B(read_babel(stream, String::new(), 0)))\n})\n}\n// Consumes the automated Preamble and validates configuration api version\npub fn start_connection(stream: TcpStream) -> impl Future<Item = TcpStream, Error = Error> {\ntrace!(\"Starting babel connection\");\n- read_babel(stream, String::new()).then(|result| {\n+ read_babel(stream, String::new(), 0).then(|result| {\nif let Err(e) = result {\nreturn Err(e);\n}\n@@ -315,7 +321,7 @@ pub fn redistribute_ip(\nreturn Either::A(future_result(Err(e).into()));\n}\nlet (stream, _out) = result.unwrap();\n- Either::B(read_babel(stream, String::new()))\n+ Either::B(read_babel(stream, String::new(), 0))\n})\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add depth limit to Babel monitor reads If you are on a cpu starved system this can get out of control, probably not going to happen on prod exits but we may as well add the change
20,244
09.06.2019 08:39:08
14,400
3d8c83ae5675e1dc56490f58d1aeeac6205b66df
Add timeouts for geoip and enforcement operations
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/geoip.rs", "new_path": "rita/src/rita_exit/database/geoip.rs", "diff": "@@ -62,10 +62,12 @@ pub fn get_gateway_ip_bulk(\nmesh_ip_list: Vec<IpAddr>,\n) -> Box<Future<Item = Vec<IpPair>, Error = Error>> {\nlet babel_port = SETTING.get_network().babel_port;\n+ trace!(\"getting gateway ip bulk\");\nBox::new(open_babel_stream(babel_port).from_err().and_then(|stream| {\nstart_connection(stream).and_then(|stream| {\nparse_routes(stream).and_then(|routes| {\n+ trace!(\"done talking to babel for gateway ip bulk\");\nlet mut remote_ip_cache: HashMap<String, IpAddr> = HashMap::new();\nlet mut results = Vec::new();\nfor mesh_ip in mesh_ip_list {\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "@@ -26,6 +26,7 @@ use crate::rita_exit::database::struct_tools::display_hashset;\nuse crate::rita_exit::database::struct_tools::to_exit_client;\nuse crate::rita_exit::database::struct_tools::to_identity;\nuse crate::rita_exit::database::struct_tools::verif_done;\n+use crate::rita_exit::rita_loop::EXIT_LOOP_TIMEOUT;\nuse crate::DB_POOL;\nuse crate::KI;\nuse crate::SETTING;\n@@ -388,6 +389,7 @@ pub fn validate_clients_region(\n})\n})\n})\n+ .timeout(EXIT_LOOP_TIMEOUT)\n.then(|output| {\nif output.is_err() {\nerror!(\"Validate clients region failed with {:?}\", output);\n@@ -583,6 +585,12 @@ pub fn enforce_exit_clients(\nOk(())\n}\n})\n- .then(|_| Ok(())),\n+ .timeout(EXIT_LOOP_TIMEOUT)\n+ .then(|res| {\n+ if let Err(e) = res {\n+ error!(\"Exit enforcement failed with {:?}\", e);\n+ }\n+ Ok(())\n+ }),\n)\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add timeouts for geoip and enforcement operations
20,244
09.06.2019 08:40:07
14,400
2e258efc0e297f0cdc1a4dc1ec943d9b2e3c83e5
SyncActor can't seem to spawn futures I was told by the Actix author that this shouldn't be possible and recent changes seem to have broken whatever automagic was making it work. We've also removed a lot of blocking so we'll roll this back.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/rita_loop/mod.rs", "new_path": "rita/src/rita_exit/rita_loop/mod.rs", "diff": "@@ -29,8 +29,8 @@ use crate::rita_exit::traffic_watcher::{TrafficWatcher, Watch};\nuse crate::KI;\nuse crate::SETTING;\nuse actix::{\n- Actor, ActorContext, Arbiter, AsyncContext, Context, Handler, Message, Supervised, SyncArbiter,\n- SyncContext, SystemService,\n+ Actor, ActorContext, Addr, Arbiter, AsyncContext, Context, Handler, Message, Supervised,\n+ SystemService,\n};\nuse actix_web::http::Method;\nuse actix_web::{server, App};\n@@ -51,35 +51,30 @@ use std::collections::HashMap;\nuse std::collections::HashSet;\nuse std::net::IpAddr;\nuse std::time::Duration;\n+use std::time::Instant;\nuse tokio::util::FutureExt;\n// the speed in seconds for the exit loop\npub const EXIT_LOOP_SPEED: u64 = 5;\n-pub const EXIT_LOOP_TIMEOUT: Duration = Duration::from_secs(3);\n+pub const EXIT_LOOP_TIMEOUT: Duration = Duration::from_secs(4);\n#[derive(Default)]\n-pub struct RitaLoop {}\n-\n-#[derive(Default)]\n-pub struct RitaSyncLoop {\n+pub struct RitaLoop {\n/// a simple cache to prevent regularly asking Maxmind for the same geoip data\npub geoip_cache: HashMap<IpAddr, String>,\n/// a cache of what tunnels we had setup last round, used to prevent extra setup ops\npub wg_clients: HashSet<ExitClient>,\n}\n+\nimpl Actor for RitaLoop {\ntype Context = Context<Self>;\nfn started(&mut self, ctx: &mut Context<Self>) {\ninfo!(\"exit loop started\");\nsetup_exit_wg_tunnel();\n- let addr = SyncArbiter::start(1, || RitaSyncLoop {\n- geoip_cache: HashMap::new(),\n- wg_clients: HashSet::new(),\n- });\n- ctx.run_interval(Duration::from_secs(EXIT_LOOP_SPEED), move |_act, _ctx| {\n- let addr = addr.clone();\n+ ctx.run_interval(Duration::from_secs(EXIT_LOOP_SPEED), move |_act, ctx| {\n+ let addr: Addr<Self> = ctx.address();\nArbiter::spawn(get_database_connection().then(move |database| {\nmatch database {\nOk(database) => addr.do_send(Tick(database)),\n@@ -91,13 +86,6 @@ impl Actor for RitaLoop {\n}\n}\n-impl Actor for RitaSyncLoop {\n- type Context = SyncContext<Self>;\n-\n- fn started(&mut self, _ctx: &mut SyncContext<Self>) {\n- info!(\"exit sync loop started\");\n- }\n-}\nimpl SystemService for RitaLoop {}\nimpl Supervised for RitaLoop {\n@@ -106,11 +94,6 @@ impl Supervised for RitaLoop {\n}\n}\n-impl Supervised for RitaSyncLoop {\n- fn restarting(&mut self, _ctx: &mut SyncContext<RitaSyncLoop>) {\n- error!(\"Rita Exit Sync loop actor died! recovering!\");\n- }\n-}\n/// Used to test actor respawning\npub struct Crash;\n@@ -133,9 +116,10 @@ impl Message for Tick {\ntype Result = Result<(), Error>;\n}\n-impl Handler<Tick> for RitaSyncLoop {\n+impl Handler<Tick> for RitaLoop {\ntype Result = Result<(), Error>;\n- fn handle(&mut self, msg: Tick, _ctx: &mut SyncContext<Self>) -> Self::Result {\n+ fn handle(&mut self, msg: Tick, _ctx: &mut Context<Self>) -> Self::Result {\n+ let start = Instant::now();\nuse exit_db::schema::clients::dsl::clients;\nlet babel_port = SETTING.get_network().babel_port;\ninfo!(\"Exit tick!\");\n@@ -195,6 +179,11 @@ impl Handler<Tick> for RitaSyncLoop {\n// this consumes client list, you can move it up in exchange for a clone\nArbiter::spawn(enforce_exit_clients(clients_list));\n+ info!(\n+ \"Completed Rita sync loop in {}s {}ms, all vars should be dropped\",\n+ start.elapsed().as_secs(),\n+ start.elapsed().subsec_millis(),\n+ );\nOk(())\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
SyncActor can't seem to spawn futures I was told by the Actix author that this shouldn't be possible and recent changes seem to have broken whatever automagic was making it work. We've also removed a lot of blocking so we'll roll this back.
20,244
10.06.2019 11:25:24
14,400
3d66075648fb6b940b15a99b7f4da1828ebb31b9
Update Readme to reflect current progress
[ { "change_type": "MODIFY", "old_path": "README.md", "new_path": "README.md", "diff": "# Althea_rs\n-This contains many (although confusingly not all) of the Rust components for the Althea firmware. The only separated components are [guac_rs](https://github.com/althea-mesh/guac_rs) which we want to be easily used externally as a Rust Payment channel light client, [Clarity](https://github.com/althea-mesh/clarity) a lightweight transaction generation library for Ethereum, and [num256](https://github.com/althea-mesh/num256) a architecture portable fixed 256 bit integer implementation.\n+This contains many (although confusingly not all) of the Rust components for the Althea firmware. The only separated components are [guac_rs](https://github.com/althea-mesh/guac_rs) which we want to be easily used externally as a Rust Payment channel light client, [Clarity](https://github.com/althea-mesh/clarity) a lightweight transaction generation library for Ethereum, and [web30](https://github.com/althea-mesh/web30) a full node communication library.\nThe primary binary crate in this repo is 'rita' which produces two binaries 'rita' and 'rita_exit'\nsee the file headers for descriptions.\n@@ -62,10 +62,10 @@ Status:\n- Opening a Wireguard tunnel to the exit: done\n- Setting the user traffic route to the exit tunnel: Partially complete, needs ipv6\n- Accepting commands from the user configuration dashboard and applying them: Done\n-- Accounts for bandwidth used and required payment: Has known bugs\n+- Accounts for bandwidth used and required payment: done\n- Communicates with Babeld to get mesh info: done\n- Communicates with Babeld to detect fraud: in progress\n-- Makes payments: Will mostly be contained in the Guac_rs repo\n+- Makes payments: done\n### althea_kernel_interface\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update Readme to reflect current progress
20,244
13.06.2019 07:51:52
14,400
3047b7cb300b842ddcea7584d52e1625faf7e628
Update for Beta 6
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -168,7 +168,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.4.7\",\n+ \"rita 0.5.0\",\n]\n[[package]]\n@@ -1841,7 +1841,7 @@ dependencies = [\n[[package]]\nname = \"rita\"\n-version = \"0.4.7\"\n+version = \"0.5.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.4.7\"\n+version = \"0.5.0\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 5 RC5\";\n+pub static READABLE_VERSION: &str = \"Beta 6 RC1\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update for Beta 6
20,244
13.06.2019 12:52:37
14,400
2340b33d4a1803f7b90d3ff6907359858cacba2d
Prevent price higher than max-fee This is mostly to protect users who don't understand what price they are setting.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/babel.rs", "new_path": "rita/src/rita_common/dashboard/babel.rs", "diff": "@@ -33,6 +33,10 @@ pub fn set_local_fee(path: Path<u32>) -> Box<Future<Item = HttpResponse, Error =\nlet new_fee = path.into_inner();\ndebug!(\"/local_fee/{} POST hit\", new_fee);\nlet babel_port = SETTING.get_network().babel_port;\n+ let max_fee = SETTING.get_payment().max_fee;\n+ // prevent the user from setting a higher price than they would pay\n+ // themselves\n+ let new_fee = if new_fee > max_fee { max_fee } else { new_fee };\nBox::new(open_babel_stream(babel_port).then(move |stream| {\n// if we can't get to babel here we panic\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Prevent price higher than max-fee This is mostly to protect users who don't understand what price they are setting.
20,244
13.06.2019 16:19:58
14,400
078a29a4cae2cc142cac34dfe3dfb3dd53e3afea
Update neighbors page to show direct metric
[ { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -50,6 +50,7 @@ This file documents the dashboard API found in Rita client.\n{\n\"nickname\": \"fd00::2\",\n\"route_metric_to_exit\": 0,\n+ \"route_metric\": 0,\n\"total_debt\": 0,\n\"current_debt\": 0,\n\"link_cost\": 0,\n@@ -58,6 +59,7 @@ This file documents the dashboard API found in Rita client.\n{\n\"nickname\": \"fd00::7\",\n\"route_metric_to_exit\": 0,\n+ \"route_metric\": 0,\n\"total_debt\": 0,\n\"current_debt\": 0,\n\"link_cost\": 0,\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/neighbors.rs", "new_path": "rita/src/rita_client/dashboard/neighbors.rs", "diff": "@@ -6,6 +6,7 @@ use ::actix_web::AsyncResponder;\nuse ::actix_web::{HttpRequest, Json};\nuse althea_types::Identity;\nuse arrayvec::ArrayString;\n+use babel_monitor::get_installed_route;\nuse babel_monitor::get_route_via_neigh;\nuse babel_monitor::open_babel_stream;\nuse babel_monitor::parse_routes;\n@@ -23,6 +24,7 @@ pub struct NodeInfo {\npub nickname: String,\npub ip: String,\npub route_metric_to_exit: u16,\n+ pub route_metric: u16,\npub total_payments: Uint256,\npub debt: Int256,\npub link_cost: u16,\n@@ -88,40 +90,52 @@ fn generate_neighbors_list(\nSome(val) => val,\nNone => ArrayString::<[u8; 32]>::from(\"No Nickname\").unwrap(),\n};\n+ let maybe_route = get_installed_route(&identity.mesh_ip, &route_table_sample);\n+ if maybe_route.is_err() {\n+ output.push(nonviable_node_info(\n+ nickname,\n+ 0,\n+ identity.mesh_ip.to_string(),\n+ ));\n+ continue;\n+ }\n+ let neigh_route = maybe_route.unwrap();\nif current_exit.is_some() {\nlet exit_ip = current_exit.unwrap().id.mesh_ip;\n- let maybe_route = get_route_via_neigh(identity.mesh_ip, exit_ip, &route_table_sample);\n+ let maybe_exit_route =\n+ get_route_via_neigh(identity.mesh_ip, exit_ip, &route_table_sample);\n// We have a peer that is an exit, so we can't find a route\n// from them to our selected exit. Other errors can also get\n// caught here\n- if maybe_route.is_err() {\n- output.push(nonviable_node_info(nickname, identity.mesh_ip.to_string()));\n+ if maybe_exit_route.is_err() {\n+ output.push(nonviable_node_info(\n+ nickname,\n+ neigh_route.metric,\n+ identity.mesh_ip.to_string(),\n+ ));\ncontinue;\n}\n// we check that this is safe above\n- let route = maybe_route.unwrap();\n+ let exit_route = maybe_exit_route.unwrap();\noutput.push(NodeInfo {\nnickname: nickname.to_string(),\nip: serde_json::to_string(&identity.mesh_ip).unwrap(),\n- route_metric_to_exit: route.metric,\n+ route_metric_to_exit: exit_route.metric,\n+ route_metric: neigh_route.metric,\ntotal_payments: debt_info.total_payment_received.clone(),\ndebt: debt_info.debt.clone(),\n- link_cost: route.refmetric,\n- price_to_exit: route.price,\n+ link_cost: exit_route.refmetric,\n+ price_to_exit: exit_route.price,\n})\n} else {\n- output.push(NodeInfo {\n- nickname: nickname.to_string(),\n- ip: serde_json::to_string(&identity.mesh_ip).unwrap(),\n- route_metric_to_exit: u16::max_value(),\n- total_payments: debt_info.total_payment_received.clone(),\n- debt: debt_info.debt.clone(),\n- link_cost: u16::max_value(),\n- price_to_exit: u32::max_value(),\n- })\n+ output.push(nonviable_node_info(\n+ nickname,\n+ 0,\n+ identity.mesh_ip.to_string(),\n+ ));\n}\n}\noutput\n@@ -140,7 +154,7 @@ fn merge_debts_and_neighbors(\n}\n}\n-fn nonviable_node_info(nickname: ArrayString<[u8; 32]>, ip: String) -> NodeInfo {\n+fn nonviable_node_info(nickname: ArrayString<[u8; 32]>, neigh_metric: u16, ip: String) -> NodeInfo {\nNodeInfo {\nnickname: nickname.to_string(),\nip,\n@@ -149,5 +163,6 @@ fn nonviable_node_info(nickname: ArrayString<[u8; 32]>, ip: String) -> NodeInfo\nlink_cost: 0,\nprice_to_exit: 0,\nroute_metric_to_exit: u16::max_value(),\n+ route_metric: neigh_metric,\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update neighbors page to show direct metric
20,244
05.04.2019 19:42:20
14,400
2f92044c3d031fed71bf606652193590c35c6350
Remove default features from httpauth
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -64,13 +64,11 @@ dependencies = [\n\"actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"brotli2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"cookie 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"h2 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -112,7 +110,7 @@ dependencies = [\n[[package]]\nname = \"actix-web-httpauth\"\nversion = \"0.1.0\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+source = \"git+https://github.com/jkilpatr/actix-web-httpauth#a97a9664b36ed3b269adc8c984bd33a5c302b15b\"\ndependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -139,11 +137,6 @@ dependencies = [\n\"syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n-[[package]]\n-name = \"adler32\"\n-version = \"1.0.3\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-\n[[package]]\nname = \"aho-corasick\"\nversion = \"0.6.10\"\n@@ -372,34 +365,11 @@ dependencies = [\n\"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n-[[package]]\n-name = \"brotli-sys\"\n-version = \"0.3.2\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n-[[package]]\n-name = \"brotli2\"\n-version = \"0.3.2\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"brotli-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n[[package]]\nname = \"bufstream\"\nversion = \"0.1.4\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n-[[package]]\n-name = \"build_const\"\n-version = \"0.2.1\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-\n[[package]]\nname = \"byte-tools\"\nversion = \"0.2.0\"\n@@ -535,8 +505,6 @@ name = \"cookie\"\nversion = \"0.11.1\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n- \"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -555,22 +523,6 @@ name = \"core-foundation-sys\"\nversion = \"0.6.2\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n-[[package]]\n-name = \"crc\"\n-version = \"1.8.1\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n-[[package]]\n-name = \"crc32fast\"\n-version = \"1.2.0\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n[[package]]\nname = \"crossbeam-channel\"\nversion = \"0.3.8\"\n@@ -874,17 +826,6 @@ dependencies = [\n\"ascii_utils 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n-[[package]]\n-name = \"flate2\"\n-version = \"1.0.7\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n[[package]]\nname = \"fnv\"\nversion = \"1.0.6\"\n@@ -1276,34 +1217,6 @@ name = \"minihttpse\"\nversion = \"0.1.6\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n-[[package]]\n-name = \"miniz-sys\"\n-version = \"0.1.12\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n-[[package]]\n-name = \"miniz_oxide\"\n-version = \"0.2.1\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n-[[package]]\n-name = \"miniz_oxide_c_api\"\n-version = \"0.2.1\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n[[package]]\nname = \"mio\"\nversion = \"0.6.19\"\n@@ -1988,24 +1901,13 @@ name = \"rgb\"\nversion = \"0.8.13\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n-[[package]]\n-name = \"ring\"\n-version = \"0.13.5\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-dependencies = [\n- \"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n-]\n-\n[[package]]\nname = \"rita\"\nversion = \"0.5.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"actix-web-httpauth 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"actix-web-httpauth 0.1.0 (git+https://github.com/jkilpatr/actix-web-httpauth)\",\n\"actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n@@ -2794,11 +2696,6 @@ name = \"unicode-xid\"\nversion = \"0.1.0\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n-[[package]]\n-name = \"untrusted\"\n-version = \"0.6.2\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n-\n[[package]]\nname = \"url\"\nversion = \"1.7.2\"\n@@ -2992,10 +2889,9 @@ dependencies = [\n\"checksum actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6c616db5fa4b0c40702fb75201c2af7f8aa8f3a2e2c1dda3b0655772aa949666\"\n\"checksum actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8bebfbe6629e0131730746718c9e032b58f02c6ce06ed7c982b9fef6c8545acd\"\n\"checksum actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b0ac60f86c65a50b140139f499f4f7c6e49e4b5d88fbfba08e4e3975991f7bf4\"\n-\"checksum actix-web-httpauth 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"843c8b2e6b9d02d2511c0b26e5e7b59834ea870d266056e474707ba8c80ff3a7\"\n+\"checksum actix-web-httpauth 0.1.0 (git+https://github.com/jkilpatr/actix-web-httpauth)\" = \"<none>\"\n\"checksum actix_derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4300e9431455322ae393d43a2ba1ef96b8080573c0fc23b196219efedfb6ba69\"\n\"checksum actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0bf5f6d7bf2d220ae8b4a7ae02a572bb35b7c4806b24049af905ab8110de156c\"\n-\"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c\"\n\"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)\" = \"81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5\"\n\"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c\"\n\"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94\"\n@@ -3016,10 +2912,7 @@ dependencies = [\n\"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab\"\n\"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b\"\n\"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09\"\n-\"checksum brotli-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd\"\n-\"checksum brotli2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e\"\n\"checksum bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8\"\n-\"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39\"\n\"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40\"\n\"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7\"\n\"checksum bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c\"\n@@ -3036,8 +2929,6 @@ dependencies = [\n\"checksum cookie 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"99be24cfcf40d56ed37fd11c2123be833959bbc5bddecb46e1c2e442e15fa3e0\"\n\"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d\"\n\"checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b\"\n-\"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb\"\n-\"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1\"\n\"checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b\"\n\"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71\"\n\"checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4\"\n@@ -3071,7 +2962,6 @@ dependencies = [\n\"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1\"\n\"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed\"\n\"checksum fast_chemail 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"495a39d30d624c2caabe6312bfead73e7717692b44e0b32df168c275a2e8e9e4\"\n-\"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)\" = \"f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa\"\n\"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3\"\n\"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1\"\n\"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b\"\n@@ -3123,9 +3013,6 @@ dependencies = [\n\"checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)\" = \"3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425\"\n\"checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed\"\n\"checksum minihttpse 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8e50e8cee436b4318ec759930d6ea5f839d14dab94e81b6fba37d492d07ebf55\"\n-\"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)\" = \"1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202\"\n-\"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e\"\n-\"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab\"\n\"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23\"\n\"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)\" = \"966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125\"\n\"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919\"\n@@ -3198,7 +3085,6 @@ dependencies = [\n\"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e\"\n\"checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb\"\n\"checksum rgb 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4f089652ca87f5a82a62935ec6172a534066c7b97be003cc8f702ee9a7a59c92\"\n-\"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)\" = \"2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a\"\n\"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)\" = \"f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a\"\n\"checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2\"\n\"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)\" = \"a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af\"\n@@ -3276,7 +3162,6 @@ dependencies = [\n\"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5\"\n\"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)\" = \"141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426\"\n\"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc\"\n-\"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f\"\n\"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a\"\n\"checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde\"\n\"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -27,7 +27,7 @@ syslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\nactix_derive = \"0.4\"\n-actix-web-httpauth = \"0.1\"\n+actix-web-httpauth = {git = \"https://github.com/jkilpatr/actix-web-httpauth\"}\nbytes = \"0.4\"\nconfig = \"0.9\"\ndiesel = { version = \"1.4\", features = [\"postgres\", \"r2d2\"] }\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/mod.rs", "new_path": "rita/src/rita_common/dashboard/mod.rs", "diff": "use ::actix::prelude::*;\nuse ::actix::registry::SystemService;\n+pub mod auth;\npub mod babel;\npub mod dao;\npub mod debts;\n@@ -15,7 +16,6 @@ pub mod pricing;\npub mod settings;\npub mod usage;\npub mod wallet;\n-pub mod auth;\npub struct Dashboard;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Remove default features from httpauth
20,244
05.04.2019 19:48:33
14,400
d7a2806524d9e866fea96f343e4365d44c8f227a
Hash and salt the dashboard password Since we're using httpauth this can't be perfect, but now the router at least secures the password at rest
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -1947,6 +1947,7 @@ dependencies = [\n\"serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"settings 0.1.0\",\n+ \"sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -2206,6 +2207,18 @@ dependencies = [\n\"keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n+[[package]]\n+name = \"sha3\"\n+version = \"0.8.2\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n[[package]]\nname = \"signal-hook\"\nversion = \"0.1.9\"\n@@ -3114,6 +3127,7 @@ dependencies = [\n\"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68\"\n\"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d\"\n\"checksum sha3 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b64dcef59ed4290b9fb562b53df07f564690d6539e8ecdd4728cf392477530bc\"\n+\"checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf\"\n\"checksum signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"72ab58f1fda436857e6337dcb6a5aaa34f16c5ddc87b3a8b6ef7a212f90b9c5a\"\n\"checksum signal-hook-registry 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"cded4ffa32146722ec54ab1f16320568465aa922aa9ab4708129599740da85d7\"\n\"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac\"\n" }, { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -1275,7 +1275,6 @@ Gets the nickname used by the router\n---\n-<<<<<<< HEAD\n## /router/update\nManually runs the update script\n@@ -1297,9 +1296,12 @@ Manually runs the update script\n- Sample Call:\n`curl -v -XPOST http://192.168.10.1:4877/router/update`\n-=======\n+\n## /router/password\n+Note a cleartext password is submitted to this endpoint but when actually used to login\n+a sha256 hashed version of the text plus the text \"RitaSalt\" must be used\n+\n- URL: `<rita ip>:<rita_dashboard_port>/router/password`\n- Method: `POST`\n- URL Params: `Content-Type: application/json`\n@@ -1324,8 +1326,7 @@ Manually runs the update script\n- Sample Call:\n-`curl -XPOST 127.0.0.1:<rita_dashboard_port>/router/password -H 'Content-Type: application/json' -i -d '{\"password\": \"this is a freeform password\"}'`\n->>>>>>> Add dashboard authentication\n+`curl -XPOST 127.0.0.1:<rita_dashboard_port>/router/password -H 'Content-Type: application/json' -i -d '{\"password\": \"this is a freeform cleartext password\"}'`\n---\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -63,6 +63,7 @@ lettre = {git = \"https://github.com/lettre/lettre/\"}\nlettre_email = {git = \"https://github.com/lettre/lettre/\"}\nphonenumber = \"0.2\"\nr2d2 = \"0.8\"\n+sha3 = \"0.8\"\n[features]\ndefault = []\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/auth.rs", "new_path": "rita/src/rita_common/dashboard/auth.rs", "diff": "@@ -5,6 +5,7 @@ use ::actix_web::{HttpResponse, Json};\nuse ::settings::FileWrite;\nuse failure::Error;\nuse settings::RitaCommonSettings;\n+use sha3::{Digest, Sha3_256};\n#[derive(Serialize, Deserialize, Default, Clone, Debug)]\npub struct RouterPassword {\n@@ -15,7 +16,10 @@ pub fn set_pass(router_pass: Json<RouterPassword>) -> Result<HttpResponse, Error\ndebug!(\"/router/password hit with {:?}\", router_pass);\nlet router_pass = router_pass.into_inner();\n// scoped to drop the write reference before we write to the disk\n- SETTING.get_network_mut().rita_dashboard_password = Some(router_pass.password.clone());\n+ let mut hasher = Sha3_256::new();\n+ hasher.input(router_pass.password.clone() + \"RitaSalt\");\n+ let hashed_pass = String::from_utf8(hasher.result().to_vec())?;\n+ SETTING.get_network_mut().rita_dashboard_password = Some(hashed_pass);\n// try and save the config and fail if we can't\nif let Err(e) = SETTING.write().unwrap().write(&ARGS.flag_config) {\nreturn Err(e);\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Hash and salt the dashboard password Since we're using httpauth this can't be perfect, but now the router at least secures the password at rest
20,244
12.04.2019 10:03:24
14,400
fd930c7619262e77be12e283d954dc15ac961914
Fix trailing slashes on some endpoints
[ { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -286,9 +286,9 @@ fn start_client_dashboard() {\nMethod::POST,\nset_system_blockchain,\n)\n- .route(\"/blockchain/get/\", Method::GET, get_system_blockchain)\n- .route(\"/nickname/get/\", Method::GET, get_nickname)\n- .route(\"/nickname/set/\", Method::POST, set_nickname)\n+ .route(\"/blockchain/get\", Method::GET, get_system_blockchain)\n+ .route(\"/nickname/get\", Method::GET, get_nickname)\n+ .route(\"/nickname/set\", Method::POST, set_nickname)\n.route(\n\"/low_balance_notification\",\nMethod::GET,\n@@ -303,7 +303,7 @@ fn start_client_dashboard() {\n.route(\"/usage/client\", Method::GET, get_client_usage)\n.route(\"/usage/payments\", Method::GET, get_payments)\n.route(\"/router/update\", Method::POST, update_router)\n- .route(\"/router/password/\", Method::POST, set_pass)\n+ .route(\"/router/password\", Method::POST, set_pass)\n.route(\"/wipe\", Method::POST, wipe)\n.route(\"/crash_actors\", Method::POST, crash_actors)\n})\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix trailing slashes on some endpoints
20,244
12.04.2019 11:53:03
14,400
a958b46621836db7f06770179363c769b5613348
Fix sha3 encoding differences Using fixed enfocing to produce a fixed sized hash and double checking against some testing references
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -944,6 +944,23 @@ name = \"hex\"\nversion = \"0.3.2\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\n+[[package]]\n+name = \"hex-literal\"\n+version = \"0.2.0\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n+[[package]]\n+name = \"hex-literal-impl\"\n+version = \"0.2.0\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n[[package]]\nname = \"hostname\"\nversion = \"0.1.5\"\n@@ -1636,6 +1653,16 @@ dependencies = [\n\"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n+[[package]]\n+name = \"proc-macro-hack\"\n+version = \"0.5.7\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n[[package]]\nname = \"proc-macro2\"\nversion = \"0.4.30\"\n@@ -1927,6 +1954,7 @@ dependencies = [\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"ipnetwork 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"lettre 0.9.1 (git+https://github.com/lettre/lettre/)\",\n@@ -2990,6 +3018,8 @@ dependencies = [\n\"checksum h2 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)\" = \"1e42e3daed5a7e17b12a0c23b5b2fbff23a925a570938ebee4baca1a9a1a2240\"\n\"checksum handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"d82e5750d8027a97b9640e3fefa66bbaf852a35228e1c90790efd13c4b09c166\"\n\"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77\"\n+\"checksum hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c3da68162fdd2147e66682e78e729bd77f93b4c99656db058c5782d8c6b6225a\"\n+\"checksum hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"06095d08c7c05760f11a071b3e1d4c5b723761c01bd8d7201c30a9536668a612\"\n\"checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\" = \"21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e\"\n\"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)\" = \"eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a\"\n\"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83\"\n@@ -3069,6 +3099,7 @@ dependencies = [\n\"checksum phonenumber 0.2.3+8.10.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b542a6190f0f629282989ba0ba4c2c53dac417a2c2f745b36e7a89d00c67463e\"\n\"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)\" = \"676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c\"\n\"checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda\"\n+\"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3\"\n\"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)\" = \"cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759\"\n\"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0\"\n\"checksum quick-xml 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"22fcc48ecef4609b243e8c01ff4695d08ee0fc9d5bdbc54630e1a5fe8bb40953\"\n" }, { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/set_system_password.rs", "new_path": "althea_kernel_interface/src/set_system_password.rs", "diff": "@@ -7,6 +7,7 @@ use std::process::{Command, Stdio};\nimpl dyn KernelInterface {\n/// Sets the system password on openwrt\npub fn set_system_password(&self, password: String) -> Result<(), Error> {\n+ trace!(\"Trying to set the system password to {}\", password);\nlet mut passwd = Command::new(\"passwd\")\n.stdout(Stdio::piped())\n.stdin(Stdio::piped())\n" }, { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -1206,7 +1206,7 @@ Sets the blockchain being used by the router, either 'Ethereum','Rinkeby' or 'Xd\nSets the blockchain being used by the router\n-- URL: `<rita ip>:<rita_dashboard_port>/blockchain/get/`\n+- URL: `<rita ip>:<rita_dashboard_port>/blockchain/get`\n- Method: `GET`\n- URL Params: `None`\n- Data Params: `None`\n@@ -1222,7 +1222,7 @@ Sets the blockchain being used by the router\n- Sample Call:\n-`curl http://192.168.10.1:4877/blockchain/get/`\n+`curl http://192.168.10.1:4877/blockchain/get`\n---\n@@ -1231,7 +1231,7 @@ Sets the blockchain being used by the router\nSets the optional nickname parameter for the router. Will error if the nickname\nis longer than 32 chars when utf-8 encoded (not always 32 assci chars)\n-- URL: `<rita ip>:<rita_dashboard_port>/nickname/set/`\n+- URL: `<rita ip>:<rita_dashboard_port>/nickname/set`\n- Method: `POST`\n- URL Params: `None`\n- Data Params: `None`\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -26,8 +26,8 @@ web30 = {git = \"https://github.com/althea-mesh/web30\", rev=\"56b0068aa43eb563db99\nsyslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\n-actix_derive = \"0.4\"\nactix-web-httpauth = {git = \"https://github.com/jkilpatr/actix-web-httpauth\"}\n+actix_derive = \"0.4\"\nbytes = \"0.4\"\nconfig = \"0.9\"\ndiesel = { version = \"1.4\", features = [\"postgres\", \"r2d2\"] }\n@@ -64,6 +64,7 @@ lettre_email = {git = \"https://github.com/lettre/lettre/\"}\nphonenumber = \"0.2\"\nr2d2 = \"0.8\"\nsha3 = \"0.8\"\n+hex-literal = \"0.2\"\n[features]\ndefault = []\n" }, { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -19,6 +19,10 @@ extern crate log;\n#[macro_use]\nextern crate serde_derive;\n+#[cfg(test)]\n+#[macro_use]\n+extern crate hex_literal;\n+\nextern crate arrayvec;\nuse env_logger;\n" }, { "change_type": "MODIFY", "old_path": "rita/src/exit.rs", "new_path": "rita/src/exit.rs", "diff": "@@ -23,6 +23,10 @@ extern crate serde_derive;\n#[macro_use]\nextern crate serde_json;\n+#[cfg(test)]\n+#[macro_use]\n+extern crate hex_literal;\n+\nextern crate phonenumber;\nuse actix_web::http::Method;\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/auth.rs", "new_path": "rita/src/rita_common/dashboard/auth.rs", "diff": "@@ -3,9 +3,11 @@ use crate::KI;\nuse crate::SETTING;\nuse ::actix_web::{HttpResponse, Json};\nuse ::settings::FileWrite;\n+use clarity::utils::bytes_to_hex_str;\nuse failure::Error;\nuse settings::RitaCommonSettings;\n-use sha3::{Digest, Sha3_256};\n+use sha3::digest::FixedOutput;\n+use sha3::{Digest, Sha3_512};\n#[derive(Serialize, Deserialize, Default, Clone, Debug)]\npub struct RouterPassword {\n@@ -15,10 +17,13 @@ pub struct RouterPassword {\npub fn set_pass(router_pass: Json<RouterPassword>) -> Result<HttpResponse, Error> {\ndebug!(\"/router/password hit with {:?}\", router_pass);\nlet router_pass = router_pass.into_inner();\n- // scoped to drop the write reference before we write to the disk\n- let mut hasher = Sha3_256::new();\n- hasher.input(router_pass.password.clone() + \"RitaSalt\");\n- let hashed_pass = String::from_utf8(hasher.result().to_vec())?;\n+ let input_string = router_pass.password.clone() + \"RitaSalt\";\n+\n+ debug!(\"Using {} as sha3 512 input\", input_string);\n+ let mut hasher = Sha3_512::new();\n+ hasher.input(input_string.as_bytes());\n+ let hashed_pass = bytes_to_hex_str(&hasher.fixed_result().to_vec());\n+\nSETTING.get_network_mut().rita_dashboard_password = Some(hashed_pass);\n// try and save the config and fail if we can't\nif let Err(e) = SETTING.write().unwrap().write(&ARGS.flag_config) {\n@@ -34,3 +39,26 @@ pub fn set_pass(router_pass: Json<RouterPassword>) -> Result<HttpResponse, Error\nOk(HttpResponse::Ok().json(()))\n}\n+\n+#[test]\n+fn test_hash() {\n+ let sha3_output = hex!(\"881c7d6ba98678bcd96e253086c4048c3ea15306d0d13ff48341c6285ee71102a47b6f16e20e4d65c0c3d677be689dfda6d326695609cbadfafa1800e9eb7fc1\");\n+\n+ let mut hasher = Sha3_512::new();\n+ hasher.input(b\"testing\");\n+ let result = hasher.fixed_result().to_vec();\n+\n+ assert_eq!(result.len(), sha3_output.len());\n+ assert_eq!(result, sha3_output.to_vec());\n+}\n+\n+#[test]\n+fn test_hash_to_string() {\n+ let sha3sum_output = \"881c7d6ba98678bcd96e253086c4048c3ea15306d0d13ff48341c6285ee71102a47b6f16e20e4d65c0c3d677be689dfda6d326695609cbadfafa1800e9eb7fc1\";\n+\n+ let mut hasher = Sha3_512::new();\n+ hasher.input(b\"testing\");\n+ let result = hasher.fixed_result().to_vec();\n+\n+ assert_eq!(bytes_to_hex_str(&result), sha3sum_output);\n+}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix sha3 encoding differences Using fixed enfocing to produce a fixed sized hash and double checking against some testing references
20,244
25.04.2019 10:16:10
14,400
ea15d476041eeaf5eff3105461f457aa37c19f35
Cleanup dependencies in the main files
[ { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -18,11 +18,9 @@ extern crate lazy_static;\nextern crate log;\n#[macro_use]\nextern crate serde_derive;\n-\n#[cfg(test)]\n#[macro_use]\nextern crate hex_literal;\n-\nextern crate arrayvec;\nuse env_logger;\n@@ -65,7 +63,6 @@ use crate::rita_client::dashboard::system_chain::*;\nuse crate::rita_client::dashboard::update::*;\nuse crate::rita_client::dashboard::usage::*;\nuse crate::rita_client::dashboard::wifi::*;\n-\nuse crate::rita_common::dashboard::auth::*;\nuse crate::rita_common::dashboard::babel::*;\nuse crate::rita_common::dashboard::dao::*;\n@@ -77,7 +74,6 @@ use crate::rita_common::dashboard::pricing::*;\nuse crate::rita_common::dashboard::settings::*;\nuse crate::rita_common::dashboard::usage::*;\nuse crate::rita_common::dashboard::wallet::*;\n-\nuse crate::rita_common::network_endpoints::*;\n#[derive(Debug, Deserialize, Default)]\n" }, { "change_type": "MODIFY", "old_path": "rita/src/exit.rs", "new_path": "rita/src/exit.rs", "diff": "@@ -22,11 +22,9 @@ extern crate log;\nextern crate serde_derive;\n#[macro_use]\nextern crate serde_json;\n-\n#[cfg(test)]\n#[macro_use]\nextern crate hex_literal;\n-\nextern crate phonenumber;\nuse actix_web::http::Method;\n@@ -41,6 +39,9 @@ use std::collections::HashMap;\nuse std::net::IpAddr;\nuse std::sync::{Arc, RwLock};\n+#[cfg(test)]\n+use std::sync::Mutex;\n+\nuse settings::exit::{RitaExitSettings, RitaExitSettingsStruct};\nuse settings::RitaCommonSettings;\n@@ -68,13 +69,9 @@ use crate::rita_common::dashboard::pricing::*;\nuse crate::rita_common::dashboard::settings::*;\nuse crate::rita_common::dashboard::usage::*;\nuse crate::rita_common::dashboard::wallet::*;\n-\nuse crate::rita_common::network_endpoints::*;\nuse crate::rita_exit::network_endpoints::*;\n-#[cfg(test)]\n-use std::sync::Mutex;\n-\n#[derive(Debug, Deserialize, Default)]\npub struct Args {\nflag_config: String,\n" }, { "change_type": "MODIFY", "old_path": "rita/src/middleware.rs", "new_path": "rita/src/middleware.rs", "diff": "@@ -36,6 +36,8 @@ impl<S> Middleware<S> for Headers {\n}\n}\n+// for some reason the Headers struct doesn't get this\n+#[allow(dead_code)]\npub struct Auth;\nimpl<S> Middleware<S> for Auth {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Cleanup dependencies in the main files
20,244
25.04.2019 10:17:12
14,400
395f15ee55371a41cec60b3a60aec13c3df79904
Update docs to reflect sha3 length change
[ { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -1300,7 +1300,7 @@ Manually runs the update script\n## /router/password\nNote a cleartext password is submitted to this endpoint but when actually used to login\n-a sha256 hashed version of the text plus the text \"RitaSalt\" must be used\n+a sha512 hashed version of the text plus the text \"RitaSalt\" must be used\n- URL: `<rita ip>:<rita_dashboard_port>/router/password`\n- Method: `POST`\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update docs to reflect sha3 length change
20,244
25.04.2019 13:37:26
14,400
507a6fe2740a4499d6045961d7b8df832b35a846
Passwd setting needs newline chars
[ { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/set_system_password.rs", "new_path": "althea_kernel_interface/src/set_system_password.rs", "diff": "@@ -8,7 +8,11 @@ impl dyn KernelInterface {\n/// Sets the system password on openwrt\npub fn set_system_password(&self, password: String) -> Result<(), Error> {\ntrace!(\"Trying to set the system password to {}\", password);\n+ let mut password_with_newline = password.as_bytes().to_vec();\n+ password_with_newline.push(b'\\n');\n+\nlet mut passwd = Command::new(\"passwd\")\n+ .args(&[\"-a sha512\"])\n.stdout(Stdio::piped())\n.stdin(Stdio::piped())\n.spawn()\n@@ -18,12 +22,13 @@ impl dyn KernelInterface {\n.stdin\n.as_mut()\n.unwrap()\n- .write_all(&password.as_bytes())?;\n+ .write_all(&password_with_newline)?;\npasswd\n.stdin\n.as_mut()\n.unwrap()\n- .write_all(&password.as_bytes())?;\n+ .write_all(&password_with_newline)?;\n+\nlet output = passwd.wait_with_output()?;\ntrace!(\"Got {} from passwd\", String::from_utf8(output.stdout)?);\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/auth.rs", "new_path": "rita/src/rita_common/dashboard/auth.rs", "diff": "@@ -27,6 +27,7 @@ pub fn set_pass(router_pass: Json<RouterPassword>) -> Result<HttpResponse, Error\nSETTING.get_network_mut().rita_dashboard_password = Some(hashed_pass);\n// try and save the config and fail if we can't\nif let Err(e) = SETTING.write().unwrap().write(&ARGS.flag_config) {\n+ trace!(\"Saved new password in config!\");\nreturn Err(e);\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Passwd setting needs newline chars
20,244
28.04.2019 09:27:28
14,400
ee914667cd86204959ae290293c1ae79c6dc7f06
Use upstream httpauth My upstream patch was accepted
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -109,11 +109,11 @@ dependencies = [\n[[package]]\nname = \"actix-web-httpauth\"\n-version = \"0.1.0\"\n-source = \"git+https://github.com/jkilpatr/actix-web-httpauth#a97a9664b36ed3b269adc8c984bd33a5c302b15b\"\n+version = \"0.2.0\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -1934,7 +1934,7 @@ version = \"0.5.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"actix-web-httpauth 0.1.0 (git+https://github.com/jkilpatr/actix-web-httpauth)\",\n+ \"actix-web-httpauth 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n@@ -2930,7 +2930,7 @@ dependencies = [\n\"checksum actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6c616db5fa4b0c40702fb75201c2af7f8aa8f3a2e2c1dda3b0655772aa949666\"\n\"checksum actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8bebfbe6629e0131730746718c9e032b58f02c6ce06ed7c982b9fef6c8545acd\"\n\"checksum actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b0ac60f86c65a50b140139f499f4f7c6e49e4b5d88fbfba08e4e3975991f7bf4\"\n-\"checksum actix-web-httpauth 0.1.0 (git+https://github.com/jkilpatr/actix-web-httpauth)\" = \"<none>\"\n+\"checksum actix-web-httpauth 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c0d5fa1bd3b68851ace29dd94623a3cce7358a122e933769460129e44ca6963f\"\n\"checksum actix_derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4300e9431455322ae393d43a2ba1ef96b8080573c0fc23b196219efedfb6ba69\"\n\"checksum actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0bf5f6d7bf2d220ae8b4a7ae02a572bb35b7c4806b24049af905ab8110de156c\"\n\"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)\" = \"81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -26,7 +26,7 @@ web30 = {git = \"https://github.com/althea-mesh/web30\", rev=\"56b0068aa43eb563db99\nsyslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\n-actix-web-httpauth = {git = \"https://github.com/jkilpatr/actix-web-httpauth\"}\n+actix-web-httpauth = \"0.2.0\"\nactix_derive = \"0.4\"\nbytes = \"0.4\"\nconfig = \"0.9\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Use upstream httpauth My upstream patch was accepted
20,249
07.06.2019 16:58:22
25,200
bb391b620aff2015006bcf584e6e222ba0b3bbea
Fork actix httpauth to return 403 instead of 401
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -110,7 +110,7 @@ dependencies = [\n[[package]]\nname = \"actix-web-httpauth\"\nversion = \"0.2.0\"\n-source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+source = \"git+https://github.com/asoltys/actix-web-httpauth#5f984f95a0b777d548ec68618671d26a96d92fde\"\ndependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1934,7 +1934,7 @@ version = \"0.5.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"actix-web-httpauth 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"actix-web-httpauth 0.2.0 (git+https://github.com/asoltys/actix-web-httpauth)\",\n\"actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n@@ -2930,7 +2930,7 @@ dependencies = [\n\"checksum actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6c616db5fa4b0c40702fb75201c2af7f8aa8f3a2e2c1dda3b0655772aa949666\"\n\"checksum actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8bebfbe6629e0131730746718c9e032b58f02c6ce06ed7c982b9fef6c8545acd\"\n\"checksum actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b0ac60f86c65a50b140139f499f4f7c6e49e4b5d88fbfba08e4e3975991f7bf4\"\n-\"checksum actix-web-httpauth 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c0d5fa1bd3b68851ace29dd94623a3cce7358a122e933769460129e44ca6963f\"\n+\"checksum actix-web-httpauth 0.2.0 (git+https://github.com/asoltys/actix-web-httpauth)\" = \"<none>\"\n\"checksum actix_derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4300e9431455322ae393d43a2ba1ef96b8080573c0fc23b196219efedfb6ba69\"\n\"checksum actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0bf5f6d7bf2d220ae8b4a7ae02a572bb35b7c4806b24049af905ab8110de156c\"\n\"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)\" = \"81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -26,7 +26,7 @@ web30 = {git = \"https://github.com/althea-mesh/web30\", rev=\"56b0068aa43eb563db99\nsyslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\n-actix-web-httpauth = \"0.2.0\"\n+actix-web-httpauth = {git = \"https://github.com/asoltys/actix-web-httpauth\"}\nactix_derive = \"0.4\"\nbytes = \"0.4\"\nconfig = \"0.9\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -23,27 +23,23 @@ extern crate serde_derive;\nextern crate hex_literal;\nextern crate arrayvec;\n+use actix_web::{http, server, App};\n+use docopt::Docopt;\nuse env_logger;\n-\n-use std::env;\n-\nuse openssl_probe;\n-\n-use docopt::Docopt;\n-#[cfg(not(test))]\n-use settings::FileWrite;\n-\nuse settings::client::{RitaClientSettings, RitaSettingsStruct};\nuse settings::RitaCommonSettings;\n-\n+use std::env;\n+use std::sync::{Arc, RwLock};\nuse actix_web::http::Method;\n-use actix_web::{http, server, App};\n-use std::sync::{Arc, RwLock};\n+#[cfg(not(test))]\n+use settings::FileWrite;\n#[cfg(test)]\nuse std::sync::Mutex;\n+\nmod middleware;\nmod rita_client;\nmod rita_common;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fork actix httpauth to return 403 instead of 401
20,244
14.06.2019 09:15:23
14,400
34b64a2c75004cc45aca8ab97fb37cd121e8a6e9
Use althea-mesh repo for httpauth
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -110,7 +110,7 @@ dependencies = [\n[[package]]\nname = \"actix-web-httpauth\"\nversion = \"0.2.0\"\n-source = \"git+https://github.com/asoltys/actix-web-httpauth#5f984f95a0b777d548ec68618671d26a96d92fde\"\n+source = \"git+https://github.com/althea-mesh/actix-web-httpauth#4d6bf7afee950668b336a68727d847aa05300723\"\ndependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1934,7 +1934,7 @@ version = \"0.5.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"actix-web-httpauth 0.2.0 (git+https://github.com/asoltys/actix-web-httpauth)\",\n+ \"actix-web-httpauth 0.2.0 (git+https://github.com/althea-mesh/actix-web-httpauth)\",\n\"actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n@@ -2930,7 +2930,7 @@ dependencies = [\n\"checksum actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6c616db5fa4b0c40702fb75201c2af7f8aa8f3a2e2c1dda3b0655772aa949666\"\n\"checksum actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"8bebfbe6629e0131730746718c9e032b58f02c6ce06ed7c982b9fef6c8545acd\"\n\"checksum actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b0ac60f86c65a50b140139f499f4f7c6e49e4b5d88fbfba08e4e3975991f7bf4\"\n-\"checksum actix-web-httpauth 0.2.0 (git+https://github.com/asoltys/actix-web-httpauth)\" = \"<none>\"\n+\"checksum actix-web-httpauth 0.2.0 (git+https://github.com/althea-mesh/actix-web-httpauth)\" = \"<none>\"\n\"checksum actix_derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4300e9431455322ae393d43a2ba1ef96b8080573c0fc23b196219efedfb6ba69\"\n\"checksum actix_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0bf5f6d7bf2d220ae8b4a7ae02a572bb35b7c4806b24049af905ab8110de156c\"\n\"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)\" = \"81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -26,7 +26,7 @@ web30 = {git = \"https://github.com/althea-mesh/web30\", rev=\"56b0068aa43eb563db99\nsyslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\n-actix-web-httpauth = {git = \"https://github.com/asoltys/actix-web-httpauth\"}\n+actix-web-httpauth = {git = \"https://github.com/althea-mesh/actix-web-httpauth\"}\nactix_derive = \"0.4\"\nbytes = \"0.4\"\nconfig = \"0.9\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Use althea-mesh repo for httpauth
20,244
17.06.2019 07:24:49
14,400
d490046f811e61126e24c0e8f81463645d90bed7
Save bw usage data every 4 hours Data was often not being saved because routers got rebooted
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/usage_tracker/mod.rs", "new_path": "rita/src/rita_common/usage_tracker/mod.rs", "diff": "@@ -31,7 +31,7 @@ use std::time::UNIX_EPOCH;\n/// On year worth of usage storage\nconst MAX_ENTRIES: usize = 8760;\n/// Save every 24 hours\n-const SAVE_FREQENCY: u64 = 24;\n+const SAVE_FREQENCY: u64 = 4;\n/// In an effort to converge this module between the three possible bw tracking\n/// use cases this enum is used to identify which sort of usage we are tracking\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Save bw usage data every 4 hours Data was often not being saved because routers got rebooted
20,244
17.06.2019 13:12:51
14,400
9d299a76fc18038432da0f79a15bc495abcc51d5
Use 105% of the provided median gas price
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/oracle/mod.rs", "new_path": "rita/src/rita_common/oracle/mod.rs", "diff": "@@ -191,7 +191,7 @@ pub fn update_nonce(our_address: Address, web3: &Web3, full_node: String) {\n/// This function updates the gas price and in the process adjusts our payment threshold\n/// The average gas price over the last hour are averaged by the web3 call we then adjust our\n-/// expected payment amount and grace period so that every transaction pays 10% in transaction fees\n+/// expected payment amount and grace period so that every transaction pays 5% in transaction fees\n/// (or whatever they care to configure as dyanmic_fee_factor). This also handles dramatic spikes in\n/// gas prices by increasing the maximum debt before a drop to the free tier occurs. So if the blockchain\n/// is simply to busy to use for some period of time payments will simply wait.\n@@ -210,7 +210,11 @@ fn update_gas_price(web3: &Web3, full_node: String) {\nif payment_settings.system_chain == SystemChain::Xdai {\npayment_settings.gas_price = 250_000_000_000u128.into();\n} else {\n- payment_settings.gas_price = value;\n+ // use 105% of the gas price provided by the full node, this is designed\n+ // to keep us above the median price provided by the full node.\n+ // This should ensure that we maintain a higher-than-median priority even\n+ // if the network is being spammed with transactions\n+ payment_settings.gas_price = value.clone() + (value / 20u32.into());\n}\nlet dynamic_fee_factor: Int256 = payment_settings.dynamic_fee_multiplier.into();\nlet transaction_gas: Int256 = 21000.into();\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Use 105% of the provided median gas price
20,249
17.06.2019 15:26:40
25,200
6f07fc9d06e6cdc7b0fe8caf39c23cb805afc28c
Accept authorization headers
[ { "change_type": "MODIFY", "old_path": "rita/src/middleware.rs", "new_path": "rita/src/middleware.rs", "diff": "@@ -30,7 +30,7 @@ impl<S> Middleware<S> for Headers {\n);\nresp.headers_mut().insert(\nheader::HeaderName::try_from(\"Access-Control-Allow-Headers\").unwrap(),\n- header::HeaderValue::from_static(\"content-type\"),\n+ header::HeaderValue::from_static(\"authorization\"),\n);\nOk(Response::Done(resp))\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Accept authorization headers
20,244
19.06.2019 11:13:16
14,400
e94cbb2299e6bbb309c45eb7b9b16bb5f068beb0
Add back content type header, bump for Beta6 rc2
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -170,7 +170,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.5.0\",\n+ \"rita 0.5.1\",\n]\n[[package]]\n@@ -1930,7 +1930,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.0\"\n+version = \"0.5.1\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.0\"\n+version = \"0.5.1\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/middleware.rs", "new_path": "rita/src/middleware.rs", "diff": "@@ -30,7 +30,7 @@ impl<S> Middleware<S> for Headers {\n);\nresp.headers_mut().insert(\nheader::HeaderName::try_from(\"Access-Control-Allow-Headers\").unwrap(),\n- header::HeaderValue::from_static(\"authorization\"),\n+ header::HeaderValue::from_static(\"authorization, content-type\"),\n);\nOk(Response::Done(resp))\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add back content type header, bump for Beta6 rc2
20,244
19.06.2019 11:14:47
14,400
b8f9de204638684d846fb7596c3f8ffc6377bc06
Update human readable version
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 6 RC1\";\n+pub static READABLE_VERSION: &str = \"Beta 6 RC2\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update human readable version
20,244
21.06.2019 16:49:44
14,400
309827114f9765df2f24ceb690fa3b1eb1227406
Fix doc inconsistency with trailing /'s
[ { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -1255,7 +1255,7 @@ is longer than 32 chars when utf-8 encoded (not always 32 assci chars)\nGets the nickname used by the router\n-- URL: `<rita ip>:<rita_dashboard_port>/nickname/get/`\n+- URL: `<rita ip>:<rita_dashboard_port>/nickname/get`\n- Method: `GET`\n- URL Params: `None`\n- Data Params: `None`\n@@ -1271,7 +1271,7 @@ Gets the nickname used by the router\n- Sample Call:\n-`curl http://192.168.10.1:4877/nickname/get/`\n+`curl http://192.168.10.1:4877/nickname/get`\n---\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix doc inconsistency with trailing /'s
20,244
21.06.2019 17:11:41
14,400
e19e11c22a2fd48af45c4855d1bc6b6eaf439659
It's better to have a tunnel without traffic shaping If we fail in this case we will set up infinite untracked tunnels and generally nothing will work right. We would prefer to log this error case over the alternative
[ { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/traffic_control.rs", "new_path": "althea_kernel_interface/src/traffic_control.rs", "diff": "@@ -127,7 +127,8 @@ impl KernelInterface {\nif !output.status.success() {\nlet res = String::from_utf8(output.stderr)?;\n- bail!(\"Failed to create new qdisc limit! {:?}\", res);\n+ error!(\"Failed to set codel shaping! {:?}\", res);\n+ bail!(\"Failed to set codel shaping! {:?}\", res);\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/tunnel_manager/mod.rs", "new_path": "rita/src/rita_common/tunnel_manager/mod.rs", "diff": "@@ -158,6 +158,7 @@ impl Tunnel {\n/// Open a real tunnel to match the virtual tunnel we store in memory\npub fn open(&self) -> Result<(), Error> {\nlet network = SETTING.get_network().clone();\n+ trace!(\"About to open tunnel\");\nKI.open_tunnel(\n&self.iface_name,\nself.listen_port,\n@@ -171,7 +172,14 @@ impl Tunnel {\nnetwork.external_nic.clone(),\n&mut SETTING.get_network_mut().default_route,\n)?;\n- KI.set_codel_shaping(&self.iface_name)\n+ trace!(\"About to set codel shaping\");\n+ if let Err(e) = KI.set_codel_shaping(&self.iface_name) {\n+ error!(\n+ \"Tunnel {} is now active without traffic shaping! {:?}\",\n+ self.iface_name, e\n+ );\n+ }\n+ Ok(())\n}\n/// Register this tunnel into Babel monitor\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
It's better to have a tunnel without traffic shaping If we fail in this case we will set up infinite untracked tunnels and generally nothing will work right. We would prefer to log this error case over the alternative
20,244
21.06.2019 17:15:12
14,400
aabfd9f2d8cc5e8739643c3b6cf3550da222818e
Bump Rita version for Beta 6 RC3
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -170,7 +170,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.5.1\",\n+ \"rita 0.5.2\",\n]\n[[package]]\n@@ -1930,7 +1930,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.1\"\n+version = \"0.5.2\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.1\"\n+version = \"0.5.2\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 6 RC2\";\n+pub static READABLE_VERSION: &str = \"Beta 6 RC3\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump Rita version for Beta 6 RC3
20,244
22.06.2019 07:30:47
14,400
39e00140c9b2944d1d95947c01c2cff3e15e7e2f
Update bounty hunter deps
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -349,7 +349,7 @@ dependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -579,7 +579,7 @@ dependencies = [\n\"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"libsqlite3-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -636,6 +636,16 @@ dependencies = [\n\"regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n+[[package]]\n+name = \"dotenv\"\n+version = \"0.14.1\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n[[package]]\nname = \"dtoa\"\nversion = \"0.4.4\"\n@@ -1135,10 +1145,9 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"libsqlite3-sys\"\n-version = \"0.9.3\"\n+version = \"0.9.1\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n- \"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -1959,7 +1968,6 @@ dependencies = [\n\"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"lettre 0.9.1 (git+https://github.com/lettre/lettre/)\",\n\"lettre_email 0.9.1 (git+https://github.com/lettre/lettre/)\",\n- \"libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"minihttpse 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"mockito 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -2982,6 +2990,7 @@ dependencies = [\n\"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c\"\n\"checksum docopt 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"7f525a586d310c87df72ebcd98009e57f1cc030c8c268305287a476beb653969\"\n\"checksum dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c0d0a1279c96732bc6800ce6337b6a614697b0e74ae058dc03c62ebeb78b4d86\"\n+\"checksum dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"4424bad868b0ffe6ae351ee463526ba625bbca817978293bbe6bb7dc1804a175\"\n\"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e\"\n\"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b\"\n\"checksum email 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)\" = \"91549a51bb0241165f13d57fc4c72cef063b4088fb078b019ecbf464a45f22e4\"\n@@ -3042,7 +3051,7 @@ dependencies = [\n\"checksum lettre 0.9.1 (git+https://github.com/lettre/lettre/)\" = \"<none>\"\n\"checksum lettre_email 0.9.1 (git+https://github.com/lettre/lettre/)\" = \"<none>\"\n\"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319\"\n-\"checksum libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"d3711dfd91a1081d2458ad2d06ea30a8755256e74038be2ad927d94e1c955ca8\"\n+\"checksum libsqlite3-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0e9eb7b8e152b6a01be6a4a2917248381875758250dc3df5d46caf9250341dda\"\n\"checksum linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd\"\n\"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83\"\n\"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\" = \"62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c\"\n" }, { "change_type": "MODIFY", "old_path": "bounty_hunter/Cargo.toml", "new_path": "bounty_hunter/Cargo.toml", "diff": "@@ -5,21 +5,21 @@ authors = [\"kingoflolz <wangben3@gmail.com>\", \"Stan Drozd <drozdziak1@gmail.com>\nedition = \"2018\"\n[dependencies]\n-actix = \"0.7.7\"\n-actix-web = {version = \"0.7.14\", features = [\"ssl\"], default_features = false}\n-clarity = \"0.1.13\"\n-diesel = { version = \"1.3.3\", default-features = false, features = [\"sqlite\"] }\n-dotenv = \"0.13.0\"\n-env_logger = \"0.6.0\"\n-failure = \"0.1.3\"\n-futures = \"0.1.25\"\n-lazy_static = \"1.2.0\"\n-libc = \"0.2.43\"\n+actix = \"0.7\"\n+actix-web = {version = \"0.7\", features = [\"ssl\"], default_features = false}\n+clarity = \"0.1\"\n+diesel = { version = \"1.4\", default-features = false, features = [\"sqlite\"] }\n+dotenv = \"0.14\"\n+env_logger = \"0.6\"\n+failure = \"0.1\"\n+futures = \"0.1\"\n+lazy_static = \"1.3\"\n+libc = \"0.2\"\nlog = \"0.4.6\"\n-num-traits = \"0.2.6\"\n+num-traits = \"0.2\"\nnum256 = \"0.2\"\n-openssl = \"0.10.15\"\n-openssl-probe = \"0.1.2\"\n-serde = \"1.0.80\"\n-serde_derive = \"1.0.80\"\n-serde_json = \"1.0.33\"\n+openssl = \"0.10\"\n+openssl-probe = \"0.1\"\n+serde = \"1.0\"\n+serde_derive = \"1.0\"\n+serde_json = \"1.0\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -31,7 +31,6 @@ actix_derive = \"0.4\"\nbytes = \"0.4\"\nconfig = \"0.9\"\ndiesel = { version = \"1.4\", features = [\"postgres\", \"r2d2\"] }\n-libsqlite3-sys = { version = \"0.9\", features = [\"bundled\"] }\ndocopt = \"1.1\"\ndotenv = \"0.13\"\nenv_logger = \"0.6\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update bounty hunter deps
20,244
22.06.2019 07:32:59
14,400
24efb86feec2df27c3d0b95fa7df4018b1f17f49
Upgrade Settings deps
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -2213,7 +2213,7 @@ dependencies = [\n\"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n[[package]]\n@@ -2611,6 +2611,14 @@ dependencies = [\n\"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n+[[package]]\n+name = \"toml\"\n+version = \"0.5.1\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+dependencies = [\n+ \"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n+]\n+\n[[package]]\nname = \"tower-service\"\nversion = \"0.1.0\"\n@@ -3202,6 +3210,7 @@ dependencies = [\n\"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92\"\n\"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)\" = \"037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445\"\n\"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)\" = \"758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f\"\n+\"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039\"\n\"checksum tower-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b32f72af77f1bfe3d3d4da8516a238ebe7039b51dd8637a09841ac7f16d2c987\"\n\"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079\"\n\"checksum trust-dns-proto 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"0838272e89f1c693b4df38dc353412e389cf548ceed6f9fd1af5a8d6e0e7cf74\"\n" }, { "change_type": "MODIFY", "old_path": "settings/Cargo.toml", "new_path": "settings/Cargo.toml", "diff": "@@ -13,10 +13,10 @@ num256 = \"0.2\"\nserde = \"1.0\"\nserde_derive = \"1.0\"\nserde_json = \"1.0\"\n-toml = \"0.4\"\n+toml = \"0.5\"\nlog = \"0.4\"\nfailure = \"0.1\"\nowning_ref = \"0.4\"\n-lazy_static = \"1.0\"\n+lazy_static = \"1.3\"\nclarity = \"0.1\"\narrayvec = {version= \"0.4\", features = [\"serde-1\"]}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Upgrade Settings deps
20,244
22.06.2019 07:39:13
14,400
d9874922881f9e581534f66ad56742a17c8bf90d
Update other minor deps
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -179,7 +179,7 @@ version = \"0.1.0\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"eui48 0.4.0 (git+https://github.com/althea-mesh/eui48)\",\n\"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -796,7 +796,7 @@ version = \"0.1.0\"\ndependencies = [\n\"althea_types 0.1.0\",\n\"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "althea_kernel_interface/Cargo.toml", "new_path": "althea_kernel_interface/Cargo.toml", "diff": "@@ -9,7 +9,7 @@ edition = \"2018\"\n[dependencies]\nfailure = \"0.1\"\nitertools = \"0.8\"\n-lazy_static = \"1.2\"\n+lazy_static = \"1.3\"\nlog = \"0.4\"\nregex = \"1.1\"\neui48 = { git = \"https://github.com/althea-mesh/eui48\", features = [\"serde\"] }\n" }, { "change_type": "MODIFY", "old_path": "althea_types/Cargo.toml", "new_path": "althea_types/Cargo.toml", "diff": "@@ -6,7 +6,7 @@ edition = \"2018\"\n[dependencies]\nnum256 = \"0.2\"\n-base64 = \"0.9\"\n+base64 = \"0.10\"\nserde_derive = \"1.0\"\nserde = \"1.0\"\nserde_json = \"1.0\"\n" }, { "change_type": "MODIFY", "old_path": "exit_db/Cargo.toml", "new_path": "exit_db/Cargo.toml", "diff": "@@ -5,8 +5,8 @@ authors = [\"Ben <wangben3@gmail.com>\"]\nedition = \"2018\"\n[dependencies]\n-diesel = { version = \"1.3\", features = [\"postgres\"] }\n-dotenv = \"0.13\"\n+diesel = { version = \"1.4\", features = [\"postgres\"] }\n+dotenv = \"0.14\"\nalthea_types = { path = \"../althea_types\", features = [\"actix\"]}\nserde = \"1.0\"\nserde_derive = \"1.0\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update other minor deps
20,244
22.06.2019 18:02:21
14,400
a8680ac9a4bc5d0bffae07c4a09c27e8dc1ef401
Use crates.io Lettre
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -1086,7 +1086,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"lettre\"\nversion = \"0.9.2\"\n-source = \"git+https://github.com/lettre/lettre/#089b811bbcb9d9f5e9afe3380264ebd7ad2140bc\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1103,11 +1103,11 @@ dependencies = [\n[[package]]\nname = \"lettre_email\"\nversion = \"0.9.2\"\n-source = \"git+https://github.com/lettre/lettre/#089b811bbcb9d9f5e9afe3380264ebd7ad2140bc\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"email 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"lettre 0.9.2 (git+https://github.com/lettre/lettre/)\",\n+ \"lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1932,8 +1932,8 @@ dependencies = [\n\"hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"ipnetwork 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"lettre 0.9.2 (git+https://github.com/lettre/lettre/)\",\n- \"lettre_email 0.9.2 (git+https://github.com/lettre/lettre/)\",\n+ \"lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"lettre_email 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"minihttpse 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"mockito 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -3022,8 +3022,8 @@ dependencies = [\n\"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)\" = \"76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73\"\n\"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14\"\n\"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f\"\n-\"checksum lettre 0.9.2 (git+https://github.com/lettre/lettre/)\" = \"<none>\"\n-\"checksum lettre_email 0.9.2 (git+https://github.com/lettre/lettre/)\" = \"<none>\"\n+\"checksum lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c66afaa5dfadbb81d4e00fd1d1ab057c7cd4c799c5a44e0009386d553587e728\"\n+\"checksum lettre_email 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"bbb68ca999042d965476e47bbdbacd52db0927348b6f8062c44dd04a3b1fd43b\"\n\"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319\"\n\"checksum linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd\"\n\"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -58,8 +58,8 @@ num-traits=\"0.2\"\nclarity = \"0.1\"\neui48 = \"0.4\"\narrayvec = {version= \"0.4\", features = [\"serde-1\"]}\n-lettre = {git = \"https://github.com/lettre/lettre/\"}\n-lettre_email = {git = \"https://github.com/lettre/lettre/\"}\n+lettre = \"0.9\"\n+lettre_email = \"0.9\"\nphonenumber = \"0.2\"\nr2d2 = \"0.8\"\nsha3 = \"0.8\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Use crates.io Lettre
20,244
23.06.2019 07:58:12
14,400
817a49d2f2feab42bc584b39e16c60971447f771
Don't error out for traffic that can't be forwarded Our logs are filled with error messages for linklocal undeliverable traffic, since this traffic can't go anywhere it can't be billed in a pay per forward system and should be more gracefully ignored.
[ { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/lib.rs", "new_path": "althea_kernel_interface/src/lib.rs", "diff": "@@ -29,7 +29,7 @@ mod iptables;\nmod is_openwrt;\nmod link_local_tools;\nmod manipulate_uci;\n-mod open_tunnel;\n+pub mod open_tunnel;\nmod openwrt_ubus;\nmod ping_check;\nmod set_system_password;\n" }, { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/open_tunnel.rs", "new_path": "althea_kernel_interface/src/open_tunnel.rs", "diff": "@@ -28,7 +28,7 @@ fn test_to_wg_local() {\n)\n}\n-fn is_link_local(ip: IpAddr) -> bool {\n+pub fn is_link_local(ip: IpAddr) -> bool {\nif let IpAddr::V6(ip) = ip {\nreturn (ip.segments()[0] & 0xffc0) == 0xfe80;\n}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/traffic_watcher/mod.rs", "new_path": "rita/src/rita_common/traffic_watcher/mod.rs", "diff": "@@ -20,6 +20,7 @@ use ipnetwork::IpNetwork;\nuse settings::RitaCommonSettings;\nuse std::collections::HashMap;\nuse std::net::IpAddr;\n+use althea_kernel_interface::open_tunnel::is_link_local;\npub struct TrafficWatcher;\n@@ -105,6 +106,7 @@ pub fn get_babel_info(routes: Vec<Route>) -> Result<(HashMap<IpAddr, i128>, u32)\n};\n//TODO gracefully handle exceeding max price\n+ trace!(\"Inserting {} into the destiantons map\", IpAddr::V6(ip.ip()));\ndestinations.insert(IpAddr::V6(ip.ip()), i128::from(price + local_fee));\n}\n}\n@@ -269,6 +271,14 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n// to credit that debt to using the interface (since tunnel interfaces are unique to a neighbor)\n// we also look up the destination cost from babel using the destination ip\nfor ((ip, interface), bytes) in total_input_counters {\n+ // our counters have captured packets that are either multicast\n+ // or ipv6 link local, these are peer to peer comms and not billable\n+ // since they are not forwarded, ignore them\n+ if is_link_local(ip) || ip.is_multicast() {\n+ trace!(\"Discarding packets that can't be forwarded\");\n+ continue;\n+ }\n+\nlet state = (destinations.get(&ip), if_to_id.get(&interface));\nmatch state {\n(Some(dest), Some(id_from_if)) => {\n@@ -282,7 +292,7 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n}\n// this can be caused by a peer that has not yet formed a babel route\n// we use _ because ip_to_if is created from identites, if one fails the other must\n- (None, Some(id)) => warn!(\"We have an id {:?} but not destination\", id),\n+ (None, Some(if_to_id)) => warn!(\"We have an id {:?} but not destination for {}\", if_to_id.mesh_ip, ip),\n// if we have a babel route we should have a peer it's possible we have a mesh client sneaking in?\n(Some(dest), None) => warn!(\"We have a destination {:?} but no id\", dest),\n// dead entry?\n@@ -296,6 +306,14 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n// to credit that debt from us using the interface (since tunnel interfaces are unique to a neighbor)\n// we also look up the destination cost from babel using the destination ip\nfor ((ip, interface), bytes) in total_output_counters {\n+ // our counters have captured packets that are either multicast\n+ // or ipv6 link local, these are peer to peer comms and not billable\n+ // since they are not forwarded, ignore them\n+ if is_link_local(ip) || ip.is_multicast() {\n+ trace!(\"Discarding packets that can't be forwarded\");\n+ continue;\n+ }\n+\nlet state = (destinations.get(&ip), if_to_id.get(&interface));\nmatch state {\n(Some(dest), Some(id_from_if)) => match debts.get_mut(&id_from_if) {\n@@ -307,7 +325,7 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n},\n// this can be caused by a peer that has not yet formed a babel route\n// we use _ because ip_to_if is created from identites, if one fails the other must\n- (None, Some(id_from_if)) => warn!(\"We have an id {:?} but not destination\", id_from_if),\n+ (None, Some(id_from_if)) => warn!(\"We have an id {:?} but not destination for {}\", id_from_if.mesh_ip, ip),\n// if we have a babel route we should have a peer it's possible we have a mesh client sneaking in?\n(Some(dest), None) => warn!(\"We have a destination {:?} but no id\", dest),\n// dead entry?\n@@ -342,3 +360,22 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\nOk(())\n}\n+\n+#[cfg(test)]\n+mod tests {\n+ use std::net::IpAddr;\n+ use std::net::Ipv6Addr;\n+ use std::collections::HashMap;\n+#[test]\n+fn test_ip_lookup() {\n+ let ip_a: IpAddr = \"fd00::1337:e8f\".parse().unwrap();\n+ let ip_b: Ipv6Addr = \"fd00::1337:e8f\".parse().unwrap();\n+ let ip_b = IpAddr::V6(ip_b);\n+ assert_eq!(ip_a, ip_b);\n+ let mut map = HashMap::new();\n+ map.insert(ip_b, \"test\");\n+ assert!(map.get(&ip_a) != None);\n+\n+\n+}\n+}\n\\ No newline at end of file\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Don't error out for traffic that can't be forwarded Our logs are filled with error messages for linklocal undeliverable traffic, since this traffic can't go anywhere it can't be billed in a pay per forward system and should be more gracefully ignored.
20,244
23.06.2019 09:31:59
14,400
f496602a87caf154a9b9a5bc89fe2d5f7d0342ae
Move linklocal check to reduce cyclomatic complexity
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/traffic_watcher/mod.rs", "new_path": "rita/src/rita_common/traffic_watcher/mod.rs", "diff": "@@ -150,6 +150,15 @@ pub fn get_input_counters() -> Result<HashMap<(IpAddr, String), u64>, Error> {\n};\nfor (k, v) in input_counters {\n+ let ip = k.0;\n+ // our counters have captured packets that are either multicast\n+ // or ipv6 link local, these are peer to peer comms and not billable\n+ // since they are not forwarded, ignore them\n+ if is_link_local(ip) || ip.is_multicast() {\n+ trace!(\"Discarding packets that can't be forwarded\");\n+ continue;\n+ }\n+\n*total_input_counters.entry(k).or_insert(0) += v\n}\n@@ -195,6 +204,15 @@ pub fn get_output_counters() -> Result<HashMap<(IpAddr, String), u64>, Error> {\n};\nfor (k, v) in output_counters {\n+ let ip = k.0;\n+ // our counters have captured packets that are either multicast\n+ // or ipv6 link local, these are peer to peer comms and not billable\n+ // since they are not forwarded, ignore them\n+ if is_link_local(ip) || ip.is_multicast() {\n+ trace!(\"Discarding packets that can't be forwarded\");\n+ continue;\n+ }\n+\n*total_output_counters.entry(k).or_insert(0) += v\n}\n@@ -271,14 +289,6 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n// to credit that debt to using the interface (since tunnel interfaces are unique to a neighbor)\n// we also look up the destination cost from babel using the destination ip\nfor ((ip, interface), bytes) in total_input_counters {\n- // our counters have captured packets that are either multicast\n- // or ipv6 link local, these are peer to peer comms and not billable\n- // since they are not forwarded, ignore them\n- if is_link_local(ip) || ip.is_multicast() {\n- trace!(\"Discarding packets that can't be forwarded\");\n- continue;\n- }\n-\nlet state = (destinations.get(&ip), if_to_id.get(&interface));\nmatch state {\n(Some(dest), Some(id_from_if)) => {\n@@ -306,14 +316,6 @@ pub fn watch(routes: Vec<Route>, neighbors: &[Neighbor]) -> Result<(), Error> {\n// to credit that debt from us using the interface (since tunnel interfaces are unique to a neighbor)\n// we also look up the destination cost from babel using the destination ip\nfor ((ip, interface), bytes) in total_output_counters {\n- // our counters have captured packets that are either multicast\n- // or ipv6 link local, these are peer to peer comms and not billable\n- // since they are not forwarded, ignore them\n- if is_link_local(ip) || ip.is_multicast() {\n- trace!(\"Discarding packets that can't be forwarded\");\n- continue;\n- }\n-\nlet state = (destinations.get(&ip), if_to_id.get(&interface));\nmatch state {\n(Some(dest), Some(id_from_if)) => match debts.get_mut(&id_from_if) {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Move linklocal check to reduce cyclomatic complexity
20,244
23.06.2019 09:32:47
14,400
745530f8bbba4612f6d9616a4555b62a0858a63f
Turns out this is possible
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/traffic_watcher/mod.rs", "new_path": "rita/src/rita_client/traffic_watcher/mod.rs", "diff": "@@ -141,7 +141,7 @@ impl Handler<QueryExitDebts> for TrafficWatcher {\nDebtKeeper::from_registry().do_send(exit_replace);\n} else {\n- error!(\"The exit owes us? That shouldn't be possible!\");\n+ info!(\"The exit owes us? We must be a gateway!\");\n}\n}\nErr(e) => {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Turns out this is possible
20,244
22.06.2019 20:34:48
14,400
4da44517fa4569acca26305700c0be8ecbb48c1a
Fix bounty hunter dir
[ { "change_type": "MODIFY", "old_path": "integration-tests/rita.py", "new_path": "integration-tests/rita.py", "diff": "@@ -22,7 +22,7 @@ BABELD = os.path.join(os.path.dirname(__file__), 'deps/babeld/babeld')\nRITA_DEFAULT = os.path.join(os.path.dirname(__file__), '../target/debug/rita')\nRITA_EXIT_DEFAULT = os.path.join(os.path.dirname(__file__), '../target/debug/rita_exit')\n-BOUNTY_HUNTER_DEFAULT = os.path.join(os.path.dirname(__file__), '../target/debug/bounty_hunter')\n+BOUNTY_HUNTER_DEFAULT = os.path.join(os.path.dirname(__file__), '/tmp/bounty_hunter/target/debug/bounty_hunter')\n# Envs for controlling postgres\nPOSTGRES_USER = os.getenv('POSTGRES_USER')\n@@ -441,7 +441,7 @@ class World:\ndef setup_dbs(self):\nos.system(\"rm -rf bounty.db exit.db\")\n- bounty_repo_dir = \"..\"\n+ bounty_repo_dir = \"/tmp/bounty_hunter/\"\nexit_repo_dir = \"..\"\nbounty_index = self.bounty_id - 1\n@@ -452,16 +452,8 @@ class World:\nif COMPAT_LAYOUT:\n# Figure out whether release A or B was\n- # assigned to the exit and\n- # bounty\n+ # assigned to the exit\nlayout = COMPAT_LAYOUTS[COMPAT_LAYOUT]\n- if layout[bounty_index] == 'a':\n- bounty_repo_dir = DIR_A\n- elif layout[bounty_index] == 'b':\n- bounty_repo_dir = DIR_B\n- else:\n- print(\"DB setup: Unknown release {} assigned to bounty\".format(layout[bounty_index]))\n- sys.exit(1)\nif layout[exit_index] == 'a':\nexit_repo_dir = DIR_A\n@@ -475,7 +467,7 @@ class World:\ncwd = os.getcwd()\n# Go to bounty_hunter/ in the bounty's release\n- os.chdir(os.path.join(cwd, bounty_repo_dir, \"bounty_hunter\"))\n+ os.chdir(bounty_repo_dir)\nif VERBOSE:\nprint(\"DB setup: Entering {}/bounty_hunter\".format(bounty_repo_dir))\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix bounty hunter dir
20,244
23.06.2019 13:18:12
14,400
1b6d000773bbbf4b8aa57e0334905222bacd364a
Trace messages for common traffic watcher route debugging
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/traffic_watcher/mod.rs", "new_path": "rita/src/rita_common/traffic_watcher/mod.rs", "diff": "@@ -87,7 +87,7 @@ pub fn prepare_helper_maps(\n}\npub fn get_babel_info(routes: Vec<Route>) -> Result<(HashMap<IpAddr, i128>, u32), Error> {\n- trace!(\"Got routes: {:?}\", routes);\n+ trace!(\"Got {} routes: {:?}\", routes.len(), routes);\nlet mut destinations = HashMap::new();\n// we assume this matches what is actually set it babel becuase we\n// panic on startup if it does not get set correctly\n@@ -106,7 +106,10 @@ pub fn get_babel_info(routes: Vec<Route>) -> Result<(HashMap<IpAddr, i128>, u32)\n};\n//TODO gracefully handle exceeding max price\n- trace!(\"Inserting {} into the destiantons map\", IpAddr::V6(ip.ip()));\n+ trace!(\n+ \"Inserting {} into the destinations map\",\n+ IpAddr::V6(ip.ip())\n+ );\ndestinations.insert(IpAddr::V6(ip.ip()), i128::from(price + local_fee));\n}\n}\n@@ -120,6 +123,8 @@ pub fn get_babel_info(routes: Vec<Route>) -> Result<(HashMap<IpAddr, i128>, u32)\ni128::from(0),\n);\n+ trace!(\"{} destinations setup\", destinations.len());\n+\nOk((destinations, local_fee))\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Trace messages for common traffic watcher route debugging
20,244
24.06.2019 21:28:18
14,400
2d130e44dda9fbf74826101ba44fd398d2a35fed
Add retries to babel monitor and unmonitor operations I had some sense that this would eventually be required when I first wrote these handlers.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/tunnel_manager/mod.rs", "new_path": "rita/src/rita_common/tunnel_manager/mod.rs", "diff": "@@ -29,6 +29,7 @@ use std::fmt;\nuse std::net::{IpAddr, SocketAddr};\nuse std::path::Path;\nuse std::time::{Duration, Instant};\n+use tokio::timer::Delay;\n#[cfg(test)]\ntype HelloHandler = Mocker<rita_common::hello_handler::HelloHandler>;\n@@ -175,43 +176,73 @@ impl Tunnel {\n}\n/// Register this tunnel into Babel monitor\n- pub fn monitor(&self) {\n+ pub fn monitor(&self, retry_count: u8) {\ninfo!(\"Monitoring tunnel {}\", self.iface_name);\nlet iface_name = self.iface_name.clone();\nlet babel_port = SETTING.get_network().babel_port;\n+ let tunnel = self.clone();\nArbiter::spawn(\nopen_babel_stream(babel_port)\n.from_err()\n.and_then(move |stream| {\n- start_connection(stream).and_then(move |stream| {\n- monitor(stream, &iface_name)\n- })\n+ start_connection(stream).and_then(move |stream| monitor(stream, &iface_name))\n})\n.then(move |res| {\n- // if you ever see this error go and make a handler to delete the tunnel from memory\n- error!(\"Monitoring tunnel has failed! The tunnels cache is an incorrect state {:?}\" , res);\n- Ok(())}),\n+ // Errors here seem very very rare, I've only ever seen it happen\n+ // twice myself and I couldn't reproduce it, nontheless it's a pretty\n+ // bad situation so we will retry\n+ if let Err(e) = res {\n+ warn!(\"Tunnel monitor failed with {:?}, retrying in 1 second\", e);\n+ let when = Instant::now() + Duration::from_secs(1);\n+ let fut = Delay::new(when)\n+ .map_err(move |e| panic!(\"timer failed; err={:?}\", e))\n+ .and_then(move |_| {\n+ TunnelManager::from_registry().do_send(TunnelMonitorFailure {\n+ tunnel_to_retry: tunnel,\n+ retry_count,\n+ });\n+ Ok(())\n+ });\n+ Arbiter::spawn(fut);\n+ }\n+ Ok(())\n+ }),\n)\n}\n- pub fn unmonitor(&self) {\n+ pub fn unmonitor(&self, retry_count: u8) {\nwarn!(\"Unmonitoring tunnel {}\", self.iface_name);\nlet iface_name = self.iface_name.clone();\nlet babel_port = SETTING.get_network().babel_port;\n+ let tunnel = self.clone();\nArbiter::spawn(\nopen_babel_stream(babel_port)\n.from_err()\n.and_then(move |stream| {\n- start_connection(stream).and_then(move |stream| {\n- unmonitor(stream, &iface_name)\n- })\n+ start_connection(stream).and_then(move |stream| unmonitor(stream, &iface_name))\n})\n.then(move |res| {\n- // if you ever see this error go and make a handler to try and unlisten until it works\n- error!(\"Unmonitoring tunnel has failed! Babel will now listen on a non-existant tunnel {:?}\", res);\n- Ok(())}),\n+ // Errors here seem very very rare, I've only ever seen it happen\n+ // twice myself and I couldn't reproduce it, nontheless it's a pretty\n+ // bad situation so we will retry\n+ if let Err(e) = res {\n+ warn!(\"Tunnel unmonitor failed with {:?}, retrying in 1 second\", e);\n+ let when = Instant::now() + Duration::from_secs(1);\n+ let fut = Delay::new(when)\n+ .map_err(move |e| panic!(\"timer failed; err={:?}\", e))\n+ .and_then(move |_| {\n+ TunnelManager::from_registry().do_send(TunnelUnMonitorFailure {\n+ tunnel_to_retry: tunnel,\n+ retry_count,\n+ });\n+ Ok(())\n+ });\n+ Arbiter::spawn(fut);\n+ }\n+ Ok(())\n+ }),\n)\n}\n}\n@@ -237,6 +268,62 @@ impl Default for TunnelManager {\n}\n}\n+/// When listening on a tunnel fails we need to try again\n+pub struct TunnelMonitorFailure {\n+ pub tunnel_to_retry: Tunnel,\n+ pub retry_count: u8,\n+}\n+\n+impl Message for TunnelMonitorFailure {\n+ type Result = ();\n+}\n+\n+impl Handler<TunnelMonitorFailure> for TunnelManager {\n+ type Result = ();\n+\n+ fn handle(&mut self, msg: TunnelMonitorFailure, _: &mut Context<Self>) -> Self::Result {\n+ let tunnel_to_retry = msg.tunnel_to_retry;\n+ let retry_count = msg.retry_count;\n+\n+ if retry_count < 10 {\n+ tunnel_to_retry.monitor(retry_count + 1);\n+ } else {\n+ // this could result in networking not working, it's better to panic if we can't\n+ // do anything over the span of 10 retries and 10 seconds\n+ let message = \"ERROR: Monitoring tunnel has failed! The tunnels cache is an incorrect state\";\n+ error!(\"{}\", message);\n+ panic!(message);\n+ }\n+ }\n+}\n+\n+/// When listening on a tunnel fails we need to try again\n+pub struct TunnelUnMonitorFailure {\n+ pub tunnel_to_retry: Tunnel,\n+ pub retry_count: u8,\n+}\n+\n+impl Message for TunnelUnMonitorFailure {\n+ type Result = ();\n+}\n+\n+impl Handler<TunnelUnMonitorFailure> for TunnelManager {\n+ type Result = ();\n+\n+ fn handle(&mut self, msg: TunnelUnMonitorFailure, _: &mut Context<Self>) -> Self::Result {\n+ let tunnel_to_retry = msg.tunnel_to_retry;\n+ let retry_count = msg.retry_count;\n+\n+ if retry_count < 10 {\n+ tunnel_to_retry.unmonitor(retry_count + 1);\n+ } else {\n+ error!(\n+ \"Unmonitoring tunnel has failed! Babel will now listen on a non-existant tunnel\"\n+ );\n+ }\n+ }\n+}\n+\npub struct IdentityCallback {\npub local_identity: LocalIdentity,\npub peer: Peer,\n@@ -398,7 +485,7 @@ impl Handler<TriggerGC> for TunnelManager {\nfor tunnel in tunnels {\n// In the same spirit, we return the port to the free port pool only after tunnel\n// deletion goes well.\n- tunnel.unmonitor();\n+ tunnel.unmonitor(0);\nKI.del_interface(&tunnel.iface_name)?;\nself.free_ports.push(tunnel.listen_port);\n}\n@@ -777,7 +864,7 @@ impl TunnelManager {\n}\n}\nlet new_key = tunnel.neigh_id.global;\n- tunnel.monitor();\n+ tunnel.monitor(0);\nself.tunnels\n.entry(new_key)\n@@ -842,7 +929,7 @@ fn tunnel_state_change(\n);\nmatch tunnel.state.registration_state {\nRegistrationState::NotRegistered => {\n- tunnel.monitor();\n+ tunnel.monitor(0);\ntunnel.state.registration_state = RegistrationState::Registered;\n}\nRegistrationState::Registered => {\n@@ -854,7 +941,7 @@ fn tunnel_state_change(\ntrace!(\"Membership for identity {:?} is expired\", id);\nmatch tunnel.state.registration_state {\nRegistrationState::Registered => {\n- tunnel.unmonitor();\n+ tunnel.unmonitor(0);\ntunnel.state.registration_state = RegistrationState::NotRegistered;\n}\nRegistrationState::NotRegistered => {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add retries to babel monitor and unmonitor operations I had some sense that this would eventually be required when I first wrote these handlers.
20,244
25.06.2019 08:15:22
14,400
3529ec69c673f066563139b8894d77986ab3c03a
Hand edit Cargo.lock to revert openssl and openssl-sys This was causing a segfault between r2d2 and diesel
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -41,7 +41,7 @@ dependencies = [\n\"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -83,7 +83,7 @@ dependencies = [\n\"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1275,9 +1275,9 @@ dependencies = [\n\"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1435,7 +1435,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"openssl\"\n-version = \"0.10.23\"\n+version = \"0.10.19\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1443,7 +1443,7 @@ dependencies = [\n\"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n[[package]]\n@@ -1453,13 +1453,13 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"openssl-sys\"\n-version = \"0.9.47\"\n+version = \"0.9.42\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n- \"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -2443,7 +2443,7 @@ version = \"0.2.1\"\nsource = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)\",\n+ \"openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n]\n@@ -3061,9 +3061,9 @@ dependencies = [\n\"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef\"\n\"checksum oncemutex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"44d11de466f4a3006fe8a5e7ec84e93b79c70cb992ae0aa0eb631ad2df8abfe2\"\n\"checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409\"\n-\"checksum openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)\" = \"97c140cbb82f3b3468193dd14c1b88def39f341f68257f8a7fe8ed9ed3f628a5\"\n+\"checksum openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)\" = \"84321fb9004c3bce5611188a644d6171f895fa2889d155927d528782edb21c5d\"\n\"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)\" = \"77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de\"\n-\"checksum openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)\" = \"75bdd6dbbb4958d38e47a1d2348847ad1eb4dc205dc5d37473ae504391865acc\"\n+\"checksum openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)\" = \"cb534d752bf98cf363b473950659ac2546517f9c6be9723771614ab3f03bbc9e\"\n\"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13\"\n\"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337\"\n\"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Hand edit Cargo.lock to revert openssl and openssl-sys This was causing a segfault between r2d2 and diesel
20,244
25.06.2019 08:16:40
14,400
2edfc503ecd448d9a11e32c9c3a29db146582801
Bump for Beta 6 RC4
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -170,7 +170,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.5.2\",\n+ \"rita 0.5.3\",\n]\n[[package]]\n@@ -1905,7 +1905,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.2\"\n+version = \"0.5.3\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.2\"\n+version = \"0.5.3\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 6 RC3\";\n+pub static READABLE_VERSION: &str = \"Beta 6 RC4\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump for Beta 6 RC4
20,244
27.06.2019 07:04:16
14,400
9453a278974c54483159aa927397981146faedca
Speed up balance requests Placing the oracle in the slow loop is technically superior but annoys people when they make a deposit. So we will make more requests instead
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/oracle/mod.rs", "new_path": "rita/src/rita_common/oracle/mod.rs", "diff": "@@ -62,7 +62,7 @@ impl Default for Oracle {\n}\n/// How long we wait for a response from the full node\n-pub const ORACLE_TIMEOUT: Duration = Duration::from_secs(5);\n+pub const ORACLE_TIMEOUT: Duration = Duration::from_secs(2);\n#[derive(Message)]\npub struct Update();\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/rita_loop/fast_loop.rs", "new_path": "rita/src/rita_common/rita_loop/fast_loop.rs", "diff": "use crate::rita_common::debt_keeper::{DebtKeeper, SendUpdate};\n+use crate::rita_common::oracle::{Oracle, Update};\nuse crate::rita_common::peer_listener::GetPeers;\nuse crate::rita_common::peer_listener::PeerListener;\nuse crate::rita_common::traffic_watcher::{TrafficWatcher, Watch};\n@@ -82,6 +83,10 @@ impl Handler<Tick> for RitaFastLoop {\nlet start = Instant::now();\n+ // Update blockchain info put here because people really\n+ // hate it when their deposits take a while to show up\n+ Oracle::from_registry().do_send(Update());\n+\n// watch neighbors for billing\nArbiter::spawn(\nTunnelManager::from_registry()\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "new_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "diff": "use crate::rita_common::dao_manager::DAOManager;\nuse crate::rita_common::dao_manager::Tick as DAOTick;\n-use crate::rita_common::oracle::{Oracle, Update};\nuse crate::rita_common::payment_validator::{PaymentValidator, Validate};\nuse crate::rita_common::tunnel_manager::{TriggerGC, TunnelManager};\nuse crate::SETTING;\n@@ -82,9 +81,6 @@ impl Handler<Tick> for RitaSlowLoop {\n// Check payments\nPaymentValidator::from_registry().do_send(Validate());\n- // Update blockchain info\n- Oracle::from_registry().do_send(Update());\n-\nTunnelManager::from_registry().do_send(TriggerGC(Duration::from_secs(\nSETTING.get_network().tunnel_timeout_seconds,\n)));\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Speed up balance requests Placing the oracle in the slow loop is technically superior but annoys people when they make a deposit. So we will make more requests instead
20,244
27.06.2019 07:08:21
14,400
77b674ed50d85063239225c461e033e7fd0c9b53
Update for mandatory dyn syntax
[ { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/traffic_control.rs", "new_path": "althea_kernel_interface/src/traffic_control.rs", "diff": "@@ -8,7 +8,7 @@ use super::KernelInterface;\nuse failure::Error;\nuse std::net::Ipv4Addr;\n-impl KernelInterface {\n+impl dyn KernelInterface {\n/// Determines if the provided interface has a configured qdisc\npub fn has_qdisc(&self, iface_name: &str) -> Result<bool, Error> {\nlet result = self.run_command(\"tc\", &[\"qdisc\", \"show\", \"dev\", iface_name])?;\n" }, { "change_type": "MODIFY", "old_path": "babel_monitor/src/lib.rs", "new_path": "babel_monitor/src/lib.rs", "diff": "@@ -124,7 +124,7 @@ fn read_babel(\nlet output = String::from_utf8(buffer);\nif let Err(e) = output {\nreturn Box::new(future::err(TokioError(format!(\"{:?}\", e)).into()))\n- as Box<Future<Item = (TcpStream, String), Error = Error>>;\n+ as Box<dyn Future<Item = (TcpStream, String), Error = Error>>;\n}\nlet output = output.unwrap();\nlet output = output.trim_matches(char::from(0));\n@@ -148,7 +148,7 @@ fn read_babel(\nreturn Box::new(future::err(\nReadFailed(format!(\"Babel read timed out!\")).into(),\n))\n- as Box<Future<Item = (TcpStream, String), Error = Error>>;\n+ as Box<dyn Future<Item = (TcpStream, String), Error = Error>>;\n} else if full_buffer {\n// our buffer is full, we should recurse right away\nwarn!(\"Babel read larger than buffer! Consider increasing it's size\");\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/neighbors.rs", "new_path": "rita/src/rita_client/dashboard/neighbors.rs", "diff": "@@ -38,7 +38,7 @@ pub struct NodeInfo {\n/// The routes info might also belong in /exits or a dedicated /routes endpoint\npub fn get_neighbor_info(\n_req: HttpRequest,\n-) -> Box<Future<Item = Json<Vec<NodeInfo>>, Error = Error>> {\n+) -> Box<dyn Future<Item = Json<Vec<NodeInfo>>, Error = Error>> {\nBox::new(\nDebtKeeper::from_registry()\n.send(Dump {})\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/babel.rs", "new_path": "rita/src/rita_common/dashboard/babel.rs", "diff": "@@ -29,7 +29,7 @@ pub fn get_metric_factor(_req: HttpRequest) -> Result<HttpResponse, Error> {\nOk(HttpResponse::Ok().json(ret))\n}\n-pub fn set_local_fee(path: Path<u32>) -> Box<Future<Item = HttpResponse, Error = Error>> {\n+pub fn set_local_fee(path: Path<u32>) -> Box<dyn Future<Item = HttpResponse, Error = Error>> {\nlet new_fee = path.into_inner();\ndebug!(\"/local_fee/{} POST hit\", new_fee);\nlet babel_port = SETTING.get_network().babel_port;\n@@ -63,7 +63,7 @@ pub fn set_local_fee(path: Path<u32>) -> Box<Future<Item = HttpResponse, Error =\n}))\n}\n-pub fn set_metric_factor(path: Path<u32>) -> Box<Future<Item = HttpResponse, Error = Error>> {\n+pub fn set_metric_factor(path: Path<u32>) -> Box<dyn Future<Item = HttpResponse, Error = Error>> {\nlet new_factor = path.into_inner();\ndebug!(\"/metric_factor/{} POST hit\", new_factor);\nlet babel_port = SETTING.get_network().babel_port;\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/geoip.rs", "new_path": "rita/src/rita_exit/database/geoip.rs", "diff": "@@ -17,7 +17,7 @@ use std::collections::HashMap;\nuse std::net::IpAddr;\n/// gets the gateway ip for a given mesh IP\n-pub fn get_gateway_ip_single(mesh_ip: IpAddr) -> Box<Future<Item = IpAddr, Error = Error>> {\n+pub fn get_gateway_ip_single(mesh_ip: IpAddr) -> Box<dyn Future<Item = IpAddr, Error = Error>> {\nlet babel_port = SETTING.get_network().babel_port;\nBox::new(\n@@ -60,7 +60,7 @@ pub struct IpPair {\n/// not appear in the result vec\npub fn get_gateway_ip_bulk(\nmesh_ip_list: Vec<IpAddr>,\n-) -> Box<Future<Item = Vec<IpPair>, Error = Error>> {\n+) -> Box<dyn Future<Item = Vec<IpPair>, Error = Error>> {\nlet babel_port = SETTING.get_network().babel_port;\ntrace!(\"getting gateway ip bulk\");\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "@@ -70,7 +70,9 @@ pub fn get_database_connection(\n) -> impl Future<Item = PooledConnection<ConnectionManager<PgConnection>>, Error = Error> {\nmatch DB_POOL.read().unwrap().try_get() {\nSome(connection) => Box::new(future::ok(connection))\n- as Box<Future<Item = PooledConnection<ConnectionManager<PgConnection>>, Error = Error>>,\n+ as Box<\n+ dyn Future<Item = PooledConnection<ConnectionManager<PgConnection>>, Error = Error>,\n+ >,\nNone => {\ntrace!(\"No available db connection sleeping!\");\nlet when = Instant::now() + Duration::from_millis(100);\n@@ -180,7 +182,7 @@ pub fn signup_client(client: ExitClientIdentity) -> impl Future<Item = ExitState\nOk(record) => record,\nErr(e) => {\nreturn Box::new(future::err(e))\n- as Box<Future<Item = ExitState, Error = Error>>\n+ as Box<dyn Future<Item = ExitState, Error = Error>>\n}\n};\n@@ -525,7 +527,7 @@ pub fn setup_clients(\n/// ourselves from exceeding the upstream free tier. As an exit we are the upstream.\npub fn enforce_exit_clients(\nclients_list: Vec<exit_db::models::Client>,\n-) -> Box<Future<Item = (), Error = ()>> {\n+) -> Box<dyn Future<Item = (), Error = ()>> {\nlet start = Instant::now();\nBox::new(\nDebtKeeper::from_registry()\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/sms.rs", "new_path": "rita/src/rita_exit/database/sms.rs", "diff": "@@ -127,7 +127,7 @@ pub fn handle_sms_registration(\n})\n}\n})\n- })) as Box<Future<Item = ExitState, Error = Error>>\n+ })) as Box<dyn Future<Item = ExitState, Error = Error>>\n}\n// user has exhausted attempts but is still not submitting code\n(Some(_number), None, true) => Box::new(future::ok(ExitState::Pending {\n@@ -148,7 +148,7 @@ pub fn handle_sms_registration(\nphone_code: None,\n})\n})\n- })) as Box<Future<Item = ExitState, Error = Error>>\n+ })) as Box<dyn Future<Item = ExitState, Error = Error>>\n}\n// user has attempts remaining and is submitting a code\n(Some(number), Some(code), false) => {\n@@ -178,12 +178,12 @@ pub fn handle_sms_registration(\n})\n}\n})\n- })) as Box<Future<Item = ExitState, Error = Error>>\n+ })) as Box<dyn Future<Item = ExitState, Error = Error>>\n}\n// user did not submit a phonenumber\n(None, _, _) => Box::new(future::ok(ExitState::Denied {\nmessage: \"This exit requires a phone number to register!\".to_string(),\n- })) as Box<Future<Item = ExitState, Error = Error>>,\n+ })) as Box<dyn Future<Item = ExitState, Error = Error>>,\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/network_endpoints/mod.rs", "new_path": "rita/src/rita_exit/network_endpoints/mod.rs", "diff": "@@ -26,7 +26,7 @@ use std::time::SystemTime;\npub fn setup_request(\ntheir_id: (Json<ExitClientIdentity>, HttpRequest),\n-) -> Box<Future<Item = Json<ExitState>, Error = Error>> {\n+) -> Box<dyn Future<Item = Json<ExitState>, Error = Error>> {\ninfo!(\n\"Received setup request from, {}\",\ntheir_id.0.global.wg_public_key\n@@ -61,7 +61,7 @@ pub fn setup_request(\npub fn status_request(\ntheir_id: Json<ExitClientIdentity>,\n-) -> Box<Future<Item = Json<ExitState>, Error = Error>> {\n+) -> Box<dyn Future<Item = Json<ExitState>, Error = Error>> {\ntrace!(\n\"Received requester identity for status, {}\",\ntheir_id.global.wg_public_key\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update for mandatory dyn syntax
20,244
27.06.2019 07:11:45
14,400
7907a05091e3590d2cd206db4b28ca009a893637
Put the price oracle on the file wide timeout
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/oracle/mod.rs", "new_path": "rita/src/rita_common/oracle/mod.rs", "diff": "@@ -282,7 +282,7 @@ fn update_our_price() {\n.finish()\n.unwrap()\n.send()\n- .timeout(Duration::from_secs(1))\n+ .timeout(ORACLE_TIMEOUT)\n.then(move |response| {\nmatch response {\nOk(response) => {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Put the price oracle on the file wide timeout
20,244
28.06.2019 09:10:42
14,400
21ae5f87f231c4e1bf3cd18557ddfca91d73d2b9
Always reboot the router after toggling of any kind The linklocal address listener bug is very persistant, but this should slay it for all cases.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/interfaces.rs", "new_path": "rita/src/rita_client/dashboard/interfaces.rs", "diff": "@@ -312,20 +312,25 @@ pub fn ethernet_transform_mode(\nerror_occured = true;\n}\n}\n+ let locally_owned_ifname = ifname.to_string();\nif error_occured {\nlet res = KI.uci_revert(\"network\");\nbail!(\"Error running UCI commands! Revert attempted: {:?}\", res);\n} else if mesh_add {\n- trace!(\"Mesh add! going to sleep for 60 seconds to get a local fe80 address\");\n- let when = Instant::now() + Duration::from_secs(60);\n- let locally_owned_ifname = ifname.to_string();\n-\n- // repeated in Listen added here to prevent config inconsistency\nSETTING\n.get_network_mut()\n.peer_interfaces\n.insert(locally_owned_ifname.clone());\n+ }\n+ KI.uci_commit(&\"network\")?;\n+ KI.openwrt_reset_network()?;\n+ SETTING.write().unwrap().write(&ARGS.flag_config)?;\n+\n+ // We edited disk contents, force global sync\n+ KI.fs_sync()?;\n+ trace!(\"Successsfully transformed ethernet mode, rebooting in 60 seconds\");\n+ let when = Instant::now() + Duration::from_secs(60);\nlet fut = Delay::new(when)\n.map_err(|e| warn!(\"timer failed; err={:?}\", e))\n.and_then(move |_| {\n@@ -339,15 +344,6 @@ pub fn ethernet_transform_mode(\n});\nArbiter::spawn(fut);\n- }\n-\n- KI.uci_commit(&\"network\")?;\n- KI.openwrt_reset_network()?;\n- SETTING.write().unwrap().write(&ARGS.flag_config)?;\n-\n- // We edited disk contents, force global sync\n- KI.fs_sync()?;\n- trace!(\"Successsfully transformed ethernet mode, rebooting in 60 seconds\");\nOk(())\n}\n@@ -466,8 +462,23 @@ pub fn wlan_transform_mode(ifname: &str, a: InterfaceMode, b: InterfaceMode) ->\nres_b\n);\n} else if mesh_add {\n- let when = Instant::now() + Duration::from_millis(60000);\n+ let locally_owned_ifname = ifname.to_string();\n+ SETTING\n+ .get_network_mut()\n+ .peer_interfaces\n+ .insert(locally_owned_ifname.clone());\n+ }\n+\n+ KI.uci_commit(&\"wireless\")?;\n+ KI.uci_commit(&\"network\")?;\n+ KI.openwrt_reset_network()?;\n+ KI.openwrt_reset_wireless()?;\n+ SETTING.write().unwrap().write(&ARGS.flag_config)?;\n+\n+ // We edited disk contents, force global sync\n+ KI.fs_sync()?;\n+ let when = Instant::now() + Duration::from_millis(60000);\nlet fut = Delay::new(when)\n.map_err(|e| warn!(\"timer failed; err={:?}\", e))\n.and_then(move |_| {\n@@ -480,16 +491,6 @@ pub fn wlan_transform_mode(ifname: &str, a: InterfaceMode, b: InterfaceMode) ->\n});\nArbiter::spawn(fut);\n- }\n-\n- KI.uci_commit(&\"wireless\")?;\n- KI.uci_commit(&\"network\")?;\n- KI.openwrt_reset_network()?;\n- KI.openwrt_reset_wireless()?;\n- SETTING.write().unwrap().write(&ARGS.flag_config)?;\n-\n- // We edited disk contents, force global sync\n- KI.fs_sync()?;\nOk(())\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Always reboot the router after toggling of any kind The linklocal address listener bug is very persistant, but this should slay it for all cases.
20,244
28.06.2019 10:51:33
14,400
820ec6578bbcaf2cbea0435b9887fd08ab11ce04
Bump for Beta 6 RC5
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -170,7 +170,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.5.3\",\n+ \"rita 0.5.4\",\n]\n[[package]]\n@@ -1905,7 +1905,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.3\"\n+version = \"0.5.4\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.3\"\n+version = \"0.5.4\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 6 RC4\";\n+pub static READABLE_VERSION: &str = \"Beta 6 RC5\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump for Beta 6 RC5
20,244
28.06.2019 21:30:04
14,400
572640bae95b1eac4165a23d89d127f798dcc7b2
Remove println from Rita slow loop left these in by accident when debugging
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "new_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "diff": "@@ -101,13 +101,9 @@ fn set_babel_price() {\nopen_babel_stream(babel_port)\n.from_err()\n.and_then(move |stream| {\n- println!(\"We opened the stream!\");\nstart_connection(stream).and_then(move |stream| {\n- println!(\"We started the connection!\");\n- set_local_fee(stream, local_fee).and_then(move |stream| {\n- println!(\" we set the local fee\");\n- Ok(set_metric_factor(stream, metric_factor))\n- })\n+ set_local_fee(stream, local_fee)\n+ .and_then(move |stream| Ok(set_metric_factor(stream, metric_factor)))\n})\n})\n.timeout(SLOW_LOOP_TIMEOUT)\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Remove println from Rita slow loop left these in by accident when debugging
20,244
29.06.2019 17:01:54
14,400
195067c36ec8859a2f9ffa74c65727214f494fa6
Store usage data in /etc/ This wasn't being persisted, I need to nail that unix file system page to my wall
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/usage_tracker/mod.rs", "new_path": "rita/src/rita_common/usage_tracker/mod.rs", "diff": "@@ -30,7 +30,7 @@ use std::time::UNIX_EPOCH;\n/// On year worth of usage storage\nconst MAX_ENTRIES: usize = 8760;\n-/// Save every 24 hours\n+/// Save every 4 hours\nconst SAVE_FREQENCY: u64 = 4;\n/// In an effort to converge this module between the three possible bw tracking\n@@ -159,6 +159,8 @@ impl Supervised for UsageTracker {}\nimpl SystemService for UsageTracker {\nfn service_started(&mut self, _ctx: &mut Context<Self>) {\ninfo!(\"UsageTracker started\");\n+ // TODO: remove this in beta 7\n+ SETTING.get_network_mut().usage_tracker_file = \"/etc/rita-usage-tracker.json\".to_string();\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "settings/src/network.rs", "new_path": "settings/src/network.rs", "diff": "@@ -19,7 +19,7 @@ fn default_metric_factor() -> u32 {\n}\nfn default_usage_tracker_file() -> String {\n- \"/var/rita-usage-tracker.json\".to_string()\n+ \"/etc/rita-usage-tracker.json\".to_string()\n}\n#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Store usage data in /etc/ This wasn't being persisted, I need to nail that unix file system page to my wall
20,244
01.07.2019 10:49:20
14,400
c22ca3d5255efcb8191d970289bc473f4fc59ed1
Log price oracle status Most of the network isn't updating prices, but I can't tell if that's because of oracle issues or just because it's disabled.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/oracle/mod.rs", "new_path": "rita/src/rita_common/oracle/mod.rs", "diff": "@@ -85,6 +85,8 @@ impl Handler<Update> for Oracle {\nget_net_version(&web3, full_node);\nif oracle_enabled {\nupdate_our_price();\n+ } else {\n+ info!(\"User has disabled the price oracle\");\n}\nself.last_updated = Instant::now();\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Log price oracle status Most of the network isn't updating prices, but I can't tell if that's because of oracle issues or just because it's disabled.
20,244
02.07.2019 08:26:28
14,400
d82cf02d3f8d8c80aa86ae07550363075dfd6c54
Add saving to debt keeper This persists debts to the disk for the first time
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -22,11 +22,19 @@ use althea_types::{Identity, PaymentTx};\nuse failure::Error;\nuse num256::{Int256, Uint256};\nuse num_traits::Signed;\n+use serde_json::Error as SerdeError;\nuse settings::RitaCommonSettings;\nuse std::collections::HashMap;\n+use std::fs::File;\n+use std::io::Error as IOError;\n+use std::io::Read;\n+use std::io::Write;\nuse std::time::Duration;\nuse std::time::Instant;\n+/// Four hours\n+const SAVE_FREQENCY: Duration = Duration::from_secs(14400);\n+\n#[derive(Clone, Debug, Serialize, Deserialize)]\npub struct NodeDebtData {\n/// The amount this node has paid us, validated in payment_validator\n@@ -72,7 +80,10 @@ impl NodeDebtData {\npub type DebtData = HashMap<Identity, NodeDebtData>;\n+#[derive(Clone, Debug, Serialize, Deserialize)]\npub struct DebtKeeper {\n+ #[serde(skip_serializing, skip_deserializing)]\n+ last_save: Option<Instant>,\ndebt_data: DebtData,\n}\n@@ -208,6 +219,8 @@ impl Handler<SendUpdate> for DebtKeeper {\nfn handle(&mut self, _msg: SendUpdate, _ctx: &mut Context<Self>) -> Self::Result {\ntrace!(\"sending debt keeper update\");\n+ self.save_if_needed();\n+\n// in order to keep from overloading actix when we have thousands of debts to process\n// (mainly on exits) we batch tunnel change operations before sending them over\nlet mut debts_message = Vec::new();\n@@ -248,20 +261,84 @@ impl Handler<SendUpdate> for DebtKeeper {\nimpl Default for DebtKeeper {\nfn default() -> DebtKeeper {\n- Self::new()\n+ assert!(SETTING.get_payment().pay_threshold >= Int256::from(0));\n+ assert!(SETTING.get_payment().close_threshold <= Int256::from(0));\n+ let file = File::open(SETTING.get_payment().debts_file.clone());\n+ // if the loading process goes wrong for any reason, we just start again\n+ let blank_usage_tracker = DebtKeeper {\n+ last_save: Some(Instant::now()),\n+ debt_data: HashMap::new(),\n+ };\n+\n+ match file {\n+ Ok(mut file) => {\n+ let mut contents = String::new();\n+ match file.read_to_string(&mut contents) {\n+ Ok(_bytes_read) => {\n+ let deserialized: Result<DebtKeeper, SerdeError> =\n+ serde_json::from_str(&contents);\n+\n+ match deserialized {\n+ Ok(value) => value,\n+ Err(e) => {\n+ error!(\"Failed to deserialize usage tracker {:?}\", e);\n+ blank_usage_tracker\n+ }\n+ }\n+ }\n+ Err(e) => {\n+ error!(\"Failed to read usage tracker file! {:?}\", e);\n+ blank_usage_tracker\n+ }\n+ }\n+ }\n+ Err(e) => {\n+ error!(\"Failed to open usage tracker file! {:?}\", e);\n+ blank_usage_tracker\n+ }\n+ }\n}\n}\nimpl DebtKeeper {\n+ #[cfg(test)]\npub fn new() -> Self {\nassert!(SETTING.get_payment().pay_threshold >= Int256::from(0));\nassert!(SETTING.get_payment().close_threshold <= Int256::from(0));\nDebtKeeper {\n+ last_save: None,\ndebt_data: DebtData::new(),\n}\n}\n+ fn save_if_needed(&mut self) {\n+ match self.last_save {\n+ Some(val) => {\n+ if Instant::now() - val > SAVE_FREQENCY {\n+ if let Err(e) = self.save() {\n+ error!(\"Failed to save debts {:?}\", e);\n+ } else {\n+ self.last_save = Some(Instant::now());\n+ }\n+ }\n+ }\n+ None => {\n+ if let Err(e) = self.save() {\n+ error!(\"Failed to save debts {:?}\", e);\n+ } else {\n+ self.last_save = Some(Instant::now());\n+ }\n+ }\n+ }\n+ }\n+\n+ fn save(&mut self) -> Result<(), IOError> {\n+ let serialized = serde_json::to_string(self)?;\n+ let mut file = File::create(SETTING.get_payment().debts_file.clone())?;\n+ file.write_all(serialized.as_bytes())\n+ }\n+\nfn get_debts(&self) -> DebtData {\nself.debt_data.clone()\n}\n" }, { "change_type": "MODIFY", "old_path": "settings/src/payment.rs", "new_path": "settings/src/payment.rs", "diff": "@@ -49,6 +49,10 @@ fn default_system_chain() -> SystemChain {\nSystemChain::Ethereum\n}\n+fn default_debts_file() -> String {\n+ \"/etc/rita-debts.json\".to_string()\n+}\n+\n/// This struct is used by both rita and rita_exit to configure the dummy payment controller and\n/// debt keeper\n#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]\n@@ -99,6 +103,9 @@ pub struct PaymentSettings {\npub price_oracle_url: String,\n#[serde(default = \"default_system_chain\")]\npub system_chain: SystemChain,\n+ /// Full file path for Debts storage\n+ #[serde(default = \"default_debts_file\")]\n+ pub debts_file: String,\n}\nimpl Default for PaymentSettings {\n@@ -123,6 +130,7 @@ impl Default for PaymentSettings {\nprice_oracle_enabled: true,\nprice_oracle_url: \"https://updates.altheamesh.com/prices\".to_string(),\nsystem_chain: SystemChain::Ethereum,\n+ debts_file: default_debts_file(),\n}\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add saving to debt keeper This persists debts to the disk for the first time
20,244
02.07.2019 09:58:31
14,400
6dd4702b3116f5a6b886c47b576fe5051bd9cf0f
update wifi docstrings
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/wifi.rs", "new_path": "rita/src/rita_client/dashboard/wifi.rs", "diff": "@@ -10,22 +10,22 @@ use serde_json::Value;\nuse settings::RitaCommonSettings;\nuse std::collections::HashMap;\n-// legal in the US and around the world, don't allow odd channels\n+/// legal in the US and around the world, don't allow odd channels\npub const ALLOWED_TWO: [u16; 3] = [1, 6, 11];\n-// list of nonoverlapping 20mhz channels generally legal in NA, SA, EU, AU\n+/// list of nonoverlapping 20mhz channels generally legal in NA, SA, EU, AU\npub const ALLOWED_FIVE_20: [u16; 22] = [\n36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 144, 149, 153, 157,\n161, 165,\n];\n// Note: all channels wider than 20mhz are specified using the first channel they overlap\n// rather than the center value, no idea who though that was a good idea\n-// list of nonoverlapping 40mhz channels generally legal in NA, SA, EU, AU\n+/// list of nonoverlapping 40mhz channels generally legal in NA, SA, EU, AU\npub const ALLOWED_FIVE_40: [u16; 12] = [36, 44, 52, 60, 100, 108, 116, 124, 132, 140, 149, 157];\n-// list of nonoverlapping 80mhz channels generally legal in NA, SA, EU, AU\n+/// list of nonoverlapping 80mhz channels generally legal in NA, SA, EU, AU\npub const ALLOWED_FIVE_80: [u16; 6] = [36, 52, 100, 116, 132, 149];\n-// list of nonoverlapping 80mhz channels for the GLB1300\n+/// list of nonoverlapping 80mhz channels for the GLB1300\npub const ALLOWED_FIVE_80_B1300: [u16; 2] = [36, 149];\n-// list of nonoverlapping 160mhz channels generally legal in NA, SA, EU, AU\n+/// list of nonoverlapping 160mhz channels generally legal in NA, SA, EU, AU\npub const ALLOWED_FIVE_160: [u16; 2] = [36, 100];\n#[derive(Serialize, Deserialize, Clone, Debug)]\n@@ -229,7 +229,8 @@ pub fn set_wifi_multi(wifi_changes: Json<Vec<WifiToken>>) -> Result<HttpResponse\nOk(HttpResponse::Ok().json(()))\n}\n-/// Validates that the channel is both correct and legal\n+/// Validates that the channel is both correct and legal the underlying driver should prevent\n+/// channels for the wrong region, but we go tht extra mile just in case\nfn validate_channel(\nold_val: u16,\nnew_val: u16,\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
update wifi docstrings
20,244
02.07.2019 09:58:47
14,400
787f579b0da9333be87925f8c9a8ae76164a6e86
Remove usage tracker file change for Beta 7
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/usage_tracker/mod.rs", "new_path": "rita/src/rita_common/usage_tracker/mod.rs", "diff": "@@ -159,8 +159,6 @@ impl Supervised for UsageTracker {}\nimpl SystemService for UsageTracker {\nfn service_started(&mut self, _ctx: &mut Context<Self>) {\ninfo!(\"UsageTracker started\");\n- // TODO: remove this in beta 7\n- SETTING.get_network_mut().usage_tracker_file = \"/etc/rita-usage-tracker.json\".to_string();\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Remove usage tracker file change for Beta 7
20,244
02.07.2019 13:46:03
14,400
6efca104ab64b79fb097de9c3555b7350f693c7b
Add release feed toggles
[ { "change_type": "MODIFY", "old_path": "docs/api/router-dashboard.md", "new_path": "docs/api/router-dashboard.md", "diff": "@@ -1404,3 +1404,59 @@ amounts are in wei\n`curl -v -XGET http://192.168.10.1:4877/usage/payments`\n---\n+\n+## /release_feed/set/{feed}\n+\n+Sets the release feed for the router update process, there are 3 feeds in order of\n+least to most stable.\n+\n+ReleaseCandidate\n+PreRelease\n+GeneralAvailability\n+\n+- URL: `<rita ip>:<rita_dashboard_port>/release_feed/set/{feed}`\n+- Method: `POST`\n+- URL Params: `None`\n+- Data Params: `None`\n+- Success Response:\n+ - Code: 200 OK\n+ - Contents:\n+\n+```\n+()\n+```\n+\n+- Error Response: `500 Server Error`\n+\n+- Sample Call:\n+\n+`curl -XPOST 127.0.0.1:<rita_dashboard_port>/release_feed/set/PreRelease`\n+\n+---\n+\n+## /release_feed/get\n+\n+Gets the release feed for the router update process, there are 3 feeds in order of\n+least to most stable.\n+\n+ReleaseCandidate\n+PreRelease\n+GeneralAvailability\n+\n+- URL: `<rita ip>:<rita_dashboard_port>/release_feed/get`\n+- Method: `GET`\n+- URL Params: `None`\n+- Data Params: `None`\n+- Success Response:\n+ - Code: 200 OK\n+ - Contents:\n+\n+```\n+()\n+```\n+\n+- Error Response: `500 Server Error`\n+\n+- Sample Call:\n+\n+`curl http://192.168.10.1:4877/release_feed/get`\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -54,6 +54,7 @@ use crate::rita_client::dashboard::logging::*;\nuse crate::rita_client::dashboard::mesh_ip::*;\nuse crate::rita_client::dashboard::neighbors::*;\nuse crate::rita_client::dashboard::notifications::*;\n+use crate::rita_client::dashboard::release_feed::*;\nuse crate::rita_client::dashboard::system_chain::*;\nuse crate::rita_client::dashboard::update::*;\nuse crate::rita_client::dashboard::usage::*;\n@@ -299,6 +300,8 @@ fn start_client_dashboard() {\n.route(\"/usage/payments\", Method::GET, get_payments)\n.route(\"/router/update\", Method::POST, update_router)\n.route(\"/router/password\", Method::POST, set_pass)\n+ .route(\"/release_feed/get\", Method::GET, get_release_feed)\n+ .route(\"/release_feed/set/{feed}\", Method::POST, set_release_feed)\n.route(\"/wipe\", Method::POST, wipe)\n.route(\"/crash_actors\", Method::POST, crash_actors)\n})\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/mod.rs", "new_path": "rita/src/rita_client/dashboard/mod.rs", "diff": "@@ -11,6 +11,7 @@ pub mod logging;\npub mod mesh_ip;\npub mod neighbors;\npub mod notifications;\n+pub mod release_feed;\npub mod system_chain;\npub mod update;\npub mod usage;\n" }, { "change_type": "ADD", "old_path": null, "new_path": "rita/src/rita_client/dashboard/release_feed.rs", "diff": "+use actix_web::http::StatusCode;\n+use actix_web::HttpRequest;\n+use actix_web::HttpResponse;\n+use actix_web::Path;\n+use failure::Error;\n+use regex::Regex;\n+use std::fs::File;\n+use std::io::BufRead;\n+use std::io::BufReader;\n+use std::io::Write;\n+use std::str::FromStr;\n+\n+static CUSTOMFEEDS: &str = \"/etc/opkg/customfeeds.conf\";\n+static FEED_NAME: &str = \"openwrt_althea\";\n+\n+#[derive(Serialize, Deserialize, Clone, Debug, Copy)]\n+pub enum ReleaseStatus {\n+ ReleaseCandidate,\n+ PreRelease,\n+ GeneralAvailability,\n+}\n+\n+impl FromStr for ReleaseStatus {\n+ type Err = ();\n+ fn from_str(s: &str) -> Result<ReleaseStatus, ()> {\n+ match s {\n+ \"ReleaseCandidate\" => Ok(ReleaseStatus::ReleaseCandidate),\n+ \"PreRelease\" => Ok(ReleaseStatus::PreRelease),\n+ \"GeneralAvailability\" => Ok(ReleaseStatus::GeneralAvailability),\n+ _ => Err(()),\n+ }\n+ }\n+}\n+\n+fn get_lines(filename: &str) -> Result<Vec<String>, Error> {\n+ let f = File::open(filename)?;\n+ let file = BufReader::new(&f);\n+ let mut out_lines = Vec::new();\n+ for line in file.lines() {\n+ match line {\n+ Ok(val) => out_lines.push(val),\n+ Err(_) => break,\n+ }\n+ }\n+\n+ Ok(out_lines)\n+}\n+\n+fn write_out(content: Vec<String>) -> Result<(), Error> {\n+ // overwrite the old version\n+ let mut file = File::create(CUSTOMFEEDS)?;\n+ let mut final_ouput = String::new();\n+ for item in content {\n+ final_ouput += &format!(\"{}\\n\", item);\n+ }\n+ file.write_all(final_ouput.as_bytes())?;\n+ Ok(())\n+}\n+\n+pub fn get_release_feed(_req: HttpRequest) -> Result<HttpResponse, Error> {\n+ let lines = get_lines(CUSTOMFEEDS)?;\n+ for line in lines.iter() {\n+ if line.contains(&\"/rc/\".to_string()) && line.contains(&FEED_NAME.to_string()) {\n+ return Ok(HttpResponse::Ok().json(ReleaseStatus::ReleaseCandidate));\n+ } else if line.contains(&\"/pr/\".to_string()) && line.contains(&FEED_NAME.to_string()) {\n+ return Ok(HttpResponse::Ok().json(ReleaseStatus::PreRelease));\n+ }\n+ }\n+ Ok(HttpResponse::Ok().json(ReleaseStatus::GeneralAvailability))\n+}\n+\n+pub fn set_release_feed(path: Path<String>) -> Result<HttpResponse, Error> {\n+ let val = path.into_inner().parse();\n+ if val.is_err() {\n+ return Ok(HttpResponse::new(StatusCode::BAD_REQUEST)\n+ .into_builder()\n+ .json(format!(\n+ \"Could not parse {:?} into a ReleaseStatus enum!\",\n+ val\n+ )));\n+ }\n+ let val = val.unwrap();\n+\n+ let mut lines = get_lines(CUSTOMFEEDS)?;\n+\n+ for line in lines.iter_mut() {\n+ if line.contains(&FEED_NAME.to_string()) {\n+ let arch = get_arch(line)?;\n+ let src_line = match val {\n+ ReleaseStatus::GeneralAvailability => format!(\n+ \"src/gz openwrt_althea https://updates.altheamesh.com/packages/{}/althea\",\n+ arch\n+ ),\n+ ReleaseStatus::PreRelease => format!(\n+ \"src/gz openwrt_althea https://updates.altheamesh.com/pr/packages/{}/althea\",\n+ arch\n+ ),\n+ ReleaseStatus::ReleaseCandidate => format!(\n+ \"src/gz openwrt_althea https://updates.altheamesh.com/rc/packages/{}/althea\",\n+ arch\n+ ),\n+ };\n+ *line = src_line;\n+ }\n+ }\n+ write_out(lines)?;\n+\n+ Ok(HttpResponse::Ok().json(()))\n+}\n+\n+fn get_arch(line: &str) -> Result<String, Error> {\n+ lazy_static! {\n+ static ref RE: Regex = Regex::new(r\"(/packages/([A-Za-z0-9\\-_]+)/althea)\")\n+ .expect(\"Unable to compile regular expression\");\n+ }\n+ let cap = RE.captures(line).unwrap()[0].to_string();\n+ let arch = cap\n+ .replace(\"packages\", \"\")\n+ .replace(\"althea\", \"\")\n+ .replace(\"/\", \"\");\n+ Ok(arch)\n+}\n+\n+#[test]\n+fn test_regex_com() {\n+ let val = get_arch(\n+ \"src/gz openwrt_althea https://updates.altheamesh.com/rc/packages/mipsel_24kc/althea\",\n+ );\n+ assert_eq!(&val.unwrap(), \"mipsel_24kc\");\n+}\n+\n+#[test]\n+fn test_regex_net() {\n+ let val =\n+ get_arch(\"src/gz openwrt_althea https://updates.althea.net/packages/mipsel_24kc/althea\");\n+ assert_eq!(&val.unwrap(), \"mipsel_24kc\");\n+}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add release feed toggles
20,244
02.07.2019 13:46:49
14,400
2f8dc0609e908b0797d72d5db544d0578d05329a
Lazy static some missed regexes
[ { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/get_neighbors.rs", "new_path": "althea_kernel_interface/src/get_neighbors.rs", "diff": "@@ -16,8 +16,13 @@ impl dyn KernelInterface {\ntrace!(\"Got {:?} from `ip neighbor`\", output);\nlet mut vec = Vec::new();\n- let re = Regex::new(r\"(\\S*).*dev (\\S*).*lladdr (\\S*).*(REACHABLE|STALE|DELAY)\").unwrap();\n- for caps in re.captures_iter(&String::from_utf8(output.stdout)?) {\n+\n+ lazy_static! {\n+ static ref RE: Regex =\n+ Regex::new(r\"(\\S*).*dev (\\S*).*lladdr (\\S*).*(REACHABLE|STALE|DELAY)\")\n+ .expect(\"Unable to compile regular expression\");\n+ }\n+ for caps in RE.captures_iter(&String::from_utf8(output.stdout)?) {\ntrace!(\"Regex captured {:?}\", caps);\nvec.push((IpAddr::from_str(&caps[1])?, caps[2].to_string()));\n" }, { "change_type": "MODIFY", "old_path": "althea_kernel_interface/src/interface_tools.rs", "new_path": "althea_kernel_interface/src/interface_tools.rs", "diff": "@@ -12,8 +12,12 @@ impl dyn KernelInterface {\nlet links = String::from_utf8(self.run_command(\"ip\", &[\"link\"])?.stdout)?;\nlet mut vec = Vec::new();\n- let re = Regex::new(r\"[0-9]+: (.*?)(:|@)\").unwrap();\n- for caps in re.captures_iter(&links) {\n+\n+ lazy_static! {\n+ static ref RE: Regex =\n+ Regex::new(r\"[0-9]+: (.*?)(:|@)\").expect(\"Unable to compile regular expression\");\n+ }\n+ for caps in RE.captures_iter(&links) {\nvec.push(String::from(&caps[1]));\n}\n@@ -40,8 +44,11 @@ impl dyn KernelInterface {\nlet output = self.run_command(\"wg\", &[\"show\", name, \"endpoints\"])?;\nlet stdout = String::from_utf8(output.stdout)?;\n- let reg = Regex::new(r\"(?:([0-9a-f:]+)%)|(?:([0-9\\.]+):)\")?;\n- let cap = reg.captures(&stdout);\n+ lazy_static! {\n+ static ref RE: Regex = Regex::new(r\"(?:([0-9a-f:]+)%)|(?:([0-9\\.]+):)\")\n+ .expect(\"Unable to compile regular expression\");\n+ }\n+ let cap = RE.captures(&stdout);\nmatch cap {\nSome(cap) => {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Lazy static some missed regexes
20,244
08.07.2019 09:51:32
14,400
36fecdb7099fcf0bbffcbec6a5919c38a7b27132
Add more details to the suspend message Seeing some strange behavior where a node will suspend for a very brief few seconds I don't see any way for the debt to change that fast so we'll improve the logging to see what's going on.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -506,7 +506,9 @@ impl DebtKeeper {\n}\ninfo!(\n- \"debt is below close threshold for {}. suspending forwarding\",\n+ \"debt {} is below close threshold {} for {}. suspending forwarding\",\n+ debt_data.debt,\n+ close_threshold,\nident.mesh_ip\n);\ndebt_data.action = DebtAction::SuspendTunnel;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add more details to the suspend message Seeing some strange behavior where a node will suspend for a very brief few seconds I don't see any way for the debt to change that fast so we'll improve the logging to see what's going on.
20,244
09.07.2019 07:58:18
14,400
38f9a08d033e43f9cdb006a4ace53a030ebba8b1
Fix debtkeeper error messages
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -281,19 +281,19 @@ impl Default for DebtKeeper {\nmatch deserialized {\nOk(value) => value,\nErr(e) => {\n- error!(\"Failed to deserialize usage tracker {:?}\", e);\n+ error!(\"Failed to deserialize debts file {:?}\", e);\nblank_usage_tracker\n}\n}\n}\nErr(e) => {\n- error!(\"Failed to read usage tracker file! {:?}\", e);\n+ error!(\"Failed to read debts file! {:?}\", e);\nblank_usage_tracker\n}\n}\n}\nErr(e) => {\n- error!(\"Failed to open usage tracker file! {:?}\", e);\n+ error!(\"Failed to open debts file! {:?}\", e);\nblank_usage_tracker\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix debtkeeper error messages
20,244
09.07.2019 08:03:10
14,400
971572dd739b2b6c1bd7a7b306dc40d8423779cb
Fix debtkeeper var name
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -265,7 +265,7 @@ impl Default for DebtKeeper {\nassert!(SETTING.get_payment().close_threshold <= Int256::from(0));\nlet file = File::open(SETTING.get_payment().debts_file.clone());\n// if the loading process goes wrong for any reason, we just start again\n- let blank_usage_tracker = DebtKeeper {\n+ let blank_debt_keeper = DebtKeeper {\nlast_save: Some(Instant::now()),\ndebt_data: HashMap::new(),\n};\n@@ -282,19 +282,19 @@ impl Default for DebtKeeper {\nOk(value) => value,\nErr(e) => {\nerror!(\"Failed to deserialize debts file {:?}\", e);\n- blank_usage_tracker\n+ blank_debt_keeper\n}\n}\n}\nErr(e) => {\nerror!(\"Failed to read debts file! {:?}\", e);\n- blank_usage_tracker\n+ blank_debt_keeper\n}\n}\n}\nErr(e) => {\nerror!(\"Failed to open debts file! {:?}\", e);\n- blank_usage_tracker\n+ blank_debt_keeper\n}\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix debtkeeper var name
20,244
09.07.2019 08:31:49
14,400
574955f5b3be0a729e4dbbcdeaddee1f22a64f54
Save debts on start
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -266,7 +266,7 @@ impl Default for DebtKeeper {\nlet file = File::open(SETTING.get_payment().debts_file.clone());\n// if the loading process goes wrong for any reason, we just start again\nlet blank_debt_keeper = DebtKeeper {\n- last_save: Some(Instant::now()),\n+ last_save: None,\ndebt_data: HashMap::new(),\n};\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Save debts on start
20,244
10.07.2019 19:18:44
14,400
068911225123f756148ef23040c6812bf323b3ec
Check all major user properties in check_user()
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/database_tools.rs", "new_path": "rita/src/rita_exit/database/database_tools.rs", "diff": "@@ -77,10 +77,6 @@ pub fn update_client(client: &ExitClientIdentity, conn: &PgConnection) -> Result\n.execute(&*conn)?;\n}\n- diesel::update(clients.find(&client.global.mesh_ip.to_string()))\n- .set(last_seen.eq(secs_since_unix_epoch() as i64))\n- .execute(&*conn)?;\n-\ndiesel::update(clients.find(&client.global.mesh_ip.to_string()))\n.set(last_seen.eq(secs_since_unix_epoch() as i64))\n.execute(&*conn)?;\n@@ -143,10 +139,17 @@ pub fn text_sent(client: &ExitClientIdentity, conn: &PgConnection, val: i32) ->\nOk(())\n}\n-pub fn client_exists(ip: &IpAddr, conn: &PgConnection) -> Result<bool, Error> {\n+pub fn client_exists(client: &ExitClientIdentity, conn: &PgConnection) -> Result<bool, Error> {\nuse self::schema::clients::dsl::*;\ntrace!(\"Checking if client exists\");\n- Ok(select(exists(clients.filter(mesh_ip.eq(ip.to_string())))).get_result(&*conn)?)\n+ let ip = client.global.mesh_ip;\n+ let wg = client.global.wg_public_key;\n+ let key = client.global.eth_address;\n+ let filtered_list = clients\n+ .filter(mesh_ip.eq(ip.to_string()))\n+ .filter(wg_pubkey.eq(wg.to_string()))\n+ .filter(eth_address.eq(key.to_string()));\n+ Ok(select(exists(filtered_list)).get_result(&*conn)?)\n}\npub fn delete_client(client: ExitClient, connection: &PgConnection) -> Result<(), Error> {\n@@ -195,6 +198,10 @@ pub fn update_low_balance_notification_time(\nconn: &PgConnection,\n) -> Result<(), Error> {\nuse self::schema::clients::dsl::{clients, last_balance_warning_time, wg_pubkey};\n+ info!(\n+ \"Updating low balance notification time for {} {:?}\",\n+ client.global.wg_public_key, client\n+ );\ndiesel::update(clients.filter(wg_pubkey.eq(client.global.wg_public_key.to_string())))\n.set(last_balance_warning_time.eq(secs_since_unix_epoch()))\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "@@ -148,7 +148,7 @@ fn create_or_update_user_record(\n) -> Result<models::Client, Error> {\nuse self::schema::clients::dsl::clients;\nlet client_mesh_ip = client.global.mesh_ip;\n- if client_exists(&client_mesh_ip, conn)? {\n+ if client_exists(&client, conn)? {\nupdate_client(&client, conn)?;\nOk(get_client(client_mesh_ip, conn)?)\n} else {\n@@ -234,7 +234,7 @@ pub fn client_status(client: ExitClientIdentity, conn: &PgConnection) -> Result<\ntrace!(\"Checking if record exists for {:?}\", client.global.mesh_ip);\n- if client_exists(&client.global.mesh_ip, &conn)? {\n+ if client_exists(&client, &conn)? {\ntrace!(\"record exists, updating\");\nlet their_record = get_client(client_mesh_ip, &conn)?;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Check all major user properties in check_user()
20,249
03.07.2019 12:22:12
25,200
3d026eb6ac2b5dd1c79c975d1dd257e18c1f2ca5
Add /router/reboot endpoint
[ { "change_type": "MODIFY", "old_path": "rita/src/client.rs", "new_path": "rita/src/client.rs", "diff": "@@ -55,8 +55,8 @@ use crate::rita_client::dashboard::mesh_ip::*;\nuse crate::rita_client::dashboard::neighbors::*;\nuse crate::rita_client::dashboard::notifications::*;\nuse crate::rita_client::dashboard::release_feed::*;\n+use crate::rita_client::dashboard::router::*;\nuse crate::rita_client::dashboard::system_chain::*;\n-use crate::rita_client::dashboard::update::*;\nuse crate::rita_client::dashboard::usage::*;\nuse crate::rita_client::dashboard::wifi::*;\nuse crate::rita_common::dashboard::auth::*;\n@@ -298,6 +298,7 @@ fn start_client_dashboard() {\n.route(\"/usage/relay\", Method::GET, get_relay_usage)\n.route(\"/usage/client\", Method::GET, get_client_usage)\n.route(\"/usage/payments\", Method::GET, get_payments)\n+ .route(\"/router/reboot\", Method::POST, reboot_router)\n.route(\"/router/update\", Method::POST, update_router)\n.route(\"/router/password\", Method::POST, set_pass)\n.route(\"/release_feed/get\", Method::GET, get_release_feed)\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/mod.rs", "new_path": "rita/src/rita_client/dashboard/mod.rs", "diff": "@@ -12,7 +12,7 @@ pub mod mesh_ip;\npub mod neighbors;\npub mod notifications;\npub mod release_feed;\n+pub mod router;\npub mod system_chain;\n-pub mod update;\npub mod usage;\npub mod wifi;\n" }, { "change_type": "RENAME", "old_path": "rita/src/rita_client/dashboard/update.rs", "new_path": "rita/src/rita_client/dashboard/router.rs", "diff": "use crate::KI;\n-use ::actix_web::{HttpRequest, HttpResponse};\n+use actix_web::{HttpRequest, HttpResponse};\nuse failure::Error;\n+pub fn reboot_router(_req: HttpRequest) -> Result<HttpResponse, Error> {\n+ if KI.is_openwrt() {\n+ KI.run_command(\"reboot\", &[])?;\n+ Ok(HttpResponse::Ok().json(()))\n+ } else {\n+ Ok(HttpResponse::Ok().json(\"This isn't an OpenWRT device, doing nothing\"))\n+ }\n+}\n+\npub fn update_router(_req: HttpRequest) -> Result<HttpResponse, Error> {\nif KI.is_openwrt() {\nKI.run_command(\"ash\", &[\"/etc/update.ash\"])?;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add /router/reboot endpoint
20,249
05.07.2019 09:07:09
25,200
0ecf81d8282a295a6228006d61c915a6ce65aff8
Reset all exit states to NEW after private key import
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "new_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "diff": "use crate::ARGS;\nuse crate::KI;\nuse crate::SETTING;\n-use ::actix_web::{HttpRequest, HttpResponse, Json};\n+use actix_web::{HttpRequest, HttpResponse, Json};\n+use althea_types::ExitState;\nuse clarity::PrivateKey;\nuse failure::Error;\n+use settings::client::RitaClientSettings;\nuse settings::FileWrite;\nuse settings::RitaCommonSettings;\nuse std::collections::HashMap;\n@@ -39,6 +41,11 @@ pub fn set_eth_private_key(data: Json<EthPrivateKey>) -> Result<HttpResponse, Er\nSETTING.get_payment_mut().eth_private_key = Some(pk);\nSETTING.get_payment_mut().eth_address = Some(pk.to_public_key()?);\n+ let mut exits = SETTING.get_exits_mut();\n+ for mut exit in exits.iter_mut() {\n+ exit.1.info = ExitState::New;\n+ }\n+\n// try and save the config and fail if we can't\nif let Err(e) = SETTING.write().unwrap().write(&ARGS.flag_config) {\nreturn Err(e);\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Reset all exit states to NEW after private key import
20,249
11.07.2019 16:30:43
25,200
cb0fa24367770bc8c1b0cac4c5961d4d2f153bf6
Reset wireguard pub key after private key import, release write locks
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "new_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "diff": "@@ -38,13 +38,27 @@ pub fn set_eth_private_key(data: Json<EthPrivateKey>) -> Result<HttpResponse, Er\ndebug!(\"/eth_private_key POST hit\");\nlet pk: PrivateKey = data.into_inner().eth_private_key.parse()?;\n- SETTING.get_payment_mut().eth_private_key = Some(pk);\n- SETTING.get_payment_mut().eth_address = Some(pk.to_public_key()?);\n- let mut exits = SETTING.get_exits_mut();\n- for mut exit in exits.iter_mut() {\n+ let mut payment_settings = SETTING.get_payment_mut();\n+ payment_settings.eth_private_key = Some(pk);\n+ payment_settings.eth_address = Some(pk.to_public_key()?);\n+ drop(payment_settings);\n+\n+ // remove the wg_public_key to force exit re-registration\n+ let mut network_settings = SETTING.get_network_mut();\n+ network_settings.wg_public_key = None;\n+ drop(network_settings);\n+\n+ // unset current exit\n+ let mut exit_client_settings = SETTING.get_exit_client_mut();\n+ exit_client_settings.current_exit = None;\n+ drop(exit_client_settings);\n+\n+ let mut exit_settings = SETTING.get_exits_mut();\n+ for mut exit in exit_settings.iter_mut() {\nexit.1.info = ExitState::New;\n}\n+ drop(exit_settings);\n// try and save the config and fail if we can't\nif let Err(e) = SETTING.write().unwrap().write(&ARGS.flag_config) {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Reset wireguard pub key after private key import, release write locks
20,244
12.07.2019 17:13:27
14,400
793d2f9f3ee37dff893a859415b5c2f8f64dc934
Fix DAO fee payment We would panic when trying to pay the dao fee becuase the wgkey was not valid
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dao_manager/mod.rs", "new_path": "rita/src/rita_common/dao_manager/mod.rs", "diff": "@@ -92,7 +92,9 @@ impl Handler<Tick> for DAOManager {\nlet dao_identity = Identity {\neth_address: address,\n- wg_public_key: \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF=\"\n+ // this key has no meaning, it's here so that we don't have to change\n+ // the identity indexing\n+ wg_public_key: \"YJhxFPv+NVeU5e+eBmwIXFd/pVdgk61jUHojuSt8IU0=\"\n.parse()\n.unwrap(),\nmesh_ip: \"::1\".parse().unwrap(),\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix DAO fee payment We would panic when trying to pay the dao fee becuase the wgkey was not valid
20,244
13.07.2019 18:43:24
14,400
7510a2b252a5f60d0189e11716f6cd7cc709fcd8
Check for client conflicts on registration
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/database_tools.rs", "new_path": "rita/src/rita_exit/database/database_tools.rs", "diff": "@@ -152,6 +152,22 @@ pub fn client_exists(client: &ExitClientIdentity, conn: &PgConnection) -> Result\nOk(select(exists(filtered_list)).get_result(&*conn)?)\n}\n+/// True if there is any client with the same eth address, wg key, or ip address already registered\n+pub fn client_conflict(client: &ExitClientIdentity, conn: &PgConnection) -> Result<bool, Error> {\n+ use self::schema::clients::dsl::*;\n+ trace!(\"Checking if client exists\");\n+ let ip = client.global.mesh_ip;\n+ let wg = client.global.wg_public_key;\n+ let key = client.global.eth_address;\n+ let ip_match = clients.filter(mesh_ip.eq(ip.to_string()));\n+ let wg_key_match = clients.filter(wg_pubkey.eq(wg.to_string()));\n+ let eth_address_match = clients.filter(eth_address.eq(key.to_string()));\n+ let ip_exists = select(exists(ip_match)).get_result(&*conn)?;\n+ let wg_exists = select(exists(wg_key_match)).get_result(&*conn)?;\n+ let eth_exists = select(exists(eth_address_match)).get_result(&*conn)?;\n+ Ok(ip_exists || eth_exists || wg_exists)\n+}\n+\npub fn delete_client(client: ExitClient, connection: &PgConnection) -> Result<(), Error> {\nuse self::schema::clients::dsl::*;\ninfo!(\"Deleting clients {:?} in database\", client);\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/mod.rs", "new_path": "rita/src/rita_exit/database/mod.rs", "diff": "use crate::rita_common::debt_keeper::DebtAction;\nuse crate::rita_common::debt_keeper::DebtKeeper;\nuse crate::rita_common::debt_keeper::GetDebtsList;\n+use crate::rita_exit::database::database_tools::client_conflict;\nuse crate::rita_exit::database::database_tools::client_exists;\nuse crate::rita_exit::database::database_tools::delete_client;\nuse crate::rita_exit::database::database_tools::get_client;\n@@ -177,13 +178,25 @@ pub fn signup_client(client: ExitClientIdentity) -> impl Future<Item = ExitState\nverify_ip(gateway_ip).and_then(move |verify_status| {\nget_country(gateway_ip).and_then(move |user_country| {\nget_database_connection().and_then(move |conn| {\n+ // check if we have any users with conflicting details\n+ match client_conflict(&client, &conn) {\n+ Ok(true) => {\n+ return Box::new(future::ok(ExitState::Denied {\n+ message: format!(\n+ \"Partially changed registration details! Please re-register {}\",\n+ display_hashset(&SETTING.get_allowed_countries()),\n+ ),\n+ }))\n+ as Box<dyn Future<Item = ExitState, Error = Error>>\n+ }\n+ Ok(false) => {}\n+ Err(e) => return Box::new(future::err(e)),\n+ }\n+\nlet their_record =\nmatch create_or_update_user_record(&conn, &client, user_country) {\nOk(record) => record,\n- Err(e) => {\n- return Box::new(future::err(e))\n- as Box<dyn Future<Item = ExitState, Error = Error>>\n- }\n+ Err(e) => return Box::new(future::err(e)),\n};\n// either update and grab an existing entry or create one\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Check for client conflicts on registration
20,244
14.07.2019 08:36:06
14,400
8b4e1ab7bc00e10062207761a75f4ea38de7a0b3
There's no conflict if the client exists
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/database_tools.rs", "new_path": "rita/src/rita_exit/database/database_tools.rs", "diff": "@@ -155,6 +155,12 @@ pub fn client_exists(client: &ExitClientIdentity, conn: &PgConnection) -> Result\n/// True if there is any client with the same eth address, wg key, or ip address already registered\npub fn client_conflict(client: &ExitClientIdentity, conn: &PgConnection) -> Result<bool, Error> {\nuse self::schema::clients::dsl::*;\n+ // we can't possibly have a conflict if we have exactly this client already\n+ // since client exists checks all major details this is safe and will return false\n+ // if it's not exactly the same client\n+ if client_exists(client, conn)? {\n+ return Ok(false);\n+ }\ntrace!(\"Checking if client exists\");\nlet ip = client.global.mesh_ip;\nlet wg = client.global.wg_public_key;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
There's no conflict if the client exists
20,244
09.07.2019 11:08:01
14,400
82c7b9ddfe82060033afb12fc2c438897f4d4e0f
Add local Docker image that runs the integration tests This handles the pesky problem of running a local Postgres server in order to run the integration tests.
[ { "change_type": "MODIFY", "old_path": "README.md", "new_path": "README.md", "diff": "@@ -5,17 +5,18 @@ This contains many (although confusingly not all) of the Rust components for the\nThe primary binary crate in this repo is 'rita' which produces two binaries 'rita' and 'rita_exit'\nsee the file headers for descriptions.\n-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.\n+This is primarily an infrastructure repo, to get a working version of Althea for real world use you should look at [installer](https://github.com/althea-mesh/installer) for desktop linux and [althea-firmware](https://github.com/althea-mesh/\n+althea-firmware) for OpenWRT.\n## Building\nDebian:\n- sudo apt-get install build-essential libssl-dev libsqlite3-dev pkg-config postgresql-dev\n+ sudo apt-get install build-essential libssl-dev libsqlite3-dev pkg-config postgresql-server-dev-all\nUbuntu:\n- sudo apt-get install build-essential libssl-dev libsqlite3-dev pkg-config postgresql-dev\n+ sudo apt-get install build-essential libssl-dev libsqlite3-dev pkg-config postgresql-server-dev-all\nCentos:\n@@ -39,9 +40,22 @@ If you want to build a development build that contains unsafe options that are n\ncargo build --all --features development\n-## Development\n+## Testing\n-Please install required git hooks before contributing. Those hooks are responsible for making the codebase consistent.\n+If you wish to test a commit you are developing, or just see Rita in action locally run\n+\n+ bash scripts/test.sh\n+\n+This runs both the unit and integration tests you will need to have installed the depenencies listed in the Building section\n+as well as docker and have the [WireGuard](https://www.wireguard.com/install/) kernel module loaded for your operating system.\n+\n+## Contributing\n+\n+This codebase is formatted using rustfmt, you can format your commits manually with\n+\n+ cargo +stable fmt\n+\n+Or install our git hook to do it for you.\n```sh\nrustup component add rustfmt-preview --toolchain nightly\n" }, { "change_type": "ADD", "old_path": null, "new_path": "integration-tests/container/Dockerfile", "diff": "+FROM postgres\n+# we pull in the git tar instead of the local folder becuase the raw code is much much smaller\n+# note that changes have to be checked in to be pulled in and tested!\n+ADD rita.tar.gz /rita\n+RUN echo \"deb http://deb.debian.org/debian/ unstable main\" > /etc/apt/sources.list.d/unstable.list\n+RUN printf 'Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n' > /etc/apt/preferences.d/limit-unstable\n+RUN apt-get update && apt-get install -y sudo iputils-ping iproute2 jq default-libmysqlclient-dev libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev iperf3 python3-pip bridge-utils wireguard linux-source curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n+RUN curl https://sh.rustup.rs -sSf | sh -s -- -y\n+ENV POSTGRES_USER=postgres\n+ENV POSTGRES_BIN=/usr/lib/postgresql/11/bin/postgres\n+ENV INITDB_BIN=/usr/lib/postgresql/11/bin/initdb\n+RUN PATH=$PATH:$HOME/.cargo/bin cargo install diesel_cli --force\n+CMD PATH=$PATH:$HOME/.cargo/bin INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR=\"1.5\" VERBOSE=1 /rita/integration-tests/rita.sh\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/rita.py", "new_path": "integration-tests/rita.py", "diff": "@@ -26,6 +26,7 @@ BOUNTY_HUNTER_DEFAULT = os.path.join(os.path.dirname(__file__), '/tmp/bounty_hun\n# Envs for controlling postgres\nPOSTGRES_USER = os.getenv('POSTGRES_USER')\n+INITDB_BIN = os.getenv('INITDB_BIN')\nPOSTGRES_BIN = os.getenv('POSTGRES_BIN')\nPOSTGRES_CONFIG = os.getenv('POSTGRES_CONFIG')\nPOSTGRES_DATABASE = os.getenv('POSTGRES_DATABASE')\n@@ -525,10 +526,15 @@ class World:\nprint(\"namespaces prepped\")\nprint(\"Starting postgres in exit namespace\")\n+ if POSTGRES_DATABASE is not None:\nexec_or_exit(\"sudo ip netns exec {} sudo -u {} {} -D {} -c config_file={}\".format(EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN, POSTGRES_DATABASE, POSTGRES_CONFIG), False)\n-\n-\ntime.sleep(30)\n+ else:\n+ exec_or_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(EXIT_NAMESPACE, POSTGRES_USER, INITDB_BIN), True)\n+ exec_or_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN), False)\n+ time.sleep(30)\n+ exec_or_exit(\"psql -c 'create database test;' -U postgres\", True)\n+\nprint(\"Perform initial database migrations\")\nexec_or_exit('sudo ip netns exec {} diesel migration run --database-url=\"postgres://postgres@localhost/test\" --migration-dir=../exit_db/migrations'.format(EXIT_NAMESPACE))\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/rita.sh", "new_path": "integration-tests/rita.sh", "diff": "@@ -19,18 +19,23 @@ set -euxo pipefail\ncd $(dirname $0) # Make the script runnable from anywhere\n# Loads module if not loaded and available, does nothing if already loaded and fails if not available\n+set +e\nsudo modprobe wireguard\nset -e\n+set -e\n# sets up bounty hunter cers\nopenssl req -newkey rsa:2048 -nodes -keyform pem -keyout bh_key.pem -x509 -days 365 -outform pem -out bh_cert.pem -subj \"/C=US/ST=Althea/L=Althea/O=Althea/OU=Althea/CN=Althea\"\nexport BOUNTY_HUNTER_CERT=$PWD/bh_cert.pem\nexport BOUNTY_HUNTER_KEY=$PWD/bh_key.pem\n-# prep postgres\n-cargo install diesel_cli --force\n+set +e\n+cargo install diesel_cli\nsudo cp $(which diesel) /usr/bin\n+set -e\n# we need to start the database again in the namespace, so we have to kill it out here\n# this sends sigint which should gracefully shut it down but terminate existing connections\n+set +e\nsudo killall -2 postgres\n+set -e\nbuild_rev() {\nremote=$1\n@@ -71,7 +76,7 @@ if [ ! -f \"${BABELD_DIR-}/babeld\" ]; then\nfi\n# Build BH if not built\n-if [ ! -f \"${BOUNTY_HUNTER_DIR-}/babeld\" ]; then\n+if [ ! -d \"${BOUNTY_HUNTER_DIR}\" ]; then\nrm -rf BOUNTY_HUNTER_DIR\ngit clone -b master https://github.com/althea-net/bounty_hunter.git $BOUNTY_HUNTER_DIR\npushd $BOUNTY_HUNTER_DIR\n" }, { "change_type": "ADD", "old_path": null, "new_path": "scripts/test.sh", "diff": "+#!/bin/bash\n+set -eux\n+RUST_TEST_THREADS=1 cargo test --all\n+\n+modprobe wireguard\n+# cleanup docker junk or this script will quickly run you out of room in /\n+docker system prune -a\n+\n+DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n+DOCKERFOLDER=$DIR/../integration-tests/container/\n+git archive -v -o $DOCKERFOLDER/rita.tar.gz --format=tar.gz HEAD\n+pushd $DOCKERFOLDER\n+docker build -t rita-test .\n+docker run --privileged -it rita-test\n+rm rita.tar.gz\n+popd\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add local Docker image that runs the integration tests This handles the pesky problem of running a local Postgres server in order to run the integration tests.
20,244
09.07.2019 17:04:07
14,400
2957e572564823e227358022219aabd029bfbbc6
Update for Gotcha
[ { "change_type": "MODIFY", "old_path": "README.md", "new_path": "README.md", "diff": "@@ -49,6 +49,8 @@ If you wish to test a commit you are developing, or just see Rita in action loca\nThis runs both the unit and integration tests you will need to have installed the depenencies listed in the Building section\nas well as docker and have the [WireGuard](https://www.wireguard.com/install/) kernel module loaded for your operating system.\n+Due to a gotcha in the docker container build you will need to have your changes commited for the integration tests to work.\n+\n## Contributing\nThis codebase is formatted using rustfmt, you can format your commits manually with\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update for Gotcha
20,244
09.07.2019 17:04:22
14,400
d648fe7df2d49b41089355b799e9401c77e847fa
Update suspension check phrase
[ { "change_type": "MODIFY", "old_path": "integration-tests/rita.py", "new_path": "integration-tests/rita.py", "diff": "@@ -1071,12 +1071,12 @@ def main():\nprint(\"Check that tunnels have not been suspended\")\n- assert_test(not check_log_contains(\"rita-n1.log\", \"debt is below close threshold\"), \"Suspension of 1 (A)\")\n- assert_test(not check_log_contains(\"rita-n2.log\", \"debt is below close threshold\"), \"Suspension of 2 (B)\")\n- assert_test(not check_log_contains(\"rita-n3.log\", \"debt is below close threshold\"), \"Suspension of 3 (C)\")\n- assert_test(not check_log_contains(\"rita-n4.log\", \"debt is below close threshold\"), \"Suspension of 4 (D)\")\n- assert_test(not check_log_contains(\"rita-n6.log\", \"debt is below close threshold\"), \"Suspension of 6 (F)\")\n- assert_test(not check_log_contains(\"rita-n7.log\", \"debt is below close threshold\"), \"Suspension of 7 (G)\")\n+ assert_test(not check_log_contains(\"rita-n1.log\", \"suspending forwarding\"), \"Suspension of 1 (A)\")\n+ assert_test(not check_log_contains(\"rita-n2.log\", \"suspending forwarding\"), \"Suspension of 2 (B)\")\n+ assert_test(not check_log_contains(\"rita-n3.log\", \"suspending forwarding\"), \"Suspension of 3 (C)\")\n+ assert_test(not check_log_contains(\"rita-n4.log\", \"suspending forwarding\"), \"Suspension of 4 (D)\")\n+ assert_test(not check_log_contains(\"rita-n6.log\", \"suspending forwarding\"), \"Suspension of 6 (F)\")\n+ assert_test(not check_log_contains(\"rita-n7.log\", \"suspending forwarding\"), \"Suspension of 7 (G)\")\nif DEBUG:\nprint(\"Debug mode active, examine the mesh after tests and press \" +\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Update suspension check phrase
20,244
11.07.2019 09:46:51
14,400
da1e993d3cbfa9809925ef1ac56d44abe68ad4c4
Better integration test balance checking
[ { "change_type": "MODIFY", "old_path": "integration-tests/container/Dockerfile", "new_path": "integration-tests/container/Dockerfile", "diff": "@@ -4,7 +4,8 @@ FROM postgres\nADD rita.tar.gz /rita\nRUN echo \"deb http://deb.debian.org/debian/ unstable main\" > /etc/apt/sources.list.d/unstable.list\nRUN printf 'Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n' > /etc/apt/preferences.d/limit-unstable\n-RUN apt-get update && apt-get install -y sudo iputils-ping iproute2 jq default-libmysqlclient-dev libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev iperf3 python3-pip bridge-utils wireguard linux-source curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n+RUN apt-get update && apt-get install -y sudo iputils-ping iproute2 jq vim netcat default-libmysqlclient-dev libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev python3-pip bridge-utils wireguard linux-source curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n+RUN apt-get install -y -t unstable iperf3\nRUN curl https://sh.rustup.rs -sSf | sh -s -- -y\nENV POSTGRES_USER=postgres\nENV POSTGRES_BIN=/usr/lib/postgresql/11/bin/postgres\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/node.py", "new_path": "integration-tests/integration-test-script/node.py", "diff": "@@ -13,6 +13,7 @@ import sys\nimport time\nimport toml\n+\nclass Node:\ndef __init__(self, id, local_fee, COMPAT_LAYOUT, COMPAT_LAYOUTS):\nself.id = id\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/rita.py", "new_path": "integration-tests/integration-test-script/rita.py", "diff": "@@ -41,7 +41,8 @@ BABELD = os.path.join(dname, 'deps/babeld/babeld')\nRITA_DEFAULT = os.path.join(dname, '../target/debug/rita')\nRITA_EXIT_DEFAULT = os.path.join(dname, '../target/debug/rita_exit')\n-BOUNTY_HUNTER_DEFAULT = os.path.join(dname, '/tmp/bounty_hunter/target/debug/bounty_hunter')\n+BOUNTY_HUNTER_DEFAULT = os.path.join(\n+ dname, '/tmp/bounty_hunter/target/debug/bounty_hunter')\n# Envs for controlling postgres\nPOSTGRES_USER = os.getenv('POSTGRES_USER')\n@@ -106,6 +107,8 @@ EXIT_SELECT = {\n},\n}\n+\n+def setup_seven_node_config():\nCOMPAT_LAYOUTS = {\nNone: ['a'] * 7, # Use *_A binaries for every node\n'old_exit': ['a'] * 4 + ['b'] + ['a'] * 2, # The exit sports Rita B\n@@ -115,13 +118,6 @@ COMPAT_LAYOUTS = {\n'random': None, # Randomize revisions used (filled at runtime)\n}\n-\n-def main():\n- COMPAT_LAYOUTS[\"random\"] = ['a' if random.randint(0, 1) else 'b' for _ in range(7)]\n-\n- if VERBOSE:\n- print(\"Random compat test layout: {}\".format(COMPAT_LAYOUTS[\"random\"]))\n-\na1 = Node(1, 10, COMPAT_LAYOUT, COMPAT_LAYOUTS)\nb2 = Node(2, 25, COMPAT_LAYOUT, COMPAT_LAYOUTS)\nc3 = Node(3, 60, COMPAT_LAYOUT, COMPAT_LAYOUTS)\n@@ -153,9 +149,86 @@ def main():\nworld.add_connection(Connection(e5, g7))\n# world.add_connection(Connection(e5, h8))\n+ traffic_test_pairs = [(c3, f6), (d4, a1), (a1, c3), (d4, e5),\n+ (e5, d4), (c3, e5), (e5, c3), (g7, e5), (e5, g7)]\n+\n+ nodes = world.nodes\n+\n+ all_routes = {\n+ nodes[1]: [\n+ (nodes[2], 50, nodes[6]),\n+ (nodes[3], 60, nodes[6]),\n+ (nodes[4], 75, nodes[6]),\n+ (nodes[5], 60, nodes[6]),\n+ (nodes[6], 0, nodes[6]),\n+ (nodes[7], 50, nodes[6]),\n+ ],\n+ nodes[2]: [\n+ (nodes[1], 50, nodes[6]),\n+ (nodes[3], 0, nodes[3]),\n+ (nodes[4], 0, nodes[4]),\n+ (nodes[5], 60, nodes[6]),\n+ (nodes[6], 0, nodes[6]),\n+ (nodes[7], 50, nodes[6]),\n+ ],\n+ nodes[3]: [\n+ (nodes[1], 60, nodes[7]),\n+ (nodes[2], 0, nodes[2]),\n+ (nodes[4], 25, nodes[2]),\n+ (nodes[5], 10, nodes[7]),\n+ (nodes[6], 10, nodes[7]),\n+ (nodes[7], 0, nodes[7]),\n+ ],\n+ nodes[4]: [\n+ (nodes[1], 75, nodes[2]),\n+ (nodes[2], 0, nodes[2]),\n+ (nodes[3], 25, nodes[2]),\n+ (nodes[5], 85, nodes[2]),\n+ (nodes[6], 25, nodes[2]),\n+ (nodes[7], 75, nodes[2]),\n+ ],\n+ nodes[5]: [\n+ (nodes[1], 60, nodes[7]),\n+ (nodes[2], 60, nodes[7]),\n+ (nodes[3], 10, nodes[7]),\n+ (nodes[4], 85, nodes[7]),\n+ (nodes[6], 10, nodes[7]),\n+ (nodes[7], 0, nodes[7]),\n+ ],\n+ nodes[6]: [\n+ (nodes[1], 0, nodes[1]),\n+ (nodes[2], 0, nodes[2]),\n+ (nodes[3], 10, nodes[7]),\n+ (nodes[4], 25, nodes[2]),\n+ (nodes[5], 10, nodes[7]),\n+ (nodes[7], 0, nodes[7]),\n+ ],\n+ nodes[7]: [\n+ (nodes[1], 50, nodes[6]),\n+ (nodes[2], 50, nodes[6]),\n+ (nodes[3], 0, nodes[3]),\n+ (nodes[4], 75, nodes[6]),\n+ (nodes[5], 0, nodes[5]),\n+ (nodes[6], 0, nodes[6]),\n+ ],\n+ }\n+\nworld.set_bounty(3) # TODO: Who should be the bounty hunter?\n+ return (COMPAT_LAYOUTS, all_routes, traffic_test_pairs, world)\n+\n+\n+def main():\n+ (COMPAT_LAYOUTS, all_routes, traffic_test_pairs,\n+ world) = setup_seven_node_config()\n+\n+ COMPAT_LAYOUTS[\"random\"] = [\n+ 'a' if random.randint(0, 1) else 'b' for _ in range(7)]\n+\n+ if VERBOSE:\n+ print(\"Random compat test layout: {}\".format(COMPAT_LAYOUTS[\"random\"]))\n- world.create(VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA, RITA_EXIT, BOUNTY_HUNTER, DIR_A, DIR_B, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B, NETWORK_LAB, BABELD, POSTGRES_DATABASE, POSTGRES_USER, POSTGRES_CONFIG, POSTGRES_BIN, INITDB_BIN, EXIT_NAMESPACE, EXIT_SETTINGS, dname)\n+ world.create(VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA, RITA_EXIT, BOUNTY_HUNTER, DIR_A, DIR_B, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A,\n+ BOUNTY_HUNTER_B, NETWORK_LAB, BABELD, POSTGRES_DATABASE, POSTGRES_USER, POSTGRES_CONFIG, POSTGRES_BIN, INITDB_BIN, EXIT_NAMESPACE, EXIT_SETTINGS, dname)\nprint(\"Waiting for network to stabilize\")\nstart_time = time.time()\n@@ -171,8 +244,10 @@ def main():\n# While we're before convergence deadline\nwhile (time.time() - start_time) <= CONVERGENCE_DELAY:\n- all_reachable = world.test_reach_all(PING6, verbose=False, global_fail=False)\n- routes_ok = world.test_routes(verbose=False, global_fail=False)\n+ all_reachable = world.test_reach_all(\n+ PING6, verbose=False, global_fail=False)\n+ routes_ok = world.test_routes(\n+ all_routes, verbose=False, global_fail=False)\nif all_reachable and routes_ok:\nbreak # We converged!\ntime.sleep(interval) # Let's check again after a delay\n@@ -187,7 +262,7 @@ def main():\nduration = time.time() - start_time\n# Test (and fail if necessary) for real and print stats on success\n- if world.test_reach_all(PING6) and world.test_routes():\n+ if world.test_reach_all(PING6) and world.test_routes(all_routes):\nprint((\"Converged in \" + colored(\"%.2f seconds\", \"green\")) % duration)\nelse:\nprint((\"No convergence after more than \" +\n@@ -218,104 +293,22 @@ def main():\nif choice != 'y':\nsys.exit(0)\n- world.test_traffic(c3, f6, {\n- 1: 0,\n- 2: 0,\n- 3: -10 * 1.05,\n- 4: 0,\n- 5: 0,\n- 6: 0 * 1.05,\n- 7: 10 * 1.05\n- })\n-\n- world.test_traffic(d4, a1, {\n- 1: 0 * 1.05,\n- 2: 25 * 1.05,\n- 3: 0,\n- 4: -75 * 1.05,\n- 5: 0,\n- 6: 50 * 1.05,\n- 7: 0\n- })\n-\n- world.test_traffic(a1, c3, {\n- 1: -60 * 1.05,\n- 2: 0,\n- 3: 0,\n- 4: 0,\n- 5: 0,\n- 6: 50 * 1.05,\n- 7: 10 * 1.05\n- })\n-\n- world.test_traffic(d4, e5, {\n- 1: 0,\n- 2: 110 * 1.1,\n- 3: 0,\n- 4: -220 * 1.1,\n- 5: 50 * 1.1,\n- 6: 50 * 1.1,\n- 7: 10 * 1.1\n- })\n-\n- world.test_traffic(e5, d4, {\n- 1: 0,\n- 2: 25 * 1.1,\n- 3: 0,\n- 4: -135 * 1.1,\n- 5: 50 * 1.1,\n- 6: 50 * 1.1,\n- 7: 10 * 1.1\n- })\n-\n- world.test_traffic(c3, e5, {\n- 1: 0,\n- 2: 0,\n- 3: -60 * 1.1,\n- 4: 0,\n- 5: 50 * 1.1,\n- 6: 0,\n- 7: 20 * 1.1\n- })\n-\n- world.test_traffic(e5, c3, {\n- 1: 0,\n- 2: 0,\n- 3: -60 * 1.1,\n- 4: 0,\n- 5: 50 * 1.1,\n- 6: 0,\n- 7: 10 * 1.1\n- })\n-\n- world.test_traffic(g7, e5, {\n- 1: 0,\n- 2: 0,\n- 3: 0,\n- 4: 0,\n- 5: 50 * 1.1,\n- 6: 0,\n- 7: -50 * 1.1\n- })\n-\n- world.test_traffic(e5, g7, {\n- 1: 0,\n- 2: 0,\n- 3: 0,\n- 4: 0,\n- 5: 50 * 1.1,\n- 6: 0,\n- 7: -50 * 1.1\n- })\n+ world.test_traffic(traffic_test_pairs)\nprint(\"Check that tunnels have not been suspended\")\n- assert_test(not check_log_contains(\"rita-n1.log\", \"suspending forwarding\"), \"Suspension of 1 (A)\")\n- assert_test(not check_log_contains(\"rita-n2.log\", \"suspending forwarding\"), \"Suspension of 2 (B)\")\n- assert_test(not check_log_contains(\"rita-n3.log\", \"suspending forwarding\"), \"Suspension of 3 (C)\")\n- assert_test(not check_log_contains(\"rita-n4.log\", \"suspending forwarding\"), \"Suspension of 4 (D)\")\n- assert_test(not check_log_contains(\"rita-n6.log\", \"suspending forwarding\"), \"Suspension of 6 (F)\")\n- assert_test(not check_log_contains(\"rita-n7.log\", \"suspending forwarding\"), \"Suspension of 7 (G)\")\n+ assert_test(not check_log_contains(\"rita-n1.log\",\n+ \"suspending forwarding\"), \"Suspension of 1 (A)\")\n+ assert_test(not check_log_contains(\"rita-n2.log\",\n+ \"suspending forwarding\"), \"Suspension of 2 (B)\")\n+ assert_test(not check_log_contains(\"rita-n3.log\",\n+ \"suspending forwarding\"), \"Suspension of 3 (C)\")\n+ assert_test(not check_log_contains(\"rita-n4.log\",\n+ \"suspending forwarding\"), \"Suspension of 4 (D)\")\n+ assert_test(not check_log_contains(\"rita-n6.log\",\n+ \"suspending forwarding\"), \"Suspension of 6 (F)\")\n+ assert_test(not check_log_contains(\"rita-n7.log\",\n+ \"suspending forwarding\"), \"Suspension of 7 (G)\")\nif DEBUG:\nprint(\"Debug mode active, examine the mesh after tests and press \" +\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/utils.py", "new_path": "integration-tests/integration-test-script/utils.py", "diff": "@@ -13,6 +13,7 @@ import sys\nimport time\nimport toml\n+\ndef get_rita_defaults():\nreturn toml.load(open(\"../settings/default.toml\"))\n@@ -34,6 +35,7 @@ def save_rita_settings(id, x):\ndef get_rita_settings(id):\nreturn toml.load(open(\"rita-settings-n{}.toml\".format(id)))\n+\ndef switch_binaries(node_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B):\n\"\"\"\nSwitch the Rita, exit Rita and bounty hunter binaries assigned to node with ID\n@@ -69,10 +71,12 @@ def switch_binaries(node_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER, COMPAT_LAY\nreturn (RITA, RITA_EXIT, BOUNTY_HUNTER)\n+\ndef register_to_exit(node):\nos.system((\"ip netns exec netlab-{} curl -XPOST \" +\n\"127.0.0.1:4877/exits/exit_a/register\").format(node.id))\n+\ndef email_verif(node):\nemail_text = read_email(node)\n@@ -85,6 +89,7 @@ def email_verif(node):\nexec_or_exit((\"ip netns exec netlab-{} curl \" +\n\"127.0.0.1:4877/settings\").format(node.id))\n+\ndef read_email(node):\nid = node.id\n# TODO: this is O(n^2)\n@@ -92,21 +97,27 @@ def read_email(node):\nwith open(os.path.join(\"mail\", mail)) as mail_file_handle:\nmail = json.load(mail_file_handle)\nif mail[\"envelope\"][\"forward_path\"][0] == \"{}@example.com\".format(id):\n- return ''.join(chr(i) for i in mail[\"message\"])\n+ message = ''.join(chr(i) for i in mail[\"message\"])\n+ if \"low balance\" in message:\n+ continue\n+ return message\nraise Exception(\"cannot find email for node {}\".format(id))\n+\ndef assert_test(x, description, verbose=True, global_fail=True):\nif verbose:\nif x:\nprint(colored(\" + \", \"green\") + \"{} Succeeded\".format(description))\nelse:\n- sys.stderr.write(colored(\" + \", \"red\") + \"{} Failed\\n\".format(description))\n+ sys.stderr.write(colored(\" + \", \"red\") +\n+ \"{} Failed\\n\".format(description))\nif global_fail and not x:\nglobal TEST_PASSES\nTEST_PASSES = False\nreturn x\n+\ndef exec_no_exit(command, blocking=True, delay=0.01):\n\"\"\"\nExecutes a command and ignores it's output.\n@@ -134,12 +145,14 @@ def exec_no_exit(command, blocking=True, delay=0.01):\nerrname = '<unknown>'\nprint('Command \"{c}\" failed: \"{strerr}\" (code {rv})'.format(\nc=command,\n- strerr=os.strerror(retval), # strerror handles unknown errors gracefuly\n+ # strerror handles unknown errors gracefuly\n+ strerr=os.strerror(retval),\nrv=errname,\nfile=sys.stderr\n)\n)\n+\ndef exec_or_exit(command, blocking=True, delay=0.01):\n\"\"\"\nExecutes a command and terminates the program if it fails.\n@@ -167,7 +180,8 @@ def exec_or_exit(command, blocking=True, delay=0.01):\nerrname = '<unknown>'\nprint('Command \"{c}\" failed: \"{strerr}\" (code {rv})'.format(\nc=command,\n- strerr=os.strerror(retval), # strerror handles unknown errors gracefuly\n+ # strerror handles unknown errors gracefuly\n+ strerr=os.strerror(retval),\nrv=errname,\nfile=sys.stderr\n)\n@@ -179,21 +193,25 @@ def cleanup():\nos.system(\"rm -rf *.db *.log *.pid private-key* mail\")\nos.system(\"mkdir mail\")\nos.system(\"sync\")\n- os.system(\"killall babeld rita rita_exit bounty_hunter iperf\") # TODO: This is very inconsiderate\n+ # TODO: This is very inconsiderate\n+ os.system(\"killall babeld rita rita_exit bounty_hunter iperf\")\ndef teardown():\nos.system(\"rm -rf *.pid private-key*\")\nos.system(\"sync\")\n- os.system(\"killall babeld rita rita_exit bounty_hunter iperf\") # TODO: This is very inconsiderate\n-\n+ # TODO: This is very inconsiderate\n+ os.system(\"killall babeld rita rita_exit bounty_hunter iperf\")\ndef prep_netns(id):\n- exec_or_exit(\"ip netns exec netlab-{} sysctl -w net.ipv4.ip_forward=1\".format(id))\n- exec_or_exit(\"ip netns exec netlab-{} sysctl -w net.ipv6.conf.all.forwarding=1\".format(id))\n+ exec_or_exit(\n+ \"ip netns exec netlab-{} sysctl -w net.ipv4.ip_forward=1\".format(id))\n+ exec_or_exit(\n+ \"ip netns exec netlab-{} sysctl -w net.ipv6.conf.all.forwarding=1\".format(id))\nexec_or_exit(\"ip netns exec netlab-{} ip link set up lo\".format(id))\n+\ndef traffic_diff(a, b):\nprint(a, b)\nreturn {key: b[key] - a.get(key, 0) for key in b.keys()}\n@@ -216,6 +234,7 @@ def check_log_contains(f, x):\nelse:\nreturn False\n+\ndef start_babel(node, BABELD):\nexec_or_exit(\n(\n@@ -240,14 +259,14 @@ def start_bounty(id, BOUNTY_HUNTER):\nid=id, bounty=BOUNTY_HUNTER))\n-\ndef start_rita(node, dname, RITA, EXIT_SETTINGS):\nid = node.id\nsettings = get_rita_defaults()\nsettings[\"network\"][\"mesh_ip\"] = \"fd00::{}\".format(id)\n- settings[\"network\"][\"wg_private_key_path\"] = \"{pwd}/private-key-{id}\".format(id=id, pwd=dname)\n+ settings[\"network\"][\"wg_private_key_path\"] = \"{pwd}/private-key-{id}\".format(\n+ id=id, pwd=dname)\nsettings[\"network\"][\"peer_interfaces\"] = node.get_veth_interfaces()\nsettings[\"payment\"][\"local_fee\"] = node.local_fee\nsettings[\"metric_factor\"] = 0 # We explicity want to disregard quality\n@@ -266,13 +285,15 @@ def start_rita(node, dname, RITA, EXIT_SETTINGS):\nos.system(\"ip netns exec netlab-{id} curl -XPOST 127.0.0.1:4877/settings -H 'Content-Type: application/json' -i -d '{data}'\"\n.format(id=id, data=json.dumps({\"exit_client\": EXIT_SETTINGS})))\n+\ndef start_rita_exit(node, dname, RITA_EXIT):\nid = node.id\nsettings = get_rita_exit_defaults()\nsettings[\"network\"][\"mesh_ip\"] = \"fd00::{}\".format(id)\n- settings[\"network\"][\"wg_private_key_path\"] = \"{pwd}/private-key-{id}\".format(id=id, pwd=dname)\n+ settings[\"network\"][\"wg_private_key_path\"] = \"{pwd}/private-key-{id}\".format(\n+ id=id, pwd=dname)\nsettings[\"network\"][\"peer_interfaces\"] = node.get_veth_interfaces()\nsettings[\"payment\"][\"local_fee\"] = node.local_fee\nsettings[\"metric_factor\"] = 0 # We explicity want to disregard quality\n@@ -284,3 +305,28 @@ def start_rita_exit(node, dname, RITA_EXIT):\n'grep -Ev \"<unknown>|mio|tokio_core|tokio_reactor|hyper\" > rita-n{id}.log &'.format(id=id, rita=RITA_EXIT,\npwd=dname)\n)\n+\n+\n+def ip_to_num(ip):\n+ return int(ip.replace(\"fd00::\", \"\"))\n+\n+\n+def num_to_ip(num):\n+ return \"fd00::{}\".format(num)\n+\n+\n+def fuzzy_match(numA, numB):\n+ # signs must not match\n+ if numA > 0 and numB > 0 or numA < 0 and numB < 0:\n+ return False\n+ numA = abs(numA)\n+ numB = abs(numB)\n+ # 5%\n+ allowed_delta = 0.5\n+ low = 1 - allowed_delta\n+ high = 1 + allowed_delta\n+ high_b = numA * high\n+ low_b = numA * low\n+ if numB < high_b and numB > low_b:\n+ return True\n+ return False\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -24,6 +24,9 @@ from utils import start_babel\nfrom utils import start_bounty\nfrom utils import get_rita_settings\nfrom utils import assert_test\n+from utils import ip_to_num\n+from utils import num_to_ip\n+from utils import fuzzy_match\nclass World:\n@@ -73,7 +76,8 @@ class World:\nexit_index = self.exit_id - 1\nif VERBOSE:\n- print(\"DB setup: bounty_hunter index: {}, exit index: {}\".format(bounty_index, exit_index))\n+ print(\"DB setup: bounty_hunter index: {}, exit index: {}\".format(\n+ bounty_index, exit_index))\nif COMPAT_LAYOUT:\n# Figure out whether release A or B was\n@@ -85,7 +89,8 @@ class World:\nelif layout[exit_index] == 'b':\nexit_repo_dir = DIR_B\nelse:\n- print(\"DB setup: Unknown release {} assigned to exit\".format(layout[exit_index]))\n+ print(\"DB setup: Unknown release {} assigned to exit\".format(\n+ layout[exit_index]))\nsys.exit(1)\n# Save the current dir\n@@ -100,15 +105,6 @@ class World:\n\"&& diesel migration run\" +\n\"&& cp test.db {dest}\").format(dest=os.path.join(cwd, \"bounty.db\")))\n- # Go to exit_db/ in the exit's release\n- os.chdir(os.path.join(cwd, exit_repo_dir, \"exit_db\"))\n- if VERBOSE:\n- print(\"DB setup: Entering {}/exit_db\".format(exit_repo_dir))\n-\n- os.system((\"rm -rf test.db \" +\n- \"&& diesel migration run\" +\n- \"&& cp test.db {dest}\").format(dest=os.path.join(cwd, \"exit.db\")))\n-\n# Go back to where we started\nos.chdir(cwd)\n@@ -136,7 +132,8 @@ class World:\nprint(\"network topology: {}\".format(network))\nprint(NETWORK_LAB)\n- proc = subprocess.Popen(['/bin/bash', NETWORK_LAB], stdin=subprocess.PIPE, universal_newlines=True)\n+ proc = subprocess.Popen(\n+ ['/bin/bash', NETWORK_LAB], stdin=subprocess.PIPE, universal_newlines=True)\nproc.stdin.write(network_string)\nproc.stdin.close()\n@@ -151,18 +148,23 @@ class World:\nprint(\"Starting postgres in exit namespace\")\nif POSTGRES_DATABASE is not None:\n- exec_or_exit(\"sudo ip netns exec {} sudo -u {} {} -D {} -c config_file={}\".format(EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN, POSTGRES_DATABASE, POSTGRES_CONFIG), False)\n+ exec_or_exit(\"sudo ip netns exec {} sudo -u {} {} -D {} -c config_file={}\".format(\n+ EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN, POSTGRES_DATABASE, POSTGRES_CONFIG), False)\ntime.sleep(30)\nelse:\n- exec_no_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(EXIT_NAMESPACE, POSTGRES_USER, INITDB_BIN), True)\n- exec_or_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN), False)\n+ exec_no_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(\n+ EXIT_NAMESPACE, POSTGRES_USER, INITDB_BIN), True)\n+ exec_or_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(\n+ EXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN), False)\ntime.sleep(30)\n+ exec_no_exit(\"psql -c 'drop database test;' -U postgres\", True)\nexec_no_exit(\"psql -c 'create database test;' -U postgres\", True)\n-\nprint(\"Perform initial database migrations\")\nexec_or_exit('sudo ip netns exec {} diesel migration run --database-url=\"postgres://postgres@localhost/test\" --migration-dir=../exit_db/migrations'.format(EXIT_NAMESPACE))\n+ # redo the migration so that we can run several times\n+ exec_or_exit('sudo ip netns exec {} diesel migration redo --database-url=\"postgres://postgres@localhost/test\" --migration-dir=../exit_db/migrations'.format(EXIT_NAMESPACE))\nprint(\"starting babel\")\n@@ -176,21 +178,25 @@ class World:\nprint(\"DB setup OK\")\nprint(\"starting bounty hunter\")\n- (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(self.bounty_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\n+ (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(self.bounty_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER,\n+ COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\nstart_bounty(self.bounty_id, BOUNTY_HUNTER)\nprint(\"bounty hunter started\")\n- (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(self.exit_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\n+ (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(self.exit_id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER,\n+ COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\nstart_rita_exit(self.nodes[self.exit_id], dname, RITA_EXIT)\ntime.sleep(1)\n- EXIT_SETTINGS[\"exits\"][\"exit_a\"][\"id\"][\"wg_public_key\"] = get_rita_settings(self.exit_id)[\"network\"][\"wg_public_key\"]\n+ EXIT_SETTINGS[\"exits\"][\"exit_a\"][\"id\"][\"wg_public_key\"] = get_rita_settings(\n+ self.exit_id)[\"network\"][\"wg_public_key\"]\nprint(\"starting rita\")\nfor id, node in self.nodes.items():\nif id != self.exit_id and id != self.external:\n- (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER, COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\n+ (RITA, RITA_EXIT, BOUNTY_HUNTER) = switch_binaries(id, VERBOSE, RITA, RITA_EXIT, BOUNTY_HUNTER,\n+ COMPAT_LAYOUT, COMPAT_LAYOUTS, RITA_A, RITA_EXIT_A, RITA_B, RITA_EXIT_B, BOUNTY_HUNTER_A, BOUNTY_HUNTER_B)\nstart_rita(node, dname, RITA, EXIT_SETTINGS)\ntime.sleep(0.5 + random.random() / 2) # wait 0.5s - 1s\nprint()\n@@ -214,12 +220,11 @@ class World:\nreturn False\nreturn True\n- def test_routes(self, verbose=True, global_fail=True):\n+ def test_routes(self, all_routes, verbose=True, global_fail=True):\n\"\"\"\nCheck the presence of all optimal routes.\n\"\"\"\nresult = True\n- nodes = self.nodes\n# Caution: all_routes directly relies on the layout of the netlab mesh.\n#\n@@ -233,65 +238,6 @@ class World:\n# [...]\n# }\n- all_routes = {\n- nodes[1]: [\n- (nodes[2], 50, nodes[6]),\n- (nodes[3], 60, nodes[6]),\n- (nodes[4], 75, nodes[6]),\n- (nodes[5], 60, nodes[6]),\n- (nodes[6], 0, nodes[6]),\n- (nodes[7], 50, nodes[6]),\n- ],\n- nodes[2]: [\n- (nodes[1], 50, nodes[6]),\n- (nodes[3], 0, nodes[3]),\n- (nodes[4], 0, nodes[4]),\n- (nodes[5], 60, nodes[6]),\n- (nodes[6], 0, nodes[6]),\n- (nodes[7], 50, nodes[6]),\n- ],\n- nodes[3]: [\n- (nodes[1], 60, nodes[7]),\n- (nodes[2], 0, nodes[2]),\n- (nodes[4], 25, nodes[2]),\n- (nodes[5], 10, nodes[7]),\n- (nodes[6], 10, nodes[7]),\n- (nodes[7], 0, nodes[7]),\n- ],\n- nodes[4]: [\n- (nodes[1], 75, nodes[2]),\n- (nodes[2], 0, nodes[2]),\n- (nodes[3], 25, nodes[2]),\n- (nodes[5], 85, nodes[2]),\n- (nodes[6], 25, nodes[2]),\n- (nodes[7], 75, nodes[2]),\n- ],\n- nodes[5]: [\n- (nodes[1], 60, nodes[7]),\n- (nodes[2], 60, nodes[7]),\n- (nodes[3], 10, nodes[7]),\n- (nodes[4], 85, nodes[7]),\n- (nodes[6], 10, nodes[7]),\n- (nodes[7], 0, nodes[7]),\n- ],\n- nodes[6]: [\n- (nodes[1], 0, nodes[1]),\n- (nodes[2], 0, nodes[2]),\n- (nodes[3], 10, nodes[7]),\n- (nodes[4], 25, nodes[2]),\n- (nodes[5], 10, nodes[7]),\n- (nodes[7], 0, nodes[7]),\n- ],\n- nodes[7]: [\n- (nodes[1], 50, nodes[6]),\n- (nodes[2], 50, nodes[6]),\n- (nodes[3], 0, nodes[3]),\n- (nodes[4], 75, nodes[6]),\n- (nodes[5], 0, nodes[5]),\n- (nodes[6], 0, nodes[6]),\n- ],\n- }\n-\nfor node, routes in all_routes.items():\nfor route in routes:\ndesc = (\"Optimal route from node {} ({}) \" +\n@@ -400,79 +346,80 @@ class World:\nprint('Unable to decode JSON {!r}: {}'.format(stdout, e))\nassert_test(False, \"Decoding the settings JSON\")\n+ def get_debts(self):\n+ \"\"\"Creates a nested dictionary of balances, for example balances[1][3] is the balance node 1 has for node 3\"\"\"\n+ status = True\n+ balances = {}\n+ n = 1\n- def get_balances(self):\n- # TODO make this work once bounty hunter works\n+ while True:\n+ ip = num_to_ip(n)\nstatus = subprocess.Popen(\n- [\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(self.bounty_id), \"curl\", \"-s\", \"-g\", \"-6\",\n- \"[::1]:8888/get_channel_state\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n+ [\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(n), \"curl\", \"-s\", \"-g\", \"-6\",\n+ \"[::1]:4877/debts\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\nstatus.wait()\noutput = status.stdout.read().decode(\"utf-8\")\n+ if output is \"\":\n+ break\nstatus = json.loads(output)\n- balances = {}\n+ balances[ip_to_num(ip)] = {}\nfor i in status:\n- balances[int(i[\"ip\"].replace(\"fd00::\", \"\"))] = int(i[\"balance\"])\n+ peer_ip = i[\"identity\"][\"mesh_ip\"]\n+ peer_debt = int(i[\"payment_details\"][\"debt\"])\n+ balances[ip_to_num(ip)][ip_to_num(peer_ip)] = peer_debt\n+ n += 1\nreturn balances\n- # Code for ensuring balances add up to 0\n-\n- # while s != 0 and n < 1:\n- # status = subprocess.Popen(\n- # [\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(self.bounty_id), \"curl\", \"-s\", \"-g\", \"-6\",\n- # \"[::1]:8888/list\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n- # status.wait()\n- # output = status.stdout.read().decode(\"utf-8\")\n- # status = json.loads(output)\n- # balances = {}\n- # s = 0\n- # m = 0\n- # for i in status:\n- # balances[int(i[\"ip\"].replace(\"fd00::\", \"\"))] = int(i[\"balance\"])\n- # s += int(i[\"balance\"])\n- # m += abs(int(i[\"balance\"]))\n- # n += 1\n- # time.sleep(0.5)\n- # print(\"time {}, value {}\".format(n, s))\n-\n- # print(\"tried {} times\".format(n))\n- # print(\"sum = {}, magnitude = {}, error = {}\".format(s, m, abs(s) / m))\n- # assert_test(s == 0 and m != 0, \"Conservation of balance\")\n-\ndef gen_traffic(self, from_node, to_node, bytes):\nif from_node.id == self.exit_id:\nserver = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-s\", \"-V\"])\n- time.sleep(0.1)\n+ time.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(to_node.id), \"iperf3\", \"-c\",\n- self.to_ip(from_node), \"-V\", \"-n\", str(bytes), \"-Z\", \"-R\"])\n+ self.to_ip(from_node), \"--connect-timeout\", \"100\", \"-V\", \"-t 60\", \"-R\", ])\nelse:\nserver = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(to_node.id), \"iperf3\", \"-s\", \"-V\"])\n- time.sleep(0.1)\n+ time.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-c\",\n- self.to_ip(to_node), \"-V\", \"-n\", str(bytes), \"-Z\"])\n-\n+ self.to_ip(to_node), \"--connect-timeout\", \"100\", \"-V\", \"-n\", \"-t 60\"])\nclient.wait()\n- time.sleep(0.1)\nserver.send_signal(signal.SIGINT)\nserver.wait()\n- def test_traffic(self, from_node, to_node, results):\n+ def test_traffic(self, traffic_test_pairs):\n+ \"\"\"Generates test traffic from and to the specified nodes, then ensure that all nodes agree\"\"\"\n+ for (from_node, to_node) in traffic_test_pairs:\nprint(\"Test traffic...\")\n- #t1 = self.get_balances()\n- #self.gen_traffic(from_node, to_node, 1e8)\n- #time.sleep(30)\n-\n- #t2 = self.get_balances()\n- #print(\"balance change from {}->{}:\".format(from_node.id, to_node.id))\n- #diff = traffic_diff(t1, t2)\n- #print(diff)\n-\n- #for node_id, balance in results.items():\n- #assert_test(fuzzy_traffic(diff[node_id], balance * 1e8),\n- # \"Balance of {} ({})\".format(node_id,\n- # self.nodes[node_id].revision))\n+ t1 = self.get_debts()\n+ print(\"Test pre-traffic blanace agreement...\")\n+ self.test_debts_reciprocal_matching(t1)\n+ self.gen_traffic(from_node, to_node, 1e8)\n+ time.sleep(30)\n+\n+ t2 = self.get_debts()\n+ print(\"Test post-traffic blanace agreement...\")\n+ self.test_debts_reciprocal_matching(t2)\n+ print(\"balance change from {}->{}:\".format(from_node.id, to_node.id))\n+ print(t2)\n+\n+ def test_debts_reciprocal_matching(self, debts):\n+ \"\"\"Tests that in a network nodes generally agree on debts, within a few percent this is done by making sure that\n+ debts[1][3] is within a few percent of debts[3][1]\"\"\"\n+\n+ for node in debts.keys():\n+ for node_to_compare in debts[node].keys():\n+ if node not in debts[node_to_compare]:\n+ print(\"Node {} has a debt for Node {} but not the other way around!\".format(\n+ node, node_to_compare))\n+ continue\n+ res = fuzzy_match(\n+ debts[node][node_to_compare], debts[node_to_compare][node])\n+ if not res:\n+ print(\"Nodes {} and {} do not agree! {} has {} and {} has {}!\".format(\n+ node, node_to_compare, node, debts[node][node_to_compare], node_to_compare, debts[node_to_compare][node]))\n+ # exit(1)\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/rita.sh", "new_path": "integration-tests/rita.sh", "diff": "@@ -36,6 +36,10 @@ set -e\nset +e\nsudo killall -2 postgres\nset -e\n+# clean up the mail from last time\n+set +e\n+rm -rf mail/\n+set -e\nbuild_rev() {\nremote=$1\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/database_tools.rs", "new_path": "rita/src/rita_exit/database/database_tools.rs", "diff": "@@ -171,6 +171,7 @@ pub fn client_conflict(client: &ExitClientIdentity, conn: &PgConnection) -> Resu\nlet ip_exists = select(exists(ip_match)).get_result(&*conn)?;\nlet wg_exists = select(exists(wg_key_match)).get_result(&*conn)?;\nlet eth_exists = select(exists(eth_address_match)).get_result(&*conn)?;\n+ info!(\"Signup conflict ip {} eth {} wg {}\", ip_exists, eth_exists, wg_exists);\nOk(ip_exists || eth_exists || wg_exists)\n}\n" }, { "change_type": "MODIFY", "old_path": "scripts/test.sh", "new_path": "scripts/test.sh", "diff": "set -eux\nRUST_TEST_THREADS=1 cargo test --all\n-modprobe wireguard\n+modprobe wireguard || echo \"Please install WireGuard https://www.wireguard.com/ and load the kernel module using 'sudo modprobe wireguard'\"\n# cleanup docker junk or this script will quickly run you out of room in /\n-docker system prune -a\n+echo \"Docker images take up a lot of space in root if you are running out of space select Yes\"\n+docker system prune -a -f\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\nDOCKERFOLDER=$DIR/../integration-tests/container/\n@@ -18,9 +19,8 @@ tar --exclude $REPOFOLDER/target \\\n--exclude $REPOFOLDER/integration-tests/deps \\\n--exclude $REPOFOLDER/integration-tests/container/rita.tar.gz \\\n--exclude $REPOFOLDER/scripts -czf $DOCKERFOLDER/rita.tar.gz $REPOFOLDER\n-#git archive -v -o $DOCKERFOLDER/rita.tar.gz --format=tar.gz HEAD\npushd $DOCKERFOLDER\n-docker build -t rita-test .\n-docker run --privileged -it rita-test\n+time docker build -t rita-test .\n+time docker run --privileged -it rita-test\nrm rita.tar.gz\npopd\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Better integration test balance checking
20,244
14.07.2019 09:23:59
14,400
0ee0ca402a6371dd7b7cfcd81961765a8a9da5cf
Fix exit wg-key copying in tests
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -190,7 +190,7 @@ class World:\ntime.sleep(1)\nEXIT_SETTINGS[\"exits\"][\"exit_a\"][\"id\"][\"wg_public_key\"] = get_rita_settings(\n- self.exit_id)[\"network\"][\"wg_public_key\"]\n+ self.exit_id)[\"exit_network\"][\"wg_public_key\"]\nprint(\"starting rita\")\nfor id, node in self.nodes.items():\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix exit wg-key copying in tests
20,244
14.07.2019 09:35:38
14,400
8d0e6a87b28a9a5a3f3c330339ac52a56d5a5d5d
Test exit reachability
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/rita.py", "new_path": "integration-tests/integration-test-script/rita.py", "diff": "@@ -293,6 +293,7 @@ def main():\nif choice != 'y':\nsys.exit(0)\n+ world.test_exit_reach_all()\nworld.test_traffic(traffic_test_pairs)\nprint(\"Check that tunnels have not been suspended\")\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -210,6 +210,14 @@ class World:\noutput = ping.stdout.read().decode(\"utf-8\")\nreturn \"1 packets transmitted, 1 received, 0% packet loss\" in output\n+ def test_exit_reach(self, node, exit_internal_ip):\n+ ping = subprocess.Popen(\n+ [\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(node.id), \"ping\",\n+ \"{}\".format(exit_internal_ip),\n+ \"-c\", \"1\"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)\n+ output = ping.stdout.read().decode(\"utf-8\")\n+ return \"1 packets transmitted, 1 received, 0% packet loss\" in output\n+\ndef test_reach_all(self, PING6, verbose=True, global_fail=True):\nfor i in self.nodes.values():\nfor j in self.nodes.values():\n@@ -220,6 +228,19 @@ class World:\nreturn False\nreturn True\n+ def test_exit_reach_all(self, verbose=True, global_fail=True):\n+ exit_internal_ip = get_rita_settings(\n+ self.exit_id)[\"exit_network\"][\"own_internal_ip\"]\n+ for node in self.nodes.values():\n+ if node.id == self.exit_id:\n+ continue\n+ if not assert_test(self.test_exit_reach(node, exit_internal_ip), \"Exit Reachability \" +\n+ \"from node {} ({})\".format(node.id,\n+ node.revision),\n+ verbose=verbose, global_fail=global_fail):\n+ return False\n+ return True\n+\ndef test_routes(self, all_routes, verbose=True, global_fail=True):\n\"\"\"\nCheck the presence of all optimal routes.\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Test exit reachability
20,244
14.07.2019 10:31:32
14,400
33186b2f9fa9d12be4ac3bc580786a496f747415
Test balance agreement
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/rita.py", "new_path": "integration-tests/integration-test-script/rita.py", "diff": "@@ -125,7 +125,6 @@ def setup_seven_node_config():\ne5 = Node(5, 0, COMPAT_LAYOUT, COMPAT_LAYOUTS)\nf6 = Node(6, 50, COMPAT_LAYOUT, COMPAT_LAYOUTS)\ng7 = Node(7, 10, COMPAT_LAYOUT, COMPAT_LAYOUTS)\n- # h8 = Node(8, 0)\n# Note: test_routes() relies heavily on this node and price layout not to\n# change. If you need to alter the test mesh, please update test_routes()\n@@ -138,7 +137,6 @@ def setup_seven_node_config():\nworld.add_exit_node(e5)\nworld.add_node(f6)\nworld.add_node(g7)\n- # world.add_external_node(h8)\nworld.add_connection(Connection(a1, f6))\nworld.add_connection(Connection(f6, g7))\n@@ -147,7 +145,6 @@ def setup_seven_node_config():\nworld.add_connection(Connection(b2, f6))\nworld.add_connection(Connection(b2, d4))\nworld.add_connection(Connection(e5, g7))\n- # world.add_connection(Connection(e5, h8))\ntraffic_test_pairs = [(c3, f6), (d4, a1), (a1, c3), (d4, e5),\n(e5, d4), (c3, e5), (e5, c3), (g7, e5), (e5, g7)]\n@@ -296,20 +293,17 @@ def main():\nworld.test_exit_reach_all()\nworld.test_traffic(traffic_test_pairs)\n+ # wait a few seconds after traffic generation for all nodes to update their debts\n+ time.sleep(10)\n+ traffic = world.get_debts()\n+ print(\"Test post-traffic blanace agreement...\")\n+ world.test_debts_reciprocal_matching(traffic)\n+\nprint(\"Check that tunnels have not been suspended\")\n- assert_test(not check_log_contains(\"rita-n1.log\",\n- \"suspending forwarding\"), \"Suspension of 1 (A)\")\n- assert_test(not check_log_contains(\"rita-n2.log\",\n- \"suspending forwarding\"), \"Suspension of 2 (B)\")\n- assert_test(not check_log_contains(\"rita-n3.log\",\n- \"suspending forwarding\"), \"Suspension of 3 (C)\")\n- assert_test(not check_log_contains(\"rita-n4.log\",\n- \"suspending forwarding\"), \"Suspension of 4 (D)\")\n- assert_test(not check_log_contains(\"rita-n6.log\",\n- \"suspending forwarding\"), \"Suspension of 6 (F)\")\n- assert_test(not check_log_contains(\"rita-n7.log\",\n- \"suspending forwarding\"), \"Suspension of 7 (G)\")\n+ for node in world.nodes:\n+ assert_test(not check_log_contains(\"rita-n{}.log\".format(node.id),\n+ \"suspending forwarding\"), \"Suspension of {}\".format(node.id))\nif DEBUG:\nprint(\"Debug mode active, examine the mesh after tests and press \" +\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -66,11 +66,10 @@ class World:\nelse:\nreturn \"fd00::{}\".format(node.id)\n- def setup_dbs(self, VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, DIR_A, DIR_B):\n+ def setup_bh_db(self, VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, DIR_A, DIR_B):\nos.system(\"rm -rf bounty.db exit.db\")\nbounty_repo_dir = \"/tmp/bounty_hunter/\"\n- exit_repo_dir = \"..\"\nbounty_index = self.bounty_id - 1\nexit_index = self.exit_id - 1\n@@ -79,20 +78,6 @@ class World:\nprint(\"DB setup: bounty_hunter index: {}, exit index: {}\".format(\nbounty_index, exit_index))\n- if COMPAT_LAYOUT:\n- # Figure out whether release A or B was\n- # assigned to the exit\n- layout = COMPAT_LAYOUTS[COMPAT_LAYOUT]\n-\n- if layout[exit_index] == 'a':\n- exit_repo_dir = DIR_A\n- elif layout[exit_index] == 'b':\n- exit_repo_dir = DIR_B\n- else:\n- print(\"DB setup: Unknown release {} assigned to exit\".format(\n- layout[exit_index]))\n- sys.exit(1)\n-\n# Save the current dir\ncwd = os.getcwd()\n@@ -173,8 +158,8 @@ class World:\nprint(\"babel started\")\n- print(\"Setting up rita_exit and bounty_hunter databases\")\n- self.setup_dbs(VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, DIR_A, DIR_B)\n+ print(\"Setting up bounty_hunter database\")\n+ self.setup_bh_db(VERBOSE, COMPAT_LAYOUT, COMPAT_LAYOUTS, DIR_A, DIR_B)\nprint(\"DB setup OK\")\nprint(\"starting bounty hunter\")\n@@ -416,17 +401,7 @@ class World:\n\"\"\"Generates test traffic from and to the specified nodes, then ensure that all nodes agree\"\"\"\nfor (from_node, to_node) in traffic_test_pairs:\nprint(\"Test traffic...\")\n- t1 = self.get_debts()\n- print(\"Test pre-traffic blanace agreement...\")\n- self.test_debts_reciprocal_matching(t1)\nself.gen_traffic(from_node, to_node, 1e8)\n- time.sleep(30)\n-\n- t2 = self.get_debts()\n- print(\"Test post-traffic blanace agreement...\")\n- self.test_debts_reciprocal_matching(t2)\n- print(\"balance change from {}->{}:\".format(from_node.id, to_node.id))\n- print(t2)\ndef test_debts_reciprocal_matching(self, debts):\n\"\"\"Tests that in a network nodes generally agree on debts, within a few percent this is done by making sure that\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/database/database_tools.rs", "new_path": "rita/src/rita_exit/database/database_tools.rs", "diff": "@@ -171,7 +171,10 @@ pub fn client_conflict(client: &ExitClientIdentity, conn: &PgConnection) -> Resu\nlet ip_exists = select(exists(ip_match)).get_result(&*conn)?;\nlet wg_exists = select(exists(wg_key_match)).get_result(&*conn)?;\nlet eth_exists = select(exists(eth_address_match)).get_result(&*conn)?;\n- info!(\"Signup conflict ip {} eth {} wg {}\", ip_exists, eth_exists, wg_exists);\n+ info!(\n+ \"Signup conflict ip {} eth {} wg {}\",\n+ ip_exists, eth_exists, wg_exists\n+ );\nOk(ip_exists || eth_exists || wg_exists)\n}\n" }, { "change_type": "MODIFY", "old_path": "settings/default.toml", "new_path": "settings/default.toml", "diff": "[payment]\npay_threshold = \"0\"\n-close_threshold = \"-1000000000\"\n+close_threshold = \"-10000000000000\"\nclose_fraction = \"100\"\nbuffer_period = 3\neth_address = \"0x0101010101010101010101010101010101010101\"\n" }, { "change_type": "MODIFY", "old_path": "settings/default_exit.toml", "new_path": "settings/default_exit.toml", "diff": "@@ -4,7 +4,7 @@ description = \"just a normal althea exit\"\n[payment]\npay_threshold = \"0\"\n-close_threshold = \"-1000000000\"\n+close_threshold = \"-10000000000000\"\nclose_fraction = \"100\"\nbuffer_period = 3\neth_address = \"0x0101010101010101010101010101010101010101\"\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Test balance agreement
20,244
14.07.2019 13:22:58
14,400
5a590af12321998765036e9585a2b736246452f3
Correct traffic matching rules
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/rita.py", "new_path": "integration-tests/integration-test-script/rita.py", "diff": "@@ -301,9 +301,9 @@ def main():\nprint(\"Check that tunnels have not been suspended\")\n- for node in world.nodes:\n- assert_test(not check_log_contains(\"rita-n{}.log\".format(node.id),\n- \"suspending forwarding\"), \"Suspension of {}\".format(node.id))\n+ for id in world.nodes:\n+ assert_test(not check_log_contains(\"rita-n{}.log\".format(id),\n+ \"suspending forwarding\"), \"Suspension of {}\".format(id))\nif DEBUG:\nprint(\"Debug mode active, examine the mesh after tests and press \" +\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/utils.py", "new_path": "integration-tests/integration-test-script/utils.py", "diff": "@@ -315,18 +315,36 @@ def num_to_ip(num):\nreturn \"fd00::{}\".format(num)\n-def fuzzy_match(numA, numB):\n+def fuzzy_traffic_match(numA, numB):\n+ \"\"\"A matching scheme with error margins for Rita traffic, allows up to 5% lower or in the case of\n+ the paying party over-estimating (packet loss) it allows more\"\"\"\n+ # ignore every small debts\n+ if abs(numA) < 1000000 and abs(numB) < 1000000:\n+ return True\n# signs must not match\nif numA > 0 and numB > 0 or numA < 0 and numB < 0:\nreturn False\n- numA = abs(numA)\n- numB = abs(numB)\n+ if numA > 0:\n+ pos = numA\n+ neg = numB\n+ if numB > 0:\n+ pos = numB\n+ neg = numA\n+ pos_abs = abs(pos)\n+ neg_abs = abs(neg)\n# 5%\n- allowed_delta = 0.5\n- low = 1 - allowed_delta\n+ allowed_delta = 0.05\nhigh = 1 + allowed_delta\n- high_b = numA * high\n- low_b = numA * low\n- if numB < high_b and numB > low_b:\n- return True\n+ low = 1 - allowed_delta\n+\n+ # debt has been undercounted, the payer has a debt value less than\n+ # 95% of the node being paid\n+ undercounting = pos_abs < (neg_abs * low)\n+ # overcounting, this is not an error, but it is worth warning about\n+ # this should only happen if there is packet loss\n+ overcounting = pos_abs > (neg_abs * high)\n+ if overcounting:\n+ print(\"Payer is overpaying, this is correct if there was significant packet loss\")\n+ if undercounting:\nreturn False\n+ return True\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -26,7 +26,7 @@ from utils import get_rita_settings\nfrom utils import assert_test\nfrom utils import ip_to_num\nfrom utils import num_to_ip\n-from utils import fuzzy_match\n+from utils import fuzzy_traffic_match\nclass World:\n@@ -413,7 +413,7 @@ class World:\nprint(\"Node {} has a debt for Node {} but not the other way around!\".format(\nnode, node_to_compare))\ncontinue\n- res = fuzzy_match(\n+ res = fuzzy_traffic_match(\ndebts[node][node_to_compare], debts[node_to_compare][node])\nif not res:\nprint(\"Nodes {} and {} do not agree! {} has {} and {} has {}!\".format(\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Correct traffic matching rules
20,244
15.07.2019 07:05:39
14,400
89a52826215dda780f093ea5bc607a9410ecfc4b
Travis can't use this flag and we don't really need it anyways
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -7,7 +7,7 @@ before_install:\n- sudo add-apt-repository ppa:wireguard/wireguard -y\n- sudo add-apt-repository universe\n- sudo apt-get -qq update\n- - sudo apt-get install -y libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev iperf3 python3-pip bridge-utils wireguard linux-source linux-headers-$(uname -r) curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n+ - sudo apt-get install -y iperf3 libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev python3-pip bridge-utils wireguard linux-source linux-headers-$(uname -r) curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n- cargo install cross --force\n- psql -c 'create database test;' -U postgres\n@@ -44,7 +44,7 @@ matrix:\n- rustup component add rustfmt-preview\n- cargo fmt --all -- --check\n# to stop opt level 3 from sneaking in\n- - \"grep -q 'opt-level = \\\"z\\\"' Cargo.toml\"\n+ - 'grep -q ''opt-level = \"z\"'' Cargo.toml'\n- \"cargo install cargo-audit --force && cargo audit\"\n- \"cargo install cargo-geiger --force && cargo geiger\"\n- script: ./integration-tests/rita.sh\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -384,7 +384,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(to_node.id), \"iperf3\", \"-c\",\n- self.to_ip(from_node), \"--connect-timeout\", \"100\", \"-V\", \"-t 60\", \"-R\", ])\n+ self.to_ip(from_node), \"-V\", \"-t 60\", \"-R\", ])\nelse:\nserver = subprocess.Popen(\n@@ -392,7 +392,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-c\",\n- self.to_ip(to_node), \"--connect-timeout\", \"100\", \"-V\", \"-n\", \"-t 60\"])\n+ self.to_ip(to_node), \"-V\", \"-n\", \"-t 60\"])\nclient.wait()\nserver.send_signal(signal.SIGINT)\nserver.wait()\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Travis can't use this flag and we don't really need it anyways
20,244
12.07.2019 15:32:39
14,400
e943ef23b3bacc555f22e04a71d4536e19469cea
Log all debts This will be a little noisy but it will allow us to chart debts divergence, somthing I want to watch over longer periods of time now
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -461,12 +461,12 @@ impl DebtKeeper {\nlet debt_data = self.get_debt_data_mut(ident);\n// the debt we started this round with\n- trace!(\n- \"send_update for {:?}: debt: {:?}, payment balance: {:?}\",\n- ident.mesh_ip,\n- debt_data.debt,\n- debt_data.incoming_payments,\n+ if debt_data.debt != Int256::from(0) {\n+ info!(\n+ \"debt update for {}: debt: {}, payment balance: {}\",\n+ ident.wg_public_key, debt_data.debt, debt_data.incoming_payments,\n);\n+ }\n// reduce debt if it's negative to try and trend to zero\n// the edge case this is supposed to handle is if a node ran out of money and then\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Log all debts This will be a little noisy but it will allow us to chart debts divergence, somthing I want to watch over longer periods of time now
20,244
15.07.2019 15:17:29
14,400
5c8bbb27fc8b73e750fe48e843b3ac3c52282103
Don't log clients that aren't online This is just a bit of log spam
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/traffic_watcher/mod.rs", "new_path": "rita/src/rita_exit/traffic_watcher/mod.rs", "diff": "@@ -96,7 +96,7 @@ fn get_babel_info(\ndestinations.insert(id.wg_public_key, u64::from(price));\n}\n- None => warn!(\"Can't find destination for client {:?}\", ip.ip()),\n+ None => trace!(\"Can't find destination for client {:?}\", ip.ip()),\n}\n}\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Don't log clients that aren't online This is just a bit of log spam
20,244
15.07.2019 15:34:21
14,400
b68e5bed66baed6c00519bd6e25ffe87f889e556
Add integration test network map in readme
[ { "change_type": "MODIFY", "old_path": "integration-tests/readme.md", "new_path": "integration-tests/readme.md", "diff": "This folder must be located in a folder containing the Althea projects being tested together:\n+Default virtual network topology:\n+\n+Where 5 is the exit and 7 is the gateway\n+\n+```\n+ 5\n+ |\n+ 7\n+ / \\\n+ 3 6\n+ / \\ / \\\n+4 2 1\n+```\n+\n```\nalthea-mesh/\n|- integration-tests/ # This folder\n@@ -10,6 +24,7 @@ althea-mesh/\nNetwork lab needs to be installed using `bpkg`.\nExample:\n+\n```\n# use this or whatever package manager is available on your platform\nsudo 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 jq\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Add integration test network map in readme
20,249
15.07.2019 12:47:35
25,200
096edbaf2262d4f24f322bd461a1952b9282e81a
Regenerate mesh IP on private key import
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "new_path": "rita/src/rita_client/dashboard/eth_private_key.rs", "diff": "@@ -4,6 +4,7 @@ use crate::SETTING;\nuse actix_web::{HttpRequest, HttpResponse, Json};\nuse althea_types::ExitState;\nuse clarity::PrivateKey;\n+use clu::linux_generate_mesh_ip;\nuse failure::Error;\nuse settings::client::RitaClientSettings;\nuse settings::FileWrite;\n@@ -44,9 +45,20 @@ pub fn set_eth_private_key(data: Json<EthPrivateKey>) -> Result<HttpResponse, Er\npayment_settings.eth_address = Some(pk.to_public_key()?);\ndrop(payment_settings);\n- // remove the wg_public_key to force exit re-registration\n+ // remove the wg_public_key and regenerate mesh_ip to force exit re-registration\nlet mut network_settings = SETTING.get_network_mut();\nnetwork_settings.wg_public_key = None;\n+\n+ match linux_generate_mesh_ip() {\n+ Ok(ip) => {\n+ network_settings.mesh_ip = Some(ip);\n+ }\n+ Err(e) => {\n+ warn!(\"Unable to generate new mesh IP: {:?}\", e);\n+ return Err(e);\n+ }\n+ }\n+\ndrop(network_settings);\n// unset current exit\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Regenerate mesh IP on private key import
20,244
16.07.2019 08:24:28
14,400
db6d436a4fff4e51ac4a5247ffaec4822c4209ce
Fix -n option for travis
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -9,7 +9,6 @@ before_install:\n- sudo apt-get -qq update\n- sudo apt-get install -y iperf3 libsqlite3-dev postgresql-client-11 postgresql-server-dev-11 libpq-dev python3-pip bridge-utils wireguard linux-source linux-headers-$(uname -r) curl git libssl-dev pkg-config build-essential ipset python3-setuptools python3-wheel\n- cargo install cross --force\n- - psql -c 'create database test;' -U postgres\nenv:\nmatrix:\n" }, { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -142,6 +142,7 @@ class World:\nexec_or_exit(\"sudo ip netns exec {} sudo -u {} PGDATA=/var/lib/postgresql/data {}\".format(\nEXIT_NAMESPACE, POSTGRES_USER, POSTGRES_BIN), False)\ntime.sleep(30)\n+\nexec_no_exit(\"psql -c 'drop database test;' -U postgres\", True)\nexec_no_exit(\"psql -c 'create database test;' -U postgres\", True)\n@@ -392,7 +393,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-c\",\n- self.to_ip(to_node), \"-V\", \"-n\", \"-t 60\"])\n+ self.to_ip(to_node), \"-V\", \"-t 60\"])\nclient.wait()\nserver.send_signal(signal.SIGINT)\nserver.wait()\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix -n option for travis
20,244
16.07.2019 09:43:00
14,400
69bc02e32526364557fed8b7b7c72b9b8bed3dc9
Print overpayment percentage
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/utils.py", "new_path": "integration-tests/integration-test-script/utils.py", "diff": "@@ -344,7 +344,8 @@ def fuzzy_traffic_match(numA, numB):\n# this should only happen if there is packet loss\novercounting = pos_abs > (neg_abs * high)\nif overcounting:\n- print(\"Payer is overpaying, this is correct if there was significant packet loss\")\n+ print(\"Payer is overpaying by {}%, this is correct if there was significant packet loss\".format(\n+ pos_abs/neg_abs))\nif undercounting:\nreturn False\nreturn True\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Print overpayment percentage
20,244
16.07.2019 12:10:56
14,400
4f6e2bdf9420cca5be22948356de354c1f795097
Fix Gateway client billing corner case This creates an alternate billing path for a gateway that is both a client and a relay for a given exit. It identifies that such a network organization exits, then evaluates billing in the same way the exit will in that case.
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_client/rita_loop/mod.rs", "new_path": "rita/src/rita_client/rita_loop/mod.rs", "diff": "//! tunnel if the signup was successful on the selected exit.\nuse crate::rita_client::exit_manager::ExitManager;\n+use crate::rita_client::traffic_watcher::TrafficWatcher;\n+use crate::rita_client::traffic_watcher::WeAreGatewayClient;\n+use crate::rita_common::tunnel_manager::GetNeighbors;\n+use crate::rita_common::tunnel_manager::TunnelManager;\n+use crate::SETTING;\nuse actix::{\n- Actor, ActorContext, Addr, AsyncContext, Context, Handler, Message, Supervised, SystemService,\n+ Actor, ActorContext, Addr, Arbiter, AsyncContext, Context, Handler, Message, Supervised,\n+ SystemService,\n};\n+use althea_types::ExitState;\nuse failure::Error;\n+use futures::future::Future;\n+use settings::client::RitaClientSettings;\nuse std::time::{Duration, Instant};\n#[derive(Default)]\n@@ -16,6 +25,7 @@ pub struct RitaLoop;\n// the speed in seconds for the client loop\npub const CLIENT_LOOP_SPEED: u64 = 5;\n+pub const CLIENT_LOOP_TIMEOUT: Duration = Duration::from_secs(4);\nimpl Actor for RitaLoop {\ntype Context = Context<Self>;\n@@ -64,6 +74,8 @@ impl Handler<Tick> for RitaLoop {\nExitManager::from_registry().do_send(Tick {});\n+ Arbiter::spawn(check_for_gateway_client_billing_corner_case());\n+\ninfo!(\n\"Rita Client loop completed in {}s {}ms\",\nstart.elapsed().as_secs(),\n@@ -77,3 +89,38 @@ pub fn check_rita_client_actors() {\nassert!(crate::rita_client::rita_loop::RitaLoop::from_registry().connected());\nassert!(crate::rita_client::exit_manager::ExitManager::from_registry().connected());\n}\n+\n+/// There is a complicated corner case where the gateway is a client and a relay to\n+/// the same exit, this will produce incorrect billing data as we need to reconcile the\n+/// relay bills (under the exit relay id) and the client bills (under the exit id) versus\n+/// the exit who just has the single billing id for the client and is combining debts\n+/// This function grabs neighbors and etermines if we have a neighbor with the same mesh ip\n+/// and eth adress as our selected exit, if we do we trigger the special case handling\n+fn check_for_gateway_client_billing_corner_case() -> impl Future<Item = (), Error = ()> {\n+ TunnelManager::from_registry()\n+ .send(GetNeighbors)\n+ .timeout(CLIENT_LOOP_TIMEOUT)\n+ .then(move |res| {\n+ // strange notication lets us scope our access to SETTING and prevent\n+ // holding a readlock\n+ let exit_server = { SETTING.get_exit_client().get_current_exit().cloned() };\n+ let neighbors = res.unwrap().unwrap();\n+\n+ if let Some(exit) = exit_server {\n+ if let ExitState::Registered { .. } = exit.info {\n+ for neigh in neighbors {\n+ // we have a neighbor who is also our selected exit!\n+ // wg_key exluded due to multihomed exits having a different one\n+ if neigh.identity.global.mesh_ip == exit.id.mesh_ip\n+ && neigh.identity.global.eth_address == exit.id.eth_address\n+ {\n+ TrafficWatcher::from_registry()\n+ .do_send(WeAreGatewayClient { value: true });\n+ }\n+ }\n+ TrafficWatcher::from_registry().do_send(WeAreGatewayClient { value: false });\n+ }\n+ }\n+ Ok(())\n+ })\n+}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_client/traffic_watcher/mod.rs", "new_path": "rita/src/rita_client/traffic_watcher/mod.rs", "diff": "//! with the ones the exit computes. While we'll never be able to totally eliminate the ability for the exit to defraud the user\n//! with fake packet loss we can at least prevent the exit from presenting insane values.\n-use crate::rita_common::debt_keeper::{DebtKeeper, Traffic, TrafficReplace};\n+use crate::rita_common::debt_keeper::{\n+ DebtKeeper, Traffic, TrafficReplace, WgKeyInsensitiveTrafficUpdate,\n+};\nuse crate::rita_common::usage_tracker::UpdateUsage;\nuse crate::rita_common::usage_tracker::UsageTracker;\nuse crate::rita_common::usage_tracker::UsageType;\n@@ -45,8 +47,13 @@ use std::time::Instant;\nuse tokio::net::TcpStream as TokioTcpStream;\npub struct TrafficWatcher {\n+ // last read download\nlast_read_input: u64,\n+ // last read upload\nlast_read_output: u64,\n+ /// handles the gateway exit client corner case where we need to reconcile client\n+ /// and relay debts\n+ gateway_exit_client: bool,\n}\nimpl Actor for TrafficWatcher {\n@@ -58,6 +65,7 @@ impl SystemService for TrafficWatcher {\ninfo!(\"Client traffic watcher started\");\nself.last_read_input = 0;\nself.last_read_output = 0;\n+ self.gateway_exit_client = false;\n}\n}\nimpl Default for TrafficWatcher {\n@@ -65,7 +73,32 @@ impl Default for TrafficWatcher {\nTrafficWatcher {\nlast_read_input: 0,\nlast_read_output: 0,\n+ gateway_exit_client: false,\n+ }\n+ }\n}\n+\n+/// There is a complicated corner case where the gateway is a client and a relay to\n+/// the same exit, this will produce incorrect billing data as we need to reconcile the\n+/// relay bills (under the exit relay id) and the client bills (under the exit id) versus\n+/// the exit who just has the single billing id for the client and is combining debts\n+/// This function grabs neighbors and etermines if we have a neighbor with the same mesh ip\n+/// and eth adress as our selected exit, if we do we trigger the special case handling\n+/// this is called in rita client loop when this condition is discovered to set it here\n+pub struct WeAreGatewayClient {\n+ pub value: bool,\n+}\n+\n+impl Message for WeAreGatewayClient {\n+ type Result = Result<(), Error>;\n+}\n+\n+impl Handler<WeAreGatewayClient> for TrafficWatcher {\n+ type Result = Result<(), Error>;\n+\n+ fn handle(&mut self, msg: WeAreGatewayClient, _: &mut Context<Self>) -> Self::Result {\n+ self.gateway_exit_client = msg.value;\n+ Ok(())\n}\n}\n@@ -98,6 +131,7 @@ impl Handler<QueryExitDebts> for TrafficWatcher {\nfn handle(&mut self, msg: QueryExitDebts, _: &mut Context<Self>) -> Self::Result {\ntrace!(\"About to query the exit for client debts\");\n+ let gateway_exit_client = self.gateway_exit_client;\nlet start = Instant::now();\nlet exit_addr = msg.exit_internal_addr;\nlet exit_id = msg.exit_id;\n@@ -131,7 +165,7 @@ impl Handler<QueryExitDebts> for TrafficWatcher {\nstart.elapsed().as_secs(),\nstart.elapsed().subsec_millis()\n);\n- if debt >= Int256::from(0) {\n+ if !gateway_exit_client {\nlet exit_replace = TrafficReplace {\ntraffic: Traffic {\nfrom: exit_id,\n@@ -140,8 +174,9 @@ impl Handler<QueryExitDebts> for TrafficWatcher {\n};\nDebtKeeper::from_registry().do_send(exit_replace);\n- } else {\n- info!(\"The exit owes us? We must be a gateway!\");\n+ }\n+ else {\n+ info!(\"We are a gateway!, Acting accordingly\");\n}\n}\nErr(e) => {\n@@ -198,7 +233,13 @@ impl Handler<Watch> for TrafficWatcher {\ntype Result = Result<(), Error>;\nfn handle(&mut self, msg: Watch, _: &mut Context<Self>) -> Self::Result {\n- watch(self, &msg.exit_id, msg.exit_price, msg.routes)\n+ watch(\n+ self,\n+ &msg.exit_id,\n+ msg.exit_price,\n+ msg.routes,\n+ self.gateway_exit_client,\n+ )\n}\n}\n@@ -207,6 +248,7 @@ pub fn watch(\nexit: &Identity,\nexit_price: u64,\nroutes: Vec<Route>,\n+ gateway_exit_client: bool,\n) -> Result<(), Error> {\nlet exit_route = find_exit_route_capped(exit.mesh_ip, routes)?;\n@@ -290,6 +332,17 @@ pub fn watch(\nif owes_exit > 0 {\ninfo!(\"Total client debt of {} this round\", owes_exit);\n+ if gateway_exit_client {\n+ let exit_replace = WgKeyInsensitiveTrafficUpdate {\n+ traffic: Traffic {\n+ from: *exit,\n+ amount: Int256::from(owes_exit),\n+ },\n+ };\n+\n+ DebtKeeper::from_registry().do_send(exit_replace);\n+ }\n+\n// update the usage tracker with the details of this round's usage\nUsageTracker::from_registry().do_send(UpdateUsage {\nkind: UsageType::Client,\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -184,6 +184,32 @@ impl Handler<TrafficUpdate> for DebtKeeper {\n}\n}\n+/// Special case traffic update for client gateway corner case, see rita client traffic watcher for more\n+/// details. This updates a debt identity matching only ip address and eth address.\n+#[derive(Message)]\n+pub struct WgKeyInsensitiveTrafficUpdate {\n+ pub traffic: Traffic,\n+}\n+\n+impl Handler<WgKeyInsensitiveTrafficUpdate> for DebtKeeper {\n+ type Result = ();\n+\n+ fn handle(\n+ &mut self,\n+ msg: WgKeyInsensitiveTrafficUpdate,\n+ _: &mut Context<Self>,\n+ ) -> Self::Result {\n+ let partial_id = msg.traffic.from;\n+ for (id, _) in self.debt_data.clone().iter() {\n+ if id.eth_address == partial_id.eth_address && id.mesh_ip == partial_id.mesh_ip {\n+ self.traffic_update(&id, msg.traffic.amount);\n+ return;\n+ }\n+ }\n+ error!(\"Wg key insensitive billing has not found a target! Gateway billing incorrect!\");\n+ }\n+}\n+\n/// A variant of traffic update that replaces one debts entry wholesale\n/// only used by the client to update it's own debt to the exit\n#[derive(Message)]\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/rita_loop/fast_loop.rs", "new_path": "rita/src/rita_common/rita_loop/fast_loop.rs", "diff": "@@ -179,7 +179,9 @@ impl Handler<Tick> for RitaFastLoop {\n}\n}\n-/// Manages gateway functionaltiy and maintains the was_gateway parameter\n+/// Manages gateway functionaltiy and maintains the was_gateway parameter, this is different from the gateway\n+/// identification in rita_client because this must function even if we aren't registered for an exit it's also\n+/// very prone to being true when the device has a wan port but no actual wan connection.\nfn manage_gateway(mut was_gateway: bool) -> bool {\n// Resolves the gateway client corner case\n// Background info here https://forum.altheamesh.com/t/the-gateway-client-corner-case/35\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Fix Gateway client billing corner case This creates an alternate billing path for a gateway that is both a client and a relay for a given exit. It identifies that such a network organization exits, then evaluates billing in the same way the exit will in that case.
20,244
16.07.2019 15:55:53
14,400
ce27358358ae9ea66eba64d2511d692fc1250e47
Reduce throughput for travis
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -385,7 +385,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(to_node.id), \"iperf3\", \"-c\",\n- self.to_ip(from_node), \"-V\", \"-t 60\", \"-R\", ])\n+ self.to_ip(from_node), \"-V\", \"-t 30\", \"-b 10M\", \"-R\", ])\nelse:\nserver = subprocess.Popen(\n@@ -393,7 +393,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-c\",\n- self.to_ip(to_node), \"-V\", \"-t 60\"])\n+ self.to_ip(to_node), \"-V\", \"-t 30\", \"-b 10M\"])\nclient.wait()\nserver.send_signal(signal.SIGINT)\nserver.wait()\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Reduce throughput for travis
20,244
17.07.2019 07:38:11
14,400
c655fd26334fbd120aad95bf068d48eaf7168e77
Send sigterm instead of sigint It looks like the lockup issue in travis is the iperf server not closing, maybe it just needs a stronger signal
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/world.py", "new_path": "integration-tests/integration-test-script/world.py", "diff": "@@ -385,7 +385,7 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(to_node.id), \"iperf3\", \"-c\",\n- self.to_ip(from_node), \"-V\", \"-t 30\", \"-b 10M\", \"-R\", ])\n+ self.to_ip(from_node), \"-V\", \"-t 60\", \"-b 200M\", \"-R\", ])\nelse:\nserver = subprocess.Popen(\n@@ -393,9 +393,9 @@ class World:\ntime.sleep(2)\nclient = subprocess.Popen(\n[\"ip\", \"netns\", \"exec\", \"netlab-{}\".format(from_node.id), \"iperf3\", \"-c\",\n- self.to_ip(to_node), \"-V\", \"-t 30\", \"-b 10M\"])\n+ self.to_ip(to_node), \"-V\", \"-t 60\", \"-b 200M\"])\nclient.wait()\n- server.send_signal(signal.SIGINT)\n+ server.send_signal(signal.SIGTERM)\nserver.wait()\ndef test_traffic(self, traffic_test_pairs):\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Send sigterm instead of sigint It looks like the lockup issue in travis is the iperf server not closing, maybe it just needs a stronger signal
20,244
17.07.2019 10:10:07
14,400
86c33370e3b1bc9fcad0208b24fac59f4bd8f7b7
Test for gateway detection
[ { "change_type": "MODIFY", "old_path": "integration-tests/integration-test-script/rita.py", "new_path": "integration-tests/integration-test-script/rita.py", "diff": "@@ -35,6 +35,10 @@ dname = os.path.dirname(os.path.dirname(abspath))\nos.chdir(dname)\nEXIT_NAMESPACE = \"netlab-5\"\n+EXIT_ID = 5\n+\n+GATEWAY_NAMESPACE = \"netlab-7\"\n+GATEWAY_ID = 7\nNETWORK_LAB = os.path.join(dname, 'deps/network-lab/network-lab.sh')\nBABELD = os.path.join(dname, 'deps/babeld/babeld')\n@@ -305,6 +309,9 @@ def main():\nassert_test(not check_log_contains(\"rita-n{}.log\".format(id),\n\"suspending forwarding\"), \"Suspension of {}\".format(id))\n+ assert_test(not check_log_contains(\"rita-n{}.log\".format(GATEWAY_ID),\n+ \"We are a gateway!, Acting accordingly\"), \"Successful gateway/exit detection\")\n+\nif DEBUG:\nprint(\"Debug mode active, examine the mesh after tests and press \" +\n\"Enter to exit\")\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Test for gateway detection
20,244
18.07.2019 17:59:12
14,400
b3763f22971c211e4e8a6fa93c81b0e8fe20591c
Bump for Beta 7 RC1
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -170,7 +170,7 @@ dependencies = [\nname = \"althea_rs\"\nversion = \"0.1.10\"\ndependencies = [\n- \"rita 0.5.5\",\n+ \"rita 0.5.6\",\n]\n[[package]]\n@@ -1905,7 +1905,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.5\"\n+version = \"0.5.6\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.5\"\n+version = \"0.5.6\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 6 RC6\";\n+pub static READABLE_VERSION: &str = \"Beta 7 RC1\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump for Beta 7 RC1
20,244
23.07.2019 16:24:53
14,400
5b6804c3e19a9b9ccbe9ea61466c555043d56492
Modify debts saving to not use structs as keys
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -79,6 +79,25 @@ impl NodeDebtData {\n}\npub type DebtData = HashMap<Identity, NodeDebtData>;\n+/// a datatype used only for the serializing of DebtData since\n+/// serde does not support structs as keys in maps\n+type DebtDataSer = Vec<(Identity, NodeDebtData)>;\n+\n+fn debt_data_to_ser(input: DebtData) -> DebtDataSer {\n+ let mut ret = DebtDataSer::new();\n+ for (i, d) in input {\n+ ret.push((i,d));\n+ }\n+ ret\n+}\n+\n+fn ser_to_debt_data(input: DebtDataSer) -> DebtData {\n+ let mut ret = DebtData::new();\n+ for (i, d) in input {\n+ ret.insert(i, d);\n+ }\n+ ret\n+}\n#[derive(Clone, Debug, Serialize, Deserialize)]\npub struct DebtKeeper {\n@@ -301,11 +320,14 @@ impl Default for DebtKeeper {\nlet mut contents = String::new();\nmatch file.read_to_string(&mut contents) {\nOk(_bytes_read) => {\n- let deserialized: Result<DebtKeeper, SerdeError> =\n+ let deserialized: Result<DebtDataSer, SerdeError> =\nserde_json::from_str(&contents);\nmatch deserialized {\n- Ok(value) => value,\n+ Ok(value) => DebtKeeper {\n+ last_save: None,\n+ debt_data: ser_to_debt_data(value)\n+ },\nErr(e) => {\nerror!(\"Failed to deserialize debts file {:?}\", e);\nblank_debt_keeper\n@@ -360,7 +382,8 @@ impl DebtKeeper {\n}\nfn save(&mut self) -> Result<(), IOError> {\n- let serialized = serde_json::to_string(self)?;\n+ // convert to the serializeable format and dump to the disk\n+ let serialized = serde_json::to_string(&debt_data_to_ser(self.debt_data.clone()))?;\nlet mut file = File::create(SETTING.get_payment().debts_file.clone())?;\nfile.write_all(serialized.as_bytes())\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Modify debts saving to not use structs as keys
20,244
23.07.2019 16:33:32
14,400
89ab9cb9d6221362a9e7164ad4da599013150886
Clean up rustdoc comment for SAVE_FREQENCY
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/debt_keeper/mod.rs", "new_path": "rita/src/rita_common/debt_keeper/mod.rs", "diff": "@@ -32,7 +32,7 @@ use std::io::Write;\nuse std::time::Duration;\nuse std::time::Instant;\n-/// Four hours\n+/// How often we save the nodes debt data, currently 4 hours\nconst SAVE_FREQENCY: Duration = Duration::from_secs(14400);\n#[derive(Clone, Debug, Serialize, Deserialize)]\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Clean up rustdoc comment for SAVE_FREQENCY
20,244
24.07.2019 10:39:20
14,400
97995f687ae51f313c98bed84fef38c56b0ce85c
Follow hardlinks for tests
[ { "change_type": "MODIFY", "old_path": "scripts/test.sh", "new_path": "scripts/test.sh", "diff": "@@ -18,7 +18,7 @@ tar --exclude $REPOFOLDER/target \\\n--exclude $REPOFOLDER/integration-tests/target_b \\\n--exclude $REPOFOLDER/integration-tests/deps \\\n--exclude $REPOFOLDER/integration-tests/container/rita.tar.gz \\\n- --exclude $REPOFOLDER/scripts -czf $DOCKERFOLDER/rita.tar.gz $REPOFOLDER\n+ --exclude $REPOFOLDER/scripts --dereference --hard-dereference -czf $DOCKERFOLDER/rita.tar.gz $REPOFOLDER\npushd $DOCKERFOLDER\ntime docker build -t rita-test .\ntime docker run --privileged -it rita-test\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Follow hardlinks for tests
20,244
24.07.2019 11:43:36
14,400
a78d1c848427abbd586d5cca35023e84cae038d2
Mute cargo Audit for now We're going to have to upgrade Actix to fix this bug and that is a pile of technical debt we can't really address right now.
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -44,7 +44,7 @@ matrix:\n- cargo fmt --all -- --check\n# to stop opt level 3 from sneaking in\n- 'grep -q ''opt-level = \"z\"'' Cargo.toml'\n- - \"cargo install cargo-audit --force && cargo audit\"\n+ #- \"cargo install cargo-audit --force && cargo audit\"\n- \"cargo install cargo-geiger --force && cargo geiger\"\n- script: ./integration-tests/rita.sh\nenv: INITIAL_POLL_INTERVAL=5 BACKOFF_FACTOR=\"1.5\" VERBOSE=1 POSTGRES_USER=postgres POSTGRES_BIN=/usr/lib/postgresql/9.6/bin/postgres POSTGRES_DATABASE=/var/ramfs/postgresql/9.6/main POSTGRES_CONFIG=/etc/postgresql/9.6/main/postgresql.conf\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Mute cargo Audit for now We're going to have to upgrade Actix to fix this bug and that is a pile of technical debt we can't really address right now.
20,244
24.07.2019 13:14:19
14,400
f19d6f0b17088087476e75445e99579340bb2427
Bump up pay threshold in tests to prevent race condition It's possible that we mesure debts in between an attempt to pay and the resulting failure of that attempt.
[ { "change_type": "MODIFY", "old_path": "settings/default.toml", "new_path": "settings/default.toml", "diff": "[payment]\n-pay_threshold = \"0\"\n+pay_threshold = \"10000000000000\"\nclose_threshold = \"-10000000000000\"\nclose_fraction = \"100\"\nbuffer_period = 3\n" }, { "change_type": "MODIFY", "old_path": "settings/default_exit.toml", "new_path": "settings/default_exit.toml", "diff": "@@ -3,7 +3,7 @@ workers = 1\ndescription = \"just a normal althea exit\"\n[payment]\n-pay_threshold = \"0\"\n+pay_threshold = \"10000000000000\"\nclose_threshold = \"-10000000000000\"\nclose_fraction = \"100\"\nbuffer_period = 3\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump up pay threshold in tests to prevent race condition It's possible that we mesure debts in between an attempt to pay and the resulting failure of that attempt.
20,244
24.07.2019 15:49:40
14,400
1b5d162606b38655c1aadf0095c98e779f3bdafe
Bump for Beta 7 RC2
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -168,9 +168,9 @@ dependencies = [\n[[package]]\nname = \"althea_rs\"\n-version = \"0.1.10\"\n+version = \"0.1.11\"\ndependencies = [\n- \"rita 0.5.6\",\n+ \"rita 0.5.7\",\n]\n[[package]]\n@@ -1969,7 +1969,7 @@ source = \"registry+https://github.com/rust-lang/crates.io-index\"\n[[package]]\nname = \"rita\"\n-version = \"0.5.6\"\n+version = \"0.5.7\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n" }, { "change_type": "MODIFY", "old_path": "Cargo.toml", "new_path": "Cargo.toml", "diff": "[package]\nname = \"althea_rs\"\n-version = \"0.1.10\"\n+version = \"0.1.11\"\nauthors = [\"Stan Drozd <drozdziak1@gmail.com>\"]\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "[package]\nname = \"rita\"\n-version = \"0.5.6\"\n+version = \"0.5.7\"\nauthors = [\"Jehan <jehan.tremback@gmail.com>\", \"Ben <wangben3@gmail.com>\"]\nbuild = \"build.rs\"\nedition = \"2018\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/dashboard/own_info.rs", "new_path": "rita/src/rita_common/dashboard/own_info.rs", "diff": "@@ -6,7 +6,7 @@ use clarity::Address;\nuse failure::Error;\nuse num256::{Int256, Uint256};\n-pub static READABLE_VERSION: &str = \"Beta 7 RC1\";\n+pub static READABLE_VERSION: &str = \"Beta 7 RC2\";\n#[derive(Serialize)]\npub struct OwnInfo {\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Bump for Beta 7 RC2
20,244
21.05.2019 19:00:22
14,400
5c9dc0759417120808ed80bc7fee311f28f85251
WIP: Eth to xdai autoconversion
[ { "change_type": "MODIFY", "old_path": "Cargo.toml", "new_path": "Cargo.toml", "diff": "@@ -20,3 +20,4 @@ codegen-units = 1\nincremental = false\n[patch.crates-io]\n+clarity = {git = \"https://github.com/althea-mesh/clarity/\"}\n" }, { "change_type": "MODIFY", "old_path": "rita/Cargo.toml", "new_path": "rita/Cargo.toml", "diff": "@@ -22,7 +22,8 @@ exit_db = { path = \"../exit_db\" }\nnum256 = \"0.2\"\nsettings = { path = \"../settings\" }\n-web30 = {git = \"https://github.com/althea-mesh/web30\", rev=\"56b0068aa43eb563db996418eb96f3ade85ef73b\"}\n+auto-bridge = {git = \"https://github.com/althea-mesh/auto_bridge/\"}\n+web30 = {git = \"https://github.com/althea-mesh/web30\"}\nsyslog = \"4\"\nactix = \"0.7\"\nactix-web = { version = \"0.7\", default_features = false, features= [\"ssl\"] }\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/mod.rs", "new_path": "rita/src/rita_common/mod.rs", "diff": "@@ -8,6 +8,7 @@ pub mod payment_controller;\npub mod payment_validator;\npub mod peer_listener;\npub mod rita_loop;\n+pub mod token_bridge;\npub mod traffic_watcher;\npub mod tunnel_manager;\npub mod usage_tracker;\n" }, { "change_type": "ADD", "old_path": null, "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "+//! This module is designed to allow easy deposits for some supported chains using Ethereum. The idea\n+//! is pretty simple, the user deposits money into their routers Ethereum address, this is then exchanged\n+//! through uniswap into DAI and then from there it is bridged over to the Xdai proof of authority chains.\n+//! Support for Cosmos chains using a DAI-pegged native currency is next on the list.\n+//!\n+//! Essentially the goal is to allow uers to deposit a popular and easy to aquire coin like Ethereum and then\n+//! actually transact in a stablecoin on a fast blockchain, eg not Ethereum. Withdraws are also transparently\n+//! converted back to Ethereum to allow easy exchange by the user.\n+//!\n+//! This entire module works on the premise we call the conveyor belt model. It's difficult to track\n+//! money through this entire process exactly, in fact there are some edge cases where it's simply not\n+//! possible to reliably say if a task has completed or not. With that in mind we simply always progress\n+//! the the process for Eth -> DAI -> XDAI unless we explicilty have a withdraw in progress. So if we find\n+//! some DAI in our address it will always be converted to XDAI even if we didn't convert that DAI from Eth\n+//! in the first place.\n+//!\n+//! For the withdraw process we create a withdraw request object which does a best effort sheparding of the\n+//! requested withdraw amount back to Eth and into the users hands. If this fails then the withdraw will timeout\n+//! and the money will not be lost but instead moved back into XDAI by the normal conveyor belt operation\n+\n+use crate::SETTING;\n+use actix::Actor;\n+use actix::Arbiter;\n+use actix::Context;\n+use actix::Handler;\n+use actix::Message;\n+use actix::Supervised;\n+use actix::SystemService;\n+use althea_types::SystemChain;\n+use auto_bridge::TokenBridge as TokenBridgeInfo;\n+use clarity::Address;\n+use futures::future;\n+use futures::future::Future;\n+use num256::Uint256;\n+use settings::RitaCommonSettings;\n+use std::str::FromStr;\n+use std::time::Duration;\n+use std::time::Instant;\n+\n+const BRIDGE_TIMEOUT: Duration = Duration::from_secs(600);\n+\n+fn is_timed_out(started: Instant) -> bool {\n+ Instant::now() - started > BRIDGE_TIMEOUT\n+}\n+\n+/// List of all possible events that may be in progress in this module\n+/// as well as a starting time in order to apply timeouts\n+pub enum InProgress {\n+ EthToDai(Instant),\n+ DaiToXdai(Instant),\n+ XdaiToDai(Instant),\n+ DaiToEth(Instant),\n+ EthToWithdraw(Instant),\n+ UniswapApprove(Instant),\n+}\n+\n+/// Represents a withdraw in progress\n+pub struct Withdraw {\n+ start: Instant,\n+ amount: Uint256,\n+}\n+\n+pub struct TokenBridge {\n+ bridge: TokenBridgeInfo,\n+ withdraws: Vec<Withdraw>,\n+ operation_in_progress: Option<InProgress>,\n+ // these amounts are in dollars, we also assume the dai price is equal to the dollar\n+ // exchange rate for Eth. The reserve amount is how much we are keeping in our Eth wallet\n+ // in order to pay for the fees of future actions we may be required to take to deposit or\n+ // withdraw. Minimum to exchange represents the minimum amount that can be exchanged without\n+ // fees becoming unreasonable.\n+ reserve_amount: u32,\n+ minimum_to_exchange: u32,\n+}\n+\n+impl Actor for TokenBridge {\n+ type Context = Context<Self>;\n+}\n+\n+impl Supervised for TokenBridge {}\n+impl SystemService for TokenBridge {\n+ fn service_started(&mut self, _ctx: &mut Context<Self>) {\n+ info!(\"TokenBridge started\");\n+ assert!(self.minimum_to_exchange > self.reserve_amount);\n+ }\n+}\n+\n+impl Default for TokenBridge {\n+ fn default() -> TokenBridge {\n+ TokenBridge {\n+ bridge: TokenBridgeInfo::new(\n+ Address::from_str(\"0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14\").unwrap(),\n+ Address::from_str(\"0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6\").unwrap(),\n+ Address::from_str(\"0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016\").unwrap(),\n+ Address::from_str(\"0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359\").unwrap(),\n+ SETTING.get_payment().eth_address.unwrap(),\n+ SETTING.get_payment().eth_private_key.unwrap(),\n+ \"https://eth.althea.org\".into(),\n+ \"https://dai.althea.org\".into(),\n+ ),\n+ withdraws: Vec::new(),\n+ operation_in_progress: None,\n+ minimum_to_exchange: 10,\n+ reserve_amount: 1,\n+ }\n+ }\n+}\n+\n+#[derive(Message)]\n+pub struct Update();\n+\n+impl Handler<Update> for TokenBridge {\n+ type Result = ();\n+\n+ fn handle(&mut self, _msg: Update, _ctx: &mut Context<Self>) -> Self::Result {\n+ let payment_settings = SETTING.get_payment();\n+ let our_address = payment_settings.eth_address.unwrap();\n+ let our_private_key = payment_settings.eth_private_key.unwrap();\n+ let balance = payment_settings.balance.clone();\n+ let gas_price = payment_settings.gas_price.clone();\n+ let system_chain = payment_settings.system_chain;\n+ drop(payment_settings);\n+\n+ match system_chain {\n+ SystemChain::Xdai => {\n+ if self.withdraws.len() > 0 {\n+ progress_xdai_withdraws()\n+ } else {\n+ progress_xdai_deposits()\n+ }\n+ }\n+ // no other chains have auto migration code, ignore clippy for now\n+ _ => {}\n+ }\n+ }\n+}\n+\n+fn progress_xdai_deposits() {\n+ dispatch_approval(bridge: TokenBridgeInfo);\n+ dispatch_eth_to_dai_swap(\n+ bridge: TokenBridgeInfo,\n+ reserve_dollars: u32,\n+ minimum_to_exchange_dollars: u32,\n+ balance: Uint256,\n+ );\n+ dispatch_dai_to_xdai_swap(\n+ bridge: TokenBridgeInfo,\n+ minimum_to_exchange_dollars: u32,\n+ address: Address,\n+ );\n+}\n+\n+fn progress_xdai_withdraws() {\n+ dispatch_approval(bridge: TokenBridgeInfo);\n+ dispatch_xdai_to_dai_swap(bridge: TokenBridgeInfo, amount: Uint256);\n+ dispatch_dai_to_eth_swap(bridge: TokenBridgeInfo, address: Address);\n+ dispatch_user_withdraw();\n+}\n+\n+/// Spawns a future that will attempt to swap Eth from our eth address into DAI also\n+/// in that same Eth address using Uniswap. The reserve dollars amount will always be\n+/// kept in Eth for txfees. If the Eth balance is not greater than the minimum to exchange\n+/// nothing will happen.\n+fn dispatch_eth_to_dai_swap(\n+ bridge: TokenBridgeInfo,\n+ reserve_dollars: u32,\n+ minimum_to_exchange_dollars: u32,\n+ balance: Uint256,\n+) {\n+ Arbiter::spawn(\n+ bridge\n+ .dai_to_eth_price(1u8.into())\n+ .then(move |wei_per_dollar| {\n+ if wei_per_dollar.is_err() {\n+ error!(\"Failed to get Dai to Eth Price with {:?}\", wei_per_dollar);\n+ return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n+ }\n+\n+ let wei_per_dollar = wei_per_dollar.unwrap();\n+ let reserve = wei_per_dollar.clone() * reserve_dollars.into();\n+ let minimum_to_exchange = wei_per_dollar * minimum_to_exchange_dollars.into();\n+\n+ if balance >= minimum_to_exchange {\n+ // do stuff\n+ let swap_amount = balance - reserve;\n+ Box::new(bridge.eth_to_dai_swap(swap_amount, 600).then(|_res| Ok(())))\n+ as Box<Future<Item = (), Error = ()>>\n+ } else {\n+ // we don't have a lot of eth, we shouldn't do anything\n+ Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n+ }\n+ }),\n+ );\n+}\n+\n+/// Spawns a future that will send DAI from our Eth address into the POA XDAI bridge\n+/// this bridge will then spawn those DAI as XDAI in the same address on the XDAI side\n+/// once again if the DAI balance is smaller than the minimum to exchange this future\n+/// will do nothing.\n+fn dispatch_dai_to_xdai_swap(\n+ bridge: TokenBridgeInfo,\n+ minimum_to_exchange_dollars: u32,\n+ address: Address,\n+) {\n+ Arbiter::spawn(\n+ bridge\n+ .get_dai_balance(address)\n+ .then(move |our_dai_balance| {\n+ if our_dai_balance.is_err() {\n+ error!(\"Failed to get Dai balance with {:?}\", our_dai_balance);\n+ return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n+ }\n+\n+ let our_dai_balance = our_dai_balance.unwrap();\n+\n+ if our_dai_balance >= minimum_to_exchange_dollars.into() {\n+ // do stuff\n+ Box::new(\n+ bridge\n+ .dai_to_xdai_bridge(our_dai_balance)\n+ .then(|_res| Ok(())),\n+ ) as Box<Future<Item = (), Error = ()>>\n+ } else {\n+ // we don't have a lot of eth, we shouldn't do anything\n+ Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n+ }\n+ }),\n+ );\n+}\n+\n+/// This is the first step to reversing the conversion process and getting XDAI back out\n+/// into Eth, this function will attempt to convert a given amount of XDAI on the POA XDAI\n+/// chain into Eth on the Eth chain. It is assumed that the user checked that they actually\n+/// have enough xdai to perform this conversion. This function does not accept a minimum\n+/// to exchange as all flows in this direction are user requested withdraws\n+fn dispatch_xdai_to_dai_swap(bridge: TokenBridgeInfo, amount: Uint256) {\n+ Arbiter::spawn(\n+ bridge\n+ .xdai_to_dai_bridge(amount.clone())\n+ .then(move |bridge_txid| {\n+ match bridge_txid {\n+ Ok(txid) => info!(\n+ \"Xdai to DAI withdraw for {} processed with txid {:#066x}\",\n+ amount, txid\n+ ),\n+ Err(e) => info!(\"Xdai to DAI withdraw failed with {:?}\", e),\n+ }\n+ Ok(())\n+ }),\n+ );\n+}\n+\n+/// This will convert Dai in our Eth address back to Eth using the uniswap exchange contract\n+/// on the Eth blockchian. It does not accept a minimum to exchange as all flows in this\n+/// direction are user requested withdraws\n+fn dispatch_dai_to_eth_swap(bridge: TokenBridgeInfo, address: Address) {\n+ Arbiter::spawn(\n+ bridge\n+ .get_dai_balance(address)\n+ .then(move |our_dai_balance| {\n+ if our_dai_balance.is_err() {\n+ error!(\"Failed to get Dai balance with {:?}\", our_dai_balance);\n+ return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n+ }\n+\n+ let our_dai_balance = our_dai_balance.unwrap();\n+\n+ Box::new(\n+ bridge\n+ .dai_to_eth_swap(our_dai_balance, 600)\n+ .then(|_res| Ok(())),\n+ ) as Box<Future<Item = (), Error = ()>>\n+ }),\n+ );\n+}\n+\n+/// In order to use the Uniswap contract on the Eth chain to exchange from DAI to ETH we need\n+/// to first approve the Uniswap contract to spend our DAI balance. This is somthing of an expensive\n+/// operation gas wise, so we first check if we've already done it.\n+fn dispatch_approval(bridge: TokenBridgeInfo) {\n+ Arbiter::spawn(\n+ bridge\n+ .check_if_uniswap_dai_approved()\n+ .then(move |approval_status| {\n+ if approval_status.is_err() {\n+ error!(\n+ \"Failed to Uniswap dai approved status with {:?}\",\n+ approval_status\n+ );\n+ return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n+ }\n+\n+ let approved = approval_status.unwrap();\n+\n+ if approved {\n+ Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n+ } else {\n+ Box::new(\n+ bridge\n+ .approve_uniswap_dai_transfers(Duration::from_secs(600))\n+ .then(|_res| Ok(())),\n+ ) as Box<Future<Item = (), Error = ()>>\n+ }\n+ }),\n+ );\n+}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/rita_loop/mod.rs", "new_path": "rita/src/rita_exit/rita_loop/mod.rs", "diff": "@@ -130,7 +130,6 @@ impl Handler<Tick> for RitaLoop {\nlet ids = clients_to_ids(clients_list.clone());\n// watch and bill for traffic\n-\nArbiter::spawn(\nopen_babel_stream(babel_port)\n.from_err()\n@@ -172,6 +171,8 @@ impl Handler<Tick> for RitaLoop {\nArbiter::spawn(validate_clients_region(clients_list.clone()));\n}\n+ // watch and bill for traffic\n+ TrafficWatcher::from_registry().do_send(Watch(ids));\n// handle enforcement on client tunnels by querying debt keeper\n// this consumes client list, you can move it up in exchange for a clone\nArbiter::spawn(enforce_exit_clients(clients_list));\n" }, { "change_type": "MODIFY", "old_path": "settings/src/payment.rs", "new_path": "settings/src/payment.rs", "diff": "use althea_types::SystemChain;\nuse clarity::{Address, PrivateKey};\n+use std::collections::HashMap;\nuse num256::{Int256, Uint256};\n@@ -83,6 +84,8 @@ pub struct PaymentSettings {\npub eth_private_key: Option<PrivateKey>,\n// Our own eth Address, derived from the private key on startup and not stored\npub eth_address: Option<Address>,\n+ // Denotes addresses that we have approved for uniswap\n+ pub approved_for_uniswap: HashMap<Address, bool>,\n#[serde(default)]\npub balance: Uint256,\n#[serde(default)]\n@@ -122,6 +125,7 @@ impl Default for PaymentSettings {\nbalance_warning_level: (10_000_000_000_000_000u64).into(),\neth_private_key: None,\neth_address: None,\n+ approved_for_uniswap: HashMap::new(),\nbalance: 0u64.into(),\nnonce: 0u64.into(),\ngas_price: 10000000000u64.into(), // 10 gwei\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
WIP: Eth to xdai autoconversion
20,248
26.05.2019 15:30:57
25,200
411c1af857c382574cb4307fdf999cfb6a790403
WIP worked out system in english
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/token_bridge/mod.rs", "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "//! For the withdraw process we create a withdraw request object which does a best effort sheparding of the\n//! requested withdraw amount back to Eth and into the users hands. If this fails then the withdraw will timeout\n//! and the money will not be lost but instead moved back into XDAI by the normal conveyor belt operation\n+//!\n+//! If there are no withdraw orders on the queue\n+//!\n+//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount, subtract the `reserve` amount\n+//! and convert it through uniswap into DAI.\n+//!\n+//! If there is a dai balance, send it through the bridge into xdai\n+//!\n+//! If there is a dai withdraw order on the queue\n+//!\n+//! If there is a dai balance (minus pending withdraw orders) greater or equal to the withdraw amount,\n+//! send the withdraw amount through uniswap into eth and create a pending dai withdraw order.\n+//! Future waits on Uniswap and upon successful transfer, deletes pending dai withdraw order and\n+//! creates eth withdraw order. Upon timeout, retries uniswap (possibly with increased timeout and/or gas fee?)\n+//!\n+//! If there is an eth withdraw order on the queue\n+//!\n+//! If there is an `eth_balance` greater or equal to the withdraw amount, send the withdraw amount to the\n+//! destination of the withdraw order, and delete the withdraw order. (Should there be a retry here?)\n+//!\n+//! Possibly simpler technique: This can only handle one withdraw at once, but that's probably ok\n+//!\n+//! DefaultState:\n+//! TickEvent:\n+//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount, subtract the `reserve` amount\n+//! and convert it through uniswap into DAI.\n+//!\n+//! If there is a dai balance, send it through the bridge into xdai\n+//!\n+//! WithdrawEvent(to, amount):\n+//! Send amount into bridge, switch to WithdrawState.\n+//!\n+//! WithdrawState{ to, amount, timestamp}:\n+//! TickEvent:\n+//! If there is a dai balance greater or equal to the withdraw amount, send the withdraw\n+//! amount through uniswap.\n+//! Future waits on Uniswap and upon successful swap, sends eth to \"to\" address. Another future\n+//! waits on this transfer to complete. When it is complete, the state switches back to DefaultState\n+//!\n+//! WithdrawEvent:\n+//! Nothing happens\n+//!\n+//! Alternate design of the above where we poll instead of using futures\n+//!\n+//! DefaultState:\n+//! TickEvent:\n+//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount, subtract the `reserve` amount\n+//! and convert it through uniswap into DAI.\n+//!\n+//! If there is a dai balance, send it through the bridge into xdai\n+//!\n+//! WithdrawEvent(to, amount):\n+//! Send amount into bridge, switch to DaiWithdrawState.\n+//!\n+//! DaiWithdrawState{ to, daiAmount, timestamp }:\n+//! TickEvent:\n+//! If there is a dai balance greater or equal to the daiAmount, send the daiAmount\n+//! through uniswap and switch to EthWithdrawState.\n+//!\n+//! WithdrawEvent:\n+//! Nothing happens\n+//!\n+//! PendingUniswapState{ to, daiAmount, timestamp }:\n+//! TickEvent:\n+//! Check our eth balance. If it is greater than daiAmount.toEth(), send daiAmount.toEth() to\n+//! \"to\" address and switch to PendingEthTransferState (alternately, also check for uniswap event).\n+//! If not, and if current time is greater than timestamp + uniswap timeout, retry sending the\n+//! daiAmount through uniswap and reset the timestamp.\n+//!\n+//! WithdrawEvent:\n+//! Nothing happens\n+//!\n+//! PendingEthTransferState{ to, daiAmount, timestamp, txHash }:\n+//! TickEvent:\n+//! Check to see if txHash has gone through. If it has, switch to DefaultState. If it has not,\n+//! check if current time is greater than timestamp + eth transfer timeout, if it is, retry.\n+//!\n+//! WithdrawEvent:\n+//! Nothing happens\n+//!\nuse crate::SETTING;\nuse actix::Actor;\n@@ -45,25 +125,39 @@ fn is_timed_out(started: Instant) -> bool {\n/// List of all possible events that may be in progress in this module\n/// as well as a starting time in order to apply timeouts\n-pub enum InProgress {\n- EthToDai(Instant),\n- DaiToXdai(Instant),\n- XdaiToDai(Instant),\n- DaiToEth(Instant),\n- EthToWithdraw(Instant),\n- UniswapApprove(Instant),\n-}\n+// pub enum InProgress {\n+// EthToDai(Instant),\n+// DaiToXdai(Instant),\n+// XdaiToDai(Instant),\n+// DaiToEth(Instant),\n+// EthToWithdraw(Instant),\n+// UniswapApprove(Instant),\n+// }\n/// Represents a withdraw in progress\n-pub struct Withdraw {\n- start: Instant,\n+pub enum Withdraw {\n+ Eth {\n+ timestamp: Instant,\n+ amount: Uint256,\n+ to: Address,\n+ },\n+ Dai {\n+ timestamp: Instant,\n+ amount: Uint256,\n+ to: Address,\n+ },\n+ PendingDai {\n+ timestamp: Instant,\namount: Uint256,\n+ to: Address,\n+ },\n}\npub struct TokenBridge {\nbridge: TokenBridgeInfo,\n- withdraws: Vec<Withdraw>,\n- operation_in_progress: Option<InProgress>,\n+ eth_withdraws: Vec<Withdraw>,\n+ dai_withdraws: Vec<Withdraw>,\n+ pending_dai_withdraws: Vec<Withdraw>,\n// these amounts are in dollars, we also assume the dai price is equal to the dollar\n// exchange rate for Eth. The reserve amount is how much we are keeping in our Eth wallet\n// in order to pay for the fees of future actions we may be required to take to deposit or\n@@ -98,8 +192,10 @@ impl Default for TokenBridge {\n\"https://eth.althea.org\".into(),\n\"https://dai.althea.org\".into(),\n),\n- withdraws: Vec::new(),\n- operation_in_progress: None,\n+ eth_withdraws: Vec::new(),\n+ dai_withdraws: Vec::new(),\n+ pending_dai_withdraws: Vec::new(),\n+ // operation_in_progress: None,\nminimum_to_exchange: 10,\nreserve_amount: 1,\n}\n@@ -123,10 +219,25 @@ impl Handler<Update> for TokenBridge {\nmatch system_chain {\nSystemChain::Xdai => {\n- if self.withdraws.len() > 0 {\n- progress_xdai_withdraws()\n+ if self.dai_withdraws.len() > 0 {\n+ self.bridge\n+ .get_dai_balance(address)\n+ .then(move |our_dai_balance| {\n+ let pending_withdraw_amount = self\n+ .pending_dai_withdraws\n+ .iter()\n+ .fold(0, |acc, x| acc + x.amount);\n+\n+ if (our_dai_balance - pending_withdraw_amount) >\n+ })\n} else {\n- progress_xdai_deposits()\n+\n+ }\n+\n+ if self.eth_withdraws.len() > 0 {\n+\n+ } else {\n+\n}\n}\n// no other chains have auto migration code, ignore clippy for now\n@@ -135,27 +246,27 @@ impl Handler<Update> for TokenBridge {\n}\n}\n-fn progress_xdai_deposits() {\n- dispatch_approval(bridge: TokenBridgeInfo);\n- dispatch_eth_to_dai_swap(\n- bridge: TokenBridgeInfo,\n- reserve_dollars: u32,\n- minimum_to_exchange_dollars: u32,\n- balance: Uint256,\n- );\n- dispatch_dai_to_xdai_swap(\n- bridge: TokenBridgeInfo,\n- minimum_to_exchange_dollars: u32,\n- address: Address,\n- );\n-}\n+// fn progress_xdai_deposits() {\n+// dispatch_approval(bridge: TokenBridgeInfo);\n+// dispatch_eth_to_dai_swap(\n+// bridge: TokenBridgeInfo,\n+// reserve_dollars: u32,\n+// minimum_to_exchange_dollars: u32,\n+// balance: Uint256,\n+// );\n+// dispatch_dai_to_xdai_swap(\n+// bridge: TokenBridgeInfo,\n+// minimum_to_exchange_dollars: u32,\n+// address: Address,\n+// );\n+// }\n-fn progress_xdai_withdraws() {\n- dispatch_approval(bridge: TokenBridgeInfo);\n- dispatch_xdai_to_dai_swap(bridge: TokenBridgeInfo, amount: Uint256);\n- dispatch_dai_to_eth_swap(bridge: TokenBridgeInfo, address: Address);\n- dispatch_user_withdraw();\n-}\n+// fn progress_xdai_withdraws() {\n+// dispatch_approval(bridge: TokenBridgeInfo);\n+// dispatch_xdai_to_dai_swap(bridge: TokenBridgeInfo, amount: Uint256);\n+// dispatch_dai_to_eth_swap(bridge: TokenBridgeInfo, address: Address);\n+// dispatch_user_withdraw();\n+// }\n/// Spawns a future that will attempt to swap Eth from our eth address into DAI also\n/// in that same Eth address using Uniswap. The reserve dollars amount will always be\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
WIP worked out system in english
20,248
26.05.2019 22:03:40
25,200
aeed8896e5e974b7f70f902658f0d798962e68a2
WIP compiles but no retry
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/token_bridge/mod.rs", "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "@@ -83,6 +83,7 @@ fn is_timed_out(started: Instant) -> bool {\n// }\n/// Represents a withdraw in progress\n+#[derive(Clone)]\npub enum State {\nDeposit {},\nWithdraw {\n@@ -152,23 +153,25 @@ impl Handler<Update> for TokenBridge {\nlet system_chain = payment_settings.system_chain;\ndrop(payment_settings);\n+ let bridge = self.bridge.clone();\n+\nmatch system_chain {\n- SystemChain::Xdai => match self.state {\n- State::Deposit {} => {\n- Box::new(futures::future::ok(())) as Box<Future<Item = (), Error = Error>>\n- }\n+ SystemChain::Xdai => match self.state.clone() {\n+ State::Deposit {} => (),\nState::Withdraw {\ntimestamp,\nto,\namount,\n- } => Box::new(self.bridge.get_dai_balance(our_address).and_then(\n- move |our_dai_balance| {\n+ } => Arbiter::spawn(\n+ self.bridge\n+ .get_dai_balance(our_address)\n+ .and_then(move |our_dai_balance| {\nif our_dai_balance >= amount {\nBox::new(\n- self.bridge\n+ bridge\n.dai_to_eth_swap(amount, UNISWAP_TIMEOUT)\n- .and_then(|transferred_eth| {\n- self.bridge\n+ .and_then(move |transferred_eth| {\n+ bridge\n.eth_web3\n.send_transaction(\nto,\n@@ -183,22 +186,25 @@ impl Handler<Update> for TokenBridge {\nSendTxOption::NetworkId(100u64),\n],\n)\n- .and_then(|tx_hash| {\n- self.bridge\n+ .and_then(move |tx_hash| {\n+ bridge\n.eth_web3\n.wait_for_transaction(tx_hash.into())\n.timeout(Duration::from_secs(\nETH_TRANSFER_TIMEOUT,\n))\n})\n- }),\n- ) as Box<Future<Item = (), Error = Error>>\n+ })\n+ .then(|_| futures::future::ok(())),\n+ )\n+ as Box<Future<Item = (), Error = Error>>\n} else {\nBox::new(futures::future::ok(()))\nas Box<Future<Item = (), Error = Error>>\n}\n- },\n- )),\n+ })\n+ .then(|_| Ok(())),\n+ ),\n},\n// no other chains have auto migration code, ignore clippy for now\n_ => {}\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_exit/rita_loop/mod.rs", "new_path": "rita/src/rita_exit/rita_loop/mod.rs", "diff": "@@ -171,8 +171,6 @@ impl Handler<Tick> for RitaLoop {\nArbiter::spawn(validate_clients_region(clients_list.clone()));\n}\n- // watch and bill for traffic\n- TrafficWatcher::from_registry().do_send(Watch(ids));\n// handle enforcement on client tunnels by querying debt keeper\n// this consumes client list, you can move it up in exchange for a clone\nArbiter::spawn(enforce_exit_clients(clients_list));\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
WIP compiles but no retry
20,248
28.05.2019 17:41:20
25,200
a1f1d3ee6fd857528696f4d2a173f941a8f74fc0
Complete, compiles, but needs code review
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/token_bridge/mod.rs", "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "//!\n//! It is implemented as a state machine:\n//!\n-//! DefaultState:\n+//! State::Deposit:\n//! TickEvent:\n-//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount, subtract the `reserve` amount\n-//! and convert it through uniswap into DAI.\n-//!\n-//! If there is a dai balance, send it through the bridge into xdai\n+//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount,\n+//! subtract the `reserve` amount and convert it through uniswap into DAI. Future waits on\n+//! Uniswap, and upon successful swap, sends dai thru the bridge into xdai.\n//!\n//! WithdrawEvent(to, amount):\n//! Send amount into bridge, switch to WithdrawState.\n//!\n-//! WithdrawState{ to, amount, timestamp}:\n+//! State::Withdraw { to, amount, timestamp}:\n//! TickEvent:\n//! If there is a dai balance greater or equal to the withdraw amount, send the withdraw\n//! amount through uniswap.\n+//!\n//! Future waits on Uniswap and upon successful swap, sends eth to \"to\" address. Another future\n-//! waits on this transfer to complete. When it is complete, the state switches back to DefaultState\n+//! waits on this transfer to complete. When it is complete, the state switches back to State::Deposit\n//!\n//! WithdrawEvent:\n//! Nothing happens\n//!\n+//! Rewrite into actor semantics where logic is grouped by event, not state...\n+//!\n+//! TickEvent:\n+//! State::Deposit:\n+//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount, subtract the `reserve` amount\n+//! and convert it through uniswap into DAI.\n+//!\n+//! Future waits on Uniswap, and upon successful swap, sends dai thru the bridge into xdai.\n+//!\n+//! State::Withdraw { to, amount, timestamp}:\n+//! If there is a dai balance greater or equal to the withdraw amount, send the withdraw\n+//! amount through uniswap.\n+//!\n+//! Future waits on Uniswap and upon successful swap, sends eth to \"to\" address. Another future\n+//! waits on this transfer to complete. When it is complete, the state switches back to State::Deposit\n+//!\n+//! WithdrawEvent:\n+//! State::Deposit:\n+//! Send amount into bridge, switch to State::Withdraw.\n+//!\n+//! State::Withdraw { to, amount, timestamp}:\n+//! Nothing happens\nuse crate::SETTING;\nuse actix::Actor;\n@@ -55,13 +77,11 @@ use clarity::Address;\nuse failure::Error;\nuse futures::future;\nuse futures::future::Future;\n-use futures_timer::FutureExt;\nuse num256::Uint256;\nuse settings::RitaCommonSettings;\nuse std::str::FromStr;\nuse std::time::Duration;\nuse std::time::Instant;\n-use web30::types::SendTxOption;\nconst BRIDGE_TIMEOUT: Duration = Duration::from_secs(600);\nconst UNISWAP_TIMEOUT: u64 = 600u64;\n@@ -71,26 +91,10 @@ fn is_timed_out(started: Instant) -> bool {\nInstant::now() - started > BRIDGE_TIMEOUT\n}\n-/// List of all possible events that may be in progress in this module\n-/// as well as a starting time in order to apply timeouts\n-// pub enum InProgress {\n-// EthToDai(Instant),\n-// DaiToXdai(Instant),\n-// XdaiToDai(Instant),\n-// DaiToEth(Instant),\n-// EthToWithdraw(Instant),\n-// UniswapApprove(Instant),\n-// }\n-\n-/// Represents a withdraw in progress\n#[derive(Clone)]\npub enum State {\nDeposit {},\n- Withdraw {\n- timestamp: Instant,\n- amount: Uint256,\n- to: Address,\n- },\n+ Withdraw { amount: Uint256, to: Address },\n}\npub struct TokenBridge {\n@@ -139,61 +143,77 @@ impl Default for TokenBridge {\n}\n#[derive(Message)]\n-pub struct Update();\n+pub struct Tick();\n-impl Handler<Update> for TokenBridge {\n+impl Handler<Tick> for TokenBridge {\ntype Result = ();\n- fn handle(&mut self, _msg: Update, _ctx: &mut Context<Self>) -> Self::Result {\n+ fn handle(&mut self, _msg: Tick, _ctx: &mut Context<Self>) -> Self::Result {\nlet payment_settings = SETTING.get_payment();\nlet our_address = payment_settings.eth_address.unwrap();\n- let our_private_key = payment_settings.eth_private_key.unwrap();\n- let balance = payment_settings.balance.clone();\n- let gas_price = payment_settings.gas_price.clone();\nlet system_chain = payment_settings.system_chain;\ndrop(payment_settings);\nlet bridge = self.bridge.clone();\n+ let reserve_amount = self.reserve_amount;\n+ let minimum_to_exchange = self.minimum_to_exchange;\n- match system_chain {\n- SystemChain::Xdai => match self.state.clone() {\n- State::Deposit {} => (),\n- State::Withdraw {\n- timestamp,\n- to,\n- amount,\n- } => Arbiter::spawn(\n+ if let SystemChain::Xdai = system_chain {\n+ match self.state.clone() {\n+ State::Deposit {} => {\n+ Arbiter::spawn(\n+ bridge\n+ .dai_to_eth_price(1u8.into())\n+ .join(bridge.eth_web3.eth_get_balance(our_address))\n+ .and_then(move |(wei_per_dollar, balance)| {\n+ // These statements convert the reserve_amount and minimum_to_exchange\n+ // into eth using the current price (units of wei)\n+ let reserve = wei_per_dollar.clone() * reserve_amount.into();\n+ let minimum_to_exchange =\n+ wei_per_dollar * minimum_to_exchange.into();\n+\n+ // This means enough has been sent into our account to start the\n+ // deposit process.\n+ if balance >= minimum_to_exchange {\n+ // Leave a reserve in the account to use for gas in the future\n+ let swap_amount = balance - reserve;\n+ Box::new(\n+ bridge\n+ // Convert to Dai in Uniswap\n+ .eth_to_dai_swap(swap_amount, 600)\n+ .and_then(move |dai_bought| {\n+ // And over the bridge into xDai\n+ bridge.dai_to_xdai_bridge(dai_bought)\n+ })\n+ .and_then(|_res| Ok(())),\n+ )\n+ as Box<Future<Item = (), Error = Error>>\n+ } else {\n+ // we don't have a lot of eth, we shouldn't do anything\n+ Box::new(future::ok(()))\n+ as Box<Future<Item = (), Error = Error>>\n+ }\n+ })\n+ .then(|_| Ok(())),\n+ )\n+ }\n+ State::Withdraw { to, amount } => Arbiter::spawn(\nself.bridge\n.get_dai_balance(our_address)\n.and_then(move |our_dai_balance| {\n+ // This is how it knows the money has come over from the bridge\nif our_dai_balance >= amount {\nBox::new(\nbridge\n+ // Then it converts to eth\n.dai_to_eth_swap(amount, UNISWAP_TIMEOUT)\n+ // And sends it to the recipient\n.and_then(move |transferred_eth| {\n- bridge\n- .eth_web3\n- .send_transaction(\n+ bridge.eth_transfer(\nto,\n- Vec::new(),\ntransferred_eth,\n- our_address,\n- our_private_key,\n- vec![\n- SendTxOption::GasPrice(\n- 10_000_000_000u128.into(),\n- ),\n- SendTxOption::NetworkId(100u64),\n- ],\n- )\n- .and_then(move |tx_hash| {\n- bridge\n- .eth_web3\n- .wait_for_transaction(tx_hash.into())\n- .timeout(Duration::from_secs(\nETH_TRANSFER_TIMEOUT,\n- ))\n- })\n+ )\n})\n.then(|_| futures::future::ok(())),\n)\n@@ -203,181 +223,59 @@ impl Handler<Update> for TokenBridge {\nas Box<Future<Item = (), Error = Error>>\n}\n})\n- .then(|_| Ok(())),\n+ .then(|_| {\n+ TokenBridge::from_registry().do_send(StateChange(State::Deposit {}));\n+ Ok(())\n+ }),\n),\n- },\n- // no other chains have auto migration code, ignore clippy for now\n- _ => {}\n}\n}\n}\n-\n-// fn progress_xdai_deposits() {\n-// dispatch_approval(bridge: TokenBridgeCore);\n-// dispatch_eth_to_dai_swap(\n-// bridge: TokenBridgeCore,\n-// reserve_dollars: u32,\n-// minimum_to_exchange_dollars: u32,\n-// balance: Uint256,\n-// );\n-// dispatch_dai_to_xdai_swap(\n-// bridge: TokenBridgeCore,\n-// minimum_to_exchange_dollars: u32,\n-// address: Address,\n-// );\n-// }\n-\n-// fn progress_xdai_withdraws() {\n-// dispatch_approval(bridge: TokenBridgeCore);\n-// dispatch_xdai_to_dai_swap(bridge: TokenBridgeCore, amount: Uint256);\n-// dispatch_dai_to_eth_swap(bridge: TokenBridgeCore, address: Address);\n-// dispatch_user_withdraw();\n-// }\n-\n-/// Spawns a future that will attempt to swap Eth from our eth address into DAI also\n-/// in that same Eth address using Uniswap. The reserve dollars amount will always be\n-/// kept in Eth for txfees. If the Eth balance is not greater than the minimum to exchange\n-/// nothing will happen.\n-fn dispatch_eth_to_dai_swap(\n- bridge: TokenBridgeCore,\n- reserve_dollars: u32,\n- minimum_to_exchange_dollars: u32,\n- balance: Uint256,\n-) {\n- Arbiter::spawn(\n- bridge\n- .dai_to_eth_price(1u8.into())\n- .then(move |wei_per_dollar| {\n- if wei_per_dollar.is_err() {\n- error!(\"Failed to get Dai to Eth Price with {:?}\", wei_per_dollar);\n- return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n}\n- let wei_per_dollar = wei_per_dollar.unwrap();\n- let reserve = wei_per_dollar.clone() * reserve_dollars.into();\n- let minimum_to_exchange = wei_per_dollar * minimum_to_exchange_dollars.into();\n-\n- if balance >= minimum_to_exchange {\n- // do stuff\n- let swap_amount = balance - reserve;\n- Box::new(bridge.eth_to_dai_swap(swap_amount, 600).then(|_res| Ok(())))\n- as Box<Future<Item = (), Error = ()>>\n- } else {\n- // we don't have a lot of eth, we shouldn't do anything\n- Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n- }\n- }),\n- );\n+#[derive(Message)]\n+pub struct Withdraw {\n+ to: Address,\n+ amount: Uint256,\n}\n-/// Spawns a future that will send DAI from our Eth address into the POA XDAI bridge\n-/// this bridge will then spawn those DAI as XDAI in the same address on the XDAI side\n-/// once again if the DAI balance is smaller than the minimum to exchange this future\n-/// will do nothing.\n-fn dispatch_dai_to_xdai_swap(\n- bridge: TokenBridgeCore,\n- minimum_to_exchange_dollars: u32,\n- address: Address,\n-) {\n- Arbiter::spawn(\n- bridge\n- .get_dai_balance(address)\n- .then(move |our_dai_balance| {\n- if our_dai_balance.is_err() {\n- error!(\"Failed to get Dai balance with {:?}\", our_dai_balance);\n- return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n- }\n+impl Handler<Withdraw> for TokenBridge {\n+ type Result = ();\n- let our_dai_balance = our_dai_balance.unwrap();\n+ fn handle(&mut self, msg: Withdraw, _ctx: &mut Context<Self>) -> Self::Result {\n+ let payment_settings = SETTING.get_payment();\n+ let system_chain = payment_settings.system_chain;\n+ drop(payment_settings);\n- if our_dai_balance >= minimum_to_exchange_dollars.into() {\n- // do stuff\n- Box::new(\n- bridge\n- .dai_to_xdai_bridge(our_dai_balance)\n- .then(|_res| Ok(())),\n- ) as Box<Future<Item = (), Error = ()>>\n- } else {\n- // we don't have a lot of eth, we shouldn't do anything\n- Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n- }\n- }),\n- );\n-}\n+ let to = msg.to;\n+ let amount = msg.amount.clone();\n-/// This is the first step to reversing the conversion process and getting XDAI back out\n-/// into Eth, this function will attempt to convert a given amount of XDAI on the POA XDAI\n-/// chain into Eth on the Eth chain. It is assumed that the user checked that they actually\n-/// have enough xdai to perform this conversion. This function does not accept a minimum\n-/// to exchange as all flows in this direction are user requested withdraws\n-fn dispatch_xdai_to_dai_swap(bridge: TokenBridgeCore, amount: Uint256) {\n- Arbiter::spawn(\n- bridge\n- .xdai_to_dai_bridge(amount.clone())\n- .then(move |bridge_txid| {\n- match bridge_txid {\n- Ok(txid) => info!(\n- \"Xdai to DAI withdraw for {} processed with txid {:#066x}\",\n- amount, txid\n+ let bridge = self.bridge.clone();\n+\n+ if let SystemChain::Xdai = system_chain {\n+ match self.state.clone() {\n+ State::Withdraw { .. } => (\n+ // Cannot start a withdraw when one is in progress\n),\n- Err(e) => info!(\"Xdai to DAI withdraw failed with {:?}\", e),\n- }\n+ State::Deposit {} => {\n+ Arbiter::spawn(bridge.xdai_to_dai_bridge(amount.clone()).then(move |_| {\n+ TokenBridge::from_registry()\n+ .do_send(StateChange(State::Withdraw { to, amount }));\nOk(())\n- }),\n- );\n+ }))\n+ }\n}\n-\n-/// This will convert Dai in our Eth address back to Eth using the uniswap exchange contract\n-/// on the Eth blockchian. It does not accept a minimum to exchange as all flows in this\n-/// direction are user requested withdraws\n-fn dispatch_dai_to_eth_swap(bridge: TokenBridgeCore, address: Address) {\n- Arbiter::spawn(\n- bridge\n- .get_dai_balance(address)\n- .then(move |our_dai_balance| {\n- if our_dai_balance.is_err() {\n- error!(\"Failed to get Dai balance with {:?}\", our_dai_balance);\n- return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n}\n-\n- let our_dai_balance = our_dai_balance.unwrap();\n-\n- Box::new(\n- bridge\n- .dai_to_eth_swap(our_dai_balance, 600)\n- .then(|_res| Ok(())),\n- ) as Box<Future<Item = (), Error = ()>>\n- }),\n- );\n}\n-\n-/// In order to use the Uniswap contract on the Eth chain to exchange from DAI to ETH we need\n-/// to first approve the Uniswap contract to spend our DAI balance. This is somthing of an expensive\n-/// operation gas wise, so we first check if we've already done it.\n-fn dispatch_approval(bridge: TokenBridgeCore) {\n- Arbiter::spawn(\n- bridge\n- .check_if_uniswap_dai_approved()\n- .then(move |approval_status| {\n- if approval_status.is_err() {\n- error!(\n- \"Failed to Uniswap dai approved status with {:?}\",\n- approval_status\n- );\n- return Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>;\n}\n- let approved = approval_status.unwrap();\n+#[derive(Message)]\n+pub struct StateChange(State);\n- if approved {\n- Box::new(future::ok(())) as Box<Future<Item = (), Error = ()>>\n- } else {\n- Box::new(\n- bridge\n- .approve_uniswap_dai_transfers(Duration::from_secs(600))\n- .then(|_res| Ok(())),\n- ) as Box<Future<Item = (), Error = ()>>\n+impl Handler<StateChange> for TokenBridge {\n+ type Result = ();\n+\n+ fn handle(&mut self, msg: StateChange, _ctx: &mut Context<Self>) -> Self::Result {\n+ self.state = msg.0;\n}\n- }),\n- );\n}\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
Complete, compiles, but needs code review
20,244
17.06.2019 07:23:34
14,400
4b0057068f90dfe2591644279cec87e78ac7d5ee
WIP: Integrate exchanging
[ { "change_type": "MODIFY", "old_path": "Cargo.lock", "new_path": "Cargo.lock", "diff": "@@ -180,7 +180,7 @@ dependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"eui48 0.4.0 (git+https://github.com/althea-mesh/eui48)\",\n\"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"num256 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -248,7 +248,7 @@ version = \"0.1.0\"\nsource = \"git+https://github.com/althea-mesh/auto_bridge/#57e00a7d03ea55032a3cde4f5a4042b99c1fe166\"\ndependencies = [\n\"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -433,7 +433,7 @@ dependencies = [\n[[package]]\nname = \"clarity\"\nversion = \"0.1.22\"\n-source = \"git+https://github.com/althea-mesh/clarity/#f1597d5eab35d31fb3ae6795989557a0e00e0796\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\ndependencies = [\n\"bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -463,7 +463,7 @@ version = \"0.0.1\"\ndependencies = [\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"ipgen 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -1998,7 +1998,7 @@ dependencies = [\n\"babel_monitor 0.1.0\",\n\"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"clu 0.0.1\",\n\"config 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -2250,7 +2250,7 @@ dependencies = [\n\"althea_kernel_interface 0.1.0\",\n\"althea_types 0.1.0\",\n\"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"config 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"eui48 0.4.0 (git+https://github.com/althea-mesh/eui48)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -2888,7 +2888,7 @@ dependencies = [\n\"actix-web 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"assert-json-diff 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)\",\n- \"clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\",\n+ \"clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)\",\n\"futures-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)\",\n@@ -3034,7 +3034,7 @@ dependencies = [\n\"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)\" = \"b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33\"\n\"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)\" = \"64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c\"\n\"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)\" = \"45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878\"\n-\"checksum clarity 0.1.22 (git+https://github.com/althea-mesh/clarity/)\" = \"<none>\"\n+\"checksum clarity 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)\" = \"c79ad42ad4a6254fa8c997650b669b766c2267dc801fb701c8c4fabe073b2823\"\n\"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f\"\n\"checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03\"\n\"checksum config 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)\" = \"f9107d78ed62b3fa5a86e7d18e647abed48cfd8f8fab6c72f4cdb982d196f7e6\"\n" }, { "change_type": "MODIFY", "old_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "new_path": "rita/src/rita_common/rita_loop/slow_loop.rs", "diff": "use crate::rita_common::dao_manager::DAOManager;\nuse crate::rita_common::dao_manager::Tick as DAOTick;\nuse crate::rita_common::payment_validator::{PaymentValidator, Validate};\n+use crate::rita_common::token_bridge::Tick as TokenBridgeTick;\n+use crate::rita_common::token_bridge::TokenBridge;\nuse crate::rita_common::tunnel_manager::{TriggerGC, TunnelManager};\nuse crate::SETTING;\nuse actix::{\n@@ -85,6 +87,8 @@ impl Handler<Tick> for RitaSlowLoop {\nSETTING.get_network().tunnel_timeout_seconds,\n)));\n+ TokenBridge::from_registry().do_send(TokenBridgeTick());\n+\n// we really only need to run this on startup, but doing so periodically\n// could catch the edge case where babel is restarted under us\nset_babel_price();\n" }, { "change_type": "MODIFY", "old_path": "settings/src/payment.rs", "new_path": "settings/src/payment.rs", "diff": "@@ -85,6 +85,7 @@ pub struct PaymentSettings {\n// Our own eth Address, derived from the private key on startup and not stored\npub eth_address: Option<Address>,\n// Denotes addresses that we have approved for uniswap\n+ #[serde(default)]\npub approved_for_uniswap: HashMap<Address, bool>,\n#[serde(default)]\npub balance: Uint256,\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
WIP: Integrate exchanging
20,248
29.06.2019 15:13:53
25,200
d0f99386ef233ecd3edadf8d8e6298550192e489
update state machine definition
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/token_bridge/mod.rs", "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "//!\n//!\n//! TickEvent:\n-//! State::Deposit:\n+//! State::Ready:\n//! If there is a Dai balance, send it thru the bridge into xdai (this rescues stuck funds in Dai)\n//!\n//! If there is an `eth_balance` that is greater than the `minimum_to_exchange` amount,\n-//! subtract the `reserve` amount and convert it through uniswap into DAI.\n+//! subtract the `reserve` amount and send it through uniswap into DAI. Change to State::Depositing.\n//!\n-//! Future waits on Uniswap, and upon successful swap, sends dai thru the bridge into xdai.\n+//! State::Depositing:\n+//! If there is a Dai balance, send it thru the bridge into xdai (this rescues stuck funds in Dai)\n+//!\n+//! Future waits on Uniswap, and upon successful swap, sends dai thru the bridge into xdai. If it\n+//! times out, change to State::Ready.\n//!\n-//! State::Withdraw { to, amount, timestamp}:\n-//! If the timestamp is expired, switch the state back into State::Deposit.\n+//! State::Withdrawing { to, amount, timestamp}:\n+//! If the timestamp is expired, switch the state back into State::Ready.\n//!\n//! If there is a dai balance greater or equal to the withdraw amount, send the withdraw\n//! amount through uniswap.\n//!\n//! Future waits on Uniswap and upon successful swap, sends eth to \"to\" address. Another future\n-//! waits on this transfer to complete. When it is complete, the state switches back to State::Deposit\n+//! waits on this transfer to complete. When it is complete, the state switches back to State::Ready\n//!\n//! WithdrawEvent:\n-//! State::Deposit:\n-//! Send amount into bridge, switch to State::Withdraw.\n+//! State::Ready:\n+//! Send amount into bridge, switch to State::Withdrawing.\n//!\n-//! State::Withdraw { to, amount, timestamp}:\n+//! State::Withdrawing { to, amount, timestamp}:\n//! Nothing happens\nuse crate::SETTING;\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
update state machine definition
20,248
01.07.2019 12:18:18
25,200
1d5e154a86cb4b6a7340881d82839d66ab8be37f
work on new state machine
[ { "change_type": "MODIFY", "old_path": "rita/src/rita_common/token_bridge/mod.rs", "new_path": "rita/src/rita_common/token_bridge/mod.rs", "diff": "//! subtract the `reserve` amount and send it through uniswap into DAI. Change to State::Depositing.\n//!\n//! State::Depositing:\n-//! If there is a Dai balance, send it thru the bridge into xdai (this rescues stuck funds in Dai)\n-//!\n-//! Future waits on Uniswap, and upon successful swap, sends dai thru the bridge into xdai. If it\n-//! times out, change to State::Ready.\n+//! Future (started in State::Ready) waits on Uniswap, and upon successful swap, sends dai\n+//! thru the bridge into xdai. When the money is out of the Dai account and in the bridge,\n+//! or if uniswap times out, change to State::Ready.\n//!\n//! State::Withdrawing { to, amount, timestamp}:\n//! If the timestamp is expired, switch the state back into State::Ready.\n@@ -83,8 +82,9 @@ fn eth_to_wei(eth: f64) -> Uint256 {\n#[derive(Clone)]\npub enum State {\n- Deposit {},\n- Withdraw {\n+ Ready {},\n+ Depositing {},\n+ Withdrawing {\namount: Uint256,\nto: Address,\ntimestamp: Instant,\n@@ -131,7 +131,7 @@ impl Default for TokenBridge {\n\"https://eth.althea.org\".into(),\n\"https://dai.althea.org\".into(),\n),\n- state: State::Deposit {},\n+ state: State::Ready {},\n// operation_in_progress: None,\nminimum_to_exchange: 10,\nreserve_amount: 1,\n@@ -140,6 +140,28 @@ impl Default for TokenBridge {\n}\n}\n+fn rescue_xdai(\n+ bridge: TokenBridgeCore,\n+ our_address: Address,\n+ minimum_stranded_dai_transfer: u32,\n+) -> Box<Future<Item = (), Error = Error>> {\n+ Box::new(bridge.get_dai_balance(our_address).and_then({\n+ move |dai_balance| {\n+ if dai_balance > eth_to_wei(minimum_stranded_dai_transfer.into()) {\n+ // Over the bridge into xDai\n+ Box::new(\n+ bridge\n+ .dai_to_xdai_bridge(dai_balance)\n+ .and_then(|_res| Ok(())),\n+ )\n+ } else {\n+ // we don't have a lot of dai, we shouldn't do anything\n+ Box::new(future::ok(())) as Box<Future<Item = (), Error = Error>>\n+ }\n+ }\n+ }))\n+}\n+\n#[derive(Message)]\npub struct Tick();\n@@ -159,29 +181,11 @@ impl Handler<Tick> for TokenBridge {\nif let SystemChain::Xdai = system_chain {\nmatch self.state.clone() {\n- State::Deposit {} => {\n+ State::Ready {} => {\n+ // Go into State::Depositing right away to prevent multiple attempts\n+ TokenBridge::from_registry().do_send(StateChange(State::Depositing {}));\nArbiter::spawn(\n- bridge\n- .get_dai_balance(our_address)\n- .and_then({\n- let bridge = self.bridge.clone();\n- move |dai_balance| {\n- if dai_balance\n- > eth_to_wei(minimum_stranded_dai_transfer.into())\n- {\n- // Over the bridge into xDai\n- Box::new(\n- bridge\n- .dai_to_xdai_bridge(dai_balance)\n- .and_then(|_res| Ok(())),\n- )\n- } else {\n- // we don't have a lot of dai, we shouldn't do anything\n- Box::new(future::ok(()))\n- as Box<Future<Item = (), Error = Error>>\n- }\n- }\n- })\n+ rescue_xdai(bridge.clone(), our_address, minimum_stranded_dai_transfer)\n.and_then(move |_| {\nbridge\n.dai_to_eth_price(eth_to_wei(1.into()))\n@@ -199,6 +203,8 @@ impl Handler<Tick> for TokenBridge {\nif eth_balance >= minimum_to_exchange {\n// Leave a reserve in the account to use for gas in the future\nlet swap_amount = eth_balance - reserve;\n+ // Temporarily changing this to debug\n+ let swap_amount = 200000000000000u64.into();\nBox::new(\nbridge\n// Convert to Dai in Uniswap\n@@ -206,8 +212,7 @@ impl Handler<Tick> for TokenBridge {\n.and_then(move |dai_bought| {\n// And over the bridge into xDai\nbridge.dai_to_xdai_bridge(dai_bought)\n- })\n- .and_then(|_res| Ok(())),\n+ }),\n)\nas Box<Future<Item = (), Error = Error>>\n} else {\n@@ -218,6 +223,11 @@ impl Handler<Tick> for TokenBridge {\n})\n})\n.then(|res| {\n+ // It goes back into State::Ready once the dai\n+ // is in the bridge. This prevents multiple\n+ // attempts to bridge the same Dai.\n+ TokenBridge::from_registry().do_send(StateChange(State::Ready {}));\n+\nif res.is_err() {\nerror!(\"Error in State::Deposit Tick handler: {:?}\", res);\n}\n@@ -225,13 +235,14 @@ impl Handler<Tick> for TokenBridge {\n}),\n)\n}\n- State::Withdraw {\n+ State::Depositing {} => {}\n+ State::Withdrawing {\nto,\namount,\ntimestamp,\n} => {\nif is_timed_out(timestamp) {\n- TokenBridge::from_registry().do_send(StateChange(State::Deposit {}));\n+ TokenBridge::from_registry().do_send(StateChange(State::Ready {}));\n} else {\nArbiter::spawn(\nbridge\n@@ -265,7 +276,7 @@ impl Handler<Tick> for TokenBridge {\n}\n// Change to Deposit whether or not there was an error\nTokenBridge::from_registry()\n- .do_send(StateChange(State::Deposit {}));\n+ .do_send(StateChange(State::Ready {}));\nOk(())\n}),\n)\n@@ -297,16 +308,19 @@ impl Handler<Withdraw> for TokenBridge {\nif let SystemChain::Xdai = system_chain {\nmatch self.state.clone() {\n- State::Withdraw { .. } => (\n+ State::Withdrawing { .. } => (\n// Cannot start a withdraw when one is in progress\n),\n- State::Deposit {} => {\n+ State::Depositing { .. } => (\n+ // Figure out something to do here\n+ ),\n+ State::Ready {} => {\nArbiter::spawn(bridge.xdai_to_dai_bridge(amount.clone()).then(move |res| {\nif res.is_err() {\nerror!(\"Error in State::Deposit Withdraw handler: {:?}\", res);\n} else {\n// Only change to Withdraw if there was no error\n- TokenBridge::from_registry().do_send(StateChange(State::Withdraw {\n+ TokenBridge::from_registry().do_send(StateChange(State::Withdrawing {\nto,\namount,\ntimestamp: Instant::now(),\n" } ]
Rust
Apache License 2.0
althea-net/althea_rs
work on new state machine