update error messages

This commit is contained in:
Darien Raymond
2017-04-07 22:56:27 +02:00
parent 9bb66b4de4
commit a034276eee
5 changed files with 29 additions and 29 deletions
+7 -7
View File
@@ -110,38 +110,38 @@ func (v *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri
func (v *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
cmd := new(protocol.CommandSwitchAccount)
if len(data) == 0 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
lenHost := int(data[0])
if len(data) < lenHost+1 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
if lenHost > 0 {
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
}
portStart := 1 + lenHost
if len(data) < portStart+2 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
cmd.Port = net.PortFromBytes(data[portStart : portStart+2])
idStart := portStart + 2
if len(data) < idStart+16 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
alterIDStart := idStart + 16
if len(data) < alterIDStart+2 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
cmd.AlterIds = serial.BytesToUint16(data[alterIDStart : alterIDStart+2])
levelStart := alterIDStart + 2
if len(data) < levelStart+1 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
cmd.Level = uint32(data[levelStart])
timeStart := levelStart + 1
if len(data) < timeStart {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
return nil, errors.New("insufficient length.").Path("Proxy", "VMess", "Encoding", "Command")
}
cmd.ValidMin = data[timeStart]
return cmd, nil
+6 -6
View File
@@ -82,7 +82,7 @@ type Handler struct {
func New(ctx context.Context, config *Config) (*Handler, error) {
space := app.SpaceFromContext(ctx)
if space == nil {
return nil, errors.New("VMess|Inbound: No space in context.")
return nil, errors.New("no space in context").Path("Proxy", "VMess", "Inbound")
}
allowedClients := vmess.NewTimedUserValidator(ctx, protocol.DefaultIDHash)
@@ -100,7 +100,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
space.OnInitialize(func() error {
handler.inboundHandlerManager = proxyman.InboundHandlerManagerFromSpace(space)
if handler.inboundHandlerManager == nil {
return errors.New("VMess|Inbound: InboundHandlerManager is not found is space.")
return errors.New("InboundHandlerManager is not found is space").Path("Proxy", "VMess", "Inbound")
}
return nil
})
@@ -180,12 +180,12 @@ func (v *Handler) Process(ctx context.Context, network net.Network, connection i
if err != nil {
if errors.Cause(err) != io.EOF {
log.Access(connection.RemoteAddr(), "", log.AccessRejected, err)
log.Trace(errors.New("VMess|Inbound: Invalid request from ", connection.RemoteAddr(), ": ", err))
log.Trace(errors.New("invalid request from ", connection.RemoteAddr(), ": ", err).Path("Proxy", "VMess", "Inbound"))
}
return err
}
log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, "")
log.Trace(errors.New("VMess|Inbound: Received request for ", request.Destination()))
log.Trace(errors.New("received request for ", request.Destination()).Path("Proxy", "VMess", "Inbound"))
connection.SetReadDeadline(time.Time{})
@@ -238,7 +238,7 @@ func (v *Handler) generateCommand(ctx context.Context, request *protocol.Request
if v.inboundHandlerManager != nil {
handler, err := v.inboundHandlerManager.GetHandler(ctx, tag)
if err != nil {
log.Trace(errors.New("VMess|Inbound: Failed to get detour handler: ", tag, err).AtWarning())
log.Trace(errors.New("failed to get detour handler: ", tag, err).AtWarning().Path("Proxy", "VMess", "Inbound"))
return nil
}
proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
@@ -248,7 +248,7 @@ func (v *Handler) generateCommand(ctx context.Context, request *protocol.Request
availableMin = 255
}
log.Trace(errors.New("VMess|Inbound: Pick detour handler for port ", port, " for ", availableMin, " minutes."))
log.Trace(errors.New("pick detour handler for port ", port, " for ", availableMin, " minutes.").Path("Proxy", "VMess", "Inbound").AtDebug())
user := inboundHandler.GetUser(request.User.Email)
if user == nil {
return nil
+8 -8
View File
@@ -30,7 +30,7 @@ type Handler struct {
func New(ctx context.Context, config *Config) (*Handler, error) {
space := app.SpaceFromContext(ctx)
if space == nil {
return nil, errors.New("VMess|Outbound: No space in context.")
return nil, errors.New("no space in context.").Path("Proxy", "VMess", "Outbound")
}
serverList := protocol.NewServerList()
@@ -61,15 +61,15 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
return nil
})
if err != nil {
return errors.New("VMess|Outbound: Failed to find an available destination.").Base(err).AtWarning()
return errors.New("failed to find an available destination").Base(err).AtWarning().Path("Proxy", "VMess", "Outbound")
}
defer conn.Close()
target, ok := proxy.TargetFromContext(ctx)
if !ok {
return errors.New("VMess|Outbound: Target not specified.")
return errors.New("target not specified").Path("Proxy", "VMess", "Outbound").AtError()
}
log.Trace(errors.New("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination()))
log.Trace(errors.New("tunneling request to ", target, " via ", rec.Destination()).Path("Proxy", "VMess", "Outbound"))
command := protocol.RequestCommandTCP
if target.Network == net.Network_UDP {
@@ -86,7 +86,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
rawAccount, err := request.User.GetTypedAccount()
if err != nil {
return errors.New("VMess|Outbound: Failed to get user account.").Base(err).AtWarning()
return errors.New("failed to get user account").Base(err).AtWarning().Path("Proxy", "VMess", "Outbound")
}
account := rawAccount.(*vmess.InternalAccount)
request.Security = account.Security
@@ -109,11 +109,11 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
bodyWriter := session.EncodeRequestBody(request, writer)
firstPayload, err := input.ReadTimeout(time.Millisecond * 500)
if err != nil && err != buf.ErrReadTimeout {
return errors.New("failed to get first payload").Base(err).Path("VMess", "Outbound")
return errors.New("failed to get first payload").Base(err).Path("Proxy", "VMess", "Outbound")
}
if !firstPayload.IsEmpty() {
if err := bodyWriter.Write(firstPayload); err != nil {
return errors.New("failed to write first payload").Base(err).Path("VMess", "Outbound")
return errors.New("failed to write first payload").Base(err).Path("Proxy", "VMess", "Outbound")
}
firstPayload.Release()
}
@@ -159,7 +159,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
})
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
return errors.New("connection ends").Base(err).Path("VMess", "Outbound")
return errors.New("connection ends").Base(err).Path("Proxy", "VMess", "Outbound")
}
runtime.KeepAlive(timer)