Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasGrether committed Mar 4, 2024
1 parent 531fce2 commit 5942536
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/org/nethergames/proxytransport/ProxyTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand All @@ -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() {
Expand Down

0 comments on commit 5942536

Please sign in to comment.