Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit c27c782

Browse files
committed
Refactoring cloud configuration:
* Removing NetworkTimeouts class from API package * adding config class to vaultformat8provider and webdav package (with own system properties!) * vaultformat8provider configurable
1 parent 329e642 commit c27c782

File tree

10 files changed

+79
-73
lines changed

10 files changed

+79
-73
lines changed

src/main/java/org/cryptomator/cloudaccess/CloudAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static CloudProvider vaultFormat8GCMCloudAccess(CloudProvider cloudProvid
6060

6161
VaultFormat8ProviderDecorator provider = new VaultFormat8ProviderDecorator(cloudProvider, pathToVault.resolve("d"), cryptor);
6262
provider.initialize();
63-
return new MetadataCachingProviderDecorator(provider, Duration.ofSeconds(Long.getLong("org.cryptomator.cloudaccess.cryptometadatatimeout", 10L)));
63+
return new MetadataCachingProviderDecorator(provider);
6464
} catch (NoSuchAlgorithmException e) {
6565
throw new IllegalStateException("JVM doesn't supply a CSPRNG", e);
6666
} catch (InterruptedException e) {

src/main/java/org/cryptomator/cloudaccess/MetadataCachingProviderDecorator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public class MetadataCachingProviderDecorator implements CloudProvider {
2626
private final CloudProvider delegate;
2727

2828
public MetadataCachingProviderDecorator(CloudProvider delegate) {
29-
this(delegate, Duration.ofSeconds(DEFAULT_CACHE_TIMEOUT_SECONDS));
29+
this(delegate, Duration.ofSeconds( //
30+
Integer.getInteger("org.cryptomator.cloudaccess.metadatacachingprovider.timeoutSeconds", DEFAULT_CACHE_TIMEOUT_SECONDS)
31+
));
3032
}
3133

3234
public MetadataCachingProviderDecorator(CloudProvider delegate, Duration cacheEntryMaxAge) {

src/main/java/org/cryptomator/cloudaccess/api/NetworkTimeouts.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/main/java/org/cryptomator/cloudaccess/vaultformat8/FileHeaderCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
class FileHeaderCache {
1616

17-
private static final Duration TIMEOUT = Duration.ofMillis(1000);
1817
private static final Logger LOG = LoggerFactory.getLogger(FileHeaderCache.class);
1918

20-
private final Cache<CloudPath, FileHeader> cache = CacheBuilder.newBuilder().expireAfterAccess(TIMEOUT).build();
19+
private final Cache<CloudPath, FileHeader> cache;
20+
21+
FileHeaderCache(int timeoutMillis) {
22+
this.cache = CacheBuilder.newBuilder().expireAfterAccess(Duration.ofMillis(timeoutMillis)).build();
23+
}
24+
2125

2226
public CompletionStage<FileHeader> get(CloudPath ciphertextPath, Function<CloudPath, CompletionStage<FileHeader>> onMiss) {
2327
var cached = cache.getIfPresent(ciphertextPath);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.cryptomator.cloudaccess.vaultformat8;
2+
3+
public class VaultFormat8ProviderConfig {
4+
5+
private static final int DEFAULT_FILEHEADER_TIMEOUT = 1000;
6+
7+
private final int fileHeaderCacheTimeoutMillis;
8+
9+
private VaultFormat8ProviderConfig(){
10+
this.fileHeaderCacheTimeoutMillis = Integer.getInteger("org.cryptomator.cloudaccess.vaultformat8.fileheadertimeoutMillis", DEFAULT_FILEHEADER_TIMEOUT);
11+
}
12+
13+
public static VaultFormat8ProviderConfig createFromSystemProperties(){
14+
return new VaultFormat8ProviderConfig();
15+
}
16+
17+
int getFileHeaderCacheTimeoutMillis() {
18+
return fileHeaderCacheTimeoutMillis;
19+
}
20+
}

src/main/java/org/cryptomator/cloudaccess/vaultformat8/VaultFormat8ProviderDecorator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ public class VaultFormat8ProviderDecorator implements CloudProvider {
4747
private final Cryptor cryptor;
4848
private final DirectoryIdCache dirIdCache;
4949
private final FileHeaderCache fileHeaderCache;
50+
private final VaultFormat8ProviderConfig config;
5051

5152
public VaultFormat8ProviderDecorator(CloudProvider delegate, CloudPath dataDir, Cryptor cryptor) {
5253
this.delegate = delegate;
5354
this.dataDir = dataDir;
5455
this.cryptor = cryptor;
56+
this.config = VaultFormat8ProviderConfig.createFromSystemProperties();
5557
this.dirIdCache = new DirectoryIdCache();
56-
this.fileHeaderCache = new FileHeaderCache();
58+
this.fileHeaderCache = new FileHeaderCache(config.getFileHeaderCacheTimeoutMillis());
5759
}
5860

5961
public void initialize() throws InterruptedException, CloudProviderException {

src/main/java/org/cryptomator/cloudaccess/webdav/WebDavClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ private enum PropfindDepth {
349349

350350
static class WebDavAuthenticator {
351351

352-
static WebDavClient createAuthenticatedWebDavClient(final WebDavCredential webDavCredential) throws ServerNotWebdavCompatibleException, UnauthorizedException {
353-
final var webDavClient = new WebDavClient(new WebDavCompatibleHttpClient(webDavCredential), webDavCredential);
352+
static WebDavClient createAuthenticatedWebDavClient(final WebDavCredential webDavCredential, WebDavProviderConfig config) throws ServerNotWebdavCompatibleException, UnauthorizedException {
353+
final var webDavClient = new WebDavClient(new WebDavCompatibleHttpClient(webDavCredential, config), webDavCredential);
354354

355355
webDavClient.checkServerCompatibility();
356356
webDavClient.tryAuthenticatedRequest();

src/main/java/org/cryptomator/cloudaccess/webdav/WebDavCloudProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
public class WebDavCloudProvider implements CloudProvider {
1717

1818
private final WebDavClient webDavClient;
19+
private final WebDavProviderConfig config;
1920

2021
private WebDavCloudProvider(final WebDavCredential webDavCredential) {
21-
webDavClient = WebDavClient.WebDavAuthenticator.createAuthenticatedWebDavClient(webDavCredential);
22+
config = WebDavProviderConfig.createFromSystemPropertiesOrDefaults();
23+
webDavClient = WebDavClient.WebDavAuthenticator.createAuthenticatedWebDavClient(webDavCredential, config);
2224
}
2325

2426
public static WebDavCloudProvider from(final WebDavCredential webDavCredential) throws UnauthorizedException, ServerNotWebdavCompatibleException {

src/main/java/org/cryptomator/cloudaccess/webdav/WebDavCompatibleHttpClient.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,36 @@
1111
import okhttp3.OkHttpClient;
1212
import okhttp3.Request;
1313
import okhttp3.Response;
14-
import org.cryptomator.cloudaccess.api.NetworkTimeouts;
1514
import org.slf4j.Logger;
1615
import org.slf4j.LoggerFactory;
1716

1817
import java.io.IOException;
1918
import java.nio.charset.StandardCharsets;
2019
import java.util.Map;
2120
import java.util.concurrent.ConcurrentHashMap;
21+
import java.util.concurrent.TimeUnit;
2222

2323
class WebDavCompatibleHttpClient {
2424

2525
private static final Logger LOG = LoggerFactory.getLogger(WebDavCompatibleHttpClient.class);
2626

2727
private final WebDavRedirectHandler webDavRedirectHandler;
2828

29-
WebDavCompatibleHttpClient(final WebDavCredential webDavCredential) {
30-
this.webDavRedirectHandler = new WebDavRedirectHandler(httpClientFor(webDavCredential));
29+
WebDavCompatibleHttpClient(final WebDavCredential webDavCredential, WebDavProviderConfig config) {
30+
this.webDavRedirectHandler = new WebDavRedirectHandler(httpClientFor(webDavCredential, config));
3131
}
3232

33-
private static OkHttpClient httpClientFor(final WebDavCredential webDavCredential) {
33+
private static OkHttpClient httpClientFor(final WebDavCredential webDavCredential, WebDavProviderConfig config) {
3434
final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
35-
var networkTimeouts = NetworkTimeouts.createBySystemPropertiesOrDefaults();
3635
final var builder = new OkHttpClient()
3736
.newBuilder()
38-
.connectTimeout(networkTimeouts.connection().getTimeout(), networkTimeouts.connection().getUnit())
39-
.readTimeout(networkTimeouts.read().getTimeout(), networkTimeouts.read().getUnit())
40-
.writeTimeout(networkTimeouts.write().getTimeout(), networkTimeouts.write().getUnit())
37+
.connectTimeout(config.getConnectionTimeoutSeconds(), TimeUnit.SECONDS)
38+
.readTimeout(config.getReadTimeoutSeconds(), TimeUnit.SECONDS)
39+
.writeTimeout(config.getWriteTimeoutSeconds(), TimeUnit.SECONDS)
4140
.followRedirects(false)
4241
.addInterceptor(new HttpLoggingInterceptor(LOG::trace))
4342
.authenticator(httpAuthenticator(webDavCredential.getUsername(), webDavCredential.getPassword(), authCache))
4443
.addInterceptor(new AuthenticationCacheInterceptor(authCache));
45-
4644
return builder.build();
4745
}
4846

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.cryptomator.cloudaccess.webdav;
2+
3+
public class WebDavProviderConfig {
4+
5+
private static final int DEFAULT_CONNECTION_TIMEOUT = 30;
6+
private static final int DEFAULT_READ_TIMEOUT = 30;
7+
private static final int DEFAULT_WRITE_TIMEOUT = 30;
8+
9+
private final int connectionTimeoutSeconds;
10+
private final int readTimeoutSeconds;
11+
private final int writeTimeoutSeconds;
12+
13+
WebDavProviderConfig() {
14+
this.connectionTimeoutSeconds = Integer.getInteger("org.cryptomator.cloudaccess.webdav.connectionTimeoutSeconds", DEFAULT_CONNECTION_TIMEOUT);
15+
this.readTimeoutSeconds = Integer.getInteger("org.cryptomator.cloudaccess.webdav.readTimeoutSeconds", DEFAULT_READ_TIMEOUT);
16+
this.writeTimeoutSeconds = Integer.getInteger("org.cryptomator.cloudaccess.webdav.writeTimeoutSeconds", DEFAULT_WRITE_TIMEOUT);
17+
}
18+
19+
public static WebDavProviderConfig createFromSystemPropertiesOrDefaults() {
20+
return new WebDavProviderConfig();
21+
}
22+
23+
int getConnectionTimeoutSeconds() {
24+
return connectionTimeoutSeconds;
25+
}
26+
27+
int getReadTimeoutSeconds() {
28+
return readTimeoutSeconds;
29+
}
30+
31+
int getWriteTimeoutSeconds() {
32+
return writeTimeoutSeconds;
33+
}
34+
}

0 commit comments

Comments
 (0)