From bb69481f990594ebb996c23a979dce27e89a1f4f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 4 Jun 2020 14:56:17 -0400 Subject: [PATCH] Lay down foundation for cross-architecture natives We have dropped the rarely used kqueue and replaced it with the new Netty aarch64 native. In addition, lay down the foundation for other aarch64 natives. --- native/compile-linux.sh | 6 ++++-- .../velocitypowered/natives/util/Natives.java | 15 +++++++++++---- .../velocity-compress.so | Bin proxy/build.gradle | 3 +-- .../proxy/network/TransportType.java | 13 +------------ 5 files changed, 17 insertions(+), 20 deletions(-) rename native/src/main/resources/{linux_x64 => linux_x86_64}/velocity-compress.so (100%) diff --git a/native/compile-linux.sh b/native/compile-linux.sh index 78072b00b..db7227d06 100755 --- a/native/compile-linux.sh +++ b/native/compile-linux.sh @@ -13,8 +13,10 @@ cd .. # Modify as you need. MBEDTLS_ROOT=mbedtls CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared -Wl,-z,noexecstack" +ARCH=$(uname -m) +mkdir -p src/main/resources/linux_$ARCH gcc $CFLAGS -Ilibdeflate src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ - libdeflate/libdeflate.a -o src/main/resources/linux_x64/velocity-compress.so + libdeflate/libdeflate.a -o src/main/resources/linux_$ARCH/velocity-compress.so gcc $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \ $MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \ - -o src/main/resources/linux_x64/velocity-cipher.so + -o src/main/resources/linux_$ARCH/velocity-cipher.so \ No newline at end of file diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index 702929a90..4a9d428df 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -63,8 +63,12 @@ public class Natives { public static final NativeCodeLoader compress = new NativeCodeLoader<>( ImmutableList.of( new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, - copyAndLoadNative("/linux_x64/velocity-compress.so"), - "libdeflate (Linux amd64)", + copyAndLoadNative("/linux_x86_64/velocity-compress.so"), + "libdeflate (Linux x86_64)", + LibdeflateVelocityCompressor.FACTORY), + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + copyAndLoadNative("/linux_aarch64/velocity-compress.so"), + "libdeflate (Linux aarch64)", LibdeflateVelocityCompressor.FACTORY), new NativeCodeLoader.Variant<>(NativeConstraints.JAVA_11, () -> { }, "Java 11", () -> Java11VelocityCompressor.FACTORY), @@ -76,8 +80,11 @@ public class Natives { public static final NativeCodeLoader cipher = new NativeCodeLoader<>( ImmutableList.of( new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, - copyAndLoadNative("/linux_x64/velocity-cipher.so"), "mbed TLS (Linux amd64)", - NativeVelocityCipher.FACTORY), + copyAndLoadNative("/linux_x86_64/velocity-cipher.so"), + "mbed TLS (Linux x86_64)", NativeVelocityCipher.FACTORY), + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + copyAndLoadNative("/linux_aarch64/velocity-cipher.so"), + "mbed TLS (Linux aarch64)", NativeVelocityCipher.FACTORY), new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> { }, "Java", JavaVelocityCipher.FACTORY) ) diff --git a/native/src/main/resources/linux_x64/velocity-compress.so b/native/src/main/resources/linux_x86_64/velocity-compress.so similarity index 100% rename from native/src/main/resources/linux_x64/velocity-compress.so rename to native/src/main/resources/linux_x86_64/velocity-compress.so diff --git a/proxy/build.gradle b/proxy/build.gradle index 5498db10b..bcf3daea5 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -48,8 +48,7 @@ dependencies { compile "io.netty:netty-handler:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" - compile "io.netty:netty-transport-native-kqueue:${nettyVersion}" - compile "io.netty:netty-transport-native-kqueue:${nettyVersion}:osx-x86_64" + compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-aarch64" compile "io.netty:netty-resolver-dns:${nettyVersion}" compile "org.apache.logging.log4j:log4j-api:${log4jVersion}" diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java index 0edff72c0..b5829f375 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java @@ -7,11 +7,6 @@ import io.netty.channel.epoll.EpollDatagramChannel; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.epoll.EpollSocketChannel; -import io.netty.channel.kqueue.KQueue; -import io.netty.channel.kqueue.KQueueDatagramChannel; -import io.netty.channel.kqueue.KQueueEventLoopGroup; -import io.netty.channel.kqueue.KQueueServerSocketChannel; -import io.netty.channel.kqueue.KQueueSocketChannel; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.ServerSocketChannel; @@ -27,11 +22,7 @@ enum TransportType { (name, type) -> new NioEventLoopGroup(0, createThreadFactory(name, type))), EPOLL("epoll", EpollServerSocketChannel.class, EpollSocketChannel.class, EpollDatagramChannel.class, - (name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type))), - KQUEUE("Kqueue", KQueueServerSocketChannel.class, KQueueSocketChannel.class, - KQueueDatagramChannel.class, - (name, type) -> new KQueueEventLoopGroup(0, createThreadFactory(name, type))); - + (name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type))); final String name; final Class serverSocketChannelClass; @@ -71,8 +62,6 @@ enum TransportType { if (Epoll.isAvailable()) { return EPOLL; - } else if (KQueue.isAvailable()) { - return KQUEUE; } else { return NIO; }