fix(wireguard): include ListenPort in buildConfigString#91
Conversation
writeConfig emits `ListenPort = ...`; buildConfigString omits it. printQRCode uses buildConfigString, so QR-imported configs lack the deterministic listen port that file-saved configs carry. The two paths now produce identical [Interface] sections for the same Interface.
Per maintainer feedback: - Remove findFreePorts(1) from parseConfig. A port found free at config-build time can be taken before WireGuard binds it (TOCTOU). When no port is given, leave listenPort unset so WireGuard auto-selects a free UDP port at bind time. - listenPort is now an optional parseConfig param and an optional interface field. - writeConfig and buildConfigString emit 'ListenPort = ...' only when a port was explicitly set, keeping the two serializers consistent. - Drop the now-unused find-free-ports import.
|
Reworked per your feedback — two changes beyond the original 1. Dropped the 2.
The now-unused Note on asymmetry with the v2ray SOCKS-port PR: there I put the optional port on the constructor, here it's on |
Summary
writeConfig(line 148) emitsListenPort = ....buildConfigString(line 177-195) omits it. SinceprintQRCodeusesbuildConfigString, QR-imported configs lack the deterministic listen port that file-saved configs carry.This is an asymmetry, not a behavior debate: the two methods should produce identical
[Interface]sections from the sameInterfaceobject.Diff
let config = "[Interface]\n"; config += "Address = " + this.interface.addresses.join(",") + "\n"; config += "PrivateKey = " + this.interface.privateKey + "\n"; +config += "ListenPort = " + this.interface.listenPort.toString() + "\n"; config += "DNS = " + this.interface.dns.join(",") + "\n";Test plan
npx tsc --noEmitpasseswriteConfigbuildConfigStringoutput now matcheswriteConfigfor the[Interface]core fields