From 594253654a735dd626aa44dc8e2c13060bb5b7a3 Mon Sep 17 00:00:00 2001 From: Tobias G Date: Tue, 5 Mar 2024 00:20:49 +0100 Subject: [PATCH] more debugging --- .../proxytransport/ProxyTransport.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/nethergames/proxytransport/ProxyTransport.java b/src/main/java/org/nethergames/proxytransport/ProxyTransport.java index 793271e..c876f3d 100644 --- a/src/main/java/org/nethergames/proxytransport/ProxyTransport.java +++ b/src/main/java/org/nethergames/proxytransport/ProxyTransport.java @@ -3,12 +3,18 @@ import dev.waterdog.waterdogpe.network.protocol.ProtocolCodecs; import dev.waterdog.waterdogpe.plugin.Plugin; import io.netty.incubator.codec.quic.Quic; +import io.netty.util.internal.NativeLibraryLoader; import org.nethergames.proxytransport.integration.QuicTransportServerInfo; import org.nethergames.proxytransport.integration.TcpTransportServerInfo; import org.nethergames.proxytransport.utils.CodecUpdater; import org.scijava.nativelib.NativeLoader; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; public class ProxyTransport extends Plugin { @@ -27,7 +33,7 @@ public void onStartup() { getLogger().error(e); try{ - NativeLoader.loadLibrary("libnetty_quiche", "META-INF/native"); + loadLibrary(); getLogger().info("Post-loaded netty library"); }catch(IOException e1) { getLogger().error("Error while explicitly fallback loading linux quiche dependency", e1); @@ -53,6 +59,31 @@ public void logException(Thread t, Throwable e) { logException(t, ec); } } + + public static void loadLibrary() throws IOException { + // Create a temporary directory to extract the native library + Path tempDir = Files.createTempDirectory("native"); + + // Specify the name of the native library file + String libraryName = "libnetty_quiche_linux_x86_64.so"; + + // Get the input stream for the native library from the JAR file + try (InputStream inputStream = ProxyTransport.class.getResourceAsStream("/META-INF/native/" + libraryName)) { + if (inputStream == null) { + throw new FileNotFoundException("Native library not found in JAR: " + libraryName); + } + + // Write the native library to the temporary directory + Path targetPath = tempDir.resolve(libraryName); + Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING); + } + + // Set the java.library.path to include the temporary directory + System.setProperty("java.library.path", tempDir.toString()); + + // Load the native library + System.load(tempDir.resolve(libraryName).toString()); + } @Override public void onEnable() {