mirror of
https://github.com/go-gost/x.git
synced 2026-10-19 16:16:32 +00:00
bc137fbd832276f2a8631c7320df3e3adaa1ddf0
gost#911: two concurrent UDP source sockets over one RUDP reverse tunnel over relay+TLS corrupted echo responses and made the host tear the tunnel down and rebind it every second. The tunnel is a single stream shared by every endpoint multiplexed over it. A datagram frame is not written to that stream atomically — UDPDatagram.WriteTo issues three separate Write calls (RSV/FRAG, SOCKS5 address, payload). Each Write is concurrency-safe on its own, but with several endpoints writing, frames interleave between those calls. A torn frame also leaves half a header in the stream, which the far end reads as io.ErrUnexpectedEOF and answers by rebuilding the whole tunnel. Hold a mutex for the whole frame instead of just the writes the datagram happens to make. Same defect in both udpTunConn copies. Reproduced with the reporter's script: relay+tls concurrent phase went from 44% loss with corrupted payloads and 1.0s gaps to 0.02% loss, no corruption, 0.003s gaps. Plain relay likewise. Single-endpoint high-rate loss (~35% at 14k pps) is unaffected UDP backpressure, not this bug.
x
The implementation layer for the GOST proxy framework. Every interface defined in core/ is implemented here — handlers, listeners, dialers, connectors, plus config parsing, registries, and all cross-cutting concerns.
Package layout
| Directory | Purpose |
|---|---|
handler/ |
Protocol handlers (http, socks4/5, ss, ssh, tunnel, tun, dns, redirect, etc.) |
listener/ |
Protocol listeners (tcp, tls, ws, http2/3, quic, kcp, icmp, tun, udp, etc.) |
dialer/ |
Outbound dialers (tcp, tls, ws, http2/3, quic, grpc, ssh, wg, kcp, icmp, etc.) |
connector/ |
Destination connectors (http, socks4/5, ss, ssh, relay, tunnel, direct, etc.) |
config/ |
Config struct, YAML/JSON parsing, and service construction |
registry/ |
Typed global registries for all component types |
service/ |
Accept loop wiring listener + handler |
chain/ |
Multi-hop forwarding chain and route implementation |
router/ |
Route table router (destination-based routing) |
hop/ |
Node group with load-balanced selection |
selector/ |
Load-balancing strategies (round-robin, random, weighted, hash) |
auth/, bypass/, admission/ |
Authentication, bypass rules, admission control |
resolver/, hosts/ |
DNS resolution and host mapping |
limiter/ |
Traffic, connection, and rate limiters |
recorder/, observer/ |
Traffic recording and observability |
ingress/, sd/, routing/ |
Ingress control, service discovery, routing rules |
logger/, metrics/, api/ |
Logging, Prometheus metrics, Web API |
metadata/, ctx/ |
Metadata key-value system and context propagation |
internal/ |
Shared internals — not importable externally |
Component pattern
Every handler, listener, dialer, and connector follows the same pattern: init() registers a constructor into a global registry, the constructor takes functional options, and Init(metadata.Metadata) extracts typed configuration from the metadata key-value map.
See CLAUDE.md for detailed architecture and conventions.
Languages
Go
100%