Commit Graph

246 Commits

Author SHA1 Message Date
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
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
7b6e65a7a5 Re-export ConnectionHttp from the network package 2018-07-08 17:48:38 +02:00
Lonami
128053750d
Implement HTTP(S) mode (closes #112) (#883) 2018-07-08 17:45:49 +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
fb40e7b508 Update mtprotoplainsender.py asserts 2018-06-28 09:48:03 +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
Lonami Exo
19900a373a More useful messages from authenticator.py 2018-06-26 11:32:09 +02:00
Lonami Exo
59f6b75391 Stop showing "data left after" warning 2018-06-25 12:54:33 +02:00
Lonami Exo
184424957d Create a separate method to start reconnections 2018-06-24 10:44:31 +02:00
Lonami Exo
a99fce471a Fix cancelling a None handle on first connection+error 2018-06-21 09:48:11 +02:00
Lonami Exo
4ab5c7d92d Fix reconnect sentinel when not reconnecting in send_loop
It would cause issues with the debug logs, since it assumes it's
a TLMessage, which have an .obj attribute. Second, the send_loop
is also smarter regarding reconnects (since OSError often occur
due to not being connected at all, namely ConnectionResetError).
2018-06-20 18:19:57 +02:00
Lonami Exo
ad1ab64415 Save last ack to resend in case of bad salt 2018-06-20 11:12:04 +02:00
Lonami Exo
463847ad50 Revisit and remove a few TODOs 2018-06-18 18:46:06 +02:00
Lonami Exo
ebfe8ebf40 Configurable per-client request/connection retries 2018-06-18 18:13:00 +02:00
Lonami Exo
09ea1179ca Except msg_id KeyError on bad salt/msg 2018-06-18 17:20:31 +02:00
Lonami Exo
3648f7c756 Log outgoing message types and incoming message IDs 2018-06-18 17:14:04 +02:00
Lonami Exo
51d8ea0fa8 Shield disconnected Future in the MTProtoSender instead 2018-06-18 15:55:24 +02:00
Lonami Exo
7641ba2d32 Fix sleep on the wrong indent and handle CancelledError
This was causing a huge slow-down every time a request was
received delaying all the subsequent incoming messages too
2018-06-18 13:29:12 +02:00
Lonami Exo
374f5e2aab Periodically send ping/getState 2018-06-18 13:22:25 +02:00
Lonami Exo
94d6c339c4 Add more logging in the MTProtoSender 2018-06-18 11:29:54 +02:00
Lonami Exo
e36aff51dd Raise ConnectionError when sending without connection
Otherwise the program could potentially block on await client(...)
since this has no timeout (unless asyncio.wait_for() was used) and
would give no further hint that the program was halted there.
2018-06-17 20:25:22 +02:00
Dan Elkouby
d5b349e031 Implement a mechanism to notify of connection failures (#852) 2018-06-17 19:29:41 +02:00
Lonami Exo
d9d586171f Fix MTProtoSender should not send content-related queries 2018-06-17 16:23:22 +02:00
Lonami Exo
226c35ff8f Pump up default timeout from 5 to 10s 2018-06-17 11:46:56 +02:00
Lonami Exo
d18ee9ecc5 Handle (re)connection errors more gracefully 2018-06-17 11:41:35 +02:00
Lonami Exo
8086772506 Make sure not to include sentinel in containers 2018-06-16 18:40:08 +02:00
Lonami Exo
bb2cacd525 Fix automatic reconnection by unblocking the send queue 2018-06-16 18:34:36 +02:00
Dan Elkouby
df15ee421c Except connection timeouts in MTProtoSender 2018-06-15 10:58:29 +03:00
Lonami Exo
091b03c635 Use create_task instead ensure_future 2018-06-14 23:33:56 +02:00
Lonami Exo
0f14f3b16a Support custom event loops 2018-06-14 19:35:12 +02:00
Lonami Exo
908dfa148b Revisit codebase to add missing async/await 2018-06-14 17:09:20 +02:00
Lonami Exo
5bb2f50232 Handle Msg state/resend/all (from 7c0af2c by @andr-04) 2018-06-14 16:23:16 +02:00
Lonami Exo
4a9eb5b085 Handle OSError on MTProtoSender 2018-06-14 16:16:11 +02:00
Lonami Exo
8a787e90c2 Remove send/recv locks
There is only one method sending and one method receiving,
so it doesn't make sense to lock-protect those operations.
2018-06-13 10:04:27 +02:00
Lonami Exo
3f16c92eb3 Subclass TLRequest for content-related objects 2018-06-12 20:14:21 +02:00
Lonami Exo
d1afc70963 Fix setting Pong results 2018-06-12 19:46:37 +02:00
Lonami Exo
64dd957189 Fix None first_query and TcpClient.disconnect() 2018-06-11 19:51:01 +02:00
Lonami Exo
15ef302428 Implement _switch_dc/fix missing first request 2018-06-10 21:30:31 +02:00