@@ -111,7 +111,7 @@ func canLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig
111111}
112112
113113func redirect (ctx context.Context , dst net.Destination , obt string ) net.Conn {
114- errors .LogInfo (ctx , "redirecting request " + dst .String () + " to " + obt )
114+ errors .LogInfo (ctx , "redirecting request " + dst .String ()+ " to " + obt )
115115 h := obm .GetHandler (obt )
116116 outbounds := session .OutboundsFromContext (ctx )
117117 ctx = session .ContextWithOutbounds (ctx , append (outbounds , & session.Outbound {
@@ -123,10 +123,16 @@ func redirect(ctx context.Context, dst net.Destination, obt string) net.Conn {
123123 ur , uw := pipe .New (pipe .OptionsFromContext (ctx )... )
124124 dr , dw := pipe .New (pipe .OptionsFromContext (ctx )... )
125125
126- go h .Dispatch (ctx , & transport.Link {Reader : ur , Writer : dw })
126+ go h .Dispatch (context .WithoutCancel (ctx ), & transport.Link {Reader : ur , Writer : dw })
127+ var readerOpt cnc.ConnectionOption
128+ if dst .Network == net .Network_TCP {
129+ readerOpt = cnc .ConnectionOutputMulti (dr )
130+ } else {
131+ readerOpt = cnc .ConnectionOutputMultiUDP (dr )
132+ }
127133 nc := cnc .NewConnection (
128134 cnc .ConnectionInputMulti (uw ),
129- cnc . ConnectionOutputMulti ( dr ) ,
135+ readerOpt ,
130136 cnc .ConnectionOnClose (common.ChainedClosable {uw , dw }),
131137 )
132138 return nc
@@ -150,7 +156,7 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
150156 ips , err := lookupIP (dest .Address .String (), sockopt .DomainStrategy , src )
151157 if err == nil && len (ips ) > 0 {
152158 dest .Address = net .IPAddress (ips [dice .Roll (len (ips ))])
153- errors .LogInfo (ctx , "replace destination with " + dest .String ())
159+ errors .LogInfo (ctx , "replace destination with " + dest .String ())
154160 } else if err != nil {
155161 errors .LogWarningInner (ctx , err , "failed to resolve ip" )
156162 }
0 commit comments