|  | @@ -25,18 +25,19 @@ type Server struct {
 | 
	
		
			
				|  |  |  	account *ShadowsocksAccount
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// NewServer create a new Shadowsocks server.
 | 
	
		
			
				|  |  |  func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
 | 
	
		
			
				|  |  |  	space := app.SpaceFromContext(ctx)
 | 
	
		
			
				|  |  |  	if space == nil {
 | 
	
		
			
				|  |  | -		return nil, errors.New("no space in context").Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return nil, errors.New("no space in context").Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	if config.GetUser() == nil {
 | 
	
		
			
				|  |  | -		return nil, errors.New("user is not specified").Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return nil, errors.New("user is not specified").Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	rawAccount, err := config.User.GetTypedAccount()
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  | -		return nil, errors.New("failed to get user account").Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return nil, errors.New("failed to get user account").Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	account := rawAccount.(*ShadowsocksAccount)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -66,7 +67,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
 | 
	
		
			
				|  |  |  	case net.Network_UDP:
 | 
	
		
			
				|  |  |  		return s.handlerUDPPayload(ctx, conn, dispatcher)
 | 
	
		
			
				|  |  |  	default:
 | 
	
		
			
				|  |  | -		return errors.New("unknown network: ", network).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return errors.New("unknown network: ", network).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -83,7 +84,7 @@ func (v *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
 | 
	
		
			
				|  |  |  		request, data, err := DecodeUDPPacket(v.user, payload)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			if source, ok := proxy.SourceFromContext(ctx); ok {
 | 
	
		
			
				|  |  | -				log.Trace(errors.New("dropping invalid UDP packet from: ", source).Base(err).Path("Shadowsocks", "Server"))
 | 
	
		
			
				|  |  | +				log.Trace(errors.New("dropping invalid UDP packet from: ", source).Base(err).Path("Proxy", "Shadowsocks", "Server"))
 | 
	
		
			
				|  |  |  				log.Access(source, "", log.AccessRejected, err)
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  			payload.Release()
 | 
	
	
		
			
				|  | @@ -91,13 +92,13 @@ func (v *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		if request.Option.Has(RequestOptionOneTimeAuth) && v.account.OneTimeAuth == Account_Disabled {
 | 
	
		
			
				|  |  | -			log.Trace(errors.New("client payload enables OTA but server doesn't allow it").Path("Shadowsocks", "Server"))
 | 
	
		
			
				|  |  | +			log.Trace(errors.New("client payload enables OTA but server doesn't allow it").Path("Proxy", "Shadowsocks", "Server"))
 | 
	
		
			
				|  |  |  			payload.Release()
 | 
	
		
			
				|  |  |  			continue
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		if !request.Option.Has(RequestOptionOneTimeAuth) && v.account.OneTimeAuth == Account_Enabled {
 | 
	
		
			
				|  |  | -			log.Trace(errors.New("client payload disables OTA but server forces it").Path("Shadowsocks", "Server"))
 | 
	
		
			
				|  |  | +			log.Trace(errors.New("client payload disables OTA but server forces it").Path("Proxy", "Shadowsocks", "Server"))
 | 
	
		
			
				|  |  |  			payload.Release()
 | 
	
		
			
				|  |  |  			continue
 | 
	
		
			
				|  |  |  		}
 | 
	
	
		
			
				|  | @@ -106,7 +107,7 @@ func (v *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
 | 
	
		
			
				|  |  |  		if source, ok := proxy.SourceFromContext(ctx); ok {
 | 
	
		
			
				|  |  |  			log.Access(source, dest, log.AccessAccepted, "")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		log.Trace(errors.New("tunnelling request to ", dest).Path("Shadowsocks", "Server"))
 | 
	
		
			
				|  |  | +		log.Trace(errors.New("tunnelling request to ", dest).Path("Proxy", "Shadowsocks", "Server"))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		ctx = protocol.ContextWithUser(ctx, request.User)
 | 
	
		
			
				|  |  |  		udpServer.Dispatch(ctx, dest, data, func(payload *buf.Buffer) {
 | 
	
	
		
			
				|  | @@ -114,7 +115,7 @@ func (v *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  			data, err := EncodeUDPPacket(request, payload)
 | 
	
		
			
				|  |  |  			if err != nil {
 | 
	
		
			
				|  |  | -				log.Trace(errors.New("failed to encode UDP packet").Base(err).Path("Shadowsocks", "Server").AtWarning())
 | 
	
		
			
				|  |  | +				log.Trace(errors.New("failed to encode UDP packet").Base(err).Path("Proxy", "Shadowsocks", "Server").AtWarning())
 | 
	
		
			
				|  |  |  				return
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  			defer data.Release()
 | 
	
	
		
			
				|  | @@ -132,7 +133,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  	request, bodyReader, err := ReadTCPSession(s.user, bufferedReader)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		log.Access(conn.RemoteAddr(), "", log.AccessRejected, err)
 | 
	
		
			
				|  |  | -		return errors.New("failed to create request from: ", conn.RemoteAddr()).Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return errors.New("failed to create request from: ", conn.RemoteAddr()).Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	conn.SetReadDeadline(time.Time{})
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -140,7 +141,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	dest := request.Destination()
 | 
	
		
			
				|  |  |  	log.Access(conn.RemoteAddr(), dest, log.AccessAccepted, "")
 | 
	
		
			
				|  |  | -	log.Trace(errors.New("tunnelling request to ", dest).Path("Shadowsocks", "Server"))
 | 
	
		
			
				|  |  | +	log.Trace(errors.New("tunnelling request to ", dest).Path("Proxy", "Shadowsocks", "Server"))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	ctx = protocol.ContextWithUser(ctx, request.User)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -155,7 +156,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  		bufferedWriter := buf.NewBufferedWriter(conn)
 | 
	
		
			
				|  |  |  		responseWriter, err := WriteTCPResponse(request, bufferedWriter)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  | -			return errors.New("failed to write response").Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +			return errors.New("failed to write response").Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		mergeReader := buf.NewMergingReader(ray.InboundOutput())
 | 
	
	
		
			
				|  | @@ -173,7 +174,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		if err := buf.PipeUntilEOF(timer, mergeReader, responseWriter); err != nil {
 | 
	
		
			
				|  |  | -			return errors.New("failed to transport all TCP response").Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +			return errors.New("failed to transport all TCP response").Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		return nil
 | 
	
	
		
			
				|  | @@ -183,7 +184,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  		defer ray.InboundInput().Close()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		if err := buf.PipeUntilEOF(timer, bodyReader, ray.InboundInput()); err != nil {
 | 
	
		
			
				|  |  | -			return errors.New("failed to transport all TCP request").Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +			return errors.New("failed to transport all TCP request").Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return nil
 | 
	
		
			
				|  |  |  	})
 | 
	
	
		
			
				|  | @@ -191,7 +192,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 | 
	
		
			
				|  |  |  	if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 | 
	
		
			
				|  |  |  		ray.InboundInput().CloseError()
 | 
	
		
			
				|  |  |  		ray.InboundOutput().CloseError()
 | 
	
		
			
				|  |  | -		return errors.New("connection ends").Base(err).Path("Shadowsocks", "Server")
 | 
	
		
			
				|  |  | +		return errors.New("connection ends").Base(err).Path("Proxy", "Shadowsocks", "Server")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	runtime.KeepAlive(timer)
 |