From 77b5fdfc3aa417eadedc12b51ea9237727be47dc Mon Sep 17 00:00:00 2001 From: tonikelope Date: Wed, 7 Mar 2018 19:20:27 +0100 Subject: [PATCH] 3.1b --- .../tonikelope/megabasterd/ChunkWriter.java | 10 +++++---- .../megabasterd/UploadMACGenerator.java | 21 ++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/tonikelope/megabasterd/ChunkWriter.java b/src/main/java/com/tonikelope/megabasterd/ChunkWriter.java index 74c3ad5c4..ede755df4 100644 --- a/src/main/java/com/tonikelope/megabasterd/ChunkWriter.java +++ b/src/main/java/com/tonikelope/megabasterd/ChunkWriter.java @@ -110,9 +110,6 @@ public final class ChunkWriter implements Runnable, SecureSingleThreadNotifiable @Override public void run() { - Chunk current_chunk; - byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE]; - int reads; try { @@ -121,7 +118,12 @@ public final class ChunkWriter implements Runnable, SecureSingleThreadNotifiable if (_file_size > 0) { while (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) { while (_chunk_queue.containsKey(_last_chunk_id_written + 1)) { - current_chunk = _chunk_queue.remove(_last_chunk_id_written + 1); + + Chunk current_chunk = _chunk_queue.remove(_last_chunk_id_written + 1); + + byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE]; + + int reads; try (CipherInputStream cis = new CipherInputStream(current_chunk.getInputStream(), genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, forwardMEGALinkKeyIV(_byte_iv, _bytes_written)))) { while ((reads = cis.read(buffer)) != -1) { diff --git a/src/main/java/com/tonikelope/megabasterd/UploadMACGenerator.java b/src/main/java/com/tonikelope/megabasterd/UploadMACGenerator.java index 5d96b7145..3979045ab 100644 --- a/src/main/java/com/tonikelope/megabasterd/UploadMACGenerator.java +++ b/src/main/java/com/tonikelope/megabasterd/UploadMACGenerator.java @@ -93,8 +93,6 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot try { - Chunk chunk; - HashMap upload_progress = DBTools.selectUploadProgress(_upload.getFile_name(), _upload.getMa().getEmail()); int[] file_mac = new int[]{0, 0, 0, 0}; @@ -109,11 +107,8 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot int[] file_iv = bin2i32a(_upload.getByte_file_iv()), int_block, mac_iv = CryptTools.AES_ZERO_IV_I32A; - int reads; + boolean new_chunk = false, upload_workers_finish = false; - String temp_file_data; - boolean new_chunk = false; - boolean upload_workers_finish = false; Cipher cryptor = genCrypter("AES", "AES/CBC/NoPadding", _upload.getByte_file_key(), i32a2bin(mac_iv)); while (!_exit && (!_upload.isStopped() || !_upload.getChunkworkers().isEmpty()) && (_bytes_read < _upload.getFile_size() || (_upload.getFile_size() == 0 && _last_chunk_id_read < 1))) { @@ -135,11 +130,13 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot upload_workers_finish = true; } - chunk = _chunk_queue.remove(_last_chunk_id_read + 1); + int reads; - try (InputStream chunk_is = chunk.getInputStream()) { + Chunk current_chunk = _chunk_queue.remove(_last_chunk_id_read + 1); - if (Upload.CHUNK_SIZE_MULTI == 1 || chunk.getId() <= 7) { + try (InputStream chunk_is = current_chunk.getInputStream()) { + + if (Upload.CHUNK_SIZE_MULTI == 1 || current_chunk.getId() <= 7) { try { @@ -220,13 +217,13 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot } - _bytes_read += chunk.getSize(); + _bytes_read += current_chunk.getSize(); - _last_chunk_id_read = chunk.getId(); + _last_chunk_id_read = current_chunk.getId(); new_chunk = true; - temp_file_data = (String.valueOf(_bytes_read) + "|" + Bin2BASE64(i32a2bin(file_mac))); + String temp_file_data = (String.valueOf(_bytes_read) + "|" + Bin2BASE64(i32a2bin(file_mac))); Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Macgenerator -> {1} {2} {3} {4}", new Object[]{Thread.currentThread().getName(), temp_file_data, _upload.calculateLastUploadedChunk(_bytes_read), _last_chunk_id_read, this.getUpload().getFile_name()});