Skip to content

Commit 1d18532

Browse files
committed
qos_core: fix new nits
1 parent 1e48be4 commit 1d18532

File tree

13 files changed

+48
-45
lines changed

13 files changed

+48
-45
lines changed

src/integration/examples/boot_enclave.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Example showing how enclaves can be booted locally end-to-end.
2+
//! Useful to make debugging easier when iterating on the core of QOS.
3+
14
use std::{
25
fs,
36
io::{BufRead, BufReader, Write},

src/integration/src/bin/pivot_proof.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use qos_core::{
1010
};
1111
use tokio::sync::RwLock;
1212

13-
#[derive(Clone)]
1413
struct Processor {
1514
ephemeral_key_handle: EphemeralKeyHandle,
1615
}
File renamed without changes.

src/integration/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ pub const PIVOT_PANIC_PATH: &str = "../target/debug/pivot_panic";
3434
/// Path to an enclave app that has routes to test remote connection features.
3535
pub const PIVOT_REMOTE_TLS_PATH: &str = "../target/debug/pivot_remote_tls";
3636
/// Path to an enclave app that has routes to test remote connection features.
37-
pub const PIVOT_ASYNC_REMOTE_TLS_PATH: &str =
38-
"../target/debug/pivot_async_remote_tls";
39-
/// Path to an enclave app that has routes to test remote connection features.
4037
pub const QOS_NET_PATH: &str = "../target/debug/qos_net";
4138
/// Path to an enclave app that has routes to stress our socket.
4239
pub const PIVOT_SOCKET_STRESS_PATH: &str =

src/integration/tests/proofs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async fn fetch_and_verify_app_proof() {
2424
wait_for_usock(PROOF_TEST_ENCLAVE_SOCKET).await;
2525

2626
let enclave_pool =
27-
StreamPool::new(SocketAddress::new_unix(PROOF_TEST_ENCLAVE_SOCKET), 1)
27+
StreamPool::single(SocketAddress::new_unix(PROOF_TEST_ENCLAVE_SOCKET))
2828
.unwrap();
2929

3030
let enclave_client = SocketClient::new(

src/integration/tests/qos_host.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ async fn connects_and_gets_info() {
6161

6262
let r = ureq::get("http://127.0.0.1:3323/qos/enclave-info").call();
6363
assert!(r.is_ok()); // expect 200 here
64+
assert_eq!(
65+
r.unwrap().into_string().unwrap(),
66+
"{\"phase\":\"WaitingForBootInstruction\",\"manifestEnvelope\":null}"
67+
);
6468
}

src/integration/tests/remote_tls.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use std::process::Command;
22

33
use borsh::BorshDeserialize;
44
use integration::{
5-
wait_for_usock, PivotRemoteTlsMsg, PIVOT_ASYNC_REMOTE_TLS_PATH,
6-
QOS_NET_PATH,
5+
wait_for_usock, PivotRemoteTlsMsg, PIVOT_REMOTE_TLS_PATH, QOS_NET_PATH,
76
};
87
use qos_core::{
98
client::SocketClient,
@@ -13,10 +12,9 @@ use qos_core::{
1312

1413
use qos_test_primitives::ChildWrapper;
1514

16-
const REMOTE_TLS_TEST_NET_PROXY_SOCKET: &str =
17-
"/tmp/async_remote_tls_test.net.sock";
15+
const REMOTE_TLS_TEST_NET_PROXY_SOCKET: &str = "/tmp/remote_tls_test.net.sock";
1816
const REMOTE_TLS_TEST_ENCLAVE_SOCKET: &str =
19-
"/tmp/async_remote_tls_test.enclave.sock";
17+
"/tmp/remote_tls_test.enclave.sock";
2018
const POOL_SIZE: &str = "1";
2119

2220
#[tokio::test]
@@ -30,7 +28,7 @@ async fn fetch_async_remote_tls_content() {
3028
.unwrap()
3129
.into();
3230

33-
let _enclave_app: ChildWrapper = Command::new(PIVOT_ASYNC_REMOTE_TLS_PATH)
31+
let _enclave_app: ChildWrapper = Command::new(PIVOT_REMOTE_TLS_PATH)
3432
.arg(REMOTE_TLS_TEST_ENCLAVE_SOCKET)
3533
.arg(REMOTE_TLS_TEST_NET_PROXY_SOCKET)
3634
.spawn()

src/qos_core/src/cli.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ impl EnclaveOpts {
4848
Self { parsed }
4949
}
5050

51+
/// Create a new `StreamPool` for connecting to the enclave.
52+
fn enclave_pool(&self) -> Result<StreamPool, IOError> {
53+
self.async_pool(false)
54+
}
55+
56+
/// Create a new `StreamPool` for connecting to the app.
57+
fn app_pool(&self) -> Result<StreamPool, IOError> {
58+
self.async_pool(true)
59+
}
60+
5161
/// Create a new `StreamPool` using the list of `SocketAddress` for the qos host.
5262
/// The `app` parameter specifies if this is a pool meant for the enclave itself, or the enclave app.
5363
fn async_pool(&self, app: bool) -> Result<StreamPool, IOError> {
@@ -64,13 +74,14 @@ impl EnclaveOpts {
6474
c.parse().map_err(|_| IOError::ConnectAddressInvalid)?;
6575
let p =
6676
p.parse().map_err(|_| IOError::ConnectAddressInvalid)?;
67-
StreamPool::new(
68-
SocketAddress::new_vsock(c, p, crate::io::VMADDR_NO_FLAGS),
69-
1,
70-
)
77+
StreamPool::single(SocketAddress::new_vsock(
78+
c,
79+
p,
80+
crate::io::VMADDR_NO_FLAGS,
81+
))
7182
}
7283
(None, None, Some(u)) => {
73-
StreamPool::new(SocketAddress::new_unix(u), 1)
84+
StreamPool::single(SocketAddress::new_unix(u))
7485
}
7586
_ => panic!("Invalid socket opts"),
7687
}
@@ -150,10 +161,9 @@ impl CLI {
150161
opts.pivot_file(),
151162
),
152163
opts.nsm(),
153-
opts.async_pool(false)
164+
opts.enclave_pool()
154165
.expect("Unable to create enclave socket pool"),
155-
opts.async_pool(true)
156-
.expect("Unable to create enclave app pool"),
166+
opts.app_pool().expect("Unable to create enclave app pool"),
157167
None,
158168
);
159169
});

src/qos_core/src/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ impl SocketClient {
5555

5656
/// Send raw bytes and wait for a response until the clients configured
5757
/// timeout.
58-
///
59-
/// # Panics
60-
/// Does not. See comment bellow.
6158
pub async fn call(&self, request: &[u8]) -> Result<Vec<u8>, ClientError> {
6259
let pool = self.pool.read().await;
6360

@@ -95,8 +92,13 @@ impl SocketClient {
9592
}
9693
}
9794

95+
// Convers TimeVal to Duration
96+
// # Panics
97+
//
98+
// Panics if timeval values are negative
9899
fn timeval_to_duration(timeval: TimeVal) -> Duration {
99-
#[allow(clippy::cast_possible_truncation)]
100-
#[allow(clippy::cast_sign_loss)]
101-
Duration::new(timeval.tv_sec() as u64, timeval.tv_usec() as u32 * 1000)
100+
let secs: u64 = timeval.tv_sec().try_into().expect("invalid TimeVal value");
101+
let usecs: u32 =
102+
timeval.tv_usec().try_into().expect("invalid TimeVal value");
103+
Duration::new(secs, usecs * 1000)
102104
}

src/qos_core/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum IOError {
4444
RecvNixError(nix::Error),
4545
/// Reading the response size resulted in a size which exceeds the max payload size.
4646
OversizedPayload(usize),
47-
/// A async socket pool error during pool operations.
47+
/// An async socket pool error during pool operations.
4848
PoolError(PoolError),
4949
}
5050

0 commit comments

Comments
 (0)