Skip to content

Conversation

@yashksaini-coder
Copy link
Contributor

Fixes: #553 (Implement Advanced Connection Management Features)

How was it fixed?

Implemented a complete connection management system matching JavaScript libp2p's capabilities:

Core Components Added:

  • DialQueue: Priority-based scheduling with concurrency limits and queue size management
  • ReconnectQueue: Automatic reconnection with exponential backoff for KEEP_ALIVE tagged peers
  • ConnectionPruner: Intelligent connection pruning based on peer tags, stream count, direction, and age
  • ConnectionRateLimiter: Per-host rate limiting using sliding window algorithm
  • ConnectionGate: IP allow/deny list filtering with CIDR support
  • AddressManager: Address sorting and filtering (transport priority, public/private, circuit relay)
  • DNSResolver: Async DNS resolution for /dns4/, /dns6/, and /dnsaddr/ multiaddrs with caching
  • ConnectionState: Enhanced connection status tracking (PENDING, OPEN, CLOSING, CLOSED) with timeline

Configuration Enhancements:

Extended ConnectionConfig with 17+ new options matching JS libp2p defaults:

  • Global connection limits (max_connections, max_parallel_dials, etc.)
  • Comprehensive timeout configuration (dial_timeout, inbound_upgrade_timeout, etc.)
  • Reconnection parameters (reconnect_retries, reconnect_backoff_factor, etc.)
  • Security lists (allow_list, deny_list with CIDR support)
  • Custom address sorting

Integration:

  • Fully integrated all components into Swarm class
  • Maintains backward compatibility with existing APIs
  • All components follow trio async patterns
  • Comprehensive error handling and logging

Summary of approach:

  1. Analyzed JS libp2p connection manager implementation
  2. Implemented components in phases following dependency order
  3. Integrated components into Swarm with proper lifecycle management
  4. Added comprehensive tests and fixed all type/lint issues

@yashksaini-coder
Copy link
Contributor Author

@seetadev @sumanjeet0012 @acul71 This PR is backed up from the original #1018 which got corrupt after resolving the commits. Raised this after the latest main branch, and the only difference in this branch is the git commit history.

Note

The failing interop tests are due to requests library not installed. There are no changes in the pyproject.toml

yashksaini-coder and others added 16 commits December 14, 2025 23:07
…load

The test creates 499 connections but the default max_connections is 300,
causing connection management to reject/prune connections. This fix:

- Configures host_a's swarm to allow enough connections (509) for all dummy peers
- Configures dummy hosts' swarms to allow more incoming connections
- Increases wait time from 0.5s to 1.0s for identify push to complete
- Fixes line length issues to pass linting

Fixes test_all_peers_receive_identify_push_with_semaphore_under_high_peer_load
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.

Implement Advanced Connection Management Features from JS libp2p

3 participants