From 55d1ffe70366ffe184a265e863732a6709ac8d28 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 28 Oct 2015 17:55:28 +0100 Subject: [PATCH] improved smoothing, stricter IO impl during encryption --- .../crypto/aes256/LengthObfuscatingInputStream.java | 11 +++++++++++ .../ui/controllers/UnlockedController.java | 13 +++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main/crypto-aes/src/main/java/org/cryptomator/crypto/aes256/LengthObfuscatingInputStream.java b/main/crypto-aes/src/main/java/org/cryptomator/crypto/aes256/LengthObfuscatingInputStream.java index e41f1c728..498fa0f29 100644 --- a/main/crypto-aes/src/main/java/org/cryptomator/crypto/aes256/LengthObfuscatingInputStream.java +++ b/main/crypto-aes/src/main/java/org/cryptomator/crypto/aes256/LengthObfuscatingInputStream.java @@ -109,6 +109,17 @@ public class LengthObfuscatingInputStream extends FilterInputStream { throw new IOException("Skip not supported"); } + @Override + public int available() throws IOException { + if (paddingLength == -1) { + // EOF not yet reached; delegate original stream to answer this rather complicated question: + return in.available(); + } else { + // EOF already reached, read from remaining padding: + return paddingLength - paddingBytesRead; + } + } + @Override public boolean markSupported() { return false; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java index b5ed0f052..06555e177 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java @@ -147,12 +147,13 @@ public class UnlockedController extends AbstractFXMLViewController { private static final double BYTES_TO_MEGABYTES_FACTOR = 1.0 / IO_SAMPLING_INTERVAL / 1024.0 / 1024.0; private static final double SMOOTHING_FACTOR = 0.3; + private static final long EFFECTIVELY_ZERO = 100000; // 100kb private final CryptorIOSampling sampler; private final Series decryptedBytes; private final Series encryptedBytes; private int step = 0; - private double oldDecBytes = 0; - private double oldEncBytes = 0; + private long oldDecBytes = 0; + private long oldEncBytes = 0; public IoSamplingAnimationHandler(CryptorIOSampling sampler, Series decryptedBytes, Series encryptedBytes) { this.sampler = sampler; @@ -164,19 +165,19 @@ public class UnlockedController extends AbstractFXMLViewController { public void handle(ActionEvent event) { step++; - final double decBytes = sampler.pollDecryptedBytes(true); + final long decBytes = sampler.pollDecryptedBytes(true); final double smoothedDecBytes = oldDecBytes + SMOOTHING_FACTOR * (decBytes - oldDecBytes); final double smoothedDecMb = smoothedDecBytes * BYTES_TO_MEGABYTES_FACTOR; - oldDecBytes = smoothedDecBytes; + oldDecBytes = smoothedDecBytes > EFFECTIVELY_ZERO ? (long) smoothedDecBytes : 0l; decryptedBytes.getData().add(new Data(step, smoothedDecMb)); if (decryptedBytes.getData().size() > IO_SAMPLING_STEPS) { decryptedBytes.getData().remove(0); } - final double encBytes = sampler.pollEncryptedBytes(true); + final long encBytes = sampler.pollEncryptedBytes(true); final double smoothedEncBytes = oldEncBytes + SMOOTHING_FACTOR * (encBytes - oldEncBytes); final double smoothedEncMb = smoothedEncBytes * BYTES_TO_MEGABYTES_FACTOR; - oldEncBytes = smoothedEncBytes; + oldEncBytes = smoothedEncBytes > EFFECTIVELY_ZERO ? (long) smoothedEncBytes : 0l; encryptedBytes.getData().add(new Data(step, smoothedEncMb)); if (encryptedBytes.getData().size() > IO_SAMPLING_STEPS) { encryptedBytes.getData().remove(0);