#2752: Configurable connect and ping timeouts

This commit is contained in:
Mystiflow 2020-01-25 11:11:30 +11:00 committed by md_5
parent 70370faf5d
commit 0a4b9b4984
5 changed files with 23 additions and 11 deletions

View File

@ -78,6 +78,22 @@ public interface ProxyConfig
*/
Collection<String> getDisabledCommands();
/**
* Time in milliseconds before timing out a clients request to connect to a
* server.
*
* @return connect timeout
*/
int getServerConnectTimeout();
/**
* Time in milliseconds before timing out a ping request from the proxy to a
* server when attempting to request server list info.
*
* @return ping timeout
*/
int getRemotePingTimeout();
/**
* The connection throttle delay.
*
@ -87,7 +103,7 @@ public interface ProxyConfig
int getThrottle();
/**
* Whether the proxy will parse IPs with spigot or not
* Whether the proxy will parse IPs with spigot or not.
*
* @return ip forward
*/

View File

@ -73,6 +73,6 @@ public class ServerConnectRequest
public static class Builder
{
private int connectTimeout = 5000; // TODO: Configurable
private int connectTimeout = ProxyServer.getInstance().getConfig().getServerConnectTimeout();
}
}

View File

@ -6,7 +6,6 @@ import java.util.Collection;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ServerConnectEvent;
import org.junit.Assert;
import org.junit.Test;
public class ServerConnectRequestTest
@ -79,13 +78,6 @@ public class ServerConnectRequestTest
}
};
@Test
public void testDefaultConnectTimeout()
{
ServerConnectRequest request = ServerConnectRequest.builder().target( DUMMY_INFO ).reason( ServerConnectEvent.Reason.JOIN_PROXY ).build();
Assert.assertEquals( 5000, request.getConnectTimeout() );
}
@Test(expected = NullPointerException.class)
public void testNullTarget()
{

View File

@ -183,7 +183,7 @@ public class BungeeServerInfo implements ServerInfo
.channel( PipelineUtils.getChannel( socketAddress ) )
.group( BungeeCord.getInstance().eventLoops )
.handler( PipelineUtils.BASE )
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, BungeeCord.getInstance().getConfig().getRemotePingTimeout() )
.remoteAddress( socketAddress )
.connect()
.addListener( listener );

View File

@ -55,6 +55,8 @@ public class Configuration implements ProxyConfig
private int remotePingCache = -1;
private int playerLimit = -1;
private Collection<String> disabledCommands;
private int serverConnectTimeout = 5000;
private int remotePingTimeout = 5000;
private int throttle = 4000;
private int throttleLimit = 3;
private boolean ipForward;
@ -88,6 +90,8 @@ public class Configuration implements ProxyConfig
logPings = adapter.getBoolean( "log_pings", logPings );
remotePingCache = adapter.getInt( "remote_ping_cache", remotePingCache );
playerLimit = adapter.getInt( "player_limit", playerLimit );
serverConnectTimeout = adapter.getInt( "server_connect_timeout", serverConnectTimeout );
remotePingTimeout = adapter.getInt( "remote_ping_timeout", remotePingTimeout );
throttle = adapter.getInt( "connection_throttle", throttle );
throttleLimit = adapter.getInt( "connection_throttle_limit", throttleLimit );
ipForward = adapter.getBoolean( "ip_forward", ipForward );