wire bx to other platforms
This commit is contained in:
1 parent
33109b1ab5
commit
97c4d4b617
9 files changed
+191
-15
No files matched your search
@@ -95,7 +95,7 @@ const (
|
||||
)
|
||||
|
||||
func main() {
|
||||
platform := flag.String("platform", "", "wbstream | telemost | vk | dion (required)")
|
||||
platform := flag.String("platform", "", "wbstream | telemost | vk | dion | bitrix (required)")
|
||||
link := flag.String("link", "", "WB Stream room link, Telemost join URI, VK call link, or DION event link (required)")
|
||||
displayName := flag.String("name", "Joiner", "display name in the room")
|
||||
socksHost := flag.String("socks-host", common.SocksLocalhostIP, "SOCKS5 listen address (use 0.0.0.0 to expose on LAN; tun2socks always connects via loopback)")
|
||||
@@ -177,6 +177,8 @@ func main() {
|
||||
var (
|
||||
pendingMu sync.Mutex
|
||||
pending []string
|
||||
pendingIPs []net.IP
|
||||
seenIPs = map[string]struct{}{}
|
||||
tunStarted bool
|
||||
)
|
||||
bringUpTun := func() {
|
||||
@@ -197,7 +199,9 @@ func main() {
|
||||
}
|
||||
pendingMu.Lock()
|
||||
drained := pending
|
||||
drainedIPs := pendingIPs
|
||||
pending = nil
|
||||
pendingIPs = nil
|
||||
tunStarted = true
|
||||
pendingMu.Unlock()
|
||||
for _, c := range drained {
|
||||
@@ -205,6 +209,11 @@ func main() {
|
||||
log.Printf("[bypass] replay: %v", err)
|
||||
}
|
||||
}
|
||||
for _, ip := range drainedIPs {
|
||||
if err := tun.AddBypassIP(ip); err != nil {
|
||||
log.Printf("[bypass] replay ip %s: %v", 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)
|
||||
@@ -239,6 +248,36 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
bypassIP := func(ipStr string) {
|
||||
if tun == nil {
|
||||
return
|
||||
}
|
||||
ip := net.ParseIP(ipStr)
|
||||
if ip == nil {
|
||||
return
|
||||
}
|
||||
v4 := ip.To4()
|
||||
if v4 == nil {
|
||||
return
|
||||
}
|
||||
key := v4.String()
|
||||
pendingMu.Lock()
|
||||
if _, ok := seenIPs[key]; ok {
|
||||
pendingMu.Unlock()
|
||||
return
|
||||
}
|
||||
seenIPs[key] = struct{}{}
|
||||
if !tunStarted {
|
||||
pendingIPs = append(pendingIPs, v4)
|
||||
pendingMu.Unlock()
|
||||
return
|
||||
}
|
||||
pendingMu.Unlock()
|
||||
if err := tun.AddBypassIP(v4); err != nil {
|
||||
log.Printf("[bypass] ip %s: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
bridge *tunnel.RelayBridge
|
||||
bridgeMu sync.Mutex
|
||||
@@ -293,6 +332,9 @@ func main() {
|
||||
onConnected, addCandidate)
|
||||
case "dion", "dn":
|
||||
runDion(*link, *displayName, onConnected, addCandidate)
|
||||
case "bitrix", "bx":
|
||||
runBitrix(*link, *displayName, *tunnelMode, *vp8FPS, *vp8Batch, *dualTrack, *reliable,
|
||||
onConnected, addCandidate, bypassIP)
|
||||
default:
|
||||
log.Fatalf("[config] unknown --platform %q", *platform)
|
||||
}
|
||||
@@ -501,6 +543,49 @@ func runDion(link, name string,
|
||||
}()
|
||||
}
|
||||
|
||||
func runBitrix(link, name, mode string, fps, batch int, dualTrack, reliable bool,
|
||||
onConnected func(tunnel.DataTunnel),
|
||||
onCandidate func(int, string),
|
||||
bypassIP func(string),
|
||||
) {
|
||||
resolve := func(host string) (string, error) {
|
||||
ip, err := resolveHostname(host)
|
||||
if err == nil {
|
||||
bypassIP(ip)
|
||||
}
|
||||
return ip, err
|
||||
}
|
||||
|
||||
inner := joinerCommon.NewBitrixHeadlessJoiner(
|
||||
log.Printf,
|
||||
resolve,
|
||||
statusEmitter{},
|
||||
nil,
|
||||
)
|
||||
joinerConfigAck = inner.MarkConfigAcked
|
||||
inner.OnConnected = onConnected
|
||||
inner.OnRemoteCandidate = onCandidate
|
||||
|
||||
params, _ := json.Marshal(struct {
|
||||
JoinLink string `json:"joinLink"`
|
||||
DisplayName string `json:"displayName"`
|
||||
TunnelMode string `json:"tunnelMode"`
|
||||
VP8FPS int `json:"vp8Fps"`
|
||||
VP8Batch int `json:"vp8Batch"`
|
||||
DualTrack bool `json:"dualTrack"`
|
||||
Reliable bool `json:"reliable"`
|
||||
}{
|
||||
JoinLink: strings.TrimSpace(link),
|
||||
DisplayName: name,
|
||||
TunnelMode: mode,
|
||||
VP8FPS: fps,
|
||||
VP8Batch: batch,
|
||||
DualTrack: dualTrack,
|
||||
Reliable: reliable,
|
||||
})
|
||||
go inner.RunWithParams(string(params))
|
||||
}
|
||||
|
||||
func resolveHostname(hostname string) (string, error) {
|
||||
if ip := net.ParseIP(hostname); ip != nil {
|
||||
return hostname, nil
|
||||
|
||||
Reference in new issue
Block a user