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