Search in sources :

Example 1 with EepGet

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

the class DevSU3UpdateRunner method update.

/**
 * Get the file
 */
@Override
protected void update() {
    // always proxy for now
    // 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.notifyTaskFailed(this, msg, null);
        return;
    }
    String zipURL = _currentURI.toString();
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Starting signed dev update URL: " + zipURL);
    try {
        // 40 retries!!
        _get = new EepGet(_context, proxyHost, proxyPort, 40, _updateFile, zipURL, false);
        _get.addStatusListener(DevSU3UpdateRunner.this);
        _get.fetch(CONNECT_TIMEOUT, -1, INACTIVITY_TIMEOUT);
    } catch (Throwable t) {
        _log.error("Error updating", t);
    }
    if (!this.done)
        _mgr.notifyTaskFailed(this, "", null);
}
Also used : EepGet(net.i2p.util.EepGet)

Example 2 with EepGet

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

the class NewsFetcher method fetchNews.

public void fetchNews() {
    boolean shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY_NEWS, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY_NEWS);
    String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    int proxyPort = ConfigUpdateHandler.proxyPort(_context);
    if (shouldProxy && proxyPort == ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT && proxyHost.equals(ConfigUpdateHandler.DEFAULT_PROXY_HOST) && _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY) < 0) {
        if (_log.shouldWarn())
            _log.warn("Cannot fetch news - HTTP client tunnel not running");
        return;
    }
    if (shouldProxy && _context.commSystem().isDummy()) {
        if (_log.shouldWarn())
            _log.warn("Cannot fetch news - VM Comm system");
        return;
    }
    for (URI uri : _urls) {
        _currentURI = addLang(uri);
        String newsURL = _currentURI.toString();
        if (_tempFile.exists())
            _tempFile.delete();
        try {
            EepGet get;
            if (shouldProxy)
                get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
            else if ("https".equals(uri.getScheme()))
                // no constructor w/ last mod check
                get = new SSLEepGet(_context, _tempFile.getAbsolutePath(), newsURL);
            else
                get = new EepGet(_context, false, null, 0, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
            get.addStatusListener(this);
            long start = _context.clock().now();
            // will be adjusted in headerReceived() below
            _newLastModified = start;
            if (get.fetch()) {
                int status = get.getStatusCode();
                if (status == 200 || status == 304) {
                    Map<String, String> opts = new HashMap<String, String>(2);
                    opts.put(NewsHelper.PROP_LAST_CHECKED, Long.toString(start));
                    if (status == 200 && _isNewer)
                        opts.put(NewsHelper.PROP_LAST_UPDATED, Long.toString(_newLastModified));
                    _context.router().saveConfig(opts, null);
                    return;
                }
            }
        } catch (Throwable t) {
            _log.error("Error fetching the news", t);
        }
    }
}
Also used : HashMap(java.util.HashMap) SSLEepGet(net.i2p.util.SSLEepGet) EepGet(net.i2p.util.EepGet) URI(java.net.URI) SSLEepGet(net.i2p.util.SSLEepGet)

Example 3 with EepGet

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

the class PluginUpdateRunner method update.

@Override
protected void update() {
    _updated = false;
    if (_xpi2pURL.startsWith("file:") || _method == UpdateMethod.FILE) {
        // strip off file:// or just file:
        String xpi2pfile = _uri.getPath();
        if (xpi2pfile == null || xpi2pfile.length() == 0) {
            statusDone("<b>" + _t("Bad URL {0}", _xpi2pURL) + "</b>");
        } else {
            // copy the contents of from to _updateFile
            long alreadyTransferred = (new File(xpi2pfile)).getAbsoluteFile().length();
            if (FileUtil.copy((new File(xpi2pfile)).getAbsolutePath(), _updateFile, true, false)) {
                updateStatus("<b>" + _t("Attempting to install from file {0}", _xpi2pURL) + "</b>");
                transferComplete(alreadyTransferred, alreadyTransferred, 0L, _xpi2pURL, _updateFile, false);
            } else {
                statusDone("<b>" + _t("Failed to install from file {0}, copy failed.", _xpi2pURL) + "</b>");
            }
        }
    } else {
        // use the same settings as for updater
        // boolean shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
        // always proxy, or else FIXME
        boolean shouldProxy = true;
        String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
        int proxyPort = ConfigUpdateHandler.proxyPort(_context);
        if (shouldProxy && 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);
            statusDone("<b>" + msg + "</b>");
            _mgr.notifyTaskFailed(this, msg, null);
            return;
        }
        updateStatus("<b>" + _t("Downloading plugin from {0}", _xpi2pURL) + "</b>");
        try {
            if (shouldProxy)
                // 10 retries!!
                _get = new EepGet(_context, proxyHost, proxyPort, 10, _updateFile, _xpi2pURL, false);
            else
                _get = new EepGet(_context, 1, _updateFile, _xpi2pURL, false);
            _get.addStatusListener(PluginUpdateRunner.this);
            _get.fetch(CONNECT_TIMEOUT, -1, shouldProxy ? INACTIVITY_TIMEOUT : NOPROXY_INACTIVITY_TIMEOUT);
        } catch (Throwable t) {
            _log.error("Error downloading plugin", t);
        }
    }
    if (_updated)
        _mgr.notifyComplete(this, _newVersion, null);
    else
        _mgr.notifyTaskFailed(this, _errMsg, null);
}
Also used : EepGet(net.i2p.util.EepGet) SecureFile(net.i2p.util.SecureFile) SU3File(net.i2p.crypto.SU3File) File(java.io.File)

Example 4 with EepGet

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

the class UnsignedUpdateRunner method update.

/**
 * Get the file
 */
@Override
protected void update() {
    // always proxy for now
    // 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.notifyTaskFailed(this, msg, null);
        return;
    }
    String zipURL = _currentURI.toString();
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Starting unsigned update URL: " + zipURL);
    try {
        // 40 retries!!
        _get = new EepGet(_context, proxyHost, proxyPort, 40, _updateFile, zipURL, false);
        _get.addStatusListener(UnsignedUpdateRunner.this);
        _get.fetch(CONNECT_TIMEOUT, -1, INACTIVITY_TIMEOUT);
    } catch (Throwable t) {
        _log.error("Error updating", t);
    }
    if (!this.done)
        _mgr.notifyTaskFailed(this, "", null);
}
Also used : EepGet(net.i2p.util.EepGet)

Example 5 with EepGet

use of net.i2p.util.EepGet 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

EepGet (net.i2p.util.EepGet)7 File (java.io.File)3 URI (java.net.URI)2 SSLEepGet (net.i2p.util.SSLEepGet)2 SecureFile (net.i2p.util.SecureFile)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 I2PSocketEepGet (net.i2p.client.streaming.I2PSocketEepGet)1 SU3File (net.i2p.crypto.SU3File)1 PartialEepGet (net.i2p.util.PartialEepGet)1