diff --git a/telethon/network/connection/connection.py b/telethon/network/connection/connection.py index 5fce6f11..e61f8720 100644 --- a/telethon/network/connection/connection.py +++ b/telethon/network/connection/connection.py @@ -127,7 +127,6 @@ class Connection(abc.ABC): else: raise result from None - # TODO Get/put to the queue with cancellation async def _send_loop(self): """ This loop is constantly popping items off the queue to send them. diff --git a/telethon/network/mtprotolayer.py b/telethon/network/mtprotolayer.py index 731cabb8..3c21877b 100644 --- a/telethon/network/mtprotolayer.py +++ b/telethon/network/mtprotolayer.py @@ -1,10 +1,13 @@ import io +import logging import struct from .mtprotostate import MTProtoState from ..tl import TLRequest from ..tl.core.messagecontainer import MessageContainer +__log__ = logging.getLogger(__name__) + class MTProtoLayer: """ @@ -64,7 +67,6 @@ class MTProtoLayer: nested inside another message and message container) and returns the serialized message data. """ - # TODO write_data_as_message raises on invalid messages, handle it # TODO This method could be an iterator yielding messages while small # respecting the ``MessageContainer.MAXIMUM_SIZE`` limit. # @@ -84,6 +86,10 @@ class MTProtoLayer: n += 1 state.msg_id = self._state.write_data_as_message( buffer, state.data, isinstance(state.request, TLRequest)) + + __log__.debug('Assigned msg_id = %d to %s (%x)', + state.msg_id, state.request.__class__.__name__, + id(state.request)) else: last_id = None for s in state: @@ -92,6 +98,9 @@ class MTProtoLayer: buffer, s.data, isinstance(s.request, TLRequest), after_id=last_id) + __log__.debug('Assigned msg_id = %d to %s (%x)', + s.msg_id, s.request.__class__.__name__, + id(s.request)) if n > 1: # Inlined code to pack several messages into a container # @@ -112,7 +121,9 @@ class MTProtoLayer: for s in state: s.container_id = container_id - return buffer.getvalue() + r = buffer.getvalue() + __log__.debug('Packed %d message(s) in %d bytes for sending', n, len(r)) + return r def __str__(self): return str(self._connection) diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 4d96cb2c..29869a63 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -343,7 +343,6 @@ class MTProtoSender: if state_list is None: break - # TODO Debug logs to notify which messages are being sent # TODO Try sending them while no future was cancelled? # TODO Handle cancelled?, arbitrary errors await self._connection.send(state_list) @@ -362,7 +361,6 @@ class MTProtoSender: Besides `connect`, only this method ever receives data. """ while self._user_connected and not self._reconnecting: - # TODO handle incomplete read? __log__.debug('Receiving items from the network...') try: message = await self._connection.recv()