From cfb696891cebbf5f51dbbdf036f15d1081def940 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Fri, 17 Aug 2018 15:42:23 -0600 Subject: [PATCH] Wallet: use gossip to identify leader's port config --- src/bin/wallet.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index d78c23389b463e..905197dfaaff12 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -9,10 +9,12 @@ extern crate solana; use clap::{App, Arg, SubCommand}; use solana::client::mk_client; -use solana::crdt::NodeInfo; +use solana::crdt::{Crdt, NodeInfo, TestNode}; use solana::drone::DRONE_PORT; use solana::fullnode::Config; use solana::logger; +use solana::ncp::Ncp; +use solana::service::Service; use solana::signature::{read_keypair, Keypair, KeypairUtil, Pubkey, Signature}; use solana::thin_client::ThinClient; use solana::wallet::request_airdrop; @@ -20,6 +22,8 @@ use std::error; use std::fmt; use std::fs::File; 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; @@ -163,6 +167,30 @@ fn parse_args() -> Result> { ))) })?; + // Set up gossip functionality + let exit = Arc::new(AtomicBool::new(false)); + let testnode = TestNode::new_localhost(); + let extra_data = testnode.data.clone(); + let crdt = Arc::new(RwLock::new(Crdt::new(extra_data).expect("Crdt::new"))); + let window = Arc::new(RwLock::new(vec![])); + let ncp = Ncp::new( + &crdt.clone(), + window, + None, + testnode.sockets.gossip, + testnode.sockets.gossip_send, + exit.clone(), + ).unwrap(); + let leader_entry_point = NodeInfo::new_entry_point(leader.contact_info.ncp); + crdt.write().unwrap().insert(&leader_entry_point); + + // Block until leader's correct contact info is received + while crdt.read().unwrap().leader_data().is_none() {} + + exit.store(true, Ordering::Relaxed); + ncp.join().unwrap(); + let leader = crdt.read().unwrap().leader_data().unwrap().clone(); + let mut drone_addr = leader.contact_info.tpu; drone_addr.set_port(DRONE_PORT);