retry index downloads from mirrors when failing for a networking reason

f1f56abd0f4253d69ee91bccaf09ce3730a648a3
fdroid/fdroidclient!697
This commit is contained in:
Hans-Christoph Steiner 2018-08-09 13:08:17 +02:00
parent e02a5987d2
commit c291b8f0f8
3 changed files with 21 additions and 5 deletions

View File

@ -47,11 +47,19 @@ import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.net.Downloader; import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.net.DownloaderFactory; import org.fdroid.fdroid.net.DownloaderFactory;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLKeyException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.HttpRetryException;
import java.net.NoRouteToHostException;
import java.net.ProtocolException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -94,6 +102,7 @@ public class IndexV1Updater extends RepoUpdater {
/** /**
* @return whether this successfully found an index of this version * @return whether this successfully found an index of this version
* @throws RepoUpdater.UpdateException * @throws RepoUpdater.UpdateException
* @see org.fdroid.fdroid.net.DownloaderService#handleIntent(android.content.Intent)
*/ */
@Override @Override
public boolean update() throws RepoUpdater.UpdateException { public boolean update() throws RepoUpdater.UpdateException {
@ -119,7 +128,10 @@ public class IndexV1Updater extends RepoUpdater {
} }
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag()); processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
} catch (ConnectException | SocketTimeoutException e) { } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
| ProtocolException | UnknownHostException e) {
// if the above list changes, also change below and in DownloaderService.handleIntent()
Utils.debugLog(TAG, "Trying to download the index from a mirror"); Utils.debugLog(TAG, "Trying to download the index from a mirror");
// Mirror logic here, so that the default download code is untouched. // Mirror logic here, so that the default download code is untouched.
String mirrorUrl; String mirrorUrl;
@ -146,7 +158,9 @@ public class IndexV1Updater extends RepoUpdater {
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag()); processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
break; break;
} catch (ConnectException | SocketTimeoutException e2) { } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
| ProtocolException | UnknownHostException e2) {
// We'll just let this try the next mirror // We'll just let this try the next mirror
Utils.debugLog(TAG, "Trying next mirror"); Utils.debugLog(TAG, "Trying next mirror");
} catch (IOException e2) { } catch (IOException e2) {

View File

@ -47,6 +47,7 @@ import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.HttpRetryException; import java.net.HttpRetryException;
import java.net.NoRouteToHostException; import java.net.NoRouteToHostException;
import java.net.ProtocolException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -193,6 +194,7 @@ public class DownloaderService extends Service {
* *
* @param intent The {@link Intent} passed via {@link * @param intent The {@link Intent} passed via {@link
* android.content.Context#startService(Intent)}. * android.content.Context#startService(Intent)}.
* @see org.fdroid.fdroid.IndexV1Updater#update()
*/ */
private void handleIntent(Intent intent) { private void handleIntent(Intent intent) {
final Uri uri = intent.getData(); final Uri uri = intent.getData();
@ -225,7 +227,8 @@ public class DownloaderService extends Service {
sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, originalUrlString); sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, originalUrlString);
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException
| SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException
| UnknownHostException e) { | ProtocolException | UnknownHostException e) {
// if the above list of exceptions changes, also change it in IndexV1Updater.update()
Log.e(TAG, e.getLocalizedMessage()); Log.e(TAG, e.getLocalizedMessage());
sendBroadcast(uri, Downloader.ACTION_CONNECTION_FAILED, localFile, repoId, originalUrlString); sendBroadcast(uri, Downloader.ACTION_CONNECTION_FAILED, localFile, repoId, originalUrlString);
} catch (IOException e) { } catch (IOException e) {

View File

@ -37,7 +37,6 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
@ -106,7 +105,7 @@ public class HttpDownloader extends Downloader {
* @see <a href="http://lucb1e.com/rp/cookielesscookies">Cookieless cookies</a> * @see <a href="http://lucb1e.com/rp/cookielesscookies">Cookieless cookies</a>
*/ */
@Override @Override
public void download() throws ConnectException, IOException, InterruptedException { public void download() throws IOException, InterruptedException {
// get the file size from the server // get the file size from the server
HttpURLConnection tmpConn = getConnection(); HttpURLConnection tmpConn = getConnection();
tmpConn.setRequestMethod("HEAD"); tmpConn.setRequestMethod("HEAD");