diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 57c0b765f2..118ff7bc0e 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -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" diff --git a/source/network/StunClient.cpp b/source/network/StunClient.cpp index e79524648f..180e3dd7db 100644 --- a/source/network/StunClient.cpp +++ b/source/network/StunClient.cpp @@ -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& 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));