Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow public addresses from command line #5303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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