P2PConnectionTimeout

P2PConnectionTimeout

#Overview

name: P2PConnectionTimeout

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of P2PConnectionTimeout is to define a timeout period in seconds for peer-to-peer (P2P) sessions in the Steam networking subsystem of Unreal Engine. This variable is used to determine when a P2P connection should be considered expired or inactive.

This setting variable is primarily relied upon by the Online Subsystem Steam plugin, specifically within the Socket Subsystem Steam module. It’s an integral part of managing P2P network connections when using Steam as the online platform.

The value of this variable is set in the DefaultEngine.ini configuration file under the [OnlineSubsystemSteam] section. If not specified in the configuration, a warning message is logged, indicating that the key is missing.

P2PConnectionTimeout interacts with other variables in the FSocketSubsystemSteam class, such as P2PCleanupTimeout and LastReceivedTime. It’s used in conjunction with these variables to manage the lifecycle of P2P sessions.

Developers must be aware that this timeout should be at least as long as the NetDriver::ConnectionTimeout to ensure proper network behavior. Setting it too low might result in premature termination of valid connections, while setting it too high could lead to resources being held longer than necessary for inactive connections.

Best practices when using this variable include:

  1. Ensuring it’s properly set in the DefaultEngine.ini file to avoid relying on default values.
  2. Adjusting the value based on the specific needs of the game, considering factors like expected network conditions and desired responsiveness.
  3. Coordinating this value with other network-related timeouts to maintain consistent behavior across the networking system.
  4. Monitoring and logging connection timeouts during development and testing to fine-tune this value for optimal performance.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:2250, section: [OnlineSubsystemSteam]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemSteam/Source/Private/SocketSubsystemSteam.cpp:90

Scope (from outer to inner):

file
function     bool FSocketSubsystemSteam::Init

Source code excerpt:

		}

		if (!GConfig->GetFloat(TEXT("OnlineSubsystemSteam"), TEXT("P2PConnectionTimeout"), P2PConnectionTimeout, GEngineIni))
		{
			UE_LOG_ONLINE(Warning, TEXT("Missing P2PConnectionTimeout key in OnlineSubsystemSteam of DefaultEngine.ini"));
		}

		if (!GConfig->GetDouble(TEXT("OnlineSubsystemSteam"), TEXT("P2PCleanupTimeout"), P2PCleanupTimeout, GEngineIni))
		{

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemSteam/Source/Private/SocketSubsystemSteam.cpp:701

Scope (from outer to inner):

file
function     bool FSocketSubsystemSteam::Tick

Source code excerpt:


		bool bExpiredSession = true;
		if (CurSeconds - ConnectionInfo.LastReceivedTime < P2PConnectionTimeout)
		{
			P2PSessionState_t SessionInfo;
			if (ConnectionInfo.SteamNetworkingPtr != nullptr && ConnectionInfo.SteamNetworkingPtr->GetP2PSessionState(SessionId, &SessionInfo))
			{
				bExpiredSession = false;

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemSteam/Source/Private/SocketSubsystemSteam.h:81

Scope (from outer to inner):

file
class        class FSocketSubsystemSteam : public ISocketSubsystem, public FTSTickerObjectBase, public FSelfRegisteringExec

Source code excerpt:

	/** 
     * Timeout (in seconds) period for any P2P session
	 * read from [OnlineSubsystemSteam.P2PConnectionTimeout]
     * (should be at least as long as NetDriver::ConnectionTimeout) 
     */
	float P2PConnectionTimeout;
	/** Accumulated time before next dump of connection info */
	double P2PDumpCounter;
	/** Connection info output interval */
	double P2PDumpInterval;
	/**
	 * The timeout (in seconds) between when a connection/channel is marked as destroyed
	 * and when it's cleaned up. This allows for catching lingering messages

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemSteam/Source/Private/SocketSubsystemSteam.h:240

Scope (from outer to inner):

file
class        class FSocketSubsystemSteam : public ISocketSubsystem, public FTSTickerObjectBase, public FSelfRegisteringExec
function     FSocketSubsystemSteam

Source code excerpt:

	FSocketSubsystemSteam() :
	    bAllowP2PPacketRelay(false),
		P2PConnectionTimeout(45.0f),
		P2PDumpCounter(0.0),
		P2PDumpInterval(10.0),
		P2PCleanupTimeout(1.5),
		LastSocketError(0)
	{
	}