11mod helpers;
22
3- use std:: { collections:: HashMap , io, sync:: Arc } ;
4-
5- use erased_serde:: Serialize ;
3+ use async_trait:: async_trait;
64use helpers:: strategy_sticky_session;
5+ use std:: { io, sync:: Arc } ;
76use tokio:: sync:: Mutex ;
87use tracing:: debug;
98
9+ use self :: helpers:: { StrategyFn , strategy_consistent_hashring, strategy_rr} ;
1010use crate :: {
1111 app:: {
1212 dispatcher:: { BoxedChainedDatagram , BoxedChainedStream } ,
@@ -19,13 +19,12 @@ use crate::{
1919 proxy:: {
2020 AnyOutboundHandler , ConnectorType , DialWithConnector , HandlerCommonOptions ,
2121 OutboundHandler , OutboundType ,
22+ group:: GroupProxyAPIResponse ,
2223 utils:: { RemoteConnector , provider_helper:: get_proxies_from_providers} ,
2324 } ,
2425 session:: Session ,
2526} ;
2627
27- use self :: helpers:: { StrategyFn , strategy_consistent_hashring, strategy_rr} ;
28-
2928#[ derive( Default , Clone ) ]
3029pub struct HandlerOptions {
3130 pub common_opts : HandlerCommonOptions ,
@@ -82,7 +81,7 @@ impl Handler {
8281
8382impl DialWithConnector for Handler { }
8483
85- #[ async_trait:: async_trait ]
84+ #[ async_trait]
8685impl OutboundHandler for Handler {
8786 /// The name of the outbound handler
8887 fn name ( & self ) -> & str {
@@ -109,13 +108,12 @@ impl OutboundHandler for Handler {
109108 let proxies = self . get_proxies ( false ) . await ;
110109 let proxy = ( self . inner . lock ( ) . await . strategy_fn ) ( proxies, sess) . await ?;
111110 debug ! ( "{} use proxy {}" , self . name( ) , proxy. name( ) ) ;
112- match proxy. connect_stream ( sess, resolver) . await {
113- Ok ( s) => {
114- s. append_to_chain ( self . name ( ) ) . await ;
115- Ok ( s)
116- }
117- Err ( e) => Err ( e) ,
118- }
111+
112+ let s = proxy. connect_stream ( sess, resolver) . await ?;
113+
114+ s. append_to_chain ( self . name ( ) ) . await ;
115+
116+ Ok ( s)
119117 }
120118
121119 /// connect to remote target via UDP
@@ -127,7 +125,12 @@ impl OutboundHandler for Handler {
127125 let proxies = self . get_proxies ( false ) . await ;
128126 let proxy = ( self . inner . lock ( ) . await . strategy_fn ) ( proxies, sess) . await ?;
129127 debug ! ( "{} use proxy {}" , self . name( ) , proxy. name( ) ) ;
130- proxy. connect_datagram ( sess, resolver) . await
128+
129+ let s = proxy. connect_datagram ( sess, resolver) . await ?;
130+
131+ s. append_to_chain ( self . name ( ) ) . await ;
132+
133+ Ok ( s)
131134 }
132135
133136 async fn support_connector ( & self ) -> ConnectorType {
@@ -148,18 +151,19 @@ impl OutboundHandler for Handler {
148151 . await
149152 }
150153
151- async fn as_map ( & self ) -> HashMap < String , Box < dyn Serialize + Send > > {
152- let all = get_proxies_from_providers ( & self . providers , false ) . await ;
154+ fn try_as_group_handler ( & self ) -> Option < & dyn GroupProxyAPIResponse > {
155+ Some ( self as _ )
156+ }
157+ }
153158
154- let mut m = HashMap :: new ( ) ;
155- m. insert ( "type" . to_string ( ) , Box :: new ( self . proto ( ) ) as _ ) ;
159+ #[ async_trait]
160+ impl GroupProxyAPIResponse for Handler {
161+ async fn get_proxies ( & self ) -> Vec < AnyOutboundHandler > {
162+ Handler :: get_proxies ( self , false ) . await
163+ }
156164
157- m. insert (
158- "all" . to_string ( ) ,
159- Box :: new ( all. iter ( ) . map ( |x| x. name ( ) . to_owned ( ) ) . collect :: < Vec < _ > > ( ) )
160- as _ ,
161- ) ;
162- m
165+ async fn get_active_proxy ( & self ) -> Option < AnyOutboundHandler > {
166+ None
163167 }
164168
165169 fn icon ( & self ) -> Option < String > {
0 commit comments