File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 2626
2727
2828class MsgFactory :
29- def __init__ (self , server_time : float = 0 ):
29+ def __init__ (self ):
3030 self .seq_no = SeqNo ()
31- self .server_time = server_time
3231
3332 def __call__ (self , body : TLObject ) -> Message :
3433 return Message (
3534 body ,
36- MsgId (self . server_time ),
35+ MsgId (),
3736 self .seq_no (not isinstance (body , not_content_related )),
3837 len (body )
3938 )
Original file line number Diff line number Diff line change 1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import logging
20+ from datetime import datetime
1921from time import monotonic
2022
23+ log = logging .getLogger (__name__ )
24+
2125
2226class MsgId :
2327 reference_clock = monotonic ()
2428 last_time = 0
2529 msg_id_offset = 0
30+ server_time = 0
2631
27- def __new__ (cls , server_time : float = 0 ) -> int :
28- now = monotonic () - cls .reference_clock + server_time
32+ def __new__ (cls ) -> int :
33+ now = monotonic () - cls .reference_clock + cls . server_time
2934 cls .msg_id_offset = cls .msg_id_offset + 4 if now == cls .last_time else 0
3035 msg_id = int (now * 2 ** 32 ) + cls .msg_id_offset
3136 cls .last_time = now
3237
3338 return msg_id
39+
40+ @classmethod
41+ def set_server_time (cls , server_time : int ):
42+ if not cls .server_time :
43+ cls .server_time = server_time
44+ log .info (f"Time synced: { datetime .utcfromtimestamp (server_time )} UTC" )
Original file line number Diff line number Diff line change 2323from datetime import datetime , timedelta
2424from hashlib import sha1
2525from io import BytesIO
26+ import os
2627
2728import pyrogram
2829from pyrogram import __copyright__ , __license__ , __version__
@@ -96,7 +97,7 @@ def __init__(
9697
9798 self .auth_key_id = sha1 (auth_key ).digest ()[- 8 :]
9899
99- self .session_id = Long ( MsgId ( time . time ()) )
100+ self .session_id = os . urandom ( 8 )
100101 self .msg_factory = MsgFactory ()
101102
102103 self .current_salt = None
@@ -247,9 +248,7 @@ async def handle_packet(self, packet):
247248
248249 for msg in messages :
249250 if msg .seq_no == 0 :
250- server_time = msg .msg_id / (2 ** 32 )
251- self .msg_factory .server_time = server_time
252- log .info (f"Time synced: { datetime .utcfromtimestamp (server_time )} UTC" )
251+ MsgId .set_server_time (msg .msg_id / (2 ** 32 ))
253252
254253 if msg .seq_no % 2 != 0 :
255254 if msg .msg_id in self .pending_acks :
You can’t perform that action at this time.
0 commit comments