import org.asamk.signal.manager.api.AccountCheckException;
import org.asamk.signal.manager.api.NotRegisteredException;
+import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.ServiceEnvironment;
import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.storage.accounts.AccountsStore;
import org.asamk.signal.manager.util.KeyUtils;
-import org.signal.libsignal.protocol.util.KeyHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException;
return accountsStore.getAllNumbers();
}
- public MultiAccountManager initMultiAccountManager() throws IOException {
- final var managers = accountsStore.getAllAccounts().parallelStream().map(a -> {
+ public MultiAccountManager initMultiAccountManager() throws IOException, AccountCheckException {
+ final var managerPairs = accountsStore.getAllAccounts().parallelStream().map(a -> {
try {
- return initManager(a.number(), a.path());
- } catch (NotRegisteredException | IOException | AccountCheckException e) {
+ return new Pair<Manager, Throwable>(initManager(a.number(), a.path()), null);
+ } catch (NotRegisteredException e) {
logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
return null;
- } catch (Throwable e) {
+ } catch (AccountCheckException | IOException e) {
logger.error("Failed to load {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
- throw e;
+ return new Pair<Manager, Throwable>(null, e);
}
}).filter(Objects::nonNull).toList();
+ for (final var pair : managerPairs) {
+ if (pair.second() instanceof IOException e) {
+ throw e;
+ } else if (pair.second() instanceof AccountCheckException e) {
+ throw e;
+ }
+ }
+
+ final var managers = managerPairs.stream().map(Pair::first).toList();
return new MultiAccountManagerImpl(managers, this);
}
}
private Manager initManager(
- String number, String accountPath
+ String number,
+ String accountPath
) throws IOException, NotRegisteredException, AccountCheckException {
if (accountPath == null) {
throw new NotRegisteredException();
}
public RegistrationManager initRegistrationManager(
- String number, Consumer<Manager> newManagerListener
+ String number,
+ Consumer<Manager> newManagerListener
) throws IOException {
final var accountPath = accountsStore.getPathByNumber(number);
if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) {
final var newAccountPath = accountPath == null ? accountsStore.addAccount(number, null) : accountPath;
var aciIdentityKey = KeyUtils.generateIdentityKeyPair();
var pniIdentityKey = KeyUtils.generateIdentityKeyPair();
- var registrationId = KeyHelper.generateRegistrationId(false);
- var pniRegistrationId = KeyHelper.generateRegistrationId(false);
var profileKey = KeyUtils.createProfileKey();
var account = SignalAccount.create(pathConfig.dataPath(),
serviceEnvironment,
aciIdentityKey,
pniIdentityKey,
- registrationId,
- pniRegistrationId,
profileKey,
settings);
+ account.initDatabase();
return new RegistrationManagerImpl(account,
pathConfig,
account.close();
throw new IOException("Number in account file doesn't match expected number: " + account.getNumber());
}
+ account.initDatabase();
return new RegistrationManagerImpl(account,
pathConfig,