mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-26 09:14:31 +03:00
Add back auth key generation process
This commit is contained in:
parent
5edc2216c7
commit
3b1142aaca
|
@ -30,7 +30,7 @@ class MTProtoPlainSender:
|
|||
body = bytes(request)
|
||||
msg_id = self._state._get_new_msg_id()
|
||||
await self._connection.send(
|
||||
struct.pack('<QQi', 0, msg_id, len(body)) + body
|
||||
struct.pack('<qqi', 0, msg_id, len(body)) + body
|
||||
)
|
||||
|
||||
body = await self._connection.recv()
|
||||
|
|
|
@ -2,11 +2,13 @@ import asyncio
|
|||
import collections
|
||||
import logging
|
||||
|
||||
from . import authenticator
|
||||
from .mtprotolayer import MTProtoLayer
|
||||
from .mtprotoplainsender import MTProtoPlainSender
|
||||
from .requeststate import RequestState
|
||||
from .. import utils
|
||||
from ..errors import (
|
||||
BadMessageError, TypeNotFoundError, rpc_message_to_error
|
||||
BadMessageError, SecurityError, TypeNotFoundError, rpc_message_to_error
|
||||
)
|
||||
from ..extensions import BinaryReader
|
||||
from ..helpers import _ReadyQueue
|
||||
|
@ -206,18 +208,18 @@ class MTProtoSender:
|
|||
.format(self._retries))
|
||||
|
||||
__log__.debug('Connection success!')
|
||||
# TODO Handle this, maybe an empty MTProtoState that does no encryption
|
||||
"""
|
||||
if self.state.auth_key is None:
|
||||
plain = MTProtoPlainSender(self._connection)
|
||||
state = self._connection._state
|
||||
if state.auth_key is None:
|
||||
plain = MTProtoPlainSender(self._connection._connection)
|
||||
for retry in range(1, self._retries + 1):
|
||||
try:
|
||||
__log__.debug('New auth_key attempt {}...'.format(retry))
|
||||
self.state.auth_key, self.state.time_offset =\
|
||||
state.auth_key, state.time_offset =\
|
||||
await authenticator.do_authentication(plain)
|
||||
|
||||
# TODO This callback feels out of place
|
||||
if self._auth_key_callback:
|
||||
self._auth_key_callback(self.state.auth_key)
|
||||
self._auth_key_callback(state.auth_key)
|
||||
|
||||
break
|
||||
except (SecurityError, AssertionError) as e:
|
||||
|
@ -228,7 +230,6 @@ class MTProtoSender:
|
|||
.format(self._retries))
|
||||
await self._disconnect(error=e)
|
||||
raise e
|
||||
"""
|
||||
|
||||
__log__.debug('Starting send loop')
|
||||
self._send_loop_handle = self._loop.create_task(self._send_loop())
|
||||
|
|
|
@ -28,6 +28,14 @@ class MTProtoState:
|
|||
for all these is not a good idea as each need their own authkey, and
|
||||
the concept of "copying" sessions with the unnecessary entities or
|
||||
updates state for these connections doesn't make sense.
|
||||
|
||||
While it would be possible to have a `MTProtoPlainState` that does no
|
||||
encryption so that it was usable through the `MTProtoLayer` and thus
|
||||
avoid the need for a `MTProtoPlainSender`, the `MTProtoLayer` is more
|
||||
focused to efficiency and this state is also more advanced (since it
|
||||
supports gzipping and invoking after other message IDs). There are too
|
||||
many methods that would be needed to make it convenient to use for the
|
||||
authentication process, at which point the `MTProtoPlainSender` is better.
|
||||
"""
|
||||
def __init__(self, auth_key):
|
||||
# Session IDs can be random on every connection
|
||||
|
|
Loading…
Reference in New Issue
Block a user