Skip to content

SOVEREIGN-NET/lib-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ZHTP lib-network: Mesh Networking for ISP Replacement

Rust License ZHTP

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.

Vision: The New Internet

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

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    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         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Features

Multi-Protocol Mesh Networking

  • 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

Advanced Security

  • 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

Economic Incentives

  • 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

Intelligent Discovery

  • 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

Module Structure

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

πŸ› οΈ Quick Start

Basic Mesh Node Setup

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(())
}

DHT Content Operations

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?;

Network Discovery

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());

Security Model

Wallet-Based Authentication

  • 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

Cryptographic Protection

  • 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 Controls

// 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?;

Economic Integration

Routing Rewards

  • 10 tokens base reward per message routed
  • 1 token per KB data size bonus
  • 5 tokens per hop multi-hop routing bonus

Automatic Payments

// 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?;

Global Coverage Strategy

Local Mesh (0-1 km)

  • Bluetooth LE: Phone-to-phone mesh networking
  • WiFi Direct: High-speed local connections

Regional Mesh (1-15 km)

  • LoRaWAN: Long-range radio with gateway infrastructure
  • WiFi Relay: Internet bridge points

Global Mesh (Worldwide)

  • Satellite: Starlink, Iridium, and other satellite networks
  • Internet Bridges: Hybrid connectivity for global reach

Performance Characteristics

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

Platform Support

Windows

  • WinRT Bluetooth APIs: Native Windows 10/11 Bluetooth LE
  • WiFi Direct APIs: Windows WiFi Direct framework
  • Device Manager Integration: Automatic hardware detection

Linux

  • BlueZ: Linux Bluetooth stack integration
  • NetworkManager: WiFi Direct and interface management
  • GPIO/SPI: Direct LoRaWAN hardware support (Raspberry Pi)

macOS

  • Core Bluetooth: Native macOS Bluetooth framework
  • System Profiler: Hardware capability detection
  • Network Framework: Modern networking APIs

Network Statistics

// 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);

Error Handling

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");
        }
    }
}

πŸ”¬ Testing

# Run all tests
cargo test

# Test with hardware detection
cargo test --features "hardware-test"

# Network integration tests
cargo test integration -- --nocapture

🀝 Contributing

lib-network is part of the ZHTP ecosystem. Contributions welcome!

  1. Protocol Implementation: Add support for new mesh protocols
  2. Platform Support: Improve cross-platform hardware detection
  3. Performance: Optimize routing and DHT operations
  4. Security: Enhance cryptographic protections

πŸ“š Related Documentation

Roadmap

Phase 1: Foundation

  • Multi-protocol mesh networking
  • Native binary DHT protocol
  • Cross-platform hardware detection
  • Wallet-based security model

Phase 2: Scale (In Progress)

  • Global satellite integration
  • Advanced routing algorithms
  • Mobile app integration
  • Industrial IoT support

Phase 3: Adoption

  • ISP partnership program
  • Community governance
  • Regulatory compliance
  • Mass deployment tools

lib-network: Powering the decentralized internet revolution, one mesh connection at a time. ✨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •