core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
This commit is contained in:
parent
ffee469c3e
commit
f3a5cb2a96
4 changed files with 11 additions and 8 deletions
|
|
@ -38,6 +38,7 @@ class Const(object):
|
||||||
# Protocol
|
# Protocol
|
||||||
XMPP_C2S_PORT = 5222
|
XMPP_C2S_PORT = 5222
|
||||||
XMPP_KEEP_ALIFE = 180
|
XMPP_KEEP_ALIFE = 180
|
||||||
|
XMPP_MAX_RETRIES = 2
|
||||||
|
|
||||||
|
|
||||||
## Parameters ##
|
## Parameters ##
|
||||||
|
|
|
||||||
|
|
@ -251,12 +251,13 @@ class SAT(service.Service):
|
||||||
profile = self.memory.getProfileName(profile_key)
|
profile = self.memory.getProfileName(profile_key)
|
||||||
return self.asyncConnect(profile, password)
|
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
|
"""Retrieve the individual parameters, authenticate the profile
|
||||||
and initiate the connection to the associated XMPP server.
|
and initiate the connection to the associated XMPP server.
|
||||||
|
|
||||||
@param password (string): the SàT profile password
|
|
||||||
@param profile: %(doc_profile)s
|
@param profile: %(doc_profile)s
|
||||||
|
@param password (string): the SàT profile password
|
||||||
|
@param max_retries (int): max number of connection retries
|
||||||
@return (D(bool)):
|
@return (D(bool)):
|
||||||
- True if the XMPP connection was already established
|
- True if the XMPP connection was already established
|
||||||
- False if the XMPP connection has been initiated (it may still fail)
|
- False if the XMPP connection has been initiated (it may still fail)
|
||||||
|
|
@ -266,7 +267,7 @@ class SAT(service.Service):
|
||||||
if self.isConnected(profile):
|
if self.isConnected(profile):
|
||||||
log.info(_("already connected !"))
|
log.info(_("already connected !"))
|
||||||
return True
|
return True
|
||||||
d = self._connectXMPPClient(profile)
|
d = self._connectXMPPClient(profile, max_retries)
|
||||||
return d.addCallback(lambda dummy: False)
|
return d.addCallback(lambda dummy: False)
|
||||||
|
|
||||||
d = self.memory.startSession(password, profile)
|
d = self.memory.startSession(password, profile)
|
||||||
|
|
@ -274,7 +275,7 @@ class SAT(service.Service):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@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"""
|
"""This part is called from asyncConnect when we have loaded individual parameters from memory"""
|
||||||
try:
|
try:
|
||||||
port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
|
port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
|
||||||
|
|
@ -285,7 +286,8 @@ class SAT(service.Service):
|
||||||
password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
|
password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
|
||||||
current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
|
current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
|
||||||
jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=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 = xmpp.SatMessageProtocol(self)
|
||||||
current.messageProt.setHandlerParent(current)
|
current.messageProt.setHandlerParent(current)
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ from twisted.words.protocols.jabber.xmlstream import XMPPHandler
|
||||||
class SatXMPPClient(client.XMPPClient):
|
class SatXMPPClient(client.XMPPClient):
|
||||||
implements(iwokkel.IDisco)
|
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.
|
# 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.
|
# 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)
|
client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT)
|
||||||
self.factory.clientConnectionLost = self.connectionLost
|
self.factory.clientConnectionLost = self.connectionLost
|
||||||
self.factory.maxRetries = 2
|
self.factory.maxRetries = max_retries
|
||||||
self.__connected = False
|
self.__connected = False
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.host_app = host_app
|
self.host_app = host_app
|
||||||
|
|
|
||||||
|
|
@ -541,7 +541,7 @@ http://www.salut-a-toi.org
|
||||||
|
|
||||||
d = self.registerAccount(None, password, jid_s, jid_s)
|
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(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!
|
def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong!
|
||||||
log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())
|
log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue