From f64449d32b127cfd4106c9711125665784ed20a5 Mon Sep 17 00:00:00 2001 From: Justin Kilpatrick Date: Wed, 10 Jan 2024 21:14:45 -0500 Subject: [PATCH] Babeld config at startup This commit provides functionality to configure Babeld at Rita startup with default interface settings. This allows us to control via Rita how exactly babel is behaving and provides the functions for potnetially tweaking these functions at runtime in the future. --- Cargo.lock | 355 +++++++++++----------- althea_types/src/interop.rs | 15 +- babel_monitor/src/lib.rs | 75 ++++- babel_monitor/src/structs.rs | 45 +++ integration_tests/src/setup_utils/rita.rs | 4 +- rita_bin/src/client.rs | 36 ++- rita_bin/src/exit.rs | 5 + rita_client/src/operator_update/mod.rs | 29 +- rita_common/src/dashboard/babel.rs | 4 +- rita_common/src/dashboard/own_info.rs | 6 +- rita_common/src/lib.rs | 1 - rita_common/src/rita_loop/slow_loop.rs | 10 +- rita_common/src/traffic_watcher/mod.rs | 2 +- rita_common/src/tunnel_manager/mod.rs | 2 +- rita_common/src/utils/mod.rs | 42 ++- rita_exit/src/traffic_watcher/mod.rs | 2 +- settings/Cargo.toml | 3 +- settings/src/network.rs | 52 +++- settings/src/payment.rs | 10 +- 19 files changed, 453 insertions(+), 245 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf8a9fef1..10c56bc47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,17 +46,17 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.4.0" +version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92ef85799cba03f76e4f7c10f533e66d87c9a7e7055f3391f09000ad8351bc9" +checksum = "129d4c88e98860e1758c5de288d1632b07970a16d59bdf7b8d66053d582bb71f" dependencies = [ "actix-codec", "actix-rt", "actix-service", "actix-tls", "actix-utils", - "ahash 0.8.6", - "base64 0.21.5", + "ahash 0.8.7", + "base64 0.21.7", "bitflags 2.4.1", "brotli", "bytes", @@ -91,14 +91,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "actix-router" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799" +checksum = "d22475596539443685426b6bdadb926ad0ecaefdfc5fb05e5e3441f15463c511" dependencies = [ "bytestring", "http", @@ -180,9 +180,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4a5b5e29603ca8c94a77c65cf874718ceb60292c5a5c3e5f4ace041af462b9" +checksum = "e43428f3bf11dee6d166b00ec2df4e3aa8cc1606aaa0b7433c146852e2f4e03b" dependencies = [ "actix-codec", "actix-http", @@ -192,7 +192,7 @@ dependencies = [ "actix-service", "actix-tls", "actix-utils", - "ahash 0.8.6", + "ahash 0.8.7", "bytes", "bytestring", "cfg-if", @@ -224,7 +224,7 @@ checksum = "1d613edf08a42ccc6864c941d30fe14e1b676a77d16f1dbadc1174d065a0a775" dependencies = [ "actix-utils", "actix-web", - "base64 0.21.5", + "base64 0.21.7", "futures-core", "futures-util", "log", @@ -239,7 +239,7 @@ checksum = "7c7db3d5a9718568e4cf4a537cfd7070e6e6ff7481510d0237fb529ac850f6d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -270,9 +270,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -392,9 +392,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.76" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arrayvec" @@ -424,18 +424,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "async-trait" -version = "0.1.75" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -444,7 +444,7 @@ version = "0.1.5" dependencies = [ "actix", "clarity", - "futures 0.3.29", + "futures 0.3.30", "log", "num", "num256", @@ -462,9 +462,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "awc" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa3c705a9c7917ac0f41c0757a0a747b43bbc29b0b364b081bd7c5fc67fb223" +checksum = "b625cad34428b3b82d0bd548b26a1cd0a3d70b6109e9b4e3355d8f1802a8b1c6" dependencies = [ "actix-codec", "actix-http", @@ -472,7 +472,7 @@ dependencies = [ "actix-service", "actix-tls", "actix-utils", - "base64 0.21.5", + "base64 0.21.7", "bytes", "cfg-if", "cookie", @@ -583,9 +583,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bech32" @@ -655,9 +655,9 @@ dependencies = [ [[package]] name = "borsh" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d4d6dafc1a3bb54687538972158f07b2c948bc57d5890df22c0739098b3028" +checksum = "f58b559fd6448c6e2fd0adb5720cd98a2506594cafa4737ff98c396f3e82f667" dependencies = [ "borsh-derive", "cfg_aliases", @@ -665,15 +665,15 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4918709cc4dd777ad2b6303ed03cb37f3ca0ccede8c1b0d28ac6db8f4710e0" +checksum = "7aadb5b6ccbd078890f6d7003694e33816e6b784358f18e15e7e6d9f065a57cd" dependencies = [ "once_cell", "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", "syn_derive", ] @@ -817,7 +817,7 @@ dependencies = [ "awc", "backoff", "flate2", - "futures 0.3.29", + "futures 0.3.30", "lazy_static", "log", "serde", @@ -872,9 +872,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -890,22 +890,18 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -919,12 +915,12 @@ dependencies = [ [[package]] name = "ctrlc" -version = "3.4.1" +version = "3.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e95fbd621905b854affdc67943b043a0fbb6ed7385fd5a25650d19a8a6cfdf" +checksum = "b467862cc8610ca6fc9a1532d7777cee0804e678ab45410897b9396495994a0b" dependencies = [ "nix 0.27.1", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -934,7 +930,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff5f0331927f701e2142333c7af97d45c1cb5e4fbab99065654d70bb2240ce6b" dependencies = [ "althea_proto", - "base64 0.21.5", + "base64 0.21.7", "bech32", "bytes", "clarity", @@ -962,9 +958,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] @@ -1066,7 +1062,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbfb21b9878cf7a348dcb8559109aabc0ec40d69924bd706fa5149846c4fef75" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "memchr", ] @@ -1189,9 +1185,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1204,9 +1200,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1214,15 +1210,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1231,38 +1227,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures 0.1.31", "futures-channel", @@ -1317,9 +1313,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -1334,9 +1330,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "b553656127a00601c8ae5590fcfdc118e4083a7924b6cf4ffc1ea4b99dc429d7" dependencies = [ "bytes", "fnv", @@ -1588,7 +1584,7 @@ dependencies = [ "diesel_migrations", "docopt", "env_logger", - "futures 0.3.29", + "futures 0.3.30", "ipnetwork", "lazy_static", "log", @@ -1633,13 +1629,13 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1688,18 +1684,18 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] [[package]] name = "keccak" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" dependencies = [ "cpufeatures", ] @@ -1722,7 +1718,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76bd09637ae3ec7bd605b8e135e757980b3968430ff2b1a4a94fb7769e50166d" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "email-encoding", "email_address", "fastrand 1.9.0", @@ -1743,9 +1739,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libsodium-sys" @@ -1847,9 +1843,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memoffset" @@ -2087,9 +2083,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -2112,7 +2108,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c75a0ec2d1b302412fb503224289325fcc0e44600176864804c7211b055cfd58" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "byteorder", "md-5", "sha2", @@ -2121,9 +2117,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.61" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -2142,7 +2138,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -2162,9 +2158,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ "cc", "libc", @@ -2231,9 +2227,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" +checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" dependencies = [ "memchr", "thiserror", @@ -2242,9 +2238,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" +checksum = "bcd6ab1236bbdb3a49027e920e693192ebfe8913f6d60e294de57463a493cfde" dependencies = [ "pest", "pest_generator", @@ -2252,22 +2248,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" +checksum = "2a31940305ffc96863a735bef7c7994a00b325a7138fdbc5bda0f1a0476d3275" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "pest_meta" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" +checksum = "a7ff62f5259e53b78d1af898941cdcdccfae7385cf7d793a6e55de5d05bb4b7d" dependencies = [ "once_cell", "pest", @@ -2322,7 +2318,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -2366,11 +2362,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +checksum = "6b2685dd208a3771337d8d386a89840f0f43cd68be8dae90a5f8c2384effc9cd" dependencies = [ - "toml_datetime", "toml_edit", ] @@ -2399,9 +2394,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.71" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -2426,7 +2421,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -2469,9 +2464,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2600,7 +2595,7 @@ version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -2710,7 +2705,7 @@ dependencies = [ "clarity", "clu", "compressed_log", - "futures 0.3.29", + "futures 0.3.30", "hex-literal", "ipnetwork", "lazy_static", @@ -2740,7 +2735,7 @@ dependencies = [ "althea_types", "awc", "clarity", - "futures 0.3.29", + "futures 0.3.30", "lazy_static", "log", "num-traits", @@ -2774,7 +2769,7 @@ dependencies = [ "deep_space", "env_logger", "flate2", - "futures 0.3.29", + "futures 0.3.30", "ipnetwork", "lazy_static", "log", @@ -2920,9 +2915,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "0a1a81a2478639a14e68937903356dbac62cf52171148924f754bb8a8cd7a96c" dependencies = [ "bitflags 2.4.1", "errno", @@ -2961,7 +2956,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", ] [[package]] @@ -2997,11 +2992,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3037,18 +3032,18 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "secp256k1" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" +checksum = "3f622567e3b4b38154fb8190bcf6b160d7a4301d70595a49195b48c116007a27" dependencies = [ "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd97a086ec737e30053fd5c46f097465d25bb81dd3608825f65298c4c98be83" +checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" dependencies = [ "cc", ] @@ -3078,15 +3073,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -3103,20 +3098,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", @@ -3143,6 +3138,7 @@ dependencies = [ "althea_types", "arrayvec", "auto-bridge", + "babel_monitor", "clarity", "ipnetwork", "lazy_static", @@ -3308,9 +3304,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -3326,7 +3322,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -3364,22 +3360,22 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "termcolor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -3398,7 +3394,7 @@ dependencies = [ "deep_space", "docopt", "env_logger", - "futures 0.3.29", + "futures 0.3.30", "integration_tests", "log", "rita_client_registration", @@ -3407,22 +3403,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -3506,7 +3502,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -3577,15 +3573,15 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ "indexmap 2.1.0", "toml_datetime", @@ -3601,7 +3597,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.21.5", + "base64 0.21.7", "bytes", "flate2", "h2", @@ -3676,7 +3672,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] @@ -3792,9 +3788,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3802,24 +3798,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -3829,9 +3825,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3839,28 +3835,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", @@ -3874,7 +3870,7 @@ checksum = "3419dff65e026307b5df735b38df61d590a0d57e8040e545d1d1f433cbd0b621" dependencies = [ "awc", "clarity", - "futures 0.3.29", + "futures 0.3.30", "lazy_static", "log", "num-traits", @@ -4056,9 +4052,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.30" +version = "0.5.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" dependencies = [ "memchr", ] @@ -4099,25 +4095,24 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.48", ] [[package]] name = "zstd" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +checksum = "bffb3309596d527cfcba7dfc6ed6052f1d39dfbd7c867aa2e865e4a449c10110" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.6" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +checksum = "43747c7422e2924c11144d5229878b98180ef8b06cca4ab5af37afc8a8d8ea3e" dependencies = [ - "libc", "zstd-sys", ] diff --git a/althea_types/src/interop.rs b/althea_types/src/interop.rs index c0ab5a949..4c8ee148b 100644 --- a/althea_types/src/interop.rs +++ b/althea_types/src/interop.rs @@ -2,8 +2,8 @@ use crate::regions::Regions; use crate::{contact_info::ContactType, wg_key::WgKey, BillingDetails, InstallationDetails}; use crate::{ClientExtender, UsageTrackerFlat, UsageTrackerTransfer, WifiDevice}; use arrayvec::ArrayString; -use babel_monitor::structs::Neighbor; use babel_monitor::structs::Route; +use babel_monitor::structs::{BabeldConfig, Neighbor}; use clarity::Address; use deep_space::Address as AltheaAddress; use ipnetwork::IpNetwork; @@ -700,8 +700,9 @@ pub struct OperatorUpdateMessage { /// When a user hits 'update router', it updates to this version pub local_update_instruction_v2: Option, /// settings for the device bandwidth shaper - #[serde(default = "default_shaper_settings")] - pub shaper_settings: ShaperSettings, + pub shaper_settings: Option, + /// settings for babeld + pub babeld_settings: Option, // Updated contact info from ops tools #[serde( serialize_with = "data_serialize", @@ -770,14 +771,6 @@ pub struct ExitConnection { pub client_pub_ipv6: Option, } -fn default_shaper_settings() -> ShaperSettings { - ShaperSettings { - max_speed: 1000, - min_speed: 50, - enabled: true, - } -} - fn default_ops_last_seen_usage_hour() -> u64 { 0 } diff --git a/babel_monitor/src/lib.rs b/babel_monitor/src/lib.rs index afea75a0b..d8a2e3c13 100644 --- a/babel_monitor/src/lib.rs +++ b/babel_monitor/src/lib.rs @@ -30,7 +30,7 @@ use std::str::FromStr; use std::str::{self}; use std::thread; use std::time::Duration; -use structs::{Interface, Neighbor}; +use structs::{BabeldInterfaceConfig, Interface, Neighbor}; /// we want to ceed the cpu just long enough for Babel /// to finish what it's doing and warp up it's write @@ -196,6 +196,7 @@ pub fn parse_interfaces(stream: &mut TcpStream) -> Result, BabelM parse_interfaces_sync(babel_output) } +/// Gets this routers local fee, what the router charges for bandwidth. The unit is wei (1*10-18 of a dollar) per byte pub fn get_local_fee(stream: &mut TcpStream) -> Result { let output = run_command(stream, "dump")?; @@ -203,6 +204,7 @@ pub fn get_local_fee(stream: &mut TcpStream) -> Result { get_local_fee_sync(babel_output) } +/// Sets this routers local fee, what the router charges for bandwidth. The unit is wei (1*10-18 of a dollar) per byte pub fn set_local_fee(stream: &mut TcpStream, new_fee: u32) -> Result<(), BabelMonitorError> { let result = run_command(stream, &format!("fee {new_fee}"))?; @@ -210,6 +212,9 @@ pub fn set_local_fee(stream: &mut TcpStream, new_fee: u32) -> Result<(), BabelMo Ok(()) } +/// Sets the metric factor for babel. This is a weighting value used to decide if this router should select +/// routes based on price or quality of service. A higher value will cause the router to prefer routes with +/// higher quailty of service, a lower value will cause the router to prefer routes with lower price. pub fn set_metric_factor(stream: &mut TcpStream, new_factor: u32) -> Result<(), BabelMonitorError> { let result = run_command(stream, &format!("metric-factor {new_factor}"))?; @@ -217,10 +222,70 @@ pub fn set_metric_factor(stream: &mut TcpStream, new_factor: u32) -> Result<(), Ok(()) } -pub fn monitor(stream: &mut TcpStream, iface: &str) -> Result<(), BabelMonitorError> { - let command = &format!("interface {iface} max-rtt-penalty 2000 enable-timestamps true"); - let iface = iface.to_string(); - let result = run_command(stream, command)?; +/// Sets the interval at which Babel will update it's routes from the kernel routing table. If set to zero Babel will only recieve +/// updates from the kernel as changes are made and will never perform a full dump. +pub fn set_kernel_check_interval( + stream: &mut TcpStream, + kernel_check_interval: Option, +) -> Result<(), BabelMonitorError> { + let interval = match kernel_check_interval { + // unit is centiseconds + Some(d) => (d.as_millis() / 100) as u16, + None => 0, + }; + let result = run_command(stream, &format!("kernel-check-interval {interval}"))?; + + let _out = result; + Ok(()) +} + +/// Sets the default interface parameters for babel. These are applied at startup and can be overridden per interface, note if modified +/// at runtime then existing interfaces will not be updated. +pub fn set_interface_defaults( + stream: &mut TcpStream, + defaults: BabeldInterfaceConfig, +) -> Result<(), BabelMonitorError> { + let mut command = "default ".to_string(); + command.push_str(&build_interface_config_string(defaults)); + let result = run_command(stream, &command)?; + + let _out = result; + Ok(()) +} + +/// internal utility for building the configuration string +fn build_interface_config_string(config: BabeldInterfaceConfig) -> String { + let mut command = String::new(); + if config.link_quality { + command.push_str("link-quality yes "); + } else { + command.push_str("link-quality no "); + } + if config.split_horizon { + command.push_str("split-horizon yes "); + } else { + command.push_str("split-horizon no "); + } + command.push_str(&format!("max-rtt-penalty {} ", config.max_rtt_penalty)); + command.push_str(&format!("rtt-min {} ", config.rtt_min)); + command.push_str(&format!("rtt-max {} ", config.rtt_max)); + command.push_str(&format!("hello-interval {} ", config.hello_interval)); + command.push_str(&format!("update-interval {} ", config.update_interval)); + command +} + +/// Adds an interface to babel to monitor, neighbors will be discovered on this interface and routes will be advertised +/// optionally this interface can have it's own configuration parameters +pub fn monitor( + stream: &mut TcpStream, + iface: &str, + options: Option, +) -> Result<(), BabelMonitorError> { + let mut command = format!("interface {iface} "); + if let Some(options) = options { + command.push_str(&build_interface_config_string(options)); + } + let result = run_command(stream, &command)?; trace!("Babel started monitoring: {}", iface); let _out = result; diff --git a/babel_monitor/src/structs.rs b/babel_monitor/src/structs.rs index 86f0b3dbb..0e591a7fc 100644 --- a/babel_monitor/src/structs.rs +++ b/babel_monitor/src/structs.rs @@ -6,6 +6,7 @@ use std::net::{AddrParseError, IpAddr}; use std::num::{ParseFloatError, ParseIntError}; use std::str::{self, ParseBoolError}; use std::string::FromUtf8Error; +use std::time::Duration; #[derive(Debug)] pub enum BabelMonitorError { @@ -139,3 +140,47 @@ pub struct Neighbor { pub rttcost: u16, pub cost: u16, } + +/// This struct lists config options for babeld, these are applied at startup +/// it is not complete and only lists options that will probably be used +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] +pub struct BabeldConfig { + /// how often to update the Babeld routing table, by doing a full kernel dump + /// Babeld listens for routing table changes and applies them immediately. If set to + /// None Babel will only listen for updates and never perform a full dump + pub kernel_check_interval: Option, + /// The Price of bandwidth advertised over this router, in terms of wei (1*10^18 of a dollar) per byte + pub local_fee: u32, + /// Decides how much weight to give to route quality versus price, a higher value means higher weight on quality + pub metric_factor: u32, + /// The default values for various interfaces options + pub interface_defaults: BabeldInterfaceConfig, +} + +/// This struct lists all config options for babeld interfaces, this can be used +/// to set the global default or used to set per interface options +/// this config is not complete, it only includes the options that will proably be used +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] +pub struct BabeldInterfaceConfig { + /// If link quality estimation is enabled for this interface + pub link_quality: bool, + /// The maximum penalty for a route with a high latency + /// the rtt value is multiplied by this value and added to the metric + /// up to rtt_max + pub max_rtt_penalty: u16, + /// The minimum rtt at which to start applying the penalty, unit is milliseconds + pub rtt_min: u16, + /// The maximum rtt at which to apply the the full value of max_rtt_penalty, unit is milliseconds + pub rtt_max: u16, + /// The interval at which to send hello messages, unit is seconds, these are used to compute packet loss + /// and latency, by default this is 1 second. The last 16 hellos are used to determine + /// route quality, increasing this value has a smoothing effect on route quality estimations + pub hello_interval: u16, + /// The interval at which to send routing table updates, since babel uses triggered + /// updates when routes becoming infeasible this can be set to a relatively high value + /// by default it is 4x the hello interval + pub update_interval: u16, + /// If set this router will avoid advertising routes it has learned from this interface + /// back to the interface, this is useful for avoiding routing loops + pub split_horizon: bool, +} diff --git a/integration_tests/src/setup_utils/rita.rs b/integration_tests/src/setup_utils/rita.rs index c3dfc0c48..4c6ff15a9 100644 --- a/integration_tests/src/setup_utils/rita.rs +++ b/integration_tests/src/setup_utils/rita.rs @@ -152,7 +152,7 @@ pub fn spawn_rita( ))); rcsettings.network.wg_private_key_path = wg_keypath; rcsettings.network.peer_interfaces = veth_interfaces; - rcsettings.payment.local_fee = local_fee; + rcsettings.network.babeld_settings.local_fee = local_fee; // mirrored from rita_bin/src/client.rs let s = clu::init(rcsettings); @@ -243,7 +243,7 @@ pub fn spawn_rita_exit( resettings.network.wg_private_key_path = wg_keypath; resettings.exit_network.wg_private_key_path = wg_keypath_exit; resettings.network.peer_interfaces = veth_interfaces; - resettings.payment.local_fee = local_fee; + resettings.network.babeld_settings.local_fee = local_fee; resettings.payment.eth_private_key = Some(instance.eth_private_key); resettings.exit_network.exit_price = exit_fee; let veth_exit_to_native = format!("vout-{}-o", ns); diff --git a/rita_bin/src/client.rs b/rita_bin/src/client.rs index 25a6a3e1d..160021d68 100644 --- a/rita_bin/src/client.rs +++ b/rita_bin/src/client.rs @@ -39,6 +39,7 @@ use rita_common::rita_loop::start_rita_common_loops; use rita_common::rita_loop::write_to_disk::save_to_disk_loop; use rita_common::rita_loop::write_to_disk::SettingsOnDisk; use rita_common::usage_tracker::save_usage_on_shutdown; +use rita_common::utils::apply_babeld_settings_defaults; use rita_common::utils::env_vars_contains; use settings::client::RitaClientSettings; use settings::save_settings_on_shutdown; @@ -60,12 +61,6 @@ fn main() { }) .expect("Error setting Ctrl-C handler"); - // Because Rita clears and sets up new Wireguard Tunnels on every restart Babel, which was attached and listening to - // the old tunnels is now in an incorrect state. We must either restart babel or empty it's interfaces list so that the newly - // created wireguard tunnels can be re-added by this instance of Rita. Due to errors in babel (see git history there) - // restarting is the way to go as removing dead interfaces often does not work - KI.restart_babel(); - let args: Args = Docopt::new(get_client_usage( env!("CARGO_PKG_VERSION"), env!("GIT_HASH"), @@ -80,10 +75,25 @@ fn main() { // and populate the memory cache of settings used throughout the program let settings: RitaClientSettings = { RitaClientSettings::new_watched(settings_file.clone()).unwrap(); - let s = settings::get_rita_client(); + let mut s = settings::get_rita_client(); settings::set_flag_config(settings_file.clone()); + // start migrations // + + // handle babel migration for old settings files + // this can be removed after all routers are upgraded paste Beta 21RC4 or Beta 20 RC31 + if let Some(local_fee) = s.payment.local_fee { + s.network.babeld_settings.local_fee = local_fee; + s.payment.local_fee = None; + } + if let Some(metric_factor) = s.network.metric_factor { + s.network.babeld_settings.metric_factor = metric_factor; + s.network.metric_factor = None; + } + + // end migrations // + let s = clu::init(s); s.write(settings_file).unwrap(); @@ -92,11 +102,21 @@ fn main() { s }; + // Because Rita clears and sets up new Wireguard Tunnels on every restart Babel, which was attached and listening to + // the old tunnels is now in an incorrect state. We must either restart babel or empty it's interfaces list so that the newly + // created wireguard tunnels can be re-added by this instance of Rita. Due to errors in babel (see git history there) + // restarting is the way to go as removing dead interfaces often does not work + KI.restart_babel(); + apply_babeld_settings_defaults( + settings.network.babel_port, + settings.network.babeld_settings, + ); + // On Linux static builds we need to probe ssl certs path to be able to // do TLS stuff. openssl_probe::init_ssl_cert_env_vars(); - // we should remove log if there's an operator address or if logging is enabled + // we should remote log if there's an operator address or if logging is enabled let should_remote_log = settings.log.enabled || settings.operator.operator_address.is_some(); // if remote logging is disabled, or the NO_REMOTE_LOG env var is set we should use the // local logger and log to std-out. Note we don't care what is actually set in NO_REMOTE_LOG diff --git a/rita_bin/src/exit.rs b/rita_bin/src/exit.rs index c593c01b1..439000891 100644 --- a/rita_bin/src/exit.rs +++ b/rita_bin/src/exit.rs @@ -37,6 +37,7 @@ use rita_common::rita_loop::start_rita_common_loops; use rita_common::rita_loop::write_to_disk::save_to_disk_loop; use rita_common::rita_loop::write_to_disk::SettingsOnDisk; use rita_common::usage_tracker::save_usage_on_shutdown; +use rita_common::utils::apply_babeld_settings_defaults; use rita_common::utils::env_vars_contains; use rita_exit::operator_update::update_loop::start_operator_update_loop; use rita_exit::rita_loop::start_rita_exit_endpoints; @@ -90,6 +91,10 @@ fn main() { println!("Look the exit settings! {settings:?}"); settings }; + apply_babeld_settings_defaults( + settings.network.babel_port, + settings.network.babeld_settings, + ); // On Linux static builds we need to probe ssl certs path to be able to // do TLS stuff. diff --git a/rita_client/src/operator_update/mod.rs b/rita_client/src/operator_update/mod.rs index 56c44f87b..863154cb0 100644 --- a/rita_client/src/operator_update/mod.rs +++ b/rita_client/src/operator_update/mod.rs @@ -211,13 +211,13 @@ pub async fn operator_update( let network = rita_client.network.clone(); trace!("Updating from operator settings"); - let payment = update_payment_settings( - rita_client.payment, + update_payment_and_network_settings( + &mut rita_client.payment, + &mut rita_client.network, use_operator_price, is_gateway, new_settings.clone(), ); - rita_client.payment = payment; trace!("Done with payment"); // merge the new settings into the local settings @@ -334,7 +334,12 @@ fn perform_operator_update( } None => {} } - network.shaper_settings = new_settings.shaper_settings; + if let Some(shaper_settings) = new_settings.shaper_settings { + network.shaper_settings = shaper_settings; + } + if let Some(babeld_settings) = new_settings.babeld_settings { + network.babeld_settings = babeld_settings; + } rita_client.network = network; settings::set_rita_client(rita_client); trace!("Successfully completed OperatorUpdate"); @@ -458,21 +463,22 @@ fn update_authorized_keys( Ok(()) } -/// Creates a payment settings from OperatorUpdateMessage to be returned and applied -fn update_payment_settings( - mut payment: PaymentSettings, +/// Updates payment settings from OperatorUpdateMessage +fn update_payment_and_network_settings( + payment: &mut PaymentSettings, + network: &mut NetworkSettings, use_operator_price: bool, is_gateway: bool, new_settings: OperatorUpdateMessage, -) -> PaymentSettings { +) { if use_operator_price { // This will be true on devices that have integrated switches // and a wan port configured. Mostly not a problem since we stopped // shipping wan ports by default if is_gateway { - payment.local_fee = new_settings.gateway; + network.babeld_settings.local_fee = new_settings.gateway; } else { - payment.local_fee = new_settings.relay; + network.babeld_settings.local_fee = new_settings.relay; } } else { info!("User has disabled the OperatorUpdate!"); @@ -481,13 +487,12 @@ fn update_payment_settings( payment.balance_warning_level = new_settings.warning.into(); if let Some(new_chain) = new_settings.system_chain { if payment.system_chain != new_chain { - set_system_blockchain(new_chain, &mut payment); + set_system_blockchain(new_chain, payment); } } if let Some(new_chain) = new_settings.withdraw_chain { payment.withdraw_chain = new_chain; } - payment } /// Returns true if the contact info sent through OperatorUpdateMessage have been more diff --git a/rita_common/src/dashboard/babel.rs b/rita_common/src/dashboard/babel.rs index c91c78a1f..fa25327ca 100644 --- a/rita_common/src/dashboard/babel.rs +++ b/rita_common/src/dashboard/babel.rs @@ -40,7 +40,7 @@ pub async fn set_local_fee(path: Path) -> HttpResponse { match babel_set_local_fee(&mut stream, new_fee) { Ok(_) => { let mut common = settings::get_rita_common(); - common.payment.local_fee = new_fee; + common.network.babeld_settings.local_fee = new_fee; settings::set_rita_common(common); // try and save the config and fail if we can't if let Err(e) = settings::write_config() { @@ -76,7 +76,7 @@ pub async fn set_metric_factor(path: Path) -> HttpResponse { match babel_set_metric_factor(&mut stream, new_factor) { Ok(_) => { let mut common = settings::get_rita_common(); - common.network.metric_factor = new_factor; + common.network.babeld_settings.metric_factor = new_factor; settings::set_rita_common(common); // try and save the config and fail if we can't diff --git a/rita_common/src/dashboard/own_info.rs b/rita_common/src/dashboard/own_info.rs index c733b79a7..44975df06 100644 --- a/rita_common/src/dashboard/own_info.rs +++ b/rita_common/src/dashboard/own_info.rs @@ -28,15 +28,15 @@ pub struct OwnInfo { pub async fn get_own_info(_req: HttpRequest) -> HttpResponse { debug!("Get own info endpoint hit!"); let payment_settings = settings::get_rita_common().payment; + let network_settings = settings::get_rita_common().network; let eth_address = payment_settings.eth_address.unwrap(); let balance = get_oracle_balance(); let pay_threshold = get_pay_thresh(); let close_threshold = calculate_close_thresh(); - let local_fee = payment_settings.local_fee; let client_can_use_free_tier = payment_settings.client_can_use_free_tier; + let local_fee = network_settings.babeld_settings.local_fee; + let metric_factor = network_settings.babeld_settings.metric_factor; - let network_settings = settings::get_rita_common().network; - let metric_factor = network_settings.metric_factor; let device = network_settings.device; let is_gateway = is_gateway(); diff --git a/rita_common/src/lib.rs b/rita_common/src/lib.rs index eba970337..4beefca0b 100644 --- a/rita_common/src/lib.rs +++ b/rita_common/src/lib.rs @@ -57,4 +57,3 @@ pub use crate::tunnel_manager::gc::*; pub use crate::tunnel_manager::id_callback::*; pub use crate::tunnel_manager::neighbor_status::*; pub use crate::tunnel_manager::shaping::*; -pub use crate::utils::ip_increment::*; diff --git a/rita_common/src/rita_loop/slow_loop.rs b/rita_common/src/rita_loop/slow_loop.rs index 7874e1da9..b45d134c9 100644 --- a/rita_common/src/rita_loop/slow_loop.rs +++ b/rita_common/src/rita_loop/slow_loop.rs @@ -52,7 +52,7 @@ pub fn start_rita_slow_loop() { Ok(mut stream) => { // we really only need to run this on startup, but doing so periodically // could catch the edge case where babel is restarted under us - if let Err(e) = set_babel_price(&mut stream) { + if let Err(e) = update_babel_price_and_metric_factor(&mut stream) { warn!("Failed to set babel price with {:?}", e); num_babel_failures += 1; } @@ -113,11 +113,13 @@ pub fn start_rita_slow_loop() { }); } -fn set_babel_price(stream: &mut TcpStream) -> Result<(), BabelMonitorError> { +/// This function updates the babeld price and metric factor by connecting to the babel instance and +/// setting those values. +fn update_babel_price_and_metric_factor(stream: &mut TcpStream) -> Result<(), BabelMonitorError> { let start = Instant::now(); let common = settings::get_rita_common(); - let local_fee = common.payment.local_fee; - let metric_factor = common.network.metric_factor; + let local_fee = common.network.babeld_settings.local_fee; + let metric_factor = common.network.babeld_settings.metric_factor; let result = set_local_fee(stream, local_fee); if let Err(e) = result { warn!( diff --git a/rita_common/src/traffic_watcher/mod.rs b/rita_common/src/traffic_watcher/mod.rs index 775b8a3fb..ffbeafe9a 100644 --- a/rita_common/src/traffic_watcher/mod.rs +++ b/rita_common/src/traffic_watcher/mod.rs @@ -68,7 +68,7 @@ pub fn get_babel_info(routes: Vec) -> Result<(HashMap, u32) let common = settings::get_rita_common(); // we assume this matches what is actually set it babel because we // panic on startup if it does not get set correctly - let local_fee = common.payment.local_fee; + let local_fee = common.network.babeld_settings.local_fee; let max_fee = common.payment.max_fee; for route in &routes { // Only ip6 diff --git a/rita_common/src/tunnel_manager/mod.rs b/rita_common/src/tunnel_manager/mod.rs index ff4c54fb5..7decec52e 100644 --- a/rita_common/src/tunnel_manager/mod.rs +++ b/rita_common/src/tunnel_manager/mod.rs @@ -209,7 +209,7 @@ impl Tunnel { // this operation blocks while opening and using a tcp stream let mut stream = open_babel_stream(babel_port, FAST_LOOP_TIMEOUT)?; - monitor(&mut stream, &iface_name) + monitor(&mut stream, &iface_name, None) } pub fn unmonitor(&self) -> Result<(), RitaCommonError> { diff --git a/rita_common/src/utils/mod.rs b/rita_common/src/utils/mod.rs index b1e4770c8..1ec26f67c 100644 --- a/rita_common/src/utils/mod.rs +++ b/rita_common/src/utils/mod.rs @@ -1,5 +1,9 @@ use std::env; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::Duration; +use std::time::{Instant, SystemTime, UNIX_EPOCH}; + +use babel_monitor::open_babel_stream; +use babel_monitor::structs::BabeldConfig; /// Random utilities that don't go anywhere else, many of these are used only in one or the other of rita_exit or rita_client so one will use it and the other will /// throw a dead code warning. @@ -27,3 +31,39 @@ pub fn secs_since_unix_epoch() -> i64 { .expect("Time went backwards"); since_the_epoch.as_secs() as i64 } + +/// This function is intended to be called at startup before any other threads are started +/// it takes the babel config and applies the settings to Babel. This must be done before +/// tunnel manager starts operating or tunnels will be setup that don't respect the defaults +/// we are trying to configure. All of these values can be changed at runtime but this function is +/// intended for startup only +pub fn apply_babeld_settings_defaults(babeld_port: u16, config: BabeldConfig) { + // how long before we give up trying to contact babel, since this is a startup process babeld + // many not be reachable due to just being started so we want to wait a bit, but not indefinately + const BABEL_CONTACT_TIMEOUT: Duration = Duration::from_secs(20); + let start = Instant::now(); + while Instant::now() < start { + if let Ok(mut stream) = open_babel_stream(babeld_port, BABEL_CONTACT_TIMEOUT) { + if let Err(e) = babel_monitor::set_local_fee(&mut stream, config.local_fee) { + error!("Failed to set babel local fee with {:?}", e); + } + if let Err(e) = babel_monitor::set_metric_factor(&mut stream, config.metric_factor) { + error!("Failed to set babel metric factor with {:?}", e); + } + if let Err(e) = + babel_monitor::set_kernel_check_interval(&mut stream, config.kernel_check_interval) + { + error!("Failed to set babel kernel check interval with {:?}", e); + } + if let Err(e) = + babel_monitor::set_interface_defaults(&mut stream, config.interface_defaults) + { + error!("Failed to set babel interface defaults with {:?}", e); + } + } + } + panic!( + "Unable to reach babel on {} please check that babel is running and configured correctly", + babeld_port + ); +} diff --git a/rita_exit/src/traffic_watcher/mod.rs b/rita_exit/src/traffic_watcher/mod.rs index 4c98ae7a7..be0811a33 100644 --- a/rita_exit/src/traffic_watcher/mod.rs +++ b/rita_exit/src/traffic_watcher/mod.rs @@ -34,7 +34,7 @@ fn get_babel_info( ) -> HashMap { // we assume this matches what is actually set it babel becuase we // panic on startup if it does not get set correctly - let local_fee = settings::get_rita_exit().payment.local_fee; + let local_fee = settings::get_rita_exit().network.babeld_settings.local_fee; // insert ourselves as a destination, don't think this is actually needed let mut destinations = HashMap::new(); diff --git a/settings/Cargo.toml b/settings/Cargo.toml index c7b69e089..f3d4c25af 100644 --- a/settings/Cargo.toml +++ b/settings/Cargo.toml @@ -5,7 +5,8 @@ authors = ["Ben "] edition = "2018" [dependencies] -althea_types = { path = "../althea_types" } +althea_types = { path = "../althea_types"} +babel_monitor = { path = "../babel_monitor"} althea_kernel_interface = { path = "../althea_kernel_interface" } auto-bridge = { path = "../auto_bridge" } num256 = "0.5" diff --git a/settings/src/network.rs b/settings/src/network.rs index d4b37656d..53af9b9b0 100644 --- a/settings/src/network.rs +++ b/settings/src/network.rs @@ -1,5 +1,6 @@ use althea_kernel_interface::DefaultRoute; use althea_types::{regions::Regions, ShaperSettings, SystemChain}; +use babel_monitor::structs::{BabeldConfig, BabeldInterfaceConfig}; use std::collections::HashSet; use std::net::{IpAddr, Ipv6Addr}; @@ -11,8 +12,44 @@ fn default_discovery_ip() -> Ipv6Addr { Ipv6Addr::new(0xff02, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x8) } -fn default_metric_factor() -> u32 { - 1_900u32 +/// Sets the default configuration values for babeld +fn default_babeld_config() -> BabeldConfig { + BabeldConfig { + // how often to update the Babeld routing table, by doing a full kernel dump + // this is useful to insert routes added to the table by other programs into the babel + // advertised route list. But this is not a property generally used in Althea. The risk of + // setting this to none is that in edge cases (such as an overloaded machine) babel may + // not get notified of a new route in the table added by another program. + kernel_check_interval: None, + // how much this router charges other routers for bandwidth, note that this value + // will be updated from operator tools defaults or the user dashboard + local_fee: 0, + // priority of quality versus price, this default value is an 'even' weight between the two + metric_factor: 1_900u32, + // the default interface config options + interface_defaults: BabeldInterfaceConfig { + // turning this off might break some of our quality monitoring code + // as we expect all links have packet loss monitoring + rtt monitoring + link_quality: true, + // the maximum route penalty for high latency, since babeld estimates latency + // by sending packets to the next hop and measuring the time it takes to get a response + // rtt can sometimes not match reality. So be careful with this value as it may cause irrational + // behavior there + max_rtt_penalty: 200u16, + // below this rtt no penalty is applied + rtt_min: 50u16, + // above this rtt only the max_rtt_penalty is applied + rtt_max: 500u16, + // how often in seconds to send hello messages, these are used to compute packet loss + hello_interval: 5u16, + // how often in seconds to send route updates, triggered updates are sent when a route changes + // so this can be safely set to a high value + update_interval: 20u16, + // When true routes are never re-advertised to the interface they were received from, this shoudl always + // be true for our use case since babel is always listening on a tunnel. + split_horizon: true, + }, + } } fn default_usage_tracker_file() -> String { @@ -35,11 +72,12 @@ fn default_allowed_countries() -> HashSet { #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] pub struct NetworkSettings { + #[serde(default = "default_babeld_config")] + pub babeld_settings: BabeldConfig, /// How much non-financial metrics matter compared to a route's cost. By default a 2x more /// expensive route will only be chosen if it scores more than 2x better in other metrics. The /// value is expressed in 1/1000 increments, i.e. 1000 = 1.0, 500 = 0.5 and 1 = 0.001 - #[serde(default = "default_metric_factor")] - pub metric_factor: u32, + pub metric_factor: Option, /// The static IP used on mesh interfaces #[serde(skip_serializing_if = "Option::is_none")] pub mesh_ip: Option, @@ -50,6 +88,9 @@ pub struct NetworkSettings { #[serde(default = "default_discovery_ip")] pub discovery_ip: Ipv6Addr, /// Port on which we connect to a local babel instance (read-write connection required) + /// this is not in the babeld_settings section because everything else in that section is applied + /// and communicated to babel, this value is only used by rita and must be pre-configured in babel + /// as it can't be changed after startup pub babel_port: u16, /// Port on which rita starts the per hop tunnel handshake on (needs to be constant across an /// entire althea deployment) @@ -122,7 +163,7 @@ impl Default for NetworkSettings { NetworkSettings { shaper_settings: default_shaper_settings(), backup_created: false, - metric_factor: default_metric_factor(), + metric_factor: None, mesh_ip: None, mesh_ip_v2: None, discovery_ip: default_discovery_ip(), @@ -146,6 +187,7 @@ impl Default for NetworkSettings { user_bandwidth_limit: None, allowed_countries: default_allowed_countries(), payment_chains: HashSet::new(), + babeld_settings: default_babeld_config(), } } } diff --git a/settings/src/payment.rs b/settings/src/payment.rs index d7d69c5a6..9322db267 100644 --- a/settings/src/payment.rs +++ b/settings/src/payment.rs @@ -7,11 +7,8 @@ use num256::Int256; use num256::Uint256; use std::collections::HashMap; -fn default_local_fee() -> u32 { - 0u32 // updated by oracle, denominated in wei/byte -} fn default_max_fee() -> u32 { - 200_000_000u32 // updated by oracle denominated in wei + 200_000_000u32 // denominated in wei/byte } fn default_free_tier_throughput() -> u32 { @@ -91,8 +88,7 @@ fn default_node_grpc() -> Vec { pub struct PaymentSettings { /// What we charge other nodes, denominated in wei/byte, represented by a u32 because that is /// the field size of the price field in Babel - #[serde(default = "default_local_fee")] - pub local_fee: u32, + pub local_fee: Option, /// A price limit, we will not pay more than this #[serde(default = "default_max_fee")] pub max_fee: u32, @@ -173,7 +169,7 @@ pub struct PaymentSettings { impl Default for PaymentSettings { fn default() -> Self { PaymentSettings { - local_fee: default_local_fee(), + local_fee: None, max_fee: default_max_fee(), free_tier_throughput: default_free_tier_throughput(), client_can_use_free_tier: default_client_can_use_free_tier(),