-More SmartProxy tunning
This commit is contained in:
tonikelope 2019-06-27 12:12:18 +02:00
parent da9211c90d
commit dad103f61b
10 changed files with 52 additions and 64 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>6.15</version>
<version>6.16</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -2,7 +2,6 @@ package com.tonikelope.megabasterd;
import static com.tonikelope.megabasterd.MainPanel.*;
import static com.tonikelope.megabasterd.MiscTools.*;
import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -28,6 +27,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
private final Object _secure_notify_lock;
private volatile boolean _error_wait;
private boolean _notified;
private String _current_smart_proxy;
public ChunkDownloader(int id, Download download) {
_notified = false;
@ -35,10 +35,15 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_secure_notify_lock = new Object();
_id = id;
_download = download;
_current_smart_proxy = null;
_error_wait = false;
}
public String getCurrent_smart_proxy() {
return _current_smart_proxy;
}
public void setExit(boolean exit) {
_exit = exit;
}
@ -104,7 +109,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
boolean timeout = false, chunk_error = false, slow_proxy = false;
String worker_url = null, current_smart_proxy = null;
String worker_url = null;
long init_chunk_time = -1, finish_chunk_time = -1, pause_init_time, paused = 0L;
@ -127,21 +132,21 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
String chunk_url = ChunkManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size);
if ((http_error == 509 || slow_proxy || (chunk_error && current_smart_proxy != null)) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if ((http_error == 509 || slow_proxy || (chunk_error && _current_smart_proxy != null)) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if (current_smart_proxy != null) {
if (_current_smart_proxy != null) {
proxy_manager.blockProxy(current_smart_proxy);
proxy_manager.blockProxy(_current_smart_proxy);
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: worker {1} excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_smart_proxy});
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: worker {1} excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, _current_smart_proxy});
}
current_smart_proxy = proxy_manager.getFastestProxy();
_current_smart_proxy = proxy_manager.getFastestProxy();
if (current_smart_proxy != null) {
if (_current_smart_proxy != null) {
String[] proxy_info = current_smart_proxy.split(":");
String[] proxy_info = _current_smart_proxy.split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_info[0], Integer.parseInt(proxy_info[1])));
@ -149,8 +154,6 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
con = (HttpURLConnection) url.openConnection(proxy);
getDownload().getView().getSpeed_label().setForeground(new Color(255, 102, 0));
getDownload().enableProxyTurboMode();
} else {
@ -166,6 +169,8 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
if (MainPanel.isUse_proxy()) {
_current_smart_proxy = null;
con = (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(MainPanel.getProxy_host(), MainPanel.getProxy_port())));
if (MainPanel.getProxy_user() != null && !"".equals(MainPanel.getProxy_user())) {
@ -175,13 +180,22 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} else {
if (_current_smart_proxy != null) {
String[] proxy_info = _current_smart_proxy.split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_info[0], Integer.parseInt(proxy_info[1])));
con = (HttpURLConnection) url.openConnection(proxy);
} else {
con = (HttpURLConnection) url.openConnection();
}
current_smart_proxy = null;
}
}
if (current_smart_proxy != null) {
if (_current_smart_proxy != null) {
con.setConnectTimeout(Download.HTTP_PROXY_TIMEOUT);
con.setReadTimeout(Download.HTTP_PROXY_TIMEOUT);
} else {
@ -217,10 +231,6 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
http_error = http_status;
if (http_error == 509 && MainPanel.isUse_smart_proxy()) {
getDownload().getView().set509Error();
}
} else {
chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + chunk_id);
@ -298,7 +308,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
http_error = 0;
if (current_smart_proxy != null) {
if (_current_smart_proxy != null) {
//Update average chunk download speed using SmartProxy
long chunk_speed = Math.round(chunk_size / (((double) (finish_chunk_time - init_chunk_time - paused)) / 1000));
@ -312,7 +322,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
if (chunk_speed < Math.round(avg_chunk_speed * SLOW_PROXY_PERC)) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] WARNING -> PROXY {2} CHUNK DOWNLOAD SPEED: {3}/s SEEMS TO BE SLOW (average is {4}/s)", new Object[]{Thread.currentThread().getName(), _id, current_smart_proxy, formatBytes(chunk_speed), formatBytes(avg_chunk_speed)});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] WARNING -> PROXY {2} CHUNK DOWNLOAD SPEED: {3}/s SEEMS TO BE SLOW (average is {4}/s)", new Object[]{Thread.currentThread().getName(), _id, _current_smart_proxy, formatBytes(chunk_speed), formatBytes(avg_chunk_speed)});
slow_proxy = true;
}
@ -352,7 +362,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download.getProgress_meter().secureNotify();
}
if (!_exit && !_download.isStopped() && !timeout && (http_error != 509 || current_smart_proxy != null) && http_error != 403) {
if (!_exit && !_download.isStopped() && !timeout && (http_error != 509 || _current_smart_proxy != null) && http_error != 403) {
_error_wait = true;

View File

@ -102,12 +102,6 @@ public class ChunkDownloaderMono extends ChunkDownloader {
http_error = http_status;
if (http_error == 509) {
getDownload().getView().set509Error();
}
getDownload().rejectChunkId(chunk_id);
conta_error++;

View File

@ -4,6 +4,7 @@ import static com.tonikelope.megabasterd.CryptTools.*;
import static com.tonikelope.megabasterd.DBTools.*;
import static com.tonikelope.megabasterd.MainPanel.*;
import static com.tonikelope.megabasterd.MiscTools.*;
import java.awt.Color;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@ -92,8 +93,6 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
private long _last_chunk_id_dispatched;
private final MegaAPI _ma;
private volatile boolean _canceled;
private volatile boolean _error509;
private volatile boolean _turbo_proxy_mode;
public Download(MainPanel main_panel, MegaAPI ma, String url, String download_path, String file_name, String file_key, Long file_size, String file_pass, String file_noexpire, boolean use_slots, boolean restart, String custom_chunks_dir) {
@ -121,8 +120,6 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_file_pass = file_pass;
_file_noexpire = file_noexpire;
_use_slots = use_slots;
_error509 = false;
_turbo_proxy_mode = false;
_restart = restart;
_secure_notify_lock = new Object();
_workers_lock = new Object();
@ -207,9 +204,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
synchronized (_turbo_proxy_lock) {
if (!_turbo_proxy_mode) {
_turbo_proxy_mode = true;
if (getChunkworkers().size() < Transference.MAX_WORKERS) {
Download tthis = this;
@ -220,6 +215,8 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
synchronized (_workers_lock) {
getView().getSpeed_label().setForeground(Color.BLACK);
getView().getSlots_spinner().setEnabled(false);
for (int t = getChunkworkers().size(); t <= Transference.MAX_WORKERS; t++) {
@ -245,14 +242,6 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
return _rejectedChunkIds;
}
public boolean isError509() {
return _error509;
}
public void setError509(boolean error509) {
_error509 = error509;
}
public Object getWorkers_lock() {
return _workers_lock;
}

View File

@ -621,18 +621,6 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
});
}
public void set509Error() {
if (!_download.isError509()) {
_download.setError509(true);
speed_label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icons8-error-40.png")));
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton close_button;
private javax.swing.JButton copy_link_button;

View File

@ -50,7 +50,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
public static final String VERSION = "6.15";
public static final String VERSION = "6.16";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;

View File

@ -19,7 +19,7 @@ import java.util.logging.Logger;
public final class SmartMegaProxyManager {
public static String DEFAULT_SMART_PROXY_URL = "https://raw.githubusercontent.com/tonikelope/megabasterd/proxy_list/proxy_list.txt";
public static final int BLOCK_TIME = 60;
public static final int BLOCK_TIME = 120;
private volatile String _proxy_list_url;
private final LinkedHashMap<String, Long> _proxy_list;
private final MainPanel _main_panel;

View File

@ -139,7 +139,7 @@ public final class SpeedMeter implements Runnable {
no_data_count = 0;
} else if (transference instanceof Download && ((Download) transference).isError509()) {
} else if (transference instanceof Download) {
sp = -1;
@ -193,13 +193,10 @@ public final class SpeedMeter implements Runnable {
trans_info.getKey().getView().updateSpeed(formatBytes(trans_sp) + "/s", true);
} else if (trans_sp == 0) {
} else {
trans_info.getKey().getView().updateSpeed("------", true);
} else {
trans_info.getKey().getView().updateSpeed("BANDWIDTH LIMIT ERROR!", true);
}
}

View File

@ -112,9 +112,19 @@ public class StreamChunkDownloader implements Runnable {
}
} else {
if (current_smart_proxy != null) {
String[] proxy_info = current_smart_proxy.split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_info[0], Integer.parseInt(proxy_info[1])));
con = (HttpURLConnection) chunk_url.openConnection(proxy);
} else {
con = (HttpURLConnection) chunk_url.openConnection();
}
}
}
con.setConnectTimeout(Transference.HTTP_TIMEOUT);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 196 KiB