-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
further refactor inner classes of CryptoPathMapper to own class files
- Loading branch information
Showing
23 changed files
with
358 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.cryptomator.cryptofs; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
//own file due to dagger | ||
public record CipherDir(String dirId, Path contentDirPath) { | ||
|
||
public CipherDir(String dirId, Path contentDirPath) { | ||
this.dirId = Objects.requireNonNull(dirId); | ||
this.contentDirPath = Objects.requireNonNull(contentDirPath); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/cryptomator/cryptofs/CipherNodeNameParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.cryptomator.cryptofs; | ||
|
||
import java.util.Objects; | ||
|
||
//own file due to dagger | ||
public record CipherNodeNameParameters(String dirId, String clearNodeName) { | ||
|
||
public CipherNodeNameParameters(String dirId, String clearNodeName) { | ||
this.dirId = Objects.requireNonNull(dirId); | ||
this.clearNodeName = Objects.requireNonNull(clearNodeName); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/cryptomator/cryptofs/ClearToCipherDirCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.cryptomator.cryptofs; | ||
|
||
import com.github.benmanes.caffeine.cache.AsyncCache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ClearToCipherDirCache { | ||
|
||
private static final int MAX_CACHED_PATHS = 5000; | ||
private static final Duration MAX_CACHE_AGE = Duration.ofSeconds(20); | ||
|
||
//TODO: not testable! | ||
private final AsyncCache<CryptoPath, CipherDir> ciphertextDirectories = Caffeine.newBuilder() // | ||
.maximumSize(MAX_CACHED_PATHS) // | ||
.expireAfterWrite(MAX_CACHE_AGE) // | ||
.buildAsync(); | ||
|
||
//TODO: this a expensive operation | ||
// with a cachesize of _n_ and comparsion cost of _x_ | ||
// runtime is n*x | ||
void removeAllKeysWithPrefix(CryptoPath basePrefix) { | ||
ciphertextDirectories.asMap().keySet().removeIf(p -> p.startsWith(basePrefix)); | ||
} | ||
|
||
//TODO: this is a very expensive operation | ||
// with a cache size of _n_ and comparsion cost of _x_ | ||
// runtime is n*(1+x) | ||
void recomputeAllKeysWithPrefix(CryptoPath oldPrefix, CryptoPath newPrefix) { | ||
var remappedEntries = new ArrayList<Map.Entry<CryptoPath, CompletableFuture<CipherDir>>>(); | ||
ciphertextDirectories.asMap().entrySet().removeIf(e -> { | ||
if (e.getKey().startsWith(oldPrefix)) { | ||
var remappedPath = newPrefix.resolve(oldPrefix.relativize(e.getKey())); | ||
return remappedEntries.add(Map.entry(remappedPath, e.getValue())); | ||
} else { | ||
return false; | ||
} | ||
}); | ||
remappedEntries.forEach(e -> ciphertextDirectories.put(e.getKey(), e.getValue())); | ||
} | ||
|
||
//cheap operation: log(n) | ||
CipherDir putIfAbsent(CryptoPath cleartextPath, CipherDirLoader ifAbsent) throws IOException { | ||
var futureMapping = new CompletableFuture<CipherDir>(); | ||
var currentMapping = ciphertextDirectories.asMap().putIfAbsent(cleartextPath, futureMapping); | ||
if (currentMapping != null) { | ||
return currentMapping.join(); | ||
} else { | ||
futureMapping.complete(ifAbsent.load()); | ||
return futureMapping.join(); | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
interface CipherDirLoader { | ||
|
||
CipherDir load() throws IOException; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.