feat: мультиплексирование звонков (#21)
This commit is contained in:
17 files changed
+1178
-48
No files matched your search
+43
-19
@@ -14,6 +14,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samosvalishe/free-turn-proxy/internal/transport/kcptun"
|
||||
"github.com/samosvalishe/free-turn-proxy/internal/uri"
|
||||
@@ -55,13 +56,15 @@ const (
|
||||
ObfProfileNone ObfProfile = "none" // обфускация отключена
|
||||
ObfProfileRTPOpus ObfProfile = "rtpopus" // RTP/opus + ChaCha20-Poly1305 AEAD
|
||||
ObfProfileRTPOpus2 ObfProfile = "rtpopus2" // rtpopus + RTP header extension (мимикрия под современный WebRTC)
|
||||
ObfProfileRTPOpus3 ObfProfile = "rtpopus3" // rtpopus2 + abs-send-time + VAD + loss simulation + variable ts
|
||||
)
|
||||
|
||||
// ObfOpts - опции обфускации TURN-payload.
|
||||
type ObfOpts struct {
|
||||
Profile ObfProfile // -obf-profile: none (default) | rtpopus | rtpopus2
|
||||
Key []byte // -obf-key (декодированный): 32-байтовый общий ключ; nil если Profile=none
|
||||
GenKey bool // -gen-obf-key: напечатать новый ключ и выйти
|
||||
Profile ObfProfile // -obf-profile: none (default) | rtpopus | rtpopus2
|
||||
Key []byte // -obf-key (декодированный): 32-байтовый общий ключ; nil если Profile=none
|
||||
GenKey bool // -gen-obf-key: напечатать новый ключ и выйти
|
||||
Timing time.Duration // -obf-timing: межпакетная задержка (RTP-мимикрия); 0=выкл
|
||||
}
|
||||
|
||||
// Enabled возвращает true когда выбран реальный профиль обфускации.
|
||||
@@ -87,10 +90,10 @@ const (
|
||||
|
||||
// VKOpts - опции VK-учёток и captcha (только клиент, провайдер "vk").
|
||||
type VKOpts struct {
|
||||
Link string // -link (нормализован до join-кода)
|
||||
StreamsPerCred int // -streams-per-cred
|
||||
ManualCaptcha bool // -manual-captcha
|
||||
Browser Browser // -browser: chrome | firefox
|
||||
Links []string // -links (нормализованные join-коды); несколько = больше стримов
|
||||
StreamsPerCred int // -streams-per-cred
|
||||
ManualCaptcha bool // -manual-captcha
|
||||
Browser Browser // -browser: chrome | firefox
|
||||
}
|
||||
|
||||
// ProviderOpts выбирает реализацию provider.Provider.
|
||||
@@ -175,15 +178,17 @@ func ParseClient(args []string, errOut io.Writer) (*Client, error) {
|
||||
port := fs.String("port", "", "порт TURN-сервера; override creds провайдера")
|
||||
listen := fs.String("listen", "127.0.0.1:9000", "локальный ip:port для WireGuard/Xray клиента")
|
||||
provider := fs.String("provider", ProviderVK, "источник TURN-creds: vk")
|
||||
link := fs.String("link", "", "ссылка VK Calls https://vk.ru/call/join/...; обязательно для -provider vk")
|
||||
link := fs.String("link", "", "(устарел) одна ссылка VK Calls, используйте -links")
|
||||
links := fs.String("links", "", "ссылки VK Calls через запятую: https://vk.ru/call/join/...,https://vk.ru/call/join/...")
|
||||
peer := fs.String("peer", "", "адрес сервера на VPS, host:port; обязательно")
|
||||
n := fs.Int("n", 10, "число параллельных TURN-потоков")
|
||||
transport := fs.String("transport", "tcp", "транспорт до TURN-реле: tcp | udp")
|
||||
mode := fs.String("mode", "udp", "режим туннеля: udp (WireGuard) | tcp (Xray/sing-box)")
|
||||
bond := fs.Bool("bond", false, "страйпинг TCP по smux-сессиям; только с -mode tcp")
|
||||
obfProfile := fs.String("obf-profile", string(ObfProfileNone), "wire-профиль обфускации: none | rtpopus | rtpopus2; должен совпадать с сервером")
|
||||
obfProfile := fs.String("obf-profile", string(ObfProfileNone), "wire-профиль обфускации: none | rtpopus | rtpopus2 | rtpopus3; должен совпадать с сервером")
|
||||
obfKey := fs.String("obf-key", "", "ключ для -obf-profile != none: 32 байта hex (64 символа)")
|
||||
genObfKey := fs.Bool("gen-obf-key", false, "напечатать новый -obf-key и выйти")
|
||||
obfTiming := fs.Duration("obf-timing", 0, "межпакетная задержка для RTP-мимикрии (напр. 20ms); 0=выкл")
|
||||
streamsPerCred := fs.Int("streams-per-cred", defaultStreamsPerCache, "TURN-потоков на один кеш VK-creds; только -provider vk")
|
||||
debug := fs.Bool("debug", false, "подробные debug-логи")
|
||||
manualCaptcha := fs.Bool("manual-captcha", false, "ручная VK captcha в браузере вместо авто; только -provider vk")
|
||||
@@ -207,6 +212,7 @@ func ParseClient(args []string, errOut io.Writer) (*Client, error) {
|
||||
Obf: ObfOpts{
|
||||
Profile: ObfProfile(*obfProfile),
|
||||
GenKey: *genObfKey,
|
||||
Timing: *obfTiming,
|
||||
},
|
||||
Proxy: ProxyOpts{
|
||||
Mode: ClientProxyMode(*mode, *bond),
|
||||
@@ -323,8 +329,8 @@ func ParseClient(args []string, errOut io.Writer) (*Client, error) {
|
||||
}
|
||||
switch c.Provider.Name {
|
||||
case ProviderVK:
|
||||
if *link == "" {
|
||||
return nil, errors.New("need -link (required for -provider vk)")
|
||||
if *links == "" && *link == "" {
|
||||
return nil, errors.New("need -links (или -link) (required for -provider vk)")
|
||||
}
|
||||
if c.VK.StreamsPerCred <= 0 {
|
||||
return nil, fmt.Errorf("-streams-per-cred must be positive")
|
||||
@@ -334,12 +340,28 @@ func ParseClient(args []string, errOut io.Writer) (*Client, error) {
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid -browser value %q: must be %s | %s", c.VK.Browser, BrowserChrome, BrowserFirefox)
|
||||
}
|
||||
parts := strings.Split(*link, "join/")
|
||||
link := parts[len(parts)-1]
|
||||
if idx := strings.IndexAny(link, "/?#"); idx != -1 {
|
||||
link = link[:idx]
|
||||
rawLinks := strings.Split(*links, ",")
|
||||
if len(rawLinks) == 1 && rawLinks[0] == "" {
|
||||
// -links не задан, используем -link (backward compat)
|
||||
rawLinks = []string{*link}
|
||||
}
|
||||
for _, raw := range rawLinks {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(raw, "join/")
|
||||
normalized := parts[len(parts)-1]
|
||||
if idx := strings.IndexAny(normalized, "/?#"); idx != -1 {
|
||||
normalized = normalized[:idx]
|
||||
}
|
||||
if normalized != "" {
|
||||
c.VK.Links = append(c.VK.Links, normalized)
|
||||
}
|
||||
}
|
||||
if len(c.VK.Links) == 0 {
|
||||
return nil, errors.New("need at least one valid VK link")
|
||||
}
|
||||
c.VK.Link = link
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid -provider value %q: must be %s", c.Provider.Name, ProviderVK)
|
||||
}
|
||||
@@ -368,9 +390,10 @@ func ParseServer(args []string, errOut io.Writer) (*Server, error) {
|
||||
listen := fs.String("listen", "0.0.0.0:56000", "локальный адрес прослушивания ip:port")
|
||||
connect := fs.String("connect", "", "локальный бэкенд host:port; обязательно: WG 127.0.0.1:51820 | Xray 127.0.0.1:443")
|
||||
mode := fs.String("mode", "udp", "режим туннеля: udp (WireGuard) | tcp (Xray/sing-box; bond авто)")
|
||||
obfProfile := fs.String("obf-profile", string(ObfProfileNone), "wire-профиль обфускации: none | rtpopus | rtpopus2; должен совпадать с клиентом")
|
||||
obfProfile := fs.String("obf-profile", string(ObfProfileNone), "wire-профиль обфускации: none | rtpopus | rtpopus2 | rtpopus3; должен совпадать с клиентом")
|
||||
obfKey := fs.String("obf-key", "", "ключ для -obf-profile != none: 32 байта hex (64 символа)")
|
||||
genObfKey := fs.Bool("gen-obf-key", false, "напечатать новый -obf-key и выйти")
|
||||
obfTiming := fs.Duration("obf-timing", 0, "межпакетная задержка для RTP-мимикрии (напр. 10ms); 0=выкл")
|
||||
debug := fs.Bool("debug", false, "подробные debug-логи")
|
||||
clientsFile := fs.String("clients-file", "", "путь к файлу clients.json для авторизации по Client ID")
|
||||
|
||||
@@ -382,6 +405,7 @@ func ParseServer(args []string, errOut io.Writer) (*Server, error) {
|
||||
Obf: ObfOpts{
|
||||
Profile: ObfProfile(*obfProfile),
|
||||
GenKey: *genObfKey,
|
||||
Timing: *obfTiming,
|
||||
},
|
||||
Proxy: ProxyOpts{
|
||||
Mode: serverProxyMode(*mode),
|
||||
@@ -426,10 +450,10 @@ func ParseServer(args []string, errOut io.Writer) (*Server, error) {
|
||||
// validateObfProfile проверяет что -obf-profile содержит известное значение.
|
||||
func validateObfProfile(p ObfProfile) error {
|
||||
switch p {
|
||||
case ObfProfileNone, ObfProfileRTPOpus, ObfProfileRTPOpus2:
|
||||
case ObfProfileNone, ObfProfileRTPOpus, ObfProfileRTPOpus2, ObfProfileRTPOpus3:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid -obf-profile value %q: must be %s | %s | %s", p, ObfProfileNone, ObfProfileRTPOpus, ObfProfileRTPOpus2)
|
||||
return fmt.Errorf("invalid -obf-profile value %q: must be %s | %s | %s | %s", p, ObfProfileNone, ObfProfileRTPOpus, ObfProfileRTPOpus2, ObfProfileRTPOpus3)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ func TestParseClient_Defaults(t *testing.T) {
|
||||
if c.VK.StreamsPerCred != defaultStreamsPerCache {
|
||||
t.Errorf("VK.StreamsPerCred default: %d", c.VK.StreamsPerCred)
|
||||
}
|
||||
if c.VK.Link != "abcdef" {
|
||||
t.Errorf("VK.Link: %q (expected abcdef)", c.VK.Link)
|
||||
if len(c.VK.Links) != 1 || c.VK.Links[0] != "abcdef" {
|
||||
t.Errorf("VK.Links: %v (expected [abcdef])", c.VK.Links)
|
||||
}
|
||||
if c.Obf.Key != nil {
|
||||
t.Errorf("Obf.Key should be nil when -obf-profile absent")
|
||||
@@ -62,8 +62,8 @@ func TestParseClient_VKLinkStrip(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.VK.Link != "CODE123" {
|
||||
t.Errorf("VK.Link: %q (expected CODE123)", c.VK.Link)
|
||||
if len(c.VK.Links) != 1 || c.VK.Links[0] != "CODE123" {
|
||||
t.Errorf("VK.Links: %v (expected [CODE123])", c.VK.Links)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +74,32 @@ func TestParseClient_MissingPeer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_MultiLinks(t *testing.T) {
|
||||
args := []string{
|
||||
"-peer", "1.2.3.4:5000",
|
||||
"-links", "https://vk.ru/call/join/LINK1,https://vk.ru/call/join/LINK2?foo=bar,https://vk.ru/call/join/LINK3/extra",
|
||||
}
|
||||
c, err := ParseClient(args, io.Discard)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(c.VK.Links) != 3 {
|
||||
t.Fatalf("expected 3 links, got %d: %v", len(c.VK.Links), c.VK.Links)
|
||||
}
|
||||
if c.VK.Links[0] != "LINK1" {
|
||||
t.Errorf("VK.Links[0]: %q (expected LINK1)", c.VK.Links[0])
|
||||
}
|
||||
if c.VK.Links[1] != "LINK2" {
|
||||
t.Errorf("VK.Links[1]: %q (expected LINK2)", c.VK.Links[1])
|
||||
}
|
||||
if c.VK.Links[2] != "LINK3" {
|
||||
t.Errorf("VK.Links[2]: %q (expected LINK3)", c.VK.Links[2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseClient_MissingVKLink(t *testing.T) {
|
||||
_, err := ParseClient([]string{"-peer", "1.2.3.4:5000"}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "-link") {
|
||||
if err == nil || !(strings.Contains(err.Error(), "-links") || strings.Contains(err.Error(), "-link")) {
|
||||
t.Errorf("expected vk-link error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user