Skip to content

Commit 24b0140

Browse files
committed
implement dynamic resizing async pool and server
1 parent c4a7911 commit 24b0140

23 files changed

+1070
-265
lines changed

src/init/init.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,20 @@ async fn main() {
9898
PIVOT_FILE.to_string(),
9999
);
100100

101-
let start_port = 3;
102-
let default_pool_size = 21; // 1 for qos-host, 20 for <app>-host, more are added as needed TODO: make the add logic dynamic
101+
let start_port = 3; // used for qos-host only! others follow 4+ for the <app>-host
103102
let core_pool = AsyncStreamPool::new(
104-
(start_port..start_port + default_pool_size)
105-
.into_iter()
106-
.map(|p| SocketAddress::new_vsock(cid, p, VMADDR_NO_FLAGS)),
103+
SocketAddress::new_vsock(cid, start_port, VMADDR_NO_FLAGS),
107104
TimeVal::seconds(0),
108-
);
105+
1, // start at pool size 1, grow based on manifest/args as necessary (see Reaper)
106+
)
107+
.expect("unable to create core pool");
109108

110109
let app_pool = AsyncStreamPool::new(
111-
(0..default_pool_size)
112-
.into_iter()
113-
.map(|p| SocketAddress::new_unix(&format!("{SEC_APP_SOCK}_{p}"))),
110+
SocketAddress::new_unix(SEC_APP_SOCK),
114111
TimeVal::seconds(5),
115-
);
112+
1, // start at pool size 1, grow based on manifest/args as necessary (see Reaper)
113+
)
114+
.expect("unable to create app pool");
116115

117116
Reaper::async_execute(&handles, Box::new(Nsm), core_pool, app_pool, None);
118117

src/integration/src/bin/pivot_async_remote_tls.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,28 @@ async fn main() {
110110
let proxy_path: &String = &args[2];
111111

112112
let pool = AsyncStreamPool::new(
113-
std::iter::once(SocketAddress::new_unix(socket_path)),
113+
SocketAddress::new_unix(socket_path),
114114
TimeVal::seconds(0), // listener, no timeout
115-
);
115+
1,
116+
)
117+
.expect("unable to create async stream pool");
116118

117119
let proxy_pool = AsyncStreamPool::new(
118-
std::iter::once(SocketAddress::new_unix(proxy_path)),
120+
SocketAddress::new_unix(proxy_path),
119121
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
122+
1,
120123
)
124+
.expect("unable to create async stream pool")
121125
.shared();
122126

123-
let tasks =
127+
let server =
124128
AsyncSocketServer::listen_all(pool, &Processor::new(proxy_pool))
125129
.unwrap();
126130

127131
match tokio::signal::ctrl_c().await {
128132
Ok(_) => {
129133
eprintln!("pivot handling ctrl+c the tokio way");
130-
for task in tasks {
131-
task.abort();
132-
}
134+
server.terminate();
133135
}
134136
Err(err) => panic!("{err}"),
135137
}

src/integration/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub const QOS_DIST_DIR: &str = "./mock/dist";
5757
pub const PCR3_PRE_IMAGE_PATH: &str = "./mock/namespaces/pcr3-preimage.txt";
5858

5959
const MSG: &str = "msg";
60+
const POOL_SIZE: &str = "pool-size";
6061

