Strip added commentary from xray_xhttp.go and tuning
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+7
-28
@@ -6,40 +6,21 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// XrayNativeTuning holds the few operator-facing knobs for the in-process native
|
||||
// Xray. Transport-shaping parameters (HTTP/2 flow control, the XHTTP reorder
|
||||
// buffer, mux/UDP socket buffers) are intentionally NOT exposed: they are pinned
|
||||
// to xray-core / Go defaults so they cannot be misconfigured into breakage. Only
|
||||
// safe operational controls remain here: CPU parallelism, a global mux-session
|
||||
// DoS cap, and a packet-level trace toggle for debugging.
|
||||
type XrayNativeTuning struct {
|
||||
// RuntimeGOMAXPROCS controls Go CPU parallelism. 0 or negative = all cores.
|
||||
RuntimeGOMAXPROCS int `json:"runtime_gomaxprocs,omitempty"`
|
||||
// MuxGlobalSessions caps total concurrent mux child sessions across every
|
||||
// client connection (a DoS guard for the multi-tenant panel). 0 = default.
|
||||
MuxGlobalSessions int `json:"mux_global_sessions,omitempty"`
|
||||
// TracePackets enables very verbose per-packet XHTTP/mux logging. Debug only.
|
||||
TracePackets bool `json:"trace_packets,omitempty"`
|
||||
RuntimeGOMAXPROCS int `json:"runtime_gomaxprocs,omitempty"`
|
||||
MuxGlobalSessions int `json:"mux_global_sessions,omitempty"`
|
||||
TracePackets bool `json:"trace_packets,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
defaultNativeRuntimeGOMAXPROCS = 0
|
||||
defaultNativeMuxGlobalSessions = 32768
|
||||
|
||||
// Fixed transport defaults, aligned with xray-core / Go's net/http2. These are
|
||||
// deliberately not operator-tunable: wrong values silently break data flow.
|
||||
fixedNativeMuxMaxSessions = 128 // per-connection mux child-session guard
|
||||
fixedNativeMuxUDPIdleMS = 120000 // mux UDP backend idle cleanup (ms)
|
||||
fixedNativeMuxUDPReadBuffer = 256 * 1024 // mux UDP socket read buffer
|
||||
fixedNativeMuxUDPWriteBuffer = 256 * 1024 // mux UDP socket write buffer
|
||||
fixedNativeMuxMaxSessions = 128
|
||||
fixedNativeMuxUDPIdleMS = 120000
|
||||
fixedNativeMuxUDPReadBuffer = 256 * 1024
|
||||
fixedNativeMuxUDPWriteBuffer = 256 * 1024
|
||||
|
||||
// XHTTP: max tracked sessions (DoS guard) and the packet-up reorder buffer.
|
||||
// The per-inbound scMaxBufferedPosts from the config still overrides this.
|
||||
// xray-core's own default is 30 (its client sends POSTs near-in-order), but
|
||||
// other clients (v2rayNG/nekobox/etc.) fan out many concurrent POSTs that can
|
||||
// arrive well out of order; a small buffer then trips the reassembly-too-large
|
||||
// teardown and stalls traffic. Keep a generous default so reordering is
|
||||
// absorbed rather than fatal.
|
||||
defaultNativeXHTTPMaxSessions = 16384
|
||||
defaultNativeXHTTPBufferedPosts = 512
|
||||
)
|
||||
@@ -84,12 +65,10 @@ func applyNativeXrayTuning(t *XrayNativeTuning) XrayNativeTuning {
|
||||
return out
|
||||
}
|
||||
|
||||
// Operator-tunable values.
|
||||
func nativeRuntimeGOMAXPROCS() int { return int(nativeTuneRuntimeGOMAXPROCS.Load()) }
|
||||
func nativeMuxGlobalSessionLimit() int { return int(nativeTuneMuxGlobalSessions.Load()) }
|
||||
func nativeTracePacketsEnabled() bool { return nativeTuneTracePackets.Load() }
|
||||
|
||||
// Fixed transport limits (see the const block for rationale).
|
||||
func nativeMuxMaxSessionLimit() int { return fixedNativeMuxMaxSessions }
|
||||
func nativeMuxUDPReadBufferSize() int { return fixedNativeMuxUDPReadBuffer }
|
||||
func nativeMuxUDPWriteBufferSize() int { return fixedNativeMuxUDPWriteBuffer }
|
||||
|
||||
Reference in New Issue
Block a user