- fixed size obfuscation padding

- fixed behaviour when serving invalid content ranges, thus improving random access performance (thats why we created the 0.8.2 workaround)
- reduced loglevels of some frequent messages
This commit is contained in:
Sebastian Stenzel
2015-10-03 13:10:28 +02:00
parent 6d1e0fe609
commit 09b4130c3e
10 changed files with 48 additions and 193 deletions
@@ -40,7 +40,6 @@ public final class WebDavServer {
private static final int MAX_THREADS = 200;
private static final int MIN_THREADS = 4;
private static final int THREAD_IDLE_SECONDS = 20;
private static final int CONNECTION_IDLE_MILLIS = 100; // idle connection slow down random access on WebDAVFS for some reason. reconnect overhead can be tolerated
private final Server server;
private final ServerConnector localConnector;
private final ContextHandlerCollection servletCollection;
@@ -51,7 +50,6 @@ public final class WebDavServer {
server = new Server(tp);
localConnector = new ServerConnector(server);
localConnector.setHost(LOCALHOST);
localConnector.setIdleTimeout(CONNECTION_IDLE_MILLIS);
servletCollection = new ContextHandlerCollection();
if (SystemUtils.IS_OS_WINDOWS) {
@@ -108,8 +108,9 @@ class EncryptedFile extends AbstractEncryptedNode implements FileConstants {
if (outputContext.hasStream()) {
final boolean authenticate = !cryptoWarningHandler.ignoreMac(getLocator().getResourcePath());
cryptor.decryptFile(c, outputContext.getOutputStream(), authenticate);
outputContext.getOutputStream().flush();
}
outputContext.getOutputStream().flush();
} catch (EOFException e) {
LOG.warn("Unexpected end of stream (possibly client hung up).");
}
@@ -41,7 +41,7 @@ class EncryptedFilePart extends EncryptedFile {
} else if (upper == null) {
range = new ImmutablePair<Long, Long>(lower, contentLength - 1);
} else {
range = new ImmutablePair<Long, Long>(lower, upper);
range = new ImmutablePair<Long, Long>(lower, Math.min(upper, contentLength - 1));
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid byte range: " + requestRange, e);
@@ -51,27 +51,31 @@ class EncryptedFilePart extends EncryptedFile {
@Override
public void spool(OutputContext outputContext) throws IOException {
assert Files.isRegularFile(filePath);
assert this.contentLength != null;
assert contentLength != null;
final Long rangeLength = range.getRight() - range.getLeft() + 1;
final Long rangeLength = range.getRight() - range.getLeft();
outputContext.setModificationTime(Files.getLastModifiedTime(filePath).toMillis());
if (rangeLength <= 0) {
if (rangeLength <= 0 || range.getLeft() > contentLength - 1) {
// unsatisfiable content range:
outputContext.setContentLength(0);
outputContext.setProperty(HttpHeader.CONTENT_RANGE.asString(), getContentRangeHeader(range.getRight(), range.getRight(), contentLength));
LOG.debug("Unsatisfiable content range: " + getContentRangeHeader(range.getLeft(), range.getRight(), contentLength));
outputContext.setProperty(HttpHeader.CONTENT_RANGE.asString(), "bytes */" + contentLength);
LOG.debug("Requested content range unsatisfiable: " + getContentRangeHeader(range.getLeft(), range.getRight(), contentLength));
return;
} else {
outputContext.setContentLength(rangeLength);
outputContext.setProperty(HttpHeader.CONTENT_RANGE.asString(), getContentRangeHeader(range.getLeft(), range.getRight(), contentLength));
}
assert range.getLeft() > 0;
assert range.getLeft() < contentLength;
assert range.getRight() < contentLength;
try (final FileChannel c = FileChannel.open(filePath, StandardOpenOption.READ)) {
if (outputContext.hasStream()) {
final boolean authenticate = !cryptoWarningHandler.ignoreMac(getLocator().getResourcePath());
cryptor.decryptRange(c, outputContext.getOutputStream(), range.getLeft(), rangeLength, authenticate);
outputContext.getOutputStream().flush();
}
outputContext.getOutputStream().flush();
} catch (EOFException e) {
if (LOG.isDebugEnabled()) {
LOG.trace("Unexpected end of stream during delivery of partial content (client hung up).");
@@ -39,7 +39,7 @@ class SilentlyFailingFileLock implements AutoCloseable {
lock = channel.tryLock(position, size, shared);
} catch (IOException | OverlappingFileLockException e) {
if (LOG.isDebugEnabled()) {
LOG.warn("Unable to lock file.");
LOG.trace("Unable to lock file.");
}
} finally {
this.lock = lock;
@@ -95,7 +95,7 @@ public class WebDavServlet extends AbstractWebdavServlet {
super.doPut(request, response, resource);
if (LOG.isDebugEnabled()) {
long t1 = System.nanoTime();
LOG.debug("PUT TIME: " + (t1 - t0) / 1000 / 1000.0 + " ms");
LOG.trace("PUT TIME: " + (t1 - t0) / 1000 / 1000.0 + " ms");
}
}
@@ -111,7 +111,7 @@ public class WebDavServlet extends AbstractWebdavServlet {
}
if (LOG.isDebugEnabled()) {
long t1 = System.nanoTime();
LOG.debug("GET TIME: " + (t1 - t0) / 1000 / 1000.0 + " ms");
LOG.trace("GET TIME: " + (t1 - t0) / 1000 / 1000.0 + " ms");
}
}