diff --git a/README.en.md b/README.en.md index fc6fa03..f665b81 100644 --- a/README.en.md +++ b/README.en.md @@ -86,6 +86,7 @@ Additional flags: - `-turn `: override TURN server address. - `-port `: override TURN server port. - `-no-dtls`: without DTLS obfuscation (may result in a ban). +- `-v1`: use v1 protocol (no session_id and stream_id sent). For legacy servers. #### Linux diff --git a/README.md b/README.md index f1aeca5..54155fd 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ chmod 777 ./client-android - `-turn `: переопределить адрес TURN сервера. - `-port `: переопределить порт TURN сервера. - `-no-dtls`: без DTLS-обфускации (может привести к бану). +- `-v1`: использовать протокол v1 (без отправки session_id и stream_id). Для серверов старой версии. #### Linux diff --git a/client/main.go b/client/main.go index 3e19922..001e127 100644 --- a/client/main.go +++ b/client/main.go @@ -52,7 +52,7 @@ func dtlsFunc(ctx context.Context, conn net.PacketConn, peer *net.UDPAddr) (net. return dtlsConn, nil } -func oneDtlsConnection(ctx context.Context, peer *net.UDPAddr, listenConn net.PacketConn, connchan chan<- net.PacketConn, okchan chan<- struct{}, c chan<- error, sessionID []byte, streamID byte) { +func oneDtlsConnection(ctx context.Context, peer *net.UDPAddr, listenConn net.PacketConn, connchan chan<- net.PacketConn, okchan chan<- struct{}, c chan<- error, sessionID []byte, streamID byte, v1 bool) { var err error = nil defer func() { c <- err }() dtlsctx, dtlscancel := context.WithCancel(ctx) @@ -81,17 +81,20 @@ func oneDtlsConnection(ctx context.Context, peer *net.UDPAddr, listenConn net.Pa log.Printf("Closed DTLS connection\n") }() - // Phase 1: Send Session ID + Stream ID (17 bytes) - dtlsConn.SetWriteDeadline(time.Now().Add(time.Second * 5)) - idBuf := make([]byte, 17) - copy(idBuf[:16], sessionID) - idBuf[16] = streamID - if _, err1 = dtlsConn.Write(idBuf); err1 != nil { - err = fmt.Errorf("failed to send session ID: %s", err1) - return + // Phase 1: Send Session ID + Stream ID (17 bytes) - only for v2 protocol + if !v1 { + dtlsConn.SetWriteDeadline(time.Now().Add(time.Second * 5)) + idBuf := make([]byte, 17) + copy(idBuf[:16], sessionID) + idBuf[16] = streamID + if _, err1 = dtlsConn.Write(idBuf); err1 != nil { + err = fmt.Errorf("failed to send session ID: %s", err1) + return + } + log.Printf("Established DTLS connection and sent session ID with stream %d!\n", streamID) + } else { + log.Printf("Established DTLS connection (v1 protocol, no session ID)!\n") } - - log.Printf("Established DTLS connection and sent session ID with stream %d!\n", streamID) go func() { for { select { @@ -369,14 +372,14 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD conn2.SetDeadline(time.Time{}) } -func oneDtlsConnectionLoop(ctx context.Context, peer *net.UDPAddr, listenConnChan <-chan net.PacketConn, connchan chan<- net.PacketConn, okchan chan<- struct{}, sessionID []byte, streamID byte) { +func oneDtlsConnectionLoop(ctx context.Context, peer *net.UDPAddr, listenConnChan <-chan net.PacketConn, connchan chan<- net.PacketConn, okchan chan<- struct{}, sessionID []byte, streamID byte, v1 bool) { for { select { case <-ctx.Done(): return case listenConn := <-listenConnChan: c := make(chan error) - go oneDtlsConnection(ctx, peer, listenConn, connchan, okchan, c, sessionID, streamID) + go oneDtlsConnection(ctx, peer, listenConn, connchan, okchan, c, sessionID, streamID, v1) if err := <-c; err != nil { log.Printf("%s", err) } @@ -432,6 +435,7 @@ func main() { //nolint:cyclop n := flag.Int("n", 0, "connections to TURN (default 4)") udp := flag.Bool("udp", false, "connect to TURN with UDP") direct := flag.Bool("no-dtls", false, "connect without obfuscation. DO NOT USE") + v1 := flag.Bool("v1", false, "use v1 server protocol (no session_id and stream_id)") sessionIDFlag := flag.String("session-id", "", "override session ID (hex, 32 chars)") flag.Parse() if *peerAddr == "" { @@ -525,7 +529,7 @@ func main() { //nolint:cyclop wg1.Add(1) go func() { defer wg1.Done() - oneDtlsConnectionLoop(ctx, peer, listenConnChan, connchan, okchan, sessionID, 0) + oneDtlsConnectionLoop(ctx, peer, listenConnChan, connchan, okchan, sessionID, 0, *v1) }() wg1.Add(1) @@ -544,7 +548,7 @@ func main() { //nolint:cyclop wg1.Add(1) go func(sID byte) { defer wg1.Done() - oneDtlsConnectionLoop(ctx, peer, listenConnChan, connchan, nil, sessionID, sID) + oneDtlsConnectionLoop(ctx, peer, listenConnChan, connchan, nil, sessionID, sID, *v1) }(byte(streamID)) wg1.Add(1) go func() {