Changeset 82d812c for router


Ignore:
Timestamp:
Feb 4, 2017 3:38:49 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6306799
Parents:
890ad25
Message:

NTP: Enable IPv6 support (ticket #1896)

Location:
router/java/src/net/i2p/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/RouterVersion.java

    r890ad25 r82d812c  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 4;
     21    public final static long BUILD = 5;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/time/RouterTimestamper.java

    r890ad25 r82d812c  
    99import net.i2p.I2PAppContext;
    1010import net.i2p.time.Timestamper;
     11import net.i2p.util.Addresses;
    1112import net.i2p.util.I2PThread;
    1213import net.i2p.util.Log;
     
    174175                // NOTE: _log is null the first time through, to prevent problems and stack overflows
    175176                updateConfig();
     177                boolean preferIPv6 = Addresses.isConnectedIPv6();
    176178                if (!_disabled) {
    177179                    // first the servers for our country and continent, we know what country we're in...
     
    181183                                _log.debug("Querying servers " + servers);
    182184                            try {
    183                                 lastFailed = !queryTime(servers.toArray(new String[servers.size()]), SHORT_TIMEOUT);
     185                                lastFailed = !queryTime(servers.toArray(new String[servers.size()]), SHORT_TIMEOUT, preferIPv6);
    184186                            } catch (IllegalArgumentException iae) {
    185187                                if (!lastFailed && _log != null && _log.shouldWarn())
     
    196198                            _log.debug("Querying servers " + _servers);
    197199                        try {
    198                             lastFailed = !queryTime(_servers.toArray(new String[_servers.size()]), DEFAULT_TIMEOUT);
     200                            // If we failed, maybe it's because IPv6 is blocked, so try IPv4 only
     201                            // also first time through, and randomly
     202                            boolean prefIPv6 = preferIPv6 && !lastFailed && _log != null && _context.random().nextInt(4) != 0;
     203                            lastFailed = !queryTime(_servers.toArray(new String[_servers.size()]), DEFAULT_TIMEOUT, prefIPv6);
    199204                        } catch (IllegalArgumentException iae) {
    200205                            lastFailed = true;
     
    263268     * True if the time was queried successfully, false if it couldn't be
    264269     */
    265     private boolean queryTime(String serverList[], int perServerTimeout) throws IllegalArgumentException {
     270    private boolean queryTime(String serverList[], int perServerTimeout, boolean preferIPv6) throws IllegalArgumentException {
    266271        long found[] = new long[_concurringServers];
    267272        long now = -1;
     
    274279            //    try { Thread.sleep(2*1000); } catch (InterruptedException ie) {}
    275280            //}
    276             // IPv6 arg TODO
    277             long[] timeAndStratum = NtpClient.currentTimeAndStratum(serverList, perServerTimeout, false, _log);
     281            long[] timeAndStratum = NtpClient.currentTimeAndStratum(serverList, perServerTimeout, preferIPv6, _log);
    278282            now = timeAndStratum[0];
    279283            stratum = (int) timeAndStratum[1];
Note: See TracChangeset for help on using the changeset viewer.