This commit is contained in:
tonikelope 2017-12-01 12:12:12 +01:00
parent 05efe13751
commit 19507d8b84
11 changed files with 136 additions and 111 deletions

View File

@ -95,7 +95,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
Chunk chunk;
int reads, conta_error, http_status;
InputStream is;
boolean error;
boolean error, error509;
String current_proxy = null;
CloseableHttpClient httpclient = null;
@ -106,17 +106,18 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
conta_error = 0;
error = false;
error509 = false;
while (!_exit && !_download.isStopped()) {
if (_download.isUse_smart_proxy() && !MainPanel.isUse_smart_proxy()) {
if (_download.isUse_smart_proxy() && !_download.getMain_panel().isUse_smart_proxy()) {
_download.setUse_smart_proxy(false);
}
if (httpclient == null || error || (MainPanel.isUse_smart_proxy() && _download.isUse_smart_proxy())) {
if (httpclient == null || error || (_download.getMain_panel().isUse_smart_proxy() && _download.isUse_smart_proxy())) {
if (error && !_download.isUse_smart_proxy()) {
if (error509 && !_download.isUse_smart_proxy()) {
_download.setUse_smart_proxy(true);
}
@ -129,7 +130,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download.getExcluded_proxies().add(current_proxy);
}
current_proxy = MainPanel.getProxy_manager().getRandomProxy(_download.getExcluded_proxies());
current_proxy = _download.getMain_panel().getProxy_manager().getRandomProxy(_download.getExcluded_proxies());
if (httpclient != null) {
try {
@ -158,6 +159,8 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
error = false;
error509 = false;
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
if (!_exit && !_download.isStopped()) {
@ -171,6 +174,11 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
error = true;
if(http_status == 509)
{
error509 = true;
}
} else {
byte[] buffer = new byte[THROTTLE_SLICE_SIZE];
@ -218,7 +226,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download.getView().updateSlotsStatus();
if (!MainPanel.isUse_smart_proxy()) {
if (!_download.getMain_panel().isUse_smart_proxy()) {
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
}

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import static megabasterd.MainPanel.*;
@ -31,8 +30,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
String current_proxy = null;
Chunk chunk;
int reads, conta_error, http_status = 200;
boolean error;
ArrayList<String> excluded = new ArrayList<>();
boolean error,error509;
HttpGet httpget = null;
CloseableHttpResponse httpresponse = null;
CloseableHttpClient httpclient = null;
@ -44,18 +42,20 @@ public class ChunkDownloaderMono extends ChunkDownloader {
error = false;
error509 = false;
InputStream is = null;
while (!isExit() && !getDownload().isStopped()) {
if (this.getDownload().isUse_smart_proxy() && !MainPanel.isUse_smart_proxy()) {
if (this.getDownload().isUse_smart_proxy() && !this.getDownload().getMain_panel().isUse_smart_proxy()) {
this.getDownload().setUse_smart_proxy(false);
}
if (httpclient == null || worker_url == null || error || (MainPanel.isUse_smart_proxy() && this.getDownload().isUse_smart_proxy())) {
if (httpclient == null || worker_url == null || error || (this.getDownload().getMain_panel().isUse_smart_proxy() && this.getDownload().isUse_smart_proxy())) {
if (error && !this.getDownload().isUse_smart_proxy()) {
if (error509 && !this.getDownload().isUse_smart_proxy()) {
this.getDownload().setUse_smart_proxy(true);
}
@ -65,10 +65,10 @@ public class ChunkDownloaderMono extends ChunkDownloader {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker mono: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
excluded.add(current_proxy);
this.getDownload().getExcluded_proxies().add(current_proxy);
}
current_proxy = MainPanel.getProxy_manager().getRandomProxy(excluded);
current_proxy = this.getDownload().getMain_panel().getProxy_manager().getRandomProxy(this.getDownload().getExcluded_proxies());
if (httpclient != null) {
try {
@ -116,6 +116,11 @@ public class ChunkDownloaderMono extends ChunkDownloader {
error = true;
if(http_status == 509)
{
error509 = true;
}
getDownload().rejectChunkId(chunk.getId());
conta_error++;
@ -124,7 +129,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
setError_wait(true);
if (!MainPanel.isUse_smart_proxy()) {
if (!this.getDownload().getMain_panel().isUse_smart_proxy()) {
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
}
@ -173,7 +178,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
setError_wait(true);
if (!MainPanel.isUse_smart_proxy()) {
if (!this.getDownload().getMain_panel().isUse_smart_proxy()) {
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
}

View File

@ -92,7 +92,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
private final MegaAPI _ma;
private volatile boolean _use_smart_proxy;
private volatile int _last_proxy_list_hashcode;
private final ArrayList<String> _excluded_proxies;
private final ConcurrentLinkedQueue<String> _excluded_proxies;
private final Object _watchdog_lock;
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, int slots, boolean restart) {
@ -122,7 +122,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_use_slots = use_slots;
_use_smart_proxy = false;
_watchdog_lock = new Object();
_excluded_proxies = new ArrayList<>();
_excluded_proxies = new ConcurrentLinkedQueue<>();
_last_proxy_list_hashcode = -1;
_slots = slots;
_restart = restart;
@ -134,7 +134,6 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_partialProgressQueue = new ConcurrentLinkedQueue<>();
_rejectedChunkIds = new ConcurrentLinkedQueue<>();
_thread_pool = newCachedThreadPool();
_view = new DownloadView(this);
_progress_meter = new ProgressMeter(this);
}
@ -146,7 +145,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
public void setUse_smart_proxy(boolean _use_smart_proxy) {
if (_use_smart_proxy) {
swingReflectionInvoke("setForeground", this.getView().getSpeed_label(), Color.ORANGE);
swingReflectionInvoke("setForeground", this.getView().getSpeed_label(), Color.DARK_GRAY);
} else {
swingReflectionInvoke("setForeground", this.getView().getSpeed_label(), new Color(0, 128, 255));
}
@ -154,7 +153,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
this._use_smart_proxy = _use_smart_proxy;
}
public ArrayList<String> getExcluded_proxies() {
public ConcurrentLinkedQueue<String> getExcluded_proxies() {
return _excluded_proxies;
}
@ -1380,7 +1379,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_use_smart_proxy = false;
int proxy_list_hashcode = MainPanel.getProxy_manager().getProxy_list().hashCode();
int proxy_list_hashcode = getMain_panel().getProxy_manager().getProxy_list().hashCode();
if (_last_proxy_list_hashcode != proxy_list_hashcode) {

View File

@ -39,7 +39,7 @@
<Component id="dance_button" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="links_label" pref="669" max="32767" attributes="0"/>
<Component id="links_label" pref="764" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="dlc_button" min="-2" max="-2" attributes="0"/>
</Group>

View File

@ -184,7 +184,7 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dance_button))
.addGroup(layout.createSequentialGroup()
.addComponent(links_label, javax.swing.GroupLayout.DEFAULT_SIZE, 669, Short.MAX_VALUE)
.addComponent(links_label, javax.swing.GroupLayout.DEFAULT_SIZE, 764, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dlc_button))
.addGroup(layout.createSequentialGroup()

View File

@ -45,7 +45,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
*/
public final class MainPanel {
public static final String VERSION = "2.42";
public static final String VERSION = "2.43";
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;
@ -58,9 +58,7 @@ public final class MainPanel {
private static int _proxy_port;
private static Credentials _proxy_credentials;
private static boolean _use_proxy;
private static boolean _use_smart_proxy;
private static String _use_smart_proxy_url;
private static SmartMegaProxyManager _proxy_manager;
public static void main(String args[]) {
@ -86,27 +84,12 @@ public final class MainPanel {
});
}
public static boolean isUse_proxy() {
return _use_proxy;
}
public static String getProxy_host() {
return _proxy_host;
}
public static int getProxy_port() {
return _proxy_port;
}
public static Credentials getProxy_credentials() {
return _proxy_credentials;
}
public static String getUse_smart_proxy_url() {
return _use_smart_proxy_url;
}
private volatile MainPanelView _view; //lazy init
private volatile boolean _use_smart_proxy;
private volatile String _use_smart_proxy_url;
private volatile SmartMegaProxyManager _proxy_manager;
private volatile MainPanelView _view;
private final GlobalSpeedMeter _global_dl_speed, _global_up_speed;
private final DownloadManager _download_manager;
private final UploadManager _upload_manager;
@ -172,9 +155,7 @@ public final class MainPanel {
_use_smart_proxy = false;
_use_smart_proxy_url = "";
_proxy_manager = null;
_use_smart_proxy_url = null;
loadUserSettings();
@ -226,24 +207,45 @@ public final class MainPanel {
_mega_proxy_server = null;
}
if (_use_smart_proxy) {
_proxy_manager = new SmartMegaProxyManager(_use_smart_proxy_url);
THREAD_POOL.execute(_proxy_manager);
}
}
public static boolean isUse_smart_proxy() {
public void setProxy_manager(SmartMegaProxyManager _proxy_manager) {
this._proxy_manager = _proxy_manager;
}
public static String getProxy_host() {
return _proxy_host;
}
public static int getProxy_port() {
return _proxy_port;
}
public static Credentials getProxy_credentials() {
return _proxy_credentials;
}
public static boolean isUse_proxy() {
return _use_proxy;
}
public boolean isUse_smart_proxy() {
return _use_smart_proxy;
}
public static SmartMegaProxyManager getProxy_manager() {
return _proxy_manager;
public String getUse_smart_proxy_url() {
return _use_smart_proxy_url;
}
public static void setProxy_manager(SmartMegaProxyManager proxy_manager) {
_proxy_manager = proxy_manager;
public SmartMegaProxyManager getProxy_manager() {
return _proxy_manager;
}
public MegaProxyServer getMega_proxy_server() {
@ -321,6 +323,14 @@ public final class MainPanel {
public MainPanelView getView() {
while (_view == null) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
}
}
return _view;
}

View File

@ -734,27 +734,27 @@ public final class MainPanelView extends javax.swing.JFrame {
_main_panel.setMega_proxy_server(null);
}
if (MainPanel.isUse_smart_proxy()) {
if (this.getMain_panel().isUse_smart_proxy()) {
if (MainPanel.getProxy_manager() == null) {
if (this.getMain_panel().getProxy_manager() == null) {
MainPanel.setProxy_manager(new SmartMegaProxyManager(MainPanel.getUse_smart_proxy_url()));
this.getMain_panel().setProxy_manager(new SmartMegaProxyManager(this.getMain_panel().getUse_smart_proxy_url()));
THREAD_POOL.execute(MainPanel.getProxy_manager());
THREAD_POOL.execute(this.getMain_panel().getProxy_manager());
} else {
MainPanel.getProxy_manager().setProxy_list_url(MainPanel.getUse_smart_proxy_url());
this.getMain_panel().getProxy_manager().setProxy_list_url(this.getMain_panel().getUse_smart_proxy_url());
}
} else if (MainPanel.getProxy_manager() != null) {
} else if (this.getMain_panel().getProxy_manager() != null) {
MainPanel.getProxy_manager().setExit(true);
this.getMain_panel().getProxy_manager().setExit(true);
synchronized (MainPanel.getProxy_manager().getRefresh_lock()) {
MainPanel.getProxy_manager().getRefresh_lock().notify();
synchronized (this.getMain_panel().getProxy_manager().getRefresh_lock()) {
this.getMain_panel().getProxy_manager().getRefresh_lock().notify();
}
MainPanel.setProxy_manager(null);
this.getMain_panel().setProxy_manager(null);
}
}

View File

@ -333,7 +333,7 @@ public final class MegaAPI {
}
} catch (IOException | URISyntaxException ex) {
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
@ -358,10 +358,6 @@ public final class MegaAPI {
}
} while (error != 0);
} catch (MegaAPIException | IOException exception) {
throw exception;
}
_seqno++;

View File

@ -86,9 +86,7 @@ public final class MiscTools {
public static final int EXP_BACKOFF_MAX_WAIT_TIME = 16;
public static final Object PASS_LOCK = new Object();
public static final int HTTP_TIMEOUT = 30;
private static final ConcurrentHashMap<String, Method> REFLECTION_METHOD_CACHE = new ConcurrentHashMap<>();
private static final Comparator<DefaultMutableTreeNode> TREE_NODE_COMPARATOR = new Comparator< DefaultMutableTreeNode>() {
@Override

View File

@ -47,6 +47,8 @@ public class SmartMegaProxyManager implements Runnable {
public synchronized String getRandomProxy() {
synchronized (_refresh_lock) {
if (_proxy_list.size() > 0) {
Random random = new Random();
@ -58,12 +60,15 @@ public class SmartMegaProxyManager implements Runnable {
return null;
}
}
}
public synchronized void setProxy_list_url(String proxy_list_url) {
_proxy_list_url = proxy_list_url;
}
public synchronized String getRandomProxy(ArrayList<String> excluded) {
public String getRandomProxy(ConcurrentLinkedQueue<String> excluded) {
synchronized (_refresh_lock) {
if (_proxy_list.size() > 0) {
@ -102,17 +107,20 @@ public class SmartMegaProxyManager implements Runnable {
return null;
}
}
}
public ConcurrentLinkedQueue<String> getProxy_list() {
return _proxy_list;
}
private synchronized void _refreshProxyList() {
private void _refreshProxyList() {
String data;
try (CloseableHttpClient httpclient = getApacheKissHttpClient()) {
if(this._proxy_list_url!=null && this._proxy_list_url.length()>0)
{
HttpGet httpget = new HttpGet(new URI(this._proxy_list_url));
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
@ -142,6 +150,7 @@ public class SmartMegaProxyManager implements Runnable {
this._proxy_list.addAll(Arrays.asList(proxy_list));
}
}
} catch (MalformedURLException ex) {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.SEVERE, null, ex);
@ -157,12 +166,12 @@ public class SmartMegaProxyManager implements Runnable {
while (!_exit) {
synchronized (_refresh_lock) {
this._refreshProxyList();
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
synchronized (_refresh_lock) {
try {
_refresh_lock.wait(1000 * REFRESH_PROXY_LIST_TIMEOUT);
} catch (InterruptedException ex) {

View File

@ -623,7 +623,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
printStatus("Starting upload, please wait...");
if (!_exit) {
if (_ul_url == null) {
if (_ul_url == null || _restart) {
int conta_error = 0;