Skip to content

Commit ff0dd77

Browse files
committed
qos_core: add client_timeout to Manifest
1 parent 8f5957d commit ff0dd77

File tree

21 files changed

+89
-80
lines changed

21 files changed

+89
-80
lines changed

src/integration/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::time::Duration;
99
use borsh::{BorshDeserialize, BorshSerialize};
1010
use qos_core::{
1111
client::SocketClient,
12-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
12+
io::{SocketAddress, StreamPool},
1313
parser::{GetParserForOptions, OptionsParser, Parser, Token},
1414
};
1515

@@ -136,7 +136,7 @@ pub struct AdditionProofPayload {
136136
pub async fn wait_for_usock(path: &str) {
137137
let addr = SocketAddress::new_unix(path);
138138
let pool = StreamPool::new(addr, 1).unwrap().shared();
139-
let client = SocketClient::new(pool, TimeVal::milliseconds(50));
139+
let client = SocketClient::new(pool, Duration::from_millis(50));
140140

141141
for _ in 0..50 {
142142
if std::fs::exists(path).unwrap() && client.try_connect().await.is_ok()

src/integration/tests/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::sync::Arc;
1+
use std::{sync::Arc, time::Duration};
22

33
use qos_core::{
44
client::SocketClient,
5-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
5+
io::{SocketAddress, StreamPool},
66
server::SocketServerError,
77
server::{RequestProcessor, SocketServer},
88
};
@@ -37,7 +37,7 @@ async fn run_echo_server(
3737
async fn direct_connect_works() {
3838
let socket_path = "/tmp/async_client_test_direct_connect_works.sock";
3939
let socket = SocketAddress::new_unix(socket_path);
40-
let timeout = TimeVal::milliseconds(500);
40+
let timeout = Duration::from_millis(500);
4141
let pool = StreamPool::new(socket, 1)
4242
.expect("unable to create async pool")
4343
.shared();
@@ -54,7 +54,7 @@ async fn direct_connect_works() {
5454
async fn times_out_properly() {
5555
let socket_path = "/tmp/async_client_test_times_out_properly.sock";
5656
let socket = SocketAddress::new_unix(socket_path);
57-
let timeout = TimeVal::milliseconds(500);
57+
let timeout = Duration::from_millis(500);
5858
let pool = StreamPool::new(socket, 1)
5959
.expect("unable to create async pool")
6060
.shared();
@@ -68,7 +68,7 @@ async fn times_out_properly() {
6868
async fn repeat_connect_works() {
6969
let socket_path = "/tmp/async_client_test_repeat_connect_works.sock";
7070
let socket = SocketAddress::new_unix(socket_path);
71-
let timeout = TimeVal::milliseconds(500);
71+
let timeout = Duration::from_millis(500);
7272
let pool = StreamPool::new(socket, 1)
7373
.expect("unable to create async pool")
7474
.shared();

src/integration/tests/enclave_app_client_socket_stress.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use integration::{
77
use qos_core::{
88
client::SocketClient,
99
handles::Handles,
10-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
10+
io::{SocketAddress, StreamPool},
1111
protocol::{
1212
msg::ProtocolMsg,
1313
services::boot::{
1414
Manifest, ManifestEnvelope, ManifestSet, Namespace, NitroConfig,
1515
PivotConfig, RestartPolicy, ShareSet,
1616
},
17-
ProtocolError, ProtocolPhase, ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
17+
ProtocolError, ProtocolPhase, INITIAL_CLIENT_TIMEOUT,
1818
},
1919
reaper::{Reaper, REAPER_RESTART_DELAY},
2020
};
@@ -103,7 +103,7 @@ async fn enclave_app_client_socket_stress() {
103103
StreamPool::single(SocketAddress::new_unix(ENCLAVE_SOCK)).unwrap();
104104
let enclave_client = SocketClient::new(
105105
enclave_client_pool.shared(),
106-
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS + 3), // needs to be bigger than the slow request below + some time for recovery
106+
INITIAL_CLIENT_TIMEOUT + Duration::from_secs(3), // needs to be bigger than the sdlow request below + some time for recovery
107107
);
108108

109109
let app_request =

src/integration/tests/interleaving_socket_stress.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use integration::{
66
};
77
use qos_core::{
88
client::{ClientError, SocketClient},
9-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
10-
protocol::ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
9+
io::{SocketAddress, StreamPool},
10+
protocol::INITIAL_CLIENT_TIMEOUT,
1111
};
1212
use qos_test_primitives::ChildWrapper;
1313

@@ -27,12 +27,12 @@ async fn interleaving_socket_stress() {
2727
wait_for_usock(SOCKET_STRESS_SOCK).await;
2828

2929
// needs to be long enough for process exit to register and not cause a timeout
30-
let timeout = TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS);
3130
let app_pool =
3231
StreamPool::new(SocketAddress::new_unix(SOCKET_STRESS_SOCK), pool_size)
3332
.unwrap();
3433

35-
let enclave_client = SocketClient::new(app_pool.shared(), timeout);
34+
let enclave_client =
35+
SocketClient::new(app_pool.shared(), INITIAL_CLIENT_TIMEOUT);
3636
let mut tasks = Vec::new();
3737

3838
// wait long enough for app to be running and listening

src/integration/tests/proofs.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use borsh::BorshDeserialize;
44
use integration::{wait_for_usock, PivotProofMsg, PIVOT_PROOF_PATH};
55
use qos_core::{
66
client::SocketClient,
7-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
8-
protocol::ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
7+
io::{SocketAddress, StreamPool},
8+
protocol::INITIAL_CLIENT_TIMEOUT,
99
};
1010

1111
use qos_p256::P256Public;
@@ -27,10 +27,8 @@ async fn fetch_and_verify_app_proof() {
2727
StreamPool::single(SocketAddress::new_unix(PROOF_TEST_ENCLAVE_SOCKET))
2828
.unwrap();
2929

30-
let enclave_client = SocketClient::new(
31-
enclave_pool.shared(),
32-
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
33-
);
30+
let enclave_client =
31+
SocketClient::new(enclave_pool.shared(), INITIAL_CLIENT_TIMEOUT);
3432

3533
let app_request =
3634
borsh::to_vec(&PivotProofMsg::AdditionRequest { a: 2, b: 2 }).unwrap();

src/integration/tests/reaper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async fn reaper_works() {
3636
let mut manifest_envelope = ManifestEnvelope::default();
3737
manifest_envelope.manifest.pivot.args =
3838
vec!["--msg".to_string(), msg.to_string()];
39+
manifest_envelope.manifest.client_timeout_ms = Some(2000); // check if this gets applied
3940

4041
handles.put_manifest_envelope(&manifest_envelope).unwrap();
4142
assert!(handles.pivot_exists());

src/integration/tests/remote_tls.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use integration::{
66
};
77
use qos_core::{
88
client::SocketClient,
9-
io::{SocketAddress, StreamPool, TimeVal, TimeValLike},
10-
protocol::ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
9+
io::{SocketAddress, StreamPool},
10+
protocol::INITIAL_CLIENT_TIMEOUT,
1111
};
1212

1313
use qos_test_primitives::ChildWrapper;
@@ -43,10 +43,8 @@ async fn fetch_async_remote_tls_content() {
4343
)
4444
.expect("unable to create enclave async pool");
4545

46-
let enclave_client = SocketClient::new(
47-
enclave_pool.shared(),
48-
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
49-
);
46+
let enclave_client =
47+
SocketClient::new(enclave_pool.shared(), INITIAL_CLIENT_TIMEOUT);
5048

5149
let app_request = borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsRequest {
5250
host: "api.turnkey.com".to_string(),

src/integration/tests/simple_socket_stress.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use integration::{
55
};
66
use qos_core::{
77
client::{ClientError, SocketClient},
8-
io::{IOError, SocketAddress, StreamPool, TimeVal, TimeValLike},
9-
protocol::ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
8+
io::{IOError, SocketAddress, StreamPool},
9+
protocol::INITIAL_CLIENT_TIMEOUT,
1010
};
1111
use qos_test_primitives::ChildWrapper;
1212

@@ -23,13 +23,13 @@ async fn simple_socket_stress() {
2323
wait_for_usock(SOCKET_STRESS_SOCK).await;
2424

2525
// needs to be long enough for process exit to register and not cause a timeout
26-
let timeout = TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS);
2726

2827
let app_pool =
2928
StreamPool::new(SocketAddress::new_unix(SOCKET_STRESS_SOCK), 1)
3029
.unwrap();
3130

32-
let enclave_client = SocketClient::new(app_pool.shared(), timeout);
31+
let enclave_client =
32+
SocketClient::new(app_pool.shared(), INITIAL_CLIENT_TIMEOUT);
3333

3434
let app_request =
3535
borsh::to_vec(&PivotSocketStressMsg::SlowRequest(5500)).unwrap();

src/qos_client/src/cli/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const NAMESPACE_DIR: &str = "namespace-dir";
4141
const UNSAFE_AUTO_CONFIRM: &str = "unsafe-auto-confirm";
4242
const PUB_PATH: &str = "pub-path";
4343
const POOL_SIZE: &str = "pool-size";
44+
const CLIENT_TIMEOUT: &str = "client-timeout";
4445
const YUBIKEY: &str = "yubikey";
4546
const SECRET_PATH: &str = "secret-path";
4647
const SHARE_PATH: &str = "share-path";
@@ -999,6 +1000,13 @@ impl ClientOpts {
9991000
})
10001001
}
10011002

1003+
fn client_timeout_ms(&self) -> Option<u16> {
1004+
self.parsed.single(CLIENT_TIMEOUT).map(|s| {
1005+
s.parse()
1006+
.expect("client timeout invalid integer in range <0..65535>")
1007+
})
1008+
}
1009+
10021010
fn pub_path(&self) -> String {
10031011
self.parsed.single(PUB_PATH).expect("Missing `--pub-path`").to_string()
10041012
}
@@ -1525,6 +1533,7 @@ mod handlers {
15251533
patch_set_dir: opts.patch_set_dir(),
15261534
quorum_key_path: opts.quorum_key_path(),
15271535
pool_size: opts.pool_size(),
1536+
client_timeout_ms: opts.client_timeout_ms(),
15281537
}) {
15291538
println!("Error: {e:?}");
15301539
std::process::exit(1);

src/qos_client/src/cli/services.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ pub(crate) struct GenerateManifestArgs<P: AsRef<Path>> {
702702
pub manifest_path: P,
703703
pub pivot_args: Vec<String>,
704704
pub pool_size: Option<u8>,
705+
pub client_timeout_ms: Option<u16>,
705706
}
706707

707708
pub(crate) fn generate_manifest<P: AsRef<Path>>(
@@ -721,6 +722,7 @@ pub(crate) fn generate_manifest<P: AsRef<Path>>(
721722
manifest_path,
722723
pivot_args,
723724
pool_size,
725+
client_timeout_ms,
724726
} = args;
725727

726728
let nitro_config =
@@ -752,6 +754,7 @@ pub(crate) fn generate_manifest<P: AsRef<Path>>(
752754
patch_set,
753755
enclave: nitro_config,
754756
pool_size,
757+
client_timeout_ms,
755758
};
756759

757760
write_with_msg(
@@ -1646,6 +1649,7 @@ pub(crate) fn dangerous_dev_boot<P: AsRef<Path>>(
16461649
},
16471650
patch_set: PatchSet { threshold: 0, members: vec![] },
16481651
pool_size: None,
1652+
client_timeout_ms: None,
16491653
};
16501654

16511655
// Create and post the boot standard instruction
@@ -2261,6 +2265,7 @@ mod tests {
22612265
patch_set: patch_set.clone(),
22622266
enclave: nitro_config.clone(),
22632267
pool_size: None,
2268+
client_timeout_ms: None,
22642269
};
22652270

22662271
let manifest_envelope = ManifestEnvelope {

0 commit comments

Comments
 (0)