Skip to content

Commit adae9da

Browse files
committed
- add ip preference mode (dpm) CLI arg
1 parent 00ce4be commit adae9da

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
- **FEATURE:** Fehlerhafte Downloads werden nun automatisch aus der Gesehen Datenbank entfernt.
3333
- **FEATURE(Windows/Linux):** Darkmode Button wird ab Windows 10 und unter Linux in der Menüzeile neben den window controls angezeigt.
3434
- **FEATURE(Windows/Linux):** Tab-Labels werden nun korrekt rotiert wenn die Tab-Position nicht oben ist.
35-
-
35+
- **FEATURE:** Der bevorzugte DNS-IP-Auflösungsmodus kann nun via `-dpm <XXX>` oder `--dns-preference-mode <XXX>` geändert werden. Zulässige Werte sind `system`, `ip_v6`, `ip_v4`, `ip_v6_only`, `ip_v4_only` (Standardwert). Eine Änderung kann bei IPv6-only Internetanschlüssen notwendig sein.
36+
37+
3638
# **14.0.0**
3739
- **ACHTUNG: macOS Sonoma 14.1 verursacht diverse Probleme und Programmhänger! Einige dieser Probleme konnten beseitigt werden, führen aber zu kleineren Einschränkungen.**
3840
- macOS: Speicherverbrauchsanzeige wurde deaktiviert. Sie verursacht bisher unbekannte Programmanomalien unter macOS Sonoma 14.1

src/main/java/mediathek/Main.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import mediathek.mainwindow.MediathekGui;
1414
import mediathek.tool.*;
1515
import mediathek.tool.affinity.Affinity;
16+
import mediathek.tool.dns.IPvPreferenceMode;
1617
import mediathek.tool.migrator.SettingsMigrator;
1718
import mediathek.windows.MediathekGuiWindows;
1819
import mediathek.x11.MediathekGuiX11;
@@ -364,6 +365,20 @@ private static void checkUiScaleSetting() {
364365
}
365366
}
366367

