changeset 1725:c1be6363bfab

core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
author souliane <souliane@mailoo.org>
date Mon, 07 Dec 2015 19:56:12 +0100
parents 13e43b2cd7a2
children 2ebe66a96d05
files src/core/constants.py src/core/sat_main.py src/core/xmpp.py src/plugins/plugin_misc_account.py
diffstat 4 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/constants.py	Mon Dec 07 15:57:33 2015 +0100
+++ b/src/core/constants.py	Mon Dec 07 19:56:12 2015 +0100
@@ -38,6 +38,7 @@
     # Protocol
     XMPP_C2S_PORT = 5222
     XMPP_KEEP_ALIFE = 180
+    XMPP_MAX_RETRIES = 2
 
 
     ## Parameters ##
--- a/src/core/sat_main.py	Mon Dec 07 15:57:33 2015 +0100
+++ b/src/core/sat_main.py	Mon Dec 07 19:56:12 2015 +0100
@@ -251,12 +251,13 @@
         profile = self.memory.getProfileName(profile_key)
         return self.asyncConnect(profile, password)
 
-    def asyncConnect(self, profile, password=''):
+    def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES):
         """Retrieve the individual parameters, authenticate the profile
         and initiate the connection to the associated XMPP server.
 
+        @param profile: %(doc_profile)s
         @param password (string): the SàT profile password
-        @param profile: %(doc_profile)s
+        @param max_retries (int): max number of connection retries
         @return (D(bool)):
             - True if the XMPP connection was already established
             - False if the XMPP connection has been initiated (it may still fail)
@@ -266,7 +267,7 @@
             if self.isConnected(profile):
                 log.info(_("already connected !"))
                 return True
-            d = self._connectXMPPClient(profile)
+            d = self._connectXMPPClient(profile, max_retries)
             return d.addCallback(lambda dummy: False)
 
         d = self.memory.startSession(password, profile)
@@ -274,7 +275,7 @@
         return d
 
     @defer.inlineCallbacks
-    def _connectXMPPClient(self, profile):
+    def _connectXMPPClient(self, profile, max_retries):
         """This part is called from asyncConnect when we have loaded individual parameters from memory"""
         try:
             port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
@@ -285,7 +286,8 @@
         password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
         current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
             jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile)),
-            password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile), port)
+            password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile),
+            port, max_retries)
 
         current.messageProt = xmpp.SatMessageProtocol(self)
         current.messageProt.setHandlerParent(current)
--- a/src/core/xmpp.py	Mon Dec 07 15:57:33 2015 +0100
+++ b/src/core/xmpp.py	Mon Dec 07 19:56:12 2015 +0100
@@ -34,12 +34,12 @@
 class SatXMPPClient(client.XMPPClient):
     implements(iwokkel.IDisco)
 
-    def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT):
+    def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT, max_retries=C.XMPP_MAX_RETRIES):
         # XXX: DNS SRV records are checked when the host is not specified.
         # If no SRV record is found, the host is directly extracted from the JID.
         client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT)
         self.factory.clientConnectionLost = self.connectionLost
-        self.factory.maxRetries = 2
+        self.factory.maxRetries = max_retries
         self.__connected = False
         self.profile = profile
         self.host_app = host_app
--- a/src/plugins/plugin_misc_account.py	Mon Dec 07 15:57:33 2015 +0100
+++ b/src/plugins/plugin_misc_account.py	Mon Dec 07 19:56:12 2015 +0100
@@ -541,7 +541,7 @@
 
         d = self.registerAccount(None, password, jid_s, jid_s)
         d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s))  # checks if the profile has been successfuly created
-        d.addCallback(self.host.asyncConnect, password)
+        d.addCallback(self.host.asyncConnect, password, 0)
 
         def removeProfile(failure):  # profile has been successfully created but the XMPP credentials are wrong!
             log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())