Skip to content

Commit

Permalink
Use io.Copy instead of io.CopyBuffer (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubrickfr authored Aug 17, 2023
1 parent d2f7768 commit 5f76f77
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f76f77

Please sign in to comment.