Skip to content

Commit

Permalink
Dokodemo TRPOXY: Interrupt download if upload timeouts/ends for UDP
Browse files Browse the repository at this point in the history
Fixes #4194
  • Loading branch information
RPRX authored Dec 28, 2024
1 parent 42aea01 commit ec46a57
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions proxy/dokodemo/dokodemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dokodemo

import (
"context"
"runtime"
"sync/atomic"

"github.com/xtls/xray-core/common"
Expand Down Expand Up @@ -147,10 +148,6 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
return nil
}

tproxyRequest := func() error {
return nil
}

var writer buf.Writer
if network == net.Network_TCP {
writer = buf.NewWriter(conn)
Expand Down Expand Up @@ -180,7 +177,11 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
return err
}
writer = NewPacketWriter(pConn, &dest, mark, back)
defer writer.(*PacketWriter).Close()
defer func() {
common.Interrupt(link.Reader)
runtime.Gosched()
writer.(*PacketWriter).Close()
}()
/*
sockopt := &internet.SocketConfig{
Tproxy: internet.SocketConfig_TProxy,
Expand Down Expand Up @@ -219,15 +220,21 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
responseDone := func() error {
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)

if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
var err error
if network == net.Network_TCP || !destinationOverridden {
err = buf.Copy(link.Reader, writer, buf.UpdateActivity(timer))
} else {
err = buf.Copy(link.Reader, writer)
}
if err != nil {
return errors.New("failed to transport response").Base(err)
}
return nil
}

if err := task.Run(ctx, task.OnSuccess(func() error {
return task.Run(ctx, requestDone, tproxyRequest)
}, task.Close(link.Writer)), responseDone); err != nil {
if err := task.Run(ctx,
task.OnSuccess(func() error { return task.Run(ctx, requestDone) }, task.Close(link.Writer)),
responseDone); err != nil {
common.Interrupt(link.Reader)
common.Interrupt(link.Writer)
return errors.New("connection ends").Base(err)
Expand Down

0 comments on commit ec46a57

Please sign in to comment.