diff --git a/common/protocol/user.go b/common/protocol/user.go index f2e09659..9b34157a 100644 --- a/common/protocol/user.go +++ b/common/protocol/user.go @@ -1,6 +1,8 @@ package protocol import ( + "time" + "v2ray.com/core/common/errors" ) @@ -30,15 +32,18 @@ func (v *User) GetTypedAccount() (Account, error) { } func (v *User) GetSettings() UserSettings { - settings := UserSettings{ - PayloadReadTimeout: 120, - } - if v.Level > 0 { - settings.PayloadReadTimeout = 0 + settings := UserSettings{} + switch v.Level { + case 0: + settings.PayloadTimeout = time.Second * 30 + case 1: + settings.PayloadTimeout = time.Minute * 2 + default: + settings.PayloadTimeout = time.Minute * 5 } return settings } type UserSettings struct { - PayloadReadTimeout uint32 + PayloadTimeout time.Duration } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index c29ea115..32fd1635 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -158,11 +158,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection) ctx, cancel := context.WithCancel(ctx) userSettings := s.user.GetSettings() - timeout := time.Second * time.Duration(userSettings.PayloadReadTimeout) - if timeout == 0 { - timeout = time.Minute * 2 - } - timer := signal.CancelAfterInactivity(ctx, cancel, timeout) + timer := signal.CancelAfterInactivity(ctx, cancel, userSettings.PayloadTimeout) ray := s.packetDispatcher.DispatchToOutbound(ctx) requestDone := signal.ExecuteAsync(func() error { diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index bcb7b24c..d6d50613 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -203,11 +203,7 @@ func (v *VMessInboundHandler) Process(ctx context.Context, network net.Network, ctx = proxy.ContextWithDestination(ctx, request.Destination()) ctx = protocol.ContextWithUser(ctx, request.User) ctx, cancel := context.WithCancel(ctx) - timeout := time.Second * time.Duration(userSettings.PayloadReadTimeout) - if timeout == 0 { - timeout = time.Minute * 2 - } - timer := signal.CancelAfterInactivity(ctx, cancel, timeout) + timer := signal.CancelAfterInactivity(ctx, cancel, userSettings.PayloadTimeout) ray := v.packetDispatcher.DispatchToOutbound(ctx) input := ray.InboundInput()