mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-29 04:28:21 +01:00
No volatile read for compression/encryption
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
f07ab21d3e
commit
236683c986
@ -52,8 +52,8 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
private final SocketChannel channel;
|
private final SocketChannel channel;
|
||||||
private SocketAddress remoteAddress;
|
private SocketAddress remoteAddress;
|
||||||
|
|
||||||
private volatile boolean encrypted = false;
|
private boolean encrypted = false;
|
||||||
private volatile boolean compressed = false;
|
private boolean compressed = false;
|
||||||
|
|
||||||
//Could be null. Only used for Mojang Auth
|
//Could be null. Only used for Mojang Auth
|
||||||
private byte[] nonce = new byte[4];
|
private byte[] nonce = new byte[4];
|
||||||
@ -174,9 +174,11 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
*/
|
*/
|
||||||
public void setEncryptionKey(@NotNull SecretKey secretKey) {
|
public void setEncryptionKey(@NotNull SecretKey secretKey) {
|
||||||
Check.stateCondition(encrypted, "Encryption is already enabled!");
|
Check.stateCondition(encrypted, "Encryption is already enabled!");
|
||||||
this.decryptCipher = MojangCrypt.getCipher(2, secretKey);
|
synchronized (bufferLock) {
|
||||||
this.encryptCipher = MojangCrypt.getCipher(1, secretKey);
|
this.decryptCipher = MojangCrypt.getCipher(2, secretKey);
|
||||||
this.encrypted = true;
|
this.encryptCipher = MojangCrypt.getCipher(1, secretKey);
|
||||||
|
this.encrypted = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,7 +191,9 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
final int threshold = MinecraftServer.getCompressionThreshold();
|
final int threshold = MinecraftServer.getCompressionThreshold();
|
||||||
Check.stateCondition(threshold == 0, "Compression cannot be enabled because the threshold is equal to 0");
|
Check.stateCondition(threshold == 0, "Compression cannot be enabled because the threshold is equal to 0");
|
||||||
writeAndFlush(new SetCompressionPacket(threshold));
|
writeAndFlush(new SetCompressionPacket(threshold));
|
||||||
this.compressed = true;
|
synchronized (bufferLock) {
|
||||||
|
this.compressed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user