368+
private static void configureDnsPreferenceMode(CommandLine.ParseResult parseResult) {
369+
var config = ApplicationConfiguration.getConfiguration();
370+
if (parseResult.hasMatchedOption("dpm")) {
371+
logger.trace("Dns preference mode set via CLI, storing config value");
372+
config.setProperty(ApplicationConfiguration.APPLICATION_NETWORKING_DNS_MODE, String.valueOf(Config.getDnsIpPreferenceMode()));
373+
}
374+
else {
375+
logger.trace("Dns preference mode NOT set, using config setting");
376+
var mode = IPvPreferenceMode.fromString(config.getString(ApplicationConfiguration.APPLICATION_NETWORKING_DNS_MODE, String.valueOf(Config.getDnsIpPreferenceMode())));
377+
Config.setDnsIpPreferenceMode(mode);
378+
}
379+
logger.trace("Setting DNS selector to mode: {}", Config.getDnsIpPreferenceMode().toString());
380+
}
381+
367382
/**
368383
* @param args the command line arguments
369384
*/
@@ -393,6 +408,8 @@ public static void main(final String... args) {
393408
setupLogging();
394409
printPortableModeInfo();
395410

411+
configureDnsPreferenceMode(parseResult);
412+
396413
if (SystemUtils.IS_OS_LINUX) {
397414
// enable custom window decorations
398415
JFrame.setDefaultLookAndFeelDecorated( true );

src/main/java/mediathek/config/Config.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
*/
2020
package mediathek.config;
2121

22+
import mediathek.tool.dns.IPvPreferenceMode;
2223
import picocli.CommandLine;
2324

2425
@CommandLine.Command(name = "MediathekView")
2526
public class Config {
26-
2727
@CommandLine.Parameters(index = "0", paramLabel = "<Pfad zum Verzeichnis>", description = "Pfad zum Einstellungsverzeichnis für Portablen Betrieb", arity = "0..1")
2828
public static String baseFilePath;
29+
/**
30+
* Specify the preferred DNS IP mode for name resolutions. Defaults to IPv4 only.
31+
*/
32+
@CommandLine.Option(names = {"-dpm", "--dns-preference-mode"}, description = "Bevorzugtes IP-Protokoll für DNS festlegen")
33+
private static IPvPreferenceMode dnsIpPreferenceMode = IPvPreferenceMode.IPV4_ONLY;
2934
@CommandLine.Option(names = {"-d", "--debug"}, hidden = true, description = "Debug-Modus aktivieren (FÜR ENTWICKLER)")
3035
private static boolean debug; // Debugmodus
3136
/**
@@ -52,7 +57,6 @@ public class Config {
5257
private static boolean portableMode;
5358
@CommandLine.Option(names = {"-m", "--maximized"}, description = "Programmfenster beim Start maximieren")
5459
private static boolean startMaximized; // Fenster maximieren
55-
5660
@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "Hilfe anzeigen")
5761
private static boolean helpRequested;
5862
@CommandLine.Option(names = {"-f", "--disable-file-logging"}, description = "Speichern des Log output in Datei deaktivieren")
@@ -62,13 +66,19 @@ public class Config {
6266
*/
6367
@CommandLine.Option(names = {"-nj", "--no-jvm-param-checks"}, description = "JVM Parameter-Prüfung deaktivieren")
6468
private static boolean disableJvmParameterChecks;
65-
6669
@CommandLine.Option(names = {"-ns", "--no-splash"}, description = "Splash-Screen nicht anzeigen")
6770
private static boolean disableSplashScreen;
68-
6971
@CommandLine.Option(names = {"-dq", "--download-quit"}, description = "Automatisch downloaden, dann beenden")
7072
private static boolean downloadAndQuit;
7173

74+
public static IPvPreferenceMode getDnsIpPreferenceMode() {
75+
return dnsIpPreferenceMode;
76+
}
77+
78+
public static void setDnsIpPreferenceMode(IPvPreferenceMode dnsIpPreferenceMode) {
79+
Config.dnsIpPreferenceMode = dnsIpPreferenceMode;
80+
}
81+
7282
public static boolean shouldDownloadAndQuit() { return downloadAndQuit;}
7383
public static boolean isSplashScreenDisabled() { return disableSplashScreen;}
7484

src/main/java/mediathek/tool/http/MVHttpClient.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import mediathek.config.Config;
44
import mediathek.tool.ApplicationConfiguration;
55
import mediathek.tool.dns.DnsSelector;
6-
import mediathek.tool.dns.IPvPreferenceMode;
76
import okhttp3.Authenticator;
87
import okhttp3.ConnectionSpec;
98
import okhttp3.OkHttpClient;
@@ -22,6 +21,7 @@ public class MVHttpClient {
2221
private static final MVHttpClient ourInstance = new MVHttpClient();
2322
private final Logger logger = LogManager.getLogger(MVHttpClient.class);
2423
private final ByteCounter byteCounter = new ByteCounter();
24+
private final DnsSelector dnsSelector = new DnsSelector();
2525
private OkHttpClient httpClient;
2626

2727
private MVHttpClient() {
@@ -84,17 +84,13 @@ private OkHttpClient.Builder getDefaultClientBuilder() {
8484
builder.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));
8585
}
8686

87-
var config = ApplicationConfiguration.getConfiguration();
88-
IPvPreferenceMode mode = IPvPreferenceMode.fromString(config.getString(ApplicationConfiguration.APPLICATION_NETWORKING_DNS_MODE, String.valueOf(IPvPreferenceMode.IPV4_ONLY)));
89-
logger.trace("Setting DNS selector to mode: {}", mode.toString());
90-
9187
builder.connectTimeout(5, TimeUnit.SECONDS)
9288
.writeTimeout(5, TimeUnit.SECONDS)
9389
.readTimeout(2, TimeUnit.SECONDS)
9490
.socketFactory(byteCounter.socketFactory())
9591
.followRedirects(true)
9692
.followSslRedirects(true)
97-
.dns(new DnsSelector(mode));
93+
.dns(dnsSelector);
9894
return builder;
9995
}
10096

src/main/kotlin/mediathek/tool/dns/DnsSelector.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package mediathek.tool.dns
22

3+
import mediathek.config.Config
34
import okhttp3.Dns
45
import org.apache.logging.log4j.LogManager
56
import java.net.Inet4Address
67
import java.net.Inet6Address
78
import java.net.InetAddress
89

9-
class DnsSelector(private val preferenceMode: IPvPreferenceMode) : Dns {
10+
class DnsSelector : Dns {
1011
/**
1112
* return IP adresses based on preferred mode.
1213
*/
1314
override fun lookup(hostname: String): List<InetAddress> {
1415
var addresses = Dns.SYSTEM.lookup(hostname)
1516

16-
addresses = when (preferenceMode) {
17+
addresses = when (Config.getDnsIpPreferenceMode()) {
1718
IPvPreferenceMode.IPV6_FIRST -> addresses.sortedBy { Inet4Address::class.java.isInstance(it) }
1819
IPvPreferenceMode.IPV4_FIRST -> addresses.sortedBy { Inet6Address::class.java.isInstance(it) }
1920
IPvPreferenceMode.IPV6_ONLY -> addresses.filter { Inet6Address::class.java.isInstance(it) }
2021
IPvPreferenceMode.IPV4_ONLY -> addresses.filter { Inet4Address::class.java.isInstance(it) }
2122
IPvPreferenceMode.SYSTEM -> addresses
23+
else -> {
24+
logger.error("IP Preference Mode was null, returning SYSTEM adresses")
25+
addresses
26+
}
2227
}
2328

2429
logger.trace("Dns ($hostname): " + addresses.joinToString(", ") { it.toString() })

0 commit comments

Comments
 (0)