Replies: 3 comments 1 reply
-
|
Hi @acul71 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks, coordinate with @seetadev |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@Antrikshgwal : Thank you for your initiative. Please go ahead. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Issue: Configurable TTL Values in py-libp2p
Problem Statement
The current py-libp2p implementation uses hardcoded TTL (Time To Live) values throughout the codebase, which is not a good practice for several reasons:
Current State Analysis
Hardcoded TTL Values Found
libp2p/identity/identify_push/identify_push.pylibp2p/pubsub/utils.pylibp2p/kad_dht/utils.pylibp2p/kad_dht/utils.pyIssues with Current Approach
Problems:
Go libp2p Best Practices
Go libp2p implements a well-structured, configurable TTL system:
1. Defined TTL Constants
2. Configurable Options
3. Context-Aware TTL Selection
Recommended Solution
1. Create TTL Configuration Module
2. Update Identify Push Implementation
3. Update Other Components
4. Host Configuration Integration
Implementation Plan
Phase 1: Core Infrastructure
TTLConfigdataclassPhase 2: Component Updates
IdentifyPushto use configurable TTLPubSubutilitiesDHTutilitiesHostclass to accept TTL configPhase 3: Testing & Documentation
Benefits of This Approach
✅ Flexibility
✅ Consistency
✅ Maintainability
✅ Testability
✅ Backward Compatibility
Usage Examples
Basic Usage (Default TTLs)
Custom TTL Configuration
Environment-Specific Configuration
Migration Strategy
1. Gradual Migration
2. Deprecation Warning
3. Future Removal
Trio-Specific Considerations
Since py-libp2p uses Trio instead of asyncio, the TTL configuration should be designed with Trio's patterns in mind:
Trio's Structured Concurrency
Trio's Cancellation Handling
Trio's Resource Management
Trio's Timeout Handling
Trio's Testing Patterns
Real-World Example: Trio's Gradual Migration
Trio itself used gradual migration successfully for breaking changes:
Phase 1: Add new API
Phase 2: Deprecation warnings
Phase 3: Full migration
Conclusion
Implementing configurable TTL values will significantly improve py-libp2p's flexibility and align it with Go libp2p's best practices. The proposed solution provides:
This change addresses a fundamental architectural issue and brings py-libp2p closer to production-ready status.
Beta Was this translation helpful? Give feedback.
All reactions