diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index 905197dfaaff12..2e5552574e022f 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -25,7 +25,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; use std::thread::sleep; -use std::time::Duration; +use std::time::{Duration, Instant}; enum WalletCommand { Address, @@ -39,6 +39,7 @@ enum WalletCommand { enum WalletError { CommandNotRecognized(String), BadParameter(String), + NoNode(String), } impl fmt::Display for WalletError { @@ -184,8 +185,13 @@ fn parse_args() -> Result> { let leader_entry_point = NodeInfo::new_entry_point(leader.contact_info.ncp); crdt.write().unwrap().insert(&leader_entry_point); + let now = Instant::now(); // Block until leader's correct contact info is received - while crdt.read().unwrap().leader_data().is_none() {} + while crdt.read().unwrap().leader_data().is_none() { + if now.elapsed() > Duration::new(10, 0) { + Err(WalletError::NoNode("No leader detected".to_string()))?; + } + } exit.store(true, Ordering::Relaxed); ncp.join().unwrap();