fix: honor LocalInterfaceAddress when connecting WiFi devices#187
Conversation
…evices WiFiDeviceFinder already records the discovering NIC in IDeviceInfo.LocalInterfaceAddress, but the TCP connect path ignored it and let the OS routing table pick the egress interface. On multi-homed hosts that meant a device discovered on one NIC could be unconnectable because the follow-up TCP connection went out a different NIC. TcpStreamTransport now accepts an optional localInterface and, when supplied, binds the outbound socket to it before connecting. DaqifiDeviceFactory.ConnectFromDeviceInfoAsync threads deviceInfo.LocalInterfaceAddress through for the WiFi path. Behavior is unchanged when no local interface is supplied. Closes #147 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Review Summary by QodoHonor LocalInterfaceAddress in WiFi device TCP connections
WalkthroughsDescription• Honor LocalInterfaceAddress when connecting WiFi devices on multi-homed hosts • TcpStreamTransport now accepts optional localInterface parameter for socket binding • DaqifiDeviceFactory threads deviceInfo.LocalInterfaceAddress through WiFi connection path • Added comprehensive tests validating local interface binding and error handling Diagramflowchart LR
A["WiFi Device Discovery"] -->|LocalInterfaceAddress| B["DaqifiDeviceFactory"]
B -->|threads through| C["TcpStreamTransport"]
C -->|binds socket to| D["Specified NIC"]
D -->|connects via| E["Correct Egress Interface"]
File Changes1. src/Daqifi.Core/Communication/Transport/TcpStreamTransport.cs
|
Code Review by Qodo
1.
|
The earlier refactor of ConnectWiFiDeviceAsync to construct TcpStreamTransport directly bypassed ConnectTcpAsync's ValidatePort call. IPEndPoint validates 0-65535, but the original behavior rejected port 0 with an explicit ArgumentOutOfRangeException named "port" — keep that for parity. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hardware test resultsTested end-to-end against a Connection pathConfirmed:
Unit tests
8/8 passed on both net9.0 and net10.0 — matches the PR description. Caveats
Note on WiFi streaming flakiness during testingLate in my test session the device's WiFi side stopped emitting |
Summary
TcpStreamTransportnow takes an optionallocalInterfaceand, when supplied, binds the outbound socket to that address before connecting (multi-homed hosts can't otherwise control egress NIC).DaqifiDeviceFactory.ConnectFromDeviceInfoAsyncthreadsdeviceInfo.LocalInterfaceAddressinto the transport for the WiFi path; serial/HID paths and existingConnectTcpAsynccallers are unchanged.SocketException) plus a factory-level test that provesLocalInterfaceAddressis threaded through end-to-end.Closes #147.
Test plan
dotnet build src/Daqifi.Core.Tests/Daqifi.Core.Tests.csproj— cleandotnet test --filter "FullyQualifiedName~LocalInterface"— 8 passed on net9.0 and net10.0🤖 Generated with Claude Code