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 #636

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
10 changes: 6 additions & 4 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::tor::config as tor_config;
use crate::tor::process as tor_process;

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

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

let res: String = self.post(url, None, req).map_err(|e| {
let res: String = self.post(url, None, req, None).map_err(|e| {
let mut report = format!("Performing version check (is recipient listening?): {}", e);
let err_string = format!("{}", e);
if err_string.contains("404") {
Expand Down Expand Up @@ -159,17 +160,18 @@ impl HttpSlateSender {
url: &str,
api_secret: Option<String>,
input: IN,
timeout: Option<u64>,
) -> Result<String, ClientError>
where
IN: Serialize,
{
let client =
if !self.use_socks {
Client::new()
Client::new(timeout)
} else {
Client::with_socks_proxy(self.socks_proxy_addr.ok_or_else(|| {
ClientErrorKind::Internal("No socks proxy address set".into())
})?)
})?, timeout)
}
.map_err(|_| ClientErrorKind::Internal("Unable to create http client".into()))?;
let req = client.create_post_request(url, api_secret, &input)?;
Expand Down Expand Up @@ -215,7 +217,7 @@ impl SlateSender for HttpSlateSender {

trace!("Sending receive_tx request: {}", req);

let res: String = self.post(&url_str, None, req).map_err(|e| {
let res: String = self.post(&url_str, None, req, Some(SEND_TX_TIMEOUT_DURATION_SECTIONS)).map_err(|e| {
let report = format!(
"Sending transaction slate to other wallet (is recipient listening?): {}",
e
Expand Down
13 changes: 7 additions & 6 deletions impls/src/client_utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,23 @@ pub struct Client {

impl Client {
/// New client
pub fn new() -> Result<Self, Error> {
Self::build(None)
pub fn new(read_and_write_timeout: Option<u64>) -> Result<Self, Error> {
Self::build(None, read_and_write_timeout)
}

pub fn with_socks_proxy(socks_proxy_addr: SocketAddr) -> Result<Self, Error> {
Self::build(Some(socks_proxy_addr))
pub fn with_socks_proxy(socks_proxy_addr: SocketAddr, read_and_write_timeout: Option<u64>) -> Result<Self, Error> {
Self::build(Some(socks_proxy_addr), read_and_write_timeout)
}

fn build(socks_proxy_addr: Option<SocketAddr>) -> Result<Self, Error> {
fn build(socks_proxy_addr: Option<SocketAddr>, read_and_write_timeout: Option<u64>) -> Result<Self, Error> {
let mut headers = HeaderMap::new();
headers.insert(USER_AGENT, HeaderValue::from_static("grin-client"));
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));

let mut builder = ClientBuilder::new()
.timeout(Duration::from_secs(20))
.timeout(Duration::from_secs(read_and_write_timeout.unwrap_or(20)))
.connect_timeout(Duration::from_secs(20))
.use_rustls_tls()
.default_headers(headers);

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 @@ -47,7 +47,7 @@ impl HTTPNodeClient {
node_api_secret: Option<String>,
) -> Result<HTTPNodeClient, libwallet::Error> {
Ok(HTTPNodeClient {
client: Client::new().map_err(|_| libwallet::ErrorKind::Node)?,
client: Client::new(None).map_err(|_| libwallet::ErrorKind::Node)?,
node_url: node_url.to_owned(),
node_api_secret: node_api_secret,
node_version_info: None,
Expand Down