◐ Shell
reader mode source ↗
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ If you don't know the name of the service you need to browse for, try:
from zeroconf import ZeroconfServiceTypes
print('\n'.join(ZeroconfServiceTypes.find()))

See examples directory for more.

Changelog
Expand Down
33 changes: 32 additions & 1 deletion src/zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from types import TracebackType

from ._cache import DNSCache
from ._dns import DNSQuestion, DNSQuestionType
from ._engine import AsyncEngine
from ._exceptions import NonUniqueNameException, NotRunningException
from ._handlers.multicast_outgoing_queue import MulticastOutgoingQueue
Expand Down Expand Up @@ -595,6 +595,37 @@ async def async_check_service(
i += 1
next_time += _CHECK_TIME

def add_listener(
self,
listener: RecordUpdateListener,
Expand Down
3 changes: 3 additions & 0 deletions src/zeroconf/_handlers/record_manager.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cdef class RecordManager:
cdef public object zc
cdef public DNSCache cache
cdef public cython.set listeners

cpdef void async_updates(self, object now, list records)

Expand All @@ -38,5 +39,7 @@ cdef class RecordManager:

cpdef void async_remove_listener(self, RecordUpdateListener listener)

@cython.locals(question=DNSQuestion, record=DNSRecord)
cdef void _async_update_matching_records(self, RecordUpdateListener listener, cython.list questions)
15 changes: 14 additions & 1 deletion src/zeroconf/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from types import TracebackType # used in type hints

from ._core import Zeroconf
from ._dns import DNSQuestionType
from ._exceptions import NotRunningException
from ._services import ServiceListener
from ._services.browser import _ServiceBrowserBase
Expand Down Expand Up @@ -224,6 +224,19 @@ async def async_update_service(self, info: ServiceInfo) -> Awaitable:
"""
return await self.zeroconf.async_update_service(info)

async def async_close(self) -> None:
"""Ends the background threads, and prevent this instance from
servicing further queries."""
Expand Down
8 changes: 8 additions & 0 deletions src/zeroconf/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
# level of rate limit and safe guards so we use 1/4 of the recommended value
_DNS_PTR_MIN_TTL = 1125

# Upper bound on the number of records the DNSCache will hold before it
# starts evicting the closest-to-expiration entry to make room for new
# arrivals. Bounds the memory a malicious LAN peer can force the cache
Expand Down
19 changes: 18 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest_asyncio

from zeroconf import Zeroconf, _core, const
from zeroconf._handlers import query_handler
from zeroconf._services import browser as service_browser
from zeroconf._services import info as service_info
from zeroconf.asyncio import AsyncZeroconf
Expand Down Expand Up @@ -188,6 +188,23 @@ def quick_aggregation_timing() -> Generator[None]:
yield


@pytest.fixture
def quick_request_timing() -> Generator[None]:
"""Shorten the initial-query delay used by AsyncServiceInfo.async_request.
Expand Down
Loading
Loading
Toggle all file notes Toggle all file annotations