wait for DB restore before bind

This commit is contained in:
Daniel Gultsch 2022-09-26 09:47:53 +02:00
parent 3d56d01826
commit cb775ece99
2 changed files with 26 additions and 9 deletions

View file

@ -1939,7 +1939,7 @@ public class XmppConnectionService extends Service {
databaseBackend.expireOldMessages(deletionDate); databaseBackend.expireOldMessages(deletionDate);
} }
Log.d(Config.LOGTAG, "restoring roster..."); Log.d(Config.LOGTAG, "restoring roster...");
for (Account account : accounts) { for (final Account account : accounts) {
databaseBackend.readRoster(account.getRoster()); databaseBackend.readRoster(account.getRoster());
account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage
} }
@ -1977,11 +1977,11 @@ public class XmppConnectionService extends Service {
public void loadPhoneContacts() { public void loadPhoneContacts() {
mContactMergerExecutor.execute(() -> { mContactMergerExecutor.execute(() -> {
Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this); final Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
Log.d(Config.LOGTAG, "start merging phone contacts with roster"); Log.d(Config.LOGTAG, "start merging phone contacts with roster");
for (Account account : accounts) { for (final Account account : accounts) {
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class); final List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class);
for (JabberIdContact jidContact : contacts.values()) { for (final JabberIdContact jidContact : contacts.values()) {
final Contact contact = account.getRoster().getContact(jidContact.getJid()); final Contact contact = account.getRoster().getContact(jidContact.getJid());
boolean needsCacheClean = contact.setPhoneContact(jidContact); boolean needsCacheClean = contact.setPhoneContact(jidContact);
if (needsCacheClean) { if (needsCacheClean) {
@ -1989,7 +1989,7 @@ public class XmppConnectionService extends Service {
} }
withSystemAccounts.remove(contact); withSystemAccounts.remove(contact);
} }
for (Contact contact : withSystemAccounts) { for (final Contact contact : withSystemAccounts) {
boolean needsCacheClean = contact.unsetPhoneContact(JabberIdContact.class); boolean needsCacheClean = contact.unsetPhoneContact(JabberIdContact.class);
if (needsCacheClean) { if (needsCacheClean) {
getAvatarService().clear(contact); getAvatarService().clear(contact);

View file

@ -753,6 +753,7 @@ public class XmppConnection implements Runnable {
processFailed(failed, false); // wait for new stream features processFailed(failed, false); // wait for new stream features
} }
if (bound != null) { if (bound != null) {
clearIqCallbacks();
this.isBound = true; this.isBound = true;
final Element streamManagementEnabled = final Element streamManagementEnabled =
bound.findChild("enabled", Namespace.STREAM_MANAGEMENT); bound.findChild("enabled", Namespace.STREAM_MANAGEMENT);
@ -1134,7 +1135,12 @@ public class XmppConnection implements Runnable {
tagReader.setInputStream(sslSocket.getInputStream()); tagReader.setInputStream(sslSocket.getInputStream());
tagWriter.setOutputStream(sslSocket.getOutputStream()); tagWriter.setOutputStream(sslSocket.getOutputStream());
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS connection established"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS connection established");
final boolean quickStart = establishStream(true); final boolean quickStart;
try {
quickStart = establishStream(true);
} catch (final InterruptedException e) {
return;
}
if (quickStart) { if (quickStart) {
this.quickStartInProgress = true; this.quickStartInProgress = true;
} }
@ -1333,6 +1339,17 @@ public class XmppConnection implements Runnable {
sm sm
&& bindFeatures != null && bindFeatures != null
&& bindFeatures.containsAll(Bind2.QUICKSTART_FEATURES); && bindFeatures.containsAll(Bind2.QUICKSTART_FEATURES);
if (bindFeatures != null) {
try {
mXmppConnectionService.restoredFromDatabaseLatch.await();
} catch (final InterruptedException e) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": interrupted while waiting for DB restore during SASL2 bind");
return;
}
}
authenticate = generateAuthenticationRequest(firstMessage, bindFeatures, sm); authenticate = generateAuthenticationRequest(firstMessage, bindFeatures, sm);
} else { } else {
throw new AssertionError("Missing implementation for " + version); throw new AssertionError("Missing implementation for " + version);
@ -1876,7 +1893,6 @@ public class XmppConnection implements Runnable {
} }
} }
} }
Log.d(Config.LOGTAG, commands.toString());
synchronized (this.commands) { synchronized (this.commands) {
this.commands.clear(); this.commands.clear();
this.commands.putAll(commands); this.commands.putAll(commands);
@ -2018,12 +2034,13 @@ public class XmppConnection implements Runnable {
} }
} }
private boolean establishStream(final boolean secureConnection) throws IOException { private boolean establishStream(final boolean secureConnection) throws IOException, InterruptedException {
final SaslMechanism saslMechanism = account.getPinnedMechanism(); final SaslMechanism saslMechanism = account.getPinnedMechanism();
if (secureConnection if (secureConnection
&& Config.SASL_2_ENABLED && Config.SASL_2_ENABLED
&& saslMechanism != null && saslMechanism != null
&& account.isOptionSet(Account.OPTION_QUICKSTART_AVAILABLE)) { && account.isOptionSet(Account.OPTION_QUICKSTART_AVAILABLE)) {
mXmppConnectionService.restoredFromDatabaseLatch.await();
this.saslMechanism = saslMechanism; this.saslMechanism = saslMechanism;
final Element authenticate = final Element authenticate =
generateAuthenticationRequest(saslMechanism.getClientFirstMessage()); generateAuthenticationRequest(saslMechanism.getClientFirstMessage());