Skip to content

Commit ecea4e4

Browse files
authored
fix: timestamps missing double precision (#1324)
1 parent a0dac46 commit ecea4e4

14 files changed

Lines changed: 37 additions & 37 deletions

File tree

src/zeroconf/_cache.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cdef class DNSCache:
3636
@cython.locals(
3737
record=DNSRecord,
3838
)
39-
cpdef async_expire(self, float now)
39+
cpdef async_expire(self, double now)
4040

4141
@cython.locals(
4242
records=cython.dict,
@@ -68,6 +68,6 @@ cdef class DNSCache:
6868

6969
@cython.locals(
7070
record=DNSRecord,
71-
created_float=cython.float,
71+
created_double=double,
7272
)
73-
cpdef async_mark_unique_records_older_than_1s_to_expire(self, cython.set unique_types, object answers, float now)
73+
cpdef async_mark_unique_records_older_than_1s_to_expire(self, cython.set unique_types, object answers, double now)

src/zeroconf/_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def async_mark_unique_records_older_than_1s_to_expire(
243243
answers_rrset = set(answers)
244244
for name, type_, class_ in unique_types:
245245
for record in self.async_all_by_details(name, type_, class_):
246-
created_float = record.created
247-
if (now - created_float > _ONE_SECOND) and record not in answers_rrset:
246+
created_double = record.created
247+
if (now - created_double > _ONE_SECOND) and record not in answers_rrset:
248248
# Expire in 1s
249249
record.set_created_ttl(now, 1)

src/zeroconf/_dns.pxd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ cdef class DNSQuestion(DNSEntry):
4343
cdef class DNSRecord(DNSEntry):
4444

4545
cdef public cython.float ttl
46-
cdef public cython.float created
46+
cdef public double created
4747

4848
cdef bint _suppressed_by_answer(self, DNSRecord answer)
4949

@@ -52,19 +52,19 @@ cdef class DNSRecord(DNSEntry):
5252
)
5353
cpdef bint suppressed_by(self, object msg)
5454

55-
cpdef get_remaining_ttl(self, cython.float now)
55+
cpdef get_remaining_ttl(self, double now)
5656

57-
cpdef get_expiration_time(self, cython.uint percent)
57+
cpdef double get_expiration_time(self, cython.uint percent)
5858

59-
cpdef bint is_expired(self, cython.float now)
59+
cpdef bint is_expired(self, double now)
6060

61-
cpdef bint is_stale(self, cython.float now)
61+
cpdef bint is_stale(self, double now)
6262

63-
cpdef bint is_recent(self, cython.float now)
63+
cpdef bint is_recent(self, double now)
6464

6565
cpdef reset_ttl(self, DNSRecord other)
6666

67-
cpdef set_created_ttl(self, cython.float now, cython.float ttl)
67+
cpdef set_created_ttl(self, double now, cython.float ttl)
6868

6969
cdef class DNSAddress(DNSRecord):
7070

src/zeroconf/_handlers/answers.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ cdef class QuestionAnswers:
1515

1616
cdef class AnswerGroup:
1717

18-
cdef public float send_after
19-
cdef public float send_before
18+
cdef public double send_after
19+
cdef public double send_before
2020
cdef public cython.dict answers
2121

2222

src/zeroconf/_handlers/multicast_outgoing_queue.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cdef class MulticastOutgoingQueue:
1919
cdef object _aggregation_delay
2020

2121
@cython.locals(last_group=AnswerGroup, random_int=cython.uint)
22-
cpdef async_add(self, float now, cython.dict answers)
22+
cpdef async_add(self, double now, cython.dict answers)
2323

2424
@cython.locals(pending=AnswerGroup)
2525
cdef _remove_answers_from_queue(self, cython.dict answers)

src/zeroconf/_handlers/record_manager.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cdef class RecordManager:
3131
record=DNSRecord,
3232
answers=cython.list,
3333
maybe_entry=DNSRecord,
34-
now_float=cython.float
34+
now_double=double
3535
)
3636
cpdef async_updates_from_response(self, DNSIncoming msg)
3737

src/zeroconf/_handlers/record_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
8484
other_adds: List[DNSRecord] = []
8585
removes: Set[DNSRecord] = set()
8686
now = msg.now
87-
now_float = now
87+
now_double = now
8888
unique_types: Set[Tuple[str, int, int]] = set()
8989
cache = self.cache
9090
answers = msg.answers()
@@ -113,7 +113,7 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
113113
record = cast(_UniqueRecordsType, record)
114114

115115
maybe_entry = cache.async_get_unique(record)
116-
if not record.is_expired(now_float):
116+
if not record.is_expired(now_double):
117117
if maybe_entry is not None:
118118
maybe_entry.reset_ttl(record)
119119
else:
@@ -129,7 +129,7 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
129129
removes.add(record)
130130

131131
if unique_types:
132-
cache.async_mark_unique_records_older_than_1s_to_expire(unique_types, answers, now_float)
132+
cache.async_mark_unique_records_older_than_1s_to_expire(unique_types, answers, now_double)
133133

134134
if updates:
135135
self.async_updates(now, updates)

src/zeroconf/_listener.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ cdef class AsyncListener:
2222
cdef ServiceRegistry _registry
2323
cdef RecordManager _record_manager
2424
cdef public cython.bytes data
25-
cdef public cython.float last_time
25+
cdef public double last_time
2626
cdef public DNSIncoming last_message
2727
cdef public object transport
2828
cdef public object sock_description
2929
cdef public cython.dict _deferred
3030
cdef public cython.dict _timers
3131

32-
@cython.locals(now=cython.float, debug=cython.bint)
32+
@cython.locals(now=double, debug=cython.bint)
3333
cpdef datagram_received(self, cython.bytes bytes, cython.tuple addrs)
3434

3535
@cython.locals(msg=DNSIncoming)
36-
cpdef _process_datagram_at_time(self, bint debug, cython.uint data_len, cython.float now, bytes data, cython.tuple addrs)
36+
cpdef _process_datagram_at_time(self, bint debug, cython.uint data_len, double now, bytes data, cython.tuple addrs)
3737

3838
cdef _cancel_any_timers_for_addr(self, object addr)
3939

src/zeroconf/_protocol/outgoing.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cdef class DNSOutgoing:
7171
index=cython.uint,
7272
length=cython.uint
7373
)
74-
cdef cython.bint _write_record(self, DNSRecord record, float now)
74+
cdef cython.bint _write_record(self, DNSRecord record, double now)
7575

