From 2dbc6ea1eb9905958beb9ee565b747b23312f969 Mon Sep 17 00:00:00 2001
From: kulikov0 <19497634+kulikov0@users.noreply.github.com>
Date: Sat, 25 Jul 2026 12:23:41 +0200
Subject: [PATCH] fix vpn notification, add more logs under debug flag
---
android-app/app/src/main/AndroidManifest.xml | 1 +
.../java/bypass/whitelist/MainActivity.kt | 22 +++++++++++++++++++
headless/telemost/main.go | 8 +++++--
headless/telemost/tunnel_relay.go | 2 +-
headless/vk/tunnel_relay.go | 10 ++++++---
relay/dion/call.go | 5 ++++-
relay/dion/signaling.go | 10 +++++++--
relay/livekit/client.go | 6 +++--
.../headless-joiner-common/telemost_joiner.go | 12 +++++++---
relay/pion/signaling.go | 2 +-
relay/pion/video_vk.go | 16 ++++++++++----
relay/tunnel/multi_track_kcp_tunnel.go | 4 +++-
relay/tunnel/relay_bridge.go | 3 +++
relay/tunnel/vk_screen_tunnel.go | 6 +++--
relay/tunnel/vp8tunnel.go | 4 ++--
relay/tunnel/vp8tunnel_legacy.go | 4 ++--
relay/wbstream/session.go | 2 +-
17 files changed, 90 insertions(+), 27 deletions(-)
diff --git a/android-app/app/src/main/AndroidManifest.xml b/android-app/app/src/main/AndroidManifest.xml
index 6d1ec6e..f81e8d8 100644
--- a/android-app/app/src/main/AndroidManifest.xml
+++ b/android-app/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
+
diff --git a/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt b/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt
index 6a53e54..76f0ad4 100644
--- a/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt
+++ b/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt
@@ -1,10 +1,13 @@
package bypass.whitelist
+import android.Manifest
import android.animation.ArgbEvaluator
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
+import android.content.pm.PackageManager
import android.net.VpnService
+import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
@@ -16,6 +19,7 @@ import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
@@ -101,11 +105,19 @@ class MainActivity :
else appendLog("VPN permission denied")
}
+ private val notificationPermissionLauncher = registerForActivityResult(
+ ActivityResultContracts.RequestPermission()
+ ) { granted ->
+ if (!granted) appendLog("Notification permission denied")
+ }
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
+ requestNotificationPermissionIfNeeded()
+
bottomNav = findViewById(R.id.bottomNav)
navMain = findViewById(R.id.navMain)
navSettings = findViewById(R.id.navSettings)
@@ -473,6 +485,16 @@ class MainActivity :
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
}
+ private fun requestNotificationPermissionIfNeeded() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
+ val granted = ContextCompat.checkSelfPermission(
+ this,
+ Manifest.permission.POST_NOTIFICATIONS
+ ) == PackageManager.PERMISSION_GRANTED
+ if (granted) return
+ notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
+ }
+
private fun handleIntent(intent: Intent?) {
if (intent?.action != ACTION_AUTO_START) return
intent.action = null
diff --git a/headless/telemost/main.go b/headless/telemost/main.go
index 2aab86e..0a0296c 100644
--- a/headless/telemost/main.go
+++ b/headless/telemost/main.go
@@ -379,7 +379,9 @@ func (b *Bridge) handleMessage(raw []byte) {
}
if ud, ok := msg["updateDescription"]; ok {
- log.Printf("[tm-ws] <- updateDescription %s", tmapi.BriefJSON(ud))
+ if common.Debug {
+ log.Printf("[tm-ws] <- updateDescription %s", tmapi.BriefJSON(ud))
+ }
udMap, _ := ud.(map[string]interface{})
descs, _ := udMap["description"].([]interface{})
b.applyDescriptionSnapshot(descs)
@@ -440,7 +442,9 @@ func (b *Bridge) handleMessage(raw []byte) {
}
if sc, ok := msg["slotsConfig"]; ok {
- log.Printf("[tm-ws] <- slotsConfig %s", tmapi.BriefJSON(sc))
+ if common.Debug {
+ log.Printf("[tm-ws] <- slotsConfig %s", tmapi.BriefJSON(sc))
+ }
needRebind := false
presentPids := make(map[string]bool)
for _, ev := range tmapi.SlotsConfigBindings(sc) {
diff --git a/headless/telemost/tunnel_relay.go b/headless/telemost/tunnel_relay.go
index e5290b2..43a371b 100644
--- a/headless/telemost/tunnel_relay.go
+++ b/headless/telemost/tunnel_relay.go
@@ -271,7 +271,7 @@ func (r *SFURelay) readTrack(track *webrtc.TrackRemote) {
continue
}
recvCount++
- if recvCount <= 3 || recvCount%200 == 0 {
+ if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
log.Printf("[video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}
diff --git a/headless/vk/tunnel_relay.go b/headless/vk/tunnel_relay.go
index f9bd39b..911afab 100644
--- a/headless/vk/tunnel_relay.go
+++ b/headless/vk/tunnel_relay.go
@@ -106,14 +106,18 @@ func (u *TunnelRelay) Init(iceServers []webrtc.ICEServer) error {
if err == nil {
dcNotif.OnOpen(func() { log.Println("[relay] producerNotification DC opened") })
dcNotif.OnMessage(func(msg webrtc.DataChannelMessage) {
- log.Printf("[relay] producerNotification msg len=%d", len(msg.Data))
+ if common.Debug {
+ log.Printf("[relay] producerNotification msg len=%d", len(msg.Data))
+ }
})
}
dcCmd, err := pc.CreateDataChannel("producerCommand", &webrtc.DataChannelInit{Ordered: &ordered})
if err == nil {
dcCmd.OnOpen(func() { log.Println("[relay] producerCommand DC opened") })
dcCmd.OnMessage(func(msg webrtc.DataChannelMessage) {
- log.Printf("[relay] producerCommand msg len=%d", len(msg.Data))
+ if common.Debug {
+ log.Printf("[relay] producerCommand msg len=%d", len(msg.Data))
+ }
})
}
producerScreen, psErr := pc.CreateDataChannel("producerScreenShare", &webrtc.DataChannelInit{Ordered: &ordered})
@@ -459,7 +463,7 @@ func (u *TunnelRelay) readTrack(track *webrtc.TrackRemote) {
continue
}
recvCount++
- if recvCount <= 3 || recvCount%200 == 0 {
+ if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
log.Printf("[video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}
diff --git a/relay/dion/call.go b/relay/dion/call.go
index 1aaef8e..f71238d 100644
--- a/relay/dion/call.go
+++ b/relay/dion/call.go
@@ -13,6 +13,7 @@ import (
"github.com/pion/rtp/codecs"
"github.com/pion/webrtc/v4"
+ "whitelist-bypass/relay/common"
"whitelist-bypass/relay/tunnel"
)
@@ -500,7 +501,9 @@ func (c *Call) handleSpeakerCamStateChanged(params SpeakerCamStateChangedParams)
c.peersByID[params.SessionID] = &PeerEntry{SessionID: params.SessionID, CamState: params.CamState, JoinedAt: time.Now()}
}
c.peersMu.Unlock()
- c.cfg.LogFn("[call] speaker_cam_state_changed session_id=%s cam=%v", params.SessionID, params.CamState)
+ if common.Debug {
+ c.cfg.LogFn("[call] speaker_cam_state_changed session_id=%s cam=%v", params.SessionID, params.CamState)
+ }
if params.CamState {
c.subscribeIfNeeded(params.SessionID)
}
diff --git a/relay/dion/signaling.go b/relay/dion/signaling.go
index c29325b..acfa42b 100644
--- a/relay/dion/signaling.go
+++ b/relay/dion/signaling.go
@@ -13,6 +13,8 @@ import (
"time"
"github.com/gorilla/websocket"
+
+ "whitelist-bypass/relay/common"
)
const (
@@ -549,11 +551,15 @@ func (c *SignalingClient) ReadLoop() error {
}
var frame Frame
if err := json.Unmarshal(raw, &frame); err != nil {
- c.logFn("dion: drop non-json frame: %v", err)
+ if common.Debug {
+ c.logFn("dion: drop non-json frame: %v", err)
+ }
continue
}
if frame.Error != nil {
- c.logFn("dion: <- %s ERROR code=%d message=%q", frame.Method, frame.Error.Code, frame.Error.Message)
+ if common.Debug {
+ c.logFn("dion: <- %s ERROR code=%d message=%q", frame.Method, frame.Error.Code, frame.Error.Message)
+ }
}
c.dispatch(frame)
}
diff --git a/relay/livekit/client.go b/relay/livekit/client.go
index 72ee5fc..7f22cde 100644
--- a/relay/livekit/client.go
+++ b/relay/livekit/client.go
@@ -367,7 +367,9 @@ func (c *Client) handleSignal(data []byte) {
c.OnParticipantUpdate(sr.Participants)
}
default:
- c.logFn("[lk] <- signal kind=%d (%d bytes)", sr.Kind, len(data))
+ if common.Debug {
+ c.logFn("[lk] <- signal kind=%d (%d bytes)", sr.Kind, len(data))
+ }
}
}
@@ -476,7 +478,7 @@ func (c *Client) PingLoop() {
return
}
sentN++
- if sentN <= 3 || sentN%12 == 0 {
+ if common.Debug && (sentN <= 3 || sentN%12 == 0) {
c.logFn("[lk] ping #%d sent", sentN)
}
}
diff --git a/relay/pion/headless-joiner-common/telemost_joiner.go b/relay/pion/headless-joiner-common/telemost_joiner.go
index 7f763fb..cac79ba 100644
--- a/relay/pion/headless-joiner-common/telemost_joiner.go
+++ b/relay/pion/headless-joiner-common/telemost_joiner.go
@@ -741,7 +741,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
}
if ud, ok := msg["updateDescription"]; ok {
- j.logFn("telemost-joiner: <- updateDescription %s", tmapi.BriefJSON(ud))
+ if common.Debug {
+ j.logFn("telemost-joiner: <- updateDescription %s", tmapi.BriefJSON(ud))
+ }
j.ack(uid)
return
}
@@ -753,7 +755,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
}
if sc, ok := msg["slotsConfig"]; ok {
- j.logFn("telemost-joiner: <- slotsConfig %s", tmapi.BriefJSON(sc))
+ if common.Debug {
+ j.logFn("telemost-joiner: <- slotsConfig %s", tmapi.BriefJSON(sc))
+ }
needRebind := false
presentPids := make(map[string]bool)
for _, ev := range tmapi.SlotsConfigBindings(sc) {
@@ -817,7 +821,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
if k == "uid" || k == "ack" {
continue
}
- j.logFn("telemost-joiner: <- %s (unhandled) %s", k, tmapi.BriefJSON(v))
+ if common.Debug {
+ j.logFn("telemost-joiner: <- %s (unhandled) %s", k, tmapi.BriefJSON(v))
+ }
break
}
diff --git a/relay/pion/signaling.go b/relay/pion/signaling.go
index 6a805e1..638253f 100644
--- a/relay/pion/signaling.go
+++ b/relay/pion/signaling.go
@@ -217,7 +217,7 @@ func ReadTrack(track *webrtc.TrackRemote, handler func([]byte), logFn func(strin
continue
}
recvCount++
- if recvCount <= 3 || recvCount%200 == 0 {
+ if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
logFn("%s: recv vp8 frame #%d %d bytes", prefix, recvCount, len(frameBuf))
}
if handler != nil {
diff --git a/relay/pion/video_vk.go b/relay/pion/video_vk.go
index 7280b99..f6c009f 100644
--- a/relay/pion/video_vk.go
+++ b/relay/pion/video_vk.go
@@ -46,7 +46,9 @@ func (c *VKClient) handleMessage(raw []byte) {
if err := json.Unmarshal(raw, &msg); err != nil {
return
}
- c.logFn("vk: >> msg type=%s id=%d", msg.Type, msg.ID)
+ if common.Debug {
+ c.logFn("vk: >> msg type=%s id=%d", msg.Type, msg.ID)
+ }
switch msg.Type {
case "ice-servers":
@@ -66,7 +68,9 @@ func (c *VKClient) handleMessage(raw []byte) {
case "close":
c.cleanup()
}
- c.logFn("vk: << msg type=%s id=%d done", msg.Type, msg.ID)
+ if common.Debug {
+ c.logFn("vk: << msg type=%s id=%d done", msg.Type, msg.ID)
+ }
}
func (c *VKClient) createPC(config webrtc.Configuration) error {
@@ -96,7 +100,9 @@ func (c *VKClient) createPC(config webrtc.Configuration) error {
c.logFn("vk: producerNotification DC opened")
})
dcNotif.OnMessage(func(msg webrtc.DataChannelMessage) {
- c.logFn("vk: producerNotification msg len=%d isString=%v", len(msg.Data), msg.IsString)
+ if common.Debug {
+ c.logFn("vk: producerNotification msg len=%d isString=%v", len(msg.Data), msg.IsString)
+ }
// Forward to Node bridge as sfu-dc-message
c.SendToHook("sfu-dc-message", map[string]interface{}{
"channel": "producerNotification",
@@ -113,7 +119,9 @@ func (c *VKClient) createPC(config webrtc.Configuration) error {
c.logFn("vk: producerCommand DC opened")
})
dcCmd.OnMessage(func(msg webrtc.DataChannelMessage) {
- c.logFn("vk: producerCommand msg len=%d", len(msg.Data))
+ if common.Debug {
+ c.logFn("vk: producerCommand msg len=%d", len(msg.Data))
+ }
c.SendToHook("sfu-dc-message", map[string]interface{}{
"channel": "producerCommand",
"data": string(msg.Data),
diff --git a/relay/tunnel/multi_track_kcp_tunnel.go b/relay/tunnel/multi_track_kcp_tunnel.go
index 067a209..49350db 100644
--- a/relay/tunnel/multi_track_kcp_tunnel.go
+++ b/relay/tunnel/multi_track_kcp_tunnel.go
@@ -7,6 +7,8 @@ import (
"time"
kcp "github.com/xtaci/kcp-go/v5"
+
+ "whitelist-bypass/relay/common"
)
const (
@@ -383,7 +385,7 @@ func (t *MultiTrackKCPTunnel) updateLoop() {
session.update()
}
ticks++
- if ticks%kcpStatsEvery == 0 && t.logFn != nil {
+ if common.Debug && ticks%kcpStatsEvery == 0 && t.logFn != nil {
t.logFn("kcptunnel: sessions=%d window=%d sent=%d delivered=%d out_segs=%d in_segs=%d raw_out=%d raw_in=%d dropped=%d",
len(sessions), t.currentWindow.Load(), t.sentMessages.Load(), t.deliveredMessages.Load(),
t.outputSegments.Load(), t.inputSegments.Load(),
diff --git a/relay/tunnel/relay_bridge.go b/relay/tunnel/relay_bridge.go
index 2fbcd84..3f8751f 100644
--- a/relay/tunnel/relay_bridge.go
+++ b/relay/tunnel/relay_bridge.go
@@ -15,6 +15,8 @@ import (
"whitelist-bypass/relay/common"
)
+const acceptErrorRetryDelay = 100 * time.Millisecond
+
type creatorUDP struct {
direct *net.UDPConn
socks *common.Socks5UDPSession
@@ -549,6 +551,7 @@ func (rb *RelayBridge) ListenSOCKS(addr string) error {
return nil
}
rb.logFn("relay: accept error: %v", err)
+ time.Sleep(acceptErrorRetryDelay)
continue
}
go rb.handleSOCKS(conn)
diff --git a/relay/tunnel/vk_screen_tunnel.go b/relay/tunnel/vk_screen_tunnel.go
index 4ed20e5..9e90dd3 100644
--- a/relay/tunnel/vk_screen_tunnel.go
+++ b/relay/tunnel/vk_screen_tunnel.go
@@ -5,6 +5,8 @@ import (
"sync"
"sync/atomic"
"time"
+
+ "whitelist-bypass/relay/common"
)
const (
@@ -134,7 +136,7 @@ func (w *ScreenWriter) emit(msg []byte) {
return
}
n := w.sent.Add(1)
- if n <= 5 || n%500 == 0 {
+ if common.Debug && (n <= 5 || n%500 == 0) {
w.logFn("[%s] sent frame #%d size=%d", w.label, n, len(msg))
}
}
@@ -252,7 +254,7 @@ func (s *SymmetricScreenTunnel) Stop() {
func (s *SymmetricScreenTunnel) HandleScreenFrame(frame []byte) {
res := s.obf.Decode(frame)
n := s.recv.Add(1)
- if n <= 10 || n%500 == 0 {
+ if common.Debug && (n <= 10 || n%500 == 0) {
s.logFn("screen recv frame #%d in=%d hasFrame=%v keepalive=%v payload=%d", n, len(frame), res.HasFrame, res.Keepalive, len(res.Payload))
}
if !res.HasFrame || res.SelfEcho || res.Keepalive || len(res.Payload) == 0 {
diff --git a/relay/tunnel/vp8tunnel.go b/relay/tunnel/vp8tunnel.go
index 7f1227d..8fa9a49 100644
--- a/relay/tunnel/vp8tunnel.go
+++ b/relay/tunnel/vp8tunnel.go
@@ -221,7 +221,7 @@ func (t *VP8DataTunnel) writerLoop() {
if isKeepalive {
t.keepaliveFrames.Add(1)
}
- if n <= 5 || n%500 == 0 {
+ if common.Debug && (n <= 5 || n%500 == 0) {
keepalives := t.keepaliveFrames.Load()
t.logFn("vp8tunnel: sent frame #%d size=%d data=%d keepalive=%d", n, len(sample), n-keepalives, keepalives)
}
@@ -249,7 +249,7 @@ func (t *VP8DataTunnel) HandleFrame(frame []byte) {
return
}
n := t.recvFrames.Add(1)
- if n <= 5 || n%500 == 0 {
+ if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel: recv frame #%d size=%d", n, len(res.Payload))
}
if t.OnData != nil {
diff --git a/relay/tunnel/vp8tunnel_legacy.go b/relay/tunnel/vp8tunnel_legacy.go
index 9bbb763..0842242 100644
--- a/relay/tunnel/vp8tunnel_legacy.go
+++ b/relay/tunnel/vp8tunnel_legacy.go
@@ -198,7 +198,7 @@ func (t *VP8LegacyTunnel) writerLoop() {
continue
}
n := t.sentFrames.Add(1)
- if n <= 5 || n%500 == 0 {
+ if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel-legacy: sent frame #%d size=%d", n, len(sample))
}
}
@@ -232,7 +232,7 @@ func (t *VP8LegacyTunnel) HandleFrame(frame []byte) {
return
}
n := t.recvFrames.Add(1)
- if n <= 5 || n%500 == 0 {
+ if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel-legacy: recv frame #%d size=%d", n, len(payload))
}
if t.OnData != nil {
diff --git a/relay/wbstream/session.go b/relay/wbstream/session.go
index dd4f293..3d333f4 100644
--- a/relay/wbstream/session.go
+++ b/relay/wbstream/session.go
@@ -628,7 +628,7 @@ func (s *Session) readVP8Track(track *webrtc.TrackRemote) {
continue
}
recvCount++
- if recvCount <= 3 || recvCount%200 == 0 {
+ if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
s.cfg.LogFn("[lk-video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}