|  | @@ -8,7 +8,6 @@ import (
 | 
											
												
													
														|  |  	"v2ray.com/core/app/log"
 |  |  	"v2ray.com/core/app/log"
 | 
											
												
													
														|  |  	"v2ray.com/core/common"
 |  |  	"v2ray.com/core/common"
 | 
											
												
													
														|  |  	"v2ray.com/core/common/buf"
 |  |  	"v2ray.com/core/common/buf"
 | 
											
												
													
														|  | -	"v2ray.com/core/common/errors"
 |  | 
 | 
											
												
													
														|  |  	"v2ray.com/core/common/net"
 |  |  	"v2ray.com/core/common/net"
 | 
											
												
													
														|  |  	"v2ray.com/core/common/protocol"
 |  |  	"v2ray.com/core/common/protocol"
 | 
											
												
													
														|  |  	"v2ray.com/core/common/retry"
 |  |  	"v2ray.com/core/common/retry"
 | 
											
										
											
												
													
														|  | @@ -40,7 +39,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 | 
											
												
													
														|  |  func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error {
 |  |  func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error {
 | 
											
												
													
														|  |  	destination, ok := proxy.TargetFromContext(ctx)
 |  |  	destination, ok := proxy.TargetFromContext(ctx)
 | 
											
												
													
														|  |  	if !ok {
 |  |  	if !ok {
 | 
											
												
													
														|  | -		return errors.New("target not specified").Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		return newError("target not specified")
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	network := destination.Network
 |  |  	network := destination.Network
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -60,9 +59,9 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  		return nil
 |  |  		return nil
 | 
											
												
													
														|  |  	})
 |  |  	})
 | 
											
												
													
														|  |  	if err != nil {
 |  |  	if err != nil {
 | 
											
												
													
														|  | -		return errors.New("failed to find an available destination").AtWarning().Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		return newError("failed to find an available destination").AtWarning().Base(err)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  | -	log.Trace(errors.New("tunneling request to ", destination, " via ", server.Destination()).Path("Proxy", "Shadowsocks", "Client"))
 |  | 
 | 
											
												
													
														|  | 
 |  | +	log.Trace(newError("tunneling request to ", destination, " via ", server.Destination()))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	defer conn.Close()
 |  |  	defer conn.Close()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -80,7 +79,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  	user := server.PickUser()
 |  |  	user := server.PickUser()
 | 
											
												
													
														|  |  	rawAccount, err := user.GetTypedAccount()
 |  |  	rawAccount, err := user.GetTypedAccount()
 | 
											
												
													
														|  |  	if err != nil {
 |  |  	if err != nil {
 | 
											
												
													
														|  | -		return errors.New("failed to get a valid user account").AtWarning().Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		return newError("failed to get a valid user account").AtWarning().Base(err)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	account := rawAccount.(*ShadowsocksAccount)
 |  |  	account := rawAccount.(*ShadowsocksAccount)
 | 
											
												
													
														|  |  	request.User = user
 |  |  	request.User = user
 | 
											
										
											
												
													
														|  | @@ -95,7 +94,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  		bufferedWriter := buf.NewBufferedWriter(conn)
 |  |  		bufferedWriter := buf.NewBufferedWriter(conn)
 | 
											
												
													
														|  |  		bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
 |  |  		bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  | -			return errors.New("failed to write request").Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			return newError("failed to write request").Base(err)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if err := bufferedWriter.SetBuffered(false); err != nil {
 |  |  		if err := bufferedWriter.SetBuffered(false); err != nil {
 | 
											
										
											
												
													
														|  | @@ -126,7 +125,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  		})
 |  |  		})
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 |  |  		if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 | 
											
												
													
														|  | -			return errors.New("connection ends").Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			return newError("connection ends").Base(err)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		return nil
 |  |  		return nil
 | 
											
										
											
												
													
														|  | @@ -141,7 +140,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		requestDone := signal.ExecuteAsync(func() error {
 |  |  		requestDone := signal.ExecuteAsync(func() error {
 | 
											
												
													
														|  |  			if err := buf.PipeUntilEOF(timer, outboundRay.OutboundInput(), writer); err != nil {
 |  |  			if err := buf.PipeUntilEOF(timer, outboundRay.OutboundInput(), writer); err != nil {
 | 
											
												
													
														|  | -				return errors.New("failed to transport all UDP request").Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +				return newError("failed to transport all UDP request").Base(err)
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  |  			return nil
 |  |  			return nil
 | 
											
												
													
														|  |  		})
 |  |  		})
 | 
											
										
											
												
													
														|  | @@ -155,13 +154,13 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  			if err := buf.PipeUntilEOF(timer, reader, outboundRay.OutboundOutput()); err != nil {
 |  |  			if err := buf.PipeUntilEOF(timer, reader, outboundRay.OutboundOutput()); err != nil {
 | 
											
												
													
														|  | -				return errors.New("failed to transport all UDP response").Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +				return newError("failed to transport all UDP response").Base(err)
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  |  			return nil
 |  |  			return nil
 | 
											
												
													
														|  |  		})
 |  |  		})
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 |  |  		if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 | 
											
												
													
														|  | -			return errors.New("connection ends").Base(err).Path("Proxy", "Shadowsocks", "Client")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			return newError("connection ends").Base(err)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		return nil
 |  |  		return nil
 |