Most things work fine now, except:

- UDP support has been temporarily removed, pending upstream QUIC library support for unreliable messages
- SOCKS5 server needs some rework
- Authentication
This commit is contained in:
Toby
2021-01-28 23:57:53 -08:00
parent d9d07a5b2a
commit 7d280393a3
24 changed files with 618 additions and 1985 deletions

View File

@@ -2,20 +2,16 @@ package utils
import (
"io"
"sync/atomic"
)
const PipeBufferSize = 65536
func Pipe(src, dst io.ReadWriter, atomicCounter *uint64) error {
func Pipe(src, dst io.ReadWriter) error {
buf := make([]byte, PipeBufferSize)
for {
rn, err := src.Read(buf)
if rn > 0 {
wn, err := dst.Write(buf[:rn])
if atomicCounter != nil {
atomic.AddUint64(atomicCounter, uint64(wn))
}
_, err := dst.Write(buf[:rn])
if err != nil {
return err
}
@@ -26,13 +22,13 @@ func Pipe(src, dst io.ReadWriter, atomicCounter *uint64) error {
}
}
func PipePair(rw1, rw2 io.ReadWriter, rw1WriteCounter, rw2WriteCounter *uint64) error {
func Pipe2Way(rw1, rw2 io.ReadWriter) error {
errChan := make(chan error, 2)
go func() {
errChan <- Pipe(rw2, rw1, rw1WriteCounter)
errChan <- Pipe(rw2, rw1)
}()
go func() {
errChan <- Pipe(rw1, rw2, rw2WriteCounter)
errChan <- Pipe(rw1, rw2)
}()
// We only need the first error
return <-errChan