重构代理解析流程,引入端口混合协议转发

This commit is contained in:
2025-03-01 17:08:56 +08:00
parent b8a3dd93dc
commit 76139d28c4
24 changed files with 841 additions and 1042 deletions

View File

@@ -9,21 +9,22 @@ import (
)
func ChanConnAccept(ctx context.Context, ls net.Listener) chan net.Conn {
connCh := make(chan net.Conn)
ch := make(chan net.Conn)
go func() {
defer close(ch)
for {
conn, err := ls.Accept()
if err != nil {
if errors.Is(err, net.ErrClosed) {
return
}
slog.Error("接受连接失败", err)
// 临时错误重试连接
var ne net.Error
if errors.As(err, &ne) && ne.Temporary() {
slog.Debug("临时错误重试")
continue
}
slog.Error("接受连接失败", err)
return
}
// ctx 取消后退出
@@ -31,16 +32,17 @@ func ChanConnAccept(ctx context.Context, ls net.Listener) chan net.Conn {
case <-ctx.Done():
Close(conn)
return
case connCh <- conn:
case ch <- conn:
}
}
}()
return connCh
return ch
}
func ChanWgWait[T WaitGroup](ctx context.Context, wg T) chan struct{} {
ch := make(chan struct{})
go func() {
defer close(ch)
wg.Wait()
select {
case <-ctx.Done():