master
兔子 9 months ago
parent 2f40158945
commit 572a6059bb

@ -141,6 +141,10 @@ func (n *NetForward) runTCP() error {
}
log := starlog.Std.NewFlag()
log.Infof("Accept New TCP Conn from %v\n", conn.RemoteAddr().String())
if n.DelayMilSec > 0 && (n.DelayToward == 0 || n.DelayToward == 1) {
log.Infof("Delay %d ms\n", n.DelayMilSec)
time.Sleep(time.Millisecond * time.Duration(n.DelayMilSec))
}
go func(conn net.Conn) {
rmt, err := net.DialTimeout("tcp", n.RemoteURI, n.DialTimeout)
if err != nil {
@ -283,42 +287,42 @@ func (n *NetForward) copy(dst, src net.Conn) {
defer wg.Done()
bufsize := make([]byte, 32*1024)
for {
if n.DelayMilSec > 0 && (n.DelayToward == 0 || n.DelayToward == 1) {
time.Sleep(time.Millisecond * time.Duration(n.DelayMilSec))
}
n, err := src.Read(bufsize)
count, err := src.Read(bufsize)
if err != nil {
dst.Close()
src.Close()
return
}
_, err = dst.Write(bufsize[:n])
_, err = dst.Write(bufsize[:count])
if err != nil {
src.Close()
dst.Close()
return
}
if n.DelayMilSec > 0 && (n.DelayToward == 0 || n.DelayToward == 1) {
time.Sleep(time.Millisecond * time.Duration(n.DelayMilSec))
}
}
}()
go func() {
defer wg.Done()
bufsize := make([]byte, 32*1024)
for {
if n.DelayMilSec > 0 && (n.DelayToward == 0 || n.DelayToward == 2) {
time.Sleep(time.Millisecond * time.Duration(n.DelayMilSec))
}
n, err := dst.Read(bufsize)
count, err := dst.Read(bufsize)
if err != nil {
src.Close()
dst.Close()
return
}
_, err = src.Write(bufsize[:n])
_, err = src.Write(bufsize[:count])
if err != nil {
src.Close()
dst.Close()
return
}
if n.DelayMilSec > 0 && (n.DelayToward == 0 || n.DelayToward == 2) {
time.Sleep(time.Millisecond * time.Duration(n.DelayMilSec))
}
}
}()
wg.Wait()

Loading…
Cancel
Save