refactor: вынести turnpipe и dtlsdial в internal/
Переносит общий пайплайн TURN dial+allocate в internal/turnpipe и DTLS-настройку клиента в internal/dtlsdial. И oneTurnConnection, и createSmuxSession теперь используют одни строительные блоки, убирая ~140 строк дублированной настройки. Глобал handshakeSem убран, заменён двумя сконфигурированными dtlsdial.Dialer: udpDtlsDialer (timeout 20s, sem cap=3) и vlessDtlsDialer (timeout 30s, без gate). Поведение идентично прежним путям. client/main.go: 1380 → 1195. Импорты netadapt, pion/dtls, selfsign, pion/logging и pion/turn вынесены из client/main.go в новые пакеты.
This commit is contained in:
1 parent
5bf6dd0399
commit
bc1aea625b
5 files changed
+329
-215
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package turnpipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Open dialing a bogus address must surface a wrapped resolve/dial error.
|
||||
func TestOpen_BadAddress(t *testing.T) {
|
||||
peer := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1}
|
||||
_, err := Open(context.Background(), Config{}, peer, "u", "p", "not-a-host-port")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for malformed addr")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "parse TURN addr") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Open with overrides resolves the override host:port (still fails because
|
||||
// there's no TURN server, but the dial error must mention the override).
|
||||
func TestOpen_HostOverrideApplied(t *testing.T) {
|
||||
peer := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||
defer cancel()
|
||||
_, err := Open(ctx, Config{HostOverride: "127.0.0.1", PortOverride: "1", UDP: false, DialTimeout: 200 * time.Millisecond}, peer, "u", "p", "8.8.8.8:443")
|
||||
if err == nil {
|
||||
t.Fatal("expected dial error against unreachable :1")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "dial TURN") {
|
||||
t.Fatalf("expected dial error, got: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user