asynciowrapper for sessions

This commit is contained in:
joseph 2018-09-28 17:32:39 +02:00
parent 4330a8b44f
commit 91af0f886e

View File

@ -17,6 +17,7 @@ from ..sessions import Session, SQLiteSession, MemorySession
from ..tl import TLObject, functions, types from ..tl import TLObject, functions, types
from ..tl.alltlobjects import LAYER from ..tl.alltlobjects import LAYER
from ..utils import AsyncClassWrapper from ..utils import AsyncClassWrapper
DEFAULT_DC_ID = 4 DEFAULT_DC_ID = 4
DEFAULT_IPV4_IP = '149.154.167.51' DEFAULT_IPV4_IP = '149.154.167.51'
DEFAULT_IPV6_IP = '[2001:67c:4e8:f002::a]' DEFAULT_IPV6_IP = '[2001:67c:4e8:f002::a]'
@ -196,6 +197,7 @@ class TelegramBaseClient(abc.ABC):
DEFAULT_IPV6_IP if self._use_ipv6 else DEFAULT_IPV4_IP, DEFAULT_IPV6_IP if self._use_ipv6 else DEFAULT_IPV4_IP,
DEFAULT_PORT DEFAULT_PORT
) )
self.flood_sleep_threshold = flood_sleep_threshold self.flood_sleep_threshold = flood_sleep_threshold
self.session = AsyncClassWrapper(session) self.session = AsyncClassWrapper(session)
self.api_id = int(api_id) self.api_id = int(api_id)
@ -372,7 +374,7 @@ class TelegramBaseClient(abc.ABC):
# auth_key's are associated with a server, which has now changed # auth_key's are associated with a server, which has now changed
# so it's not valid anymore. Set to None to force recreating it. # so it's not valid anymore. Set to None to force recreating it.
self.session.auth_key = self._sender.state.auth_key = None self.session.auth_key = self._sender.state.auth_key = None
self.session.save() await self.session.save()
await self._disconnect() await self._disconnect()
return await self.connect() return await self.connect()
@ -471,8 +473,8 @@ class TelegramBaseClient(abc.ABC):
session = self._exported_sessions.get(cdn_redirect.dc_id) session = self._exported_sessions.get(cdn_redirect.dc_id)
if not session: if not session:
dc = await self._get_dc(cdn_redirect.dc_id, cdn=True) dc = await self._get_dc(cdn_redirect.dc_id, cdn=True)
session = self.session.clone() session = await self.session.clone()
session.set_dc(dc.id, dc.ip_address, dc.port) await session.set_dc(dc.id, dc.ip_address, dc.port)
self._exported_sessions[cdn_redirect.dc_id] = session self._exported_sessions[cdn_redirect.dc_id] = session
__log__.info('Creating new CDN client') __log__.info('Creating new CDN client')