fixed some disco / carbon related bugs

This commit is contained in:
iNPUTmice 2014-11-15 17:24:06 +01:00
parent 35bf13f5ef
commit 7ba9854c22
1 changed files with 44 additions and 30 deletions

View File

@ -88,8 +88,10 @@ public class XmppConnection implements Runnable {
private int smVersion = 3; private int smVersion = 3;
private SparseArray<String> messageReceipts = new SparseArray<>(); private SparseArray<String> messageReceipts = new SparseArray<>();
private boolean usingCompression = false; private boolean enabledCompression = false;
private boolean usingEncryption = false; private boolean enabledEncryption = false;
private boolean enabledCarbons = false;
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
private long lastPaketReceived = 0; private long lastPaketReceived = 0;
@ -138,8 +140,8 @@ public class XmppConnection implements Runnable {
protected void connect() { protected void connect() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting"); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
usingCompression = false; enabledCompression = false;
usingEncryption = false; enabledEncryption = false;
lastConnect = SystemClock.elapsedRealtime(); lastConnect = SystemClock.elapsedRealtime();
lastPingSent = SystemClock.elapsedRealtime(); lastPingSent = SystemClock.elapsedRealtime();
this.attempt++; this.attempt++;
@ -351,8 +353,9 @@ public class XmppConnection implements Runnable {
} catch (final NumberFormatException ignored) { } catch (final NumberFormatException ignored) {
} }
sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryItems(account.getServer());
sendInitialPing(); sendInitialPing();
} else if (nextTag.isStart("r")) { } else if (nextTag.isStart("r")) {
tagReader.readElement(nextTag); tagReader.readElement(nextTag);
AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); AckPacket ack = new AckPacket(this.stanzasReceived, smVersion);
@ -532,7 +535,7 @@ public class XmppConnection implements Runnable {
sendStartStream(); sendStartStream();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": compression enabled"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": compression enabled");
usingCompression = true; enabledCompression = true;
processStream(tagReader.readTag()); processStream(tagReader.readTag());
} }
@ -600,7 +603,7 @@ public class XmppConnection implements Runnable {
sendStartStream(); sendStartStream();
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": TLS connection established"); + ": TLS connection established");
usingEncryption = true; enabledEncryption = true;
processStream(tagReader.readTag()); processStream(tagReader.readTag());
sslSocket.close(); sslSocket.close();
} catch (final NoSuchAlgorithmException | KeyManagementException e1) { } catch (final NoSuchAlgorithmException | KeyManagementException e1) {
@ -611,20 +614,20 @@ public class XmppConnection implements Runnable {
private void processStreamFeatures(Tag currentTag) private void processStreamFeatures(Tag currentTag)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
this.streamFeatures = tagReader.readElement(currentTag); this.streamFeatures = tagReader.readElement(currentTag);
if (this.streamFeatures.hasChild("starttls") && !usingEncryption) { if (this.streamFeatures.hasChild("starttls") && !enabledEncryption) {
sendStartTLS(); sendStartTLS();
} else if (compressionAvailable()) { } else if (compressionAvailable()) {
sendCompressionZlib(); sendCompressionZlib();
} else if (this.streamFeatures.hasChild("register") } else if (this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER) && account.isOptionSet(Account.OPTION_REGISTER)
&& usingEncryption) { && enabledEncryption) {
sendRegistryRequest(); sendRegistryRequest();
} else if (!this.streamFeatures.hasChild("register") } else if (!this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER)) { && account.isOptionSet(Account.OPTION_REGISTER)) {
changeStatus(Account.STATUS_REGISTRATION_NOT_SUPPORTED); changeStatus(Account.STATUS_REGISTRATION_NOT_SUPPORTED);
disconnect(true); disconnect(true);
} else if (this.streamFeatures.hasChild("mechanisms") } else if (this.streamFeatures.hasChild("mechanisms")
&& shouldAuthenticate && usingEncryption) { && shouldAuthenticate && enabledEncryption) {
final List<String> mechanisms = extractMechanisms(streamFeatures final List<String> mechanisms = extractMechanisms(streamFeatures
.findChild("mechanisms")); .findChild("mechanisms"));
final Element auth = new Element("auth"); final Element auth = new Element("auth");
@ -771,6 +774,8 @@ public class XmppConnection implements Runnable {
stanzasSent = 0; stanzasSent = 0;
messageReceipts.clear(); messageReceipts.clear();
} }
enabledCarbons = false;
disco.clear();
sendServiceDiscoveryInfo(account.getServer()); sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryItems(account.getServer()); sendServiceDiscoveryItems(account.getServer());
if (bindListener != null) { if (bindListener != null) {
@ -796,6 +801,11 @@ public class XmppConnection implements Runnable {
} }
private void sendServiceDiscoveryInfo(final Jid server) { private void sendServiceDiscoveryInfo(final Jid server) {
if (disco.containsKey(server.toDomainJid().toString())) {
if (account.getServer().equals(server.toDomainJid())) {
enableAdvancedStreamFeatures();
}
} else {
final IqPacket iq = new IqPacket(IqPacket.TYPE_GET); final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
iq.setTo(server.toDomainJid()); iq.setTo(server.toDomainJid());
iq.query("http://jabber.org/protocol/disco#info"); iq.query("http://jabber.org/protocol/disco#info");
@ -818,12 +828,15 @@ public class XmppConnection implements Runnable {
} }
}); });
} }
}
private void enableAdvancedStreamFeatures() { private void enableAdvancedStreamFeatures() {
if (getFeatures().carbons()) { if (getFeatures().carbons()) {
if (!enabledCarbons) {
sendEnableCarbons(); sendEnableCarbons();
} }
} }
}
private void sendServiceDiscoveryItems(final Jid server) { private void sendServiceDiscoveryItems(final Jid server) {
final IqPacket iq = new IqPacket(IqPacket.TYPE_GET); final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
@ -858,6 +871,7 @@ public class XmppConnection implements Runnable {
if (!packet.hasChild("error")) { if (!packet.hasChild("error")) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": successfully enabled carbons"); + ": successfully enabled carbons");
enabledCarbons = true;
} else { } else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": error enableing carbons " + packet.toString()); + ": error enableing carbons " + packet.toString());
@ -1131,7 +1145,7 @@ public class XmppConnection implements Runnable {
} }
public boolean compression() { public boolean compression() {
return connection.usingCompression; return connection.enabledCompression;
} }
} }
} }