mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-29 13:00:15 +02:00
4.1
-SmartProxy
This commit is contained in:
parent
b160bff5e5
commit
cd73aa5fb6
@ -118,9 +118,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
|||||||
|
|
||||||
if (error && current_proxy != null) {
|
if (error && current_proxy != null) {
|
||||||
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
MainPanel.getProxy_manager().removeProxy(current_proxy);
|
||||||
|
|
||||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
||||||
@ -152,9 +150,9 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet(new URI(chunk.getUrl()));
|
HttpGet httpget = new HttpGet(new URI(chunk.getUrl()));
|
||||||
|
|
||||||
error = false;
|
error = true;
|
||||||
|
|
||||||
error509 = false;
|
error509 = true;
|
||||||
|
|
||||||
if (getDownload().isError509()) {
|
if (getDownload().isError509()) {
|
||||||
getDownload().getView().set509Error(false);
|
getDownload().getView().set509Error(false);
|
||||||
|
@ -48,7 +48,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
|||||||
*/
|
*/
|
||||||
public final class MainPanel {
|
public final class MainPanel {
|
||||||
|
|
||||||
public static final String VERSION = "4.0";
|
public static final String VERSION = "4.1";
|
||||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||||
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
||||||
public static final int STREAMER_PORT = 1337;
|
public static final int STREAMER_PORT = 1337;
|
||||||
|
@ -312,7 +312,7 @@ public final class MegaAPI {
|
|||||||
|
|
||||||
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
||||||
|
|
||||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
MainPanel.getProxy_manager().removeProxy(current_proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
||||||
|
@ -820,7 +820,7 @@ public final class MiscTools {
|
|||||||
|
|
||||||
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
||||||
|
|
||||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
MainPanel.getProxy_manager().removeProxy(current_proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
||||||
|
@ -11,8 +11,6 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import static com.tonikelope.megabasterd.MainPanel.THREAD_POOL;
|
import static com.tonikelope.megabasterd.MainPanel.THREAD_POOL;
|
||||||
import static com.tonikelope.megabasterd.MiscTools.getApacheKissHttpClient;
|
import static com.tonikelope.megabasterd.MiscTools.getApacheKissHttpClient;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
@ -23,12 +21,9 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
*/
|
*/
|
||||||
public class SmartMegaProxyManager implements Runnable {
|
public class SmartMegaProxyManager implements Runnable {
|
||||||
|
|
||||||
public static final int PROXY_TIMEOUT = 30;
|
public static final int PROXY_TIMEOUT = 15;
|
||||||
public static final int PROXY_MAX_EXCLUDE_COUNTER = 5;
|
|
||||||
public static final int PROXY_EXCLUDE_SECS = 10;
|
|
||||||
private volatile String _proxy_list_url;
|
private volatile String _proxy_list_url;
|
||||||
private final ConcurrentLinkedQueue<String> _proxy_list;
|
private final ConcurrentLinkedQueue<String> _proxy_list;
|
||||||
private final ConcurrentHashMap<String, HashMap> _proxy_info;
|
|
||||||
private final MainPanel _main_panel;
|
private final MainPanel _main_panel;
|
||||||
private volatile boolean _exit;
|
private volatile boolean _exit;
|
||||||
|
|
||||||
@ -36,7 +31,6 @@ public class SmartMegaProxyManager implements Runnable {
|
|||||||
_main_panel = main_panel;
|
_main_panel = main_panel;
|
||||||
_proxy_list_url = proxy_list_url;
|
_proxy_list_url = proxy_list_url;
|
||||||
_proxy_list = new ConcurrentLinkedQueue<>();
|
_proxy_list = new ConcurrentLinkedQueue<>();
|
||||||
_proxy_info = new ConcurrentHashMap<>();
|
|
||||||
_exit = false;
|
_exit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,57 +57,28 @@ public class SmartMegaProxyManager implements Runnable {
|
|||||||
|
|
||||||
public String getFastestProxy() {
|
public String getFastestProxy() {
|
||||||
|
|
||||||
for (String proxy : _proxy_list) {
|
return _proxy_list.peek();
|
||||||
|
|
||||||
HashMap<String, Object> proxy_info = (HashMap<String, Object>) _proxy_info.get(proxy);
|
|
||||||
|
|
||||||
Long extimestamp = (Long) proxy_info.get("extimestamp");
|
|
||||||
|
|
||||||
if (extimestamp == null || extimestamp + PROXY_EXCLUDE_SECS * 1000 < System.currentTimeMillis()) {
|
|
||||||
|
|
||||||
return proxy;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy is temporary excluded -> {1}", new Object[]{Thread.currentThread().getName(), proxy});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void excludeProxy(String proxy) {
|
public void removeProxy(String proxy) {
|
||||||
|
|
||||||
if (_proxy_info.containsKey(proxy)) {
|
if (_proxy_list.contains(proxy)) {
|
||||||
|
|
||||||
HashMap<String, Object> proxy_info = (HashMap<String, Object>) _proxy_info.get(proxy);
|
_proxy_list.remove(proxy);
|
||||||
|
|
||||||
int excount = (int) proxy_info.get("excount") + 1;
|
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
||||||
|
|
||||||
if (excount < PROXY_MAX_EXCLUDE_COUNTER) {
|
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy removed -> {1}", new Object[]{Thread.currentThread().getName(), proxy});
|
||||||
|
|
||||||
proxy_info.put("excount", excount);
|
if (_proxy_list.isEmpty()) {
|
||||||
|
|
||||||
proxy_info.put("extimestamp", System.currentTimeMillis());
|
THREAD_POOL.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
} else {
|
_refreshProxyList();
|
||||||
|
}
|
||||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy removed -> {1}", new Object[]{Thread.currentThread().getName(), proxy});
|
});
|
||||||
|
|
||||||
_proxy_list.remove(proxy);
|
|
||||||
_proxy_info.remove(proxy);
|
|
||||||
|
|
||||||
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
|
||||||
|
|
||||||
if (_proxy_list.isEmpty()) {
|
|
||||||
|
|
||||||
THREAD_POOL.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
_refreshProxyList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,23 +117,18 @@ public class SmartMegaProxyManager implements Runnable {
|
|||||||
if (proxy_list.length > 0) {
|
if (proxy_list.length > 0) {
|
||||||
|
|
||||||
_proxy_list.clear();
|
_proxy_list.clear();
|
||||||
_proxy_info.clear();
|
|
||||||
|
|
||||||
for (String proxy : proxy_list) {
|
for (String proxy : proxy_list) {
|
||||||
|
|
||||||
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
|
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
|
||||||
_proxy_list.add(proxy);
|
_proxy_list.add(proxy);
|
||||||
HashMap<String, Object> proxy_info = new HashMap<>();
|
|
||||||
proxy_info.put("extimestamp", null);
|
|
||||||
proxy_info.put("excount", 0);
|
|
||||||
_proxy_info.put(proxy.trim(), proxy_info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
|
|
||||||
|
|
||||||
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
||||||
|
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (MalformedURLException ex) {
|
} catch (MalformedURLException ex) {
|
||||||
|
@ -72,9 +72,7 @@ public class StreamChunkDownloader implements Runnable {
|
|||||||
|
|
||||||
if (error && current_proxy != null) {
|
if (error && current_proxy != null) {
|
||||||
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
MainPanel.getProxy_manager().removeProxy(current_proxy);
|
||||||
|
|
||||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user