Skip to content

feat: add max_clients limit per service#447

Open
daviddang91 wants to merge 3 commits intorathole-org:mainfrom
daviddang91:main
Open

feat: add max_clients limit per service#447
daviddang91 wants to merge 3 commits intorathole-org:mainfrom
daviddang91:main

Conversation

@daviddang91
Copy link

Implement connection limit feature allowing administrators to restrict the number of concurrent client connections per service.

Features:

  • Add optional max_clients field to ServerServiceConfig
  • Shared ServiceConnectionTracker per service using Arc
  • RAII-based ConnectionGuard for automatic slot management
  • Pre-authentication connection limit check
  • ServiceAtFullCapacity protocol response for rejected clients
  • Drop-based cleanup ensuring slots freed on disconnect
  • Configurable heartbeat_interval for disconnect detection

Implementation details:

  • Connection tracking stored in Server.connection_trackers HashMap
  • Semaphore-based slot management (non-blocking try_acquire)
  • Automatic cleanup via ControlChannel Drop trait
  • Clean, minimal logging (connection/disconnection events only)

Example configs:

  • server_simple.toml: single client limit (max_clients=1)
  • server.toml: multiple scenarios (1, 5, unlimited)
  • heartbeat_interval=10s for fast disconnect detection

Backward compatible: existing configs work unchanged (unlimited by default)

Implement connection limit feature allowing administrators to restrict
the number of concurrent client connections per service.

Features:
- Add optional max_clients field to ServerServiceConfig
- Shared ServiceConnectionTracker per service using Arc<Semaphore>
- RAII-based ConnectionGuard for automatic slot management
- Pre-authentication connection limit check
- ServiceAtFullCapacity protocol response for rejected clients
- Drop-based cleanup ensuring slots freed on disconnect
- Configurable heartbeat_interval for disconnect detection

Implementation details:
- Connection tracking stored in Server.connection_trackers HashMap
- Semaphore-based slot management (non-blocking try_acquire)
- Automatic cleanup via ControlChannel Drop trait
- Clean, minimal logging (connection/disconnection events only)

Example configs:
- server_simple.toml: single client limit (max_clients=1)
- server.toml: multiple scenarios (1, 5, unlimited)
- heartbeat_interval=10s for fast disconnect detection

Backward compatible: existing configs work unchanged (unlimited by default)
Updated both English and Chinese README files to document the new
max_clients configuration option for server services.

- Added max_clients field in server.services configuration example
- Explained that it limits concurrent connections per service
- Default value: unlimited (backward compatible)
Consolidated example configurations to single pair of files:
- Removed server_simple.toml and client_simple.toml
- Simplified server.toml and client.toml to minimal config
- Kept only essential single-service example with max_clients=1

This makes the examples easier to understand and maintain while
still demonstrating the max_clients feature effectively.
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