Skip to content

Commit

Permalink
multi host client demo
Browse files Browse the repository at this point in the history
Bind to the same interface as the user supplied client address.
  • Loading branch information
aeyakovenko committed May 3, 2018
1 parent 62a6051 commit 21dffad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/accountant_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl AccountantStub {
let subscriptions = vec![Subscription::EntryInfo];
let req = Request::Subscribe { subscriptions };
let data = serialize(&req).expect("serialize Subscribe");
trace!("subscribing to {}", self.addr);
let _res = self.socket.send_to(&data, &self.addr);
}

Expand Down Expand Up @@ -114,6 +115,7 @@ impl AccountantStub {
pub fn get_last_id(&mut self) -> FutureResult<Hash, ()> {
let req = Request::GetLastId;
let data = serialize(&req).expect("serialize GetId");
assert!(data.len() < 4096);
self.socket
.send_to(&data, &self.addr)
.expect("buffer error");
Expand Down
17 changes: 10 additions & 7 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use solana::signature::{KeyPair, KeyPairUtil};
use solana::transaction::Transaction;
use std::env;
use std::io::{stdin, Read};
use std::net::UdpSocket;
use std::net::{SocketAddr, UdpSocket};
use std::process::exit;
use std::time::Instant;
use untrusted::Input;
Expand All @@ -33,7 +33,7 @@ fn print_usage(program: &str, opts: Options) {
fn main() {
let mut threads = 4usize;
let mut addr: String = "127.0.0.1:8000".to_string();
let mut send_addr: String = "127.0.0.1:8001".to_string();
let mut client_addr: String = "127.0.0.1:8001".to_string();

let mut opts = Options::new();
opts.optopt("s", "", "server address", "host:port");
Expand All @@ -58,7 +58,7 @@ fn main() {
addr = matches.opt_str("s").unwrap();
}
if matches.opt_present("c") {
send_addr = matches.opt_str("c").unwrap();
client_addr = matches.opt_str("c").unwrap();
}
if matches.opt_present("t") {
threads = matches.opt_str("t").unwrap().parse().expect("integer");
Expand All @@ -82,11 +82,13 @@ fn main() {
exit(1);
});

let socket = UdpSocket::bind(&send_addr).unwrap();
println!("Binding to {}", client_addr);
let socket = UdpSocket::bind(&client_addr).unwrap();
let mut acc = AccountantStub::new(&addr, socket);

println!("Get last ID...");
let last_id = acc.get_last_id().wait().unwrap();
println!("Got last ID {:?}", last_id);

println!("Creating keypairs...");
let txs = demo.users.len() / 2;
Expand Down Expand Up @@ -119,9 +121,10 @@ fn main() {
let sz = transactions.len() / threads;
let chunks: Vec<_> = transactions.chunks(sz).collect();
chunks.into_par_iter().for_each(|trs| {
println!("Transferring 1 unit {} times...", trs.len());
let send_addr = "0.0.0.0:0";
let socket = UdpSocket::bind(send_addr).unwrap();
println!("Transferring 1 unit {} times... to", trs.len());
let mut client_addr: SocketAddr = client_addr.parse().unwrap();
client_addr.set_port(0);
let socket = UdpSocket::bind(client_addr).unwrap();
let acc = AccountantStub::new(&addr, socket);
for tr in trs {
acc.transfer_signed(tr.clone()).unwrap();
Expand Down

0 comments on commit 21dffad

Please sign in to comment.