Skip to content

Commit 4bada2d

Browse files
committed
Replace ESteamNetTransportKind with flags
(At least in the public interface.) P4:6571004,6571013
1 parent 9f8fbdc commit 4bada2d

File tree

8 files changed

+116
-43
lines changed

8 files changed

+116
-43
lines changed

include/steam/steamnetworkingtypes.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,6 @@ enum ESteamNetConnectionEnd
622622
k_ESteamNetConnectionEnd__Force32Bit = 0x7fffffff
623623
};
624624

625-
/// Enumerate different kinds of transport that can be used
626-
enum ESteamNetTransportKind
627-
{
628-
k_ESteamNetTransport_Unknown = 0,
629-
k_ESteamNetTransport_LoopbackBuffers = 1, // Internal buffers, not using OS network stack
630-
k_ESteamNetTransport_LocalHost = 2, // Using OS network stack to talk to localhost address
631-
k_ESteamNetTransport_UDP = 3, // Ordinary UDP connection.
632-
k_ESteamNetTransport_UDPProbablyLocal = 4, // Ordinary UDP connection over a route that appears to be "local", meaning we think it is probably fast. This is just a guess: VPNs and IPv6 make this pretty fuzzy.
633-
k_ESteamNetTransport_TURN = 5, // Relayed over TURN server
634-
k_ESteamNetTransport_SDRP2P = 6, // P2P connection relayed over Steam Datagram Relay
635-
k_ESteamNetTransport_SDRHostedServer = 7, // Connection to a server hosted in a known data center via Steam Datagram Relay
636-
637-
k_ESteamNetTransport_Force32Bit = 0x7fffffff
638-
};
639-
640625
/// Max length, in bytes (including null terminator) of the reason string
641626
/// when a connection is closed.
642627
const int k_cchSteamNetworkingMaxConnectionCloseReason = 128;
@@ -645,6 +630,13 @@ const int k_cchSteamNetworkingMaxConnectionCloseReason = 128;
645630
/// of a connection.
646631
const int k_cchSteamNetworkingMaxConnectionDescription = 128;
647632

633+
const int k_nSteamNetworkConnectionInfoFlags_Unauthenticated = 1; // We don't have a certificate for the remote host.
634+
const int k_nSteamNetworkConnectionInfoFlags_Unencrypted = 2; // Information is being sent out over a wire unencrypted (by this library)
635+
const int k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers = 4; // Internal loopback buffers. Won't be true for localhost. (You can check the address to determine that.) This implies k_nSteamNetworkConnectionInfoFlags_FastLAN
636+
const int k_nSteamNetworkConnectionInfoFlags_Fast = 8; // The connection is "fast" and "reliable". Either internal/localhost (check the address to find out), or the peer is on the same LAN. (Probably. It's based on the address and the ping time, this is actually hard to determine unambiguously).
637+
const int k_nSteamNetworkConnectionInfoFlags_Relayed = 16; // The connection is relayed somehow (SDR or TURN).
638+
const int k_nSteamNetworkConnectionInfoFlags_DualWifi = 32; // We're taking advantage of dual-wifi multi-path
639+
648640
/// Describe the state of a connection.
649641
struct SteamNetConnectionInfo_t
650642
{
@@ -689,11 +681,8 @@ struct SteamNetConnectionInfo_t
689681
/// internal logging messages.
690682
char m_szConnectionDescription[ k_cchSteamNetworkingMaxConnectionDescription ];
691683

692-
/// What kind of transport is currently being used?
693-
/// Note that this is potentially a dynamic property! Also, it may not
694-
/// always be available, especially right as the connection starts, or
695-
/// after the connection ends.
696-
ESteamNetTransportKind m_eTransportKind;
684+
/// Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx
685+
int m_nFlags;
697686

698687
/// Internal stuff, room to change API easily
699688
uint32 reserved[63];

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ void CSteamNetworkConnectionBase::ClearCrypto()
11121112
m_msgCertRemote.Clear();
11131113
m_msgCryptRemote.Clear();
11141114
m_bCertHasIdentity = false;
1115+
m_bRemoteCertHasTrustedCASignature = false;
11151116
m_keyPrivate.Wipe();
11161117
ClearLocalCrypto();
11171118
}
@@ -1530,6 +1531,9 @@ bool CSteamNetworkConnectionBase::BRecvCryptoHandshake( const CMsgSteamDatagramC
15301531
return false;
15311532
}
15321533

