ptp-helper: Rewrite in Rust for portability and safety
Fixes #1259 (closed)
The goal here is to only use meson's Rust support and to not use cargo. See this for rationale.
While this is more code than the C version
- 1/3 of it is platform API definitions that are provided in C by the platform's headers, and would be provided in Rust by the
libc
andwindows-sys
crates but we can't easily make use of them here for build system and packaging reasons - There's Windows support and neither the Rust std library nor GLib have any API for single-threaded asynchronous IO
- Neither the Rust std library nor GLib have any API for listing all network interfaces
- More error paths are handled correctly
All the platform-specific complications are hidden behind abstractions so that adding support for another platform, or e.g. epoll()
instead of plain poll()
on Linux, should be doable without changing any of the existing code now.
TODO
-
Make Rust compiler optional and only build PTP support if it is available -
Generate a config.h
equivalent -
Split up code into multiple modules -
Switch stdout to not be line-buffered and stdin/stdout to raw encoding (especially for Windows) -
Proper error handling / reporting -
Join multicast addresses for the given interfaces, if any -
Collect MAC addresses from the interfaces (Linux) -
Collect MAC addresses from the interfaces (Windows, others?) -
Create a proper random clock ID (if no MAC address can be collected) -
Implement libcap support for dropping privileges -
Change from root to another UID/group if configured that way -
Figure out privileges situation on Windows -
Don't spawn 4 threads but use asynchronous IO (libc/ poll()
and Windows FFIWaitForMultipleObject
/WSAEventSelect()
) -
Extend protocol to directly collect capture times in the helper process to reduce jitterTo be done as a separate MR -
Set higher-than-normal thread priorities -
Include rustc in the non-cerbero CI images (!4327 (merged)) -
Fix cross-build on macOS/arm64 (cerbero!1151 (merged)) -
Clean up meson build rules