share vp8 config push and ice resolve, fix vk ice hosts, widen kick greps
This commit is contained in:
1 parent
2f366b1128
commit
69de2bd8b7
10 files changed
+83
-162
No files matched your search
@@ -93,9 +93,9 @@ dump_logs() {
|
||||
|
||||
dump_kick_logs() {
|
||||
log " --- creator kick events ---"
|
||||
grep -nE '\[kick\]|kicked previous|active call guest|kick failed|usersAnswered|kicked stale peer|kick_one' "$CREATOR_LOG" 2>/dev/null | tail -20 >&2
|
||||
grep -nE '\[kick\]|kicked previous|active call guest|kick failed|usersAnswered|kicked stale peer|kick_one|Kicking|kick confirmed|Ghost participant|waiting_room_update|Participant joined|Participant left' "$CREATOR_LOG" 2>/dev/null | tail -30 >&2
|
||||
log " --- joiner A kick-watch ---"
|
||||
grep -nE 'subws2|pull config|kick-detect|kicked from|shutting down|chatUserLeave|you_kicked|server kicked' "$_log_a" 2>/dev/null | tail -20 >&2
|
||||
grep -nE 'subws2|pull config|kick-detect|kicked from|shutting down|chatUserLeave|you_kicked|server kicked|close 4004|reconnect attempt|before reconnect|TUNNEL CONNECTED' "$_log_a" 2>/dev/null | tail -30 >&2
|
||||
}
|
||||
|
||||
start_joiner() {
|
||||
|
||||
@@ -268,20 +268,8 @@ func (s *MediaSession) maybeStartDCTunnel() {
|
||||
}
|
||||
|
||||
func (s *MediaSession) configPingPong(tun tunnel.DataTunnel, trackCount int) {
|
||||
tun.SendData(tunnel.EncodeVP8Config(s.p.FPS, s.p.Batch, trackCount))
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-s.configAcked:
|
||||
return
|
||||
case <-s.stopCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
s.p.LogFn("[bx] resending vp8 config no ack yet")
|
||||
tun.SendData(tunnel.EncodeVP8Config(s.p.FPS, s.p.Batch, trackCount))
|
||||
}
|
||||
}
|
||||
tunnel.SendVP8ConfigUntilAcked(s.configAcked, nil, s.stopCh, tun,
|
||||
s.p.FPS, s.p.Batch, trackCount, s.p.LogFn, "[bx]")
|
||||
}
|
||||
|
||||
func (s *MediaSession) fireOnConnected(tun tunnel.DataTunnel) {
|
||||
|
||||
@@ -56,3 +56,38 @@ func ExtractICEHost(iceURL string) string {
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
func ResolveICEHosts(urls []string, resolveFn func(host string) (string, error), logFn func(string, ...any), logPrefix string) []string {
|
||||
out := make([]string, len(urls))
|
||||
copy(out, urls)
|
||||
if resolveFn == nil {
|
||||
return out
|
||||
}
|
||||
resolved := make(map[string]string)
|
||||
for i, iceURL := range out {
|
||||
fixed := FixICEURL(iceURL)
|
||||
host := ExtractICEHost(fixed)
|
||||
if host == "" || net.ParseIP(host) != nil {
|
||||
out[i] = fixed
|
||||
continue
|
||||
}
|
||||
ip, ok := resolved[host]
|
||||
if !ok {
|
||||
resolvedIP, err := resolveFn(host)
|
||||
if err != nil {
|
||||
if logFn != nil {
|
||||
logFn("%s: resolve ICE host %s failed: %s", logPrefix, MaskAddr(host), MaskError(err))
|
||||
}
|
||||
out[i] = fixed
|
||||
continue
|
||||
}
|
||||
ip = resolvedIP
|
||||
resolved[host] = ip
|
||||
if logFn != nil {
|
||||
logFn("%s: resolved ICE host %s -> %s", logPrefix, host, ip)
|
||||
}
|
||||
}
|
||||
out[i] = strings.Replace(fixed, host, ip, 1)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package dion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/kulikov0/headless-client/webrtc"
|
||||
|
||||
"whitelist-bypass/relay/common"
|
||||
)
|
||||
|
||||
type TransceiverPlan struct {
|
||||
@@ -60,63 +60,17 @@ type PionPeer struct {
|
||||
}
|
||||
|
||||
func ResolveICEServerHosts(entries []ICEServerEntry, resolveFn func(host string) (string, error), logFn func(string, ...any)) []ICEServerEntry {
|
||||
if resolveFn == nil {
|
||||
return entries
|
||||
}
|
||||
resolved := make(map[string]string)
|
||||
out := make([]ICEServerEntry, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
urls := make([]string, len(entry.URLs))
|
||||
copy(urls, entry.URLs)
|
||||
for k, raw := range urls {
|
||||
host := extractICEHost(raw)
|
||||
if host == "" {
|
||||
continue
|
||||
}
|
||||
ip, ok := resolved[host]
|
||||
if !ok {
|
||||
resolvedIP, err := resolveFn(host)
|
||||
if err != nil {
|
||||
if logFn != nil {
|
||||
logFn("[dion] resolve ICE host %s failed: %v", host, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
ip = resolvedIP
|
||||
resolved[host] = ip
|
||||
if logFn != nil {
|
||||
logFn("[dion] resolved ICE host %s -> %s", host, ip)
|
||||
}
|
||||
}
|
||||
urls[k] = strings.Replace(raw, host, ip, 1)
|
||||
}
|
||||
out = append(out, ICEServerEntry{URLs: urls, Username: entry.Username, Credential: entry.Credential})
|
||||
out = append(out, ICEServerEntry{
|
||||
URLs: common.ResolveICEHosts(entry.URLs, resolveFn, logFn, "[dion]"),
|
||||
Username: entry.Username,
|
||||
Credential: entry.Credential,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// extractICEHost pulls the hostname out of a stun:/turn:/turns: URL. Returns
|
||||
// "" if the URL has no host or the host is already an IP literal.
|
||||
func extractICEHost(raw string) string {
|
||||
value := raw
|
||||
for _, prefix := range []string{"stun:", "turn:", "turns:"} {
|
||||
value = strings.TrimPrefix(value, prefix)
|
||||
}
|
||||
if idx := strings.Index(value, "?"); idx >= 0 {
|
||||
value = value[:idx]
|
||||
}
|
||||
if idx := strings.LastIndex(value, ":"); idx >= 0 {
|
||||
value = value[:idx]
|
||||
}
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
if net.ParseIP(value) != nil {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func IceServerEntriesToWebRTC(entries []ICEServerEntry) []webrtc.ICEServer {
|
||||
out := make([]webrtc.ICEServer, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
|
||||
+1
-24
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -220,30 +219,8 @@ func (c *Client) Close() {
|
||||
|
||||
func (c *Client) iceServersAsWebRTC() []webrtc.ICEServer {
|
||||
out := make([]webrtc.ICEServer, 0, len(c.join.ICEServers))
|
||||
resolved := make(map[string]string)
|
||||
for _, s := range c.join.ICEServers {
|
||||
urls := make([]string, len(s.URLs))
|
||||
copy(urls, s.URLs)
|
||||
if c.resolveICEHost != nil {
|
||||
for k, u := range urls {
|
||||
host := common.ExtractICEHost(u)
|
||||
if host == "" || net.ParseIP(host) != nil {
|
||||
continue
|
||||
}
|
||||
ip, ok := resolved[host]
|
||||
if !ok {
|
||||
var err error
|
||||
ip, err = c.resolveICEHost(host)
|
||||
if err != nil {
|
||||
c.logFn("[lk] resolve ICE host %s failed: %v", host, err)
|
||||
continue
|
||||
}
|
||||
resolved[host] = ip
|
||||
c.logFn("[lk] resolved ICE host %s -> %s", host, ip)
|
||||
}
|
||||
urls[k] = strings.Replace(u, host, ip, 1)
|
||||
}
|
||||
}
|
||||
urls := common.ResolveICEHosts(s.URLs, c.resolveICEHost, c.logFn, "[lk]")
|
||||
ice := webrtc.ICEServer{URLs: urls}
|
||||
if s.Username != "" {
|
||||
ice.Username = s.Username
|
||||
|
||||
@@ -2,13 +2,8 @@ package joiner
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"whitelist-bypass/relay/tunnel"
|
||||
)
|
||||
|
||||
const configResendPeriod = 3 * time.Second
|
||||
|
||||
type configAckTracker struct {
|
||||
mu sync.Mutex
|
||||
acked chan struct{}
|
||||
@@ -46,23 +41,3 @@ func (t *configAckTracker) mark() {
|
||||
close(t.acked)
|
||||
}
|
||||
}
|
||||
|
||||
func sendVP8ConfigUntilAcked(acked, cancel <-chan struct{}, stopCh <-chan struct{}, tun tunnel.DataTunnel, fps, batch, trackCount int, logFn func(string, ...any), logPrefix string) {
|
||||
tun.SendData(tunnel.EncodeVP8Config(fps, batch, trackCount))
|
||||
ticker := time.NewTicker(configResendPeriod)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-acked:
|
||||
return
|
||||
case <-cancel:
|
||||
return
|
||||
case <-stopCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
logFn("%s: resending vp8 config fps=%d batch=%d trackCount=%d, no ack yet",
|
||||
logPrefix, fps, batch, trackCount)
|
||||
tun.SendData(tunnel.EncodeVP8Config(fps, batch, trackCount))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -517,7 +516,7 @@ func (j *TelemostHeadlessJoiner) initPC() {
|
||||
trackCount = 2
|
||||
}
|
||||
acked, cancel := j.configAck.arm()
|
||||
go sendVP8ConfigUntilAcked(acked, cancel, j.stopCh, active,
|
||||
go tunnel.SendVP8ConfigUntilAcked(acked, cancel, j.stopCh, active,
|
||||
vp8tun.FPS(), vp8tun.Batch(), trackCount, j.logFn, "telemost-joiner")
|
||||
j.logFn("telemost-joiner: pushed vp8 config to creator fps=%d batch=%d", vp8tun.FPS(), vp8tun.Batch())
|
||||
}
|
||||
@@ -920,38 +919,17 @@ func (j *TelemostHeadlessJoiner) parseICEServersFromHello(sh map[string]interfac
|
||||
if u, ok := sm["urls"].([]interface{}); ok {
|
||||
for _, v := range u {
|
||||
if vs, ok := v.(string); ok {
|
||||
urls = append(urls, common.FixICEURL(vs))
|
||||
urls = append(urls, vs)
|
||||
}
|
||||
}
|
||||
}
|
||||
ice := webrtc.ICEServer{URLs: urls}
|
||||
ice := webrtc.ICEServer{URLs: common.ResolveICEHosts(urls, j.ResolveFn, j.logFn, "telemost-joiner")}
|
||||
if u, ok := sm["username"].(string); ok && u != "" {
|
||||
ice.Username = u
|
||||
ice.Credential, _ = sm["credential"].(string)
|
||||
}
|
||||
iceServers = append(iceServers, ice)
|
||||
}
|
||||
resolved := make(map[string]string)
|
||||
for i, s := range iceServers {
|
||||
for k, u := range s.URLs {
|
||||
host := common.ExtractICEHost(u)
|
||||
if host == "" || net.ParseIP(host) != nil {
|
||||
continue
|
||||
}
|
||||
ip, ok := resolved[host]
|
||||
if !ok {
|
||||
var err error
|
||||
ip, err = j.ResolveFn(host)
|
||||
if err != nil {
|
||||
j.logFn("telemost-joiner: resolve ICE host %s failed: %s", common.MaskAddr(host), common.MaskError(err))
|
||||
continue
|
||||
}
|
||||
resolved[host] = ip
|
||||
j.logFn("telemost-joiner: resolved ICE host %s -> %s", host, ip)
|
||||
}
|
||||
iceServers[i].URLs[k] = strings.Replace(u, host, ip, 1)
|
||||
}
|
||||
}
|
||||
j.iceServers = iceServers
|
||||
for i, s := range iceServers {
|
||||
j.logFn("telemost-joiner: ICE server %d: urls=%v", i, s.URLs)
|
||||
|
||||
@@ -557,11 +557,13 @@ func (h *VKHeadlessJoiner) handleConnection(msg map[string]interface{}) {
|
||||
func (h *VKHeadlessJoiner) initPC() {
|
||||
var iceServers []webrtc.ICEServer
|
||||
if len(h.joinResp.StunServer.URLs) > 0 {
|
||||
iceServers = append(iceServers, webrtc.ICEServer{URLs: h.joinResp.StunServer.URLs})
|
||||
iceServers = append(iceServers, webrtc.ICEServer{
|
||||
URLs: common.ResolveICEHosts(h.joinResp.StunServer.URLs, h.ResolveFn, h.logFn, "vk-joiner"),
|
||||
})
|
||||
}
|
||||
if len(h.joinResp.TurnServer.URLs) > 0 {
|
||||
iceServers = append(iceServers, webrtc.ICEServer{
|
||||
URLs: h.joinResp.TurnServer.URLs,
|
||||
URLs: common.ResolveICEHosts(h.joinResp.TurnServer.URLs, h.ResolveFn, h.logFn, "vk-joiner"),
|
||||
Username: h.joinResp.TurnServer.Username,
|
||||
Credential: h.joinResp.TurnServer.Credential,
|
||||
})
|
||||
@@ -658,7 +660,7 @@ func (h *VKHeadlessJoiner) initPC() {
|
||||
vp8tun := h.vp8tunnel
|
||||
if !h.configAck.acknowledged() {
|
||||
acked, cancel := h.configAck.arm()
|
||||
go sendVP8ConfigUntilAcked(acked, cancel, h.stopCh, vp8tun,
|
||||
go tunnel.SendVP8ConfigUntilAcked(acked, cancel, h.stopCh, vp8tun,
|
||||
vp8tun.FPS(), vp8tun.Batch(), trackCount, h.logFn, "vk-joiner")
|
||||
h.logFn("vk-joiner: pushed vp8 config to creator fps=%d batch=%d trackCount=%d", vp8tun.FPS(), vp8tun.Batch(), trackCount)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package tunnel
|
||||
|
||||
import "encoding/binary"
|
||||
import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
MsgConnect byte = 0x01
|
||||
@@ -14,6 +17,8 @@ const (
|
||||
MsgConfigAck byte = 0x09
|
||||
|
||||
WireHeaderLen = 4 + 1
|
||||
|
||||
configResendPeriod = 3 * time.Second
|
||||
)
|
||||
|
||||
const ControlConnID uint32 = 0
|
||||
@@ -64,6 +69,26 @@ func DecodeVP8Config(payload []byte) (fps, batch, trackCount int, ok bool) {
|
||||
return fps, batch, trackCount, true
|
||||
}
|
||||
|
||||
func SendVP8ConfigUntilAcked(acked, cancel, stopCh <-chan struct{}, tun DataTunnel, fps, batch, trackCount int, logFn func(string, ...any), logPrefix string) {
|
||||
tun.SendData(EncodeVP8Config(fps, batch, trackCount))
|
||||
ticker := time.NewTicker(configResendPeriod)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-acked:
|
||||
return
|
||||
case <-cancel:
|
||||
return
|
||||
case <-stopCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
logFn("%s: resending vp8 config fps=%d batch=%d trackCount=%d, no ack yet",
|
||||
logPrefix, fps, batch, trackCount)
|
||||
tun.SendData(EncodeVP8Config(fps, batch, trackCount))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func EncodeFrame(connID uint32, msgType byte, payload []byte) []byte {
|
||||
buf := make([]byte, 4+5+len(payload))
|
||||
binary.BigEndian.PutUint32(buf[0:4], uint32(5+len(payload)))
|
||||
|
||||
@@ -296,21 +296,8 @@ func (s *Session) startTunnel() {
|
||||
}
|
||||
|
||||
func (s *Session) configPingPong(tun tunnel.DataTunnel, trackCount int) {
|
||||
frame := tunnel.EncodeVP8Config(s.cfg.VP8FPS, s.cfg.VP8Batch, trackCount)
|
||||
tun.SendData(frame)
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-s.configAcked:
|
||||
return
|
||||
case <-s.done:
|
||||
return
|
||||
case <-ticker.C:
|
||||
s.cfg.LogFn("[lk] resending vp8 config (no ack yet)")
|
||||
tun.SendData(tunnel.EncodeVP8Config(s.cfg.VP8FPS, s.cfg.VP8Batch, trackCount))
|
||||
}
|
||||
}
|
||||
tunnel.SendVP8ConfigUntilAcked(s.configAcked, nil, s.done, tun,
|
||||
s.cfg.VP8FPS, s.cfg.VP8Batch, trackCount, s.cfg.LogFn, "[lk]")
|
||||
}
|
||||
|
||||
func (s *Session) maybeStartDCTunnel() {
|
||||
|
||||
Reference in new issue
Block a user