Skip to content

fix(sync): prefer gateway-backed LAN interfaces on Windows#247

Merged
ahmet-cetinkaya merged 2 commits into
mainfrom
fix/sync-windows-interface-selection
Feb 27, 2026
Merged

fix(sync): prefer gateway-backed LAN interfaces on Windows#247
ahmet-cetinkaya merged 2 commits into
mainfrom
fix/sync-windows-interface-selection

Conversation

@ahmet-cetinkaya

Copy link
Copy Markdown
Owner

Summary

Fixes Windows sync server address selection where WHPH could advertise a Hyper-V/virtual adapter IP (e.g. 172.31.x.x) instead of a LAN-reachable adapter.

This change makes interface selection route-aware and gateway-aware so pairing details prefer adapters that are actually reachable from the local network.

Closes #246.

What Changed

  • Extended NetworkInterfaceInfo with metadata used for smarter ranking:
    • hasDefaultGateway
    • interfaceMetric
    • isVirtual
    • gatewayIp
  • Added Windows interface metadata enrichment in NetworkInterfaceService:
    • queries PowerShell (Get-NetIPConfiguration, Get-NetIPInterface)
    • parses gateway + metric info
    • safely falls back to existing behavior if unavailable
  • Replaced interface priority logic with route-aware scoring:
    • strongly prefers default-gateway interfaces
    • prefers lower interface metric
    • keeps physical Ethernet/Wi-Fi preference
    • penalizes virtual adapters without default gateway
  • Updated primary IP retrieval path to use preferred ordering:
    • NetworkUtils.getLocalIpAddresses() now delegates to getPreferredIPAddresses()
  • Improved connection info robustness:
    • QR payload now includes all preferred local IPs while preserving best-ranked primary IP
  • Added tests for:
    • virtual-vs-physical ordering
    • gateway-backed 172.x handling
    • Windows metadata parsing

Validation

  • fvm flutter test test/core/application/features/sync/services/network_interface_service_test.dart
  • fvm flutter analyze lib/core/application/features/sync/services/network_interface_service.dart lib/core/application/features/sync/services/abstraction/i_network_interface_service.dart lib/presentation/ui/shared/utils/network_utils.dart lib/presentation/ui/features/sync/components/sync_connect_info_dialog.dart

…ay and metric support

Enhance network interface detection to prioritize interfaces based on gateway availability and interface metrics. Adds new fields to NetworkInterfaceInfo (hasDefaultGateway, interfaceMetric, isVirtual, gatewayIp), implements Windows-specific metadata retrieval via PowerShell, and refactors priority calculation to prefer physical interfaces with active gateways over virtual adapters. Exposes sorted results via new getPreferredIPAddresses() method.
@ahmet-cetinkaya ahmet-cetinkaya self-assigned this Feb 27, 2026
Repository owner deleted a comment from gemini-code-assist Bot Feb 27, 2026
…ndling and testability

- Add timeout (10s) to Windows metadata PowerShell query to prevent hanging
- Add error IDs for all error logging points for better debugging
- Include hasDefaultGateway, interfaceMetric, isVirtual, and gatewayIp in NetworkInterfaceInfo equality
- Refactor _calculatePriority to use isVirtual parameter instead of parsing name
- Add @VisibleForTesting wrappers for priority calculation, virtual interface detection, and Windows metadata resolution
- Add comprehensive tests for priority calculation, virtual interface detection, and metadata resolution
@ahmet-cetinkaya ahmet-cetinkaya merged commit 8e44a8a into main Feb 27, 2026
3 checks passed
@ahmet-cetinkaya ahmet-cetinkaya deleted the fix/sync-windows-interface-selection branch May 22, 2026 20: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.

[BUG] Device Sync: Windows server binds to virtual Hyper-V adapter instead of physical LAN interface

1 participant