mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
refactor tproxy handling in dokodemo
This commit is contained in:
parent
7bb5db712d
commit
bb5a959876
@ -117,9 +117,9 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
return nil
|
||||
}
|
||||
|
||||
var tConn net.Conn
|
||||
responseDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||
tproxyRequest := func() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var writer buf.Writer
|
||||
if network == net.Network_TCP {
|
||||
@ -136,41 +136,35 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
sockopt.BindAddress = dest.Address.IP()
|
||||
sockopt.BindPort = uint32(dest.Port)
|
||||
}
|
||||
var err error
|
||||
tConn, err = internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
|
||||
tConn, err := internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tConn.Close()
|
||||
|
||||
writer = &buf.SequentialWriter{Writer: tConn}
|
||||
tReader := buf.NewReader(tConn)
|
||||
go func() {
|
||||
defer tConn.Close()
|
||||
defer common.Close(link.Writer)
|
||||
tproxyRequest = func() error {
|
||||
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
newError("failed to transport request (TPROXY conn)").Base(err).WriteToLog()
|
||||
return newError("failed to transport request (TPROXY conn)").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if tConn != nil {
|
||||
tConn.Close()
|
||||
}
|
||||
}()
|
||||
responseDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||
|
||||
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport response").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := task.Run(ctx, task.OnSuccess(requestDone, task.Close(link.Writer)), responseDone); err != nil {
|
||||
if err := task.Run(ctx, task.OnSuccess(requestDone, task.Close(link.Writer)), responseDone, tproxyRequest); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
if tConn != nil {
|
||||
tConn.Close()
|
||||
}
|
||||
return newError("connection ends").Base(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user