lib-network is the core networking library of the ZHTP (Zero-Hash Transport Protocol) ecosystem, designed to create a mesh networking system that can replace traditional ISPs with a decentralized, community-owned internet infrastructure.
ZHTP lib-network enables:
- ** ISP Replacement**: Direct peer-to-peer mesh networking without ISP dependency
- ** Earn While You Connect**: Users get paid tokens for participating in the mesh network
- ** Post-Quantum Security**: Cryptographically secure with Dilithium2 and Kyber encryption
- π± Universal Access: Works on phones, laptops, IoT devices via Bluetooth, WiFi, LoRaWAN, Satellite
- π Local-First: Local mesh networking with global reach through relays
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ZHTP Mesh Server β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Wallet-Based Security Economic Incentives β
β β‘ Hardware Detection Emergency Controls β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Multi-Protocol Stack β
βββββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββββββββββββββββββ€
β π± Bluetooth β πΆ WiFi β LoRaWAN/Satellite β
β LE + Classic β Direct P2P β Long-Range Global β
βββββββββββββββββββΌββββββββββββββββΌββββββββββββββββββββββββββββ€
β Discovery & Routing System β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Hardware Detection Geographic Location β
β πΈοΈ Smart Routing Network Monitoring β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Native Binary DHT (lib-storage backend) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ποΈ Content Distribution Zero-Knowledge Proofs β
β Web4 Integration β‘ High-Performance Binary β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Bluetooth LE: Device-to-device communication (phones, laptops, IoT)
- Bluetooth Classic: High-throughput mesh connections
- WiFi Direct: Medium-range peer-to-peer connections
- LoRaWAN: Long-range (15km+) low-power communication
- Satellite: Global coverage for remote areas
- TCP/UDP: Internet bridging for hybrid connectivity
- Post-Quantum Cryptography: Dilithium2 signatures, Kyber encryption
- Wallet-Based Authentication: No centralized identity required
- Zero-Knowledge Proofs: Privacy-preserving verification
- Emergency Controls: Owner/admin access controls with audit logs
- Routing Rewards: Earn tokens for forwarding mesh traffic
- Storage Rewards: Get paid for providing DHT storage
- Relay Rewards: Compensation for internet bridge services
- UBI Distribution: Universal Basic Income through network participation
- Cross-Platform Hardware Detection: Automatic protocol enablement
- Geographic Routing: Location-aware mesh optimization
- Network Health Monitoring: Real-time statistics and diagnostics
- Smart Peer Selection: Reputation-based routing decisions
lib-network/
βββ src/
β βββ lib.rs # Main API and exports
β βββ types/ # Core data structures
β β βββ network_statistics.rs # Network monitoring
β β βββ mesh_message.rs # Mesh communication
β β βββ api_response.rs # API responses
β βββ mesh/
β β βββ server.rs # ZHTP Mesh Server (main component)
β βββ dht/ # Distributed Hash Table
β β βββ protocol.rs # Native binary DHT protocol
β β βββ cache.rs # Content caching
β β βββ monitoring.rs # DHT health monitoring
β βββ protocols/ # Network protocols
β β βββ bluetooth.rs # Bluetooth LE mesh
β β βββ wifi_direct.rs # WiFi Direct P2P
β β βββ lorawan.rs # LoRaWAN long-range
β β βββ satellite.rs # Satellite connectivity
β βββ discovery/ # Peer and hardware discovery
β β βββ hardware.rs # Cross-platform detection
β β βββ network_scanner.rs # Network topology scanning
β β βββ smart_routing.rs # Intelligent routing
β βββ platform/ # Platform-specific implementations
β βββ windows.rs # Windows WinRT APIs
β βββ linux.rs # Linux BlueZ/NetworkManager
β βββ macos.rs # macOS Core Bluetooth
βββ docs/ # This documentation
use lib_network::{ZhtpMeshServer, NetworkProtocol};
use lib_crypto::PublicKey;
use lib_storage::UnifiedStorageSystem;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize storage system
let storage = UnifiedStorageSystem::new().await?;
// Create owner wallet key for node control
let owner_key = PublicKey::new(vec![/* your public key */]);
// Configure protocols (auto-detected based on hardware)
let protocols = vec![
NetworkProtocol::BluetoothLE,
NetworkProtocol::WiFiDirect,
NetworkProtocol::LoRaWAN, // If hardware available
NetworkProtocol::Satellite, // Software-based
];
// Create and start mesh server
let mut server = ZhtpMeshServer::new(
[1u8; 32], // Node ID
owner_key,
storage,
protocols
).await?;
// Start the mesh internet
server.start().await?;
println!(" ZHTP Mesh Network ONLINE!");
println!(" Earning tokens for network participation!");
// Keep the server running
tokio::signal::ctrl_c().await?;
server.stop().await?;
Ok(())
}use lib_network::dht::DhtProtocolHandler;
// Query content from the mesh DHT
let content_hash = dht.query_content(
"example.zhtp", // Domain
"/index.html", // Path
peer_addr // Peer to query
).await?;
// Store content in the distributed network
let success = dht.store_content(
"mysite.zhtp", // Domain
"/page.html", // Path
content_data, // Content bytes
peer_addr // Storage peer
).await?;use lib_network::discovery::HardwareCapabilities;
// Detect available networking hardware
let capabilities = HardwareCapabilities::detect().await?;
println!("Available protocols:");
for protocol in capabilities.get_enabled_protocols() {
println!(" {}", protocol);
}
// Discover mesh peers
let peers = dht.discover_peers(10, bootstrap_peer).await?;
println!("Found {} mesh peers", peers.len());- Owner Wallet: Full node control, emergency stop, admin management
- Admin Wallets: Can disconnect peers, view audit logs
- User Wallets: Can disconnect own connections
- Routing Wallet: Receives automatic routing rewards
- Dilithium2 Signatures: Post-quantum digital signatures for all operations
- Kyber Encryption: Post-quantum key exchange for secure communication
- Blake3 Hashing: High-performance content addressing
- Replay Protection: Timestamp and nonce validation
// Emergency stop (owner only)
server.emergency_stop(&owner_credentials).await?;
// Connection limits for safety
server.set_max_connections(100).await?;
// Audit log for security operations
let audit_log = server.get_security_audit_log(&admin_credentials).await?;- 10 tokens base reward per message routed
- 1 token per KB data size bonus
- 5 tokens per hop multi-hop routing bonus
// Check routing earnings
let balance = server.get_routing_rewards_balance().await?;
println!("Earned {} tokens from routing", balance);
// Transfer rewards to external wallet
server.transfer_routing_rewards(recipient_key, amount).await?;- Bluetooth LE: Phone-to-phone mesh networking
- WiFi Direct: High-speed local connections
- LoRaWAN: Long-range radio with gateway infrastructure
- WiFi Relay: Internet bridge points
- Satellite: Starlink, Iridium, and other satellite networks
- Internet Bridges: Hybrid connectivity for global reach
| Protocol | Range | Bandwidth | Latency | Power |
|---|---|---|---|---|
| Bluetooth LE | 100m | 1 Mbps | 50ms | Low |
| WiFi Direct | 200m | 250 Mbps | 10ms | Medium |
| LoRaWAN | 15km | 50 kbps | 1s | Ultra-Low |
| Satellite | Global | 100 Mbps | 500ms | High |
- WinRT Bluetooth APIs: Native Windows 10/11 Bluetooth LE
- WiFi Direct APIs: Windows WiFi Direct framework
- Device Manager Integration: Automatic hardware detection
- BlueZ: Linux Bluetooth stack integration
- NetworkManager: WiFi Direct and interface management
- GPIO/SPI: Direct LoRaWAN hardware support (Raspberry Pi)
- Core Bluetooth: Native macOS Bluetooth framework
- System Profiler: Hardware capability detection
- Network Framework: Modern networking APIs
// Get comprehensive network statistics
let stats = server.get_network_stats().await;
println!("Network Status:");
println!(" Active Connections: {}", stats.active_connections);
println!(" Total Data Routed: {} MB", stats.total_data_routed / 1_000_000);
println!(" Routing Rewards: {} tokens", stats.routing_rewards_earned);
println!(" Network Health: {:.1}%", stats.network_health * 100.0);lib-network uses anyhow::Result for comprehensive error handling:
use anyhow::Result;
match server.start().await {
Ok(_) => println!(" Mesh server started successfully"),
Err(e) => {
eprintln!(" Failed to start mesh server: {}", e);
// Check for specific error conditions
if e.to_string().contains("hardware") {
eprintln!("π‘ Try: Install LoRaWAN hardware or enable Bluetooth");
}
}
}# Run all tests
cargo test
# Test with hardware detection
cargo test --features "hardware-test"
# Network integration tests
cargo test integration -- --nocapturelib-network is part of the ZHTP ecosystem. Contributions welcome!
- Protocol Implementation: Add support for new mesh protocols
- Platform Support: Improve cross-platform hardware detection
- Performance: Optimize routing and DHT operations
- Security: Enhance cryptographic protections
- Multi-protocol mesh networking
- Native binary DHT protocol
- Cross-platform hardware detection
- Wallet-based security model
- Global satellite integration
- Advanced routing algorithms
- Mobile app integration
- Industrial IoT support
- ISP partnership program
- Community governance
- Regulatory compliance
- Mass deployment tools
lib-network: Powering the decentralized internet revolution, one mesh connection at a time. β¨