mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Support configuring client request timeout (#54)
This commit is contained in:
parent
2dd8c0fddf
commit
f3bbc6ad9f
3 changed files with 14 additions and 8 deletions
|
@ -25,6 +25,8 @@ macro_rules! usage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_REQ_TIMEOUT: u64 = 120;
|
||||||
|
|
||||||
const COLORS: [Color; 13] = [
|
const COLORS: [Color; 13] = [
|
||||||
Color::Blue,
|
Color::Blue,
|
||||||
Color::Cyan,
|
Color::Cyan,
|
||||||
|
@ -182,6 +184,7 @@ pub struct TunableValues {
|
||||||
pub reaction_shortcode_display: bool,
|
pub reaction_shortcode_display: bool,
|
||||||
pub read_receipt_send: bool,
|
pub read_receipt_send: bool,
|
||||||
pub read_receipt_display: bool,
|
pub read_receipt_display: bool,
|
||||||
|
pub request_timeout: u64,
|
||||||
pub typing_notice_send: bool,
|
pub typing_notice_send: bool,
|
||||||
pub typing_notice_display: bool,
|
pub typing_notice_display: bool,
|
||||||
pub users: UserOverrides,
|
pub users: UserOverrides,
|
||||||
|
@ -194,6 +197,7 @@ pub struct Tunables {
|
||||||
pub reaction_shortcode_display: Option<bool>,
|
pub reaction_shortcode_display: Option<bool>,
|
||||||
pub read_receipt_send: Option<bool>,
|
pub read_receipt_send: Option<bool>,
|
||||||
pub read_receipt_display: Option<bool>,
|
pub read_receipt_display: Option<bool>,
|
||||||
|
pub request_timeout: Option<u64>,
|
||||||
pub typing_notice_send: Option<bool>,
|
pub typing_notice_send: Option<bool>,
|
||||||
pub typing_notice_display: Option<bool>,
|
pub typing_notice_display: Option<bool>,
|
||||||
pub users: Option<UserOverrides>,
|
pub users: Option<UserOverrides>,
|
||||||
|
@ -209,6 +213,7 @@ impl Tunables {
|
||||||
.or(other.reaction_shortcode_display),
|
.or(other.reaction_shortcode_display),
|
||||||
read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
|
read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
|
||||||
read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
|
read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
|
||||||
|
request_timeout: self.request_timeout.or(other.request_timeout),
|
||||||
typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
|
typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
|
||||||
typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
|
typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
|
||||||
users: merge_users(self.users, other.users),
|
users: merge_users(self.users, other.users),
|
||||||
|
@ -222,6 +227,7 @@ impl Tunables {
|
||||||
reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false),
|
reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false),
|
||||||
read_receipt_send: self.read_receipt_send.unwrap_or(true),
|
read_receipt_send: self.read_receipt_send.unwrap_or(true),
|
||||||
read_receipt_display: self.read_receipt_display.unwrap_or(true),
|
read_receipt_display: self.read_receipt_display.unwrap_or(true),
|
||||||
|
request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT),
|
||||||
typing_notice_send: self.typing_notice_send.unwrap_or(true),
|
typing_notice_send: self.typing_notice_send.unwrap_or(true),
|
||||||
typing_notice_display: self.typing_notice_display.unwrap_or(true),
|
typing_notice_display: self.typing_notice_display.unwrap_or(true),
|
||||||
users: self.users.unwrap_or_default(),
|
users: self.users.unwrap_or_default(),
|
||||||
|
|
|
@ -174,6 +174,7 @@ pub fn mock_tunables() -> TunableValues {
|
||||||
reaction_shortcode_display: false,
|
reaction_shortcode_display: false,
|
||||||
read_receipt_send: true,
|
read_receipt_send: true,
|
||||||
read_receipt_display: true,
|
read_receipt_display: true,
|
||||||
|
request_timeout: 120,
|
||||||
typing_notice_send: true,
|
typing_notice_send: true,
|
||||||
typing_notice_display: true,
|
typing_notice_display: true,
|
||||||
users: vec![(TEST_USER5.clone(), UserDisplayTunables {
|
users: vec![(TEST_USER5.clone(), UserDisplayTunables {
|
||||||
|
|
|
@ -82,7 +82,6 @@ use crate::{
|
||||||
|
|
||||||
const IAMB_DEVICE_NAME: &str = "iamb";
|
const IAMB_DEVICE_NAME: &str = "iamb";
|
||||||
const IAMB_USER_AGENT: &str = "iamb";
|
const IAMB_USER_AGENT: &str = "iamb";
|
||||||
const REQ_TIMEOUT: Duration = Duration::from_secs(60);
|
|
||||||
|
|
||||||
fn initial_devname() -> String {
|
fn initial_devname() -> String {
|
||||||
format!("{} on {}", IAMB_DEVICE_NAME, gethostname().to_string_lossy())
|
format!("{} on {}", IAMB_DEVICE_NAME, gethostname().to_string_lossy())
|
||||||
|
@ -447,20 +446,20 @@ impl ClientWorker {
|
||||||
let (tx, rx) = unbounded_channel();
|
let (tx, rx) = unbounded_channel();
|
||||||
let account = &settings.profile;
|
let account = &settings.profile;
|
||||||
|
|
||||||
// Set up a custom client that only uses HTTP/1.
|
let req_timeout = Duration::from_secs(settings.tunables.request_timeout);
|
||||||
//
|
|
||||||
// During my testing, I kept stumbling across something weird with sync and HTTP/2 that
|
// Set up the HTTP client.
|
||||||
// will need to be revisited in the future.
|
|
||||||
let http = reqwest::Client::builder()
|
let http = reqwest::Client::builder()
|
||||||
.user_agent(IAMB_USER_AGENT)
|
.user_agent(IAMB_USER_AGENT)
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(req_timeout)
|
||||||
.pool_idle_timeout(Duration::from_secs(60))
|
.pool_idle_timeout(Duration::from_secs(60))
|
||||||
.pool_max_idle_per_host(10)
|
.pool_max_idle_per_host(10)
|
||||||
.tcp_keepalive(Duration::from_secs(10))
|
.tcp_keepalive(Duration::from_secs(10))
|
||||||
.http1_only()
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let req_config = RequestConfig::new().timeout(req_timeout).retry_timeout(req_timeout);
|
||||||
|
|
||||||
// Set up the Matrix client for the selected profile.
|
// Set up the Matrix client for the selected profile.
|
||||||
let client = Client::builder()
|
let client = Client::builder()
|
||||||
.http_client(Arc::new(http))
|
.http_client(Arc::new(http))
|
||||||
|
@ -468,7 +467,7 @@ impl ClientWorker {
|
||||||
.store_config(StoreConfig::default())
|
.store_config(StoreConfig::default())
|
||||||
.sled_store(settings.matrix_dir.as_path(), None)
|
.sled_store(settings.matrix_dir.as_path(), None)
|
||||||
.expect("Failed to setup up sled store for Matrix SDK")
|
.expect("Failed to setup up sled store for Matrix SDK")
|
||||||
.request_config(RequestConfig::new().timeout(REQ_TIMEOUT).retry_timeout(REQ_TIMEOUT))
|
.request_config(req_config)
|
||||||
.build()
|
.build()
|
||||||
.await
|
.await
|
||||||
.expect("Failed to instantiate Matrix client");
|
.expect("Failed to instantiate Matrix client");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue