main.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use anyhow::Result;
  19. use arti_client::{BootstrapBehavior, TorClient};
  20. use async_std::io::{ReadExt, WriteExt};
  21. #[async_std::main]
  22. async fn main() -> Result<()> {
  23. //const ADDR: &str = "p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion";
  24. const ADDR: &str = "parazyd.org";
  25. let mut log_cfg = simplelog::ConfigBuilder::new();
  26. simplelog::TermLogger::init(
  27. simplelog::LevelFilter::Debug,
  28. log_cfg.build(),
  29. simplelog::TerminalMode::Mixed,
  30. simplelog::ColorChoice::Auto,
  31. )?;
  32. let tor_client = TorClient::builder()
  33. .bootstrap_behavior(BootstrapBehavior::OnDemand)
  34. .create_unbootstrapped()?;
  35. let mut stream = tor_client.connect((ADDR, 80)).await?;
  36. let req = format!("GET / HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n", ADDR);
  37. stream.write_all(req.as_bytes()).await?;
  38. stream.flush().await?;
  39. let mut buf = vec![];
  40. stream.read_to_end(&mut buf).await?;
  41. println!("{}", String::from_utf8_lossy(&buf));
  42. Ok(())
  43. }