Commit Graph

52 Commits

Author SHA1 Message Date
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
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
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
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
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
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
67c5572d7b Possibly fix possible deadlock 2018-10-28 11:53:28 +01:00
Lonami Exo
b0e587c03d Except expected ConnectionError in the receive loop 2018-10-26 10:36:33 +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
9dc4009152 Handle the right errors 2018-10-19 14:41:50 +02:00
Lonami Exo
f5bc952309 Don't set the disconnected flag twice 2018-10-19 13:25:00 +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
ded24db3dd Fix proxy support by removing conflicting arguments 2018-10-06 20:56:09 +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
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
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
9402b4a26d Create a new layer to lift encryption off the MTProtoSender 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
128053750d
Implement HTTP(S) mode (closes #112) (#883) 2018-07-08 17:45:49 +02:00
Lonami Exo
226c35ff8f Pump up default timeout from 5 to 10s 2018-06-17 11:46: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
9477c75fce Fix basic requests sending and receiving 2018-06-06 21:42:48 +02:00
Lonami Exo
e469258ab9 Create a new MTProtoSender structure and its foundation
This means that the TcpClient and the Connection (currently only
ConnectionTcpFull) will no longer be concerned about handling
errors, but the MTProtoSender will.

The foundation of the library will now be based on asyncio.
2018-06-06 20:41:01 +02:00