From dab33cdaa1040cd46765610c7b2bbbc588637426 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Wed, 7 Aug 2013 16:18:16 +0300 Subject: [PATCH] Fixes a problem where xmpp can trigger several reconnects on NoRouteToHostException. --- .../ProtocolProviderServiceJabberImpl.java | 36 ++++++++++++++----- .../ReconnectPluginActivator.java | 14 ++++---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index 51672dd8e..4182b3158 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -471,8 +471,8 @@ public void register(final SecurityAuthority authority) inConnectAndLogin = true; } - connectAndLogin(authority, - SecurityAuthority.AUTHENTICATION_REQUIRED); + initializeConnectAndLogin(authority, + SecurityAuthority.AUTHENTICATION_REQUIRED); } catch (XMPPException ex) { @@ -528,7 +528,7 @@ void reregister(int authReasonCode) if (logger.isTraceEnabled()) logger.trace("Trying to reregister us!"); - // sets this if any is tring to use us through registration + // sets this if any is trying to use us through registration // to know we are not registered this.unregister(false); @@ -541,8 +541,7 @@ void reregister(int authReasonCode) inConnectAndLogin = true; } - connectAndLogin(authority, - authReasonCode); + initializeConnectAndLogin(authority, authReasonCode); } catch(OperationFailedException ex) { @@ -639,7 +638,7 @@ public TransportProtocol getTransportProtocol() * @throws OperationFailedException if login parameters * as server port are not correct */ - private void connectAndLogin(SecurityAuthority authority, + private void initializeConnectAndLogin(SecurityAuthority authority, int reasonCode) throws XMPPException, OperationFailedException { @@ -738,6 +737,8 @@ private void connectAndLogin(SecurityAuthority authority, { logger.error("No server addresses found"); + eventDuringLogin = null; + fireRegistrationStateChanged( getRegistrationState(), RegistrationState.CONNECTION_FAILED, @@ -951,9 +952,19 @@ private ConnectState connectAndLogin(InetSocketAddress currentAddress, //as we got an exception not handled in connectAndLogin //no state was set, so fire it here so we can continue //with the re-register process - fireRegistrationStateChanged(getRegistrationState(), + //2013-08-07 do not fire event, if we have several + // addresses and we fire event will activate reconnect + // but we will continue connecting with other addresses + // and can register with address, then unregister and try again + // that is from reconnect plugin. + // Storing event for fire after all have failed and we have + // tried every address. + eventDuringLogin = new RegistrationStateChangeEvent( + ProtocolProviderServiceJabberImpl.this, + getRegistrationState(), RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, null); + RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, + null); throw ex; } @@ -1185,6 +1196,8 @@ else if (tlsRequired) logger.error("Connection not established, server not found!"); + eventDuringLogin = null; + fireRegistrationStateChanged(getRegistrationState(), RegistrationState.CONNECTION_FAILED, RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, null); @@ -1213,6 +1226,7 @@ else if (tlsRequired) if (!loginStrategy.login(connection, userName, resource)) { disconnectAndCleanConnection(); + eventDuringLogin = null; fireRegistrationStateChanged( getRegistrationState(), // not auth failed, or there would be no info-popup @@ -1225,6 +1239,8 @@ else if (tlsRequired) if(connection.isAuthenticated()) { + eventDuringLogin = null; + fireRegistrationStateChanged( getRegistrationState(), RegistrationState.REGISTERED, @@ -1255,6 +1271,8 @@ else if (tlsRequired) { disconnectAndCleanConnection(); + eventDuringLogin = null; + fireRegistrationStateChanged( getRegistrationState() , RegistrationState.UNREGISTERED @@ -1421,6 +1439,7 @@ public void unregister(boolean fireEvent) { if(fireEvent) { + eventDuringLogin = null; fireRegistrationStateChanged( getRegistrationState() , RegistrationState.UNREGISTERING @@ -1434,6 +1453,7 @@ public void unregister(boolean fireEvent) if(fireEvent) { + eventDuringLogin = null; fireRegistrationStateChanged( currRegState, RegistrationState.UNREGISTERED, diff --git a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java index 37a9b3831..4243804ca 100644 --- a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java @@ -596,9 +596,10 @@ public void run() currentlyReconnecting.put(pp, task); - if (logger.isTraceEnabled()) - logger.trace("Reconnect " + pp + - " after " + task.delay + " ms."); + if (logger.isInfoEnabled()) + logger.info("Reconnect " + + pp.getAccountID().getDisplayName() + + " after " + task.delay + " ms."); timer.schedule(task, task.delay); } @@ -858,9 +859,10 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) currentlyReconnecting.put(pp, task); - if (logger.isTraceEnabled()) - logger.trace("Reconnect " + pp + - " after " + task.delay + " ms."); + if (logger.isInfoEnabled()) + logger.info("Reconnect " + + pp.getAccountID().getDisplayName() + + " after " + task.delay + " ms."); timer.schedule(task, task.delay); }