File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,13 @@ def _request_address(self, level: int) -> bool:
183183 if not contacts :
184184 return False
185185
186+ def _get_level (address : int ) -> int :
187+ count = 0
188+ while address :
189+ address >>= 3
190+ count += 1
191+ return count
192+
186193 new_addr = None
187194 for contact in contacts :
188195 # print("Requesting address from", oct(contact))
@@ -199,8 +206,7 @@ def _request_address(self, level: int) -> bool:
199206 and self .frame_buf .header .reserved == self .node_id
200207 ):
201208 new_addr = struct .unpack ("<H" , self .frame_buf .message [:2 ])[0 ]
202- level = 0 if contact < 7 else len (oct (contact )[2 :])
203- test_addr = new_addr & ~ (0xFFFF << (level * 3 ))
209+ test_addr = new_addr & ~ (0xFFFF << (_get_level (contact ) * 3 ))
204210 if test_addr != contact :
205211 new_addr = None
206212 else :
You can’t perform that action at this time.
0 commit comments