Telecom Module
Overview
The Telecom Module is the core networking and proxy management component of the Helium system. It provides comprehensive functionality for managing VPN/proxy networks, user subscriptions, traffic monitoring, and billing operations.
This module implements a sophisticated proxy network infrastructure that supports multiple protocols and backends, including XRayR and SSP compatibility, making it suitable for various deployment scenarios.
Key Features
Node Management
- Node Servers: Physical proxy servers that handle user connections
- Node Clients: Proxy endpoints that users connect to
- Multi-protocol Support: Compatible with various proxy protocols
- Geographic Distribution: Node location and route classification
- Status Monitoring: Real-time node health and availability tracking
Package System
- User Packages: Subscription-based service packages with traffic limits
- Package Queue: Automated package activation system
- Flexible Billing: Traffic-based and time-based billing models
- Traffic Factor: Custom billing multipliers per node
Traffic Analysis
- Real-time Monitoring: Track upload/download usage per user
- Historical Data: Traffic usage history and trends
- Billing Analytics: Calculate actual billed traffic vs raw usage
- Node Usage Statistics: Identify popular nodes and usage patterns
Subscription Management
- Dynamic Links: Generate subscription URLs for client applications
- Multiple Formats: Support various client configurations
- Token Management: Secure subscription tokens per user
- Auto-configuration: Client-side configuration generation
Architecture
Core Services
| Service | Purpose |
|---|---|
| NodeClientService | Manages proxy client endpoints |
| NodeServerService | Handles proxy server infrastructure |
| PackageQueueService | Processes user subscription packages |
| SubscribeLinkService | Generates subscription links |
| AnalysisService | Analyzes traffic and usage patterns |
| ManageService | Administrative operations |
gRPC API Structure
The module exposes two main gRPC services:
-
Telecom Service (
helium.telecom)- User-facing operations
- Node listing and information
- Package management
- Subscription links
- Traffic usage queries
-
Management Service (
helium.telecom_manage)- Admin operations
- Node server/client CRUD
- Package queue management
- Configuration validation
Data Models
Node Hierarchy
NodeServer (Physical Server)
├── NodeClient (Proxy Endpoint 1)
├── NodeClient (Proxy Endpoint 2)
└── NodeClient (Proxy Endpoint N)
Package Lifecycle
Created → In Queue → Active → Consumed/Cancelled
Integration Points
Dependencies
- Database: PostgreSQL for persistent data
- Redis: Caching and session management
- Message Queue: AMQP for event processing
- Authentication: Integration with auth module
- Management: Admin interface integration
External Libraries
- libsubconv: Subscription format conversion
- xrayr_feeder: XRayR backend integration
- subscribe_client_config: Client configuration generation
Usage Examples
Creating a Node Client
use telecom::services::manage::ManageService;
let manage_service = ManageService::new(db_pool, redis_conn);
// Create node client via processor pattern
let request = CreateNodeClientRequest {
server_id: 1,
name: "US-West-1".to_string(),
traffic_factor: "1.0".to_string(),
display_order: 100,
// ... other fields
};
let result = manage_service.process(request).await?;
Checking User Package
use telecom::services::package_queue::PackageQueueService;
let package_service = PackageQueueService::new(db_pool, redis_conn);
// Get user's current active package
let request = GetCurrentPackage { user_id };
let package_info = package_service.process(request).await?;
Generating Subscription Links
use telecom::services::subscribe_link::SubscribeLinkService;
let subscribe_service = SubscribeLinkService::new(db_pool, redis_conn);
// Generate subscription links for user
let request = GetSubscribeLinks { user_id };
let links = subscribe_service.process(request).await?;
Database Schema
Key database entities:
node_servers: Physical proxy serversnode_clients: Proxy client endpointspackages: Available service packagespackage_queue: User package subscriptionsuser_package_usage: Traffic usage trackingnode_status_history: Node availability history
Configuration
Environment Variables
The module uses configuration from telecom::config which includes:
- Database connection settings
- Redis connection parameters
- External service endpoints
- Billing calculation parameters
Node Configuration
Both node servers and clients support flexible JSON configuration for different proxy protocols and backends.
Event System
The module implements an event-driven architecture with:
Events
- Package Activation: When packages become active
- Usage Recording: Traffic usage events
- Node Status Changes: Server/client status updates
Hooks
- Billing Hook: Calculate traffic charges
- Registration Hook: New user package setup
- Package Queue Hook: Automated package processing
Automated Tasks (Cron)
The module includes scheduled tasks for:
- Package queue processing
- Traffic usage aggregation
- Node status monitoring
- Billing calculations
Testing
Comprehensive test coverage includes:
- Unit tests for each service
- Integration tests with database
- Management service tests
- Package queue processing tests
- Subscribe link generation tests
Test infrastructure uses testcontainers for isolated testing environments.
Development Guidelines
Service Pattern
All business logic is implemented using the Processor pattern (not object-oriented patterns). Each service exposes its functionality through the Processor trait.
Error Handling
- Use
anyhow::Resultfor error propagation - Proper error context with
tracing - No
unwrap()orexpect()calls (forbidden by clippy)
Database Access
- Use owned
RedisConnectiontype (not static lifetimes) - Proper connection pooling
- Transaction management for consistency
API Documentation
For detailed API documentation, refer to the generated protobuf documentation from:
proto/telecom/telecom.protoproto/telecom/manage.protoproto/telecom/common.proto
Troubleshooting
Common Issues
- Node Offline: Check server connectivity and configuration
- Package Not Activating: Verify queue processing and billing status
- Subscription Links Invalid: Check token generation and node availability
- Traffic Not Recording: Verify event processing and database connections
Logging
The module uses structured logging with tracing. Key log points:
- Package activation/deactivation
- Node status changes
- Traffic usage recording
- API request/response patterns
Migration Notes
When migrating from other proxy management systems:
- Import existing node configurations
- Migrate user packages and quotas
- Set up traffic factor mappings
- Configure billing parameters
- Test subscription link generation
For specific migration procedures, refer to the migration documentation in doc/src/migration/.