mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6330] [MERGED] fix(amneziawg): H1-H4 generator + queue-depth throughput fixes #6220
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6220
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6330
Author: @kuzzrus
Created: 8/25/2026
Status: ✅ Merged
Merged: 9/3/2026
Merged by: @MHSanaei
Base:
main← Head:fix/awg-h-values-and-queue-depth📝 Commits (4)
6a8ca28fix(amneziawg): stop H1-H4 generator misclassifying transport packets6b73226fix(amneziawgnet): raise tunQueueDepth to absorb slow-start burstsba83255fix(amneziawg): trim comment blocks to the repo's 2-line cap2bd2ebfMerge remote-tracking branch 'origin/main' into pr/6330📊 Changes
6 files changed (+40 additions, -42 deletions)
View changed files
📝
docs/content/docs/en/config/amneziawg.mdx(+4 -4)📝
frontend/src/lib/xray/amneziawg-obfuscation.ts(+5 -9)📝
frontend/src/test/amneziawg-obfuscation.test.ts(+14 -2)📝
internal/amneziawg/params.go(+5 -11)📝
internal/amneziawg/params_test.go(+10 -15)📝
internal/amneziawgnet/netstack.go(+2 -1)📄 Description
Summary
Two independent fixes for AmneziaWG throughput, both found and live-tested while investigating #6303 ("AmneziaWG import speed is extremely poor").
1. H1-H4 generator: single value instead of a range
GenerateObfuscation31(and its frontend mirror,generateAwgObfuscation) picked a random range for each of H1-H4, with only a minimum width enforced (hMinWidth = 1000), no maximum. amneziawg-go's packet classifier (DeterminePacketTypeAndPadding) only ever compares a fixed-size ciphertext prefix against these bounds to decide "handshake vs. transport" — so a wider range buys zero DPI resistance (the range boundaries themselves are never observable on the wire, only whichever single value the classifier lets through matters). It does cost real throughput:randomTrailersis generatedtruehere, and with it on, amneziawg-go's handshake-size checks relax from==to>, so a wide H-range starts misclassifying a proportional fraction of ordinary transport packets as handshakes and silently dropping them. This was independently found and filed the same week as amnezia-vpn/amneziawg-go#183, with a synthetic-packet regression test proving the mechanism.Live-tested on two boxes, single-variable (only H1-H4 narrowed, nothing else changed): upload went from 2-3 Mbit/s to 200+ Mbit/s on one, and a flat ~20 Mbit/s to 120-156 Mbit/s on another.
A single value per H field is strictly safer than any range — the same reasoning @alekskomp's own native-Amnezia-Docker config in #6303 already uses (
H1=1, H2=2, H3=3, H4=4). This changes what the generator produces, not what's accepted: a manually-entered range still validates fine (ValidateObfuscation/validateUintRangeuntouched).Fixed in both places that generate these values, since they're independent implementations that could silently drift apart again:
internal/amneziawg/params.go(Go, server-side) andfrontend/src/lib/xray/amneziawg-obfuscation.ts(what the inbound form's "Regenerate" button calls).2.
tunQueueDepth: 1024 → 8192A separate contributor to the same "AmneziaWG slower than expected" symptom, specifically on the download side. 1024 was originally sized for a single-connection buffering problem (the gVisor-to-amneziawg-go TUN handoff channel — see the pre-existing comment above the constant). Watching
tcpip.Stack.Stats()live during a real many-connection download (20-28 concurrent TCP flows, e.g. a segmented speed test) showedSlowStartRetransmitsjump by ~770 in a single second the momentCurrentEstablishedcrossed ~20 — consistent with several connections' simultaneous slow-start growth briefly exceeding 1024 outstanding packets, with gVisor's channel endpoint (whosequeue.Writeis non-blocking and drops silently when full) treating the resulting drops as ordinary network loss.Context
Both root causes, with the live-test numbers, are written up in more detail in my comment on #6303.
One thing worth flagging for review:
GenerateObfuscation31always turnsRandomTrailerson for a freshly generated set (it's a normal toggle a user can flip off afterward, but "on" is what every new/regenerated inbound gets) — which is exactly the setting that makes the H1-H4 misclassification bug bite. This PR doesn't touch that default; a single H-value is safe regardless ofrandomTrailers, so the two are orthogonal. Flagging only so reviewers have the full picture — not proposing a change there.Test plan
go vet/go testoninternal/amneziawgandinternal/amneziawgnettsc --noEmit,oxlint,oxfmt --check,vitest runon the touched frontend files🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.