Skip to content

Commit

Permalink
2.54
Browse files Browse the repository at this point in the history
  • Loading branch information
tonikelope committed Dec 16, 2017
1 parent 30b1b3d commit 7e526db
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/megabasterd/ChunkDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 43 additions & 13 deletions src/megabasterd/SmartMegaProxyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
}
});
}
}
}
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/megabasterd/StreamChunkDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7e526db

Please sign in to comment.