3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Allow tweaking compression.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-03 16:56:19 -04:00
Ursprung 0191b74840
Commit 68ded7ca7f
3 geänderte Dateien mit 35 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -29,12 +29,15 @@ public class VelocityConfiguration {
private final IPForwardingMode ipForwardingMode; private final IPForwardingMode ipForwardingMode;
private final Map<String, String> servers; private final Map<String, String> servers;
private final List<String> attemptConnectionOrder; private final List<String> attemptConnectionOrder;
private final int compressionThreshold;
private final int compressionLevel;
private Component motdAsComponent; private Component motdAsComponent;
private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode, private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode,
IPForwardingMode ipForwardingMode, Map<String, String> servers, IPForwardingMode ipForwardingMode, Map<String, String> servers,
List<String> attemptConnectionOrder) { List<String> attemptConnectionOrder, int compressionThreshold,
int compressionLevel) {
this.bind = bind; this.bind = bind;
this.motd = motd; this.motd = motd;
this.showMaxPlayers = showMaxPlayers; this.showMaxPlayers = showMaxPlayers;
@ -42,6 +45,8 @@ public class VelocityConfiguration {
this.ipForwardingMode = ipForwardingMode; this.ipForwardingMode = ipForwardingMode;
this.servers = servers; this.servers = servers;
this.attemptConnectionOrder = attemptConnectionOrder; this.attemptConnectionOrder = attemptConnectionOrder;
this.compressionThreshold = compressionThreshold;
this.compressionLevel = compressionLevel;
} }
public boolean validate() { public boolean validate() {
@ -102,6 +107,18 @@ public class VelocityConfiguration {
valid = false; valid = false;
} }
if (compressionLevel < -1 || compressionLevel > 9) {
logger.error("Invalid compression level {}", compressionLevel);
} else if (compressionLevel == 0) {
logger.warn("ALL packets going through the proxy are going to be uncompressed. This will increase bandwidth usage.");
}
if (compressionThreshold < -1) {
logger.error("Invalid compression threshold {}", compressionLevel);
} else if (compressionThreshold == 0) {
logger.warn("ALL packets going through the proxy are going to be compressed. This may hurt performance.");
}
return valid; return valid;
} }
@ -144,6 +161,14 @@ public class VelocityConfiguration {
return attemptConnectionOrder; return attemptConnectionOrder;
} }
public int getCompressionThreshold() {
return compressionThreshold;
}
public int getCompressionLevel() {
return compressionLevel;
}
@Override @Override
public String toString() { public String toString() {
return "VelocityConfiguration{" + return "VelocityConfiguration{" +
@ -179,7 +204,9 @@ public class VelocityConfiguration {
toml.getBoolean("online-mode"), toml.getBoolean("online-mode"),
IPForwardingMode.valueOf(toml.getString("ip-forwarding").toUpperCase()), IPForwardingMode.valueOf(toml.getString("ip-forwarding").toUpperCase()),
ImmutableMap.copyOf(servers), ImmutableMap.copyOf(servers),
toml.getTable("servers").getList("try")); toml.getTable("servers").getList("try"),
toml.getTable("advanced").getLong("compression-threshold", 1024L).intValue(),
toml.getTable("advanced").getLong("compression-level", -1L).intValue());
} }
} }
} }

Datei anzeigen

@ -3,6 +3,7 @@ package com.velocitypowered.proxy.connection;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.natives.compression.VelocityCompressor; import com.velocitypowered.natives.compression.VelocityCompressor;
import com.velocitypowered.natives.util.Natives; import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.PacketWrapper; import com.velocitypowered.proxy.protocol.PacketWrapper;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.natives.encryption.JavaVelocityCipher; import com.velocitypowered.natives.encryption.JavaVelocityCipher;
@ -20,7 +21,6 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.zip.Deflater;
import static com.velocitypowered.network.Connections.CIPHER_DECODER; import static com.velocitypowered.network.Connections.CIPHER_DECODER;
import static com.velocitypowered.network.Connections.CIPHER_ENCODER; import static com.velocitypowered.network.Connections.CIPHER_ENCODER;
@ -193,7 +193,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
return; return;
} }
VelocityCompressor compressor = Natives.compressor.get().create(Deflater.DEFAULT_COMPRESSION); int level = VelocityServer.getServer().getConfiguration().getCompressionLevel();
VelocityCompressor compressor = Natives.compressor.get().create(level);
MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor); MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor);
MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor); MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor);

Datei anzeigen

@ -125,8 +125,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
return; return;
} }
inbound.write(new SetCompression(256)); int threshold = VelocityServer.getServer().getConfiguration().getCompressionThreshold();
inbound.setCompressionThreshold(256); inbound.write(new SetCompression(threshold));
inbound.setCompressionThreshold(threshold);
ServerLoginSuccess success = new ServerLoginSuccess(); ServerLoginSuccess success = new ServerLoginSuccess();
success.setUsername(profile.getName()); success.setUsername(profile.getName());