pub fn push_switch_logical<T, I, N, NSvc, SSvc>(
        self,
        logical: N,
    ) -> Outbound<svc::ArcNewTcp<(Option<profiles::Receiver>, T), I>>
    where
        Self: Clone + 'static,
        T: svc::Param<OrigDstAddr> + Clone + Send + Sync + 'static,
        I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + fmt::Debug + Send + Unpin + 'static,
        N: svc::NewService<tcp::Logical, Service = NSvc> + Clone + Send + Sync + 'static,
        NSvc: svc::Service<I, Response = (), Error = Error> + Send + 'static,
        NSvc::Future: Send,
        S: svc::NewService<tcp::Endpoint, Service = SSvc> + Clone + Send + Sync + 'static,
        SSvc: svc::Service<I, Response = (), Error = Error> + Send + 'static,
        SSvc::Future: Send,
    {
        let no_tls_reason = self.no_tls_reason();
        self.map_stack(|config, _, endpoint| {
            let inbound_ips = config.inbound_ips.clone();
            endpoint
                .push_switch(
                    move |(profile, target): (Option<profiles::Receiver>, T)| -> Result<_, Infallible> {
                        if let Some(rx) = profile {
                            let is_opaque = rx.is_opaque_protocol();

                            // If the profile provides an endpoint, then the target is single
                            // endpoint and not a logical/load-balanced service.
                            if let Some((addr, metadata)) = rx.endpoint() {
                                tracing::debug!(%is_opaque, "Profile describes an endpoint");
                                return Ok(svc::Either::A(Endpoint::from_metadata(
                                    addr,
                                    metadata,
                                    no_tls_reason,
                                    is_opaque,
                                    &*inbound_ips,
                                )));
                            }

                            // If the profile provides a (named) logical address, then we build a
                            // logical stack so we apply routes, traffic splits, and load balancing.
                            if let Some(logical_addr) = rx.logical_addr() {
                                tracing::debug!("Profile describes a logical service");
                                return Ok(svc::Either::B(Logical::new(logical_addr, rx)));
                            }

                            // Otherwise, if there was a profile but it didn't include an endpoint or logical
                            // address, create a bare endpoint from the original destination address
                            // using the profile-provided opaqueness. This applies for targets that
                            // aren't known by the destination controller that may target ports
                            // included in the cluster-wide default opaque list.
                            tracing::debug!("Unknown endpoint");
                            return Ok(svc::Either::A(Endpoint::forward(
                                target.param(),
                                no_tls_reason,
                                is_opaque,
                            )));
                        }

                        // If there was no profile, create a bare endpoint from the original
                        // destination address.
                        tracing::debug!("No profile");
                        Ok(svc::Either::A(Endpoint::forward(
                            target.param(),
                            no_tls_reason,
                            false,
                        )))
                    },
                    logical,
                )
                .push_on_service(svc::BoxService::layer())
                .push(svc::ArcNewService::layer())
        })
    }
/// Wraps an endpoint stack to switch to an alternate logical stack when an appropriate profile
/// is provided:
///
/// - When a profile includes endpoint information, it is used to build an endpoint stack;
/// - Otherwise, if the profile indicates the target is logical, a logical stack is built;
/// - Otherwise, we assume the target is not part of the mesh and we should connect to the
///   original destination.
Wraps an endpoint stack to switch to an alternate logical stack when an appropriate profile
is provided.