1534+
// Remember if we they were authenticated
1535+
m_bRemoteCertHasTrustedCASignature = ( pCACertAuthScope != nullptr );
1536+
15331537
// Deserialize crypt info
15341538
if ( !m_msgCryptRemote.ParseFromString( m_sCryptRemote ) )
15351539
{
@@ -1891,6 +1895,12 @@ void CSteamNetworkConnectionBase::ConnectionPopulateInfo( SteamNetConnectionInfo
18911895
V_strcpy_safe( info.m_szEndDebug, m_szEndDebug );
18921896
V_strcpy_safe( info.m_szConnectionDescription, m_szDescription );
18931897

1898+
// Set security flags
1899+
if ( !m_bRemoteCertHasTrustedCASignature || m_identityRemote.IsInvalid() || m_identityRemote.m_eType == k_ESteamNetworkingIdentityType_IPAddress )
1900+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Unauthenticated;
1901+
if ( m_eNegotiatedCipher <= k_ESteamNetworkingSocketsCipher_NULL )
1902+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Unencrypted;
1903+
18941904
if ( m_pTransport )
18951905
m_pTransport->TransportPopulateConnectionInfo( info );
18961906
}
@@ -2791,8 +2801,8 @@ void CSteamNetworkConnectionBase::ConnectionPopulateDiagnostics( ESteamNetworkin
27912801
APIGetDetailedConnectionStatus( stats, usecNow );
27922802

27932803
// Fill in diagnostic fields that correspond to SteamNetConnectionInfo_t
2794-
if ( stats.m_info.m_eTransportKind != k_ESteamNetTransport_Unknown )
2795-
msgConnectionState.set_transport_kind( stats.m_info.m_eTransportKind );
2804+
if ( stats.m_eTransportKind != k_ESteamNetTransport_Unknown )
2805+
msgConnectionState.set_transport_kind( stats.m_eTransportKind );
27962806
if ( stats.m_info.m_idPOPRelay )
27972807
msgConnectionState.set_sdrpopid_local( SteamNetworkingPOPIDRender( stats.m_info.m_idPOPRelay ).c_str() );
27982808
if ( stats.m_info.m_idPOPRemote )
@@ -3928,7 +3938,12 @@ int CSteamNetworkConnectionPipe::SendEncryptedDataChunk( const void *pChunk, int
39283938
void CSteamNetworkConnectionPipe::TransportPopulateConnectionInfo( SteamNetConnectionInfo_t &info ) const
39293939
{
39303940
CConnectionTransport::TransportPopulateConnectionInfo( info );
3931-
info.m_eTransportKind = k_ESteamNetTransport_LoopbackBuffers;
3941+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers | k_nSteamNetworkConnectionInfoFlags_Fast;
3942+
3943+
// Since we're using loopback buffers, the security flags can't really apply.
3944+
// Make sure they are turned off
3945+
info.m_nFlags &= ~k_nSteamNetworkConnectionInfoFlags_Unauthenticated;
3946+
info.m_nFlags &= ~k_nSteamNetworkConnectionInfoFlags_Unencrypted;
39323947
}
39333948

39343949
void CSteamNetworkConnectionPipe::ConnectionStateChanged( ESteamNetworkingConnectionState eOldState )

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ class CSteamNetworkConnectionBase : public ILockableThinker< ConnectionLock >
697697
std::string m_sCryptRemote;
698698
CMsgSteamDatagramCertificate m_msgCertRemote;
699699
CMsgSteamDatagramSessionCryptInfo m_msgCryptRemote;
700+
bool m_bRemoteCertHasTrustedCASignature; // Could expand this to an enum of different states
700701

701702
// Local crypto info for this connection
702703
CECSigningPrivateKey m_keyPrivate; // Private key corresponding to our cert. We'll wipe this in FinalizeLocalCrypto, as soon as we've locked in the crypto properties we're going to use
@@ -952,7 +953,7 @@ class CSteamNetworkConnectionPipe final : public CSteamNetworkConnectionBase, pu
952953
virtual void DestroyTransport() override;
953954
virtual void ConnectionStateChanged( ESteamNetworkingConnectionState eOldState ) override;
954955

955-
// CSteamNetworkConnectionTransport
956+
// CConnectionTransport
956957
virtual bool SendDataPacket( SteamNetworkingMicroseconds usecNow ) override;
957958
virtual bool BCanSendEndToEndConnectRequest() const override;
958959
virtual bool BCanSendEndToEndData() const override;

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p_ice.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,44 @@ void CConnectionTransportP2PICE::TransportPopulateConnectionInfo( SteamNetConnec
4242
CConnectionTransport::TransportPopulateConnectionInfo( info );
4343

4444
info.m_addrRemote = m_currentRouteRemoteAddress;
45-
info.m_eTransportKind = m_eCurrentRouteKind;
46-
47-
// If we thought the route was local, but ping time is too high, then clear local flag.
48-
// (E.g. VPN)
49-
if ( info.m_eTransportKind == k_ESteamNetTransport_UDPProbablyLocal )
45+
switch ( m_eCurrentRouteKind )
5046
{
51-
int nPingMin, nPingMax;
52-
m_pingEndToEnd.GetPingRangeFromRecentBuckets( nPingMin, nPingMax, SteamNetworkingSockets_GetLocalTimestamp() );
53-
if ( nPingMin >= k_nMinPingTimeLocalTolerance )
54-
info.m_eTransportKind = k_ESteamNetTransport_UDP;
47+
default:
48+
case k_ESteamNetTransport_SDRP2P:
49+
case k_ESteamNetTransport_Unknown:
50+
// Hm...
51+
Assert( false );
52+
break;
53+
54+
case k_ESteamNetTransport_LocalHost:
55+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Fast;
56+
break;
57+
58+
case k_ESteamNetTransport_UDP:
59+
break;
60+
61+
case k_ESteamNetTransport_UDPProbablyLocal:
62+
{
63+
int nPingMin, nPingMax;
64+
m_pingEndToEnd.GetPingRangeFromRecentBuckets( nPingMin, nPingMax, SteamNetworkingSockets_GetLocalTimestamp() );
65+
if ( nPingMin < k_nMinPingTimeLocalTolerance )
66+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Fast;
67+
break;
68+
}
69+
70+
case k_ESteamNetTransport_TURN:
71+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Relayed;
72+
info.m_addrRemote.Clear();
73+
break;
5574
}
5675
}
5776

5877
void CConnectionTransportP2PICE::GetDetailedConnectionStatus( SteamNetworkingDetailedConnectionStatus &stats, SteamNetworkingMicroseconds usecNow )
5978
{
60-
// FIXME Need to indicate whether we are relayed or were able to pierce NAT
61-
CConnectionTransport::GetDetailedConnectionStatus( stats, usecNow );
79+
CConnectionTransportUDPBase::GetDetailedConnectionStatus( stats, usecNow );
80+
stats.m_eTransportKind = m_eCurrentRouteKind;
81+
if ( stats.m_eTransportKind == k_ESteamNetTransport_UDPProbablyLocal && !( stats.m_info.m_nFlags & k_nSteamNetworkConnectionInfoFlags_Fast ) )
82+
stats.m_eTransportKind = k_ESteamNetTransport_UDP;
6283
}
6384

6485
// Base-64 encode the least significant 30 bits.

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_udp.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,25 @@ void CConnectionTransportUDPBase::Received_NoConnection( const CMsgSteamSockets_
896896
m_connection.ConnectionState_ClosedByPeer( k_ESteamNetConnectionEnd_Misc_PeerSentNoConnection, "Received unexpected 'no connection' from peer");
897897
}
898898

899+
void CConnectionTransportUDPBase::GetDetailedConnectionStatus( SteamNetworkingDetailedConnectionStatus &stats, SteamNetworkingMicroseconds usecNow )
900+
{
901+
CConnectionTransport::GetDetailedConnectionStatus( stats, usecNow );
902+
903+
// Assume that flags field has already been populated by code above
904+
if ( stats.m_info.m_addrRemote.IsLocalHost() )
905+
{
906+
stats.m_eTransportKind = k_ESteamNetTransport_LocalHost;
907+
}
908+
else if ( stats.m_info.m_nFlags & k_nSteamNetworkConnectionInfoFlags_Fast )
909+
{
910+
stats.m_eTransportKind = k_ESteamNetTransport_UDPProbablyLocal;
911+
}
912+
else
913+
{
914+
stats.m_eTransportKind = k_ESteamNetTransport_UDP;
915+
}
916+
}
917+
899918
/////////////////////////////////////////////////////////////////////////////
900919
//
901920
// IP connections
@@ -1312,18 +1331,26 @@ void CConnectionTransportUDP::TransportConnectionStateChanged( ESteamNetworkingC
13121331

13131332
void CConnectionTransportUDP::TransportPopulateConnectionInfo( SteamNetConnectionInfo_t &info ) const
13141333
{
1315-
CConnectionTransport::TransportPopulateConnectionInfo( info );
1334+
CConnectionTransportUDPBase::TransportPopulateConnectionInfo( info );
13161335

13171336
if ( m_pSocket )
13181337
{
13191338
const netadr_t &addr = m_pSocket->GetRemoteHostAddr();
13201339
NetAdrToSteamNetworkingIPAddr( info.m_addrRemote, addr );
1321-
if ( addr.IsLoopback() )
1322-
info.m_eTransportKind = k_ESteamNetTransport_LocalHost;
1340+
if ( addr.IsLoopback() ) // Actually "localhost"
1341+
{
1342+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Fast;
1343+
1344+
// Should we turn off security flags? not sure. We are not really sure that
1345+
// the other side is "us", meaning our own process. It could be
1346+
// some rogue hacker process.
1347+
//info.m_nFlags &= ~k_nSteamNetworkConnectionInfoFlags_Unauthenticated;
1348+
//info.m_nFlags &= ~k_nSteamNetworkConnectionInfoFlags_Unencrypted;
1349+
}
13231350
else if ( m_connection.m_statsEndToEnd.m_ping.m_nSmoothedPing <= 5 && IsRouteToAddressProbablyLocal( addr ) )
1324-
info.m_eTransportKind = k_ESteamNetTransport_UDPProbablyLocal;
1325-
else
1326-
info.m_eTransportKind = k_ESteamNetTransport_UDP;
1351+
{
1352+
info.m_nFlags |= k_nSteamNetworkConnectionInfoFlags_Fast;
1353+
}
13271354
}
13281355
}
13291356

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_udp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ class CConnectionTransportUDPBase : public CConnectionTransport
125125
public:
126126
CConnectionTransportUDPBase( CSteamNetworkConnectionBase &connection );
127127

128-
// Implements CSteamNetworkConnectionTransport
128+
// Implements CConnectionTransport
129129
virtual bool SendDataPacket( SteamNetworkingMicroseconds usecNow ) override;
130130
virtual int SendEncryptedDataChunk( const void *pChunk, int cbChunk, SendPacketContext_t &ctx ) override;
131131
virtual void SendEndToEndStatsMsg( EStatsReplyRequest eRequest, SteamNetworkingMicroseconds usecNow, const char *pszReason ) override;
132+
virtual void GetDetailedConnectionStatus( SteamNetworkingDetailedConnectionStatus &stats, SteamNetworkingMicroseconds usecNow ) override;
132133

133134
protected:
134135
void Received_Data( const uint8 *pPkt, int cbPkt, SteamNetworkingMicroseconds usecNow );
@@ -157,7 +158,7 @@ class CConnectionTransportUDP final : public CConnectionTransportUDPBase
157158
public:
158159
CConnectionTransportUDP( CSteamNetworkConnectionUDP &connection );
159160

160-
// Implements CSteamNetworkConnectionTransport
161+
// Implements CConnectionTransport
161162
virtual void TransportFreeResources() override;
162163
virtual bool BCanSendEndToEndConnectRequest() const override;
163164
virtual bool BCanSendEndToEndData() const override;

src/steamnetworkingsockets/steamnetworking_stats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#include <steam/steamnetworkingtypes.h>
14+
#include "steamnetworkingsockets_internal.h"
1415

1516
#pragma pack(push)
1617
#pragma pack(8)
@@ -328,6 +329,9 @@ struct SteamNetworkingDetailedConnectionStatus
328329
/// Basic connection info
329330
SteamNetConnectionInfo_t m_info;
330331

332+
/// What kind of transport us being used?
333+
ESteamNetTransportKind m_eTransportKind;
334+
331335
/// Do we have a valid network configuration? We cannot do anything without this.
332336
ESteamNetworkingAvailability m_eAvailNetworkConfig;
333337

src/steamnetworkingsockets/steamnetworkingsockets_internal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@
7070
#endif
7171
#endif
7272

73+
/// Enumerate different kinds of transport that can be used
74+
enum ESteamNetTransportKind
75+
{
76+
k_ESteamNetTransport_Unknown = 0,
77+
k_ESteamNetTransport_LoopbackBuffers = 1, // Internal buffers, not using OS network stack
78+
k_ESteamNetTransport_LocalHost = 2, // Using OS network stack to talk to localhost address
79+
k_ESteamNetTransport_UDP = 3, // Ordinary UDP connection.
80+
k_ESteamNetTransport_UDPProbablyLocal = 4, // Ordinary UDP connection over a route that appears to be "local", meaning we think it is probably fast. This is just a guess: VPNs and IPv6 make this pretty fuzzy.
81+
k_ESteamNetTransport_TURN = 5, // Relayed over TURN server
82+
k_ESteamNetTransport_SDRP2P = 6, // P2P connection relayed over Steam Datagram Relay
83+
k_ESteamNetTransport_SDRHostedServer = 7, // Connection to a server hosted in a known data center via Steam Datagram Relay
84+
85+
k_ESteamNetTransport_Force32Bit = 0x7fffffff
86+
};
87+
7388
// Redefine the macros for byte-swapping, to sure the correct
7489
// argument size. We probably should move this into platform.h,
7590
// but I suspect we'd find a bunch of "bugs" which currently don't

0 commit comments

Comments
 (0)