mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 04:48:06 +00:00
Merge branch 'master' into new-api
This commit is contained in:
commit
70cd0500de
@ -32,8 +32,8 @@ class Connection:
|
||||
2: TCPIntermediate
|
||||
}
|
||||
|
||||
def __init__(self, ipv4: str, proxy: type, mode: int = 1):
|
||||
self.address = (ipv4, 80)
|
||||
def __init__(self, address: tuple, proxy: type, mode: int = 1):
|
||||
self.address = address
|
||||
self.proxy = proxy
|
||||
self.mode = self.MODES.get(mode, TCPAbridged)
|
||||
self.lock = threading.Lock()
|
||||
|
@ -35,4 +35,4 @@ class DataCenter:
|
||||
}
|
||||
|
||||
def __new__(cls, dc_id: int, test_mode: bool):
|
||||
return cls.TEST[dc_id] if test_mode else cls.PROD[dc_id]
|
||||
return (cls.TEST[dc_id], 80) if test_mode else (cls.PROD[dc_id], 443)
|
||||
|
@ -19,6 +19,7 @@
|
||||
import logging
|
||||
import platform
|
||||
import threading
|
||||
import time
|
||||
from datetime import timedelta, datetime
|
||||
from hashlib import sha1, sha256
|
||||
from io import BytesIO
|
||||
@ -61,7 +62,7 @@ class Session:
|
||||
|
||||
INITIAL_SALT = 0x616e67656c696361
|
||||
NET_WORKERS = 1
|
||||
WAIT_TIMEOUT = 30
|
||||
WAIT_TIMEOUT = 15
|
||||
MAX_RETRIES = 5
|
||||
ACKS_THRESHOLD = 8
|
||||
PING_INTERVAL = 5
|
||||
@ -159,6 +160,9 @@ class Session:
|
||||
log.info("Connection inited: Layer {}".format(layer))
|
||||
except (OSError, TimeoutError, Error):
|
||||
self.stop()
|
||||
except Exception as e:
|
||||
self.stop()
|
||||
raise e
|
||||
else:
|
||||
break
|
||||
|
||||
@ -308,8 +312,10 @@ class Session:
|
||||
break
|
||||
|
||||
try:
|
||||
self._send(functions.PingDelayDisconnect(0, self.PING_INTERVAL + 15), False)
|
||||
except (OSError, TimeoutError):
|
||||
self._send(functions.PingDelayDisconnect(
|
||||
0, self.WAIT_TIMEOUT + 10
|
||||
), False)
|
||||
except (OSError, TimeoutError, Error):
|
||||
pass
|
||||
|
||||
log.debug("PingThread stopped")
|
||||
@ -338,7 +344,7 @@ class Session:
|
||||
|
||||
try:
|
||||
self.current_salt = self._send(functions.GetFutureSalts(1)).salts[0]
|
||||
except (OSError, TimeoutError):
|
||||
except (OSError, TimeoutError, Error):
|
||||
self.connection.close()
|
||||
break
|
||||
|
||||
@ -395,12 +401,15 @@ class Session:
|
||||
|
||||
def send(self, data: Object):
|
||||
for i in range(self.MAX_RETRIES):
|
||||
self.is_connected.wait()
|
||||
self.is_connected.wait(self.WAIT_TIMEOUT)
|
||||
|
||||
try:
|
||||
return self._send(data)
|
||||
except (OSError, TimeoutError):
|
||||
(log.warning if i > 0 else log.info)("{}: {} Retrying {}".format(i, datetime.now(), type(data)))
|
||||
(log.warning if i > 2 else log.info)(
|
||||
"{}: {} Retrying {}".format(i, datetime.now(), type(data))
|
||||
)
|
||||
time.sleep(1)
|
||||
continue
|
||||
else:
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user