Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 committed Apr 19, 2024
1 parent 5d7de56 commit 9fe20e8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
20 changes: 20 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
unstable_features = true

version = "Two"

group_imports = "StdExternalCrate"
imports_granularity = "Crate"
reorder_imports = true

wrap_comments = true
normalize_comments = true

reorder_impl_items = true
condense_wildcard_suffixes = true
enum_discrim_align_threshold = 20
use_field_init_shorthand = true
overflow_delimited_expr = true

format_strings = true
format_code_in_doc_comments = true
format_macro_matchers = true
3 changes: 1 addition & 2 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ pub fn start(args: BootArgs) -> crate::Result<()> {
/// Stop the daemon
#[cfg(target_family = "unix")]
pub fn stop() -> crate::Result<()> {
use nix::sys::signal;
use nix::unistd::Pid;
use nix::{sys::signal, unistd::Pid};

check_root();

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ mod proxy;
mod update;
mod util;

use clap::{Args, Parser, Subcommand};
use std::net::SocketAddr;

use clap::{Args, Parser, Subcommand};

type Result<T, E = error::Error> = std::result::Result<T, E>;

#[derive(Parser)]
Expand Down Expand Up @@ -75,6 +76,7 @@ pub enum ProxyType {

impl std::str::FromStr for ProxyType {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"http" => Ok(Self::Http),
Expand All @@ -86,11 +88,9 @@ impl std::str::FromStr for ProxyType {

// To try this example:
// 1. cargo run --example http_proxy
// 2. config http_proxy in command line
// $ export http_proxy=http://127.0.0.1:8100
// 2. config http_proxy in command line $ export http_proxy=http://127.0.0.1:8100
// $ export https_proxy=http://127.0.0.1:8100
// 3. send requests
// $ curl -i https://www.some_domain.com/
// 3. send requests $ curl -i https://www.some_domain.com/
fn main() -> crate::Result<()> {
let opt = Opt::parse();

Expand Down
40 changes: 21 additions & 19 deletions src/proxy/http.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
use crate::proxy::auth;
use crate::BootArgs;
use std::{
net::{IpAddr, Ipv6Addr, SocketAddr, ToSocketAddrs},
sync::Arc,
};

use bytes::Bytes;
use cidr::Ipv6Cidr;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use hyper_util::rt::TokioIo;
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::{
server::conn::http1, service::service_fn, upgrade::Upgraded, Method, Request, Response,
};
use hyper_util::{
client::legacy::{connect::HttpConnector, Client},
rt::{TokioExecutor, TokioIo},
};
use rand::Rng;
use tokio::sync::Semaphore;

use std::net::{IpAddr, Ipv6Addr, SocketAddr, ToSocketAddrs};
use std::sync::Arc;
use tokio::{
net::{TcpListener, TcpSocket, TcpStream},
sync::Semaphore,
};

use super::error::ProxyError;
use bytes::Bytes;
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::upgrade::Upgraded;
use hyper::{Method, Request, Response};
use tokio::net::{TcpListener, TcpSocket, TcpStream};
use crate::{proxy::auth, BootArgs};

pub async fn run(args: BootArgs) -> crate::Result<()> {
tracing::info!("Listening on http://{}", args.bind);
Expand Down Expand Up @@ -151,8 +153,8 @@ impl HttpProxy {
.boxed()
}

// Create a TCP connection to host:port, build a tunnel between the connection and
// the upgraded connection
// Create a TCP connection to host:port, build a tunnel between the connection
// and the upgraded connection
async fn tunnel(&self, upgraded: Upgraded, addr_str: String) -> std::io::Result<()> {
for addr in addr_str.to_socket_addrs()? {
match self.try_connect(addr).await {
Expand Down
3 changes: 2 additions & 1 deletion src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ mod error;
mod http;
mod socks5;

use crate::BootArgs;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

use crate::BootArgs;

#[tokio::main(flavor = "multi_thread")]
pub async fn run(args: BootArgs) -> crate::Result<()> {
if args.debug {
Expand Down

0 comments on commit 9fe20e8

Please sign in to comment.