docs(handler/masque): add comprehensive comments for MASQUE proxy handler

Add detailed documentation to the masque handler package covering:
- Package-level doc explaining MASQUE protocol (RFC 9298 CONNECT-UDP,
  RFC 9114 CONNECT-TCP) and request flow
- Doc comments on all exported and unexported types, methods, and structs
- Inline comments explaining HTTP/3 context extraction and data path
- Field-level comments on metadata struct explaining each config param
- Step-by-step flow and data path diagrams for handleConnectUDP and
  handleConnectTCP
This commit is contained in:
ginuerzh
2026-06-07 14:29:18 +08:00
parent 3f671abfb6
commit 28e5922fce
2 changed files with 180 additions and 20 deletions
+29 -7
View File
@@ -8,22 +8,44 @@ import (
)
const (
// defaultBufferSize is the default UDP relay buffer size in bytes.
defaultBufferSize = 4096
defaultRealm = "gost"
// defaultRealm is the default HTTP Basic authentication realm for proxy auth.
defaultRealm = "gost"
)
// metadata holds parsed configuration values for the MASQUE handler.
// Values are extracted from the generic metadata map via parseMetadata.
type metadata struct {
hash string
bufferSize int
authBasicRealm string
idleTimeout time.Duration
// hash defines the hash source for load-balancing selector.
// When set to "host", the target address is used as the hash input
// for consistent routing through chain hops.
hash string
// bufferSize is the UDP relay buffer size in bytes for datagram forwarding.
bufferSize int
// authBasicRealm is the realm string sent in Proxy-Authenticate challenges.
authBasicRealm string
// idleTimeout is the read timeout for TCP connections during bidirectional relay.
// After this duration with no data, the relay is terminated.
idleTimeout time.Duration
observerPeriod time.Duration
observerResetTraffic bool
// observerPeriod is the interval between observer stats collection cycles.
observerPeriod time.Duration
// observerResetTraffic controls whether per-client traffic counters are
// reset to zero after each observer report.
observerResetTraffic bool
// limiterRefreshInterval controls how often the cached traffic limiter
// refreshes its limits from the global limiter source.
limiterRefreshInterval time.Duration
// limiterCleanupInterval controls how often the cached traffic limiter
// removes stale cached entries for disconnected clients.
limiterCleanupInterval time.Duration
}
// parseMetadata extracts typed configuration values from the generic metadata map.
// Metadata keys support multiple fallback names for compatibility (e.g., "bufferSize"
// and "udp.bufferSize"). Duration values accept both integer (seconds) and string
// (Go duration format like "5s") inputs.
func (h *masqueHandler) parseMetadata(md mdata.Metadata) (err error) {
h.md.hash = mdutil.GetString(md, "hash")