The OptiFi Core Engine is a high-performance C++ system daemon that bridges local host network traffic over USB to the ESP32 hardware node.
To compile and run the Core Engine daemon, please refer to the specific setup instructions for your operating system:
The Core Engine is built to bypass standard network bottlenecks, using libusb and the Linux kernel's Universal TUN/TAP driver to push hardware-accelerated traffic.
Why it was implemented: We need a main event loop that continuously polls the virtual network interface and the USB hardware to shuttle packets synchronously. Signatures & Logic:
- Uses standard POSIX
read()andwrite()calls to interact with the Linuxoptifi0TAP interface. - Framing Protocol: When pushing data from USB to the TAP interface, it parses the custom byte-level framing protocol (
'O','P','T','I', followed by a length header) to guarantee packet integrity across USB batch boundaries. - IPC Telemetry Server: Provisions a Unix Domain Socket at
/tmp/optifi.sock. It formats live bridge statistics into pipe-delimited strings (e.g.,BRIDGE_STATS|tx_bytes|rx_bytes|credits) and broadcasts them to any connected GUI clients.
Why it was implemented: Direct manipulation of the OS network stack is platform-specific. This file isolates Linux kernel-level operations. Signatures & Logic:
PlatformLinux::CreateTapDevice(...): Interfaces with/dev/net/tunviaioctl(fd, TUNSETIFF, ...)to spawn a raw Layer-2 Ethernet TAP device namedoptifi0.- Issues
ifconfig(orip link) commands dynamically to set the MAC address to02:00:00:13:37:00and bring the interface UP.
Why it was implemented: To talk directly to the TinyUSB vendor endpoints on the ESP32 without relying on slow OS-level CDC/serial drivers. Signatures & Logic:
- Interfaces with
libusb-1.0. UsbHardware::SendPacket(...): Dispatches data to the0x01Bulk OUT endpoint.UsbHardware::Poll(...): Actively drains the0x81Bulk IN endpoint.- Burst Batching Optimization: It aggressively loops up to 20 times per poll cycle, draining massive multi-megabit bursts from the USB FIFO instantly, completely eliminating software-induced bottlenecks and achieving esports-level ping times.