Reduce time needed for STUN
In my tests this reduced the time necessary for starting to host a game or joining a hosted game by ~180ms.
This commit is contained in:
parent
0efaf5ac4b
commit
8519eb9b86
@ -518,8 +518,13 @@ enabled = true ; The STUN protocol allows hosting games wi
|
||||
; If STUN is disabled, the game relies on direct connection, UPnP and port forwarding.
|
||||
server = "lobby.wildfiregames.com" ; Address of the STUN server.
|
||||
port = 3478 ; Port of the STUN server.
|
||||
delay = 200 ; Duration in milliseconds that is waited between STUN messages.
|
||||
; Smaller numbers speed up joins but also become less stable.
|
||||
delay = 10 ; Duration in milliseconds that is waited between checking for retrieved STUN responses.
|
||||
; Smaller numbers speed up joins but may make them less stable, if max_tries isn't increased proportionally as well.
|
||||
max_tries = 100 ; Maximum number of tries for receiving STUN responses.
|
||||
|
||||
[lobby.fw_punch]
|
||||
delay = 200 ; Duration in milliseconds between sending hole punching messages.
|
||||
num_msg = 3 ; Number of hole punching messages to send.
|
||||
|
||||
[mod]
|
||||
enabledmods = "mod public"
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* Copyright (C) 2013-2016 SuperTuxKart-Team.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
@ -183,12 +183,13 @@ bool ReceiveStunResponse(ENetHost& transactionHost, std::vector<u8>& buffer)
|
||||
ENetAddress sender = m_StunServer;
|
||||
int len = enet_socket_receive(transactionHost.socket, &sender, &enetBuffer, 1);
|
||||
|
||||
int delay = 200;
|
||||
int delay = 10;
|
||||
CFG_GET_VAL("lobby.stun.delay", delay);
|
||||
int maxTries = 100;
|
||||
CFG_GET_VAL("lobby.stun.max_tries", maxTries);
|
||||
|
||||
// Wait to receive the message because enet sockets are non-blocking
|
||||
const int max_tries = 5;
|
||||
for (int count = 0; len <= 0 && (count < max_tries || max_tries == -1); ++count)
|
||||
for (int count = 0; len <= 0 && (count < maxTries || maxTries == -1); ++count)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
||||
len = enet_socket_receive(transactionHost.socket, &sender, &enetBuffer, 1);
|
||||
@ -359,10 +360,12 @@ void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAdd
|
||||
enet_address_set_host(&addr, serverAddress.c_str());
|
||||
|
||||
int delay = 200;
|
||||
CFG_GET_VAL("lobby.stun.delay", delay);
|
||||
CFG_GET_VAL("lobby.fw_punch.delay", delay);
|
||||
int numMsg = 3;
|
||||
CFG_GET_VAL("lobby.fw_punch.num_msg", numMsg);
|
||||
|
||||
// Send an UDP message from enet host to ip:port
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int i = 0; i < numMsg || numMsg == -1; ++i)
|
||||
{
|
||||
SendStunRequest(enetClient, addr);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
||||
|
Loading…
Reference in New Issue
Block a user