Assume exported auths last forever

This implies that export senders will NOT be deleted from
memory once all borrows are returned, thus their auth_key
remains as well. When borrowing them if they existed they
will be connect()ed if it's the first borrow.

This probably fixes #901.
This commit is contained in:
Lonami Exo 2018-07-21 11:24:20 +02:00
parent 13437cc3f2
commit 5a9a00e7ae

View File

@ -433,6 +433,9 @@ class TelegramBaseClient(abc.ABC):
if not sender:
sender = await self._create_exported_sender(dc_id)
sender.dc_id = dc_id
elif not n:
dc = await self._get_dc(dc_id)
await sender.connect(dc.ip_address, dc.port)
self._borrowed_senders[dc_id] = (n + 1, sender)
@ -447,12 +450,10 @@ class TelegramBaseClient(abc.ABC):
dc_id = sender.dc_id
n, _ = self._borrowed_senders[dc_id]
n -= 1
if n > 0:
self._borrowed_senders[dc_id] = (n, sender)
else:
if not n:
__log__.info('Disconnecting borrowed sender for DC %d', dc_id)
await sender.disconnect()
del self._borrowed_senders[dc_id]
async def _get_cdn_client(self, cdn_redirect):
"""Similar to ._borrow_exported_client, but for CDNs"""