mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-18 21:24:37 +03:00
Compare commits
4 Commits
remove-udp
...
timer-redu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b668333546 | ||
|
|
a22c4cf301 | ||
|
|
eba1f7258e | ||
|
|
33272a0499 |
@@ -15,9 +15,10 @@ type ActivityUpdater interface {
|
||||
|
||||
type ActivityTimer struct {
|
||||
sync.RWMutex
|
||||
updated chan struct{}
|
||||
checkTask *task.Periodic
|
||||
onTimeout func()
|
||||
updated chan struct{}
|
||||
checkTask *task.Periodic
|
||||
onTimeout func()
|
||||
overridden bool
|
||||
}
|
||||
|
||||
func (t *ActivityTimer) Update() {
|
||||
@@ -31,14 +32,16 @@ func (t *ActivityTimer) check() error {
|
||||
select {
|
||||
case <-t.updated:
|
||||
default:
|
||||
t.finish()
|
||||
t.finish(false)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ActivityTimer) finish() {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
func (t *ActivityTimer) finish(locked bool) {
|
||||
if !locked {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
}
|
||||
|
||||
if t.onTimeout != nil {
|
||||
t.onTimeout()
|
||||
@@ -50,9 +53,12 @@ func (t *ActivityTimer) finish() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||
func (t *ActivityTimer) setTimeout(timeout time.Duration) {
|
||||
if t.onTimeout == nil {
|
||||
return
|
||||
}
|
||||
if timeout == 0 {
|
||||
t.finish()
|
||||
t.finish(true)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -61,14 +67,26 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||
Execute: t.check,
|
||||
}
|
||||
|
||||
t.Lock()
|
||||
|
||||
if t.checkTask != nil {
|
||||
t.checkTask.Close()
|
||||
t.overridden = true
|
||||
}
|
||||
t.checkTask = checkTask
|
||||
t.Update()
|
||||
common.Must(checkTask.Start())
|
||||
}
|
||||
|
||||
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||
t.Lock()
|
||||
t.setTimeout(timeout)
|
||||
t.Unlock()
|
||||
}
|
||||
|
||||
func (t *ActivityTimer) SetTimeoutIfNotOverridden(timeout time.Duration) {
|
||||
t.Lock()
|
||||
if !t.overridden {
|
||||
t.setTimeout(timeout)
|
||||
}
|
||||
t.Unlock()
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -27,7 +27,7 @@ require (
|
||||
golang.org/x/sys v0.35.0
|
||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
||||
google.golang.org/grpc v1.75.0
|
||||
google.golang.org/protobuf v1.36.7
|
||||
google.golang.org/protobuf v1.36.8
|
||||
gvisor.dev/gvisor v0.0.0-20250428193742-2d800c3129d5
|
||||
h12.io/socks v1.0.3
|
||||
lukechampine.com/blake3 v1.4.1
|
||||
|
||||
4
go.sum
4
go.sum
@@ -145,8 +145,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 h1:
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||
google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=
|
||||
google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
|
||||
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
|
||||
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
||||
@@ -595,10 +595,10 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net
|
||||
errors.LogInfo(ctx, "CopyRawConn splice")
|
||||
statWriter, _ := writer.(*dispatcher.SizeStatWriter)
|
||||
//runtime.Gosched() // necessary
|
||||
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
|
||||
timer.SetTimeout(8 * time.Hour) // prevent leak, just in case
|
||||
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
|
||||
timer.SetTimeoutIfNotOverridden(24 * time.Hour) // prevent leak, just in case
|
||||
if inTimer != nil {
|
||||
inTimer.SetTimeout(8 * time.Hour)
|
||||
inTimer.SetTimeoutIfNotOverridden(24 * time.Hour)
|
||||
}
|
||||
w, err := tc.ReadFrom(readerConn)
|
||||
if readCounter != nil {
|
||||
|
||||
Reference in New Issue
Block a user