13
0
geforkt von Mirrors/Velocity

Help smoke out some internal concurrency issues

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-08 21:28:18 -04:00
Ursprung 2671590ad2
Commit 40c8343494

Datei anzeigen

@ -155,6 +155,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
} }
} }
private void ensureInEventLoop() {
Preconditions.checkState(this.channel.eventLoop().inEventLoop(), "Not in event loop");
}
public EventLoop eventLoop() { public EventLoop eventLoop() {
return channel.eventLoop(); return channel.eventLoop();
} }
@ -233,6 +237,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
* @param autoReading whether or not we should read data automatically * @param autoReading whether or not we should read data automatically
*/ */
public void setAutoReading(boolean autoReading) { public void setAutoReading(boolean autoReading) {
ensureInEventLoop();
channel.config().setAutoRead(autoReading); channel.config().setAutoRead(autoReading);
if (autoReading) { if (autoReading) {
// For some reason, the channel may not completely read its queued contents once autoread // For some reason, the channel may not completely read its queued contents once autoread
@ -249,6 +255,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
* @param state the new state * @param state the new state
*/ */
public void setState(StateRegistry state) { public void setState(StateRegistry state) {
ensureInEventLoop();
this.state = state; this.state = state;
this.channel.pipeline().get(MinecraftEncoder.class).setState(state); this.channel.pipeline().get(MinecraftEncoder.class).setState(state);
this.channel.pipeline().get(MinecraftDecoder.class).setState(state); this.channel.pipeline().get(MinecraftDecoder.class).setState(state);
@ -263,6 +271,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
* @param protocolVersion the protocol version to use * @param protocolVersion the protocol version to use
*/ */
public void setProtocolVersion(ProtocolVersion protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
ensureInEventLoop();
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.nextProtocolVersion = protocolVersion; this.nextProtocolVersion = protocolVersion;
if (protocolVersion != ProtocolVersion.LEGACY) { if (protocolVersion != ProtocolVersion.LEGACY) {
@ -284,6 +294,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
* @param sessionHandler the handler to use * @param sessionHandler the handler to use
*/ */
public void setSessionHandler(MinecraftSessionHandler sessionHandler) { public void setSessionHandler(MinecraftSessionHandler sessionHandler) {
ensureInEventLoop();
if (this.sessionHandler != null) { if (this.sessionHandler != null) {
this.sessionHandler.deactivated(); this.sessionHandler.deactivated();
} }
@ -302,6 +314,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
*/ */
public void setCompressionThreshold(int threshold) { public void setCompressionThreshold(int threshold) {
ensureOpen(); ensureOpen();
ensureInEventLoop();
if (threshold == -1) { if (threshold == -1) {
channel.pipeline().remove(COMPRESSION_DECODER); channel.pipeline().remove(COMPRESSION_DECODER);
@ -325,6 +338,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
*/ */
public void enableEncryption(byte[] secret) throws GeneralSecurityException { public void enableEncryption(byte[] secret) throws GeneralSecurityException {
ensureOpen(); ensureOpen();
ensureInEventLoop();
SecretKey key = new SecretKeySpec(secret, "AES"); SecretKey key = new SecretKeySpec(secret, "AES");
@ -342,6 +356,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
} }
public void setAssociation(MinecraftConnectionAssociation association) { public void setAssociation(MinecraftConnectionAssociation association) {
ensureInEventLoop();
this.association = association; this.association = association;
} }