FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: speed up incoming packet parsing (#1830) · python-zeroconf/python-zeroconf@b3634f2 · GitHub

Commit b3634f2

Browse files
authored
feat: speed up incoming packet parsing (#1830)
1 parent e63bf6f commit b3634f2

4 files changed

Lines changed: 416 additions & 57 deletions

File tree

‎src/zeroconf/_protocol/incoming.pxd‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cdef cython.uint DNS_COMPRESSION_HEADER_LEN
66
cdef cython.uint MAX_DNS_LABELS
77
cdef cython.uint DNS_COMPRESSION_POINTER_LEN
88
cdef cython.uint MAX_NAME_LENGTH
9+
cdef cython.uint MAX_MSG_LEN
910

1011
cdef cython.uint _TYPE_A
1112
cdef cython.uint _TYPE_CNAME
@@ -16,7 +17,6 @@ cdef cython.uint _TYPE_HINFO
1617
cdef cython.uint _TYPE_AAAA
1718
cdef cython.uint _TYPE_NSEC
1819
cdef cython.uint _FLAGS_QR_MASK
19-
cdef cython.uint _FLAGS_QR_MASK
2020
cdef cython.uint _FLAGS_TC
2121
cdef cython.uint _FLAGS_QR_QUERY
2222
cdef cython.uint _FLAGS_QR_RESPONSE
@@ -44,10 +44,11 @@ cdef class DNSIncoming:
4444
cdef bint _did_read_others
4545
cdef public unsigned int flags
4646
cdef cython.uint offset
47-
cdef public bytes data
48-
cdef const unsigned char [:] view
47+
cdef readonly bytes data
48+
cdef const unsigned char* _buf
4949
cdef unsigned int _data_len
5050
cdef cython.dict _name_cache
51+
cdef cython.dict _name_str_cache
5152
cdef cython.list _questions
5253
cdef cython.list _answers
5354
cdef public cython.uint id
@@ -81,30 +82,39 @@ cdef class DNSIncoming:
8182
link="unsigned int",
8283
link_data="unsigned int",
8384
link_py_int=object,
84-
linked_labels=cython.list
85+
linked_labels=cython.list,
86+
buf="const unsigned char *",
8587
)
8688
cdef unsigned int _decode_labels_at_offset(self, unsigned int off, cython.list labels, cython.set seen_pointers, unsigned int depth)
8789

88-
@cython.locals(offset="unsigned int")
90+
@cython.locals(offset="unsigned int", buf="const unsigned char *")
8991
cdef void _read_header(self)
9092

9193
cdef void _initial_parse(self)
9294

9395
@cython.locals(
9496
end="unsigned int",
9597
length="unsigned int",
96-
offset="unsigned int"
98+
offset="unsigned int",
99+
answers=cython.list,
100+
buf="const unsigned char *",
97101
)
98102
cdef void _read_others(self)
99103

100-
@cython.locals(offset="unsigned int", question=DNSQuestion)
104+
@cython.locals(offset="unsigned int", question=DNSQuestion, buf="const unsigned char *")
101105
cdef _read_questions(self)
102106

103107
@cython.locals(
104108
length="unsigned int",
109+
start="unsigned int",
110+
end="unsigned int",
105111
)
106112
cdef str _read_character_string(self)
107113

114+
@cython.locals(
115+
start="unsigned int",
116+
end="unsigned int",
117+
)
108118
cdef bytes _read_string(self, unsigned int length)
109119

110120
@cython.locals(
@@ -116,20 +126,32 @@ cdef class DNSIncoming:
116126
srv_rec=DNSService,
117127
hinfo_rec=DNSHinfo,
118128
nsec_rec=DNSNsec,
129+
buf="const unsigned char *",
119130
)
120131
cdef _read_record(self, str domain, unsigned int type_, unsigned int class_, unsigned int ttl, unsigned int length)
121132

122133
@cython.locals(
123134
offset="unsigned int",
124135
offset_plus_one="unsigned int",
125136
offset_plus_two="unsigned int",
126-
window="unsigned int",
127137
bit="unsigned int",
128138
byte="unsigned int",
129139
i="unsigned int",
130140
bitmap_length="unsigned int",
131141
bitmap_end="unsigned int",
142+
window_base="unsigned int",
143+
bit_base="unsigned int",
144+
buf="const unsigned char *",
132145
)
133146
cdef list _read_bitmap(self, unsigned int end)
134147

148+
@cython.locals(
149+
original_offset="unsigned int",
150+
length="unsigned int",
151+
link="unsigned int",
152+
is_pure_pointer=cython.bint,
153+
name=str,
154+
cached_name=str,
155+
name_str_cache=cython.dict,
156+
)
135157
cdef str _read_name(self)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL