Trying to fix -> https://github.com/tonikelope/megabasterd/issues/282
This commit is contained in:
tonikelope 2021-01-04 13:48:19 +01:00
parent 71427a2762
commit 5847ff5cca
15 changed files with 70 additions and 66 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>7.37</version>
<version>7.38</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -97,7 +97,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(Level.SEVERE, ex.getMessage());

View File

@ -72,7 +72,7 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(Level.SEVERE, ex.getMessage());

View File

@ -113,7 +113,7 @@ public class ChunkWriterManager implements Runnable, SecureSingleThreadNotifiabl
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(Level.SEVERE, ex.getMessage());
@ -153,77 +153,81 @@ public class ChunkWriterManager implements Runnable, SecureSingleThreadNotifiabl
@Override
public void run() {
try {
LOG.log(Level.INFO, "{0} ChunkWriterManager: let's do some work! {1}", new Object[]{Thread.currentThread().getName(), _download.getFile_name()});
LOG.log(Level.INFO, "{0} ChunkWriterManager LAST CHUNK WRITTEN -> [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written, _download.getFile_name()});
boolean download_finished = false;
if (_file_size > 0) {
while (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
LOG.log(Level.INFO, "{0} ChunkWriterManager: let's do some work! {1}", new Object[]{Thread.currentThread().getName(), _download.getFile_name()});
boolean chunk_io_error;
LOG.log(Level.INFO, "{0} ChunkWriterManager LAST CHUNK WRITTEN -> [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written, _download.getFile_name()});
do {
boolean download_finished = false;
chunk_io_error = false;
if (_file_size > 0) {
while (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
try {
File chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
File chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
while (chunk_file.exists() && chunk_file.canRead()) {
while (chunk_file.exists() && chunk_file.canRead() && chunk_file.length() > 0) {
if (!download_finished && _download.getProgress() == _file_size) {
if (!download_finished && _download.getProgress() == _file_size) {
_download.getMain_panel().getDownload_manager().getTransference_running_list().remove(_download);
_download.getMain_panel().getDownload_manager().secureNotify();
_download.getMain_panel().getDownload_manager().getTransference_running_list().remove(_download);
_download.getMain_panel().getDownload_manager().secureNotify();
_download.getView().printStatusNormal("Download finished. Joining file chunks, please wait...");
_download.getView().getPause_button().setVisible(false);
_download.getMain_panel().getGlobal_dl_speed().detachTransference(_download);
_download.getView().getSpeed_label().setVisible(false);
_download.getView().getSlots_label().setVisible(false);
_download.getView().getSlot_status_label().setVisible(false);
_download.getView().getSlots_spinner().setVisible(false);
download_finished = true;
}
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
try (CipherInputStream cis = new CipherInputStream(new BufferedInputStream(new FileInputStream(chunk_file)), genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, forwardMEGALinkKeyIV(_byte_iv, _bytes_written)))) {
while ((reads = cis.read(buffer)) != -1) {
_download.getOutput_stream().write(buffer, 0, reads);
_download.getView().printStatusNormal("Download finished. Joining file chunks, please wait...");
_download.getView().getPause_button().setVisible(false);
_download.getMain_panel().getGlobal_dl_speed().detachTransference(_download);
_download.getView().getSpeed_label().setVisible(false);
_download.getView().getSlots_label().setVisible(false);
_download.getView().getSlot_status_label().setVisible(false);
_download.getView().getSlots_spinner().setVisible(false);
download_finished = true;
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
try (CipherInputStream cis = new CipherInputStream(new BufferedInputStream(new FileInputStream(chunk_file)), genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, forwardMEGALinkKeyIV(_byte_iv, _bytes_written)))) {
while ((reads = cis.read(buffer)) != -1) {
_download.getOutput_stream().write(buffer, 0, reads);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}
_bytes_written += chunk_file.length();
_last_chunk_id_written++;
LOG.log(Level.INFO, "{0} ChunkWriterManager has written to disk chunk [{1}] {2} {3} {4}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written, _download.calculateLastWrittenChunk(_bytes_written), _download.getFile_name()});
chunk_file.delete();
chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
}
_bytes_written += chunk_file.length();
LOG.log(Level.INFO, "{0} ChunkWriterManager has written to disk chunk [{1}] {2} {3} {4}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _bytes_written, _download.calculateLastWrittenChunk(_bytes_written), _download.getFile_name()});
_last_chunk_id_written++;
chunk_file.delete();
chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
} catch (IOException ex) {
chunk_io_error = true;
LOG.log(Level.WARNING, ex.getMessage());
MiscTools.pausar(1000);
}
} while (chunk_io_error);
if (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
if (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
LOG.log(Level.INFO, "{0} ChunkWriterManager waiting for chunk [{1}] {2}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _download.getFile_name()});
LOG.log(Level.INFO, "{0} ChunkWriterManager waiting for chunk [{1}] {2}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _download.getFile_name()});
secureWait();
secureWait();
}
}
if (_bytes_written == _file_size) {
delete_chunks_temp_dir();
}
}
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
_download.stopDownloader(ex.getMessage());
if (_bytes_written == _file_size) {
delete_chunks_temp_dir();
}
}
_exit = true;

View File

@ -81,7 +81,7 @@ public class ClipboardSpy implements Runnable, ClipboardOwner, SecureSingleThrea
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
LOG.log(SEVERE, ex.getMessage());
}

View File

@ -1621,7 +1621,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(SEVERE, null, ex);

View File

@ -87,7 +87,7 @@ public class KissVideoStreamServer implements HttpHandler, SecureSingleThreadNot
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
LOG.log(SEVERE, null, ex);
}

View File

@ -60,7 +60,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
public static final String VERSION = "7.37";
public static final String VERSION = "7.38";
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;

View File

@ -47,7 +47,7 @@ public class ProgressMeter implements Runnable, SecureSingleThreadNotifiable {
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(SEVERE, null, ex);

View File

@ -170,7 +170,7 @@ public class StreamChunkManager implements Runnable, SecureMultiThreadNotifiable
while (!_notified_threads.get(current_thread)) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}

View File

@ -96,7 +96,7 @@ public class StreamThrottlerSupervisor implements Runnable, SecureMultiThreadNot
while (!_notified_threads.get(current_thread)) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}

View File

@ -212,7 +212,7 @@ abstract public class TransferenceManager implements Runnable, SecureSingleThrea
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}

View File

@ -360,7 +360,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(Level.SEVERE, ex.getMessage());

View File

@ -49,7 +49,7 @@ public class UploadMACGenerator implements Runnable, SecureSingleThreadNotifiabl
while (!_notified) {
try {
_secure_notify_lock.wait();
_secure_notify_lock.wait(1000);
} catch (InterruptedException ex) {
_exit = true;
LOG.log(Level.SEVERE, ex.getMessage());

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

After

Width:  |  Height:  |  Size: 180 KiB