3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Split natives. Add proper disposal for natives.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-01 00:20:39 -04:00
Ursprung 284a2a67a2
Commit 22dd4bbb99
15 geänderte Dateien mit 56 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@ plugins {
dependencies {
compile 'com.google.code.gson:gson:2.8.5'
compile 'com.google.guava:guava:25.1-jre'
compile "com.google.guava:guava:${guavaVersion}"
compile 'net.kyori:text:1.12-1.6.0-SNAPSHOT'
compile 'com.moandjiezana.toml:toml4j:0.7.2'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"

Datei anzeigen

@ -14,6 +14,7 @@ allprojects {
junitVersion = '5.3.0-M1'
log4jVersion = '2.11.0'
nettyVersion = '4.1.28.Final'
guavaVersion = '25.1-jre'
}
repositories {

8
native/build.gradle Normale Datei
Datei anzeigen

@ -0,0 +1,8 @@
plugins {
id 'java'
}
dependencies {
compile "com.google.guava:guava:${guavaVersion}"
compile "io.netty:netty-buffer:${nettyVersion}"
}

Datei anzeigen

@ -1,9 +1,13 @@
package com.velocitypowered.proxy.util;
package com.velocitypowered.natives;
/**
* This marker interface indicates that this object should be explicitly disposed before the object can no longer be used.
* Not disposing these objects will likely leak native resources and eventually lead to resource exhaustion.
*/
public interface Disposable {
/**
* Disposes this object. After this call returns, any use of this object becomes invalid. Multiple calls to
* this function should be safe: there should be no side-effects once an object is disposed.
*/
void dispose();
}

Datei anzeigen

@ -1,4 +1,4 @@
package com.velocitypowered.proxy.protocol.compression;
package com.velocitypowered.natives.compression;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
@ -50,7 +50,6 @@ public class JavaVelocityCompressor implements VelocityCompressor {
@Override
public void dispose() {
ensureNotDisposed();
disposed = true;
}

Datei anzeigen

@ -1,6 +1,6 @@
package com.velocitypowered.proxy.protocol.compression;
package com.velocitypowered.natives.compression;
import com.velocitypowered.proxy.util.Disposable;
import com.velocitypowered.natives.Disposable;
import io.netty.buffer.ByteBuf;
import java.util.zip.DataFormatException;

Datei anzeigen

@ -1,4 +1,4 @@
package com.velocitypowered.proxy.protocol.encryption;
package com.velocitypowered.natives.encryption;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
@ -33,7 +33,6 @@ public class JavaVelocityCipher implements VelocityCipher {
@Override
public void dispose() {
ensureNotDisposed();
disposed = true;
}

Datei anzeigen

@ -1,6 +1,6 @@
package com.velocitypowered.proxy.protocol.encryption;
package com.velocitypowered.natives.encryption;
import com.velocitypowered.proxy.util.Disposable;
import com.velocitypowered.natives.Disposable;
import io.netty.buffer.ByteBuf;
import javax.crypto.ShortBufferException;

Datei anzeigen

@ -20,6 +20,7 @@ jar {
dependencies {
compile project(':velocity-api')
compile project(':velocity-native')
compile "io.netty:netty-codec:${nettyVersion}"
compile "io.netty:netty-codec-http:${nettyVersion}"
compile "io.netty:netty-handler:${nettyVersion}"

Datei anzeigen

@ -3,9 +3,9 @@ package com.velocitypowered.proxy.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.protocol.PacketWrapper;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.compression.JavaVelocityCompressor;
import com.velocitypowered.proxy.protocol.encryption.JavaVelocityCipher;
import com.velocitypowered.proxy.protocol.encryption.VelocityCipher;
import com.velocitypowered.natives.compression.JavaVelocityCompressor;
import com.velocitypowered.natives.encryption.JavaVelocityCipher;
import com.velocitypowered.natives.encryption.VelocityCipher;
import com.velocitypowered.proxy.protocol.netty.*;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;

Datei anzeigen

@ -1,7 +1,7 @@
package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.protocol.encryption.VelocityCipher;
import com.velocitypowered.natives.encryption.VelocityCipher;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
@ -26,4 +26,9 @@ public class MinecraftCipherDecoder extends ByteToMessageDecoder {
throw e;
}
}
@Override
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
cipher.dispose();
}
}

Datei anzeigen

@ -1,7 +1,7 @@
package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.protocol.encryption.VelocityCipher;
import com.velocitypowered.natives.encryption.VelocityCipher;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
@ -17,4 +17,9 @@ public class MinecraftCipherEncoder extends MessageToByteEncoder<ByteBuf> {
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
cipher.process(msg, out);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
cipher.dispose();
}
}

Datei anzeigen

@ -2,7 +2,7 @@ package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.compression.VelocityCompressor;
import com.velocitypowered.natives.compression.VelocityCompressor;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
@ -42,4 +42,9 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
throw e;
}
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
compressor.dispose();
}
}

Datei anzeigen

@ -1,9 +1,10 @@
package com.velocitypowered.proxy.protocol.netty;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.compression.VelocityCompressor;
import com.velocitypowered.natives.compression.VelocityCompressor;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.MessageToByteEncoder;
public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
@ -34,4 +35,9 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
compressedBuffer.release();
}
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
compressor.dispose();
}
}

Datei anzeigen

@ -1,6 +1,9 @@
rootProject.name = 'velocity'
include 'api'
include 'proxy'
include (
'api',
'proxy',
'native'
)
findProject(':api')?.name = 'velocity-api'
findProject(':proxy')?.name = 'velocity-proxy'
findProject(':native')?.name = 'velocity-native'