diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index e1a0b192a36930..92bc03e06e9db0 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -301,20 +301,18 @@ fn main() { } fn mk_client(r: &ReplicatedData) -> ThinClient { - let transactions_socket_pair = udp_public_bind("transactions"); - let requests_socket_pair = udp_public_bind("requests"); + let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); + let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); - requests_socket_pair - .receiver + requests_socket .set_read_timeout(Some(Duration::new(1, 0))) .unwrap(); ThinClient::new( r.requests_addr, - requests_socket_pair.sender, - requests_socket_pair.receiver, + requests_socket, r.transactions_addr, - transactions_socket_pair.sender, + transactions_socket, ) } diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index 6adc10a8a6f8f4..d290de898373e8 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -12,7 +12,6 @@ use clap::{App, Arg, SubCommand}; use solana::crdt::ReplicatedData; use solana::drone::DroneRequest; use solana::mint::Mint; -use solana::nat::udp_public_bind; use solana::signature::{PublicKey, Signature}; use solana::thin_client::ThinClient; use std::error; @@ -20,7 +19,7 @@ use std::fmt; use std::fs::File; use std::io; use std::io::prelude::*; -use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; +use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream, UdpSocket}; use std::process::exit; use std::thread::sleep; use std::time::Duration; @@ -288,19 +287,17 @@ fn read_mint(path: String) -> Result> { } fn mk_client(r: &ReplicatedData) -> io::Result { - let transactions_socket_pair = udp_public_bind("transactions"); - let requests_socket_pair = udp_public_bind("requests"); - requests_socket_pair - .receiver + let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); + let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); + requests_socket .set_read_timeout(Some(Duration::new(1, 0))) .unwrap(); Ok(ThinClient::new( r.requests_addr, - requests_socket_pair.sender, - requests_socket_pair.receiver, + requests_socket, r.transactions_addr, - transactions_socket_pair.sender, + transactions_socket, )) } diff --git a/src/drone.rs b/src/drone.rs index 53c673c024d7e7..edf10392cf6699 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -99,7 +99,6 @@ impl Drone { let mut client = ThinClient::new( self.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, self.transactions_addr, transactions_socket, @@ -293,7 +292,6 @@ mod tests { let mut client = ThinClient::new( leader.data.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, leader.data.transactions_addr, transactions_socket, diff --git a/src/thin_client.rs b/src/thin_client.rs index f24067cccd5278..bdc25ea1ed1ab9 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -15,8 +15,7 @@ use transaction::Transaction; /// An object for querying and sending transactions to the network. pub struct ThinClient { requests_addr: SocketAddr, - requests_sender: UdpSocket, - requests_receiver: UdpSocket, + requests_socket: UdpSocket, transactions_addr: SocketAddr, transactions_socket: UdpSocket, last_id: Option, @@ -31,15 +30,13 @@ impl ThinClient { /// to a public address before invoking ThinClient methods. pub fn new( requests_addr: SocketAddr, - requests_sender: UdpSocket, - requests_receiver: UdpSocket, + requests_socket: UdpSocket, transactions_addr: SocketAddr, transactions_socket: UdpSocket, ) -> Self { let client = ThinClient { requests_addr, - requests_sender, - requests_receiver, + requests_socket, transactions_addr, transactions_socket, last_id: None, @@ -53,7 +50,7 @@ impl ThinClient { pub fn recv_response(&self) -> io::Result { let mut buf = vec![0u8; 1024]; trace!("start recv_from"); - self.requests_receiver.recv_from(&mut buf)?; + self.requests_socket.recv_from(&mut buf)?; trace!("end recv_from"); let resp = deserialize(&buf).expect("deserialize balance in thin_client"); Ok(resp) @@ -115,7 +112,7 @@ impl ThinClient { trace!("get_balance"); let req = Request::GetBalance { key: *pubkey }; let data = serialize(&req).expect("serialize GetBalance in pub fn get_balance"); - self.requests_sender + self.requests_socket .send_to(&data, &self.requests_addr) .expect("buffer error in pub fn get_balance"); let mut done = false; @@ -139,7 +136,7 @@ impl ThinClient { serialize(&req).expect("serialize GetTransactionCount in pub fn transaction_count"); let mut done = false; while !done { - self.requests_sender + self.requests_socket .send_to(&data, &self.requests_addr) .expect("buffer error in pub fn transaction_count"); @@ -163,7 +160,7 @@ impl ThinClient { let mut done = false; while !done { debug!("get_last_id send_to {}", &self.requests_addr); - self.requests_sender + self.requests_socket .send_to(&data, &self.requests_addr) .expect("buffer error in pub fn get_last_id"); @@ -205,7 +202,7 @@ impl ThinClient { let data = serialize(&req).expect("serialize GetSignature in pub fn check_signature"); let mut done = false; while !done { - self.requests_sender + self.requests_socket .send_to(&data, &self.requests_addr) .expect("buffer error in pub fn get_last_id"); @@ -267,7 +264,6 @@ mod tests { let mut client = ThinClient::new( leader.data.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, leader.data.transactions_addr, transactions_socket, @@ -315,7 +311,6 @@ mod tests { let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let mut client = ThinClient::new( leader.data.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, leader.data.transactions_addr, transactions_socket, @@ -374,7 +369,6 @@ mod tests { let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let mut client = ThinClient::new( leader.data.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, leader.data.transactions_addr, transactions_socket, diff --git a/tests/multinode.rs b/tests/multinode.rs index bd2acc3a2c6196..9ef8916318eb84 100644 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -246,7 +246,6 @@ fn mk_client(leader: &ReplicatedData) -> ThinClient { ThinClient::new( leader.requests_addr, - requests_socket.try_clone().unwrap(), requests_socket, leader.transactions_addr, transactions_socket,