bAllowP2PPacketRelay

bAllowP2PPacketRelay

#Overview

name: bAllowP2PPacketRelay

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 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of bAllowP2PPacketRelay is to control whether Steam’s peer-to-peer (P2P) connections should fall back to using Steam servers as relays when direct connections between peers fail. This setting is primarily used in the networking and online subsystems of Unreal Engine, specifically for Steam-based multiplayer functionality.

The Unreal Engine subsystems that rely on this setting variable are:

  1. OnlineSubsystemSteam
  2. SocketSubsystemSteam
  3. SteamSockets plugin

The value of this variable is set in the configuration file, typically in the “DefaultEngine.ini” file under the [OnlineSubsystemSteam] section. It is read using the GConfig->GetBool() function in multiple places throughout the code.

This variable interacts with other networking-related variables, such as:

Developers must be aware of the following when using this variable:

  1. It affects the behavior of P2P connections in Steam-based multiplayer games.
  2. Enabling this option can improve connection reliability but may introduce additional latency.
  3. It’s important to consider the trade-offs between connection reliability and performance when setting this value.

Best practices when using this variable include:

  1. Carefully consider the needs of your game’s networking requirements before enabling or disabling this feature.
  2. Test your game’s multiplayer functionality thoroughly with both settings to determine the optimal configuration.
  3. Document the chosen setting and the reasoning behind it for future reference and team communication.
  4. Monitor the impact of this setting on your game’s performance and player experience in real-world scenarios.
  5. Consider providing an in-game option for players to toggle this setting if it significantly affects their experience.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:2249, 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/OnlineSessionAsyncServerSteam.cpp:172

Scope (from outer to inner):

file
function     void GetServerKeyValuePairsFromSessionInfo

Source code excerpt:

		bool bUseRelays = false;
		bool bIsDefaultSubsystem = false;
		GConfig->GetBool(TEXT("OnlineSubsystemSteam"), TEXT("bAllowP2PPacketRelay"), bUseRelays, GEngineIni);
		// If this config specifically does not exist, then set it to true
		if (!GConfig->GetBool(TEXT("OnlineSubsystemSteam"), TEXT("bUseSteamNetworking"), bIsDefaultSubsystem, GEngineIni))
		{
			bIsDefaultSubsystem = true;
		}

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

Scope (from outer to inner):

file
function     bool FSocketSubsystemSteam::Init

Source code excerpt:

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

		if (!GConfig->GetFloat(TEXT("OnlineSubsystemSteam"), TEXT("P2PConnectionTimeout"), P2PConnectionTimeout, GEngineIni))
		{

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

Scope (from outer to inner):

file
function     bool FSocketSubsystemSteam::Init

Source code excerpt:

	if (SteamNetworking())
	{
		SteamNetworking()->AllowP2PPacketRelay(bAllowP2PPacketRelay);
	}

	if (SteamGameServerNetworking())
	{
		SteamGameServerNetworking()->AllowP2PPacketRelay(bAllowP2PPacketRelay);
	}

	return true;
}

/**

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

Scope (from outer to inner):

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

Source code excerpt:

	/**
	 * Should Steam P2P sockets all fall back to Steam servers relay if a direct connection fails
	 * read from [OnlineSubsystemSteam.bAllowP2PPacketRelay]
	 */
	bool bAllowP2PPacketRelay;
	/** 
     * 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 */

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

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)
	{

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemSteam/Source/Public/OnlinePingInterfaceSteam.h:24

Scope (from outer to inner):

file
function     class ONLINESUBSYSTEMSTEAM_API FOnlinePingInterfaceSteam { public: FOnlinePingInterfaceSteam

Source code excerpt:

	 * for communication.
	 *
	 * Uses OnlineSubsystemSteam.bAllowP2PPacketRelay
	 *
	 * @return true if relays are enabled for P2P connections.
	 */
	virtual bool IsUsingP2PRelays() const = 0;

	/**
	 * Returns the P2P relay ping information for the current machine. This information can be
	 * serialized over the network and used to calculate the ping data between a client and a host.
	 *
	 * @return relay information blob stored as a string for relaying over the network. 
	 *         If an error occurred, the return is an empty string.
	 */
	virtual FString GetHostPingData() const = 0;

#Loc: <Workspace>/Engine/Plugins/Runtime/Steam/SteamSockets/Source/SteamSockets/Private/SteamSocketsSubsystem.cpp:85

Scope (from outer to inner):

file
function     bool FSteamSocketsSubsystem::Init

Source code excerpt:

	if (GConfig)
	{
		if (!GConfig->GetBool(TEXT("OnlineSubsystemSteam"), TEXT("bAllowP2PPacketRelay"), bUseRelays, GEngineIni))
		{
			UE_CLOG(bIsDedicated, LogSockets, Warning, TEXT("SteamSockets: Missing config value for bAllowP2PPacketRelay, will be unable to determine ping functionality"));
		}
	}

	// Debug commandline support for socket relays.