Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase network read timeout when sending transactions #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use grin_wallet_libwallet::proof::proofaddress::ProvableAddress;
use grin_wallet_libwallet::slatepack::SlatePurpose;

const TOR_CONFIG_PATH: &str = "tor/sender";
const SEND_TX_TIMEOUT_DURATION_SECTIONS: u64 = 5 * 60;

#[derive(Clone)]
pub struct HttpDataSender {
Expand Down Expand Up @@ -114,7 +115,7 @@ impl HttpDataSender {
"params": []
});

let res = self.post(url, self.apisecret.clone(), req);
let res = self.post(url, self.apisecret.clone(), req, None);

let diff_time = start_time.elapsed().as_millis();
trace!("elapsed time check version = {}", diff_time);
Expand Down Expand Up @@ -236,7 +237,7 @@ impl HttpDataSender {
"params": []
});

let res = self.post(url, self.apisecret.clone(), req);
let res = self.post(url, self.apisecret.clone(), req, None);

let diff_time = start_time.elapsed().as_millis();
trace!("elapsed time check proof address = {}", diff_time);
Expand Down Expand Up @@ -308,12 +309,13 @@ impl HttpDataSender {
url: &str,
api_secret: Option<String>,
input: IN,
read_timeout: Option<u64>,
) -> Result<String, ClientError>
where
IN: Serialize,
{
// For state sender we want send and disconnect
let client = Client::new(self.use_socks, self.socks_proxy_addr)?;
let client = Client::new(self.use_socks, self.socks_proxy_addr, read_timeout)?;
let req = client.create_post_request(url, Some("mwc".to_string()), api_secret, &input)?;
let res = client.send_request(req)?;
Ok(res)
Expand Down Expand Up @@ -489,7 +491,7 @@ impl SlateSender for HttpDataSender {
});
trace!("Sending receive_tx request: {}", req);

let res = self.post(&url_str, self.apisecret.clone(), req);
let res = self.post(&url_str, self.apisecret.clone(), req, Some(SEND_TX_TIMEOUT_DURATION_SECTIONS));

let diff_time = start_time.elapsed().as_millis();
trace!("diff time slate send = {}", diff_time);
Expand Down Expand Up @@ -602,7 +604,7 @@ impl SwapMessageSender for HttpDataSender {
});
trace!("Sending receive_swap_message request: {}", req);

let res = self.post(&url_str, self.apisecret.clone(), req);
let res = self.post(&url_str, self.apisecret.clone(), req, None);

let diff_time = start_time.elapsed().as_millis();
if !res.is_err() {
Expand Down Expand Up @@ -655,7 +657,7 @@ impl MarketplaceMessageSender for HttpDataSender {
});
trace!("Sending marketplace_message request: {}", req);

let res = self.post(&url_str, self.apisecret.clone(), req);
let res = self.post(&url_str, self.apisecret.clone(), req, None);

let diff_time = start_time.elapsed().as_millis();
if !res.is_err() {
Expand Down
12 changes: 6 additions & 6 deletions impls/src/client_utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ pub struct Client {

impl Client {
/// New client
pub fn new(use_socks: bool, socks_proxy_addr: Option<SocketAddr>) -> Result<Self,Error> {
let (https_client, socks_client) = Self::construct_client(use_socks, socks_proxy_addr)?;
pub fn new(use_socks: bool, socks_proxy_addr: Option<SocketAddr>, read_timeout: Option<u64>) -> Result<Self,Error> {
let (https_client, socks_client) = Self::construct_client(use_socks, socks_proxy_addr, read_timeout)?;
Ok(Client {
https_client: Arc::new(https_client),
socks_client: Arc::new(socks_client),
})
}

fn construct_client(use_socks: bool, socks_proxy_addr: Option<SocketAddr>) ->
fn construct_client(use_socks: bool, socks_proxy_addr: Option<SocketAddr>, read_timeout: Option<u64>) ->
Result< (Option<hyper::Client<TimeoutConnector<hyper_rustls::HttpsConnector<HttpConnector>>>>,
Option<hyper::Client<TimeoutConnector<hyper_socks2::SocksConnector<hyper_rustls::HttpsConnector<HttpConnector>>>>>), Error> {
if !use_socks {
Expand All @@ -117,15 +117,15 @@ impl Client {
#[cfg(not(target_os = "android"))]
{
connector.set_connect_timeout(Some(Duration::from_secs(10)));
connector.set_read_timeout(Some(Duration::from_secs(20)));
connector.set_read_timeout(Some(Duration::from_secs(read_timeout.unwrap_or(20))));
connector.set_write_timeout(Some(Duration::from_secs(20)));
}

#[cfg(target_os = "android")]
{
// For android timeouts need to be longer because we already experiencing some connection issues.
connector.set_connect_timeout(Some(Duration::from_secs(30)));
connector.set_read_timeout(Some(Duration::from_secs(30)));
connector.set_read_timeout(Some(Duration::from_secs(read_timeout.unwrap_or(30))));
connector.set_write_timeout(Some(Duration::from_secs(30)));
}

Expand All @@ -152,7 +152,7 @@ impl Client {
};
let mut connector = TimeoutConnector::new(socks);
connector.set_connect_timeout(Some(Duration::from_secs(10)));
connector.set_read_timeout(Some(Duration::from_secs(120))); // For TOR the timeout need to be pretty long. It takes time to builkd a route
connector.set_read_timeout(Some(Duration::from_secs(read_timeout.unwrap_or(120)))); // For TOR the timeout need to be pretty long. It takes time to builkd a route
connector.set_write_timeout(Some(Duration::from_secs(120)));
let client = HyperClient::builder()
.pool_idle_timeout(Duration::from_secs(300))
Expand Down
2 changes: 1 addition & 1 deletion impls/src/node_clients/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl HTTPNodeClient {
node_url_list: Vec<String>,
node_api_secret: Option<String>,
) -> Result<HTTPNodeClient, Error> {
let client = Client::new(false, None)
let client = Client::new(false, None, None)
.map_err(|e| Error::GenericError(format!("Unable to create a client, {}", e)))?;

Ok(HTTPNodeClient {
Expand Down