diff --git a/src/megabasterd/ChunkDownloader.java b/src/megabasterd/ChunkDownloader.java index 7f418237a..a28e22463 100644 --- a/src/megabasterd/ChunkDownloader.java +++ b/src/megabasterd/ChunkDownloader.java @@ -130,7 +130,7 @@ public void run() { _download.getMain_panel().getProxy_manager().excludeProxy(current_proxy); } - current_proxy = _download.getMain_panel().getProxy_manager().getRandomProxy(true); + current_proxy = _download.getMain_panel().getProxy_manager().getFastestProxy(true); if (httpclient != null) { try { diff --git a/src/megabasterd/MainPanel.java b/src/megabasterd/MainPanel.java index 302fcd3fa..d15fac34c 100644 --- a/src/megabasterd/MainPanel.java +++ b/src/megabasterd/MainPanel.java @@ -45,7 +45,7 @@ */ public final class MainPanel { - public static final String VERSION = "2.53"; + public static final String VERSION = "2.54"; 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; diff --git a/src/megabasterd/SmartMegaProxyManager.java b/src/megabasterd/SmartMegaProxyManager.java index bd1533d71..ffb321c8d 100644 --- a/src/megabasterd/SmartMegaProxyManager.java +++ b/src/megabasterd/SmartMegaProxyManager.java @@ -33,7 +33,6 @@ public class SmartMegaProxyManager implements Runnable { private final MainPanel _main_panel; private volatile boolean _exit; private volatile boolean _use_smart_proxy; - private volatile Integer _last_list_hash; private final Object _refresh_lock; public SmartMegaProxyManager(MainPanel main_panel, String proxy_list_url) { @@ -43,7 +42,6 @@ public SmartMegaProxyManager(MainPanel main_panel, String proxy_list_url) { _excluded_proxies = new ConcurrentLinkedQueue<>(); _exit = false; _use_smart_proxy = false; - _last_list_hash = null; _refresh_lock = new Object(); } @@ -131,6 +129,36 @@ public String getRandomProxy(boolean skip_excluded) { } } + public String getFastestProxy(boolean skip_excluded) { + + synchronized (_refresh_lock) { + + if (_proxy_list.size() > 0) { + + if (skip_excluded && _excluded_proxies.size() > 0) { + + for (String proxy : _proxy_list) { + + if (!_excluded_proxies.contains(proxy)) { + + return proxy; + } + } + + return null; + + } else { + + return _proxy_list.peek(); + } + + } else { + + return null; + } + } + } + public void excludeProxy(String proxy) { synchronized (_refresh_lock) { @@ -143,7 +171,18 @@ public void excludeProxy(String proxy) { if (_proxy_list.size() == _excluded_proxies.size()) { - _refreshProxyList(); + _excluded_proxies.clear(); + + THREAD_POOL.execute(new Runnable() { + @Override + public void run() { + + synchronized (_refresh_lock) { + + _refreshProxyList(); + } + } + }); } } } @@ -197,16 +236,7 @@ private void _refreshProxyList() { _use_smart_proxy = false; - int proxy_list_hashcode = _proxy_list.hashCode(); - - if (_last_list_hash != proxy_list_hashcode) { - - _last_list_hash = proxy_list_hashcode; - - _excluded_proxies.clear(); - - Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.INFO, "{0} Smart Proxy Manager: excluded list cleared!", new Object[]{Thread.currentThread().getName()}); - } + _excluded_proxies.clear(); } swingReflectionInvoke("setText", _main_panel.getView().getSmart_proxy_status(), "SmartProxy: " + (_proxy_list.size() - _excluded_proxies.size()) + "/" + _proxy_list.size()); diff --git a/src/megabasterd/StreamChunkDownloader.java b/src/megabasterd/StreamChunkDownloader.java index 9e029a49d..11413f2cc 100644 --- a/src/megabasterd/StreamChunkDownloader.java +++ b/src/megabasterd/StreamChunkDownloader.java @@ -83,7 +83,7 @@ public void run() { _chunkwriter.getServer().getMain_panel().getProxy_manager().excludeProxy(current_proxy); } - current_proxy = _chunkwriter.getServer().getMain_panel().getProxy_manager().getRandomProxy(true); + current_proxy = _chunkwriter.getServer().getMain_panel().getProxy_manager().getFastestProxy(true); if (httpclient != null) { try {