diff --git a/Cargo.lock b/Cargo.lock index ac5f3c2..73d4b2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1245,16 +1245,17 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", "getrandom", "libc", "spin", "untrusted", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] diff --git a/README.md b/README.md new file mode 100644 index 0000000..cd8f843 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +## Ideas + +* HTTP3 support +* First show all results, then sort them on server, hide old results and show new sorted ones +* Check if results have already been sent and don't send them again diff --git a/src/main.rs b/src/main.rs index cf0cf3f..da00ece 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ // Found no other way to make this work use crate::engines::engine_base::engine_base::EngineBase; -use std::io::{Read, Write}; +use std::io::{BufRead, BufReader, Read, Write}; use std::net::TcpStream; use std::str; use std::sync::Arc; @@ -28,7 +28,9 @@ use std::time::Instant; use engines::brave::brave::Brave; use futures::lock::Mutex; +use futures::StreamExt; use lazy_static::lazy_static; +use reqwest::ClientBuilder; use rocket::response::{ content::{RawCss, RawHtml}, stream::TextStream, @@ -98,7 +100,7 @@ async fn slowresponse() -> TextStream![String] { #[get("/searchquery?")] async fn hello<'a>(query: &str) -> RawHtml { - let query_box = Box::new(query.to_string()); + let query_box = query.to_string(); let now = Arc::new(Box::new(Instant::now())); let completed_ref = Arc::new(Mutex::new(false)); @@ -202,44 +204,66 @@ async fn hello<'a>(query: &str) -> RawHtml { let mut conn = rustls::ClientConnection::new(Arc::new(config), server_name).unwrap(); let mut sock = TcpStream::connect("search.brave.com:443").unwrap(); let mut tls = rustls::Stream::new(&mut conn, &mut sock); + let now_sock = Instant::now(); tls.write_all( - concat!( - "GET /search?q=test&show_local=0&source=unlocalise HTTP/1.1\r\n", - "Host: search.brave.com\r\n", - "Connection: close\r\n", - "Accept-Encoding: identity\r\n", - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.3\r\n", - "\r\n", + format!( + "GET /search?q={}&show_local=0&source=unlocalise HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\nAccept-Encoding: identity\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.3\r\n\r\n", + query_box, ) .as_bytes(), ) .unwrap(); - loop { - let mut buf = [0; 65535]; - tls.conn.complete_io(tls.sock); - let n = tls.conn.reader().read(&mut buf); + let nw = Instant::now(); - // dbg!(&n); + let client = ClientBuilder::new().build().unwrap(); + let resposne = client + .get("https://www.bing.com/search?q=test") + .send() + .await + .unwrap(); - if n.is_ok() { - let n = n.unwrap(); - if n == 0 { - break; - } - // println!("{}", String::from_utf8_lossy(&buf)); - let mut brave = ddg_ref_writer.lock().await; + dbg!(nw.elapsed()); - if let Some(result) = brave.parse_packet(buf.iter()) { - println!("Brave: {}", now_ref.elapsed().as_millis()); - brave.add_result(result); + let mut stream = resposne.bytes_stream(); + while let Some(chunk) = stream.next().await { + let chunk = chunk.unwrap(); - drop(brave); - tokio::task::yield_now().await; - } - } + println!("{}", "========"); + dbg!(nw.elapsed()); + println!("{}", String::from_utf8_lossy(&chunk)); } + dbg!(nw.elapsed()); + + // loop { + // let mut buf = [0; 16384]; + // let n = tls.conn.reader().read(&mut buf); + // + // // dbg!(&n); + // + // if n.is_ok() { + // let n = n.unwrap(); + // if n == 0 { + // break; + // } + // // println!("{}", String::from_utf8_lossy(&buf)); + // // let mut brave = ddg_ref_writer.lock().await; + // + // dbg!(nw.elapsed()); + // + // // if let Some(result) = brave.parse_packet(buf.iter()) { + // // // println!("Brave: {}", now_ref.elapsed().as_millis()); + // // brave.add_result(result); + // // + // // drop(brave); + // // tokio::task::yield_now().await; + // // } + // } else { + // tls.conn.complete_io(tls.sock); + // } + // } + let mut completed = completed_ref_writer.lock().await; *completed = true; }); @@ -255,8 +279,8 @@ async fn hello<'a>(query: &str) -> RawHtml { let len = ddg.results.len(); if len == 0 { - drop(ddg); - tokio::task::yield_now().await; + drop(ddg); + tokio::task::yield_now().await; continue }