roturLink

roturLink Platform Documentation

Overview

roturLink provides cross-platform system monitoring and control capabilities through both HTTP REST APIs and WebSocket connections. This document details the implementation differences between the Arch Linux (archLink.py) and macOS (macosLink.py) versions.

Architecture

Both implementations follow the same architectural pattern:

Configuration

Both platforms use an embedded configuration:

CONFIG = {
    "allowed_modules": [
        "system", "cpu", "memory", "disk", "network", 
        "bluetooth", "battery", "temperature"
    ],
    "allowed_origins": [
        "https://turbowarp.org", "https://origin.mistium.com",
        "http://localhost:5001", "http://localhost:5002", "http://localhost:3000",
        "http://127.0.0.1:5001", "http://127.0.0.1:5002", "http://127.0.0.1:3000"
    ]
}

Module Implementations

1. System Information Module

Purpose: Provides basic system and hardware information

Arch Linux Implementation

macOS Implementation

Common Data Returned:

{
    "platform": {"system": "macOS/Arch Linux", "architecture": "arm64/x86_64"},
    "cpu": {"cores": 8, "threads": 16},
    "bluetooth": {"available": true, "backend": "bleak"},
    "memory": {"total_gb": 16.0},
    "hostname": "hostname"
}

2. CPU Module

Purpose: Real-time CPU usage monitoring

Both Platforms

Data Returned:

{"cpu": {"percent": 25.4}}

3. Memory Module

Purpose: RAM usage statistics

Both Platforms

Data Returned:

{
    "memory": {
        "total": 17179869184,
        "used": 8589934592, 
        "percent": 50.0
    }
}

4. Disk Module

Purpose: Storage usage information

Both Platforms

Data Returned:

{
    "disk": {
        "total": 1000000000000,
        "used": 500000000000,
        "percent": 50.0
    }
}

5. Network Module

Purpose: Network I/O statistics

Both Platforms

Data Returned:

{
    "network": {
        "sent": 1234567890,
        "received": 9876543210
    }
}

6. WiFi Module

Purpose: WiFi connection status and nearby network scanning

Arch Linux

macOS

Data Returned:

{
    "wifi": {
        "connected": true,
        "ssid": "NetworkName",
        "signal_strength": 85,
        "scan": [
            {"ssid": "Network1", "signal_strength": 90, "frequency": 2412, "connected": false},
            {"ssid": "Network2", "signal_strength": 75, "frequency": 5180, "connected": false}
        ]
    }
}

7. Bluetooth Module

Purpose: Bluetooth device discovery and monitoring

Both Platforms

Data Returned:

{
    "bluetooth": {
        "devices": [
            {"name": "Device Name", "address": "AA:BB:CC:DD:EE:FF", "rssi": -45, "last_seen": 1640995200}
        ],
        "count": 1,
        "timestamp": 1640995200
    }
}

8. Battery Module

Purpose: Battery status and power information

Both Platforms

Data Returned:

{
    "battery": {
        "percent": 85.5,
        "plugged": true
    }
}

9. Brightness Control Module

Purpose: Display brightness monitoring and control

Arch Linux

macOS

API Endpoints:

10. Volume Control Module

Purpose: Audio volume monitoring and control

Arch Linux

macOS

API Endpoints:

11. USB Drive Module

Purpose: USB drive detection, mounting, and file system access

Arch Linux

macOS

Security: Path validation restricts access to mounted USB drives only

API Endpoints:

12. File System Module

Purpose: File operations on USB drives

Both Platforms

Security: All operations restricted to validated USB drive paths

API Endpoints:

13. Temperature Module

Purpose: System temperature monitoring

Implementation Status

WebSocket Communication

Connection Flow

  1. Handshake: Server sends version info
  2. Initial Data: System info and current metrics
  3. Real-time Updates: Periodic metric broadcasts
  4. Command Handling: Bidirectional command/response

Message Format

{
    "cmd": "command_name",
    "val": { /* command-specific data */ }
}

Background Tasks

Security Features

Origin Validation

Path Validation

Dependencies Summary

Arch Linux

macOS

Error Handling

Command Execution

WebSocket Management

Performance Considerations

Caching Strategy

Async Operations

Development Guidelines

Adding New Modules

  1. Add module name to CONFIG["allowed_modules"]
  2. Implement platform-specific functions
  3. Add caching strategy if needed
  4. Create WebSocket command handlers
  5. Add HTTP endpoints if required
  6. Update this documentation

Platform-Specific Implementation

  1. Create separate functions for each platform
  2. Use run_command() wrapper for system calls
  3. Implement graceful fallbacks
  4. Test with and without optional dependencies
  5. Document required tools and packages

Testing Considerations