mirror of https://github.com/zlatinb/muwire
cache hidden roots as they are likely to repeat a lot
parent
f9290ffcaf
commit
da2d006405
|
@ -44,6 +44,7 @@ class PersisterFolderService extends BasePersisterService {
|
||||||
|
|
||||||
private final byte[] salt
|
private final byte[] salt
|
||||||
private final String saltHash
|
private final String saltHash
|
||||||
|
private final Map<Path, String> cachedRoots = Collections.synchronizedMap(new HashMap<>())
|
||||||
private final Core core;
|
private final Core core;
|
||||||
final File location
|
final File location
|
||||||
final EventBus listener
|
final EventBus listener
|
||||||
|
@ -270,11 +271,17 @@ class PersisterFolderService extends BasePersisterService {
|
||||||
Path toParent = root.toPath().relativize(parent.toPath())
|
Path toParent = root.toPath().relativize(parent.toPath())
|
||||||
Path visible = Path.of(root.getName(), toParent.toString())
|
Path visible = Path.of(root.getName(), toParent.toString())
|
||||||
Path invisible = root.getParentFile().toPath()
|
Path invisible = root.getParentFile().toPath()
|
||||||
|
|
||||||
|
String invisbleRoot = cachedRoots.computeIfAbsent(invisible, {mac(it)})
|
||||||
|
return Path.of(invisbleRoot, visible.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mac(Path path) {
|
||||||
Mac mac = Mac.getInstance("HmacSHA256")
|
Mac mac = Mac.getInstance("HmacSHA256")
|
||||||
Key key = new HMACKey(salt)
|
Key key = new HMACKey(salt)
|
||||||
mac.init(key)
|
mac.init(key)
|
||||||
mac.update(invisible.toString().getBytes(StandardCharsets.UTF_8))
|
mac.update(path.toString().getBytes(StandardCharsets.UTF_8))
|
||||||
return Path.of(Base64.encode(mac.doFinal()), visible.toString())
|
Base64.encode(mac.doFinal())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,11 +298,8 @@ class PersisterFolderService extends BasePersisterService {
|
||||||
Path toParent = explicitParent.toPath().relativize(parent.toPath())
|
Path toParent = explicitParent.toPath().relativize(parent.toPath())
|
||||||
Path visible = Path.of(explicitParent.getName(), toParent.toString())
|
Path visible = Path.of(explicitParent.getName(), toParent.toString())
|
||||||
Path invisible = explicitParent.getParentFile().toPath()
|
Path invisible = explicitParent.getParentFile().toPath()
|
||||||
Mac mac = Mac.getInstance("HmacSHA256")
|
String invisibleRoot = cachedRoots.computeIfAbsent(invisible,{mac(it)})
|
||||||
Key key = new HMACKey(salt)
|
return Path.of(invisibleRoot, visible.toString())
|
||||||
mac.init(key)
|
|
||||||
mac.update(invisible.toString().getBytes(StandardCharsets.UTF_8))
|
|
||||||
return Path.of(Base64.encode(mac.doFinal()), visible.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistFile(SharedFile sf, InfoHash ih) {
|
private void persistFile(SharedFile sf, InfoHash ih) {
|
||||||
|
|
Loading…
Reference in New Issue