Skip to content

feat: add per-proxy-group bandwidth limiting - #3053

Open
bobbyunknown wants to merge 1 commit into
MetaCubeX:Alphafrom
bobbyunknown:feat/speed-limit-per-group
Open

feat: add per-proxy-group bandwidth limiting#3053
bobbyunknown wants to merge 1 commit into
MetaCubeX:Alphafrom
bobbyunknown:feat/speed-limit-per-group

Conversation

@bobbyunknown

Copy link
Copy Markdown

Add optional 'bandwidth' field to proxy groups for shared bidirectional rate limiting. Traffic routed through a bandwidth-limited group is throttled using a token-bucket limiter (bits/sec) shared across all connections in the group.

Config syntax:
proxy-groups:
- name: SPEED-LIMITED type: select
bandwidth: 500k # 500 Kbps (accepts: k/m/g/bps)
proxies:
- DIRECT

Implementation:

  • New component/ratelimit package with Limiter, RateLimitedConn (net.Conn), limitedCConn (C.Conn with ReadBuffer/WriteBuffer overrides to prevent bufio.Copy/Relay bypass via sing ExtendedConn promotion), and limitedPacketConn (UDP with WaitReadFrom zero-copy path coverage)
  • GroupBase stores shared *Limiter; GroupBase.LimitConn/LimitPacketConn wrap connections after dial in all group DialContext/ListenPacketContext
  • ParseBandwidth() handles '500k', '1m', '1Mbps', bare integers (Mbps)
  • Default bandwidth: 0 = unlimited (backward compatible)
  • transport/jls/jls.go refactored to use shared ratelimit package, removing duplicate rate limiter code

Add optional 'bandwidth' field to proxy groups for shared bidirectional
rate limiting. Traffic routed through a bandwidth-limited group is
throttled using a token-bucket limiter (bits/sec) shared across all
connections in the group.

Config syntax:
  proxy-groups:
    - name: SPEED-LIMITED
      type: select
      bandwidth: 500k   # 500 Kbps (accepts: k/m/g/bps)
      proxies:
        - DIRECT

Implementation:
- New component/ratelimit package with Limiter, RateLimitedConn (net.Conn),
  limitedCConn (C.Conn with ReadBuffer/WriteBuffer overrides to prevent
  bufio.Copy/Relay bypass via sing ExtendedConn promotion), and
  limitedPacketConn (UDP with WaitReadFrom zero-copy path coverage)
- GroupBase stores shared *Limiter; GroupBase.LimitConn/LimitPacketConn
  wrap connections after dial in all group DialContext/ListenPacketContext
- ParseBandwidth() handles '500k', '1m', '1Mbps', bare integers (Mbps)
- Default bandwidth: 0 = unlimited (backward compatible)
- transport/jls/jls.go refactored to use shared ratelimit package,
  removing duplicate rate limiter code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant