generate prekeys on cpu executor

This commit is contained in:
Daniel Gultsch 2023-02-25 07:21:00 +01:00
parent 2abcb1b4e4
commit 677cfcd34c
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
4 changed files with 15 additions and 8 deletions

View file

@ -94,7 +94,8 @@ public class Transformer {
try { try {
final var payload = axolotlService.decrypt(transformation.from, encrypted); final var payload = axolotlService.decrypt(transformation.from, encrypted);
if (payload.hasPayload()) { if (payload.hasPayload()) {
contents = ImmutableList.of(MessageContent.text(payload.payloadAsString(),null)); contents =
ImmutableList.of(MessageContent.text(payload.payloadAsString(), null));
} else { } else {
return true; return true;
} }

View file

@ -7,7 +7,8 @@ import java.util.concurrent.Executors;
public class AbstractManager extends XmppConnection.Delegate { public class AbstractManager extends XmppConnection.Delegate {
protected static final Executor IO_EXECUTOR = Executors.newSingleThreadExecutor(); protected static final Executor FILE_IO_EXECUTOR = Executors.newSingleThreadExecutor();
protected static final Executor CPU_EXECUTOR = Executors.newSingleThreadExecutor();
protected AbstractManager(final Context context, final XmppConnection connection) { protected AbstractManager(final Context context, final XmppConnection connection) {
super(context, connection); super(context, connection);

View file

@ -101,7 +101,8 @@ public class AvatarManager extends AbstractManager {
} }
private ListenableFuture<byte[]> getCachedOrFetch(final Jid address, final String id) { private ListenableFuture<byte[]> getCachedOrFetch(final Jid address, final String id) {
final var cachedFuture = Futures.submit(() -> getCachedAvatar(address, id), IO_EXECUTOR); final var cachedFuture =
Futures.submit(() -> getCachedAvatar(address, id), FILE_IO_EXECUTOR);
return Futures.catchingAsync( return Futures.catchingAsync(
cachedFuture, cachedFuture,
Exception.class, Exception.class,
@ -133,7 +134,7 @@ public class AvatarManager extends AbstractManager {
} }
throw new IllegalStateException("Avatar sha1hash did not match expected value"); throw new IllegalStateException("Avatar sha1hash did not match expected value");
}, },
IO_EXECUTOR); FILE_IO_EXECUTOR);
} }
private File getCacheFile(final Jid address, final String id) { private File getCacheFile(final Jid address, final String id) {

View file

@ -265,8 +265,7 @@ public class AxolotlManager extends AbstractManager {
} }
private ListenableFuture<Void> publishBundle() { private ListenableFuture<Void> publishBundle() {
final ListenableFuture<Bundle> bundleFuture = final ListenableFuture<Bundle> bundleFuture = prepareBundle();
Futures.submit(this::prepareBundle, IO_EXECUTOR);
return Futures.transformAsync( return Futures.transformAsync(
bundleFuture, bundleFuture,
bundle -> { bundle -> {
@ -282,8 +281,13 @@ public class AxolotlManager extends AbstractManager {
MoreExecutors.directExecutor()); MoreExecutors.directExecutor());
} }
private Bundle prepareBundle() { private ListenableFuture<Bundle> prepareBundle() {
refillPreKeys(); final var refillFuture = Futures.submit(this::refillPreKeys, CPU_EXECUTOR);
return Futures.transform(
refillFuture, this::prepareBundle, getDatabase().getQueryExecutor());
}
private Bundle prepareBundle(Void v) {
final var bundle = new Bundle(); final var bundle = new Bundle();
bundle.setIdentityKey( bundle.setIdentityKey(
signalProtocolStore().getIdentityKeyPair().getPublicKey().getPublicKey()); signalProtocolStore().getIdentityKeyPair().getPublicKey().getPublicKey());