Skip to content

Commit

Permalink
Wallet: use gossip to identify leader's port config
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 17, 2018
1 parent 04bfd5c commit cfb6968
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ 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;
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;

Expand Down Expand Up @@ -163,6 +167,30 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
)))
})?;

// 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);

Expand Down

0 comments on commit cfb6968

Please sign in to comment.