1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Randomly choose file download block sizes in the hope of getting rid of FLOOD_WARN errors.

This commit is contained in:
Fabian Schlenz 2016-07-11 06:21:34 +02:00
parent 8cae413e6a
commit 05dea702c3
2 changed files with 8 additions and 2 deletions

View File

@ -34,7 +34,11 @@ public class Config {
public static final String FILE_FILES_BASE = "files"; public static final String FILE_FILES_BASE = "files";
public static final String FILE_STICKER_BASE = "stickers"; public static final String FILE_STICKER_BASE = "stickers";
public static final int FILE_DOWNLOAD_BLOCK_SIZE = 1*1024*1024; public static final int[] FILE_DOWNLOAD_BLOCK_SIZES = new int[]{
1*1024*1024,
512*1024,
2*1024*1024,
4*1024*1024};
public static int DELAY_AFTER_GET_MESSAGES = 200; public static int DELAY_AFTER_GET_MESSAGES = 200;
public static int DELAY_AFTER_GET_FILE = 1000; public static int DELAY_AFTER_GET_FILE = 1000;

View File

@ -38,6 +38,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Random;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -221,7 +222,8 @@ public class DownloadManager {
int offset = 0; int offset = 0;
TLFile response; TLFile response;
do { do {
TLRequestUploadGetFile req = new TLRequestUploadGetFile(loc, offset, Config.FILE_DOWNLOAD_BLOCK_SIZE); int block_size = Config.FILE_DOWNLOAD_BLOCK_SIZES[new Random().nextInt(Config.FILE_DOWNLOAD_BLOCK_SIZES.length)];
TLRequestUploadGetFile req = new TLRequestUploadGetFile(loc, offset, block_size);
if (dcID==null) { if (dcID==null) {
response = (TLFile) client.executeRpcQuery(req); response = (TLFile) client.executeRpcQuery(req);
} else { } else {