Skip to content

Fix noise after udphop - #7372

Open
FDeghy wants to merge 2 commits into
XTLS:mainfrom
FDeghy:codex/fix-noise-after-udphop
Open

FDeghy wants to merge 2 commits into
XTLS:mainfrom
FDeghy:codex/fix-noise-after-udphop

Conversation

@FDeghy

@FDeghy FDeghy commented Nov 10, 2026

Copy link
Copy Markdown

Fix noise emission when noise and udphop are used together.

Previously, noise state was keyed by the destination passed to WriteTo. udphop could replace that destination internally or switch the source socket without invalidating the noise state. Continuous outgoing traffic also refreshed the noise reset timeout, allowing repeated hops without another noise sequence.

Implementation

  • Add shared UDPPath state through the existing finalmask dialer, containing the actual destination, a generation counter, and a mutex.
  • Increment the generation after a successful hop changes the local endpoint, destination IP, or destination port.
  • Have the noise wrapper clear its cached reset state when it observes a new generation. The next write emits noise before its payload, then resumes the existing reset behavior.
  • Serialize the complete masked write against hopping, keeping all noise packets, configured delays, and the associated payload on the same socket and destination.

Generation tracking also handles returning to a previously used endpoint. Failed hops retain the active path and generation; attempts that leave the endpoints unchanged do not trigger additional noise.

Both configured noise items and Lua scripts use the existing emission code. Mask ordering, socket deadline propagation, receive handling, and connection cleanup remain unchanged. The existing connection stays in place, preserving Hysteria continuity. No configuration fields are added.

Regression coverage

  • Source-port-only, destination-port-only, destination-IP-only, and combined changes.
  • Continuous traffic, repeated writes on one path, and returning to a previous endpoint.
  • Unchanged endpoints and failed hops.
  • Concurrent hopping during delayed noise emission.
  • Configured items and Lua scripts, mask ordering, reset behavior, deadline propagation, and socket cleanup.

Verification

  • Focused noise/udphop tests and race detection passed.
  • Finalmask and Hysteria package checks passed in short mode.
  • GitHub’s formatting/protobuf check passed after applying the repository formatter.
  • The full package run timed out in the separate Sudoku end-to-end harness; that run did not complete.

@FDeghy FDeghy changed the title Codex/fix noise after udphop fix noise after udphop Nov 10, 2026
@FDeghy FDeghy changed the title fix noise after udphop Fix noise after udphop Nov 10, 2026
@RPRX
RPRX requested a review from LjhAUMEM November 11, 2026 08:31
@LjhAUMEM

Copy link
Copy Markdown
Contributor

这么多 First-time contributor 真的有点诡异了

你可以选择在你的自定义 fork 传自定义 dialer 给 udphop,更改 udphop 的代码是绝对的 shit 💩

@LjhAUMEM LjhAUMEM closed this Nov 12, 2026
@FDeghy

FDeghy commented Nov 12, 2026

Copy link
Copy Markdown
Author

It's really a bit strange to have so many first-time contributors.

You can choose to pass a custom dialer to UDPHop in your custom fork; modifying UDPHop's code is absolute shit 💩

The correct approach is to apply the noise to every new connection so that the new connection can send data just like the previous ones. A new connection can either be a genuinely new connection or one created as a result of udphop, which simply changes the previous connection's port or IP address.

@patterniha

patterniha commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

It's really a bit strange to have so many first-time contributors.

You can choose to pass a custom dialer to UDPHop in your custom fork; modifying UDPHop's code is absolute shit 💩

I know @FDeghy , and I know he's knowledgeable.

He's right. When the port changes, we have a new connection, and GFW inspects the initial packets of every new connection. If their pattern matches QUIC or WireGuard, it can identify them.

So we need to send noise with every new connection (although it is better to use salamander obfuscation instead).

Also, I really don't appreciate the way you're talking. Sending a poop emoji is insulting and disrespectful, and I honestly didn't expect that from you.

@patterniha patterniha reopened this Nov 12, 2026
@LjhAUMEM

Copy link
Copy Markdown
Contributor

不需要 quote,我不会删除我说过的话

我知道这个 pr 的意思,但不影响我评价这个方案吧

没事,可以 reopen,但以后 finalmask 相关我希望你都可以出现处理 @patterniha,我很乐意让权,先说好被入侵的部分我不会再碰

@RPRX

RPRX commented Nov 12, 2026

Copy link
Copy Markdown
Member

感觉应该只需要改 noise 的代码?

@LjhAUMEM

Copy link
Copy Markdown
Contributor

noise 这种纯客户端的怎么搞都行,我上面的评价也带了方案,但我最近完全不想看代码,能在这里把 finalmask 交出去也不错

@RPRX

RPRX commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

不太对,如果是改 noise 的代码的话,其它很多 UDP mask 都得改

我觉得该这么设计:如果 udphop 在先,对后面的 noise 等 mask 来说就是新的 UDP,reapply,如果 noise 在先就是现在这样

这样才符合直觉,具体代码上不以改某个 mask 为主,而是以改 finalmask 的架构为主,具体的 UDP mask 若要改则只是附带

@LjhAUMEM

Copy link
Copy Markdown
Contributor

反正谁要实现这个"开创性"的 udphop + noise 以后整个 finalmask 都可以给他了,有这个实力,另外我说的嵌套 dialer 就是动的架构,就是细节要处理一下

@patterniha

Copy link
Copy Markdown
Collaborator

It's okay, you can reopen it, but I hope you can handle all finalmask-related issues in the future

I didn't open the PR because the code is correct. I opened it because the issue it addresses is valid.

Currently, UDP follows a whitelist-based pattern in Iran, so a random pattern like Salamander won't work.

Also, currently by using finalmask-udp-header-custom and appending a white header (for example SIP header), we can bypass the firewall.

@LjhAUMEM

Copy link
Copy Markdown
Contributor

我关的点是因为这方案没起效果?就这种只是实现 udphop+noise 我有几百种方式,但你有没有考虑过其他 mask 的搭配方式,当初设计的架构就不允许出现这种情况,早知道当初老老实实搞个 hy2 就好了

@LjhAUMEM

Copy link
Copy Markdown
Contributor

off-topic

我不是很了解伊朗,听说谷歌在你们那没有被封,所以很好奇你们翻墙是为了访问什么网站,是否有 geosite:gfw-iran @patterniha

@patterniha

patterniha commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

off-topic

我不是很了解伊朗,听说谷歌在你们那没有被封,所以很好奇你们翻墙是为了访问什么网站,是否有 geosite:gfw-iran @patterniha

instagram, X, telegram, youtube, whatsapp, ... . also for bypassing sanctions to access AI,...
also CDNs are now whitelisted (all upload packets dropped after about 20 packets for non-whitelist domains), so gfw-iran is meaningless.

@RPRX

RPRX commented Nov 13, 2026

Copy link
Copy Markdown
Member

@patterniha 像我说的这样 #7372 (comment) 改吧

@Meo597

Meo597 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

或许交给 lua 做比较合适,也不用吵了

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.

5 participants