-
Notifications
You must be signed in to change notification settings - Fork 191
Feat/advance connection management #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/advance connection management #1018
Conversation
… pruning, dialing, metrics tracking, rate limiting, and reconnection queue. These modules provide functionality for IP filtering, connection limits, priority-based dialing, metrics collection, rate limiting for incoming connections, and automatic reconnections for peers tagged with KEEP_ALIVE, aligning with JavaScript libp2p behavior.
… and improving connection handling in the Swarm class. Added support for connection limits, timeouts, rate limiting, and security features such as allow/deny lists. Introduced connection queues for dialing and reconnection, along with metrics tracking for active connections.
Introduced a new network layer for libp2p, including connection management features such as address sorting, filtering, and selection logic. The address manager aligns with JavaScript libp2p behavior and provides functionality for handling IP addresses, including checks for private and loopback addresses, as well as transport priority sorting. Updated connection pruner to enhance sorting logic for connection management.
Introduced a new module for managing connection states in libp2p, aligning with JavaScript libp2p behavior. This includes tracking connection statuses and timelines. Additionally, added a DNS resolver module for handling multiaddrs, supporting /dns4/, /dns6/, and /dnsaddr/ resolutions with caching capabilities. Both modules enhance the network layer's functionality and maintain consistency with existing libp2p features.
Updated the DialQueue class to integrate an AddressManager and DNSResolver for improved address handling. This allows for sorting, filtering, and resolving DNS addresses before dialing peers. The changes enhance the dialing process by preparing addresses and handling potential resolution failures, aligning with the overall network layer improvements.
- Introduced `is_closed` property in `INetConn` interface to check connection status. - Renamed `connection_gater` to `connection_gate` in `AddressManager` for consistency. - Enhanced error handling and logging in `ConnectionPruner` and `Swarm` classes. - Implemented connection management components including `ConnectionGate`, `ConnectionRateLimiter`, `AddressManager`, `DNSResolver`, `DialQueue`, `ReconnectQueue`, and `ConnectionPruner` in the `Swarm` class. - Added checks for connection limits and improved connection dialing logic using a dial queue. - Triggered connection pruning and reconnection logic based on connection status and limits.
- Improved dial queue management by checking if it is started before attempting to dial. - Added detailed error handling for various connection scenarios, including recoverable errors from the dial queue. - Ensured proper cleanup of connections and resources during failures in dialing and upgrading connections. - Refactored connection upgrade logic to handle exceptions and resource management more robustly. - Updated resource scope release to handle both coroutine and synchronous close methods.
…ng and logging - Updated the `allow_list` parameter in `ConnectionPruner` to accept both string and Multiaddr types for better flexibility. - Enhanced logging messages in the `Swarm` class for clarity and consistency, particularly in error handling and connection management. - Improved code readability by breaking long lines and adding whitespace for better structure.
- Added `prometheus-client` version 0.23.0 to the development dependencies in `pyproject.toml` for enhanced monitoring capabilities.
…nnection limits, parallel dials, and timeouts. Implement exponential backoff for connection retries and improve peerstore update verification. Adjust concurrency settings to optimize performance with a higher number of peers.
… code readability. Adjust comments for better understanding of connection management and increase sleep duration for connection establishment.
…hance logging. Update comments for clarity and adjust sleep duration for improved connection stability.
…es to improve code cleanliness and maintainability.
|
Hi @yashksaini-coder, thanks for this PR. FAILED tests/core/network/test_connection_management.py::TestDNSResolver::test_dns_resolver_initialization - Failed: async def functions are not natively supported.
FAILED tests/core/network/test_connection_management.py::TestDNSResolver::test_dns_resolver_non_dns_address - Failed: async def functions are not natively supported.
FAILED tests/core/network/test_connection_management.py::TestDNSResolver::test_dns_resolver_cache - Failed: async def functions are not natively supported.
FAILED tests/core/network/test_connection_management.py::TestDNSResolver::test_dns_resolver_clear_cache - Failed: async def functions are not natively supported.why are you using @pytest.mark.asyncio
async def test_dns_resolver_initialization(self):
# Instead of :
@pytest.mark.trio
async def test_dns_resolver_initialization(self):Full review here: AI Pull Request Review: #1018 - Feat/advance connection managementReview Date: 2025-11-20 1. Summary of ChangesThis PR implements comprehensive advanced connection management features for py-libp2p, addressing issue #553. The changes bring Python libp2p's connection management capabilities in line with JavaScript libp2p's implementation. Issues Addressed
Issue #553 describes missing features in Python's connection management compared to JavaScript libp2p, including:
Modules AffectedNew Modules Added:
Modified Modules:
Statistics
Breaking ChangesNone identified. The PR maintains backward compatibility with existing APIs. 2. Branch Sync Status and Merge ConflictsBranch Sync Status
Merge Conflict Analysis
3. Strengths
4. Issues FoundCritical4.1 Missing Newsfragment (BLOCKER)
4.2 Test Failures: DNS Resolver Tests Using Wrong Pytest Marker
Major4.3 Pytest Unknown Mark Warnings
Minor4.4 DNS Resolver Uses
|
…r improved compatibility
…based dial queues, automatic reconnection, connection limits, rate limiting, and comprehensive metrics to align py-libp2p with JavaScript libp2p.
…le for consistency
…uts for outbound and inbound stream negotiations, and adding connection direction tracking in the Swarm and ConnectionState classes.
…r for outbound and inbound stream negotiation timeouts in BasicHost class
Fixes: #553 (Implement Advanced Connection Management Features)
What was wrong?
Python libp2p was missing advanced connection management features present in JavaScript libp2p, including:
How was it fixed?
Implemented a complete connection management system matching JavaScript libp2p's capabilities:
Core Components Added:
/dns4/,/dns6/, and/dnsaddr/multiaddrs with cachingConfiguration Enhancements:
Extended
ConnectionConfigwith 17+ new options matching JS libp2p defaults:max_connections,max_parallel_dials, etc.)dial_timeout,inbound_upgrade_timeout, etc.)reconnect_retries,reconnect_backoff_factor, etc.)allow_list,deny_listwith CIDR support)Integration:
SwarmclassTesting:
Summary of approach:
@seetadev @sumanjeet0012 Raised a base PR to help add more advance connection management features.