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
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
5BD8
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