From c262e61622a4e0de278a117a34c564590b3df4d2 Mon Sep 17 00:00:00 2001 From: Martin Stefcek <35243812+Cifko@users.noreply.github.com> Date: Tue, 23 Nov 2021 16:30:59 +0100 Subject: [PATCH] chore: public_address for TCP node has higher priority from env/config (#3600) Description --- The tcp `public_address` read from env/config (if set) instead of `base_node_id.json`. I've added a comment to the newly generated `base_node_id.json` that this value is overwritten. I've chosen json5 so it's backwards compatible. How Has This Been Tested? --- Manually. --- Cargo.lock | 241 +++++++++++++----- applications/tari_app_utilities/Cargo.toml | 1 + .../src/identity_management.rs | 39 ++- applications/tari_base_node/src/bootstrap.rs | 12 +- .../tari_console_wallet/src/init/mod.rs | 5 +- common/src/configuration/global.rs | 11 +- common/src/configuration/utils.rs | 7 +- integration_tests/helpers/baseNodeProcess.js | 3 +- integration_tests/package-lock.json | 5 +- integration_tests/package.json | 1 + 10 files changed, 238 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec15c0129c..d1f677ff1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -23,7 +23,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -46,7 +46,7 @@ dependencies = [ "cfg-if 1.0.0", "cipher 0.3.0", "cpufeatures", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -84,7 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" dependencies = [ "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -94,7 +94,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" dependencies = [ "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -353,8 +353,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ "crypto-mac", - "digest", - "opaque-debug", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding 0.1.5", + "byte-tools", + "byteorder", + "generic-array 0.12.4", ] [[package]] @@ -363,8 +375,8 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", - "generic-array", + "block-padding 0.2.1", + "generic-array 0.14.4", ] [[package]] @@ -373,7 +385,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f337a3e6da609650eb74e02bc9fac7b735049f7623ab12f2e4c719316fcc7e80" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -383,7 +395,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c9b14fd8a4739e6548d4b6018696cf991dcf8c6effd9ef9eb33b29b8a650972" dependencies = [ "block-cipher", - "block-padding", + "block-padding 0.2.1", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", ] [[package]] @@ -400,7 +421,7 @@ checksum = "32fa6a061124e37baba002e496d203e23ba3d7b73750be82dbfbc92913048a5b" dependencies = [ "byteorder", "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -443,6 +464,12 @@ version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + [[package]] name = "bytemuck" version = "1.7.2" @@ -505,7 +532,7 @@ checksum = "1285caf81ea1f1ece6b24414c521e625ad0ec94d880625c20f2e65d8d3f78823" dependencies = [ "byteorder", "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -624,7 +651,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -633,7 +660,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -980,7 +1007,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array", + "generic-array 0.14.4", "subtle", ] @@ -1046,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", - "digest", + "digest 0.9.0", "rand_core 0.5.1", "serde 1.0.130", "subtle", @@ -1060,7 +1087,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" dependencies = [ "byteorder", - "digest", + "digest 0.9.0", "packed_simd_2", "rand_core 0.6.3", "serde 1.0.130", @@ -1196,7 +1223,7 @@ checksum = "b24e7c748888aa2fa8bce21d8c64a52efc810663285315ac7476f7197a982fae" dependencies = [ "byteorder", "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -1238,13 +1265,22 @@ dependencies = [ "migrations_macros", ] +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.4", +] + [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -1395,6 +1431,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "887dc6b1e1f9ef25ac52649e19ce610a2520b4c55b48429030782b6c8a70e78a" +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + [[package]] name = "fast-float" version = "0.2.0" @@ -1692,6 +1734,15 @@ version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + [[package]] name = "generic-array" version = "0.14.4" @@ -1752,7 +1803,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" dependencies = [ - "opaque-debug", + "opaque-debug 0.3.0", "polyval 0.4.5", ] @@ -1762,7 +1813,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" dependencies = [ - "opaque-debug", + "opaque-debug 0.3.0", "polyval 0.5.3", ] @@ -1839,7 +1890,7 @@ dependencies = [ "http", "httpdate", "mime", - "sha-1", + "sha-1 0.9.8", ] [[package]] @@ -2091,6 +2142,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb2522ff59fbfefb955e9bd44d04d5e5c2d0e8865bfc2c3d1ab3916183ef5ee" +dependencies = [ + "pest", + "pest_derive", + "serde 1.0.130", +] + [[package]] name = "jsonrpc" version = "0.12.0" @@ -2342,6 +2404,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matchers" version = "0.0.1" @@ -2363,9 +2431,9 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15" dependencies = [ - "block-buffer", - "digest", - "opaque-debug", + "block-buffer 0.9.0", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -2505,7 +2573,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "752a61cd890ff691b4411423d23816d5866dd5621e4d1c5687a53b94b5a979d8" dependencies = [ - "generic-array", + "generic-array 0.14.4", "multihash-derive", "unsigned-varint", ] @@ -2787,6 +2855,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -3029,6 +3103,40 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.81", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1 0.8.2", +] + [[package]] name = "petgraph" version = "0.5.1" @@ -3049,7 +3157,7 @@ dependencies = [ "base64 0.12.3", "bitfield", "block-modes", - "block-padding", + "block-padding 0.2.1", "blowfish", "buf_redux", "byteorder", @@ -3062,10 +3170,10 @@ dependencies = [ "crc24", "derive_builder", "des", - "digest", + "digest 0.9.0", "ed25519-dalek", "flate2", - "generic-array", + "generic-array 0.14.4", "hex", "lazy_static 1.4.0", "log", @@ -3077,7 +3185,7 @@ dependencies = [ "rand 0.7.3", "ripemd160", "rsa", - "sha-1", + "sha-1 0.9.8", "sha2", "sha3", "signature", @@ -3154,7 +3262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" dependencies = [ "cpufeatures", - "opaque-debug", + "opaque-debug 0.3.0", "universal-hash", ] @@ -3165,7 +3273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" dependencies = [ "cpuid-bool", - "opaque-debug", + "opaque-debug 0.3.0", "universal-hash", ] @@ -3177,7 +3285,7 @@ checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "opaque-debug", + "opaque-debug 0.3.0", "universal-hash", ] @@ -3665,9 +3773,9 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" dependencies = [ - "block-buffer", - "digest", - "opaque-debug", + "block-buffer 0.9.0", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -3708,7 +3816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3648b669b10afeab18972c105e284a7b953a669b0be3514c27f9b17acab2f9cd" dependencies = [ "byteorder", - "digest", + "digest 0.9.0", "lazy_static 1.4.0", "num-bigint-dig", "num-integer", @@ -4039,17 +4147,29 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + [[package]] name = "sha-1" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", - "opaque-debug", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -4058,11 +4178,11 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", - "opaque-debug", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -4071,10 +4191,10 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" dependencies = [ - "block-buffer", - "digest", + "block-buffer 0.9.0", + "digest 0.9.0", "keccak", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -4415,6 +4535,7 @@ dependencies = [ "config", "dirs-next 1.0.2", "futures 0.3.17", + "json5", "log", "qrcode", "rand 0.8.4", @@ -4484,7 +4605,7 @@ dependencies = [ "byteorder", "clear_on_drop", "curve25519-dalek-ng", - "digest", + "digest 0.9.0", "merlin", "rand 0.8.4", "rand_core 0.6.3", @@ -4534,7 +4655,7 @@ dependencies = [ name = "tari_common_types" version = "0.21.2" dependencies = [ - "digest", + "digest 0.9.0", "futures 0.3.17", "lazy_static 1.4.0", "rand 0.8.4", @@ -4557,7 +4678,7 @@ dependencies = [ "cidr", "clear_on_drop", "data-encoding", - "digest", + "digest 0.9.0", "env_logger 0.7.1", "futures 0.3.17", "lazy_static 1.4.0", @@ -4606,7 +4727,7 @@ dependencies = [ "clap", "diesel", "diesel_migrations", - "digest", + "digest 0.9.0", "env_logger 0.7.1", "futures 0.3.17", "futures-test", @@ -4664,7 +4785,7 @@ dependencies = [ "bitflags 1.3.2", "chrono", "crossterm 0.17.7", - "digest", + "digest 0.9.0", "futures 0.3.17", "log", "opentelemetry", @@ -4714,7 +4835,7 @@ dependencies = [ "croaring", "decimal-rs", "derive_more", - "digest", + "digest 0.9.0", "env_logger 0.7.1", "fs2", "futures 0.3.17", @@ -4768,7 +4889,7 @@ dependencies = [ "cbindgen", "clear_on_drop", "curve25519-dalek-ng", - "digest", + "digest 0.9.0", "lazy_static 1.4.0", "merlin", "rand 0.8.4", @@ -4803,7 +4924,7 @@ dependencies = [ "chrono", "clear_on_drop", "crc32fast", - "digest", + "digest 0.9.0", "rand 0.8.4", "sha2", "strum 0.22.0", @@ -4896,7 +5017,7 @@ dependencies = [ "blake2", "criterion", "croaring", - "digest", + "digest 0.9.0", "log", "rand 0.8.4", "serde 1.0.130", @@ -5093,7 +5214,7 @@ dependencies = [ "crossbeam-channel 0.3.9", "diesel", "diesel_migrations", - "digest", + "digest 0.9.0", "env_logger 0.7.1", "fs2", "futures 0.3.17", @@ -5747,7 +5868,7 @@ dependencies = [ "httparse", "log", "rand 0.8.4", - "sha-1", + "sha-1 0.9.8", "thiserror", "url 2.2.2", "utf-8", @@ -5761,7 +5882,7 @@ checksum = "0028f5982f23ecc9a1bc3008ead4c664f843ed5d78acd3d213b99ff50c441bc2" dependencies = [ "byteorder", "cipher 0.2.5", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -5866,7 +5987,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array", + "generic-array 0.14.4", "subtle", ] diff --git a/applications/tari_app_utilities/Cargo.toml b/applications/tari_app_utilities/Cargo.toml index a943e35544..ae6d9c9d1f 100644 --- a/applications/tari_app_utilities/Cargo.toml +++ b/applications/tari_app_utilities/Cargo.toml @@ -16,6 +16,7 @@ futures = { version = "^0.3.16", default-features = false, features = ["alloc"] qrcode = { version = "0.12" } dirs-next = "1.0.2" serde_json = "1.0" +json5 = "0.2.2" log = { version = "0.4.8", features = ["std"] } rand = "0.8" tokio = { version = "1.11", features = ["signal"] } diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index f8bb2893d7..7dc6458b5f 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -22,8 +22,11 @@ use log::*; use rand::rngs::OsRng; -use std::{clone::Clone, fs, path::Path, string::ToString, sync::Arc}; -use tari_common::{configuration::bootstrap::prompt, exit_codes::ExitCodes}; +use std::{clone::Clone, fs, path::Path, str::FromStr, string::ToString, sync::Arc}; +use tari_common::{ + configuration::{bootstrap::prompt, utils::get_local_ip}, + exit_codes::ExitCodes, +}; use tari_common_types::types::PrivateKey; use tari_comms::{multiaddr::Multiaddr, peer_manager::PeerFeatures, NodeIdentity}; use tari_crypto::{ @@ -44,12 +47,18 @@ pub const LOG_TARGET: &str = "tari_application"; /// A NodeIdentity wrapped in an atomic reference counter on success, the exit code indicating the reason on failure pub fn setup_node_identity>( identity_file: P, - public_address: &Multiaddr, + public_address: &Option, create_id: bool, peer_features: PeerFeatures, ) -> Result, ExitCodes> { match load_identity(&identity_file) { - Ok(id) => Ok(Arc::new(id)), + Ok(id) => match public_address { + Some(public_address) => { + id.set_public_address(public_address.clone()); + Ok(Arc::new(id)) + }, + None => Ok(Arc::new(id)), + }, Err(e) => { if !create_id { let prompt = prompt("Node identity does not exist.\nWould you like to to create one (Y/n)?"); @@ -117,7 +126,7 @@ pub fn load_identity>(path: P) -> Result { e.to_string() ) })?; - let id = NodeIdentity::from_json(&id_str).map_err(|e| { + let id = json5::from_str::(&id_str).map_err(|e| { format!( "The node identity file, {}, has an error. {}", path.as_ref().to_str().unwrap_or("?"), @@ -141,11 +150,20 @@ pub fn load_identity>(path: P) -> Result { /// Result containing the node identity, string will indicate reason on error pub fn create_new_identity>( path: P, - public_addr: Multiaddr, + public_addr: Option, features: PeerFeatures, ) -> Result { let private_key = PrivateKey::random(&mut OsRng); - let node_identity = NodeIdentity::new(private_key, public_addr, features); + let node_identity = NodeIdentity::new( + private_key, + match public_addr { + Some(public_addr) => public_addr, + None => format!("{}/tcp/18141", get_local_ip().ok_or("Can't get local ip address")?) + .parse() + .map_err(|e: ::Err| e.to_string())?, + }, + features, + ); save_as_json(path, &node_identity)?; Ok(node_identity) } @@ -203,7 +221,12 @@ pub fn save_as_json, T: MessageFormat>(path: P, object: &T) -> Re fs::create_dir_all(p).map_err(|e| format!("Could not save json to data folder. {}", e.to_string()))?; } } - fs::write(path.as_ref(), json.as_bytes()).map_err(|e| { + let json_with_comment = format!( + "// The public address is overwritten by the config/environment variable \ + (TARI_BASE_NODE____PUBLIC_ADDRESS)\n{}", + json + ); + fs::write(path.as_ref(), json_with_comment.as_bytes()).map_err(|e| { format!( "Error writing json file, {}. {}", path.as_ref().to_str().unwrap_or(""), diff --git a/applications/tari_base_node/src/bootstrap.rs b/applications/tari_base_node/src/bootstrap.rs index 94f00af43e..516e93d2f1 100644 --- a/applications/tari_base_node/src/bootstrap.rs +++ b/applications/tari_base_node/src/bootstrap.rs @@ -58,6 +58,7 @@ use tari_p2p::{ initialization::{P2pConfig, P2pInitializer}, peer_seeds::SeedPeer, services::liveness::{LivenessConfig, LivenessInitializer}, + transport::TransportType, }; use tari_service_framework::{ServiceHandles, StackBuilder}; use tari_shutdown::ShutdownSignal; @@ -184,11 +185,16 @@ where B: BlockchainBackend + 'static let comms = comms.add_protocol_extension(mempool_protocol); let comms = Self::setup_rpc_services(comms, &handles, self.db.into(), config); - let comms = initialization::spawn_comms_using_transport(comms, transport_type).await?; + let comms = initialization::spawn_comms_using_transport(comms, transport_type.clone()).await?; // Save final node identity after comms has initialized. This is required because the public_address can be // changed by comms during initialization when using tor. - identity_management::save_as_json(&config.base_node_identity_file, &*comms.node_identity()) - .map_err(|e| anyhow!("Failed to save node identity: {:?}", e))?; + match transport_type { + TransportType::Tcp { .. } => {}, // Do not overwrite TCP public_address in the base_node_id! + _ => { + identity_management::save_as_json(&config.base_node_identity_file, &*comms.node_identity()) + .map_err(|e| anyhow!("Failed to save node identity: {:?}", e))?; + }, + }; if let Some(hs) = comms.hidden_service() { identity_management::save_as_json(&config.base_node_tor_identity_file, hs.tor_identity()) .map_err(|e| anyhow!("Failed to save tor identity: {:?}", e))?; diff --git a/applications/tari_console_wallet/src/init/mod.rs b/applications/tari_console_wallet/src/init/mod.rs index 0cb9d96338..f974ed4b9f 100644 --- a/applications/tari_console_wallet/src/init/mod.rs +++ b/applications/tari_console_wallet/src/init/mod.rs @@ -299,7 +299,10 @@ pub async fn init_wallet( ); let node_address = match wallet_db.get_node_address().await? { - None => config.public_address.clone(), + None => config + .public_address + .clone() + .ok_or_else(|| ExitCodes::ConfigError("node public address error".to_string()))?, Some(a) => a, }; diff --git a/common/src/configuration/global.rs b/common/src/configuration/global.rs index 990b9acd13..04086be1f0 100644 --- a/common/src/configuration/global.rs +++ b/common/src/configuration/global.rs @@ -75,7 +75,7 @@ pub struct GlobalConfig { pub pruned_mode_cleanup_interval: u64, pub core_threads: Option, pub base_node_identity_file: PathBuf, - pub public_address: Multiaddr, + pub public_address: Option, pub grpc_enabled: bool, pub grpc_base_node_address: Multiaddr, pub grpc_console_wallet_address: Multiaddr, @@ -328,13 +328,12 @@ fn convert_node_config( // Public address let key = config_string("base_node", net_str, "public_address"); - let public_address = cfg - .get_str(&key) - .map_err(|e| ConfigurationError::new(&key, &e.to_string())) - .and_then(|addr| { + let public_address = optional(cfg.get_str(&key))? + .map(|addr| { addr.parse::() .map_err(|e| ConfigurationError::new(&key, &e.to_string())) - })?; + }) + .transpose()?; // GPRC enabled let key = config_string("base_node", net_str, "grpc_enabled"); diff --git a/common/src/configuration/utils.rs b/common/src/configuration/utils.rs index 1c1f59c38a..7b0f2c4cf0 100644 --- a/common/src/configuration/utils.rs +++ b/common/src/configuration/utils.rs @@ -226,11 +226,6 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config { default_subdir("config/base_node_id.json", Some(&bootstrap.base_path)), ) .unwrap(); - cfg.set_default( - "base_node.weatherwax.public_address", - format!("{}/tcp/18141", local_ip_addr), - ) - .unwrap(); cfg.set_default("base_node.weatherwax.allow_test_addresses", false) .unwrap(); @@ -435,7 +430,7 @@ fn set_transport_defaults(cfg: &mut Config) -> Result<(), config::ConfigError> { Ok(()) } -fn get_local_ip() -> Option { +pub fn get_local_ip() -> Option { use std::net::IpAddr; get_if_addrs::get_if_addrs().ok().and_then(|if_addrs| { diff --git a/integration_tests/helpers/baseNodeProcess.js b/integration_tests/helpers/baseNodeProcess.js index 097285d607..4de9f1e79e 100644 --- a/integration_tests/helpers/baseNodeProcess.js +++ b/integration_tests/helpers/baseNodeProcess.js @@ -6,6 +6,7 @@ const BaseNodeClient = require("./baseNodeClient"); const { getFreePort } = require("./util"); const dateFormat = require("dateformat"); const { createEnv } = require("./config"); +const JSON5 = require("json5"); let outputProcess; class BaseNodeProcess { @@ -78,7 +79,7 @@ class BaseNodeProcess { } } - this.nodeInfo = JSON.parse( + this.nodeInfo = JSON5.parse( fs.readFileSync(this.baseDir + "/" + this.nodeFile, "utf8") ); } diff --git a/integration_tests/package-lock.json b/integration_tests/package-lock.json index 059a7730c4..90c7663a38 100644 --- a/integration_tests/package-lock.json +++ b/integration_tests/package-lock.json @@ -17,6 +17,7 @@ "dateformat": "^3.0.3", "glob": "^7.2.0", "hex64": "^0.4.0", + "json5": "^2.2.0", "jszip": "^3.7.1", "nvm": "^0.0.4", "sha3": "^2.1.3", @@ -2964,8 +2965,8 @@ }, "node_modules/json5": { "version": "2.2.0", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", - "dev": true, "dependencies": { "minimist": "^1.2.5" }, @@ -6495,8 +6496,8 @@ }, "json5": { "version": "2.2.0", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", - "dev": true, "requires": { "minimist": "^1.2.5" } diff --git a/integration_tests/package.json b/integration_tests/package.json index 7c040ec972..539b4771e8 100644 --- a/integration_tests/package.json +++ b/integration_tests/package.json @@ -46,6 +46,7 @@ "dateformat": "^3.0.3", "glob": "^7.2.0", "hex64": "^0.4.0", + "json5": "^2.2.0", "jszip": "^3.7.1", "nvm": "^0.0.4", "sha3": "^2.1.3",