Skip to content

Commit

Permalink
fix: allow public addresses from command line (#5303)
Browse files Browse the repository at this point in the history
Description
---
Add `from_str` to `public_addresses` so it can now be set via command
line or envvar.


How Has This Been Tested?
---
There are cargo test and also manually.

What process can a PR reviewer use to test or verify this change?
---
You can set `public_addresses` via commandline.

Fixes: #5260 

Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
Cifko authored Apr 13, 2023
1 parent 449027d commit 349ac89
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 23 deletions.
2 changes: 1 addition & 1 deletion applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn main_inner() -> Result<(), ExitError> {
// Load or create the Node identity
let node_identity = setup_node_identity(
&config.base_node.identity_file,
config.base_node.p2p.public_addresses.clone(),
config.base_node.p2p.public_addresses.clone().into_vec(),
cli.non_interactive_mode || cli.init,
PeerFeatures::COMMUNICATION_NODE,
)?;
Expand Down
14 changes: 10 additions & 4 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use tari_app_utilities::identity_management::setup_node_identity;
use tari_common::{
configuration::{
bootstrap::{grpc_default_port, prompt, ApplicationType},
MultiaddrList,
Network,
},
exit_codes::{ExitCode, ExitError},
Expand Down Expand Up @@ -378,8 +379,8 @@ pub async fn init_wallet(

let node_addresses = if config.wallet.p2p.public_addresses.is_empty() {
match wallet_db.get_node_address()? {
Some(addr) => vec![addr],
None => vec![],
Some(addr) => MultiaddrList::from(vec![addr]),
None => MultiaddrList::default(),
}
} else {
config.wallet.p2p.public_addresses.clone()
Expand All @@ -394,9 +395,14 @@ pub async fn init_wallet(
"Node identity overridden by file {}",
identity_file.to_string_lossy()
);
setup_node_identity(identity_file, node_addresses, true, PeerFeatures::COMMUNICATION_CLIENT)?
setup_node_identity(
identity_file,
node_addresses.to_vec(),
true,
PeerFeatures::COMMUNICATION_CLIENT,
)?
},
None => setup_identity_from_db(&wallet_db, &master_seed, node_addresses)?,
None => setup_identity_from_db(&wallet_db, &master_seed, node_addresses.to_vec())?,
};

let mut wallet_config = config.wallet.clone();
Expand Down
4 changes: 2 additions & 2 deletions base_layer/contacts/tests/contacts_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::{convert::TryInto, sync::Arc, time::Duration};

use rand::rngs::OsRng;
use tari_common::configuration::{Network, StringList};
use tari_common::configuration::{MultiaddrList, Network, StringList};
use tari_common_sqlite::connection::{DbConnection, DbConnectionUrl};
use tari_common_types::{tari_address::TariAddress, types::PublicKey};
use tari_comms::{peer_manager::PeerFeatures, NodeIdentity};
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn setup_contacts_service<T: ContactsBackend + 'static>(
));
let comms_config = P2pConfig {
override_from: None,
public_addresses: vec![],
public_addresses: MultiaddrList::default(),
transport: TransportConfig {
transport_type: TransportType::Memory,
memory: MemoryTransportConfig {
Expand Down
5 changes: 3 additions & 2 deletions base_layer/p2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tari_common::{
configuration::{
serializers,
utils::{deserialize_string_or_struct, serialize_string},
MultiaddrList,
StringList,
},
DnsNameServer,
Expand Down Expand Up @@ -87,7 +88,7 @@ pub struct P2pConfig {
/// The public address advertised to other peers by this node. If not set it will be set automatically depending on
/// the transport type. The TCP transport is not able to determine the users public IP, so this will need to be
/// manually set.
pub public_addresses: Vec<Multiaddr>,
pub public_addresses: MultiaddrList,
/// Transport configuration
pub transport: TransportConfig,
/// Path to the LMDB data files.
Expand Down Expand Up @@ -132,7 +133,7 @@ impl Default for P2pConfig {
fn default() -> Self {
Self {
override_from: None,
public_addresses: vec![],
public_addresses: MultiaddrList::default(),
transport: Default::default(),
datastore_path: PathBuf::from("peer_db"),
peer_database_name: "peers".to_string(),
Expand Down
6 changes: 3 additions & 3 deletions base_layer/wallet/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{mem::size_of, panic, path::Path, sync::Arc, time::Duration};
use chacha20poly1305::{Key, KeyInit, XChaCha20Poly1305};
use rand::{rngs::OsRng, RngCore};
use support::utils::make_input;
use tari_common::configuration::StringList;
use tari_common::configuration::{MultiaddrList, StringList};
use tari_common_types::{
chain_metadata::ChainMetadata,
tari_address::TariAddress,
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn create_wallet(
let node_identity = NodeIdentity::random(&mut OsRng, get_next_memory_address(), PeerFeatures::COMMUNICATION_NODE);
let comms_config = P2pConfig {
override_from: None,
public_addresses: vec![],
public_addresses: MultiaddrList::default(),
transport: TransportConfig::new_memory(MemoryTransportConfig {
listener_address: node_identity.first_public_address(),
}),
Expand Down Expand Up @@ -669,7 +669,7 @@ async fn test_import_utxo() {
let (connection, _temp_dir) = make_wallet_database_connection(None);
let comms_config = P2pConfig {
override_from: None,
public_addresses: vec![],
public_addresses: MultiaddrList::default(),
transport: TransportConfig::new_tcp(TcpTransportConfig {
listener_address: "/ip4/127.0.0.1/tcp/0".parse().unwrap(),
tor_socks_address: None,
Expand Down
12 changes: 6 additions & 6 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use log4rs::{
};
use num_traits::FromPrimitive;
use rand::rngs::OsRng;
use tari_common::configuration::StringList;
use tari_common::configuration::{MultiaddrList, StringList};
use tari_common_types::{
emoji::emoji_set,
tari_address::{TariAddress, TariAddressError},
Expand Down Expand Up @@ -4772,9 +4772,9 @@ pub unsafe extern "C" fn comms_config_create(
match public_address {
Ok(public_address) => {
let addresses = if (*transport).transport_type == TransportType::Tor {
vec![]
MultiaddrList::default()
} else {
vec![public_address]
MultiaddrList::from(vec![public_address])
};

let config = TariCommsConfig {
Expand Down Expand Up @@ -5294,8 +5294,8 @@ pub unsafe extern "C" fn wallet_create(
let node_features = wallet_database.get_node_features()?.unwrap_or_default();
let node_addresses = if comms_config.public_addresses.is_empty() {
match wallet_database.get_node_address()? {
Some(addr) => vec![addr],
None => vec![],
Some(addr) => MultiaddrList::from(vec![addr]),
None => MultiaddrList::default(),
}
} else {
comms_config.public_addresses.clone()
Expand All @@ -5316,7 +5316,7 @@ pub unsafe extern "C" fn wallet_create(
// SAFETY: we are manually checking the validity of this signature before adding Some(..)
let node_identity = Arc::new(NodeIdentity::with_signature_unchecked(
comms_secret_key,
node_addresses,
node_addresses.to_vec(),
node_features,
identity_sig,
));
Expand Down
2 changes: 2 additions & 0 deletions common/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub mod loader;
mod network;
pub use network::Network;
mod common_config;
mod multiaddr_list;
pub mod name_server;
pub mod serializers;
mod string_list;
Expand All @@ -52,6 +53,7 @@ use std::{iter::FromIterator, net::SocketAddr};

pub use common_config::CommonConfig;
use multiaddr::{Error, Multiaddr, Protocol};
pub use multiaddr_list::MultiaddrList;
pub use string_list::StringList;

/// Interpret a string as either a socket address (first) or a multiaddr format string.
Expand Down
Loading

0 comments on commit 349ac89

Please sign in to comment.