Skip to content

Commit 65c2090

Browse files
committed
Connection refactoring
1 parent 9001ccd commit 65c2090

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

pyrogram/client/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,6 @@ def load_config(self):
843843

844844
if self.proxy:
845845
self.proxy["enabled"] = True
846-
self.proxy["username"] = self.proxy.get("username", None)
847-
self.proxy["password"] = self.proxy.get("password", None)
848846
else:
849847
self.proxy = {}
850848

pyrogram/connection/transport/tcp/tcp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def __init__(self, proxy: dict):
4141
if proxy and self.proxy_enabled:
4242
self.set_proxy(
4343
proxy_type=socks.SOCKS5,
44-
addr=proxy["hostname"],
45-
port=proxy["port"],
46-
username=proxy["username"],
47-
password=proxy["password"]
44+
addr=proxy.get("hostname", None),
45+
port=proxy.get("port", None),
46+
username=proxy.get("username", None),
47+
password=proxy.get("password", None)
4848
)
4949

5050
log.info("Using proxy {}:{}".format(
51-
proxy["hostname"],
52-
proxy["port"]
51+
proxy.get("hostname", None),
52+
proxy.get("port", None)
5353
))
5454

5555
def close(self):

pyrogram/session/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class Auth:
4949
def __init__(self, dc_id: int, test_mode: bool, proxy: dict):
5050
self.dc_id = dc_id
5151
self.test_mode = test_mode
52+
self.proxy = proxy
5253

53-
self.connection = Connection(DataCenter(dc_id, test_mode), proxy)
54+
self.connection = None
5455

5556
@staticmethod
5657
def pack(data: Object) -> bytes:
@@ -83,6 +84,8 @@ def create(self):
8384
# The server may close the connection at any time, causing the auth key creation to fail.
8485
# If that happens, just try again up to MAX_RETRIES times.
8586
while True:
87+
self.connection = Connection(DataCenter(self.dc_id, self.test_mode), self.proxy)
88+
8689
try:
8790
log.info("Start creating a new auth key on DC{}".format(self.dc_id))
8891

pyrogram/session/session.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ def __init__(self,
9696
print("Licensed under the terms of the " + __license__, end="\n\n")
9797
Session.notice_displayed = True
9898

99-
self.connection = Connection(DataCenter(dc_id, test_mode), proxy)
99+
self.dc_id = dc_id
100+
self.test_mode = test_mode
101+
self.proxy = proxy
100102
self.api_id = api_id
101103
self.is_cdn = is_cdn
102104
self.client = client
103105

106+
self.connection = None
107+
104108
self.auth_key = auth_key
105109
self.auth_key_id = sha1(auth_key).digest()[-8:]
106110

@@ -126,6 +130,8 @@ def __init__(self,
126130

127131
def start(self):
128132
while True:
133+
self.connection = Connection(DataCenter(self.dc_id, self.test_mode), self.proxy)
134+
129135
try:
130136
self.connection.connect()
131137

0 commit comments

Comments
 (0)