From 7fc14d8956157a735dcba939418b80ef3d1cb48a Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Fri, 31 Jul 2020 19:47:23 -0400 Subject: [PATCH] Add customizable MTU support (#1068) * Add customizable MTU support Fixes clients being unable to connect in rare instances. * Make config.yml nicer --- .../geysermc/platform/sponge/GeyserSpongeConfiguration.java | 5 +++++ .../main/java/org/geysermc/connector/GeyserConnector.java | 5 +++++ .../connector/configuration/GeyserConfiguration.java | 2 ++ .../connector/configuration/GeyserJacksonConfiguration.java | 3 +++ connector/src/main/resources/config.yml | 6 +++++- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 27c5432682a..279aca544a4 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -253,6 +253,11 @@ public String getUniqueId() { } } + @Override + public int getMtu() { + return node.getNode("mtu").getInt(1400); + } + @Override public int getConfigVersion() { return node.getNode("config-version").getInt(0); diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index ee687dbbdd2..6224dfcd5f5 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.nukkitx.network.raknet.RakNetConstants; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v407.Bedrock_v407; @@ -168,6 +169,10 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) { if (config.isAboveBedrockNetherBuilding()) DimensionUtils.changeBedrockNetherId(); // Apply End dimension ID workaround to Nether + // https://github.com/GeyserMC/Geyser/issues/957 + RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu(); + logger.debug("Setting MTU to " + config.getMtu()); + bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort())); bedrockServer.setHandler(new ConnectorServerEventHandler(this)); bedrockServer.bind().whenComplete((avoid, throwable) -> { diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index 57b4d7392b1..94322db9bce 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -118,6 +118,8 @@ interface IMetricsInfo { String getUniqueId(); } + int getMtu(); + int getConfigVersion(); static void checkGeyserConfiguration(GeyserConfiguration geyserConfig, GeyserLogger geyserLogger) { diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java index c31e9d2f51c..d6eaf934328 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java @@ -138,6 +138,9 @@ public static class MetricsInfo implements IMetricsInfo { private String uniqueId; } + @JsonProperty("mtu") + private int mtu = 1400; + @JsonProperty("config-version") private int configVersion; } diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index c587b21d97d..d8961270ec6 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -110,5 +110,9 @@ metrics: # UUID of server, don't change! uuid: generateduuid -# DO NOT TOUCH! +# ADVANCED OPTIONS - DO NOT TOUCH UNLESS YOU KNOW WHAT YOU ARE DOING! +# The internet supports a maximum MTU of 1492 but could cause issues with packet fragmentation. +# 1400 is the default. +# mtu: 1400 + config-version: 3