Skip to content

feat: enhance WebSocket connection handling and improve MTProto trans…#233

Closed
DanielLavrushin wants to merge 1 commit into
mainfrom
ws-bridge-issues
Closed

feat: enhance WebSocket connection handling and improve MTProto trans…#233
DanielLavrushin wants to merge 1 commit into
mainfrom
ws-bridge-issues

Conversation

@DanielLavrushin

Copy link
Copy Markdown
Owner

…port logic

Copilot AI review requested due to automatic review settings May 31, 2026 22:23
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves MTProto upstream connection reliability (especially WebSocket routing) by rotating across multiple known-good Telegram WS edge IPs and by refactoring/removing the WS connection pool. It also updates the Web UI “Connections” page to base filtering/timestamps on the connection data’s timestamps (to avoid issues when the viewer device clock is skewed).

Changes:

  • MTProto: rotate WS-edge dial targets across a default IP set and refactor WS/TCP cooldown + logging state into a dedicated module; remove the WS prewarm pool and simplify dialing call sites.
  • Tests: update transport-planning tests to account for multiple WS plans per SNI (per-IP fan-out).
  • Web UI: adjust connections aggregation and “now” handling to rely on data timestamps; minor Discovery UI layout/formatting updates; document the Connections-page clock-skew fix in the changelog.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/mtproto/wsstate.go New shared WS/TCP cooldown/blacklist + dial-error throttling state moved out of the removed pool.
src/mtproto/wspool.go Removes WS pool implementation (prewarmed connections).
src/mtproto/transparent.go Removes pool lifecycle and switches transparent bridge dialing to DialObfuscatedDC.
src/mtproto/server.go Removes server-held WS pool and switches dialing to DialObfuscatedDC.
src/mtproto/plantransports_test.go Updates tests for WS plan fan-out across multiple edge IPs and validates anti-funneling behavior.
src/mtproto/obfuscated2.go Adds WS edge IP rotation + fans out native-edge WS plans per IP; removes pooled dial path.
src/http/ui/src/workers/connections-aggregator.worker.ts Uses data timestamps as the “now” basis; tracks latestTs.
src/http/ui/src/components/discovery/Discovery.tsx UI formatting/conditional rendering adjustments for log panel and handlers.
src/http/ui/src/components/connections/views/AggregatedView.tsx Changes time-window cutoff and “now” derivation to use data timestamps (removes browser nowTick).
changelog.md Adds release note about fixing Connections page behavior when device clock is out of sync.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 53 to +54
const cleanTs = rawTs.replaceAll(" [INFO]", "").trim().split(".")[0];
const ts = Date.parse(cleanTs.replaceAll("/", "-")) || Date.now();
const ts = Date.parse(cleanTs.replaceAll("/", "-")) || latestTs;
Comment on lines 79 to +86
const state = useConnectionGroups(lines, deviceMap, paused);

useEffect(() => {
const id = globalThis.setInterval(() => setNowTick(Date.now()), 1000);
return () => globalThis.clearInterval(id);
}, []);
const now = useMemo(() => {
let latest = 0;
for (const g of state.groups) if (g.lastSeen > latest) latest = g.lastSeen;
for (const d of state.devices) if (d.lastSeen > latest) latest = d.lastSeen;
return latest;
}, [state.groups, state.devices]);
Comment on lines +268 to 272
hosts := wsEdgeDialHosts(cfg)
primarySNI := fmt.Sprintf("kws%d.web.telegram.org", absDC)
mediaSNI := fmt.Sprintf("kws%d-1.web.telegram.org", absDC)
sniOrder := []string{primarySNI, mediaSNI}
if dc < 0 {
Comment thread src/mtproto/wsstate.go
Comment on lines +122 to +131
func wsRecordFailure(dc int, allRedirect bool) {
k := wsKeyFromDC(dc)
wsStateMu.Lock()
defer wsStateMu.Unlock()
if allRedirect {
wsBlacklist[k] = true
log.Warnf("MTProto WS %s blacklisted (all redirects)", k)
}
wsCooldownTo[k] = time.Now().Add(wsDCFailCooldown)
}
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 31 complexity

Metric Results
Complexity 31

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@DanielLavrushin

Copy link
Copy Markdown
Owner Author

abandone this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants