Skip to content

Conversation

@i-am-logger
Copy link

Summary

This PR implements a time delta/offset approach to fix incorrect timestamps on devices that cannot sync via NITZ (e.g., devices without active SIM cards). Instead of modifying the system clock (which requires root and may fail), we store a time offset in memory and apply it to all rayhunter-generated timestamps.

Addresses #121

Implementation Details

Backend

  • daemon/src/time_correction.rs: TimeCorrection module that stores offset in seconds and provides sync/get methods
  • API endpoints:
    • GET /api/time-correction - Get current offset and last sync time
    • POST /api/time-correction/sync - Sync time from browser timestamp
  • Manifest timestamps: Applied via apply_time_correction() in stats.rs
  • PCAP timestamps: Applied via write_gsmtap_message_with_datetime() in pcap.rs

Frontend

  • TimeSyncCard component: UI component for syncing time from browser
  • Displays current offset in human-readable format (hours/minutes/seconds)
  • Shows last sync timestamp
  • One-click sync button

How it works

  1. Browser sends current timestamp to /api/time-correction/sync
  2. Backend calculates offset: browser_time - system_time
  3. Offset stored in ServerState (in-memory, no persistence)
  4. All timestamps (manifest + PCAP) corrected when served via API
  5. Frontend displays current offset and allows re-sync

Benefits

  • ✅ No system clock modification (100% safe, no root required)
  • ✅ Works on locked-down devices where date -s fails
  • ✅ Timestamps remain consistent (no sudden jumps in files)
  • ✅ Easy to test on development machines

Testing

  • ✅ All 15 daemon unit tests passing (added 5 new tests)
  • ✅ Manually tested API endpoints
  • ✅ Verified manifest timestamps are corrected
  • ✅ Built successfully without warnings

Note on QMDL Files

QMDL files remain unmodified as they are raw binary diagnostic logs that should preserve data integrity. Only generated/served content (manifest entries, PCAP files) have corrected timestamps.

Open Question for Maintainers

Should we store the offset per-recording in the manifest to enable proper timestamp correlation between QMDL and PCAP files?

Currently, all recordings use the current global offset, which means:

  • If offset changes over time, old recordings will show different timestamps when re-downloaded
  • QMDL files have original timestamps while PCAP files have corrected timestamps
  • There's no easy way to know what offset was applied to a specific PCAP file

Potential solutions:

  1. Store offset_seconds in each ManifestEntry (preserves the offset used at recording time)
  2. Include offset metadata in PCAP file comments
  3. Keep current approach (simpler, assumes system clock was wrong the whole time)

Would appreciate guidance on which approach aligns better with the project goals.

Additional Commit

This PR also includes a devenv.nix setup commit for a reproducible development environment (similar to the PDS project structure). This is separate from the feature and can be reviewed independently or split into a separate PR if preferred.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings November 30, 2025 21:17
Copilot finished reviewing on behalf of i-am-logger November 30, 2025 21:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a time synchronization feature for devices without cellular connectivity by introducing a time offset approach that corrects timestamps without modifying the system clock. The implementation stores an in-memory offset that is applied to all rayhunter-generated timestamps (manifest entries and PCAP files). Additionally, the PR includes a devenv.nix development environment configuration for reproducible builds.

Key Changes

  • Time correction module that calculates and stores offset between browser time and system time
  • API endpoints for retrieving current offset and syncing time from browser
  • Frontend TimeSyncCard component with user-friendly offset display and one-click sync
  • PCAP and manifest timestamps are corrected on-the-fly when served via API
  • Development environment setup using devenv for reproducible builds

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
daemon/src/time_correction.rs Core time correction module with offset calculation and storage
daemon/src/stats.rs Applies time corrections to manifest entry timestamps
daemon/src/pcap.rs Applies time corrections to PCAP file generation
daemon/src/server.rs API endpoints for time correction (GET and POST)
daemon/src/main.rs Integrates time correction state and routes
lib/src/pcap.rs Adds method to write PCAP messages with corrected datetime
daemon/web/src/lib/components/TimeSyncCard.svelte UI component for time synchronization
daemon/web/src/lib/utils.svelte.ts Client-side API functions for time correction
daemon/web/src/routes/+page.svelte Integrates TimeSyncCard into main page
devenv.nix Development environment configuration with Rust and Node.js setup
devenv.yaml DevEnv inputs configuration for rust-overlay
devenv.lock Lock file for devenv dependencies
.envrc Direnv configuration for automatic environment loading
Cargo.lock Version bump to 0.8.0 for installer-gui

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@untitaker
Copy link
Collaborator

@i-am-logger gave it a quick look, code looks okay. here's three requests:

  • please remove the devenv stuff, it has nothign to do with this PR
  • if you are going to let agents review other agent's output, please do so on a fork rather than this PR. copilot reviewing cursor reviewing claude will generate notification emails for everybody.
  • some (very few) of the changes don't seem necessary, such as changing pcap.rs

@i-am-logger
Copy link
Author

i-am-logger commented Dec 1, 2025

@untitaker, I removed the devenv commit and fixed copilot comments, sorry didn't realize it will auto-trigger.

The pcap.rs changes apply time correction to downloaded PCAP/ZIP files so they match the corrected timestamps shown in the UI. QMDL files stay raw since changing timestamps there would break checksums. Happy to remove the PCAP changes if you prefer, though it's an open question whether users need corrected timestamps in downloaded files.

@i-am-logger i-am-logger force-pushed the feature/time-timezone-config branch from e8bb135 to 4ee47c5 Compare December 1, 2025 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants