Skip to content

Commit

Permalink
Refactor the "ReplicatedData" struct
Browse files Browse the repository at this point in the history
Rename the "ReplicatedData" struct to the "NodeInfo" struct.
Also refactors and renames the members in this struct.
  • Loading branch information
carllin authored and garious committed Jul 11, 2018
1 parent 705720f commit 468ac9f
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 134 deletions.
22 changes: 11 additions & 11 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate solana;
use bincode::serialize;
use clap::{App, Arg};
use rayon::prelude::*;
use solana::crdt::{Crdt, ReplicatedData};
use solana::crdt::{Crdt, NodeInfo};
use solana::drone::DroneRequest;
use solana::fullnode::Config;
use solana::hash::Hash;
Expand Down Expand Up @@ -38,7 +38,7 @@ fn sample_tx_count(
exit: Arc<AtomicBool>,
maxes: Arc<RwLock<Vec<(f64, u64)>>>,
first_count: u64,
v: ReplicatedData,
v: NodeInfo,
sample_period: u64,
) {
let mut client = mk_client(&v);
Expand Down Expand Up @@ -79,7 +79,7 @@ fn generate_and_send_txs(
tx_clients: &Vec<ThinClient>,
id: &Mint,
keypairs: &Vec<KeyPair>,
leader: &ReplicatedData,
leader: &NodeInfo,
txs: i64,
last_id: &mut Hash,
threads: usize,
Expand Down Expand Up @@ -185,12 +185,12 @@ fn main() {
)
.get_matches();

let leader: ReplicatedData;
let leader: NodeInfo;
if let Some(l) = matches.value_of("leader") {
leader = read_leader(l.to_string()).node_info;
} else {
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
leader = ReplicatedData::new_leader(&server_addr);
leader = NodeInfo::new_leader(&server_addr);
};

let id: Mint;
Expand Down Expand Up @@ -319,7 +319,7 @@ fn main() {
}
}

fn mk_client(r: &ReplicatedData) -> ThinClient {
fn mk_client(r: &NodeInfo) -> ThinClient {
let requests_socket = udp_random_bind(8000, 10000, 5).unwrap();
let transactions_socket = udp_random_bind(8000, 10000, 5).unwrap();

Expand All @@ -335,11 +335,11 @@ fn mk_client(r: &ReplicatedData) -> ThinClient {
)
}

fn spy_node() -> (ReplicatedData, UdpSocket) {
fn spy_node() -> (NodeInfo, UdpSocket) {
let gossip_socket_pair = udp_public_bind("gossip", 8000, 10000);
let pubkey = KeyPair::new().pubkey();
let daddr = "0.0.0.0:0".parse().unwrap();
let node = ReplicatedData::new(
let node = NodeInfo::new(
pubkey,
//gossip.local_addr().unwrap(),
gossip_socket_pair.addr,
Expand All @@ -352,11 +352,11 @@ fn spy_node() -> (ReplicatedData, UdpSocket) {
}

fn converge(
leader: &ReplicatedData,
leader: &NodeInfo,
exit: Arc<AtomicBool>,
num_nodes: usize,
threads: &mut Vec<JoinHandle<()>>,
) -> Vec<ReplicatedData> {
) -> Vec<NodeInfo> {
//lets spy on the network
let daddr = "0.0.0.0:0".parse().unwrap();
let (spy, spy_gossip) = spy_node();
Expand All @@ -376,7 +376,7 @@ fn converge(
let mut rv = vec![];
//wait for the network to converge, 30 seconds should be plenty
for _ in 0..30 {
let v: Vec<ReplicatedData> = spy_ref
let v: Vec<NodeInfo> = spy_ref
.read()
.unwrap()
.table
Expand Down
6 changes: 3 additions & 3 deletions src/bin/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate tokio_io;

use bincode::deserialize;
use clap::{App, Arg};
use solana::crdt::ReplicatedData;
use solana::crdt::NodeInfo;
use solana::drone::{Drone, DroneRequest};
use solana::fullnode::Config;
use solana::mint::Mint;
Expand Down Expand Up @@ -60,12 +60,12 @@ fn main() {
)
.get_matches();

let leader: ReplicatedData;
let leader: NodeInfo;
if let Some(l) = matches.value_of("leader") {
leader = read_leader(l.to_string()).node_info;
} else {
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
leader = ReplicatedData::new_leader(&server_addr);
leader = NodeInfo::new_leader(&server_addr);
};

let mint: Mint;
Expand Down
6 changes: 3 additions & 3 deletions src/bin/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate solana;

use atty::{is, Stream};
use clap::{App, Arg};
use solana::crdt::{ReplicatedData, TestNode};
use solana::crdt::{NodeInfo, TestNode};
use solana::fullnode::{Config, FullNode, InFile, OutFile};
use solana::service::Service;
use solana::signature::{KeyPair, KeyPairUtil};
Expand Down Expand Up @@ -52,7 +52,7 @@ fn main() -> () {

let bind_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
let mut keypair = KeyPair::new();
let mut repl_data = ReplicatedData::new_leader_with_pubkey(keypair.pubkey(), &bind_addr);
let mut repl_data = NodeInfo::new_leader_with_pubkey(keypair.pubkey(), &bind_addr);
if let Some(l) = matches.value_of("identity") {
let path = l.to_string();
if let Ok(file) = File::open(path.clone()) {
Expand Down Expand Up @@ -82,7 +82,7 @@ fn main() -> () {
None,
)
} else {
node.data.current_leader_id = node.data.id.clone();
node.data.leader_id = node.data.id.clone();

let outfile = if let Some(o) = matches.value_of("output") {
OutFile::Path(o.to_string())
Expand Down
12 changes: 6 additions & 6 deletions src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate solana;

use bincode::serialize;
use clap::{App, Arg, SubCommand};
use solana::crdt::ReplicatedData;
use solana::crdt::NodeInfo;
use solana::drone::DroneRequest;
use solana::fullnode::Config;
use solana::mint::Mint;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl error::Error for WalletError {
}

struct WalletConfig {
leader: ReplicatedData,
leader: NodeInfo,
id: Mint,
drone_addr: SocketAddr,
command: WalletCommand,
Expand All @@ -66,7 +66,7 @@ impl Default for WalletConfig {
fn default() -> WalletConfig {
let default_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
WalletConfig {
leader: ReplicatedData::new_leader(&default_addr.clone()),
leader: NodeInfo::new_leader(&default_addr.clone()),
id: Mint::new(0),
drone_addr: default_addr.clone(),
command: WalletCommand::Balance,
Expand Down Expand Up @@ -141,12 +141,12 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
.subcommand(SubCommand::with_name("address").about("Get your public key"))
.get_matches();

let leader: ReplicatedData;
let leader: NodeInfo;
if let Some(l) = matches.value_of("leader") {
leader = read_leader(l.to_string()).node_info;
} else {
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
leader = ReplicatedData::new_leader(&server_addr);
leader = NodeInfo::new_leader(&server_addr);
};

let id: Mint;
Expand Down Expand Up @@ -298,7 +298,7 @@ fn read_mint(path: String) -> Result<Mint, Box<error::Error>> {
Ok(mint)
}

fn mk_client(r: &ReplicatedData) -> io::Result<ThinClient> {
fn mk_client(r: &NodeInfo) -> io::Result<ThinClient> {
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
requests_socket
Expand Down
8 changes: 4 additions & 4 deletions src/choose_gossip_peer_strategy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crdt::{CrdtError, ReplicatedData};
use crdt::{CrdtError, NodeInfo};
use rand::distributions::{Distribution, Weighted, WeightedChoice};
use rand::thread_rng;
use result::Result;
Expand All @@ -9,7 +9,7 @@ use std::collections::HashMap;
pub const DEFAULT_WEIGHT: u32 = 1;

pub trait ChooseGossipPeerStrategy {
fn choose_peer<'a>(&self, options: Vec<&'a ReplicatedData>) -> Result<&'a ReplicatedData>;
fn choose_peer<'a>(&self, options: Vec<&'a NodeInfo>) -> Result<&'a NodeInfo>;
}

pub struct ChooseRandomPeerStrategy<'a> {
Expand All @@ -27,7 +27,7 @@ impl<'a, 'b> ChooseRandomPeerStrategy<'a> {
}

impl<'a> ChooseGossipPeerStrategy for ChooseRandomPeerStrategy<'a> {
fn choose_peer<'b>(&self, options: Vec<&'b ReplicatedData>) -> Result<&'b ReplicatedData> {
fn choose_peer<'b>(&self, options: Vec<&'b NodeInfo>) -> Result<&'b NodeInfo> {
if options.is_empty() {
Err(CrdtError::TooSmall)?;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'a> ChooseWeightedPeerStrategy<'a> {
}

impl<'a> ChooseGossipPeerStrategy for ChooseWeightedPeerStrategy<'a> {
fn choose_peer<'b>(&self, options: Vec<&'b ReplicatedData>) -> Result<&'b ReplicatedData> {
fn choose_peer<'b>(&self, options: Vec<&'b NodeInfo>) -> Result<&'b NodeInfo> {
if options.len() < 1 {
Err(CrdtError::TooSmall)?;
}
Expand Down
Loading

0 comments on commit 468ac9f

Please sign in to comment.