Permalink
Browse files

Fix SRV handling and a couple of NPEs.

SRV lookup failure was being cached.
  • Loading branch information...
1 parent 88e3df6 commit ed064a8af57af421d16e784ba2cbfbb9fcf15948 @devrandom committed May 25, 2012
@@ -65,8 +65,6 @@ public void addConnection (ImConnectionAdapter connection)
public void removeConnection (ImConnectionAdapter connection)
{
mConnections.remove(connection);
- this.mConnections.remove(connection.getLoginUser().getAddress().getScreenName());
-
}
public ImConnectionAdapter findConnection(String localAddress) {
@@ -173,7 +173,8 @@ public void join() {
mExecutor = null;
// This will send us an interrupt, which we will ignore. We will terminate
// anyway after the caller is done. This also drains the executor queue.
- executor.shutdownNow();
+ if (executor != null)
+ executor.shutdownNow();
}
public void sendPacket(final org.jivesoftware.smack.packet.Packet packet) {
@@ -426,7 +427,7 @@ public void initConnection(MyXMPPConnection connection, Contact user, int state)
private void initConnection(String userName, final String password,
Imps.ProviderSettings.QueryMap providerSettings) throws Exception {
-// android.os.Debug.waitForDebugger();
+ android.os.Debug.waitForDebugger();
boolean allowPlainAuth = providerSettings.getAllowPlainAuth();
boolean requireTls = providerSettings.getRequireTls();
@@ -461,7 +462,10 @@ private void initConnection(String userName, final String password,
debug(TAG, "(DNS SRV) resolving: "+domain);
DNSUtil.HostAddress srvHost = DNSUtil.resolveXMPPDomain(domain);
server = srvHost.getHost();
- //serverPort = srvHost.getPort(); //ignore port right now, as we are always a client
+ if (serverPort <= 0) {
+ // If user did not override port, use port from SRV record
+ serverPort = srvHost.getPort();
+ }
debug(TAG, "(DNS SRV) resolved: "+domain+"=" + server + ":" + serverPort);
}
@@ -128,18 +128,14 @@ public static HostAddress resolveXMPPDomain(String domain) {
}
- if (result == null) {
- result = resolveSRV("_xmpp-server._tcp." + domain);
- }
-
-
- if (result == null) {
+ if (result != null) {
+ // Add item to cache.
+ synchronized (ccache) {
+ ccache.put(domain, result);
@n8fr8

n8fr8 May 26, 2012

how long does this cache last?

@devrandom

devrandom May 26, 2012

Owner

10 minutes. It looks like xbill has its own cache too, not sure why there are multiple cache levels. We should consider if this level is really needed.

In any case, this change only eliminates caching negative results (i.e. storing new HostAddress(domain, 5222) when result = null).

@devrandom

devrandom May 26, 2012

Owner

Oh, when I say "negative results", this includes the case where DNS server times out, network issues, etc. .

+ }
+ } else {
result = new HostAddress(domain, 5222);
}
- // Add item to cache.
- synchronized (ccache) {
- ccache.put(domain, result);
- }
return result;
}

0 comments on commit ed064a8

Please sign in to comment.