6162
/// Request/Response messages for "socket stress" pivot app.
6263
#[derive(BorshDeserialize, BorshSerialize, Debug, PartialEq, Eq)]
@@ -135,9 +136,17 @@ pub struct AdditionProofPayload {
135136
struct PivotParser;
136137
impl GetParserForOptions for PivotParser {
137138
fn parser() -> Parser {
138-
Parser::new().token(
139-
Token::new(MSG, "A msg to write").takes_value(true).required(true),
140-
)
139+
Parser::new()
140+
.token(
141+
Token::new(MSG, "A msg to write")
142+
.takes_value(true)
143+
.required(true),
144+
)
145+
.token(
146+
Token::new(POOL_SIZE, "App pool size")
147+
.takes_value(true)
148+
.required(false),
149+
)
141150
}
142151
}
143152

src/integration/tests/async_boot.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,23 @@ async fn async_standard_boot_e2e() {
3030
const PIVOT_HASH_PATH: &str = "/tmp/async_standard_boot_e2e-pivot-hash.txt";
3131

3232
let host_port = qos_test_primitives::find_free_port().unwrap();
33-
let tmp: PathWrapper = "/tmp/boot-e2e".into();
33+
let tmp: PathWrapper = "/tmp/async-boot-e2e".into();
3434
let _: PathWrapper = PIVOT_OK5_SUCCESS_FILE.into();
3535
let _: PathWrapper = PIVOT_HASH_PATH.into();
3636
fs::create_dir_all(&*tmp).unwrap();
3737

38-
let usock: PathWrapper = "/tmp/boot-e2e/boot_e2e.sock".into();
39-
let secret_path: PathWrapper = "/tmp/boot-e2e/boot_e2e.secret".into();
40-
let pivot_path: PathWrapper = "/tmp/boot-e2e/boot_e2e.pivot".into();
41-
let manifest_path: PathWrapper = "/tmp/boot-e2e/boot_e2e.manifest".into();
42-
let eph_path: PathWrapper = "/tmp/boot-e2e/ephemeral_key.secret".into();
38+
let usock: PathWrapper = "/tmp/async-boot-e2e/boot_e2e.sock".into();
39+
let secret_path: PathWrapper = "/tmp/async-boot-e2e/boot_e2e.secret".into();
40+
let pivot_path: PathWrapper = "/tmp/async-boot-e2e/boot_e2e.pivot".into();
41+
let manifest_path: PathWrapper =
42+
"/tmp/async-boot-e2e/boot_e2e.manifest".into();
43+
let eph_path: PathWrapper =
44+
"/tmp/async-boot-e2e/ephemeral_key.secret".into();
4345

44-
let boot_dir: PathWrapper = "/tmp/boot-e2e/boot-dir".into();
46+
let boot_dir: PathWrapper = "/tmp/async-boot-e2e/boot-dir".into();
4547
fs::create_dir_all(&*boot_dir).unwrap();
46-
let attestation_dir: PathWrapper = "/tmp/boot-e2e/attestation-dir".into();
48+
let attestation_dir: PathWrapper =
49+
"/tmp/async-boot-e2e/attestation-dir".into();
4750
fs::create_dir_all(&*attestation_dir).unwrap();
4851
let attestation_doc_path = format!("{}/attestation_doc", &*attestation_dir);
4952

@@ -65,7 +68,7 @@ async fn async_standard_boot_e2e() {
6568

6669
// -- CLIENT create manifest.
6770
let msg = "testing420";
68-
let pivot_args = format!("[--msg,{msg}]");
71+
let pivot_args = format!("[--msg,{msg},--pool-size,20]");
6972
let cli_manifest_path = format!("{}/manifest", &*boot_dir);
7073

7174
assert!(Command::new("../target/debug/qos_client")
@@ -131,7 +134,12 @@ async fn async_standard_boot_e2e() {
131134
let pivot = PivotConfig {
132135
hash: mock_pivot_hash,
133136
restart: RestartPolicy::Never,
134-
args: vec!["--msg".to_string(), msg.to_string()],
137+
args: vec![
138+
"--msg".to_string(),
139+
msg.to_string(),
140+
"--pool-size".to_string(),
141+
"20".to_string(),
142+
],
135143
};
136144
assert_eq!(manifest.pivot, pivot);
137145
let manifest_set = ManifestSet { threshold: 2, members: members.clone() };
@@ -221,7 +229,7 @@ async fn async_standard_boot_e2e() {
221229
);
222230
assert_eq!(
223231
&stdout.next().unwrap().unwrap(),
224-
"[\"--msg\", \"testing420\"]?"
232+
"[\"--msg\", \"testing420\", \"--pool-size\", \"20\"]?"
225233
);
226234
assert_eq!(&stdout.next().unwrap().unwrap(), "(y/n)");
227235
stdin.write_all("y\n".as_bytes()).expect("Failed to write to stdin");

0 commit comments

Comments
 (0)