Lonami Exo
08b78f0c47
Unify retry loops in mtprotosender._connect
...
Now the retry count is not twice its value.
2019-10-24 13:40:09 +02:00
Lonami Exo
3039915ce9
Factor out parts from mtprotosender._connect
...
This will help unifying the retry loop and reconnecting
if the server disconnects us during auth key generation
which will be done in a follow-up commit.
2019-10-24 13:36:32 +02:00
Lonami Exo
09f27f0dd7
Update Telegram's RSA keys
2019-10-03 20:52:25 +02:00
Lonami Exo
e24dd3ad75
Prevent double-connect causing double-reads later
...
Which leads to "RuntimeError: readexactly() called while another
coroutine is already waiting for incoming data" being raised,
and causing everything to break or halt.
2019-08-11 19:05:11 +02:00
Lonami Exo
f5de2cd9a0
Fix logging bug on disconnect
2019-08-08 09:32:18 +02:00
Lonami Exo
a7a7c4add2
Pass all Updates when building events
2019-06-30 16:34:34 +02:00
Lonami Exo
aa2b3daccc
Factor out setting entities to events
2019-06-30 16:34:34 +02:00
Lonami
86cdb7c1f8
Remove accidentally-committed debug print
2019-06-15 23:14:59 +02:00
Lonami Exo
40d32cee95
Assert that dispatched updates are Updates
2019-06-15 21:15:57 +02:00
Lonami Exo
e5f1b2afa3
Update logging calls to use proper formatting
2019-05-17 12:30:13 +02:00
Lonami Exo
c1be0bd2e8
Fix disconnection without a previous connection
2019-05-11 16:53:11 +02:00
Lonami Exo
278f0e9e98
Don't raise errors during disconnect
2019-05-10 18:54:10 +02:00
Lonami Exo
cd4b915522
Add type hints to all public methods in the client
2019-05-03 21:38:41 +02:00
Lonami Exo
1e17ef1c98
Apply several lints
2019-05-03 21:38:41 +02:00
Lonami Exo
19664cd9cf
Call self._writer.wait_closed() on disconnect
...
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.wait_closed
2019-04-25 09:56:30 +02:00
yegor
8edbfbdced
Fix dd mode in MTProxies ( #1157 )
2019-04-19 22:09:22 +02:00
Lonami Exo
9965cda968
Save pts and date in a tuple for immutability
...
This way it is easy and cheap to copy the two required values
to all incoming updates in case we need to getDifference since
the previous pts/date to fetch entities.
This is still a work in progress.
2019-04-10 21:10:34 +04:00
Lonami Exo
ad963fd23e
Don't clear pending_ack on disconnect
...
Upon reconnecting, we must make sure to send all `pending_ack`,
or Telegram may resend some responses (e.g. causing duplicated
updates).
2019-03-28 12:16:15 +01:00
Lonami Exo
5554b414e1
Propagate the last error on reconnect, not always ConnectionError
2019-03-28 10:11:33 +01:00
Lonami Exo
7523869875
Except IOError and not ConnectionError
...
PySocks' errors do not subclass ConnectionError so the library
was unnecessarily logging them as unexpected, when any IOError
was actually expected.
2019-03-28 09:54:35 +01:00
Lonami Exo
f6fe580eb7
Safer auto reconnect to prevent double connect
2019-03-22 19:01:40 +01:00
Lonami Exo
436fb64289
Prevent double autoreconnect like #1112
2019-03-22 16:21:18 +01:00
Lonami Exo
04ba2e1fc7
Revert disconnect() to be async again ( #1133 )
...
It's the only way to properly clean all background tasks,
which the library makes heavy use for in MTProto/Connection
send and receive loops.
Some parts of the code even relied on the fact that it was
asynchronous (it used to return a future so you could await
it and not be breaking).
It's automatically syncified to reduce the damage of being
a breaking change.
2019-03-21 12:21:00 +01:00
Lonami Exo
2e4476a754
Workaround #1134 by early checking if proxy closes connection
2019-03-21 11:22:09 +01:00
Сергей Прохоров
43505e0aad
Use issubclass
instead of direct class comparison
2019-03-12 20:25:33 +01:00
Сергей Прохоров
4696dfc25e
Rework class hierarchy, try to DRY more
2019-03-12 01:12:55 +01:00
Сергей Прохоров
b873aa67cc
Implement different mtproto proxy protocols; refactor obfuscated2
2019-03-10 03:26:24 +01:00
Lonami Exo
8429f9bd3c
Update to v1.6
2019-02-27 21:04:18 +01:00
Lonami Exo
abadf3c789
Provide a blanket implementation for _init_conn
2019-02-21 10:43:31 +01:00
Lonami Exo
6de7329ce7
Fix Connection abstraction leak
2019-02-21 10:41:33 +01:00
Dmitry D. Chernov
d25442345e
Fix incorrect sending of DC id when connecting to MTProxy
2019-02-12 21:17:08 +10:00
Dmitry D. Chernov
45d0ba9e2f
Initial implementation of MTProxy support ( #1107 )
2019-02-11 00:16:46 +01:00
Dmitry D. Chernov
8c428e8566
Fix broken connection establishment in ConnectionTcpObfuscated
...
This regression was introduced in ebde3be820
.
2019-02-11 07:54:59 +10:00
Dmitry D. Chernov
c39cc06908
Fix incorrect check for reserved data prefix in ConnectionTcpObfuscated
2019-02-11 05:47:09 +10:00
Dmitry D. Chernov
fc2977fc0d
Tiny style fixes
2019-02-07 06:55:34 +10:00
Dmitry D. Chernov
c8f16a4e89
Fix a couple of inconsistencies in the public interface ( #1102 )
...
* Create `_NOT_A_REQUEST` when needed. Currently, modifications
in the raised exception would be "global".
* `retries` parameters were actually attempts. This has been fixed
to actually be the amount of retries, so 0 now means don't retry.
* Helper function to deal with retries instead of using a range with
different styles every time.
2019-02-06 19:41:45 +01:00
Lonami Exo
ae4d4ba3ef
Fix-up missing loggers from f271316
2019-01-12 12:15:29 +01:00
Tulir Asokan
f271316d7d
Make logger fully configurable ( #1087 )
2019-01-11 15:52:30 +01:00
Lonami Exo
95cf873bad
Don't mark the user as connected until successfull connection
...
The idea behind distinguishing between the user being connected and
the actual connection having been made was to support retries while
the user decided to connect, even if the connection wasn't made yet.
The problem is that _user_connected is used directly to tell whether
the sender is connected or not which will be wrong if an exception
occurs on the initial connection. Since the logic retry isn't used
there we can simply mark as connected once a successfull connection
is made.
2019-01-02 10:53:10 +01:00
Lonami Exo
d2ac7e5b0a
Actually perform all checks in 2fa
2018-12-24 14:16:50 +01:00
Sister Midnight
f3013c6817
Fix ConnectionHttp SSL socket wrap ( #1064 )
2018-12-10 14:43:48 +01:00
Lonami Exo
c48d41d99d
Expect ConnectionError in the send loop
2018-12-06 16:27:09 +01:00
Lonami Exo
10b9b4b969
Handle TimeoutError on automatic reconnect
2018-11-29 13:11:34 +01:00
Lonami Exo
d2e995ef95
Change code to recv and handle disconnections
2018-11-24 20:53:28 +01:00
Lonami Exo
f046d1f0a3
Fix deadlock on unexpected disconnections
2018-11-10 11:23:19 +01:00
Lonami Exo
cdbd1f6193
Fix valid auth_key never being saved after switching DC
2018-11-03 18:53:26 +01:00
Lonami Exo
67c5572d7b
Possibly fix possible deadlock
2018-10-28 11:53:28 +01:00
painor
45999001be
Added retry_delay parameter for auto-reconnection ( #1031 )
2018-10-28 10:55:58 +01:00
Lonami Exo
b0e587c03d
Except expected ConnectionError in the receive loop
2018-10-26 10:36:33 +02:00
Lonami Exo
091180b32d
Except CancelledError in MTProtoSender send/recv loop
...
This way, the tasks should not end with the cancelled exception
which should get rid of the warning if any.
2018-10-25 15:54:25 +02:00
Lonami Exo
4562ba9ccf
Fix auth_key not actually being saved
...
This would make the user have to login every time.
2018-10-22 20:58:07 +02:00
Lonami Exo
7dece209a0
Cancel tasks on reconnect instead of awaiting them
...
This prevents us from locking forever on any task that doesn't
rely on cancellation tokens, in this case, Connection.recv()'s
_recv_queue.get() would never complete after the server closed
the connection.
Additionally, working with cancellation tokens in asyncio is
somewhat annoying to do.
Last but not least removing the Connection._disconnected future
avoids the need to use its state (if an exception was set it
should be retrieved) to prevent asyncio from complaining, which
it was before.
2018-10-21 16:20:05 +02:00
Lonami Exo
f2e77f4030
Fix using the wrong logger in Connection
2018-10-21 16:10:09 +02:00
Lonami Exo
0686ec4440
Implement after_msg_id back
2018-10-19 16:53:50 +02:00
Lonami Exo
9dc4009152
Handle the right errors
2018-10-19 14:41:50 +02:00
Lonami Exo
b93b01cb02
Fix manual BadMessageError instantiation
2018-10-19 14:02:20 +02:00
Lonami Exo
6b280dc3bd
Clarify MTProtoSender._disconnected
2018-10-19 14:01:03 +02:00
Lonami Exo
945b34b103
Set MTProtoSender.auth_key on its creation
2018-10-19 13:56:11 +02:00
Lonami Exo
8563b9560d
Fix auth_key not being set
2018-10-19 13:35:29 +02:00
Lonami Exo
939854a0dd
Fix-up e2fe3eb
(packer was OK, encryption was not made)
2018-10-19 13:33:24 +02:00
Lonami Exo
f5bc952309
Don't set the disconnected flag twice
2018-10-19 13:25:00 +02:00
Lonami Exo
e2fe3eb503
Use new broken MessagePacker
2018-10-19 13:24:52 +02:00
Lonami Exo
6d30a38316
Let Connection._disconnected be a proper Future
...
This means that awaiting on disconnect will properly raise errors,
allowing to differentiate clean disconnects from faulty ones.
2018-10-19 10:46:34 +02:00
Lonami Exo
542d0f539b
Revisit connection and properly detail the class' intent
2018-10-19 10:35:22 +02:00
Lonami Exo
9cbc088b76
Make disconnect synchronous
...
This also fixes a bug when auto-reconnecting in MTProtoSender.
2018-10-16 11:56:17 +02:00
Lonami Exo
99129daeee
Show the request that caused RPC errors in their messages
2018-10-15 18:35:51 +02:00
Lonami Exo
6e77f583f1
Detect arbitrary negative HTTP error codes
2018-10-12 19:47:40 +02:00
Lonami Exo
ded24db3dd
Fix proxy support by removing conflicting arguments
2018-10-06 20:56:09 +02:00
Lonami Exo
fb9660afe0
Add missing awaits
2018-10-06 12:39:07 +02:00
josephbiko
3dd8b7c6d1
Support async def in sessions ( #1013 )
2018-10-05 20:25:49 +02:00
Lonami Exo
dc77136453
Don't expect responses from ack, log send errors, remove TODOs
2018-10-05 13:26:44 +02:00
Lonami Exo
ef60ade647
Rewrite container packing to support arbitrary sizes
2018-10-05 13:26:44 +02:00
Lonami Exo
7e7bbcf4c0
Remove irrelevant TODOs and add more logging
2018-10-05 13:26:44 +02:00
Lonami Exo
a5d4e97922
Fix alternative connection modes
2018-10-05 13:26:44 +02:00
Lonami Exo
ebde3be820
Add support for proxy again
2018-10-05 13:26:44 +02:00
Lonami Exo
db83709c6b
Support connection timeout
2018-10-05 13:26:44 +02:00
Lonami Exo
1b9d6aac06
Gzip only content related data
2018-10-05 13:26:44 +02:00
Lonami Exo
37b9922f64
Handle cancellation on the receive loop
2018-10-05 13:26:44 +02:00
Lonami Exo
e319fa3aa9
Handle IncompleteReadError and InvalidChecksumError
2018-10-05 13:26:44 +02:00
Lonami Exo
3fd7c33127
Fix automatic reconnect (e.g. on bad auth key)
...
This took more time than it should have to debug.
2018-10-05 13:26:44 +02:00
Lonami Exo
bc1fd9039d
Handle receiving errors
2018-10-05 13:26:44 +02:00
Lonami Exo
cf7e5d5592
Set auth_key on connection
2018-10-05 13:26:44 +02:00
Lonami Exo
21ffa2f26b
Fix DC migration and seqno
2018-10-05 13:26:44 +02:00
Lonami Exo
ac567ebf1d
Handle bad salt/msg not resending containers
2018-10-05 13:26:44 +02:00
Lonami Exo
3b1142aaca
Add back auth key generation process
2018-10-05 13:26:44 +02:00
Lonami Exo
5edc2216c7
Handle initial connection if network is down correctly
2018-10-05 13:26:44 +02:00
Lonami Exo
2d275989cb
Properly handle cancellation in _ReadyQueue
2018-10-05 13:26:44 +02:00
Lonami Exo
105bd52eee
Abstract the send queue off MTProtoSender
2018-10-05 13:26:44 +02:00
Lonami Exo
b02ebcb69b
Stop waiting for send items on disconnection
2018-10-05 13:26:44 +02:00
Lonami Exo
470fb9f5df
Make use of the MTProtoLayer in MTProtoSender
2018-10-05 13:26:44 +02:00
Lonami Exo
9402b4a26d
Create a new layer to lift encryption off the MTProtoSender
2018-10-05 13:26:44 +02:00
Lonami Exo
5daad2aaab
Actually use the new connection class
2018-10-05 13:26:44 +02:00
Lonami Exo
daf94e416b
Fix connection never receiving and missing clone method
2018-10-05 13:26:44 +02:00
Lonami Exo
2fd51b8582
Let all connection modes implement the new Connection
2018-10-05 13:26:44 +02:00
Lonami Exo
096424ea78
Create a new Connection class to work through queues
2018-10-05 13:26:44 +02:00
Lonami Exo
fbc46bd388
Use loop.create_future instead asyncio.Future
2018-08-21 12:22:06 +02:00
Lonami Exo
47190d7d55
Fix event loop not being passed into many asyncio calls
2018-08-21 11:31:14 +02:00
Lonami Exo
f0cd1fdd6e
Don't disconnect sender on cancellation ( #958 )
...
This was causing a "race condition" where the sender would
be disconnected after cancellation when another was created.
2018-08-20 14:59:17 +02:00
Lonami Exo
171e13daa9
Special case File responses without parent request ( #658 )
2018-08-20 11:42:51 +02:00
Lonami Exo
f4b9c9d6d4
Remove critical code from assert statements
2018-08-14 19:14:13 +02:00