on Windows, SO_REUSEADDR does not carry over the same semantics as on
POSIX systems. a second socket can set SO_REUSEADDR and bind to a
port that is already in use by another process running under
the same user account. this means another local process could bind to
the P2P listen port and receive incoming connections intended for
bitcoind.
this matters because the P2P listener is expected to have exclusive ownership of its address and port. allowing another process to bind to it could let that process intercept incoming P2P connections. this is in a similar spirit to #36169, which made the RPC listener exclusive on Windows.
to fix this, we use SO_EXCLUSIVEADDRUSE for the P2P listen socket on
Windows instead of SO_REUSEADDR, while retaining SO_REUSEADDR on
other platforms. the added test verifies the expected behaviour by
attempting to bind a second socket to the same port. on Windows, this
fails with WSAEACCES (10013), which Python exposes as
PermissionError (an OSError subclass).
references: