Browse Source

fix: Rename tcp mode into vless

pull/102/head
Moroka8 2 months ago
parent
commit
44b91d7eee
  1. 17
      README.md
  2. 20
      client/main.go
  3. 8
      docker-entrypoint.sh
  4. 18
      server/main.go

17
README.md

@ -203,7 +203,7 @@ curl -L -o client https://github.com/cacggghp/vk-turn-proxy/releases/latest/down
С помощью опции `-turn` можно указать адрес TURN сервера вручную. Это должен быть сервер ВК, Макса или Одноклассников (ссылка вк) или Яндекса (ссылка яндекса). Возможно потом составлю список.
Если не работает TCP, попробуйте добавить флаг `-udp`.
Если не работает VLESS, попробуйте добавить флаг `-udp`.
Добавьте флаг `-n 1` для более стабильного подключения в 1 поток (ограничение 5 Мбит/с для ВК)
@ -330,29 +330,29 @@ curl -L -o client https://github.com/cacggghp/vk-turn-proxy/releases/latest/down
</details>
## VLESS (TCP-режим)
## VLESS-режим
Если WireGuard блокируется DPI, можно использовать VLESS через флаг `-tcp`. В этом режиме вместо UDP-пакетов пробрасываются TCP-соединения через TURN-туннель с помощью KCP и smux.
Если WireGuard блокируется DPI, можно использовать VLESS через флаг `-vless`. В этом режиме вместо UDP-пакетов пробрасываются TCP-соединения через TURN-туннель с помощью KCP и smux.
### Настройка
1. На VPS установить Xray с VLESS inbound
2. Запустить `server` с флагом `-tcp`
3. На клиенте запустить `client` с флагом `-tcp`
2. Запустить `server` с флагом `-vless`
3. На клиенте запустить `client` с флагом `-vless`
4. Настроить Xray/v2rayN клиент с VLESS outbound на `127.0.0.1:9000`
### Сервер (VPS)
```
./server -listen 0.0.0.0:56000 -connect 127.0.0.1:443 -tcp
./server -listen 0.0.0.0:56000 -connect 127.0.0.1:443 -vless
```
#### Docker
```
docker run -p 56000:56000/udp -e CONNECT_ADDR=127.0.0.1:443 -e TCP_MODE=true vk-turn-proxy
docker run -p 56000:56000/udp -e CONNECT_ADDR=127.0.0.1:443 -e VLESS_MODE=true vk-turn-proxy
```
### Клиент
```
./client -peer <ip сервера>:56000 -vk-link <VK ссылка> -listen 127.0.0.1:9000 -tcp
./client -peer <ip сервера>:56000 -vk-link <VK ссылка> -listen 127.0.0.1:9000 -vless
```
<details>
@ -442,7 +442,6 @@ Xray сервер (config.json)
</details>
> **Важно:** В TCP-режиме используется один TURN-поток. Для VK это ограничивает скорость ~5 Мбит/с.
## Direct mode

20
client/main.go

