Skip to content

Add measured USB4 and network path selection - #159

Merged
swellweb merged 1 commit into
swellweb:dev-3.4.0from
Betafer:codex/measured-usb4-paths
Aug 10, 2026
Merged

swellweb merged 1 commit into
swellweb:dev-3.4.0from
Betafer:codex/measured-usb4-paths

Conversation

@Betafer

@Betafer Betafer commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Context — a short story

I discovered TargetBridge while looking for a practical way to reuse a 21.5-inch 2017 Retina 4K iMac as the display for a Mac mini M4. Apple's Target Display Mode is unavailable on this iMac, while ordinary screen sharing was too slow for comfortable daily use.

I really liked TargetBridge's design: it creates a virtual display on the Sender and carries a low-latency encoded stream to the Receiver, instead of pretending that the iMac is a physical DisplayPort monitor. While testing it with Thunderbolt, USB4/USB-C, direct Ethernet and Wi-Fi, I found that the hardest part for a non-technical user was not the stream itself, but making sure it used the best cable instead of silently falling back to Wi-Fi.

This PR isolates that one improvement from the larger integrated prototype in #157, so it can be reviewed and accepted independently.

What this PR adds

  • Discovers separate Receiver endpoints for:
    • Thunderbolt Bridge
    • direct USB/USB4 networking
    • Ethernet
    • Wi-Fi
  • Identifies the matching local interface without assuming that Wi-Fi is always en0 or en1.
  • Performs a bounded, protocol-valid 16 MiB transfer over each candidate path.
  • Binds every probe to the exact local interface and measures application-level throughput plus connection latency.
  • Selects the measured fastest working path; interface names are used only as a tie-breaker.
  • Adds explicit preferences: auto, wired, thunderbolt, usb, ethernet, and wifi.
  • Exposes the selection through targetbridge connect --path ... and the existing URL/launch-argument automation.
  • Keeps legacy behavior unchanged when --path is omitted.

USB4 clarification

This does not turn the iMac into a native USB-C/DisplayPort sink and does not claim a raw 40 Gbit/s video path.

When macOS creates a direct USB-C/USB4 network interface between the two Macs, it normally appears as USB-NCM with a self-assigned 169.254.x.x address. TargetBridge continues to use its encoded network protocol over that interface. The selector measures the throughput TargetBridge can actually obtain, rather than trusting the cable's advertised link rate.

The same mechanism deliberately supports direct Ethernet and Thunderbolt Bridge, because the fastest real path depends on both Macs, adapters, macOS routing and the cable.

Receiver behavior

The Receiver advertises its Thunderbolt, USB/link-local, Ethernet and Wi-Fi IPv4 addresses as separate Bonjour TXT fields. Probe packets use the existing TEST_DATA packet type, which the Receiver discards without marking a video session active, so path selection does not start capture or flash the fullscreen session UI.

Examples

targetbridge connect --receiver auto --path auto
targetbridge connect --receiver auto --path wired
targetbridge connect --receiver auto --path usb

Intentionally not included

To keep this review focused, this PR does not include:

  • automatic retry or headless startup
  • Receiver-side Start/Stop controls
  • Retina 4K/60 capture changes
  • keyboard, mouse or clipboard forwarding
  • audio/display controls
  • installer or packaging changes

Those parts remain described in #157 and can be proposed as separate PRs by utility.

Validation

Tested on a Mac mini M4 and a 21.5-inch 2017 Retina 4K iMac with direct USB4/USB-C, Thunderbolt Bridge, Ethernet and Wi-Fi paths.

  • Sender: 96 XCTest tests passed
  • Receiver networking: 67 C checks passed
  • Receiver: full build completed successfully
  • CLI: shell syntax and help output verified
  • git diff --check: clean

No credentials, privileged helper, kernel extension or third-party dependency is added.

@swellweb

Copy link
Copy Markdown
Owner

Thank you for this focused contribution. The measured connection-path selection has been merged and released in TargetBridge 3.5.0 after local, live Thunderbolt and Apple Silicon/Intel CI verification.

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