Skip to content

Commit 725a64f

Browse files
authored
Implement non-blocking TCP connection (
1 parent 833e960 commit 725a64f

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pyrogram/session/auth.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from hashlib import sha1
2323
from io import BytesIO
2424
from os import urandom
25+
from typing import Optional
2526

2627
import pyrogram
2728
from pyrogram import raw
@@ -37,13 +38,21 @@
3738
class Auth:
3839
MAX_RETRIES = 5
3940

40-
def __init__(self, client: "pyrogram.Client", dc_id: int, test_mode: bool):
41+
def __init__(
42+
self,
43+
client: "pyrogram.Client",
44+
dc_id: int,
45+
test_mode: bool
46+
):
4147
self.dc_id = dc_id
4248
self.test_mode = test_mode
4349
self.ipv6 = client.ipv6
50+
self.alt_port = client.alt_port
4451
self.proxy = client.proxy
52+
self.connection_factory = client.connection_factory
53+
self.protocol_factory = client.protocol_factory
4554

46-
self.connection = None
55+
self.connection: Optional[Connection] = None
4756

4857
@staticmethod
4958
def pack(data: TLObject) -> bytes:
@@ -76,7 +85,15 @@ async def create(self):
7685
# The server may close the connection at any time, causing the auth key creation to fail.
7786
# If that happens, just try again up to MAX_RETRIES times.
7887
while True:
79-
self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy)
88+
self.connection = self.connection_factory(
89+
dc_id=self.dc_id,
90+
test_mode=self.test_mode,
91+
ipv6=self.ipv6,
92+
alt_port=self.alt_port,
93+
proxy=self.proxy,
94+
media=False,
95+
protocol_factory=self.protocol_factory
96+
)
8097

8198
try:
8299
log.info("Start creating a new auth key on DC%s", self.dc_id)

0 commit comments

Comments
 (0)