From 8361676ba599425290570ad4d7040858dd9af130 Mon Sep 17 00:00:00 2001 From: ananyabalagere <124413045+ananyabalagere@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:30:13 -0800 Subject: [PATCH] Bridging smoltcp and tiny-http (#240) * testing shim with completed functions: bind, accept, and connect * commiting preliminary test of the tiny-http - smoltcp shim * commiting basic test with tiny-http in main.rs before finding the bug that requires client to sleep * tcplistener and tcpstream types complete * minor change - double checking specific numbers in the code * changed path for git submodule * changed path for git submodule * changed path for git submodule and took out commented stuff in main.rs * small changes in cargo.toml and lib.rs within tiny-http * update tiny-http cargo.toml * update cargo.toml and xtask build --- .gitmodules | 3 + Cargo.lock | 123 +++++++- Cargo.toml | 2 + src/bin/test-tiny-http/Cargo.lock | 277 ++++++++++++++++++ src/bin/test-tiny-http/Cargo.toml | 11 + src/bin/test-tiny-http/src/main.rs | 45 +++ src/bin/test-tiny-http/src/tiny-http-twizzler | 1 + tools/xtask/src/build.rs | 2 + 8 files changed, 462 insertions(+), 2 deletions(-) create mode 100644 src/bin/test-tiny-http/Cargo.lock create mode 100644 src/bin/test-tiny-http/Cargo.toml create mode 100644 src/bin/test-tiny-http/src/main.rs create mode 160000 src/bin/test-tiny-http/src/tiny-http-twizzler diff --git a/.gitmodules b/.gitmodules index a771e732..0efdf21f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,3 +9,6 @@ [submodule "src/abi"] path = src/abi url = ../../twizzler-operating-system/abi.git +[submodule "src/bin/test-tiny-http/src/tiny-http-twizzler"] + path = src/bin/test-tiny-http/src/tiny-http-twizzler + url = ../../twizzler-operating-system/tiny-http-twizzler.git \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index fe1171b8..888fe126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,6 +228,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + [[package]] name = "async-executor" version = "1.9.1" @@ -551,7 +557,7 @@ dependencies = [ "serde-untagged", "serde_ignored", "serde_json", - "sha1", + "sha1 0.10.6", "shell-escape", "supports-hyperlinks", "supports-unicode", @@ -747,6 +753,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chunked_transfer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" + [[package]] name = "clap" version = "4.5.23" @@ -3193,7 +3205,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -4479,6 +4491,36 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if 1.0.0", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + [[package]] name = "rprompt" version = "1.0.5" @@ -4560,6 +4602,27 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "rustversion" version = "1.0.19" @@ -4602,6 +4665,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "sec1" version = "0.7.3" @@ -4754,6 +4827,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + [[package]] name = "sha1" version = "0.10.6" @@ -4891,6 +4973,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -5113,6 +5201,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-tiny-http" +version = "0.1.0" +dependencies = [ + "smoltcp", + "tiny_http", + "tracing", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -5693,6 +5790,18 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.4" @@ -5913,6 +6022,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 45c3095c..f397137b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "src/bin/devmgr", "src/bin/etl_twizzler", "src/bin/mnemosyne", + "src/bin/test-tiny-http", "src/bin/random_validation", "src/bin/genrandom", "src/bin/randtest", @@ -56,6 +57,7 @@ initrd = [ "crate:bootstrap", "crate:init", "crate:devmgr", + "crate:test-tiny-http", "crate:etl_twizzler", "crate:virtio", "crate:monitor", diff --git a/src/bin/test-tiny-http/Cargo.lock b/src/bin/test-tiny-http/Cargo.lock new file mode 100644 index 00000000..390801e4 --- /dev/null +++ b/src/bin/test-tiny-http/Cargo.lock @@ -0,0 +1,277 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chunked_transfer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" + +[[package]] +name = "defmt" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" +dependencies = [ + "bitflags", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" +dependencies = [ + "defmt-parser", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "defmt-parser" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" +dependencies = [ + "thiserror", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.167" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "managed" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "smoltcp" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97" +dependencies = [ + "bitflags", + "byteorder", + "cfg-if", + "defmt", + "heapless", + "libc", + "log", + "managed", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "2.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "test-tiny-http" +version = "0.1.0" +dependencies = [ + "smoltcp", + "tiny_http", + "tracing", +] + +[[package]] +name = "thiserror" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiny_http" +version = "0.12.0" +dependencies = [ + "ascii", + "chunked_transfer", + "httpdate", + "lazy_static", + "log", + "smoltcp", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" diff --git a/src/bin/test-tiny-http/Cargo.toml b/src/bin/test-tiny-http/Cargo.toml new file mode 100644 index 00000000..9989c6b1 --- /dev/null +++ b/src/bin/test-tiny-http/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "test-tiny-http" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tiny_http = { path = "src/tiny-http-twizzler" } +smoltcp = "0.11.0" +tracing = "0.1" diff --git a/src/bin/test-tiny-http/src/main.rs b/src/bin/test-tiny-http/src/main.rs new file mode 100644 index 00000000..1d3c270b --- /dev/null +++ b/src/bin/test-tiny-http/src/main.rs @@ -0,0 +1,45 @@ +// extern crate twizzler_abi; +use tiny_http::shim::SmolTcpListener as TcpListener; +use tiny_http::{shim::SmolTcpStream as TcpStream, Response, Server}; +use std::{io::{Read, Write}, + sync::{Arc}, + thread,}; + +// hello world made single threaded : TINY_HTTP +fn main() { + let server = Arc::new(Server::http("127.0.0.1:9975").unwrap()); + println!("Now listening on port 9975"); + + let thread = thread::spawn(move || { + for request in server.incoming_requests() { + println!( + "received request! method: {:?}, url: {:?}, headers: {:?}", + request.method(), + request.url(), + request.headers() + ); + + let response = Response::from_string("hello world"); + request.respond(response).expect("Responded"); + } + }); + + let client = thread::spawn(|| { + let _ = std_client(9975); + }); + + thread.join().unwrap(); + client.join().unwrap(); +} +fn std_client(port: u16) -> std::io::Result<()> { + println!("in client thread!"); + let mut client = TcpStream::connect(("127.0.0.1", port))?; + let mut rx_buffer = [0; 2048]; + let msg = b"GET /notes HTTP/1.1\r\n\r\n"; + let _result = client.write(msg)?; + println!("{}", client.read(&mut rx_buffer)?); + println!("{}", String::from_utf8((&rx_buffer[0..2048]).to_vec()).unwrap()); + Ok(()) +} + + diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler new file mode 160000 index 00000000..5ec73747 --- /dev/null +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -0,0 +1 @@ +Subproject commit 5ec737478b9a7f0804f22ffef7a229c10bdc540a diff --git a/tools/xtask/src/build.rs b/tools/xtask/src/build.rs index 506082a1..934c4de4 100644 --- a/tools/xtask/src/build.rs +++ b/tools/xtask/src/build.rs @@ -295,6 +295,8 @@ fn maybe_build_tests_dynamic<'a>( "twizzler-net" => None, "twizzler-futures" => None, "twizzler-async" => None, + "tiny_http" => None, + "test-tiny-http" => None, // for now -- tests aren't ready in this crate to run. Too many todo!()'s still. //"twizzler" => None, _ => Some(p.name().to_string()),