From 86185e2c91b3b70bc2987f247fd856d4417cc342 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Tue, 26 Nov 2024 14:59:26 -0800 Subject: [PATCH 01/11] testing shim with completed functions: bind, accept, and connect --- .gitmodules | 3 + .../bin/test-tiny-http/src/tiny-http-twizzler | 1 + src/bin/test-tiny-http/Cargo.toml | 11 ++ src/bin/test-tiny-http/src/main.rs | 152 ++++++++++++++++++ src/bin/test-tiny-http/src/tiny-http-twizzler | 1 + 5 files changed, 168 insertions(+) create mode 160000 src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler 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..9f8abab6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,3 +9,6 @@ [submodule "src/abi"] path = src/abi url = ../../twizzler-operating-system/abi.git +[submodule "src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler"] + path = src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler + url = git@github.com:ClariseTG/tiny-http-twizzler.git diff --git a/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler new file mode 160000 index 00000000..f69ea1db --- /dev/null +++ b/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -0,0 +1 @@ +Subproject commit f69ea1db7fb47588fb2a3fe33395431cb9daa9d4 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..635fb264 --- /dev/null +++ b/src/bin/test-tiny-http/src/main.rs @@ -0,0 +1,152 @@ +// extern crate twizzler_abi; +use std::sync::{Arc, Mutex}; +use tiny_http::{Server, Response}; +// #[path="./tiny-http-twizzler/src/shim.rs"] +// mod shim; + +use tiny_http::shim::SmolTcpStream as TcpStream; +use tiny_http::shim::SmolTcpListener as TcpListener; + +// hello world made single threaded : TINY_HTTP +fn main() { + // main + let listener = { + println!("in main!"); + TcpListener::bind("127.0.0.1:1234").unwrap() + }; + println!("bound to 127.0.0.1:1234"); + // server thread + let server = std::thread::spawn(move || { + match listener.accept() { + Ok((_socket, addr)) => println!("new client: {addr:?}"), + Err(e) => println!("couldn't get client: {e:?}"), + } + println!("accepted connection"); + }); + + // client thread + let client = std::thread::spawn (move || { + std_client(1234); + }); + server.join().unwrap(); + client.join().unwrap(); +} + +fn std_server(){ + let listener = { + let m = Arc::new(Mutex::new(0)); // unlocked state + m.lock().unwrap(); + println!("in standard server thread!"); + println!("before bind()"); + TcpListener::bind("127.0.0.1:1234").unwrap() + }; + println!("after bind()"); + // block to drop mutex after + match listener.accept() { + Ok((_socket, addr)) => println!("new client: {addr:?}"), + Err(e) => println!("couldn't get client: {e:?}"), + } + println!("accepted connection"); +} +// tiny-http server +fn tiny_http_server(){ + println!("in tiny_http server thread!"); + let server = Arc::new(Server::http("0.0.0.0:1234").unwrap()); + println!("server: now listening on port 1234"); + for rq in server.incoming_requests() { + let response = Response::from_string("hello world".to_string()); + let _ = rq.respond(response); + } +} +// std client +fn std_client(port: u16) { + println!("in client thread!"); + if let client = TcpStream::connect(("127.0.0.1",port)).unwrap() { + println!("Connected to the server!"); + } else { + println!("Couldn't connect to server..."); + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// smoltcp "server" +fn smoltcp_server(){ + println!("in server thread!"); + + // creating my own lil smoltcp server + let tcp1_rx_buffer = tcp::SocketBuffer::new(vec![0; 64]); + let tcp1_tx_buffer = tcp::SocketBuffer::new(vec![0; 128]); + let tcp1_socket = tcp::Socket::new(tcp1_rx_buffer, tcp1_tx_buffer); + let mut sockets = SocketSet::new(vec![]); + let tcp1_handle = sockets.add(tcp1_socket); + // let mut tcp_6970_active = false; + // tcp:6969: respond "hello" + let socket = sockets.get_mut::(tcp1_handle); + if !socket.is_open() { + socket.listen(1234).unwrap(); + println!("server: state: {}", socket.state()); + } + if socket.can_send() { + println!("server: tcp:1234 send greeting"); + writeln!(socket, "hello").unwrap(); + println!("server: sent hello"); + println!("server: tcp:1234 close"); + socket.close(); + } +} + +// smoltcp client +use std::net::{Ipv4Addr, IpAddr}; +use smoltcp::socket::tcp; +use smoltcp::time::Instant; +use smoltcp::iface::{Config, Interface, SocketSet}; +use smoltcp::phy::{Loopback, Medium}; +use smoltcp::wire::{EthernetAddress, IpEndpoint, IpAddress, IpCidr}; +use std::fmt::Write; +pub type SocketBuffer<'a> = smoltcp::storage::RingBuffer<'a, u8>; + +fn smoltcp_client() { + println!("in client thread!"); + // open tcp socket + let rx_buffer = SocketBuffer::new(Vec::new()); + let tx_buffer = SocketBuffer::new(Vec::new()); + let mut sock = tcp::Socket::new(rx_buffer, tx_buffer); + let config = Config::new(EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into()); // change later? + let mut device = Loopback::new(Medium::Ethernet); + let mut iface = Interface::new(config, &mut device, Instant::now()); + iface.update_ip_addrs(|ip_addrs| { + ip_addrs + .push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)) + .unwrap(); + }); + let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); + let error = sock.connect(iface.context(), (addr, 1234), 49152); // make sure local endpoint matches the server address + match error { + Err(e) => { + println!("connection error!! {}", e); + return; + }, + Ok(()) => {println!("ok");}, + } + println!("local_endpoint: {}", sock.local_endpoint().unwrap()); + println!("remote_endpoint: {}", sock.remote_endpoint().unwrap()); + // write a single static string for http req to it + let request = "GET /notes HTTP/1.1\r\n\r\n"; + println!("client state: {}", sock.state()); + if sock.may_send() { + sock.send_slice(request.as_ref()).expect("cannot send"); + println!("sent req!"); + // close connection + sock.send_slice(b"Connection: close\r\n").expect("cannot send"); + sock.send_slice(b"\r\n").expect("cannot send"); + } + if sock.may_recv() { + sock.recv(|data| { + println!("{}", std::str::from_utf8(data).unwrap_or("(invalid utf8)")); + (data.len(), ()) + }).unwrap(); + } + // receive whatever + // check that it received a response + // close it. +} 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..f69ea1db --- /dev/null +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -0,0 +1 @@ +Subproject commit f69ea1db7fb47588fb2a3fe33395431cb9daa9d4 From bfbf2ef45a942652342de82ad45166a251d2b88e Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Sat, 28 Dec 2024 22:48:59 -0800 Subject: [PATCH 02/11] commiting preliminary test of the tiny-http - smoltcp shim --- src/bin/test-tiny-http/Cargo.lock | 277 ++++++++++++++++++ src/bin/test-tiny-http/src/main.rs | 240 ++++++++------- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 3 files changed, 411 insertions(+), 108 deletions(-) create mode 100644 src/bin/test-tiny-http/Cargo.lock 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/src/main.rs b/src/bin/test-tiny-http/src/main.rs index 635fb264..2063caf2 100644 --- a/src/bin/test-tiny-http/src/main.rs +++ b/src/bin/test-tiny-http/src/main.rs @@ -1,38 +1,40 @@ // extern crate twizzler_abi; use std::sync::{Arc, Mutex}; -use tiny_http::{Server, Response}; -// #[path="./tiny-http-twizzler/src/shim.rs"] -// mod shim; -use tiny_http::shim::SmolTcpStream as TcpStream; +// #[path="./tiny-http-twizzler/src/shim.rs"] +// mod shim; use tiny_http::shim::SmolTcpListener as TcpListener; +use tiny_http::{shim::SmolTcpStream as TcpStream, Response, Server}; +use std::io::{Read, Write}; +use std::thread; // hello world made single threaded : TINY_HTTP fn main() { - // main - let listener = { - println!("in main!"); - TcpListener::bind("127.0.0.1:1234").unwrap() - }; - println!("bound to 127.0.0.1:1234"); - // server thread - let server = std::thread::spawn(move || { - match listener.accept() { - Ok((_socket, addr)) => println!("new client: {addr:?}"), - Err(e) => println!("couldn't get client: {e:?}"), + let server = Arc::new(tiny_http::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"); } - println!("accepted connection"); }); - - // client thread - let client = std::thread::spawn (move || { - std_client(1234); + let client = thread::spawn(move || { + let _ = std_client(9975); }); - server.join().unwrap(); + + thread.join().unwrap(); client.join().unwrap(); } -fn std_server(){ +fn std_server() { let listener = { let m = Arc::new(Mutex::new(0)); // unlocked state m.lock().unwrap(); @@ -49,7 +51,7 @@ fn std_server(){ println!("accepted connection"); } // tiny-http server -fn tiny_http_server(){ +fn tiny_http_server() { println!("in tiny_http server thread!"); let server = Arc::new(Server::http("0.0.0.0:1234").unwrap()); println!("server: now listening on port 1234"); @@ -58,95 +60,119 @@ fn tiny_http_server(){ let _ = rq.respond(response); } } -// std client -fn std_client(port: u16) { + +fn std_client(port: u16) -> std::io::Result<()> { println!("in client thread!"); - if let client = TcpStream::connect(("127.0.0.1",port)).unwrap() { - println!("Connected to the server!"); - } else { - println!("Couldn't connect to server..."); - } + let mut client = TcpStream::connect(("127.0.0.1", port))?; + println!("connected to server"); + let mut rx_buffer = [0; 2048]; + let msg = b"GET /notes HTTP/1.1\r\n\r\n"; + client.write(msg)?; + println!("wrote msg"); + let _bytes_read = client.read(&mut rx_buffer)?; + println!("RECEIVED:"); + println!("{}", String::from_utf8((&rx_buffer[0..2048]).to_vec()).unwrap()); + Ok(()) } +// std client +// fn std_client(port: u16) { +// println!("in client thread!"); +// let client = TcpStream::connect(("127.0.0.1", port)); +// if let Ok(SmolTcpStream) = client { +// println!("Connected to the server! {} {}", "127.0.0.1", port); +// } else { +// println!("Couldn't connect to server..."); +// } +// } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // smoltcp "server" -fn smoltcp_server(){ - println!("in server thread!"); +// fn smoltcp_server() { +// println!("in server thread!"); - // creating my own lil smoltcp server - let tcp1_rx_buffer = tcp::SocketBuffer::new(vec![0; 64]); - let tcp1_tx_buffer = tcp::SocketBuffer::new(vec![0; 128]); - let tcp1_socket = tcp::Socket::new(tcp1_rx_buffer, tcp1_tx_buffer); - let mut sockets = SocketSet::new(vec![]); - let tcp1_handle = sockets.add(tcp1_socket); - // let mut tcp_6970_active = false; - // tcp:6969: respond "hello" - let socket = sockets.get_mut::(tcp1_handle); - if !socket.is_open() { - socket.listen(1234).unwrap(); - println!("server: state: {}", socket.state()); - } - if socket.can_send() { - println!("server: tcp:1234 send greeting"); - writeln!(socket, "hello").unwrap(); - println!("server: sent hello"); - println!("server: tcp:1234 close"); - socket.close(); - } -} +// // creating my own lil smoltcp server +// let tcp1_rx_buffer = tcp::SocketBuffer::new(vec![0; 64]); +// let tcp1_tx_buffer = tcp::SocketBuffer::new(vec![0; 128]); +// let tcp1_socket = tcp::Socket::new(tcp1_rx_buffer, tcp1_tx_buffer); +// let mut sockets = SocketSet::new(vec![]); +// let tcp1_handle = sockets.add(tcp1_socket); +// // let mut tcp_6970_active = false; +// // tcp:6969: respond "hello" +// let socket = sockets.get_mut::(tcp1_handle); +// if !socket.is_open() { +// socket.listen(1234).unwrap(); +// println!("server: state: {}", socket.state()); +// } +// if socket.can_send() { +// println!("server: tcp:1234 send greeting"); +// writeln!(socket, "hello").unwrap(); +// println!("server: sent hello"); +// println!("server: tcp:1234 close"); +// socket.close(); +// } +// } -// smoltcp client -use std::net::{Ipv4Addr, IpAddr}; -use smoltcp::socket::tcp; -use smoltcp::time::Instant; -use smoltcp::iface::{Config, Interface, SocketSet}; -use smoltcp::phy::{Loopback, Medium}; -use smoltcp::wire::{EthernetAddress, IpEndpoint, IpAddress, IpCidr}; -use std::fmt::Write; -pub type SocketBuffer<'a> = smoltcp::storage::RingBuffer<'a, u8>; +// // smoltcp client +// use std::{ +// fmt::Write, +// net::{IpAddr, Ipv4Addr}, +// }; -fn smoltcp_client() { - println!("in client thread!"); - // open tcp socket - let rx_buffer = SocketBuffer::new(Vec::new()); - let tx_buffer = SocketBuffer::new(Vec::new()); - let mut sock = tcp::Socket::new(rx_buffer, tx_buffer); - let config = Config::new(EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into()); // change later? - let mut device = Loopback::new(Medium::Ethernet); - let mut iface = Interface::new(config, &mut device, Instant::now()); - iface.update_ip_addrs(|ip_addrs| { - ip_addrs - .push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)) - .unwrap(); - }); - let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); - let error = sock.connect(iface.context(), (addr, 1234), 49152); // make sure local endpoint matches the server address - match error { - Err(e) => { - println!("connection error!! {}", e); - return; - }, - Ok(()) => {println!("ok");}, - } - println!("local_endpoint: {}", sock.local_endpoint().unwrap()); - println!("remote_endpoint: {}", sock.remote_endpoint().unwrap()); - // write a single static string for http req to it - let request = "GET /notes HTTP/1.1\r\n\r\n"; - println!("client state: {}", sock.state()); - if sock.may_send() { - sock.send_slice(request.as_ref()).expect("cannot send"); - println!("sent req!"); - // close connection - sock.send_slice(b"Connection: close\r\n").expect("cannot send"); - sock.send_slice(b"\r\n").expect("cannot send"); - } - if sock.may_recv() { - sock.recv(|data| { - println!("{}", std::str::from_utf8(data).unwrap_or("(invalid utf8)")); - (data.len(), ()) - }).unwrap(); - } - // receive whatever - // check that it received a response - // close it. -} +// use smoltcp::{ +// iface::{Config, Interface, SocketSet}, +// phy::{Loopback, Medium}, +// socket::tcp, +// time::Instant, +// wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint}, +// }; +// pub type SocketBuffer<'a> = smoltcp::storage::RingBuffer<'a, u8>; + +// fn smoltcp_client() { +// println!("in client thread!"); +// // open tcp socket +// let rx_buffer = SocketBuffer::new(Vec::new()); +// let tx_buffer = SocketBuffer::new(Vec::new()); +// let mut sock = tcp::Socket::new(rx_buffer, tx_buffer); +// let config = Config::new(EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into()); // change later? +// let mut device = Loopback::new(Medium::Ethernet); +// let mut iface = Interface::new(config, &mut device, Instant::now()); +// iface.update_ip_addrs(|ip_addrs| { +// ip_addrs +// .push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)) +// .unwrap(); +// }); +// let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); +// let error = sock.connect(iface.context(), (addr, 1234), 49152); // make sure local endpoint matches the server address +// match error { +// Err(e) => { +// println!("connection error!! {}", e); +// return; +// } +// Ok(()) => { +// println!("ok"); +// } +// } +// println!("local_endpoint: {}", sock.local_endpoint().unwrap()); +// println!("remote_endpoint: {}", sock.remote_endpoint().unwrap()); +// // write a single static string for http req to it +// let request = "GET /notes HTTP/1.1\r\n\r\n"; +// println!("client state: {}", sock.state()); +// if sock.may_send() { +// sock.send_slice(request.as_ref()).expect("cannot send"); +// println!("sent req!"); +// // close connection +// sock.send_slice(b"Connection: close\r\n") +// .expect("cannot send"); +// sock.send_slice(b"\r\n").expect("cannot send"); +// } +// if sock.may_recv() { +// sock.recv(|data| { +// println!("{}", std::str::from_utf8(data).unwrap_or("(invalid utf8)")); +// (data.len(), ()) +// }) +// .unwrap(); +// } +// // receive whatever +// // check that it received a response +// // close it. +// } diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler index f69ea1db..a489a47c 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit f69ea1db7fb47588fb2a3fe33395431cb9daa9d4 +Subproject commit a489a47c905ec6d8d33c81faf09b5079d0257884 From a71590133fa10f221151ba80806d83a72d33b6af Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Tue, 7 Jan 2025 16:32:03 -0800 Subject: [PATCH 03/11] commiting basic test with tiny-http in main.rs before finding the bug that requires client to sleep --- src/bin/test-tiny-http/src/main.rs | 63 ++++++++----------- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/bin/test-tiny-http/src/main.rs b/src/bin/test-tiny-http/src/main.rs index 2063caf2..86734d1b 100644 --- a/src/bin/test-tiny-http/src/main.rs +++ b/src/bin/test-tiny-http/src/main.rs @@ -1,16 +1,16 @@ // extern crate twizzler_abi; -use std::sync::{Arc, Mutex}; - // #[path="./tiny-http-twizzler/src/shim.rs"] // mod shim; use tiny_http::shim::SmolTcpListener as TcpListener; use tiny_http::{shim::SmolTcpStream as TcpStream, Response, Server}; -use std::io::{Read, Write}; -use std::thread; +use std::{io::{Read, Write}, + sync::{Arc, Mutex}, + thread,}; +use std::net::Shutdown; // hello world made single threaded : TINY_HTTP fn main() { - let server = Arc::new(tiny_http::Server::http("127.0.0.1:9975").unwrap()); + let server = Arc::new(Server::http("127.0.0.1:9975").unwrap()); println!("Now listening on port 9975"); let thread = thread::spawn(move || { @@ -26,6 +26,7 @@ fn main() { request.respond(response).expect("Responded"); } }); + let client = thread::spawn(move || { let _ = std_client(9975); }); @@ -33,48 +34,34 @@ fn main() { thread.join().unwrap(); client.join().unwrap(); } - -fn std_server() { - let listener = { - let m = Arc::new(Mutex::new(0)); // unlocked state - m.lock().unwrap(); - println!("in standard server thread!"); - println!("before bind()"); - TcpListener::bind("127.0.0.1:1234").unwrap() - }; - println!("after bind()"); - // block to drop mutex after - match listener.accept() { - Ok((_socket, addr)) => println!("new client: {addr:?}"), - Err(e) => println!("couldn't get client: {e:?}"), - } - println!("accepted connection"); -} -// tiny-http server -fn tiny_http_server() { - println!("in tiny_http server thread!"); - let server = Arc::new(Server::http("0.0.0.0:1234").unwrap()); - println!("server: now listening on port 1234"); - for rq in server.incoming_requests() { - let response = Response::from_string("hello world".to_string()); - let _ = rq.respond(response); - } -} - fn std_client(port: u16) -> std::io::Result<()> { println!("in client thread!"); + thread::sleep(std::time::Duration::from_millis(2000)); let mut client = TcpStream::connect(("127.0.0.1", port))?; - println!("connected to server"); let mut rx_buffer = [0; 2048]; let msg = b"GET /notes HTTP/1.1\r\n\r\n"; - client.write(msg)?; - println!("wrote msg"); + let _result = client.write(msg)?; + thread::sleep(std::time::Duration::from_millis(2000)); let _bytes_read = client.read(&mut rx_buffer)?; - println!("RECEIVED:"); println!("{}", String::from_utf8((&rx_buffer[0..2048]).to_vec()).unwrap()); Ok(()) } -// std client + +fn handle_connection(mut stream: (TcpStream, std::net::SocketAddr)) { + let mut stream1 = stream.0; + let mut buffer = [0; 512]; + stream1.read(&mut buffer).unwrap(); + println!("Request: {}", String::from_utf8_lossy(&buffer[..])); + stream1.shutdown(Shutdown::Write); +} + +pub fn create_listener(listener: TcpListener) -> std::io::Result<()> { + let stream = listener.accept().unwrap(); + handle_connection(stream); + Ok(()) +} + +// OLD std client // fn std_client(port: u16) { // println!("in client thread!"); // let client = TcpStream::connect(("127.0.0.1", port)); diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler index a489a47c..7ce4916e 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit a489a47c905ec6d8d33c81faf09b5079d0257884 +Subproject commit 7ce4916e7bdef3708e9091027b144e9dbcc04416 From bcf150e2675487bcd9f85267b832c666bd731f28 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Thu, 9 Jan 2025 19:06:45 -0800 Subject: [PATCH 04/11] tcplistener and tcpstream types complete --- Cargo.lock | 244 +++++++++++++++++- Cargo.toml | 2 + .../bin/test-tiny-http/src/tiny-http-twizzler | 1 - src/bin/test-tiny-http/src/main.rs | 10 +- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 5 files changed, 247 insertions(+), 12 deletions(-) delete mode 160000 src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler diff --git a/Cargo.lock b/Cargo.lock index 1293b2c1..fd18e087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,6 +224,12 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[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" @@ -330,6 +336,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.5" @@ -497,7 +509,7 @@ dependencies = [ "serde-untagged", "serde_ignored", "serde_json", - "sha1", + "sha1 0.10.6", "shell-escape", "supports-hyperlinks", "supports-unicode", @@ -671,6 +683,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[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.20" @@ -965,6 +983,38 @@ dependencies = [ "winapi", ] +[[package]] +name = "defmt" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0" +dependencies = [ + "bitflags 1.3.2", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9f309eff1f79b3ebdf252954d90ae440599c26c2c553fe87a2d17195f2dcb" +dependencies = [ + "defmt-parser", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.85", +] + +[[package]] +name = "defmt-parser" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f" +dependencies = [ + "thiserror", +] + [[package]] name = "der" version = "0.7.9" @@ -1186,6 +1236,15 @@ dependencies = [ "log", ] +[[package]] +name = "fdlimit" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0da54a593b34c71b889ee45f5b5bb900c74148c5f7f8c6a9479ee7899f69603c" +dependencies = [ + "libc", +] + [[package]] name = "fdt" version = "0.1.5" @@ -2290,6 +2349,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -2326,6 +2394,16 @@ dependencies = [ "hashbrown 0.14.5", ] +[[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 = "heck" version = "0.4.1" @@ -2750,7 +2828,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -2867,9 +2945,12 @@ dependencies = [ [[package]] name = "limine" -version = "0.1.11" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f45c67c512034e8eb0064556e1db5da671b3ef50791cd6ac6376e7aefc0ef27e" +checksum = "846c87e24d089e8717a61098cba72b378e3525c46a87cf75b71352dcf668e68c" +dependencies = [ + "bitflags 2.6.0", +] [[package]] name = "linked_list_allocator" @@ -2919,6 +3000,12 @@ dependencies = [ "hashbrown 0.15.0", ] +[[package]] +name = "managed" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" + [[package]] name = "matchers" version = "0.1.0" @@ -3792,6 +3879,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" @@ -3827,6 +3944,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-serialize" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" + [[package]] name = "rustc-std-workspace-alloc" version = "1.0.0" @@ -3864,6 +3987,27 @@ dependencies = [ "windows-sys 0.52.0", ] +[[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.14" @@ -3906,6 +4050,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" @@ -4035,6 +4189,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" @@ -4146,6 +4309,22 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617d17f088ec733e5a6b86da6ce4cce1414e6e856d6061c16dda51cceae6f68c" +[[package]] +name = "smoltcp" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "cfg-if 1.0.0", + "defmt", + "heapless", + "libc", + "log", + "managed", +] + [[package]] name = "socket2" version = "0.4.10" @@ -4166,6 +4345,12 @@ dependencies = [ "windows-sys 0.48.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" @@ -4361,6 +4546,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.65" @@ -4450,6 +4644,26 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny_http" +version = "0.12.0" +dependencies = [ + "ascii", + "chunked_transfer", + "fdlimit", + "httpdate", + "lazy_static", + "log", + "native-tls", + "openssl", + "rustc-serialize", + "rustls", + "rustls-pemfile", + "sha1 0.6.1", + "smoltcp", + "zeroize", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -4861,6 +5075,18 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[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.2" @@ -5025,6 +5251,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 421cf0de..6d0e1eec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "src/bin/nettest", "src/bin/pager", "src/bin/mnemosyne", + "src/bin/test-tiny-http", "src/bin/stdfs_demo", "src/kernel", "src/lib/twizzler-queue-raw", @@ -41,6 +42,7 @@ initrd = [ "crate:netmgr", "crate:nettest", "crate:pager", + "crate:test-tiny-http", #"lib:twz-rt", #"lib:monitor", "crate:mnemosyne", diff --git a/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler deleted file mode 160000 index f69ea1db..00000000 --- a/src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f69ea1db7fb47588fb2a3fe33395431cb9daa9d4 diff --git a/src/bin/test-tiny-http/src/main.rs b/src/bin/test-tiny-http/src/main.rs index 86734d1b..85a23de5 100644 --- a/src/bin/test-tiny-http/src/main.rs +++ b/src/bin/test-tiny-http/src/main.rs @@ -1,6 +1,4 @@ // extern crate twizzler_abi; -// #[path="./tiny-http-twizzler/src/shim.rs"] -// mod shim; use tiny_http::shim::SmolTcpListener as TcpListener; use tiny_http::{shim::SmolTcpStream as TcpStream, Response, Server}; use std::{io::{Read, Write}, @@ -27,7 +25,7 @@ fn main() { } }); - let client = thread::spawn(move || { + let client = thread::spawn(|| { let _ = std_client(9975); }); @@ -36,13 +34,13 @@ fn main() { } fn std_client(port: u16) -> std::io::Result<()> { println!("in client thread!"); - thread::sleep(std::time::Duration::from_millis(2000)); + // thread::sleep(std::time::Duration::from_millis(1000)); 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)?; - thread::sleep(std::time::Duration::from_millis(2000)); - let _bytes_read = client.read(&mut rx_buffer)?; + // thread::sleep(std::time::Duration::from_millis(1000)); + 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 index 7ce4916e..ede91849 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit 7ce4916e7bdef3708e9091027b144e9dbcc04416 +Subproject commit ede91849c2c6654dc5dde51e36d8632ea146daa8 From f52e5957af4e774edfd3fcf1ed031cf0771776b7 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Fri, 10 Jan 2025 13:38:25 -0800 Subject: [PATCH 05/11] minor change - double checking specific numbers in the code --- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler index ede91849..11e76f30 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit ede91849c2c6654dc5dde51e36d8632ea146daa8 +Subproject commit 11e76f300f17fe63bc143447bcefa1195fafca4e From fbc1af77d6c31c949ca8b325875253c358a62ae5 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Fri, 10 Jan 2025 14:11:08 -0800 Subject: [PATCH 06/11] changed path for git submodule --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9f8abab6..35160313 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,6 +9,6 @@ [submodule "src/abi"] path = src/abi url = ../../twizzler-operating-system/abi.git -[submodule "src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler"] - path = src/bin/src/bin/test-tiny-http/src/tiny-http-twizzler - url = git@github.com:ClariseTG/tiny-http-twizzler.git +[submodule "src/bin/test-tiny-http/src/tiny-http-twizzler"] + path = src/bin/test-tiny-http/src/tiny-http-twizzler + url = git@github.com:dbittman/tiny-http-twizzler.git From 323b975a35127aa66d5f6fb293b639537433c73f Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Fri, 10 Jan 2025 14:38:16 -0800 Subject: [PATCH 07/11] changed path for git submodule --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 35160313..0efdf21f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,4 +11,4 @@ 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 = git@github.com:dbittman/tiny-http-twizzler.git + url = ../../twizzler-operating-system/tiny-http-twizzler.git \ No newline at end of file From 5a113850d0e00504cc9727a384feaffdfb67e734 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Fri, 10 Jan 2025 14:42:57 -0800 Subject: [PATCH 08/11] changed path for git submodule and took out commented stuff in main.rs --- src/bin/test-tiny-http/src/main.rs | 120 +---------------------------- 1 file changed, 1 insertion(+), 119 deletions(-) diff --git a/src/bin/test-tiny-http/src/main.rs b/src/bin/test-tiny-http/src/main.rs index 85a23de5..1d3c270b 100644 --- a/src/bin/test-tiny-http/src/main.rs +++ b/src/bin/test-tiny-http/src/main.rs @@ -2,9 +2,8 @@ use tiny_http::shim::SmolTcpListener as TcpListener; use tiny_http::{shim::SmolTcpStream as TcpStream, Response, Server}; use std::{io::{Read, Write}, - sync::{Arc, Mutex}, + sync::{Arc}, thread,}; -use std::net::Shutdown; // hello world made single threaded : TINY_HTTP fn main() { @@ -34,130 +33,13 @@ fn main() { } fn std_client(port: u16) -> std::io::Result<()> { println!("in client thread!"); - // thread::sleep(std::time::Duration::from_millis(1000)); 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)?; - // thread::sleep(std::time::Duration::from_millis(1000)); println!("{}", client.read(&mut rx_buffer)?); println!("{}", String::from_utf8((&rx_buffer[0..2048]).to_vec()).unwrap()); Ok(()) } -fn handle_connection(mut stream: (TcpStream, std::net::SocketAddr)) { - let mut stream1 = stream.0; - let mut buffer = [0; 512]; - stream1.read(&mut buffer).unwrap(); - println!("Request: {}", String::from_utf8_lossy(&buffer[..])); - stream1.shutdown(Shutdown::Write); -} - -pub fn create_listener(listener: TcpListener) -> std::io::Result<()> { - let stream = listener.accept().unwrap(); - handle_connection(stream); - Ok(()) -} - -// OLD std client -// fn std_client(port: u16) { -// println!("in client thread!"); -// let client = TcpStream::connect(("127.0.0.1", port)); -// if let Ok(SmolTcpStream) = client { -// println!("Connected to the server! {} {}", "127.0.0.1", port); -// } else { -// println!("Couldn't connect to server..."); -// } -// } - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// smoltcp "server" -// fn smoltcp_server() { -// println!("in server thread!"); - -// // creating my own lil smoltcp server -// let tcp1_rx_buffer = tcp::SocketBuffer::new(vec![0; 64]); -// let tcp1_tx_buffer = tcp::SocketBuffer::new(vec![0; 128]); -// let tcp1_socket = tcp::Socket::new(tcp1_rx_buffer, tcp1_tx_buffer); -// let mut sockets = SocketSet::new(vec![]); -// let tcp1_handle = sockets.add(tcp1_socket); -// // let mut tcp_6970_active = false; -// // tcp:6969: respond "hello" -// let socket = sockets.get_mut::(tcp1_handle); -// if !socket.is_open() { -// socket.listen(1234).unwrap(); -// println!("server: state: {}", socket.state()); -// } -// if socket.can_send() { -// println!("server: tcp:1234 send greeting"); -// writeln!(socket, "hello").unwrap(); -// println!("server: sent hello"); -// println!("server: tcp:1234 close"); -// socket.close(); -// } -// } - -// // smoltcp client -// use std::{ -// fmt::Write, -// net::{IpAddr, Ipv4Addr}, -// }; - -// use smoltcp::{ -// iface::{Config, Interface, SocketSet}, -// phy::{Loopback, Medium}, -// socket::tcp, -// time::Instant, -// wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint}, -// }; -// pub type SocketBuffer<'a> = smoltcp::storage::RingBuffer<'a, u8>; -// fn smoltcp_client() { -// println!("in client thread!"); -// // open tcp socket -// let rx_buffer = SocketBuffer::new(Vec::new()); -// let tx_buffer = SocketBuffer::new(Vec::new()); -// let mut sock = tcp::Socket::new(rx_buffer, tx_buffer); -// let config = Config::new(EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into()); // change later? -// let mut device = Loopback::new(Medium::Ethernet); -// let mut iface = Interface::new(config, &mut device, Instant::now()); -// iface.update_ip_addrs(|ip_addrs| { -// ip_addrs -// .push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)) -// .unwrap(); -// }); -// let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); -// let error = sock.connect(iface.context(), (addr, 1234), 49152); // make sure local endpoint matches the server address -// match error { -// Err(e) => { -// println!("connection error!! {}", e); -// return; -// } -// Ok(()) => { -// println!("ok"); -// } -// } -// println!("local_endpoint: {}", sock.local_endpoint().unwrap()); -// println!("remote_endpoint: {}", sock.remote_endpoint().unwrap()); -// // write a single static string for http req to it -// let request = "GET /notes HTTP/1.1\r\n\r\n"; -// println!("client state: {}", sock.state()); -// if sock.may_send() { -// sock.send_slice(request.as_ref()).expect("cannot send"); -// println!("sent req!"); -// // close connection -// sock.send_slice(b"Connection: close\r\n") -// .expect("cannot send"); -// sock.send_slice(b"\r\n").expect("cannot send"); -// } -// if sock.may_recv() { -// sock.recv(|data| { -// println!("{}", std::str::from_utf8(data).unwrap_or("(invalid utf8)")); -// (data.len(), ()) -// }) -// .unwrap(); -// } -// // receive whatever -// // check that it received a response -// // close it. -// } From acf0ab6ee6493493f61e45ed18e65766e6916637 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Fri, 10 Jan 2025 21:52:21 -0800 Subject: [PATCH 09/11] small changes in cargo.toml and lib.rs within tiny-http --- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler index 11e76f30..7efd6e3e 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit 11e76f300f17fe63bc143447bcefa1195fafca4e +Subproject commit 7efd6e3e6d52d7deec7f7e4707e56ad4ddc3632f From 8abc47ffb9a49260f3de1e3b297184d0e0bcbbec Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Sat, 11 Jan 2025 12:49:30 -0800 Subject: [PATCH 10/11] update tiny-http cargo.toml --- src/bin/test-tiny-http/src/tiny-http-twizzler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/test-tiny-http/src/tiny-http-twizzler b/src/bin/test-tiny-http/src/tiny-http-twizzler index 7efd6e3e..5ec73747 160000 --- a/src/bin/test-tiny-http/src/tiny-http-twizzler +++ b/src/bin/test-tiny-http/src/tiny-http-twizzler @@ -1 +1 @@ -Subproject commit 7efd6e3e6d52d7deec7f7e4707e56ad4ddc3632f +Subproject commit 5ec737478b9a7f0804f22ffef7a229c10bdc540a From bb08942c8a7b2ee8d09cba3857da9aba5219c863 Mon Sep 17 00:00:00 2001 From: ananyabalagere Date: Sun, 12 Jan 2025 12:46:46 -0800 Subject: [PATCH 11/11] update cargo.toml and xtask build --- Cargo.toml | 5 ----- tools/xtask/src/build.rs | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 24217738..7a3f9c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,12 +54,7 @@ initrd = [ "crate:bootstrap", "crate:init", "crate:devmgr", - "crate:netmgr", - "crate:nettest", - "crate:pager", "crate:test-tiny-http", - #"lib:twz-rt", - #"lib:monitor", "crate:etl_twizzler", "crate:virtio", "crate:monitor", 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()),