improved smoothing, stricter IO impl during encryption

This commit is contained in:
Sebastian Stenzel
2015-10-28 17:55:28 +01:00
parent 5fefa3c6d4
commit 55d1ffe703
2 changed files with 18 additions and 6 deletions

View File

@@ -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;

View File

@@ -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<Number, Number> decryptedBytes;
private final Series<Number, Number> 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<Number, Number> decryptedBytes, Series<Number, Number> 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<Number, Number>(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<Number, Number>(step, smoothedEncMb));
if (encryptedBytes.getData().size() > IO_SAMPLING_STEPS) {
encryptedBytes.getData().remove(0);