Skip to content

Commit a25e05c

Browse files
committed
fix: source _RECENT_PACKETS_MAX from const so cdef restores C-int compare
1 parent 5ef3054 commit a25e05c

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/zeroconf/_listener.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cdef object DEBUG_ENABLED
1313
cdef bint TYPE_CHECKING
1414

1515
cdef cython.uint _MAX_MSG_ABSOLUTE
16+
cdef cython.uint _RECENT_PACKETS_MAX
1617

1718

1819
cdef class AsyncListener:

src/zeroconf/_listener.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
from ._protocol.incoming import DNSIncoming
3333
from ._transport import _WrappedTransport, make_wrapped_transport
3434
from ._utils.time import current_time_millis, millis_to_seconds
35-
from .const import _DUPLICATE_PACKET_SUPPRESSION_INTERVAL, _MAX_MSG_ABSOLUTE
35+
from .const import _DUPLICATE_PACKET_SUPPRESSION_INTERVAL, _MAX_MSG_ABSOLUTE, _RECENT_PACKETS_MAX
3636

3737
if TYPE_CHECKING:
3838
from ._core import Zeroconf
3939

4040
_TC_DELAY_RANDOM_INTERVAL = (400, 500)
4141

42-
# Bounded recency window so an alternating (A, B, A, B, ...) flood can't
43-
# slip past single-slot dedup. State lives on the listener (one per
44-
# interface) so a duplicate seen on one interface does not suppress a
45-
# legitimate QU / unicast reply that arrives on a different interface.
46-
_RECENT_PACKETS_MAX = 16
42+
# Bounded recency window (`_RECENT_PACKETS_MAX`, imported from `.const`)
43+
# so an alternating (A, B, A, B, ...) flood can't slip past single-slot
44+
# dedup. State lives on the listener (one per interface) so a duplicate
45+
# seen on one interface does not suppress a legitimate QU / unicast
46+
# reply that arrives on a different interface.
4747

4848

4949
_bytes = bytes

src/zeroconf/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
_LISTENER_TIME = 200 # ms
3434
_BROWSER_TIME = 10000 # ms
3535
_DUPLICATE_PACKET_SUPPRESSION_INTERVAL = 1000 # ms
36+
_RECENT_PACKETS_MAX = 16 # Bounded recency window for per-listener dedup
3637
_DUPLICATE_QUESTION_INTERVAL = 999 # ms # Must be 1ms less than _DUPLICATE_PACKET_SUPPRESSION_INTERVAL
3738
_CACHE_CLEANUP_INTERVAL = 10 # s
3839
_LOADED_SYSTEM_TIMEOUT = 10 # s

tests/test_listener.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def handle_query_or_defer(
365365
now = current_time_millis()
366366

367367
packets = []
368-
for i in range(_listener._RECENT_PACKETS_MAX + 4):
368+
for i in range(const._RECENT_PACKETS_MAX + 4):
369369
query = r.DNSOutgoing(const._FLAGS_QR_QUERY, multicast=True)
370370
query.add_question(r.DNSQuestion(f"n{i}._http._tcp.local.", const._TYPE_PTR, const._CLASS_IN))
371371
packets.append(query.packets()[0])
@@ -377,7 +377,7 @@ def handle_query_or_defer(
377377
_handle_query_or_defer.reset_mock()
378378

379379
# The oldest packets should have been evicted and now replay.
380-
evicted = packets[: len(packets) - _listener._RECENT_PACKETS_MAX]
380+
evicted = packets[: len(packets) - const._RECENT_PACKETS_MAX]
381381
for packet in evicted:
382382
listener._process_datagram_at_time(False, len(packet), now, packet, addrs)
383383
assert _handle_query_or_defer.call_count == len(evicted)

0 commit comments

Comments
 (0)