mirror of https://github.com/v2ray/v2ray-core
refine user timeout
parent
ad7d98473f
commit
08b9778f05
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue