From 5f76f777d569e33869bd51219a8a57ae10a595cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Guerraz?= Date: Thu, 17 Aug 2023 21:40:19 +0000 Subject: [PATCH] Use io.Copy instead of io.CopyBuffer (#85) --- routine.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/routine.go b/routine.go index b52d4d0..6bbba96 100644 --- a/routine.go +++ b/routine.go @@ -162,9 +162,8 @@ func (c CredentialValidator) Valid(username, password string) bool { } // connForward copy data from `from` to `to`, then close both stream. -func connForward(bufSize int, from io.ReadWriteCloser, to io.ReadWriteCloser) { - buf := make([]byte, bufSize) - _, err := io.CopyBuffer(to, from, buf) +func connForward(from io.ReadWriteCloser, to io.ReadWriteCloser) { + _, err := io.Copy(to, from) if err != nil { errorLogger.Printf("Cannot forward traffic: %s\n", err.Error()) } @@ -188,8 +187,8 @@ func tcpClientForward(vt *VirtualTun, raddr *addressPort, conn net.Conn) { return } - go connForward(1024, sconn, conn) - go connForward(1024, conn, sconn) + go connForward(sconn, conn) + go connForward(conn, sconn) } // STDIOTcpForward starts a new connection via wireguard and forward traffic from `conn` @@ -214,8 +213,8 @@ func STDIOTcpForward(vt *VirtualTun, raddr *addressPort) { return } - go connForward(1024, os.Stdin, sconn) - go connForward(1024, sconn, stdout) + go connForward(os.Stdin, sconn) + go connForward(sconn, stdout) } // SpawnRoutine spawns a local TCP server which acts as a proxy to the specified target @@ -265,8 +264,8 @@ func tcpServerForward(vt *VirtualTun, raddr *addressPort, conn net.Conn) { return } - go connForward(1024, sconn, conn) - go connForward(1024, conn, sconn) + go connForward(sconn, conn) + go connForward(conn, sconn) } // SpawnRoutine spawns a TCP server on wireguard which acts as a proxy to the specified target