|
39 | 39 | cast, |
40 | 40 | ) |
41 | 41 |
|
42 | | -from .._dns import DNSPointer, DNSQuestion, DNSQuestionType, DNSRecord |
| 42 | +from .._dns import DNSPointer, DNSQuestion, DNSQuestionType |
43 | 43 | from .._logger import log |
44 | 44 | from .._protocol.outgoing import DNSOutgoing |
45 | 45 | from .._services import ( |
@@ -383,50 +383,46 @@ def _enqueue_callback( |
383 | 383 | ): |
384 | 384 | self._pending_handlers[key] = state_change |
385 | 385 |
|
386 | | - def _async_process_record_update( |
387 | | - self, now: float, record: DNSRecord, old_record: Optional[DNSRecord] |
388 | | - ) -> None: |
389 | | - """Process a single record update from a batch of updates.""" |
390 | | - record_type = record.type |
391 | | - |
392 | | - if record_type is _TYPE_PTR: |
393 | | - if TYPE_CHECKING: |
394 | | - record = cast(DNSPointer, record) |
395 | | - for type_ in self.types.intersection(cached_possible_types(record.name)): |
396 | | - if old_record is None: |
397 | | - self._enqueue_callback(ServiceStateChange.Added, type_, record.alias) |
398 | | - elif record.is_expired(now): |
399 | | - self._enqueue_callback(ServiceStateChange.Removed, type_, record.alias) |
400 | | - else: |
401 | | - self.reschedule_type(type_, now, record.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT)) |
402 | | - return |
403 | | - |
404 | | - # If its expired or already exists in the cache it cannot be updated. |
405 | | - if old_record or record.is_expired(now): |
406 | | - return |
407 | | - |
408 | | - if record_type in _ADDRESS_RECORD_TYPES: |
409 | | - # Iterate through the DNSCache and callback any services that use this address |
410 | | - for type_, name in self._names_matching_types( |
411 | | - {service.name for service in self.zc.cache.async_entries_with_server(record.name)} |
412 | | - ): |
413 | | - self._enqueue_callback(ServiceStateChange.Updated, type_, name) |
414 | | - return |
415 | | - |
416 | | - for type_, name in self._names_matching_types((record.name,)): |
417 | | - self._enqueue_callback(ServiceStateChange.Updated, type_, name) |
418 | | - |
419 | 386 | def async_update_records(self, zc: 'Zeroconf', now: float, records: List[RecordUpdate]) -> None: |
420 | 387 | """Callback invoked by Zeroconf when new information arrives. |
421 | 388 |
|
422 | 389 | Updates information required by browser in the Zeroconf cache. |
423 | 390 |
|
424 | | - Ensures that there is are no unecessary duplicates in the list. |
| 391 | + Ensures that there is are no unnecessary duplicates in the list. |
425 | 392 |
|
426 | 393 | This method will be run in the event loop. |
427 | 394 | """ |
428 | | - for record in records: |
429 | | - self._async_process_record_update(now, record[0], record[1]) |
| 395 | + for record_update in records: |
| 396 | + record, old_record = record_update |
| 397 | + record_type = record.type |
| 398 | + |
| 399 | + if record_type is _TYPE_PTR: |
| 400 | + if TYPE_CHECKING: |
| 401 | + record = cast(DNSPointer, record) |
| 402 | + for type_ in self.types.intersection(cached_possible_types(record.name)): |
| 403 | + if old_record is None: |
| 404 | + self._enqueue_callback(ServiceStateChange.Added, type_, record.alias) |
| 405 | + elif record.is_expired(now): |
| 406 | + self._enqueue_callback(ServiceStateChange.Removed, type_, record.alias) |
| 407 | + else: |
| 408 | + expire_time = record.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT) |
| 409 | + self.reschedule_type(type_, now, expire_time) |
| 410 | + continue |
| 411 | + |
| 412 | + # If its expired or already exists in the cache it cannot be updated. |
| 413 | + if old_record or record.is_expired(now): |
| 414 | + continue |
| 415 | + |
| 416 | + if record_type in _ADDRESS_RECORD_TYPES: |
| 417 | + # Iterate through the DNSCache and callback any services that use this address |
| 418 | + for type_, name in self._names_matching_types( |
| 419 | + {service.name for service in self.zc.cache.async_entries_with_server(record.name)} |
| 420 | + ): |
| 421 | + self._enqueue_callback(ServiceStateChange.Updated, type_, name) |
| 422 | + continue |
| 423 | + |
| 424 | + for type_, name in self._names_matching_types((record.name,)): |
| 425 | + self._enqueue_callback(ServiceStateChange.Updated, type_, name) |
430 | 426 |
|
431 | 427 | @abstractmethod |
432 | 428 | def async_update_records_complete(self) -> None: |
|
0 commit comments