diff options
author | nicoco <nicoco@nicoco.fr> | 2022-07-16 17:08:21 +0200 |
---|---|---|
committer | nicoco <nicoco@nicoco.fr> | 2022-07-16 17:08:21 +0200 |
commit | afedfa4b061da4ec526db11f08677fa3e30bafeb (patch) | |
tree | f5f759587756f2615e62640869f9de5b68d619ea /slixmpp/xmlstream/xmlstream.py | |
parent | afb5419b6820c2d4e256ff1ce2f31e4442dcfe2a (diff) | |
parent | 5998069203fc1690e702b1267bcf694859e783f7 (diff) | |
download | slixmpp-afedfa4b061da4ec526db11f08677fa3e30bafeb.tar.gz slixmpp-afedfa4b061da4ec526db11f08677fa3e30bafeb.tar.bz2 slixmpp-afedfa4b061da4ec526db11f08677fa3e30bafeb.tar.xz slixmpp-afedfa4b061da4ec526db11f08677fa3e30bafeb.zip |
Merge branch 'master' of https://lab.louiz.org/poezio/slixmpp
Diffstat (limited to 'slixmpp/xmlstream/xmlstream.py')
-rw-r--r-- | slixmpp/xmlstream/xmlstream.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 18143f87..18464ccd 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -493,16 +493,11 @@ class XMLStream(asyncio.BaseProtocol): except Socket.gaierror as e: self.event('connection_failed', 'No DNS record available for %s' % self.default_domain) + self.reschedule_connection_attempt() except OSError as e: log.debug('Connection failed: %s', e) self.event("connection_failed", e) - if self._current_connection_attempt is None: - return - self._connect_loop_wait = self._connect_loop_wait * 2 + 1 - self._current_connection_attempt = asyncio.ensure_future( - self._connect_routine(), - loop=self.loop, - ) + self.reschedule_connection_attempt() def process(self, *, forever: bool = True, timeout: Optional[int] = None) -> None: """Process all the available XMPP events (receiving or sending data on the @@ -638,6 +633,20 @@ class XMLStream(asyncio.BaseProtocol): self._set_disconnected_future() self.event("disconnected", self.disconnect_reason or exception) + def reschedule_connection_attempt(self) -> None: + """ + Increase the exponential back-off and initate another background + _connect_routine call to connect to the server. + """ + # abort if there is no ongoing connection attempt + if self._current_connection_attempt is None: + return + self._connect_loop_wait = min(300, self._connect_loop_wait * 2 + 1) + self._current_connection_attempt = asyncio.ensure_future( + self._connect_routine(), + loop=self.loop, + ) + def cancel_connection_attempt(self) -> None: """ Immediately cancel the current create_connection() Future. @@ -800,6 +809,8 @@ class XMLStream(asyncio.BaseProtocol): self.ssl_context.verify_mode = ssl.CERT_REQUIRED self.ssl_context.load_verify_locations(cafile=ca_cert) + else: + self.ssl_context.set_default_verify_paths() return self.ssl_context |