Skip to content

Commit efc4315

Browse files
authored
Merge branch 'master' into cython_31
2 parents 0ae5dc1 + 5a72fd4 commit efc4315

File tree

10 files changed

+39
-41
lines changed

10 files changed

+39
-41
lines changed

src/zeroconf/_cache.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ cdef class DNSCache:
8383
self,
8484
DNSRecord record,
8585
double now,
86-
cython.float ttl
86+
unsigned int ttl
8787
)

src/zeroconf/_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def async_mark_unique_records_older_than_1s_to_expire(
317317
# Expire in 1s
318318
self._async_set_created_ttl(record, now, 1)
319319

320-
def _async_set_created_ttl(self, record: DNSRecord, now: _float, ttl: _float) -> None:
320+
def _async_set_created_ttl(self, record: DNSRecord, now: _float, ttl: _int) -> None:
321321
"""Set the created time and ttl of a record."""
322322
# It would be better if we made a copy instead of mutating the record
323323
# in place, but records currently don't have a copy method.

src/zeroconf/_dns.pxd

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ cdef class DNSQuestion(DNSEntry):
4444

4545
cdef class DNSRecord(DNSEntry):
4646

47-
cdef public cython.float ttl
47+
cdef public unsigned int ttl
4848
cdef public double created
4949

50-
cdef _fast_init_record(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, double created)
50+
cdef _fast_init_record(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, double created)
5151

5252
cdef bint _suppressed_by_answer(self, DNSRecord answer)
5353

@@ -66,15 +66,15 @@ cdef class DNSRecord(DNSEntry):
6666

6767
cpdef bint is_recent(self, double now)
6868

69-
cdef _set_created_ttl(self, double now, cython.float ttl)
69+
cdef _set_created_ttl(self, double now, unsigned int ttl)
7070

7171
cdef class DNSAddress(DNSRecord):
7272

7373
cdef public cython.int _hash
7474
cdef public bytes address
7575
cdef public object scope_id
7676

77-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, bytes address, object scope_id, double created)
77+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, bytes address, object scope_id, double created)
7878

7979
cdef bint _eq(self, DNSAddress other)
8080

@@ -87,7 +87,7 @@ cdef class DNSHinfo(DNSRecord):
8787
cdef public str cpu
8888
cdef public str os
8989

90-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, str cpu, str os, double created)
90+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, str cpu, str os, double created)
9191

9292
cdef bint _eq(self, DNSHinfo other)
9393

@@ -99,7 +99,7 @@ cdef class DNSPointer(DNSRecord):
9999
cdef public str alias
100100
cdef public str alias_key
101101

102-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, str alias, double created)
102+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, str alias, double created)
103103

104104
cdef bint _eq(self, DNSPointer other)
105105

@@ -110,7 +110,7 @@ cdef class DNSText(DNSRecord):
110110
cdef public cython.int _hash
111111
cdef public bytes text
112112

113-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, bytes text, double created)
113+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, bytes text, double created)
114114

115115
cdef bint _eq(self, DNSText other)
116116

@@ -125,7 +125,7 @@ cdef class DNSService(DNSRecord):
125125
cdef public str server
126126
cdef public str server_key
127127

128-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, cython.uint priority, cython.uint weight, cython.uint port, str server, double created)
128+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, cython.uint priority, cython.uint weight, cython.uint port, str server, double created)
129129

130130
cdef bint _eq(self, DNSService other)
131131

@@ -137,7 +137,7 @@ cdef class DNSNsec(DNSRecord):
137137
cdef public str next_name
138138
cdef public cython.list rdtypes
139139

140-
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, cython.float ttl, str next_name, cython.list rdtypes, double created)
140+
cdef _fast_init(self, str name, cython.uint type_, cython.uint class_, unsigned int ttl, str next_name, cython.list rdtypes, double created)
141141

142142
cdef bint _eq(self, DNSNsec other)
143143

src/zeroconf/_dns.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,17 @@ class DNSRecord(DNSEntry):
166166

167167
__slots__ = ("created", "ttl")
168168

169-
# TODO: Switch to just int ttl
170169
def __init__(
171170
self,
172171
name: str,
173172
type_: int,
174173
class_: int,
175-
ttl: float | int,
174+
ttl: _int,
176175
created: float | None = None,
177176
) -> None:
178177
self._fast_init_record(name, type_, class_, ttl, created or current_time_millis())
179178

180-
def _fast_init_record(self, name: str, type_: _int, class_: _int, ttl: _float, created: _float) -> None:
179+
def _fast_init_record(self, name: str, type_: _int, class_: _int, ttl: _int, created: _float) -> None:
181180
"""Fast init for reuse."""
182181
self._fast_init_entry(name, type_, class_)
183182
self.ttl = ttl
@@ -227,7 +226,7 @@ def is_recent(self, now: _float) -> bool:
227226
"""Returns true if the record more than one quarter of its TTL remaining."""
228227
return self.created + (_RECENT_TIME_MS * self.ttl) > now
229228

