Skip to content

Mux (Yamux)

[!NOTE] This document is partially generated by AI.

The Mux (Multiplexer) protocol allows multiple logical streams to be multiplexed over a single underlying physical connection (like a single TCP connection). yuhaiin uses Yamux for this purpose.

  • TCP: Supported (Stream-based).
  • UDP: Not supported. Mux is designed to manage multiple streams over a single reliable transport.

In both outbound and inbound scenarios, the mux block uses a single primary setting:

  • concurrency (int): The maximum number of concurrent streams allowed on the underlying connection.
    • Recommendation: Values between 4 and 16 are common. higher values allow more simultaneous sessions but may increase memory usage.
{
"mux": {
"concurrency": 8
}
}

Yamux provides flow control and keep-alive features, making it ideal for maintaining stable connections over unreliable networks. It can be paired with protocols like Shadowsocks or Trojan to add multiplexing capabilities.

yuhaiin uses the hashicorp/yamux library. The implementation is located in pkg/net/proxy/mux.