Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use io.Copy instead of io.CopyBuffer #85

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading