hysteria2: Fix obfs silently disabling socket buffer sizing - #17
Open
realyxl wants to merge 15 commits into
Open
hysteria2: Fix obfs silently disabling socket buffer sizing#17realyxl wants to merge 15 commits into
realyxl wants to merge 15 commits into
Conversation
Discover/Punch now take []netip.AddrPort and stay family-agnostic; the caller resolves STUN servers once and filters per-family at the call site. Drops conn.LocalAddr() v4/v6 inference, which was ambiguous on dual-stack or unbound sockets and redundant now that the client and server already know which family each socket belongs to.
Options.IPVersion (4 or 6) restricts realm connections to a single IP family: the client only opens the matching family conn, and the server only resolves STUN servers and punches peer candidates of that family.
Optional gateway port mapping established before STUN discovery, so in a double-NAT setup the address STUN observes corresponds to the path through the static pinhole. The mapped external address is merged into published and connect addresses; the mapping is renewed at half its lease lifetime and removed when the owning connection closes.
SalamanderPacketConn and GeckoPacketConn embed the net.PacketConn interface, which hides SetReadBuffer/SetWriteBuffer. quic-go's type assertion in setReceiveBuffer/setSendBuffer then fails and the socket keeps net.core.rmem_default instead of the 8 MB it asks for. Re-expose both methods, resolving the underlying conn with common.Cast as hysteria/hop.go does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SalamanderPacketConnandGeckoPacketConnembed thenet.PacketConninterface, soSetReadBuffer/SetWriteBufferare not promoted. quic-go gives up on its first assertion:No syscall is ever issued, so with
obfsconfigured the socket stays atnet.core.rmem_default(212992, ~146 packets of depth) instead of quic-go's 8 MB and overflows in bursts. Withoutobfsthe conn arrives as a bare*net.UDPConnand sizing works, which is why the symptom only shows with obfuscation on. Upstream hysteria forwards these methods for the same reason (extras/obfs/conn.go).Both are re-exposed through
common.Cast, which followsUpstream()so client-side wrappers such asbufio.UnbindPacketConnare resolved; this mirrorshysteria/hop.go.SyscallConnis deliberately left out:wrapConnaborts listen/dial when it errors, and the client may run over a non-UDP conn through a detour dialer.Reproducing quic-go's assertions against a real socket:
SetReadBufferOOBCapablePacketConn*net.UDPConn(reference)OOBCapablePacketConnstays false, so quic-go keeps usingReadFrom/WriteToand never bypasses deobfuscation. Over a non-UDP conn both returnos.ErrInvalid, whichwrapConndiscards.Builds and vets clean on linux, android, windows, darwin and freebsd;
gofumpt,gofmt -sandgcireport no changes.The
salamander.gohalf applies unchanged tomainif you want it on the 1.13.x line.