Changeset 8296 in josm


Ignore:
Timestamp:
2015-04-30T22:53:20+02:00 (9 years ago)
Author:
stoecker
Message:

see #8562 - move IPv6 detection to main class instead of preferences

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r8295 r8296  
    1717import java.lang.annotation.RetentionPolicy;
    1818import java.lang.reflect.Field;
    19 import java.net.InetAddress;
    20 import java.net.Inet6Address;
    2119import java.nio.charset.StandardCharsets;
    2220import java.nio.file.Files;
     
    927925            }
    928926        }
    929         if("auto".equals(get("prefer.ipv6", "auto"))) {
    930              new Thread(new Runnable() { /* this may take some time (DNS, Connect) */
    931                 public void run() {
    932                     boolean hasv6 = false;
    933                     try {
    934                         /* Use the check result from last run of the software, as after the test value
    935                            changes have no effect anymore */
    936                         if(getBoolean("validated.ipv6", false)) {
    937                             Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
    938                         }
    939                         for(InetAddress a : InetAddress.getAllByName("josm.openstreetmap.de")) {
    940                             if(a instanceof Inet6Address) {
    941                                 if(a.isReachable(1000)) {
    942                                     Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
    943                                     if(!getBoolean("validated.ipv6", false)) {
    944                                         Main.info(tr("Automatics detected useable IPv6 network, prefering IPv6 over IPv4 after next restart."));
    945                                     } else {
    946                                         Main.info(tr("Automatics detected useable IPv6 network, prefering IPv6 over IPv4."));
    947                                     }
    948                                     hasv6 = true;
    949                                 }
    950                                 break; /* we're done */
    951                             }
    952                         }
    953                     } catch (Exception e) {
    954                     }
    955                     put("validated.ipv6", hasv6);
    956                 }
    957             }).start();
    958         }
    959927    }
    960928
     
    14071375        if("true".equals(get("prefer.ipv6", "auto"))) {
    14081376            // never set this to false, only true!
    1409             Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
     1377            if(!"true".equals(Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true"))) {
     1378                Main.info(tr("Try enabling IPv6 network, prefering IPv4 over IPv6 (only works on early startup)."));
     1379            }
    14101380        }
    14111381        Utils.updateSystemProperty("http.agent", Version.getInstance().getAgentString());
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r8290 r8296  
    1616import java.io.InputStream;
    1717import java.net.Authenticator;
     18import java.net.InetAddress;
     19import java.net.Inet6Address;
    1820import java.net.ProxySelector;
    1921import java.net.URL;
     
    363365        Main.pref.init(args.containsKey(Option.RESET_PREFERENCES));
    364366
     367        if (args.containsKey(Option.SET)) {
     368            for (String i : args.get(Option.SET)) {
     369                String[] kv = i.split("=", 2);
     370                Main.pref.put(kv[0], "null".equals(kv[1]) ? null : kv[1]);
     371            }
     372        }
     373
    365374        if (!languageGiven) {
    366375            I18n.set(Main.pref.get("language", null));
    367376        }
    368377        Main.pref.updateSystemProperties();
     378
     379        checkIPv6();
    369380
    370381        // asking for help? show help and exit
     
    394405                    throw new RuntimeException(ex);
    395406                }
    396             }
    397         }
    398 
    399         if (args.containsKey(Option.SET)) {
    400             for (String i : args.get(Option.SET)) {
    401                 String[] kv = i.split("=", 2);
    402                 Main.pref.put(kv[0], "null".equals(kv[1]) ? null : kv[1]);
    403407            }
    404408        }
     
    525529    }
    526530
     531    /**
     532     * Check if IPv6 can be safely enabled and do so. Because this cannot be done after network activation,
     533     * disabling or enabling IPV6 may only be done with next start.
     534     */
     535    private static void checkIPv6() {
     536        if("auto".equals(Main.pref.get("prefer.ipv6", "auto"))) {
     537             new Thread(new Runnable() { /* this may take some time (DNS, Connect) */
     538                public void run() {
     539                    boolean hasv6 = false;
     540                    boolean wasv6 = Main.pref.getBoolean("validated.ipv6", false);
     541                    try {
     542                        /* Use the check result from last run of the software, as after the test, value
     543                           changes have no effect anymore */
     544                        if(wasv6) {
     545                            Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
     546                        }
     547                        for(InetAddress a : InetAddress.getAllByName("josm.openstreetmap.de")) {
     548                            if(a instanceof Inet6Address) {
     549                                if(a.isReachable(1000)) {
     550                                    Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
     551                                    if(!wasv6) {
     552                                        Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4 after next restart."));
     553                                    } else {
     554                                        Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4."));
     555                                    }
     556                                    hasv6 = true;
     557                                }
     558                                break; /* we're done */
     559                            }
     560                        }
     561                    } catch (Exception e) {
     562                    }
     563                    if(wasv6 && !hasv6) {
     564                        Main.info(tr("Automatics detected no useable IPv6 network, prefering IPv4 over IPv6 after next restart."));
     565                    }
     566                    Main.pref.put("validated.ipv6", hasv6);
     567                }
     568            }).start();
     569        }
     570    }
     571   
    527572    private static class GuiFinalizationWorker implements Runnable {
    528573
Note: See TracChangeset for help on using the changeset viewer.