Commit Graph

100 Commits

Author SHA1 Message Date
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
10b9b4b969 Handle TimeoutError on automatic reconnect 2018-11-29 13:11:34 +01:00
Lonami Exo
cdbd1f6193 Fix valid auth_key never being saved after switching DC 2018-11-03 18:53:26 +01:00
painor
45999001be Added retry_delay parameter for auto-reconnection (#1031) 2018-10-28 10:55:58 +01: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
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
e2fe3eb503 Use new broken MessagePacker 2018-10-19 13:24:52 +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
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
7e7bbcf4c0 Remove irrelevant TODOs and add more logging 2018-10-05 13:26:44 +02:00
Lonami Exo
db83709c6b Support connection timeout 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
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
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
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
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
a688c8a4ce Fix exception ignored warnings and invalid state #935 2018-08-04 15:06:11 +02:00
Lonami Exo
7729a2a78f More logging for bad messages (#907) 2018-07-25 12:33:12 +02:00
Lonami Exo
b3990546eb Fix RPCError may occur for no parent message (#908) 2018-07-25 12:19:28 +02:00
josephbiko
e6981e7676 Remove empty except (#887) 2018-07-09 20:54:43 +02:00
Lonami Exo
393e1966c7 Avoid exceeding maximum container size
This issue would likely be triggered when automatically
merging multiple requests into a single one while having
their size exceed 1044456 bytes like SaveFilePartRequest.

This commit avoids such issue by keeping track of the
current size, and if it exceeds the limit, avoid merge.
2018-07-07 11:58:48 +02:00
Lonami Exo
33ce702ab9 Pre-pack outgoing TLMessage
This has several benefits:
- The message can be resent without re-calling bytes(),
  which for some requests may be expensive.
- Converting requests to bytes early lets us detect
  errors early, such as OverflowError on bad requests.
- Containers can't exceed 1044456 bytes so knowing their
  length is important. This can now be done in O(1).

But also several drawbacks:
- If the object is modified the bytes won't reflect this.
  This isn't an issue because it's only done for in msgs.
- Incoming messages can no longer be reconverted into
  bytes but this was never needed anyway.
2018-07-07 11:46:21 +02:00
Lonami Exo
a6782ac6ea Send getState upon successful reconnection 2018-06-27 19:40:32 +02:00
Lonami Exo
18f06f1a25 Fix bad notification due to wrong system clock never ending 2018-06-27 19:04:33 +02:00
Lonami Exo
4be248932d Fix non-ending awaits due to requests not being resent on reconnect 2018-06-27 10:26:26 +02:00
Lonami Exo
58aadce5ba Fix-up 2b090f8 not actually resaving new auth_keys 2018-06-27 10:15:59 +02:00