Skip to content

Commit f56d60b

Browse files
author
tonikelope
committed
2.30
1 parent b05a133 commit f56d60b

File tree

5 files changed

+1156
-1059
lines changed

5 files changed

+1156
-1059
lines changed

src/megabasterd/ChunkDownloader.java

+34-11
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
*/
2121
public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
2222

23+
public static final int DISABLE_SMART_PROXY_TIMEOUT = 3600;
2324
private final int _id;
2425
private final Download _download;
2526
private volatile boolean _exit;
2627
private final Object _secure_notify_lock;
2728
private volatile boolean _error_wait;
2829
private boolean _notified;
29-
private boolean _error_no_proxy;
30-
private String _proxy;
30+
private volatile boolean _use_smart_proxy;
3131

3232
public ChunkDownloader(int id, Download download) {
3333
_notified = false;
@@ -36,15 +36,15 @@ public ChunkDownloader(int id, Download download) {
3636
_id = id;
3737
_download = download;
3838
_error_wait = false;
39-
_error_no_proxy = false;
39+
_use_smart_proxy = false;
4040
}
4141

42-
public boolean isError_no_proxy() {
43-
return _error_no_proxy;
42+
public boolean isUse_smart_proxy() {
43+
return _use_smart_proxy;
4444
}
4545

46-
public void setError_no_proxy(boolean _error_no_proxy) {
47-
this._error_no_proxy = _error_no_proxy;
46+
public void setUse_smart_proxy(boolean value) {
47+
_use_smart_proxy = value;
4848
}
4949

5050
public void setExit(boolean exit) {
@@ -101,6 +101,24 @@ public void secureWait() {
101101

102102
@Override
103103
public void run() {
104+
105+
THREAD_POOL.execute(new Runnable() {
106+
107+
@Override
108+
public void run() {
109+
110+
while (!_exit) {
111+
112+
try {
113+
_use_smart_proxy = false;
114+
Thread.sleep(DISABLE_SMART_PROXY_TIMEOUT * 1000);
115+
} catch (InterruptedException ex) {
116+
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
117+
}
118+
}
119+
}
120+
});
121+
104122
String worker_url = null;
105123
Chunk chunk;
106124
int reads, conta_error, http_status;
@@ -120,13 +138,18 @@ public void run() {
120138

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

123-
if (httpclient == null || error || (MainPanel.isUse_smart_proxy() && _error_no_proxy)) {
141+
if (_use_smart_proxy && !MainPanel.isUse_smart_proxy()) {
142+
143+
_use_smart_proxy = false;
144+
}
145+
146+
if (httpclient == null || error || (MainPanel.isUse_smart_proxy() && _use_smart_proxy)) {
124147

125-
if (error) {
126-
_error_no_proxy = true;
148+
if (error && !_use_smart_proxy) {
149+
_use_smart_proxy = true;
127150
}
128151

129-
if (MainPanel.isUse_smart_proxy() && _error_no_proxy) {
152+
if (_use_smart_proxy && !MainPanel.isUse_proxy()) {
130153

131154
if (error && current_proxy != null) {
132155

src/megabasterd/ChunkDownloaderMono.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ public ChunkDownloaderMono(Download download) {
2626

2727
@Override
2828
public void run() {
29+
30+
THREAD_POOL.execute(new Runnable() {
31+
32+
@Override
33+
public void run() {
34+
35+
while (!isExit()) {
36+
37+
try {
38+
setUse_smart_proxy(false);
39+
Thread.sleep(ChunkDownloader.DISABLE_SMART_PROXY_TIMEOUT * 1000);
40+
} catch (InterruptedException ex) {
41+
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
42+
}
43+
}
44+
}
45+
});
46+
2947
String worker_url = null;
3048
String current_proxy = null;
3149
Chunk chunk;
@@ -47,13 +65,18 @@ public void run() {
4765

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

50-
if (httpclient == null || worker_url == null || error || (MainPanel.isUse_smart_proxy() && this.isError_no_proxy())) {
68+
if (this.isUse_smart_proxy() && !MainPanel.isUse_smart_proxy()) {
69+
70+
this.setUse_smart_proxy(false);
71+
}
72+
73+
if (httpclient == null || worker_url == null || error || (MainPanel.isUse_smart_proxy() && this.isUse_smart_proxy())) {
5174

52-
if (error) {
53-
this.setError_no_proxy(true);
75+
if (error && !this.isUse_smart_proxy()) {
76+
this.setUse_smart_proxy(true);
5477
}
5578

56-
if (MainPanel.isUse_smart_proxy() && this.isError_no_proxy()) {
79+
if (this.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
5780

5881
if (error && current_proxy != null) {
5982

@@ -84,7 +107,9 @@ public void run() {
84107
if (httpresponse != null) {
85108
httpresponse.close();
86109
}
110+
87111
}
112+
88113
chunk = new Chunk(getDownload().nextChunkId(), getDownload().getFile_size(), null);
89114

90115
try {

src/megabasterd/MainPanel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public final class MainPanel {
4747

48-
public static final String VERSION = "2.29";
48+
public static final String VERSION = "2.30";
4949
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
5050
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
5151
public static final int STREAMER_PORT = 1337;

0 commit comments

Comments
 (0)