8000 feat: reorder incoming data handler to reduce overhead by bdraco · Pull Request #1189 · python-zeroconf/python-zeroconf · GitHub
[go: up one dir, main page]

Skip to content

feat: reorder incoming data handler to reduce overhead #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,9 @@ def datagram_received(
self, data: bytes, addrs: Union[Tuple[str, int], Tuple[str, int, int, int]]
) -> None:
assert self.transport is not None
v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = ()
data_len = len(data)
debug = log.isEnabledFor(logging.DEBUG)

if len(addrs) == 2:
# https://github.com/python/mypy/issues/1178
addr, port = addrs # type: ignore
scope = None
else:
# https://github.com/python/mypy/issues/1178
addr, port, flow, scope = addrs # type: ignore
if debug:
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
v6_flow_scope = (flow, scope)

if data_len > _MAX_MSG_ABSOLUTE:
# Guard against oversized packets to ensure bad implementations cannot overwhelm
# the system.
Expand All @@ -308,15 +296,26 @@ def datagram_received(
# Guard against duplicate packets
if debug:
log.debug(
'Ignoring duplicate message with no unicast questions received from %r:%r [socket %s] (%d bytes) as [%r]',
addr,
port,
'Ignoring duplicate message with no unicast questions received from %s [socket %s] (%d bytes) as [%r]',
addrs,
self.sock_description,
data_len,
data,
)
return

v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = ()
if len(addrs) == 2:
# https://github.com/python/mypy/issues/1178
addr, port = addrs # type: ignore
scope = None
else:
# https://github.com/python/mypy/issues/1178
addr, port, flow, scope = addrs # type: ignore
if debug:
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
v6_flow_scope = (flow, scope)

msg = DNSIncoming(data, (addr, port), scope, now)
self.data = data
self.last_time = now
Expand Down
0