From 734971b8832082775fc843861d3068983602c5cd Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 5 Aug 2025 13:41:36 -0400 Subject: [PATCH] successfully loaded content via Tor --- Cargo.toml | 2 +- src/net.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/tests.rs | 13 +++++++++++ src/ui.rs | 1 + 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ca265e..c62a8f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] iced = { git = "https://github.com/iced-rs/iced", branch = "master", features = ["image", "markdown", "svg"] } -reqwest = { version = "0.12", features= ["blocking"]} +reqwest = { version = "0.12", features= ["blocking","socks"]} rss = "2.0" web-sys = "0.3.70" mdka = "1.2.10" #Not Sure if this is useful... diff --git a/src/net.rs b/src/net.rs index 8250aa9..2e92892 100644 --- a/src/net.rs +++ b/src/net.rs @@ -1,9 +1,69 @@ use core::panic; use iced::widget::image::Handle; use rss::{Channel}; -use reqwest::{self, blocking::Client, header::USER_AGENT}; +use reqwest::{self, blocking::Client, header::USER_AGENT, Error, Proxy}; use scraper::{Html, Selector}; +const DEFAULT_TOR_PROXY: &str = "socks5h://127.0.0.1:9050"; +const DEFAULT_I2P_PROXY: &str = "socks5h://127.0.0.1:4447"; + +enum Network{ + Clearnet, + Tor, + I2P +} + +fn get_client(network: Network) -> Result{ + //in the long run, support for fancy things like arti & user-configurable proxies will be important, nevermind other networks like reticulum! + match network { + Network::Clearnet => { + return Ok(Client::new()); + } + Network::Tor => { + match Client::builder().proxy(Proxy::http(DEFAULT_TOR_PROXY).unwrap()).build() { + Ok(client) => {return Ok(client);} + Err(e) => {return Err(e);} + } + } + Network::I2P => { + match Client::builder().proxy(Proxy::http(DEFAULT_I2P_PROXY).unwrap()).build() { + Ok(client) => {return Ok(client);} + Err(e) => {return Err(e);} + } + + } + } +} + +pub fn get_onion_content(url: &str) -> Option { + match Client::builder().proxy( + Proxy::http(DEFAULT_TOR_PROXY).unwrap() + ).build() { + Ok(client) => { + let res = client.get(url) + .header(USER_AGENT,"RSS Reader") + .send(); + match res { + Ok(resp) => { + match resp.text() { + Ok(body) => {return Some(body);} + Err(_) => {return None;} + } + } + Err(e) => { + println!("Error loading content via Tor\nError:{}",e); + return None; + } + } + } + Err(e) => { + println!("Failed to get Tor client\nError:{}",e); + return None; + } + } + +} + fn get_content(url: &str) -> Option { let client = Client::new(); let res = client.get(url) diff --git a/src/tests.rs b/src/tests.rs index 6730f7e..930ffd2 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -7,6 +7,19 @@ fn get_feed_test(){ } +#[test] +fn tor_gabe() { + let onion_gabe = net::get_onion_content("http://gabriel262me3lgv3w7xohtesg3laoojmtye644pwirhdm73qmedmsqd.onion/rss"); + match onion_gabe { + Some(b) => { + println!("Successfully loaded over Tor:\n{}",b); + } + None => { + panic!("Failed to load via Tor") + } + } +} + #[test] fn load_feeds() { let url = "https://gabe.rocks"; diff --git a/src/ui.rs b/src/ui.rs index 8b9d073..bf228d2 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -145,6 +145,7 @@ fn view(state: &State) -> Element<'_, Message> { Page::AllItems => item_list(&state), Page::ItemView => item_view(&state), Page::Testing => testing(&state), + _ => {home(&state)} } }