33pub use crate :: proxy:: http;
44use crate :: { cache, Error } ;
55pub use linkerd_concurrency_limit:: ConcurrencyLimit ;
6+ use linkerd_error:: Recover ;
7+ use linkerd_exp_backoff:: { ExponentialBackoff , ExponentialBackoffStream } ;
8+ pub use linkerd_reconnect:: NewReconnect ;
69pub use linkerd_stack:: {
710 self as stack, layer, BoxNewService , BoxService , BoxServiceLayer , Fail , Filter , MapTargetLayer ,
811 NewRouter , NewService , Param , Predicate , UnwrapOr ,
@@ -26,6 +29,9 @@ pub use tower::{
2629 Service , ServiceExt ,
2730} ;
2831
32+ #[ derive( Copy , Clone , Debug ) ]
33+ pub struct AlwaysReconnect ( ExponentialBackoff ) ;
34+
2935pub type Buffer < Req , Rsp , E > = TowerBuffer < BoxService < Req , Rsp , E > , Req > ;
3036
3137pub type BoxHttp < B = http:: BoxBody > =
@@ -47,6 +53,8 @@ pub fn stack<S>(inner: S) -> Stack<S> {
4753 Stack ( inner)
4854}
4955
56+ // === impl IdentityProxy ===
57+
5058pub fn proxies ( ) -> Stack < IdentityProxy > {
5159 Stack ( IdentityProxy ( ( ) ) )
5260}
@@ -59,6 +67,8 @@ impl<T> NewService<T> for IdentityProxy {
5967 fn new_service ( & mut self , _: T ) -> Self :: Service { }
6068}
6169
70+ // === impl Layers ===
71+
6272#[ allow( dead_code) ]
6373impl < L > Layers < L > {
6474 pub fn push < O > ( self , outer : O ) -> Layers < Pair < L , O > > {
@@ -69,13 +79,6 @@ impl<L> Layers<L> {
6979 self . push ( stack:: MapTargetLayer :: new ( map_target) )
7080 }
7181
72- /// Wraps an inner `MakeService` to be a `NewService`.
73- pub fn push_into_new_service (
74- self ,
75- ) -> Layers < Pair < L , stack:: new_service:: FromMakeServiceLayer > > {
76- self . push ( stack:: new_service:: FromMakeServiceLayer :: default ( ) )
77- }
78-
7982 /// Buffers requests in an mpsc, spawning the inner service onto a dedicated task.
8083 pub fn push_spawn_buffer < Req > (
8184 self ,
@@ -105,6 +108,8 @@ impl<M, L: Layer<M>> Layer<M> for Layers<L> {
105108 }
106109}
107110
111+ // === impl Stack ===
112+
108113#[ allow( dead_code) ]
109114impl < S > Stack < S > {
110115 pub fn push < L : Layer < S > > ( self , layer : L ) -> Stack < L :: Service > {
@@ -137,7 +142,14 @@ impl<S> Stack<S> {
137142
138143 /// Wraps an inner `MakeService` to be a `NewService`.
139144 pub fn into_new_service ( self ) -> Stack < stack:: new_service:: FromMakeService < S > > {
140- self . push ( stack:: new_service:: FromMakeServiceLayer :: default ( ) )
145+ self . push ( stack:: new_service:: FromMakeService :: layer ( ) )
146+ }
147+
148+ pub fn push_new_reconnect (
149+ self ,
150+ backoff : ExponentialBackoff ,
151+ ) -> Stack < NewReconnect < AlwaysReconnect , S > > {
152+ self . push ( NewReconnect :: layer ( AlwaysReconnect ( backoff) ) )
141153 }
142154
143155 /// Buffer requests when when the next layer is out of capacity.
@@ -331,3 +343,13 @@ where
331343 self . 0 . call ( t)
332344 }
333345}
346+
347+ // === impl AlwaysReconnect ===
348+
349+ impl < E : Into < Error > > Recover < E > for AlwaysReconnect {
350+ type Backoff = ExponentialBackoffStream ;
351+
352+ fn recover ( & self , _: E ) -> Result < Self :: Backoff , E > {
353+ Ok ( self . 0 . stream ( ) )
354+ }
355+ }
0 commit comments