Skip to content

Commit

Permalink
Minor comment tweaks, bumps borsh to v1 in qos_net
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Jun 27, 2024
1 parent d290dfb commit 310ea4f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 138 deletions.
95 changes: 9 additions & 86 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/qos_core/src/io/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ mod test {
fn stream_implements_read_write_traits() {
let socket_server_path = "./stream_implements_read_write_traits.sock";

// Start a barebone socket server which replies "Roger that." to any
// incoming request
// Start a simple socket server which replies "PONG" to any incoming
// request
let mut server =
HarakiriPongServer::new(socket_server_path.to_string());
thread::spawn(move || {
Expand Down
2 changes: 1 addition & 1 deletion src/qos_net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
qos_core = { path = "../qos_core", default-features = false }

borsh = { version = "0.10" }
borsh = { version = "1.0", features = ["std", "derive"] , default-features = false}
serde = { version = "1", features = ["derive"], default-features = false }
hickory-resolver = { version = "0.24.1", features = ["tokio-runtime"], default-features = false, optional = true}
rand = { version = "0.8.5", default-features = false, optional = true }
Expand Down
6 changes: 3 additions & 3 deletions src/qos_net/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const PORT: &str = "port";
/// "usock"
pub const USOCK: &str = "usock";

/// CLI options for starting up the enclave server.
/// CLI options for starting up the proxy.
#[derive(Default, Clone, Debug, PartialEq)]
struct ProxyOpts {
parsed: Parser,
Expand Down Expand Up @@ -55,10 +55,10 @@ impl ProxyOpts {
}
}

/// Enclave server CLI.
/// Proxy CLI.
pub struct CLI;
impl CLI {
/// Execute the enclave server CLI with the environment args.
/// Execute the enclave proxy CLI with the environment args.
pub fn execute() {
let mut args: Vec<String> = env::args().collect();
let opts = ProxyOpts::new(&mut args);
Expand Down
29 changes: 14 additions & 15 deletions src/qos_net/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Protocol proxy for our remote QOS net proxy
use std::io::{Read, Write};

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshDeserialize;
use qos_core::server;

use crate::{
Expand Down Expand Up @@ -214,9 +214,10 @@ impl Proxy {
impl server::RequestProcessor for Proxy {
fn process(&mut self, req_bytes: Vec<u8>) -> Vec<u8> {
if req_bytes.len() > MAX_ENCODED_MSG_LEN {
return ProxyMsg::ProxyError(QosNetError::OversizedPayload)
.try_to_vec()
.expect("ProtocolMsg can always be serialized. qed.");
return borsh::to_vec(&ProxyMsg::ProxyError(
QosNetError::OversizedPayload,
))
.expect("ProtocolMsg can always be serialized. qed.");
}

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

resp.try_to_vec()
borsh::to_vec(&resp)
.expect("Protocol message can always be serialized. qed!")
}
}
Expand All @@ -294,7 +295,7 @@ mod test {
#[test]
fn simple_status_request() {
let mut proxy = Proxy::new();
let request = ProxyMsg::StatusRequest.try_to_vec().unwrap();
let request = borsh::to_vec(&ProxyMsg::StatusRequest).unwrap();
let response = proxy.process(request);
let msg = ProxyMsg::try_from_slice(&response).unwrap();
assert_eq!(msg, ProxyMsg::StatusResponse(0));
Expand All @@ -305,13 +306,12 @@ mod test {
let mut proxy = Proxy::new();
assert_eq!(proxy.num_connections(), 0);

let request = ProxyMsg::ConnectByNameRequest {
let request = borsh::to_vec(&ProxyMsg::ConnectByNameRequest {
hostname: "api.turnkey.com".to_string(),
port: 443,
dns_resolvers: vec!["8.8.8.8".to_string()],
dns_port: 53,
}
.try_to_vec()
})
.unwrap();
let response = proxy.process(request);
let msg = ProxyMsg::try_from_slice(&response).unwrap();
Expand All @@ -325,11 +325,10 @@ mod test {
};
let http_request = "GET / HTTP/1.1\r\nHost: api.turnkey.com\r\nConnection: close\r\n\r\n".to_string();

let request = ProxyMsg::WriteRequest {
let request = borsh::to_vec(&ProxyMsg::WriteRequest {
connection_id,
data: http_request.as_bytes().to_vec(),
}
.try_to_vec()
})
.unwrap();
let response = proxy.process(request);
let msg: ProxyMsg = ProxyMsg::try_from_slice(&response).unwrap();
Expand All @@ -341,9 +340,9 @@ mod test {
// Check that we now have an active connection
assert_eq!(proxy.num_connections(), 1);

let request = ProxyMsg::ReadRequest { connection_id, size: 512 }
.try_to_vec()
.unwrap();
let request =
borsh::to_vec(&ProxyMsg::ReadRequest { connection_id, size: 512 })
.unwrap();
let response = proxy.process(request);
let msg: ProxyMsg = ProxyMsg::try_from_slice(&response).unwrap();
let data = match msg {
Expand Down
Loading

0 comments on commit 310ea4f

Please sign in to comment.