Add Human-Readable IP Address Support to TON Configuration Files #1723
      
        
          +206
        
        
          −8
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
🎯 Overview
This PR introduces comprehensive human-readable IP address support for TON configuration files, making node configuration more user-friendly while maintaining full backward compatibility with existing numeric IP formats.
🚀 Features Implemented
✨ Human-Readable IPv4 Support
"ip": "192.168.1.100")"ip": -1062731775→192.168.0.1)"ip": 0→0.0.0.0)🔧 Components Enhanced
tl_json.hwith IP address conversion utilities🌐 Configuration Format Support
"ip": "192.168.1.100""ip": 3232235876"ip": -1062731775"ip": 0📋 Usage Examples
New Human-Readable Format (Recommended)
{ "@type": "engine.validator.config", "out_port": 3278, "addrs": [ { "@type": "engine.addr", "ip": "192.168.1.100", "port": 3278, "categories": [1], "priority_categories": [] }, { "@type": "engine.addrProxy", "in_ip": "10.0.0.50", "in_port": 3279, "out_ip": "203.0.113.10", "out_port": 3278, "proxy_type": { "@type": "adnl.proxy.fast", "shared_secret": "17ED48941A08F981574694FEFB4C3CDAB99AD44C19EF7B5E8A67306AF8D28C01" }, "categories": [1], "priority_categories": [] } ] }Legacy Numeric Format (Still Supported)
{ "@type": "engine.addr", "ip": 3232235876, // Equivalent to 192.168.1.100 "port": 3278 }Negative IP Format (Fully Compatible)
{ "@type": "engine.addr", "ip": -1062731775, // Equivalent to 192.168.0.1 "port": 3278 }🧪 Testing Results
✅ Comprehensive Test Suite Passed
validator-engineanddht-servercompile successfullyvalidator-engine --helpand basic operations work📊 IP Address Conversion Verification
🔍 Test Files Created
test-config-human-readable.json- Human-readable IP configuration exampletest-config-numeric.json- Numeric IP configuration exampletest-config-negative-ip.json- Negative IP configuration exampletest-human-readable-ip.sh- Comprehensive test script🔧 Technical Implementation
Core Changes
Enhanced JSON Serialization (
tl/tl/tl_json.h):from_json_ip_address()function for parsing both string and numeric IP formatsto_json_ip_address()function for outputting human-readable IP addressesConfiguration Processing (
validator-engine/validator-engine.cpp):load_config()with human-readable IP preprocessingwrite_config()to output human-readable IP formatDHT Server Support (
dht-server/dht-server.cpp):Conversion Logic
td::IPAddress::get_ipv4_address()td::IPAddress::ipv4_to_str()static_cast<td::uint32>(ip)to preserve bit patterns🎯 Benefits
For Users
For Developers
🛡️ Compatibility & Safety
📚 Migration Guide
For New Deployments
Use the new human-readable format for better maintainability:
For Existing Deployments
No changes required - your current configurations will continue to work:
For Mixed Environments
You can mix both formats in the same configuration file:
{ "addrs": [ { "ip": "192.168.1.100", "port": 3278 }, // Human-readable { "ip": 3232235876, "port": 3279 } // Numeric ] }🔮 Future Enhancements
This implementation provides a solid foundation for:
This enhancement makes TON node configuration more accessible while maintaining the robustness and compatibility that production environments require. 🚀