230-
def _set_created_ttl(self, created: _float, ttl: float | int) -> None:
229+
def _set_created_ttl(self, created: _float, ttl: _int) -> None:
231230
"""Set the created and ttl of a record."""
232231
# It would be better if we made a copy instead of mutating the record
233232
# in place, but records currently don't have a copy method.
@@ -266,7 +265,7 @@ def _fast_init(
266265
name: str,
267266
type_: _int,
268267
class_: _int,
269-
ttl: _float,
268+
ttl: _int,
270269
address: bytes,
271270
scope_id: _int | None,
272271
created: _float,
@@ -327,7 +326,7 @@ def __init__(
327326
self._fast_init(name, type_, class_, ttl, cpu, os, created or current_time_millis())
328327

329328
def _fast_init(
330-
self, name: str, type_: _int, class_: _int, ttl: _float, cpu: str, os: str, created: _float
329+
self, name: str, type_: _int, class_: _int, ttl: _int, cpu: str, os: str, created: _float
331330
) -> None:
332331
"""Fast init for reuse."""
333332
self._fast_init_record(name, type_, class_, ttl, created)
@@ -374,7 +373,7 @@ def __init__(
374373
self._fast_init(name, type_, class_, ttl, alias, created or current_time_millis())
375374

376375
def _fast_init(
377-
self, name: str, type_: _int, class_: _int, ttl: _float, alias: str, created: _float
376+
self, name: str, type_: _int, class_: _int, ttl: _int, alias: str, created: _float
378377
) -> None:
379378
self._fast_init_record(name, type_, class_, ttl, created)
380379
self.alias = alias
@@ -429,7 +428,7 @@ def __init__(
429428
self._fast_init(name, type_, class_, ttl, text, created or current_time_millis())
430429

431430
def _fast_init(
432-
self, name: str, type_: _int, class_: _int, ttl: _float, text: bytes, created: _float
431+
self, name: str, type_: _int, class_: _int, ttl: _int, text: bytes, created: _float
433432
) -> None:
434433
self._fast_init_record(name, type_, class_, ttl, created)
435434
self.text = text
@@ -468,7 +467,7 @@ def __init__(
468467
name: str,
469468
type_: int,
470469
class_: int,
471-
ttl: float | int,
470+
ttl: int,
472471
priority: int,
473472
weight: int,
474473
port: int,
@@ -484,7 +483,7 @@ def _fast_init(
484483
name: str,
485484
type_: _int,
486485
class_: _int,
487-
ttl: _float,
486+
ttl: _int,
488487
priority: _int,
489488
weight: _int,
490489
port: _int,
@@ -539,7 +538,7 @@ def __init__(
539538
name: str,
540539
type_: int,
541540
class_: int,
542-
ttl: int | float,
541+
ttl: _int,
543542
next_name: str,
544543
rdtypes: list[int],
545544
created: float | None = None,
@@ -551,7 +550,7 @@ def _fast_init(
551550
name: str,
552551
type_: _int,
553552
class_: _int,
554-
ttl: _float,
553+
ttl: _int,
555554
next_name: str,
556555
rdtypes: list[_int],
557556
created: _float,

src/zeroconf/_handlers/record_manager.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from .._updates cimport RecordUpdateListener
88
from .._utils.time cimport current_time_millis
99
from .._record_update cimport RecordUpdate
1010

11-
cdef cython.float _DNS_PTR_MIN_TTL
11+
cdef unsigned int _DNS_PTR_MIN_TTL
1212
cdef cython.uint _TYPE_PTR
1313
cdef object _ADDRESS_RECORD_TYPES
1414
cdef bint TYPE_CHECKING

src/zeroconf/_listener.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cdef class AsyncListener:
5050

5151
cpdef _respond_query(
5252
self,
53-
object msg,
53+
DNSIncoming msg,
5454
object addr,
5555
object port,
5656
object transport,

src/zeroconf/_services/browser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,8 @@ def _schedule_ptr_refresh(
394394
refresh_time_millis: float_,
395395
) -> None:
396396
"""Schedule a query for a pointer."""
397-
ttl = int(pointer.ttl) if isinstance(pointer.ttl, float) else pointer.ttl
398397
scheduled_ptr_query = _ScheduledPTRQuery(
399-
pointer.alias, pointer.name, ttl, expire_time_millis, refresh_time_millis
398+
pointer.alias, pointer.name, pointer.ttl, expire_time_millis, refresh_time_millis
400399
)
401400
self._schedule_ptr_query(scheduled_ptr_query)
402401

src/zeroconf/_services/info.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@ def _process_record_threadsafe(self, zc: Zeroconf, record: DNSRecord, now: float
577577

578578
def dns_addresses(
579579
self,
580-
override_ttl: int | None = None,
580+
override_ttl: int_ | None = None,
581581
version: IPVersion = IPVersion.All,
582582
) -> list[DNSAddress]:
583583
"""Return matching DNSAddress from ServiceInfo."""
584584
return self._dns_addresses(override_ttl, version)
585585

586586
def _dns_addresses(
587587
self,
588-
override_ttl: int | None,
588+
override_ttl: int_ | None,
589589
version: IPVersion,
590590
) -> list[DNSAddress]:
591591
"""Return matching DNSAddress from ServiceInfo."""
@@ -611,11 +611,11 @@ def _dns_addresses(
611611
self._dns_address_cache = records
612612
return records
613613

614-
def dns_pointer(self, override_ttl: int | None = None) -> DNSPointer:
614+
def dns_pointer(self, override_ttl: int_ | None = None) -> DNSPointer:
615615
"""Return DNSPointer from ServiceInfo."""
616616
return self._dns_pointer(override_ttl)
617617

618-
def _dns_pointer(self, override_ttl: int | None) -> DNSPointer:
618+
def _dns_pointer(self, override_ttl: int_ | None) -> DNSPointer:
619619
"""Return DNSPointer from ServiceInfo."""
620620
cacheable = override_ttl is None
621621
if self._dns_pointer_cache is not None and cacheable:
@@ -632,11 +632,11 @@ def _dns_pointer(self, override_ttl: int | None) -> DNSPointer:
632632
self._dns_pointer_cache = record
633633
return record
634634

635-
def dns_service(self, override_ttl: int | None = None) -> DNSService:
635+
def dns_service(self, override_ttl: int_ | None = None) -> DNSService:
636636
"""Return DNSService from ServiceInfo."""
637637
return self._dns_service(override_ttl)
638638

639-
def _dns_service(self, override_ttl: int | None) -> DNSService:
639+
def _dns_service(self, override_ttl: int_ | None) -> DNSService:
640640
"""Return DNSService from ServiceInfo."""
641641
cacheable = override_ttl is None
642642
if self._dns_service_cache is not None and cacheable:
@@ -659,11 +659,11 @@ def _dns_service(self, override_ttl: int | None) -> DNSService:
659659
self._dns_service_cache = record
660660
return record
661661

662-
def dns_text(self, override_ttl: int | None = None) -> DNSText:
662+
def dns_text(self, override_ttl: int_ | None = None) -> DNSText:
663663
"""Return DNSText from ServiceInfo."""
664664
return self._dns_text(override_ttl)
665665

666-
def _dns_text(self, override_ttl: int | None) -> DNSText:
666+
def _dns_text(self, override_ttl: int_ | None) -> DNSText:
667667
"""Return DNSText from ServiceInfo."""
668668
cacheable = override_ttl is None
669669
if self._dns_text_cache is not None and cacheable:
@@ -680,11 +680,11 @@ def _dns_text(self, override_ttl: int | None) -> DNSText:
680680
self._dns_text_cache = record
681681
return record
682682

683-
def dns_nsec(self, missing_types: list[int], override_ttl: int | None = None) -> DNSNsec:
683+
def dns_nsec(self, missing_types: list[int], override_ttl: int_ | None = None) -> DNSNsec:
684684
"""Return DNSNsec from ServiceInfo."""
685685
return self._dns_nsec(missing_types, override_ttl)
686686

687-
def _dns_nsec(self, missing_types: list[int], override_ttl: int | None) -> DNSNsec:
687+
def _dns_nsec(self, missing_types: list[int], override_ttl: int_ | None) -> DNSNsec:
688688
"""Return DNSNsec from ServiceInfo."""
689689
return DNSNsec(
690690
self._name,
@@ -696,11 +696,11 @@ def _dns_nsec(self, missing_types: list[int], override_ttl: int | None) -> DNSNs
696696
0.0,
697697
)
698698

699-
def get_address_and_nsec_records(self, override_ttl: int | None = None) -> set[DNSRecord]:
699+
def get_address_and_nsec_records(self, override_ttl: int_ | None = None) -> set[DNSRecord]:
700700
"""Build a set of address records and NSEC records for non-present record types."""
701701
return self._get_address_and_nsec_records(override_ttl)
702702

703-
def _get_address_and_nsec_records(self, override_ttl: int | None) -> set[DNSRecord]:
703+
def _get_address_and_nsec_records(self, override_ttl: int_ | None) -> set[DNSRecord]:
704704
"""Build a set of address records and NSEC records for non-present record types."""
705705
cacheable = override_ttl is None
706706
if self._get_address_and_nsec_records_cache is not None and cacheable:

src/zeroconf/const.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
# ServiceBrowsers generating excessive queries refresh queries.
5858
# Apple uses a 15s minimum TTL, however we do not have the same
5959
# level of rate limit and safe guards so we use 1/4 of the recommended value
60-
_DNS_PTR_MIN_TTL = _DNS_OTHER_TTL / 4
60+
_DNS_PTR_MIN_TTL = 1125
6161

6262
_DNS_PACKET_HEADER_LEN = 12
6363

tests/test_protocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_suppress_answer(self):
196196
"testname2.local.",
197197
const._TYPE_SRV,
198198
const._CLASS_IN | const._CLASS_UNIQUE,
199-
const._DNS_HOST_TTL / 2,
199+
int(const._DNS_HOST_TTL / 2),
200200
0,
201201
0,
202202
80,

0 commit comments

Comments
 (0)