/// Builds a stack that accepts connections. Connections to the proxy port are diverted to the
/// 'direct' stack; otherwise connections are associated with a policy and passed to the inner
/// stack.
Builds a stack that accepts connections. Connections to the proxy port are diverted to the
'direct' stack; otherwise connections are associated with a policy and passed to the inner
stack.
Builds a stack that accepts connections . Connections to the proxy port are diverted to the ' direct ' stack ; otherwise connections are associated with a policy and passed to the inner stack .
pub(crate) fn push_accept<T, I, NSvc, D, DSvc>(
        self,
        proxy_port: u16,
        policies: impl CheckPolicy + Clone + Send + Sync + 'static,
        direct: D,
    ) -> Inbound<svc::ArcNewTcp<T, I>>
    where
        T: svc::Param<Remote<ClientAddr>> + svc::Param<OrigDstAddr>,
        T: Clone + Send + 'static,
        I: io::AsyncRead + io::AsyncWrite + io::Peek + io::PeerAddr,
        I: Debug + Send + Sync + Unpin + 'static,
        N: svc::NewService<Accept, Service = NSvc> + Clone + Send + Sync + Unpin + 'static,
        NSvc: svc::Service<I, Response = ()>,
        NSvc: Send + Unpin + 'static,
        NSvc::Error: Into<Error>,
        NSvc::Future: Send,
        D: svc::NewService<T, Service = DSvc> + Clone + Send + Sync + Unpin + 'static,
        DSvc: svc::Service<I, Response = ()> + Send + 'static,
        DSvc::Error: Into<Error>,
        DSvc::Future: Send,
    {
        self.map_stack(|cfg, rt, accept| {
            accept
                .push_switch(
                    // Switch to the `direct` stack when a connection's original destination is the
                    // proxy's inbound port. Otherwise, check that connections are allowed on the
                    // port and obtain the port's policy before processing the connection.
                    move |t: T| -> Result<_, Error> {
                        let OrigDstAddr(addr) = t.param();
                        if addr.port() == proxy_port {
                            return Ok(svc::Either::B(t));
                        }
                        let orig_dst_addr = t.param();
                        let policy = policies.check_policy(orig_dst_addr)?;
                        tracing::debug!(?policy, "Accepted");
                        Ok(svc::Either::A(Accept {
                            client_addr: t.param(),
                            orig_dst_addr,
                            policy,
                        }))
                    },
                    direct,
                )
                .check_new_service::<T, I>()
                .push_request_filter(cfg.allowed_ips.clone())
                .push(rt.metrics.tcp_errors.to_layer())
                .check_new_service::<T, I>()
                .instrument(|t: &T| {
                    let OrigDstAddr(addr) = t.param();
                    info_span!("server", port = addr.port())
                })
                .push_on_service(svc::BoxService::layer())
                .push(svc::ArcNewService::layer())
        })
    }
pub ( crate ) fn push_accept < T , I , NSvc , D , DSvc > ( self , proxy_port : u16 , policies : impl CheckPolicy + Clone + Send + Sync + ' static , direct : D , ) -> Inbound < svc :: ArcNewTcp < T , I > > where T : svc :: Param < Remote < ClientAddr > > + svc :: Param < OrigDstAddr > , T : Clone + Send + ' static , I : io :: AsyncRead + io :: AsyncWrite + io :: Peek + io :: PeerAddr , I : Debug + Send + Sync + Unpin + ' static , N : svc :: NewService < Accept , Service = NSvc > + Clone + Send + Sync + Unpin + ' static , NSvc : svc :: Service < I , Response = ( ) > , NSvc : Send + Unpin + ' static , NSvc :: Error : Into < Error > , NSvc :: Future : Send , D : svc :: NewService < T , Service = DSvc > + Clone + Send + Sync + Unpin + ' static , DSvc : svc :: Service < I , Response = ( ) > + Send + ' static , DSvc :: Error : Into < Error > , DSvc :: Future : Send , { self . map_stack ( | cfg , rt , accept | { accept . push_switch ( // Switch to the `direct` stack when a connection's original destination is the // proxy's inbound port. Otherwise, check that connections are allowed on the // port and obtain the port's policy before processing the connection. move | t : T | -> Result < _ , Error > { let OrigDstAddr ( addr ) = t . param ( ) ; if addr . port ( ) == proxy_port { return Ok ( svc :: Either :: B ( t ) ) ; } let orig_dst_addr = t . param ( ) ; let policy = policies . check_policy ( orig_dst_addr ) ? ; tracing :: debug ! ( policy " " ) ; Ok ( svc :: Either :: A ( Accept { client_addr : t . param ( ) , orig_dst_addr , policy , } ) ) } , direct , ) . check_new_service :: < T , I > ( ) . push_request_filter ( cfg . allowed_ips . clone ( ) ) . push ( rt . metrics . tcp_errors . to_layer ( ) ) . check_new_service :: < T , I > ( ) . instrument ( | t : & T | { let OrigDstAddr ( addr ) = t . param ( ) ; info_span ! ( " " port addr port ( ) ) } ) . push_on_service ( svc :: BoxService :: layer ( ) ) . push ( svc :: ArcNewService :: layer ( ) ) } ) }
Builds a stack that accepts connections.
Builds a stack that accepts connections .
self
proxy_port
u16
policies
impl CheckPolicy + Clone + Send + Sync + 'static
direct
D