7676
@cython.locals(class_=cython.uint)
7777
cdef _write_record_class(self, DNSEntry record)
@@ -92,7 +92,7 @@ cdef class DNSOutgoing:
9292

9393
cdef bint _has_more_to_add(self, unsigned int questions_offset, unsigned int answer_offset, unsigned int authority_offset, unsigned int additional_offset)
9494

95-
cdef _write_ttl(self, DNSRecord record, float now)
95+
cdef _write_ttl(self, DNSRecord record, double now)
9696

9797
@cython.locals(
9898
labels=cython.list,
@@ -135,7 +135,7 @@ cdef class DNSOutgoing:
135135

136136
cpdef add_answer(self, DNSIncoming inp, DNSRecord record)
137137

138-
@cython.locals(now_float=cython.float)
138+
@cython.locals(now_double=double)
139139
cpdef add_answer_at_time(self, DNSRecord record, object now)
140140

141141
cpdef add_authorative_answer(self, DNSPointer record)

src/zeroconf/_protocol/outgoing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def add_answer(self, inp: DNSIncoming, record: DNSRecord) -> None:
152152

153153
def add_answer_at_time(self, record: Optional[DNSRecord], now: Union[float, int]) -> None:
154154
"""Adds an answer if it does not expire by a certain time"""
155-
now_float = now
156-
if record is not None and (now_float == 0 or not record.is_expired(now_float)):
155+
now_double = now
156+
if record is not None and (now_double == 0 or not record.is_expired(now_double)):
157157
self.answers.append((record, now))
158158

159159
def add_authorative_answer(self, record: DNSPointer) -> None:

0 commit comments

Comments
 (0)