linux joiner

This commit is contained in:
kulikov0 committed 2026-05-11 18:01:34 +02:00
1 parent 30ed29a161
commit 18358c8927
17 files changed
+185 -86

No files matched your search

@@ -0,0 +1,7 @@
desktop-joiner-windows-*.exe
desktop-joiner-linux-*
desktop-joiner-bundle
desktop-joiner-bundle.exe
wintun-*.dll
wintun-bundle.dll
wintun.zip
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="whitelist.bypass.desktop-joiner"
version="1.0.0.0"
processorArchitecture="*"/>
<description>Whitelist Bypass Desktop Joiner</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10/11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>
+49
View File
@@ -0,0 +1,49 @@
module desktop-joiner
go 1.26.1
require whitelist-bypass/relay v0.0.0
require (
github.com/ajg/form v1.5.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-chi/chi/v5 v5.2.1 // indirect
github.com/go-chi/cors v1.2.1 // indirect
github.com/go-chi/render v1.0.3 // indirect
github.com/go-gost/relay v0.5.0 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/schema v1.4.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/pion/datachannel v1.6.0 // indirect
github.com/pion/dtls/v3 v3.1.2 // indirect
github.com/pion/ice/v4 v4.2.1 // indirect
github.com/pion/interceptor v0.1.44 // indirect
github.com/pion/logging v0.2.4 // indirect
github.com/pion/mdns/v2 v2.1.0 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.16 // indirect
github.com/pion/rtp v1.10.1 // indirect
github.com/pion/sctp v1.9.2 // indirect
github.com/pion/sdp/v3 v3.0.18 // indirect
github.com/pion/srtp/v3 v3.0.10 // indirect
github.com/pion/stun/v3 v3.1.1 // indirect
github.com/pion/transport/v4 v4.0.1 // indirect
github.com/pion/turn/v4 v4.1.4 // indirect
github.com/pion/webrtc/v4 v4.2.9 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
github.com/xjasonlyu/tun2socks/v2 v2.6.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/time v0.11.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb // indirect
gvisor.dev/gvisor v0.0.0-20250523182742-eede7a881b20 // indirect
)
replace whitelist-bypass/relay => ../../relay
+90
View File
@@ -0,0 +1,90 @@
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
github.com/go-gost/relay v0.5.0 h1:JG1tgy/KWiVXS0ukuVXvbM0kbYuJTWxYpJ5JwzsCf/c=
github.com/go-gost/relay v0.5.0/go.mod h1:lcX+23LCQ3khIeASBo+tJ/WbwXFO32/N5YN6ucuYTG8=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pion/datachannel v1.6.0 h1:XecBlj+cvsxhAMZWFfFcPyUaDZtd7IJvrXqlXD/53i0=
github.com/pion/datachannel v1.6.0/go.mod h1:ur+wzYF8mWdC+Mkis5Thosk+u/VOL287apDNEbFpsIk=
github.com/pion/dtls/v3 v3.1.2 h1:gqEdOUXLtCGW+afsBLO0LtDD8GnuBBjEy6HRtyofZTc=
github.com/pion/dtls/v3 v3.1.2/go.mod h1:Hw/igcX4pdY69z1Hgv5x7wJFrUkdgHwAn/Q/uo7YHRo=
github.com/pion/ice/v4 v4.2.1 h1:XPRYXaLiFq3LFDG7a7bMrmr3mFr27G/gtXN3v/TVfxY=
github.com/pion/ice/v4 v4.2.1/go.mod h1:2quLV1S5v1tAx3VvAJaH//KGitRXvo4RKlX6D3tnN+c=
github.com/pion/interceptor v0.1.44 h1:sNlZwM8dWXU9JQAkJh8xrarC0Etn8Oolcniukmuy0/I=
github.com/pion/interceptor v0.1.44/go.mod h1:4atVlBkcgXuUP+ykQF0qOCGU2j7pQzX2ofvPRFsY5RY=
github.com/pion/logging v0.2.4 h1:tTew+7cmQ+Mc1pTBLKH2puKsOvhm32dROumOZ655zB8=
github.com/pion/logging v0.2.4/go.mod h1:DffhXTKYdNZU+KtJ5pyQDjvOAh/GsNSyv1lbkFbe3so=
github.com/pion/mdns/v2 v2.1.0 h1:3IJ9+Xio6tWYjhN6WwuY142P/1jA0D5ERaIqawg/fOY=
github.com/pion/mdns/v2 v2.1.0/go.mod h1:pcez23GdynwcfRU1977qKU0mDxSeucttSHbCSfFOd9A=
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.16 h1:fk1B1dNW4hsI78XUCljZJlC4kZOPk67mNRuQ0fcEkSo=
github.com/pion/rtcp v1.2.16/go.mod h1:/as7VKfYbs5NIb4h6muQ35kQF/J0ZVNz2Z3xKoCBYOo=
github.com/pion/rtp v1.10.1 h1:xP1prZcCTUuhO2c83XtxyOHJteISg6o8iPsE2acaMtA=
github.com/pion/rtp v1.10.1/go.mod h1:rF5nS1GqbR7H/TCpKwylzeq6yDM+MM6k+On5EgeThEM=
github.com/pion/sctp v1.9.2 h1:HxsOzEV9pWoeggv7T5kewVkstFNcGvhMPx0GvUOUQXo=
github.com/pion/sctp v1.9.2/go.mod h1:OTOlsQ5EDQ6mQ0z4MUGXt2CgQmKyafBEXhUVqLRB6G8=
github.com/pion/sdp/v3 v3.0.18 h1:l0bAXazKHpepazVdp+tPYnrsy9dfh7ZbT8DxesH5ZnI=
github.com/pion/sdp/v3 v3.0.18/go.mod h1:ZREGo6A9ZygQ9XkqAj5xYCQtQpif0i6Pa81HOiAdqQ8=
github.com/pion/srtp/v3 v3.0.10 h1:tFirkpBb3XccP5VEXLi50GqXhv5SKPxqrdlhDCJlZrQ=
github.com/pion/srtp/v3 v3.0.10/go.mod h1:3mOTIB0cq9qlbn59V4ozvv9ClW/BSEbRp4cY0VtaR7M=
github.com/pion/stun/v3 v3.1.1 h1:CkQxveJ4xGQjulGSROXbXq94TAWu8gIX2dT+ePhUkqw=
github.com/pion/stun/v3 v3.1.1/go.mod h1:qC1DfmcCTQjl9PBaMa5wSn3x9IPmKxSdcCsxBcDBndM=
github.com/pion/transport/v3 v3.1.1 h1:Tr684+fnnKlhPceU+ICdrw6KKkTms+5qHMgw6bIkYOM=
github.com/pion/transport/v3 v3.1.1/go.mod h1:+c2eewC5WJQHiAA46fkMMzoYZSuGzA/7E2FPrOYHctQ=
github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k8o=
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
github.com/pion/turn/v4 v4.1.4 h1:EU11yMXKIsK43FhcUnjLlrhE4nboHZq+TXBIi3QpcxQ=
github.com/pion/turn/v4 v4.1.4/go.mod h1:ES1DXVFKnOhuDkqn9hn5VJlSWmZPaRJLyBXoOeO/BmQ=
github.com/pion/webrtc/v4 v4.2.9 h1:DZIh1HAhPIL3RvwEDFsmL5hfPSLEpxsQk9/Jir2vkJE=
github.com/pion/webrtc/v4 v4.2.9/go.mod h1:9EmLZve0H76eTzf8v2FmchZ6tcBXtDgpfTEu+drW6SY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/xjasonlyu/tun2socks/v2 v2.6.0 h1:gI9saJT3XgH4e6v9jBuHRLwK7l3aN9YFWec/SsDTDx4=
github.com/xjasonlyu/tun2socks/v2 v2.6.0/go.mod h1:35AwqxIxnMkfBfT0UJ1Lku7PZm2ZiZJ8sxHyp0gt1yw=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4=
golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA=
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb h1:whnFRlWMcXI9d+ZbWg+4sHnLp52d5yiIPUxMBSt4X9A=
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb/go.mod h1:rpwXGsirqLqN2L0JDJQlwOboGHmptD5ZD6T2VmcqhTw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20250523182742-eede7a881b20 h1:0DxLu8hxI1OGp1qVRPqNd+2k1a7hMNUNqbZG0IrtKlM=
gvisor.dev/gvisor v0.0.0-20250523182742-eede7a881b20/go.mod h1:3r5CMtNQMKIvBlrmM9xWUNamjKBYPOWyXOjmg5Kts3g=
+393
View File
@@ -0,0 +1,393 @@
// Command desktop-joiner is the engine behind the desktop joiner GUI.
// On Windows it brings up a wintun adapter so every IP packet on the
// host is steered through the resulting SOCKS5 proxy. On Linux it
// only exposes the SOCKS5 proxy (TUN routing is left to the user).
//
// On Windows it must run with administrator rights (the embedded
// manifest asks for them); creating wintun adapters and editing the
// route table both require elevation.
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/url"
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"strings"
"sync"
"syscall"
"time"
joinerCommon "whitelist-bypass/relay/pion/headless-joiner-common"
"whitelist-bypass/relay/common"
"whitelist-bypass/relay/pion"
"whitelist-bypass/relay/tunnel"
"whitelist-bypass/relay/wbstream"
"whitelist-bypass/relay/wintunnel"
)
type statusEmitter struct{}
func (statusEmitter) EmitStatus(status string) {
log.Printf("[status] %s", status)
// CAPTCHA:url is fired by the VK auth path when an interactive
// captcha is required. The Electron wrapper watches stdout for
// this exact prefix and opens a BrowserWindow at the URL.
if strings.HasPrefix(status, "CAPTCHA:") {
fmt.Printf("STATUS:%s\n", status)
}
}
func (statusEmitter) EmitStatusError(msg string) { log.Printf("[status] ERROR: %s", msg) }
type fileCacheStore struct{ dir string }
func newFileCacheStore() *fileCacheStore {
dir, _ := os.UserCacheDir()
if dir == "" {
dir = os.TempDir()
}
cacheDir := filepath.Join(dir, "whitelist-bypass")
os.MkdirAll(cacheDir, 0755)
return &fileCacheStore{dir: cacheDir}
}
func (c *fileCacheStore) Save(key, value string) {
os.WriteFile(filepath.Join(c.dir, key), []byte(value), 0644)
}
func (c *fileCacheStore) Load(key string) string {
data, err := os.ReadFile(filepath.Join(c.dir, key))
if err != nil {
return ""
}
return string(data)
}
const (
tunAdapter = "WhitelistBypass"
tunIP = "10.99.0.2"
tunMask = "255.255.255.0"
tunPeer = "10.99.0.1"
tunMTU = 1500
)
func main() {
platform := flag.String("platform", "", "wbstream | telemost | vk (required)")
link := flag.String("link", "", "WB Stream room link, Telemost join URI, or VK call link (required)")
displayName := flag.String("name", "Joiner", "display name in the room")
socksPort := flag.Int("socks-port", 1080, "local SOCKS5 port")
socksUser := flag.String("socks-user", "", "optional SOCKS5 username")
socksPass := flag.String("socks-pass", "", "optional SOCKS5 password")
resources := flag.String("resources", "default", "moderate | default | unlimited")
tunnelMode := flag.String("tunnel-mode", "video", "tunnel mode for WB Stream: video | dc")
vp8FPS := flag.Int("vp8-fps", 24, "VP8 frame rate")
vp8Batch := flag.Int("vp8-batch", 30, "VP8 batch multiplier")
dns := flag.String("dns", "1.1.1.1,8.8.8.8", "comma-separated DNS servers for the tunnel adapter")
noTun := flag.Bool("no-tun", false, "expose SOCKS5 only, do not bring up the wintun adapter")
flag.Parse()
if *platform == "" || *link == "" {
log.Fatal("--platform and --link are required")
}
switch *resources {
case "moderate":
debug.SetMemoryLimit(64 << 20)
case "default":
debug.SetMemoryLimit(128 << 20)
case "unlimited":
debug.SetMemoryLimit(256 << 20)
default:
log.Fatalf("[config] unknown resources mode: %s", *resources)
}
common.MaskingEnabled = true
// One wintunnel.Tunnel covers both platforms. Created up-front so
// signaling-host bypass routes can be installed before any platform
// code touches the network.
var tun *wintunnel.Tunnel
if !*noTun {
cfg := wintunnel.Config{
AdapterName: tunAdapter,
TunnelIP: tunIP,
TunnelMask: tunMask,
TunnelPeer: tunPeer,
MTU: tunMTU,
DNSServers: splitCSV(*dns),
SocksHost: "127.0.0.1",
SocksPort: *socksPort,
SocksUser: *socksUser,
SocksPass: *socksPass,
LogFn: log.Printf,
}
var err error
tun, err = wintunnel.New(cfg)
if err != nil {
log.Fatalf("[wintunnel] init: %v", err)
}
}
// Add bypass routes for the signaling hosts before any traffic
// from the joiner reaches them. These are needed even before
// engine.Start, because the joiner opens its WebSocket as soon
// as we call Start() below.
bypassHosts := signalingHosts(*platform, *link)
preResolved := map[string][]net.IP{}
for _, h := range bypassHosts {
ips, err := net.LookupIP(h)
if err != nil {
log.Printf("[bypass] resolve %s: %v (will rely on candidate hook)", h, err)
continue
}
preResolved[h] = ips
log.Printf("[bypass] %s -> %v (pre-tun)", h, ips)
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
tunReady := make(chan struct{})
var tunOnce sync.Once
bringUpTun := func() {
tunOnce.Do(func() {
if tun == nil {
close(tunReady)
return
}
if err := tun.Start(); err != nil {
log.Fatalf("[wintunnel] start: %v", err)
}
// Now that the tunnel knows the original gateway,
// pin /32 bypass routes for the signaling hosts.
for host, ips := range preResolved {
for _, ip := range ips {
if err := tun.AddBypassIP(ip); err != nil {
log.Printf("[bypass] %s ip %s: %v", host, ip, err)
}
}
}
fmt.Printf("\n TUNNEL ACTIVE on adapter %q (DNS=%s)\n all traffic now egresses via %s\n\n",
tunAdapter, *dns, *platform)
close(tunReady)
})
}
addCandidate := func(target int, candidateOrSDP string) {
if tun == nil {
return
}
if err := tun.AddBypassFromCandidate(candidateOrSDP); err != nil {
log.Printf("[bypass] candidate: %v", err)
}
// SDP path: scan every candidate line in the blob
if strings.Contains(candidateOrSDP, "a=candidate:") {
for _, line := range strings.Split(candidateOrSDP, "\n") {
line = strings.TrimRight(line, "\r")
if strings.HasPrefix(line, "a=candidate:") {
if err := tun.AddBypassFromCandidate(line); err != nil {
log.Printf("[bypass] sdp candidate: %v", err)
}
}
}
}
}
onConnected := func(t tunnel.DataTunnel) {
readBuf := common.VP8BufSize
if _, ok := t.(*tunnel.DCTunnel); ok {
readBuf = common.DCBufSize
}
bridge := tunnel.NewRelayBridgeWithAuth(t, "joiner", readBuf, log.Printf, *socksUser, *socksPass)
bridge.MarkReady()
addr := fmt.Sprintf("127.0.0.1:%d", *socksPort)
go func() {
if err := bridge.ListenSOCKS(addr); err != nil {
log.Printf("[socks] listen: %v", err)
}
}()
log.Printf("[socks] listening on %s", addr)
// SOCKS5 is up; bring up wintun so the OS starts steering
// traffic into it. Doing this after the joiner has connected
// also means we already have remote candidates and bypass
// routes are in place.
bringUpTun()
}
switch strings.ToLower(*platform) {
case "wbstream", "wb":
runWBStream(*link, *displayName, *tunnelMode, *vp8FPS, *vp8Batch,
onConnected, addCandidate)
case "telemost", "tm":
runTelemost(*link, *displayName, *vp8FPS, *vp8Batch,
onConnected, addCandidate)
case "vk":
runVK(*link, *displayName, *tunnelMode, *vp8FPS, *vp8Batch,
onConnected, addCandidate)
default:
log.Fatalf("[config] unknown --platform %q", *platform)
}
<-sig
log.Printf("[main] shutting down")
if tun != nil {
tun.Stop()
}
// Give in-flight goroutines a beat to drain before the process exits.
time.Sleep(200 * time.Millisecond)
}
func splitCSV(s string) []string {
var out []string
for _, p := range strings.Split(s, ",") {
p = strings.TrimSpace(p)
if p != "" {
out = append(out, p)
}
}
return out
}
func signalingHosts(platform, link string) []string {
switch strings.ToLower(platform) {
case "wbstream", "wb":
return []string{"stream.wb.ru", "wbstream01-el.wb.ru"}
case "telemost", "tm":
hosts := []string{"telemost.yandex.ru", "telemost-api.yandex.ru"}
if u, err := url.Parse(strings.TrimSpace(link)); err == nil && u.Host != "" {
hosts = append(hosts, u.Host)
}
return hosts
case "vk":
hosts := []string{"vk.com", "login.vk.com", "api.vk.com", "ok.ru", "cloud-api.yandex.ru"}
if u, err := url.Parse(strings.TrimSpace(link)); err == nil && u.Host != "" {
hosts = append(hosts, u.Host)
}
return hosts
}
return nil
}
func runWBStream(link, name, mode string, fps, batch int,
onConnected func(tunnel.DataTunnel),
onCandidate func(int, string),
) {
id := strings.TrimPrefix(strings.TrimSpace(link), "wbstream://")
roomID, roomToken, _, err := wbstream.AuthAndGetToken(nil, id, name)
if err != nil {
log.Fatalf("[wb] auth: %v", err)
}
log.Printf("[wb] room=%s mode=%s", roomID, mode)
obf, err := tunnel.NewTunnelObfuscator(tunnel.DeriveSecretFromJoinLink(roomID))
if err != nil {
log.Fatalf("[wb] obfuscator: %v", err)
}
sess := wbstream.NewSession(wbstream.SessionConfig{
RoomToken: roomToken,
DisplayName: name,
TunnelMode: mode,
Obfuscator: obf,
LogFn: log.Printf,
VP8FPS: fps,
VP8Batch: batch,
})
sess.OnConnected = onConnected
sess.OnRemoteCandidate = onCandidate
if err := sess.Start(); err != nil {
log.Fatalf("[wb] session: %v", err)
}
}
func runTelemost(link, name string, fps, batch int,
onConnected func(tunnel.DataTunnel),
onCandidate func(int, string),
) {
inner := joinerCommon.NewTelemostHeadlessJoiner(
log.Printf,
resolveHostname,
statusEmitter{},
nil,
pion.AddTunnelTracks,
pion.ReadTrack,
)
inner.OnConnected = onConnected
inner.OnRemoteCandidate = onCandidate
params, _ := json.Marshal(struct {
JoinLink string `json:"joinLink"`
DisplayName string `json:"displayName"`
VP8FPS int `json:"vp8Fps"`
VP8Batch int `json:"vp8Batch"`
}{
JoinLink: strings.TrimSpace(link),
DisplayName: name,
VP8FPS: fps,
VP8Batch: batch,
})
go inner.RunWithParams(string(params))
}
func runVK(link, name, mode string, fps, batch int,
onConnected func(tunnel.DataTunnel),
onCandidate func(int, string),
) {
emitter := statusEmitter{}
statusFn := func(s string) { emitter.EmitStatus(s) }
authJSON, err := joinerCommon.RunVKAuth(strings.TrimSpace(link), name,
log.Printf, statusFn, newFileCacheStore(), resolveHostname)
if err != nil {
log.Fatalf("[vk] auth: %v", err)
}
var authParams map[string]interface{}
if json.Unmarshal([]byte(authJSON), &authParams) != nil {
log.Fatalf("[vk] auth response not JSON: %s", authJSON)
}
authParams["tunnelMode"] = mode
authParams["vp8Fps"] = fps
authParams["vp8Batch"] = batch
patched, err := json.Marshal(authParams)
if err != nil {
log.Fatalf("[vk] auth marshal: %v", err)
}
inner := joinerCommon.NewVKHeadlessJoiner(
log.Printf,
resolveHostname,
emitter,
nil,
pion.AddTunnelTracks,
pion.ReadTrack,
)
inner.OnConnected = onConnected
inner.OnRemoteCandidate = onCandidate
go inner.RunWithParams(string(patched))
}
func resolveHostname(hostname string) (string, error) {
if ip := net.ParseIP(hostname); ip != nil {
return hostname, nil
}
ips, err := net.LookupIP(hostname)
if err != nil {
return "", err
}
for _, ip := range ips {
if v4 := ip.To4(); v4 != nil {
return v4.String(), nil
}
}
for _, ip := range ips {
return ip.String(), nil
}
return "", fmt.Errorf("no IPs for %s", hostname)
}