Skip to content

Commit 6bcbe4c

Browse files
committed
fix: restore _DUPLICATE_PACKET_SUPPRESSION_INTERVAL cdef and rework suppression fixture
1 parent 4eceea5 commit 6bcbe4c

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎setup.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
from setuptools import setup
3+
4+
package_dir = \
5+
{'': 'src'}
6+
7+
packages = \
8+
['zeroconf',
9+
'zeroconf._handlers',
10+
'zeroconf._protocol',
11+
'zeroconf._services',
12+
'zeroconf._utils']
13+
14+
package_data = \
15+
{'': ['*']}
16+
17+
install_requires = \
18+
['ifaddr>=0.1.7']
19+
20+
setup_kwargs = {
21+
'name': 'zeroconf',
22+
'version': '0.149.9',
23+
'description': 'A pure python implementation of multicast DNS service discovery',
24+
'long_description': 'python-zeroconf\n===============\n\n.. image:: https://github.com/python-zeroconf/python-zeroconf/workflows/CI/badge.svg\n :target: https://github.com/python-zeroconf/python-zeroconf?query=workflow%3ACI+branch%3Amaster\n\n.. image:: https://img.shields.io/pypi/v/zeroconf.svg\n :target: https://pypi.python.org/pypi/zeroconf\n\n.. image:: https://codecov.io/gh/python-zeroconf/python-zeroconf/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/python-zeroconf/python-zeroconf\n\n.. image:: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json\n :target: https://codspeed.io/python-zeroconf/python-zeroconf\n :alt: Codspeed.io status for python-zeroconf\n\n.. image:: https://readthedocs.org/projects/python-zeroconf/badge/?version=latest\n :target: https://python-zeroconf.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\n`Documentation <https://python-zeroconf.readthedocs.io/en/latest/>`_.\n\nThis is fork of pyzeroconf, Multicast DNS Service Discovery for Python,\noriginally by Paul Scott-Murphy (https://github.com/paulsm/pyzeroconf),\nmodified by William McBrine (https://github.com/wmcbrine/pyzeroconf).\n\nThe original William McBrine\'s fork note::\n\n This fork is used in all of my TiVo-related projects: HME for Python\n (and therefore HME/VLC), Network Remote, Remote Proxy, and pyTivo.\n Before this, I was tracking the changes for zeroconf.py in three\n separate repos. I figured I should have an authoritative source.\n\n Although I make changes based on my experience with TiVos, I expect that\n they\'re generally applicable. This version also includes patches found\n on the now-defunct (?) Launchpad repo of pyzeroconf, and elsewhere\n around the net -- not always well-documented, sorry.\n\nCompatible with:\n\n* Bonjour\n* Avahi\n\nCompared to some other Zeroconf/Bonjour/Avahi Python packages, python-zeroconf:\n\n* isn\'t tied to Bonjour or Avahi\n* doesn\'t use D-Bus\n* doesn\'t force you to use particular event loop or Twisted (asyncio is used under the hood but not required)\n* is pip-installable\n* has PyPI distribution\n* has an optional cython extension for performance (pure python is supported as well)\n\nPython compatibility\n--------------------\n\n* CPython 3.10+\n* PyPy 3.10+\n\nVersioning\n----------\n\nThis project uses semantic versioning.\n\nStatus\n------\n\nThis project is actively maintained.\n\nTraffic Reduction\n-----------------\n\nBefore version 0.32, most traffic reduction techniques described in https://datatracker.ietf.org/doc/html/rfc6762#section-7\nwhere not implemented which could lead to excessive network traffic. It is highly recommended that version 0.32 or later\nis used if this is a concern.\n\nIPv6 support\n------------\n\nIPv6 support is relatively new and currently limited, specifically:\n\n* `InterfaceChoice.All` is an alias for `InterfaceChoice.Default` on non-POSIX\n systems.\n* Dual-stack IPv6 sockets are used, which may not be supported everywhere (some\n BSD variants do not have them).\n* Listening on localhost (`::1`) does not work. Help with understanding why is\n appreciated.\n\nHow to get python-zeroconf?\n===========================\n\n* PyPI page https://pypi.org/project/zeroconf/\n* GitHub project https://github.com/python-zeroconf/python-zeroconf\n\nThe easiest way to install python-zeroconf is using pip::\n\n pip install zeroconf\n\n\n\nHow do I use it?\n================\n\nHere\'s an example of browsing for a service:\n\n.. code-block:: python\n\n from zeroconf import ServiceBrowser, ServiceListener, Zeroconf\n\n\n class MyListener(ServiceListener):\n\n def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:\n print(f"Service {name} updated")\n\n def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:\n print(f"Service {name} removed")\n\n def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:\n info = zc.get_service_info(type_, name)\n print(f"Service {name} added, service info: {info}")\n\n\n zeroconf = Zeroconf()\n listener = MyListener()\n browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)\n try:\n input("Press enter to exit...\\n\\n")\n finally:\n zeroconf.close()\n\n.. note::\n\n Discovery and service registration use *all* available network interfaces by default.\n If you want to customize that you need to specify ``interfaces`` argument when\n constructing ``Zeroconf`` object (see the code for details).\n\nIf you don\'t know the name of the service you need to browse for, try:\n\n.. code-block:: python\n\n from zeroconf import ZeroconfServiceTypes\n print(\'\\n\'.join(ZeroconfServiceTypes.find()))\n\nSee examples directory for more.\n\nChangelog\n=========\n\n`Changelog <CHANGELOG.md>`_\n\nLicense\n=======\n\nLGPL, see COPYING file for details.\n',
25+
'author': 'Paul Scott-Murphy',
26+
'author_email': 'None',
27+
'maintainer': 'None',
28+
'maintainer_email': 'None',
29+
'url': 'https://github.com/python-zeroconf/python-zeroconf',
30+
'package_dir': package_dir,
31+
'packages': packages,
32+
'package_data': package_data,
33+
'install_requires': install_requires,
34+
'python_requires': '>=3.10',
35+
}
36+
from build_ext import *
37+
build(setup_kwargs)
38+
39+
setup(**setup_kwargs)

‎src/zeroconf/_listener.pxd‎

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

1515
cdef cython.uint _MAX_MSG_ABSOLUTE
1616
cdef cython.uint _RECENT_PACKETS_MAX
17+
cdef cython.uint _DUPLICATE_PACKET_SUPPRESSION_INTERVAL
1718

1819

1920
cdef class AsyncListener:

‎tests/conftest.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,23 @@ def run_isolated():
3636

3737
@pytest.fixture
3838
def disable_duplicate_packet_suppression() -> Generator[None]:
39-
"""Disable duplicate packet suppression."""
40-
# _listener rebinds the interval at module scope, so const-only
41-
# patching does not reach the hot path.
39+
"""Disable duplicate packet suppression.
40+
41+
Wraps `_process_datagram_at_time` so the recency window is cleared
42+
before each call, which reaches both pure-Python and Cython builds —
43+
a const-only patch never reaches the hot path because `_listener`
44+
rebinds the interval at module scope, and the rebound name is
45+
cdef'd in `_listener.pxd` for the C-int compare on hot packets.
46+
"""
47+
orig = _listener.AsyncListener._process_datagram_at_time
48+
49+
def _clear_then_process(self, *args, **kwargs):
50+
self._recent_packets.clear()
51+
return orig(self, *args, **kwargs)
52+
4253
with (
4354
patch.object(const, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0),
44-
patch.object(_listener, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0),
55+
patch.object(_listener.AsyncListener, "_process_datagram_at_time", _clear_then_process),
4556
):
4657
yield
4758

0 commit comments

Comments
 (0)