@ -1366,7 +1366,7 @@ func main() { //nolint:cyclop
n := flag.Int("n", 0, "connections to TURN (default 10 for VK, 1 for Yandex)")
udp := flag.Bool("udp", false, "connect to TURN with UDP")
direct := flag.Bool("no-dtls", false, "connect without obfuscation. DO NOT USE")
tcpMode := flag.Bool("tcp", false, "TCP mode: forward TCP connections (for VLESS) instead of UDP packets")
vlessMode := flag.Bool("vless", false, "VLESS mode: forward TCP connections (for VLESS) instead of UDP packets")
flag.Parse()
if *peerAddr == "" {
log.Panicf("Need peer address!")
@ -1416,8 +1416,8 @@ func main() { //nolint:cyclop
getCreds: poolCreds(getCreds, 1),
}
if *tcpMode {
runTCPMode(ctx, params, peer, *listen, *n)
if *vlessMode {
runVLESSMode(ctx, params, peer, *listen, *n)
return
}
@ -1530,8 +1530,8 @@ func (p *sessionPool) count() int {
return len(p.sessions)
}
// runTCPMode implements TCP forwarding with round-robin across N TURN sessions.
func runTCPMode(ctx context.Context, tp *turnParams, peer *net.UDPAddr, listenAddr string, numSessions int) {
// runVLESSMode implements TCP forwarding with round-robin across N TURN sessions.
func runVLESSMode(ctx context.Context, tp *turnParams, peer *net.UDPAddr, listenAddr string, numSessions int) {
pool := &sessionPool{}
// Start N session maintainers with staggered startup
@ -1545,12 +1545,12 @@ func runTCPMode(ctx context.Context, tp *turnParams, peer *net.UDPAddr, listenAd
return
case <-time.After(time.Duration(id) * 300 * time.Millisecond):
}
maintainTCPSession(ctx, tp, peer, id, pool)
maintainVLESSSession(ctx, tp, peer, id, pool)
}(i)
}
// Wait for at least one session
log.Printf("TCP mode: waiting for sessions to connect (total: %d)...", numSessions)
log.Printf("VLESS mode: waiting for sessions to connect (total: %d)...", numSessions)
for {
select {
case <-ctx.Done():
@ -1568,7 +1568,7 @@ func runTCPMode(ctx context.Context, tp *turnParams, peer *net.UDPAddr, listenAd
log.Panicf("TCP listen: %s", err)
}
context.AfterFunc(ctx, func() { _ = listener.Close() })
log.Printf("TCP mode: listening on %s (round-robin across %d sessions)", listenAddr, numSessions)
log.Printf("VLESS mode: listening on %s (round-robin across %d sessions)", listenAddr, numSessions)
var wgConn sync.WaitGroup
for {
@ -1607,8 +1607,8 @@ func runTCPMode(ctx context.Context, tp *turnParams, peer *net.UDPAddr, listenAd
}
}
// maintainTCPSession keeps one TURN+DTLS+KCP+smux session alive, reconnecting on failure.
func maintainTCPSession(ctx context.Context, tp *turnParams, peer *net.UDPAddr, id int, pool *sessionPool) {
// maintainVLESSSession keeps one TURN+DTLS+KCP+smux session alive, reconnecting on failure.
func maintainVLESSSession(ctx context.Context, tp *turnParams, peer *net.UDPAddr, id int, pool *sessionPool) {
for {
select {
case <-ctx.Done():

8
docker-entrypoint.sh

@ -3,9 +3,9 @@ set -e
CONNECT="${CONNECT_ADDR:?CONNECT_ADDR is required}"
TCP_FLAG=""
if [ "${TCP_MODE}" = "true" ]; then
TCP_FLAG="-tcp"
VLESS_FLAG=""
if [ "${VLESS_MODE}" = "true" ]; then
VLESS_FLAG="-vless"
fi
exec ./vk-turn-proxy -listen 0.0.0.0:56000 -connect "$CONNECT" $TCP_FLAG
exec ./vk-turn-proxy -listen 0.0.0.0:56000 -connect "$CONNECT" $VLESS_FLAG

18
server/main.go

@ -23,7 +23,7 @@ import (
func main() {
listen := flag.String("listen", "0.0.0.0:56000", "listen on ip:port")
connect := flag.String("connect", "", "connect to ip:port")
tcpMode := flag.Bool("tcp", false, "TCP mode: forward TCP connections (for VLESS) instead of UDP packets")
vlessMode := flag.Bool("vless", false, "VLESS mode: forward TCP connections (for VLESS) instead of UDP packets")
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
@ -113,8 +113,8 @@ func main() {
cancel1()
log.Println("Handshake done")
if *tcpMode {
handleTCPConnection(ctx, dtlsConn, *connect)
if *vlessMode {
handleVLESSConnection(ctx, dtlsConn, *connect)
} else {
handleUDPConnection(ctx, conn, *connect)
}
@ -212,16 +212,16 @@ func handleUDPConnection(ctx context.Context, conn net.Conn, connectAddr string)
wg.Wait()
}
// handleTCPConnection creates a KCP+smux session over DTLS and forwards
// handleVLESSConnection creates a KCP+smux session over DTLS and forwards
// each smux stream as a TCP connection to the backend (Xray/VLESS).
func handleTCPConnection(ctx context.Context, dtlsConn net.Conn, connectAddr string) {
func handleVLESSConnection(ctx context.Context, dtlsConn net.Conn, connectAddr string) {
// 1. Create KCP session over DTLS
kcpSess, err := tcputil.NewKCPOverDTLS(dtlsConn, true)
if err != nil {
log.Printf("KCP session error: %s", err)
return
}
defer func() { _ = kcpSess.Close() }()
defer kcpSess.Close()
log.Printf("KCP session established (server)")
// 2. Create smux server session over KCP
@ -230,7 +230,7 @@ func handleTCPConnection(ctx context.Context, dtlsConn net.Conn, connectAddr str
log.Printf("smux server error: %s", err)
return
}
defer func() { _ = smuxSess.Close() }()
defer smuxSess.Close()
log.Printf("smux session established (server)")
// 3. Accept smux streams and forward to backend via TCP
@ -249,7 +249,7 @@ func handleTCPConnection(ctx context.Context, dtlsConn net.Conn, connectAddr str
wg.Add(1)
go func(s *smux.Stream) {
defer wg.Done()
defer func() { _ = s.Close() }()
defer s.Close()
// Connect to backend (Xray/VLESS)
backendConn, err := net.DialTimeout("tcp", connectAddr, 10*time.Second)
@ -257,7 +257,7 @@ func handleTCPConnection(ctx context.Context, dtlsConn net.Conn, connectAddr str
log.Printf("backend dial error: %s", err)
return
}
defer func() { _ = backendConn.Close() }()
defer backendConn.Close()
// Bidirectional copy
pipeConn(ctx, s, backendConn)

Loading…
Cancel
Save