mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Avoid counterintuitive automatic connection
This commit is contained in:
parent
bbd3eb7c28
commit
468033fa7e
|
@ -11,6 +11,7 @@ def do_authentication(transport):
|
|||
"""Executes the authentication process with the Telegram servers.
|
||||
If no error is rose, returns both the authorization key and the time offset"""
|
||||
sender = MtProtoPlainSender(transport)
|
||||
sender.connect()
|
||||
|
||||
# Step 1 sending: PQ Request
|
||||
nonce = os.urandom(16)
|
||||
|
@ -184,6 +185,9 @@ def do_authentication(transport):
|
|||
|
||||
# Step 3 response: Complete DH Exchange
|
||||
with BinaryReader(sender.receive()) as reader:
|
||||
# Everything read from the server, disconnect now
|
||||
sender.disconnect()
|
||||
|
||||
code = reader.read_int(signed=False)
|
||||
if code == 0x3bcbf734: # DH Gen OK
|
||||
nonce_from_server = reader.read(16)
|
||||
|
|
|
@ -12,8 +12,13 @@ class MtProtoPlainSender:
|
|||
self._time_offset = 0
|
||||
self._last_msg_id = 0
|
||||
self._transport = transport
|
||||
|
||||
def connect(self):
|
||||
self._transport.connect()
|
||||
|
||||
def disconnect(self):
|
||||
self._transport.close()
|
||||
|
||||
def send(self, data):
|
||||
"""Sends a plain packet (auth_key_id = 0) containing the given message body (data)"""
|
||||
with BinaryWriter() as writer:
|
||||
|
|
|
@ -46,8 +46,6 @@ class MtProtoSender:
|
|||
self.updates_thread_sleep = None
|
||||
self.updates_thread = None # Set later
|
||||
|
||||
self.connect()
|
||||
|
||||
def connect(self):
|
||||
"""Connects to the server"""
|
||||
self.transport.connect()
|
||||
|
|
|
@ -99,6 +99,7 @@ class TelegramClient:
|
|||
self.session.save()
|
||||
|
||||
self.sender = MtProtoSender(self.transport, self.session)
|
||||
self.sender.connect()
|
||||
|
||||
# Now it's time to send an InitConnectionRequest
|
||||
# This must always be invoked with the layer we'll be using
|
||||
|
|
Loading…
Reference in New Issue
Block a user