Skip to content

Commit

Permalink
2.55
Browse files Browse the repository at this point in the history
  • Loading branch information
tonikelope committed Dec 17, 2017
1 parent 7e526db commit 8d6579a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 100 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().getFastestProxy(true);
current_proxy = _download.getMain_panel().getProxy_manager().getFastestProxy();

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.54";
public static final String VERSION = "2.55";
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
110 changes: 16 additions & 94 deletions src/megabasterd/SmartMegaProxyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -29,7 +27,6 @@ public class SmartMegaProxyManager implements Runnable {
public static final int REFRESH_PROXY_LIST_TIMEOUT = 1800;
private volatile String _proxy_list_url;
private final ConcurrentLinkedQueue<String> _proxy_list;
private final ConcurrentLinkedQueue<String> _excluded_proxies;
private final MainPanel _main_panel;
private volatile boolean _exit;
private volatile boolean _use_smart_proxy;
Expand All @@ -39,7 +36,6 @@ public SmartMegaProxyManager(MainPanel main_panel, String proxy_list_url) {
_main_panel = main_panel;
_proxy_list_url = proxy_list_url;
_proxy_list = new ConcurrentLinkedQueue<>();
_excluded_proxies = new ConcurrentLinkedQueue<>();
_exit = false;
_use_smart_proxy = false;
_refresh_lock = new Object();
Expand Down Expand Up @@ -68,6 +64,7 @@ public void setExit(boolean exit) {
}

public void setProxy_list_url(String proxy_list_url) {

_proxy_list_url = proxy_list_url;

THREAD_POOL.execute(new Runnable() {
Expand All @@ -86,104 +83,31 @@ public Object getRefresh_lock() {
return _refresh_lock;
}

public String getRandomProxy(boolean skip_excluded) {

synchronized (_refresh_lock) {

if (_proxy_list.size() > 0) {

if (skip_excluded && _excluded_proxies.size() > 0) {

ArrayList<String> available_proxys = new ArrayList<>();

for (String proxy : _proxy_list) {

if (!_excluded_proxies.contains(proxy)) {

available_proxys.add(proxy);
}
}

if (available_proxys.size() > 0) {

Random random = new Random();

return (String) available_proxys.toArray()[random.nextInt(available_proxys.size())];

} else {

return null;
}

} else {

Random random = new Random();

return (String) _proxy_list.toArray()[random.nextInt(_proxy_list.size())];
}

} else {

return null;
}
}
}

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 {
public String getFastestProxy() {

return _proxy_list.peek();
}

} else {

return null;
}
}
return _proxy_list.peek();
}

public void excludeProxy(String proxy) {

synchronized (_refresh_lock) {

if (!_excluded_proxies.contains(proxy)) {
if (_proxy_list.contains(proxy)) {

_excluded_proxies.add(proxy);
_proxy_list.remove(proxy);

swingReflectionInvoke("setText", _main_panel.getView().getSmart_proxy_status(), "SmartProxy: " + (_proxy_list.size() - _excluded_proxies.size()) + "/" + _proxy_list.size());
swingReflectionInvoke("setText", _main_panel.getView().getSmart_proxy_status(), "SmartProxy: " + _proxy_list.size());

if (_proxy_list.size() == _excluded_proxies.size()) {
if (_proxy_list.isEmpty()) {

_excluded_proxies.clear();
THREAD_POOL.execute(new Runnable() {
@Override
public void run() {

THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
synchronized (_refresh_lock) {

synchronized (_refresh_lock) {

_refreshProxyList();
}
_refreshProxyList();
}
});
}
}
});
}
}
}
Expand All @@ -195,6 +119,7 @@ private void _refreshProxyList() {
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)) {
Expand Down Expand Up @@ -235,12 +160,9 @@ private void _refreshProxyList() {
if (_use_smart_proxy) {

_use_smart_proxy = false;

_excluded_proxies.clear();
}

swingReflectionInvoke("setText", _main_panel.getView().getSmart_proxy_status(), "SmartProxy: " + (_proxy_list.size() - _excluded_proxies.size()) + "/" + _proxy_list.size());

swingReflectionInvoke("setText", _main_panel.getView().getSmart_proxy_status(), "SmartProxy: " + _proxy_list.size());
}

} catch (MalformedURLException ex) {
Expand Down
6 changes: 2 additions & 4 deletions 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().getFastestProxy(true);
current_proxy = _chunkwriter.getServer().getMain_panel().getProxy_manager().getFastestProxy();

if (httpclient != null) {
try {
Expand Down Expand Up @@ -191,9 +191,7 @@ public void run() {
}
}

} catch (IOException | URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (ChunkInvalidException | InterruptedException ex) {
} catch (IOException | URISyntaxException | ChunkInvalidException | InterruptedException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Expand Down

0 comments on commit 8d6579a

Please sign in to comment.