From 943ea019982c779d64e61c21fee3c5a712a26c89 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 31 Oct 2022 06:50:11 -0500 Subject: [PATCH] feat: speed up auth phase We now try to read a whole line at a time since there is no risk of reading too far ahead given that the spec says: The first octet received by the server after the \r\n of the BEGIN command from the client must be the first octet of the authenticated/encrypted stream of D-Bus messages. Unlike all other commands, the server does not reply to the BEGIN command with an authentication command of its own. After the \r\n of the reply to the command before BEGIN, the next octet received by the client must be the first octet of the authenticated/encrypted stream of D-Bus messages. fixes #128 --- src/dbus_fast/aio/message_bus.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dbus_fast/aio/message_bus.py b/src/dbus_fast/aio/message_bus.py index b0941f68..8d5aea30 100644 --- a/src/dbus_fast/aio/message_bus.py +++ b/src/dbus_fast/aio/message_bus.py @@ -430,7 +430,9 @@ def done(fut): async def _auth_readline(self) -> str: buf = b"" while buf[-2:] != b"\r\n": - buf += await self._loop.sock_recv(self._sock, 2) + # The auth protocol is line based, so we can read until we get a + # newline. + buf += await self._loop.sock_recv(self._sock, 1024) return buf[:-2].decode() async def _authenticate(self) -> None: @@ -455,6 +457,9 @@ async def _authenticate(self) -> None: ) self._stream.flush() if response == "BEGIN": + # The first octet received by the server after the \r\n of the BEGIN command + # from the client must be the first octet of the authenticated/encrypted stream + # of D-Bus messages. break def disconnect(self) -> None: