Skip to content

Commit

Permalink
2.30
Browse files Browse the repository at this point in the history
  • Loading branch information
tonikelope committed Nov 27, 2017
1 parent b05a133 commit f56d60b
Show file tree
Hide file tree
Showing 5 changed files with 1,156 additions and 1,059 deletions.
45 changes: 34 additions & 11 deletions src/megabasterd/ChunkDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*/
public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {

public static final int DISABLE_SMART_PROXY_TIMEOUT = 3600;
private final int _id;
private final Download _download;
private volatile boolean _exit;
private final Object _secure_notify_lock;
private volatile boolean _error_wait;
private boolean _notified;
private boolean _error_no_proxy;
private String _proxy;
private volatile boolean _use_smart_proxy;

public ChunkDownloader(int id, Download download) {
_notified = false;
Expand All @@ -36,15 +36,15 @@ public ChunkDownloader(int id, Download download) {
_id = id;
_download = download;
_error_wait = false;
_error_no_proxy = false;
_use_smart_proxy = false;
}

public boolean isError_no_proxy() {
return _error_no_proxy;
public boolean isUse_smart_proxy() {
return _use_smart_proxy;
}

public void setError_no_proxy(boolean _error_no_proxy) {
this._error_no_proxy = _error_no_proxy;
public void setUse_smart_proxy(boolean value) {
_use_smart_proxy = value;
}

public void setExit(boolean exit) {
Expand Down Expand Up @@ -101,6 +101,24 @@ public void secureWait() {

@Override
public void run() {

THREAD_POOL.execute(new Runnable() {

@Override
public void run() {

while (!_exit) {

try {
_use_smart_proxy = false;
Thread.sleep(DISABLE_SMART_PROXY_TIMEOUT * 1000);
} catch (InterruptedException ex) {
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});

String worker_url = null;
Chunk chunk;
int reads, conta_error, http_status;
Expand All @@ -120,13 +138,18 @@ public void run() {

while (!_exit && !_download.isStopped()) {

if (httpclient == null || error || (MainPanel.isUse_smart_proxy() && _error_no_proxy)) {
if (_use_smart_proxy && !MainPanel.isUse_smart_proxy()) {

_use_smart_proxy = false;
}

if (httpclient == null || error || (MainPanel.isUse_smart_proxy() && _use_smart_proxy)) {

if (error) {
_error_no_proxy = true;
if (error && !_use_smart_proxy) {
_use_smart_proxy = true;
}

if (MainPanel.isUse_smart_proxy() && _error_no_proxy) {
if (_use_smart_proxy && !MainPanel.isUse_proxy()) {

if (error && current_proxy != null) {

Expand Down
33 changes: 29 additions & 4 deletions src/megabasterd/ChunkDownloaderMono.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ public ChunkDownloaderMono(Download download) {

@Override
public void run() {

THREAD_POOL.execute(new Runnable() {

@Override
public void run() {

while (!isExit()) {

try {
setUse_smart_proxy(false);
Thread.sleep(ChunkDownloader.DISABLE_SMART_PROXY_TIMEOUT * 1000);
} catch (InterruptedException ex) {
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});

String worker_url = null;
String current_proxy = null;
Chunk chunk;
Expand All @@ -47,13 +65,18 @@ public void run() {

while (!isExit() && !getDownload().isStopped()) {

if (httpclient == null || worker_url == null || error || (MainPanel.isUse_smart_proxy() && this.isError_no_proxy())) {
if (this.isUse_smart_proxy() && !MainPanel.isUse_smart_proxy()) {

this.setUse_smart_proxy(false);
}

if (httpclient == null || worker_url == null || error || (MainPanel.isUse_smart_proxy() && this.isUse_smart_proxy())) {

if (error) {
this.setError_no_proxy(true);
if (error && !this.isUse_smart_proxy()) {
this.setUse_smart_proxy(true);
}

if (MainPanel.isUse_smart_proxy() && this.isError_no_proxy()) {
if (this.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {

if (error && current_proxy != null) {

Expand Down Expand Up @@ -84,7 +107,9 @@ public void run() {
if (httpresponse != null) {
httpresponse.close();
}

}

chunk = new Chunk(getDownload().nextChunkId(), getDownload().getFile_size(), 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.29";
public static final String VERSION = "2.30";
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
Loading

0 comments on commit f56d60b

Please sign in to comment.