Changeset 1109331 for router


Ignore:
Timestamp:
May 31, 2019 9:43:41 PM (10 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f44a8e4
Parents:
8a4c469
Message:

Transport: UPnP fixes for Android

Location:
router/java/src/net/i2p/router
Files:
1 added
3 edited

Legend:

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

    r8a4c469 r1109331  
    5353import net.i2p.router.tasks.*;
    5454import net.i2p.router.transport.FIFOBandwidthLimiter;
     55import net.i2p.router.transport.UPnPScannerCallback;
    5556import net.i2p.router.transport.ntcp.NTCPTransport;
    5657import net.i2p.router.transport.udp.UDPTransport;
     
    104105    private boolean _familyKeyCryptoFail;
    105106    public final Object _familyKeyLock = new Object();
     107    private UPnPScannerCallback _upnpScannerCallback;
    106108   
    107109    public final static String PROP_CONFIG_FILE = "router.configLocation";
     
    385387        }
    386388        _networkID = id;
     389        // for testing
     390        setUPnPScannerCallback(new LoggerCallback());
    387391        changeState(State.INITIALIZED);
    388392        // *********  Start no threads before here ********* //
     
    607611    public RouterContext getContext() { return _context; }
    608612   
     613    private class LoggerCallback implements UPnPScannerCallback {
     614        public void beforeScan() { _log.info("SSDP beforeScan()"); }
     615        public void afterScan() { _log.info("SSDP afterScan()"); }
     616    }
     617
     618    /**
     619     *  For Android only.
     620     *  MUST be set before runRouter() is called.
     621     *
     622     *  @param callback the callback or null to clear it
     623     *  @since 0.9.41
     624     */
     625    public synchronized void setUPnPScannerCallback(UPnPScannerCallback callback) {
     626        _upnpScannerCallback = callback;
     627    }
     628
     629    /**
     630     *  For Android only.
     631     *
     632     *  @return the callback or null if none
     633     *  @since 0.9.41
     634     */
     635    public synchronized UPnPScannerCallback getUPnPScannerCallback() {
     636        return _upnpScannerCallback;
     637    }
     638
    609639    /**
    610640     *  This must be called after instantiation.
  • router/java/src/net/i2p/router/transport/TransportManager.java

    r8a4c469 r1109331  
    342342        // What firewall supports UPnP and is configured with a public address on the LAN side?
    343343        // Unlikely.
    344         if (_upnpManager != null && Addresses.getAnyAddress() == null)
     344        // Always start on Android, as we may have a cellular IPv4 address but
     345        // are routing all traffic through WiFi.
     346        // Also, conditions may change rapidly.
     347        if (_upnpManager != null && (SystemVersion.isAndroid() || Addresses.getAnyAddress() == null))
    345348            _upnpManager.start();
    346349        configTransports();
  • router/java/src/net/i2p/router/transport/UPnPManager.java

    r8a4c469 r1109331  
    3535    private final UPnP _upnp;
    3636    private final UPnPCallback _upnpCallback;
     37    private final UPnPScannerCallback _scannerCallback;
     38    private final DelayedCallback _delayedCallback;
    3739    private volatile boolean _isRunning;
    3840    private volatile boolean _shouldBeRunning;
     
    7476        _upnp = new UPnP(context);
    7577        _upnpCallback = new UPnPCallback();
     78        _scannerCallback = _context.router().getUPnPScannerCallback();
     79        _delayedCallback = (_scannerCallback != null) ? new DelayedCallback() : null;
    7680        _rescanner = new Rescanner();
    7781    }
     
    9296                _upnp.setHTTPPort(_context.getProperty(PROP_HTTP_PORT, DEFAULT_HTTP_PORT));
    9397                _upnp.setSSDPPort(_context.getProperty(PROP_SSDP_PORT, DEFAULT_SSDP_PORT));
     98                if (_scannerCallback != null) {
     99                    _scannerCallback.beforeScan();
     100                }
    94101                _isRunning = _upnp.runPlugin();
     102                if (_scannerCallback != null) {
     103                    if (_isRunning)
     104                        _delayedCallback.reschedule();
     105                    else
     106                        _scannerCallback.afterScan();
     107                }
    95108                if (_log.shouldDebug())
    96109                    _log.info("UPnP runPlugin took " + (_context.clock().now() - b));
     
    100113                    _log.error("UPnP error, please report", e);
    101114                    _errorLogged = true;
     115                }
     116                if (_scannerCallback != null) {
     117                    _scannerCallback.afterScan();
    102118                }
    103119            }
     
    157173        _lastRescan = now;
    158174        if (_isRunning) {
     175            if (_scannerCallback != null)
     176                _scannerCallback.beforeScan();
    159177            if (_log.shouldLog(Log.DEBUG))
    160178                _log.debug("UPnP Rescan");
     
    164182            // Kevin Mills and Christopher Dabrowski
    165183            _upnp.search();
     184            if (_scannerCallback != null)
     185                _delayedCallback.reschedule();
    166186        } else {
    167187            start();
     
    187207                reschedule(_isRunning ? RESCAN_LONG_DELAY : RESCAN_SHORT_DELAY);
    188208            }
     209        }
     210    }
     211
     212    /**
     213     * Delayed Callback
     214     *
     215     * @since 0.9.41
     216     */
     217    private class DelayedCallback extends SimpleTimer2.TimedEvent {
     218
     219        /** caller must reschedule() */
     220        public DelayedCallback() {
     221            super(_context.simpleTimer2());
     222        }
     223
     224        public void timeReached() {
     225             _scannerCallback.afterScan();
     226        }
     227
     228        /**
     229         *  Pushes out.
     230         *  We do it this way because we may have two scans running concurrently,
     231         *  we only want to call afterScan() once.
     232         */
     233        void reschedule() {
     234            // false == use latest time
     235            reschedule((_upnp.getSearchMx() * 1000) + 500, false);
    189236        }
    190237    }
Note: See TracChangeset for help on using the changeset viewer.