diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java index 7a8dbda4..2e41b4c4 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java @@ -78,6 +78,22 @@ public interface ProxyConfig */ Collection 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 */ diff --git a/api/src/main/java/net/md_5/bungee/api/ServerConnectRequest.java b/api/src/main/java/net/md_5/bungee/api/ServerConnectRequest.java index ad2ebdea..cf81850a 100644 --- a/api/src/main/java/net/md_5/bungee/api/ServerConnectRequest.java +++ b/api/src/main/java/net/md_5/bungee/api/ServerConnectRequest.java @@ -73,6 +73,6 @@ public class ServerConnectRequest public static class Builder { - private int connectTimeout = 5000; // TODO: Configurable + private int connectTimeout = ProxyServer.getInstance().getConfig().getServerConnectTimeout(); } } diff --git a/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java b/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java index 3bae8064..aefe026e 100644 --- a/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java +++ b/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java @@ -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() { diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 0874544f..4bb0f68f 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -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 ); diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 82ba6afb..e1a6b2b3 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -55,6 +55,8 @@ public class Configuration implements ProxyConfig private int remotePingCache = -1; private int playerLimit = -1; private Collection 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 );