@@ -67,14 +67,14 @@ def unpack(b: BytesIO):
6767 b .seek (20 ) # Skip auth_key_id (8), message_id (8) and message_length (4)
6868 return Object .read (b )
6969
70- def send (self , data : Object ):
70+ async def send (self , data : Object ):
7171 data = self .pack (data )
72- self .connection .send (data )
73- response = BytesIO (self .connection .recv ())
72+ await self .connection .send (data )
73+ response = BytesIO (await self .connection .recv ())
7474
7575 return self .unpack (response )
7676
77- def create (self ):
77+ async def create (self ):
7878 """
7979 https://core.telegram.org/mtproto/auth_key
8080 https://core.telegram.org/mtproto/samples-auth_key
@@ -89,12 +89,12 @@ def create(self):
8989 try :
9090 log .info ("Start creating a new auth key on DC{}" .format (self .dc_id ))
9191
92- self .connection .connect ()
92+ await self .connection .connect ()
9393
9494 # Step 1; Step 2
9595 nonce = int .from_bytes (urandom (16 ), "little" , signed = True )
9696 log .debug ("Send req_pq: {}" .format (nonce ))
97- res_pq = self .send (functions .ReqPqMulti (nonce ))
97+ res_pq = await self .send (functions .ReqPqMulti (nonce ))
9898 log .debug ("Got ResPq: {}" .format (res_pq .server_nonce ))
9999 log .debug ("Server public key fingerprints: {}" .format (res_pq .server_public_key_fingerprints ))
100100
@@ -138,7 +138,7 @@ def create(self):
138138
139139 # Step 5. TODO: Handle "server_DH_params_fail". Code assumes response is ok
140140 log .debug ("Send req_DH_params" )
141- server_dh_params = self .send (
141+ server_dh_params = await self .send (
142142 functions .ReqDHParams (
143143 nonce ,
144144 server_nonce ,
@@ -198,7 +198,7 @@ def create(self):
198198 encrypted_data = AES .ige256_encrypt (data_with_hash , tmp_aes_key , tmp_aes_iv )
199199
200200 log .debug ("Send set_client_DH_params" )
201- set_client_dh_params_answer = self .send (
201+ set_client_dh_params_answer = await self .send (
202202 functions .SetClientDHParams (
203203 nonce ,
204204 server_nonce ,
0 commit comments