Skip to content

Commit 310ea4f

Browse files
committed
Minor comment tweaks, bumps borsh to v1 in qos_net
1 parent d290dfb commit 310ea4f

File tree

6 files changed

+55
-138
lines changed

6 files changed

+55
-138
lines changed

src/Cargo.lock

Lines changed: 9 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/qos_core/src/io/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ mod test {
442442
fn stream_implements_read_write_traits() {
443443
let socket_server_path = "./stream_implements_read_write_traits.sock";
444444

445-
// Start a barebone socket server which replies "Roger that." to any
446-
// incoming request
445+
// Start a simple socket server which replies "PONG" to any incoming
446+
// request
447447
let mut server =
448448
HarakiriPongServer::new(socket_server_path.to_string());
449449
thread::spawn(move || {

src/qos_net/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
qos_core = { path = "../qos_core", default-features = false }
99

10-
borsh = { version = "0.10" }
10+
borsh = { version = "1.0", features = ["std", "derive"] , default-features = false}
1111
serde = { version = "1", features = ["derive"], default-features = false }
1212
hickory-resolver = { version = "0.24.1", features = ["tokio-runtime"], default-features = false, optional = true}
1313
rand = { version = "0.8.5", default-features = false, optional = true }

src/qos_net/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub const PORT: &str = "port";
1717
/// "usock"
1818
pub const USOCK: &str = "usock";
1919

20-
/// CLI options for starting up the enclave server.
20+
/// CLI options for starting up the proxy.
2121
#[derive(Default, Clone, Debug, PartialEq)]
2222
struct ProxyOpts {
2323
parsed: Parser,
@@ -55,10 +55,10 @@ impl ProxyOpts {
5555
}
5656
}
5757

58-
/// Enclave server CLI.
58+
/// Proxy CLI.
5959
pub struct CLI;
6060
impl CLI {
61-
/// Execute the enclave server CLI with the environment args.
61+
/// Execute the enclave proxy CLI with the environment args.
6262
pub fn execute() {
6363
let mut args: Vec<String> = env::args().collect();
6464
let opts = ProxyOpts::new(&mut args);

src/qos_net/src/proxy.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Protocol proxy for our remote QOS net proxy
22
use std::io::{Read, Write};
33

4-
use borsh::{BorshDeserialize, BorshSerialize};
4+
use borsh::BorshDeserialize;
55
use qos_core::server;
66

77
use crate::{
@@ -214,9 +214,10 @@ impl Proxy {
214214
impl server::RequestProcessor for Proxy {
215215
fn process(&mut self, req_bytes: Vec<u8>) -> Vec<u8> {
216216
if req_bytes.len() > MAX_ENCODED_MSG_LEN {
217-
return ProxyMsg::ProxyError(QosNetError::OversizedPayload)
218-
.try_to_vec()
219-
.expect("ProtocolMsg can always be serialized. qed.");
217+
return borsh::to_vec(&ProxyMsg::ProxyError(
218+
QosNetError::OversizedPayload,
219+
))
220+
.expect("ProtocolMsg can always be serialized. qed.");
220221
}
221222

222223
let resp = match ProxyMsg::try_from_slice(&req_bytes) {
@@ -278,7 +279,7 @@ impl server::RequestProcessor for Proxy {
278279
Err(_) => ProxyMsg::ProxyError(QosNetError::InvalidMsg),
279280
};
280281

281-
resp.try_to_vec()
282+
borsh::to_vec(&resp)
282283
.expect("Protocol message can always be serialized. qed!")
283284
}
284285
}
@@ -294,7 +295,7 @@ mod test {
294295
#[test]
295296
fn simple_status_request() {
296297
let mut proxy = Proxy::new();
297-
let request = ProxyMsg::StatusRequest.try_to_vec().unwrap();
298+
let request = borsh::to_vec(&ProxyMsg::StatusRequest).unwrap();
298299
let response = proxy.process(request);
299300
let msg = ProxyMsg::try_from_slice(&response).unwrap();
300301
assert_eq!(msg, ProxyMsg::StatusResponse(0));
@@ -305,13 +306,12 @@ mod test {
305306
let mut proxy = Proxy::new();
306307
assert_eq!(proxy.num_connections(), 0);
307308

308-
let request = ProxyMsg::ConnectByNameRequest {
309+
let request = borsh::to_vec(&ProxyMsg::ConnectByNameRequest {
309310
hostname: "api.turnkey.com".to_string(),
310311
port: 443,
311312
dns_resolvers: vec!["8.8.8.8".to_string()],
312313
dns_port: 53,
313-
}
314-
.try_to_vec()
314+
})
315315
.unwrap();
316316
let response = proxy.process(request);
317317
let msg = ProxyMsg::try_from_slice(&response).unwrap();
@@ -325,11 +325,10 @@ mod test {
325325
};
326326
let http_request = "GET / HTTP/1.1\r\nHost: api.turnkey.com\r\nConnection: close\r\n\r\n".to_string();
327327

328-
let request = ProxyMsg::WriteRequest {
328+
let request = borsh::to_vec(&ProxyMsg::WriteRequest {
329329
connection_id,
330330
data: http_request.as_bytes().to_vec(),
331-
}
332-
.try_to_vec()
331+
})
333332
.unwrap();
334333
let response = proxy.process(request);
335334
let msg: ProxyMsg = ProxyMsg::try_from_slice(&response).unwrap();
@@ -341,9 +340,9 @@ mod test {
341340
// Check that we now have an active connection
342341
assert_eq!(proxy.num_connections(), 1);
343342

344-
let request = ProxyMsg::ReadRequest { connection_id, size: 512 }
345-
.try_to_vec()
346-
.unwrap();
343+
let request =
344+
borsh::to_vec(&ProxyMsg::ReadRequest { connection_id, size: 512 })
345+
.unwrap();
347346
let response = proxy.process(request);
348347
let msg: ProxyMsg = ProxyMsg::try_from_slice(&response).unwrap();
349348
let data = match msg {

0 commit comments

Comments
 (0)