|
|
|
@@ -2,8 +2,8 @@ package dokodemo
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"runtime"
|
|
|
|
|
"sync/atomic"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
|
"github.com/xtls/xray-core/common/buf"
|
|
|
|
@@ -115,7 +115,14 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|
|
|
|
|
|
|
|
|
plcy := d.policy()
|
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
|
timer := signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
|
|
|
|
|
|
|
|
|
|
var timer *signal.ActivityTimer
|
|
|
|
|
// if dns req, set a short timeout value
|
|
|
|
|
if dest.Port == 53 {
|
|
|
|
|
timer = signal.CancelAfterInactivity(ctx, cancel, 10*time.Second)
|
|
|
|
|
} else {
|
|
|
|
|
timer = signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if inbound != nil {
|
|
|
|
|
inbound.Timer = timer
|
|
|
|
@@ -148,6 +155,10 @@ 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)
|
|
|
|
@@ -177,12 +188,6 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
writer = NewPacketWriter(pConn, &dest, mark, back)
|
|
|
|
|
defer func() {
|
|
|
|
|
runtime.Gosched()
|
|
|
|
|
common.Interrupt(link.Reader) // maybe duplicated
|
|
|
|
|
runtime.Gosched()
|
|
|
|
|
writer.(*PacketWriter).Close() // close fake UDP conns
|
|
|
|
|
}()
|
|
|
|
|
/*
|
|
|
|
|
sockopt := &internet.SocketConfig{
|
|
|
|
|
Tproxy: internet.SocketConfig_TProxy,
|
|
|
|
@@ -221,9 +226,8 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|
|
|
|
responseDone := func() error {
|
|
|
|
|
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
|
|
|
|
|
|
|
|
|
if network == net.Network_UDP && destinationOverridden {
|
|
|
|
|
buf.Copy(link.Reader, writer) // respect upload's timeout
|
|
|
|
|
return nil
|
|
|
|
|
if pw, ok := writer.(*PacketWriter); ok {
|
|
|
|
|
defer pw.Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
|
|
|
|
@@ -232,13 +236,11 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := task.Run(ctx,
|
|
|
|
|
task.OnSuccess(func() error { return task.Run(ctx, requestDone) }, task.Close(link.Writer)),
|
|
|
|
|
responseDone); err != nil {
|
|
|
|
|
runtime.Gosched()
|
|
|
|
|
common.Interrupt(link.Writer)
|
|
|
|
|
runtime.Gosched()
|
|
|
|
|
if err := task.Run(ctx, task.OnSuccess(func() error {
|
|
|
|
|
return task.Run(ctx, requestDone, tproxyRequest)
|
|
|
|
|
}, task.Close(link.Writer)), responseDone); err != nil {
|
|
|
|
|
common.Interrupt(link.Reader)
|
|
|
|
|
common.Interrupt(link.Writer)
|
|
|
|
|
return errors.New("connection ends").Base(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|