Search in sources :

Example 1 with PartialEepGet

use of net.i2p.util.PartialEepGet in project i2p.i2p by i2p.

the class DevSU3UpdateChecker method update.

@Override
protected void update() {
    // must be set for super
    _isPartial = true;
    // use the same settings as for updater
    // always proxy, or else FIXME
    // boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
    String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    int proxyPort = ConfigUpdateHandler.proxyPort(_context);
    if (proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
        String msg = _t("HTTP client proxy tunnel must be running");
        if (_log.shouldWarn())
            _log.warn(msg);
        updateStatus("<b>" + msg + "</b>");
        _mgr.notifyCheckComplete(this, false, false);
        return;
    }
    // updateStatus("<b>" + _t("Checking for development build update") + "</b>");
    _baos.reset();
    try {
        _get = new PartialEepGet(_context, proxyHost, proxyPort, _baos, _currentURI.toString(), TrustedUpdate.HEADER_BYTES);
        _get.addStatusListener(this);
        _get.fetch(CONNECT_TIMEOUT);
    } catch (Throwable t) {
        _log.error("Error fetching the update", t);
    }
}
Also used : PartialEepGet(net.i2p.util.PartialEepGet)

Example 2 with PartialEepGet

use of net.i2p.util.PartialEepGet in project i2p.i2p by i2p.

the class PluginUpdateChecker method update.

@Override
protected void update() {
    // must be set for super
    _isPartial = true;
    // use the same settings as for updater
    // always proxy, or else FIXME
    // boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
    String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    int proxyPort = ConfigUpdateHandler.proxyPort(_context);
    if (proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
        String msg = _t("HTTP client proxy tunnel must be running");
        if (_log.shouldWarn())
            _log.warn(msg);
        updateStatus("<b>" + msg + "</b>");
        _mgr.notifyCheckComplete(this, false, false);
        return;
    }
    updateStatus("<b>" + _t("Checking for update of plugin {0}", _appName) + "</b>");
    _baos.reset();
    try {
        _get = new PartialEepGet(_context, proxyHost, proxyPort, _baos, _currentURI.toString(), TrustedUpdate.HEADER_BYTES);
        _get.addStatusListener(this);
        _get.fetch(CONNECT_TIMEOUT);
    } catch (Throwable t) {
        _log.error("Error checking update for plugin", t);
    }
}
Also used : PartialEepGet(net.i2p.util.PartialEepGet)

Example 3 with PartialEepGet

use of net.i2p.util.PartialEepGet in project i2p.i2p by i2p.

the class UpdateRunner method update.

/**
 *  Loop through the entire list of update URLs.
 *  For each one, first get the version from the first 56 bytes and see if
 *  it is newer than what we are running now.
 *  If it is, get the whole thing.
 */
protected void update() {
    // Do a PartialEepGet on the selected URL, check for version we expect,
    // and loop if it isn't what we want.
    // This will allows us to do a release without waiting for the last host to install the update.
    // Alternative: In bytesTransferred(), Check the data in the output file after
    // we've received at least 56 bytes. Need a cancel() method in EepGet ?
    boolean shouldProxy;
    String proxyHost;
    int proxyPort;
    boolean isSSL = false;
    if (_method == HTTP) {
        shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
        if (shouldProxy) {
            proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
            proxyPort = ConfigUpdateHandler.proxyPort(_context);
            if (proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
                String msg = _t("HTTP client proxy tunnel must be running");
                if (_log.shouldWarn())
                    _log.warn(msg);
                updateStatus("<b>" + msg + "</b>");
                _mgr.notifyTaskFailed(this, msg, null);
                return;
            }
        } else {
            // TODO, wrong method, fail
            proxyHost = null;
            proxyPort = 0;
        }
    } else if (_method == HTTP_CLEARNET) {
        shouldProxy = false;
        proxyHost = null;
        proxyPort = 0;
    } else if (_method == HTTPS_CLEARNET) {
        shouldProxy = false;
        proxyHost = null;
        proxyPort = 0;
        isSSL = true;
    } else {
        throw new IllegalArgumentException();
    }
    if (_urls.isEmpty()) {
        // not likely, don't bother translating
        String msg = "Update source list is empty, cannot download update";
        updateStatus("<b>" + msg + "</b>");
        _log.error(msg);
        _mgr.notifyTaskFailed(this, msg, null);
        return;
    }
    for (URI uri : _urls) {
        _currentURI = uri;
        String updateURL = uri.toString();
        if ((_method == HTTP && !"http".equals(uri.getScheme())) || (_method == HTTP_CLEARNET && !"http".equals(uri.getScheme())) || (_method == HTTPS_CLEARNET && !"https".equals(uri.getScheme())) || uri.getHost() == null || (_method != HTTP && uri.getHost().toLowerCase(Locale.US).endsWith(".i2p"))) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("Bad update URI " + uri + " for method " + _method);
            continue;
        }
        updateStatus("<b>" + _t("Updating from {0}", linkify(updateURL)) + "</b>");
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Selected update URL: " + updateURL);
        // Check the first 56 bytes for the version
        // FIXME PartialEepGet works with clearnet but not with SSL
        _newVersion = null;
        if (!isSSL) {
            _isPartial = true;
            _baos.reset();
            try {
                // no retries
                _get = new PartialEepGet(_context, proxyHost, proxyPort, _baos, updateURL, TrustedUpdate.HEADER_BYTES);
                _get.addStatusListener(UpdateRunner.this);
                _get.fetch(CONNECT_TIMEOUT);
            } catch (Throwable t) {
            }
            _isPartial = false;
            if (_newVersion == null)
                continue;
        }
        // Now get the whole thing
        try {
            if (shouldProxy)
                // 40 retries!!
                _get = new EepGet(_context, proxyHost, proxyPort, 40, _updateFile, updateURL, false);
            else if (isSSL)
                _get = new SSLEepGet(_context, _updateFile, updateURL);
            else
                _get = new EepGet(_context, 1, _updateFile, updateURL, false);
            _get.addStatusListener(UpdateRunner.this);
            _get.fetch(CONNECT_TIMEOUT, -1, shouldProxy ? INACTIVITY_TIMEOUT : NOPROXY_INACTIVITY_TIMEOUT);
        } catch (Throwable t) {
            _log.error("Error updating", t);
        }
        if (this.done)
            break;
    }
    (new File(_updateFile)).delete();
    if (!this.done)
        _mgr.notifyTaskFailed(this, "", null);
}
Also used : PartialEepGet(net.i2p.util.PartialEepGet) EepGet(net.i2p.util.EepGet) SSLEepGet(net.i2p.util.SSLEepGet) PartialEepGet(net.i2p.util.PartialEepGet) URI(java.net.URI) File(java.io.File) SSLEepGet(net.i2p.util.SSLEepGet)

Aggregations

PartialEepGet (net.i2p.util.PartialEepGet)3 File (java.io.File)1 URI (java.net.URI)1 EepGet (net.i2p.util.EepGet)1 SSLEepGet (net.i2p.util.SSLEepGet)1