pub async fn run(context: SharedContext) -> io::Result<()> {
    let local_addr = context.config().local.as_ref().expect("Missing local config");
    let bind_addr = local_addr.bind_addr(&*context).await?;

    let servers: PingBalancer<ServerScore> = PingBalancer::new(context, ServerType::Tcp).await;

    let make_service = make_service_fn(|socket: &AddrStream| {
        let client_addr = socket.remote_addr();
        let svr_score = servers.pick_server();

        async move {
            Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
                server_dispatch(req, svr_score.clone(), client_addr)
            }))
        }
    });

    let server = Server::bind(&bind_addr).serve(make_service);
    info!("ShadowSocks HTTP Listening on {}", server.local_addr());

    if let Err(err) = server.await {
        use std::io::Error;

        error!("Hyper Server error: {}", err);
        return Err(Error::new(ErrorKind::Other, err));
    }

    Ok(())
}
/// Starts a TCP local server with HTTP proxy protocol
Starts a TCP local server with HTTP proxy protocol
Starts a TCP local server with HTTP proxy protocol
pub async fn run(context: SharedContext) -> io::Result<()> {
    let local_addr = context.config().local.as_ref().expect("Missing local config");
    let bind_addr = local_addr.bind_addr(&*context).await?;
    let servers: PingBalancer<ServerScore> = PingBalancer::new(context, ServerType::Tcp).await;
    let make_service = make_service_fn(|socket: &AddrStream| {
        let client_addr = socket.remote_addr();
        let svr_score = servers.pick_server();
        async move {
            Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
                server_dispatch(req, svr_score.clone(), client_addr)
            }))
        }
    });
    let server = Server::bind(&bind_addr).serve(make_service);
    info!("ShadowSocks HTTP Listening on {}", server.local_addr());
    if let Err(err) = server.await {
        use std::io::Error;
        error!("Hyper Server error: {}", err);
        return Err(Error::new(ErrorKind::Other, err));
    }
    Ok(())
}
pub async fn run ( context : SharedContext ) -> io :: Result < ( ) > { let local_addr = context . config ( ) . local . as_ref ( ) . expect ( " " ) ; let bind_addr = local_addr . bind_addr ( & * context ) . await ? ; let servers : PingBalancer < ServerScore > = PingBalancer :: new ( context , ServerType :: Tcp ) . await ; let make_service = make_service_fn ( | socket : & AddrStream | { let client_addr = socket . remote_addr ( ) ; let svr_score = servers . pick_server ( ) ; async move { Ok :: < _ , Infallible > ( service_fn ( move | req : Request < Body > | { server_dispatch ( req , svr_score . clone ( ) , client_addr ) } ) ) } } ) ; let server = Server :: bind ( & bind_addr ) . serve ( make_service ) ; info ! ( " " server local_addr ( ) ) ; if let Err ( err ) = server . await { use std :: io :: Error ; error ! ( " " err ) ; return Err ( Error :: new ( ErrorKind :: Other , err ) ) ; } Ok ( ( ) ) }
Starts a TCP local server with HTTP proxy protocol
Starts a TCP local server with HTTP proxy protocol
context
SharedContext
context
SharedContext