When a profile includes endpoint information, it is used to build an endpoint stack;
Otherwise, if the profile indicates the target is logical, a logical stack is built;
Otherwise, we assume the target is not part of the mesh and we should connect to the
original destination.
Wraps an endpoint stack to switch to an alternate logical stack when an appropriate profile is provided . When a profile includes endpoint information it is used to build an endpoint stack ; Otherwise if the profile indicates the target is logical a logical stack is built ; Otherwise we assume the target is not part of the mesh and we should connect to the original destination .
pub fn push_switch_logical<T, I, N, NSvc, SSvc>(
        self,
        logical: N,
    ) -> Outbound<svc::ArcNewTcp<(Option<profiles::Receiver>, T), I>>
    where
        Self: Clone + 'static,
        T: svc::Param<OrigDstAddr> + Clone + Send + Sync + 'static,
        I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + fmt::Debug + Send + Unpin + 'static,
        N: svc::NewService<tcp::Logical, Service = NSvc> + Clone + Send + Sync + 'static,
        NSvc: svc::Service<I, Response = (), Error = Error> + Send + 'static,
        NSvc::Future: Send,
        S: svc::NewService<tcp::Endpoint, Service = SSvc> + Clone + Send + Sync + 'static,
        SSvc: svc::Service<I, Response = (), Error = Error> + Send + 'static,
        SSvc::Future: Send,
    {
        let no_tls_reason = self.no_tls_reason();
        self.map_stack(|config, _, endpoint| {
            let inbound_ips = config.inbound_ips.clone();
            endpoint
                .push_switch(
                    move |(profile, target): (Option<profiles::Receiver>, T)| -> Result<_, Infallible> {
                        if let Some(rx) = profile {
                            let is_opaque = rx.is_opaque_protocol();
                            // If the profile provides an endpoint, then the target is single
                            // endpoint and not a logical/load-balanced service.
                            if let Some((addr, metadata)) = rx.endpoint() {
                                tracing::debug!(%is_opaque, "Profile describes an endpoint");
                                return Ok(svc::Either::A(Endpoint::from_metadata(
                                    addr,
                                    metadata,
                                    no_tls_reason,
                                    is_opaque,
                                    &*inbound_ips,
                                )));
                            }
                            // If the profile provides a (named) logical address, then we build a
                            // logical stack so we apply routes, traffic splits, and load balancing.
                            if let Some(logical_addr) = rx.logical_addr() {
                                tracing::debug!("Profile describes a logical service");
                                return Ok(svc::Either::B(Logical::new(logical_addr, rx)));
                            }
                            // Otherwise, if there was a profile but it didn't include an endpoint or logical
                            // address, create a bare endpoint from the original destination address
                            // using the profile-provided opaqueness. This applies for targets that
                            // aren't known by the destination controller that may target ports
                            // included in the cluster-wide default opaque list.
                            tracing::debug!("Unknown endpoint");
                            return Ok(svc::Either::A(Endpoint::forward(
                                target.param(),
                                no_tls_reason,
                                is_opaque,
                            )));
                        }
                        // If there was no profile, create a bare endpoint from the original
                        // destination address.
                        tracing::debug!("No profile");
                        Ok(svc::Either::A(Endpoint::forward(
                            target.param(),
                            no_tls_reason,
                            false,
                        )))
                    },
                    logical,
                )
                .push_on_service(svc::BoxService::layer())
                .push(svc::ArcNewService::layer())
        })
    }
pub fn push_switch_logical < T , I , N , NSvc , SSvc > ( self , logical : N , ) -> Outbound < svc :: ArcNewTcp < ( Option < profiles :: Receiver > , T ) , I > > where Self : Clone + ' static , T : svc :: Param < OrigDstAddr > + Clone + Send + Sync + ' static , I : io :: AsyncRead + io :: AsyncWrite + io :: PeerAddr + fmt :: Debug + Send + Unpin + ' static , N : svc :: NewService < tcp :: Logical , Service = NSvc > + Clone + Send + Sync + ' static , NSvc : svc :: Service < I , Response = ( ) , Error = Error > + Send + ' static , NSvc :: Future : Send , S : svc :: NewService < tcp :: Endpoint , Service = SSvc > + Clone + Send + Sync + ' static , SSvc : svc :: Service < I , Response = ( ) , Error = Error > + Send + ' static , SSvc :: Future : Send , { let no_tls_reason = self . no_tls_reason ( ) ; self . map_stack ( | config , _ , endpoint | { let inbound_ips = config . inbound_ips . clone ( ) ; endpoint . push_switch ( move | ( profile , target ) : ( Option < profiles :: Receiver > , T ) | -> Result < _ , Infallible > { if let Some ( rx ) = profile { let is_opaque = rx . is_opaque_protocol ( ) ; // If the profile provides an endpoint, then the target is single // endpoint and not a logical/load-balanced service. if let Some ( ( addr , metadata ) ) = rx . endpoint ( ) { tracing :: debug ! ( is_opaque " " ) ; return Ok ( svc :: Either :: A ( Endpoint :: from_metadata ( addr , metadata , no_tls_reason , is_opaque , & * inbound_ips , ) ) ) ; } // If the profile provides a (named) logical address, then we build a // logical stack so we apply routes, traffic splits, and load balancing. if let Some ( logical_addr ) = rx . logical_addr ( ) { tracing :: debug ! ( " " ) ; return Ok ( svc :: Either :: B ( Logical :: new ( logical_addr , rx ) ) ) ; } // Otherwise, if there was a profile but it didn't include an endpoint or logical // address, create a bare endpoint from the original destination address // using the profile-provided opaqueness. This applies for targets that // aren't known by the destination controller that may target ports // included in the cluster-wide default opaque list. tracing :: debug ! ( " " ) ; return Ok ( svc :: Either :: A ( Endpoint :: forward ( target . param ( ) , no_tls_reason , is_opaque , ) ) ) ; } // If there was no profile, create a bare endpoint from the original // destination address. tracing :: debug ! ( " " ) ; Ok ( svc :: Either :: A ( Endpoint :: forward ( target . param ( ) , no_tls_reason , false , ) ) ) } , logical , ) . push_on_service ( svc :: BoxService :: layer ( ) ) . push ( svc :: ArcNewService :: layer ( ) ) } ) }
Wraps an endpoint stack to switch to an alternate logical stack when an appropriate profile
is provided:
Wraps an endpoint stack to switch to an alternate logical stack when an appropriate profile is provided :
self
logical
N