From 54d0d59e1b4e7101265e554e8d0ca5d0a4a301df Mon Sep 17 00:00:00 2001 From: Fletcher Dunn Date: Thu, 7 Apr 2022 17:32:35 -0700 Subject: [PATCH] Fix bug preventing multiple P2P connections to the same listen socket Added some comments and a warning if we hit a bad case where they are misusing the API. P4:7193688 --- .../clientlib/steamnetworkingsockets_p2p.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.cpp index 2b7a274..2affeb7 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.cpp @@ -3532,11 +3532,27 @@ bool CSteamNetworkingSockets::InternalReceivedP2PSignal( const CMsgSteamNetworki if ( bSearchDuplicateConnections ) { - CSteamNetworkConnectionP2P *pMatchingConnection = CSteamNetworkConnectionP2P::FindDuplicateConnection( this, nLocalVirtualPort, identityRemote, nRemoteVirtualPort, nUseSymmetricConnection > 0, nullptr ); + + // If this connection is symmetric, then we want to match any other connection. + // (Although it really ought to also be symmetric if they are using the API + // properly.) If this connection is NOT symmetric, then only match another + // symmetric connection. (Again, this is not the best practices use of the API.) + bool bMatchOnlySymmetricConnections = ( nUseSymmetricConnection <= 0 ); + + CSteamNetworkConnectionP2P *pMatchingConnection = CSteamNetworkConnectionP2P::FindDuplicateConnection( this, nLocalVirtualPort, identityRemote, nRemoteVirtualPort, nUseSymmetricConnection <= 0, nullptr ); if ( pMatchingConnection ) { ConnectionScopeLock lockMatchingConnection( *pMatchingConnection ); Assert( pMatchingConnection->m_pParentListenSocket == nullptr ); // This conflict should only happen for connections we initiate! + + // Check if they are mixing symmetric and asymmetric connections. + // That's not good. + if ( bMatchOnlySymmetricConnections ) + { + SpewWarning( "[%s] Outbound symmetric connection (local vport %d, remote vport %d) and matched to incoming connect request remote cxn ID #%u. You should configure the listen socket in symmetric mode\n", + pMatchingConnection->GetDescription(), pMatchingConnection->LocalVirtualPort(), pMatchingConnection->m_nRemoteVirtualPort, msg.from_connection_id() ); + } + int cmp = CompareSymmetricConnections( pMatchingConnection->m_unConnectionIDLocal, pMatchingConnection->GetSignedCertLocal().cert(), msg.from_connection_id(), msgConnectRequest.cert().cert() ); // Check if we prefer for our connection to act as the "client"