Skip to content

Commit

Permalink
Add DNS resolving information which is useful for debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Apr 7, 2023
1 parent 2cfb4a8 commit 3896031
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/net/minecraftforge/installer/DownloadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.net.ssl.SSLHandshakeException;

import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.json.Artifact;
Expand Down Expand Up @@ -229,9 +236,16 @@ private static URLConnection getConnection(String address) {
return null;
}

URL url = null;
try {
url = new URL(address);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}

try {
int MAX = 3;
URL url = new URL(address);
URLConnection connection = null;
for (int x = 0; x < MAX; x++) { //Maximum of 3 redirects.
connection = url.openConnection();
Expand Down Expand Up @@ -259,12 +273,28 @@ private static URLConnection getConnection(String address) {
}
}
return connection;
} catch (SSLHandshakeException e) {
System.out.println("Failed to establish connection to " + address);
String host = url.getHost();
System.out.println(" Host: " + host + " [" + getIps(host).stream().collect(Collectors.joining(", ")) + "]");
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

public static List<String> getIps(String host) {
try {
InetAddress[] addresses = InetAddress.getAllByName(host);
return Arrays.stream(addresses).map(InetAddress::getHostAddress).collect(Collectors.toList());
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
return null;
}

public static boolean downloadFileEtag(File target, String url) {
try {
URLConnection connection = getConnection(url);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/minecraftforge/installer/SimpleInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import java.io.PrintStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
Expand Down Expand Up @@ -70,6 +73,7 @@ public static void main(String[] args) throws IOException, URISyntaxException
String jvmVersion = System.getProperty("java.vm.version", "missing jvm version");
monitor.message(String.format("JVM info: %s - %s - %s", vendor, javaVersion, jvmVersion));
monitor.message("java.net.preferIPv4Stack=" + System.getProperty("java.net.preferIPv4Stack"));
monitor.message("Current Time: " + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()));

File installer = new File(SimpleInstaller.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if (installer.getAbsolutePath().contains("!/"))
Expand Down Expand Up @@ -105,6 +109,16 @@ public static void main(String[] args) throws IOException, URISyntaxException
}
else
{
for(String host : new String[] {
"files.minecraftforge.net",
"maven.minecraftforge.net",
"libraries.minecraft.net",
"launchermeta.mojang.com",
"piston-meta.mojang.com",
"authserver.mojang.com",
}) {
monitor.message("Host: " + host + " [" + DownloadUtils.getIps(host).stream().collect(Collectors.joining(", ")) + "]");
}
FixSSL.fixup(monitor);
}

Expand Down

0 comments on commit 3896031

Please sign in to comment.