Skip to content

Commit

Permalink
Add timeout to wallet gossip, in case of no leader up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 17, 2018
1 parent cfb6968 commit 6fdf076
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,6 +39,7 @@ enum WalletCommand {
enum WalletError {
CommandNotRecognized(String),
BadParameter(String),
NoNode(String),
}

impl fmt::Display for WalletError {
Expand Down Expand Up @@ -184,8 +185,13 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
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();
Expand Down

0 comments on commit 6fdf076

Please sign in to comment.