successfully loaded content via Tor

This commit is contained in:
Gabriel 2025-08-05 13:41:36 -04:00
parent afd34b416a
commit 734971b883
4 changed files with 76 additions and 2 deletions

View file

@ -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...

View file

@ -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<Client,Error>{
//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<String> {
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<String> {
let client = Client::new();
let res = client.get(url)

View file

@ -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";

View file

@ -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)}
}
}