Ë
    R/j  ã                  óP   — d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 e
Z G d„ d«      Zy)	a‡  Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
é    )Úannotationsé   )ÚDNSQuestionÚ	DNSRecord)Ú_DUPLICATE_QUESTION_INTERVALÚ$_MAX_KNOWN_ANSWERS_PER_HISTORY_ENTRYÚ_MAX_QUESTION_HISTORY_ENTRIESc                  ó@   — e Zd ZdZd	d„Zd
d„Zdd„Zdd„Zd	d„Zdd„Z	y)ÚQuestionHistoryz%Remember questions and known answers.c                ó   — i | _         y)zInit a new QuestionHistory.N)Ú_history©Úselfs    úC/home/josh/.local/lib/python3.12/site-packages/zeroconf/_history.pyÚ__init__zQuestionHistory.__init__)   s	   € àIKˆ�ó    c                óÂ   — t        |«      t        kD  ry|| j                  vr-t        | j                  «      t        k\  r| j	                  |«       ||f| j                  |<   y)z'Remember a question with known answers.N)Úlenr   r   r	   Ú_evict_to_make_room)r   ÚquestionÚnowÚknown_answerss       r   Úadd_question_at_timez$QuestionHistory.add_question_at_time-   sS   € äˆ}ÓÔ DÒDð Ø˜4Ÿ=™=Ñ(¬S°·±Ó-?ÔC`Ò-`Ø×$Ñ$ SÔ)Ø#&¨Ð"6ˆ�‰�hÒr   c                ón   — | j                   j                  |«      }|sy|\  }}||z
  t        kD  ry||z
   S )a/  Check to see if a question should be suppressed.

        https://datatracker.ietf.org/doc/html/rfc6762#section-7.3
        When multiple queriers on the network are querying
        for the same resource records, there is no need for them to all be
        repeatedly asking the same question.
        F)r   Úgetr   )r   r   r   r   Úprevious_questionÚthanÚprevious_known_answerss          r   Ú
suppresseszQuestionHistory.suppresses<   sJ   € ð !ŸM™M×-Ñ-¨hÓ7Ðá ØØ'8Ñ$ˆÐ$à�‰:Ô4Ò4Øð *¨MÑ9Ð9Ð9r   c                óº   — g }| j                   j                  «       D ](  \  }}|\  }}||z
  t        kD  sŒ|j                  |«       Œ* |D ]  }| j                   |= Œ y)z$Expire the history of old questions.N)r   Úitemsr   Úappend)r   r   Úremovesr   Únow_known_answersr   Ú_s          r   Úasync_expirezQuestionHistory.async_expireP   sh   € à%'ˆØ+/¯=©=×+>Ñ+>Ó+@ò 	)Ñ'ˆHÐ'Ø'‰GˆD�!Ø�T‰zÔ8Ó8Ø—‘˜xÕ(ð	)ð  ò 	(ˆHØ—‘˜hÑ'ñ	(r   c                ó8   — | j                   j                  «        y)zClear the history.N)r   Úclearr   s    r   r(   zQuestionHistory.clearZ   s   € à�‰×ÑÕr   c                óh  — t        t        | j                  «      «      }| j                  |   }|d   }||z
  t        kD  r| j	                  |«       t        | j                  «      t        k\  rG| j                  t        t        | j                  «      «      = t        | j                  «      t        k\  rŒFyy)uT  Drop expired or oldest entries when the history is at cap.

        Peeks at the oldest insertion (dict is ordered) â€” only runs the
        full O(n) async_expire sweep if it could actually reclaim
        something, else a sustained flood at cap turns each insert into
        a wasted scan. Falls back to oldest-first eviction.
        r   N)ÚnextÚiterr   r   r&   r   r	   )r   r   ÚoldestÚoldest_entryÚoldest_thans        r   r   z#QuestionHistory._evict_to_make_room^   sŠ   € ô ”d˜4Ÿ=™=Ó)Ó*ˆØ—}‘} VÑ,ˆØ" 1‘oˆØ�ÑÔ;Ò;Ø×Ñ˜cÔ"Ü�$—-‘-Ó Ô$AÒAØ—‘œd¤4¨¯©Ó#6Ó7Ð8ô �$—-‘-Ó Ô$AÕAr   N)ÚreturnÚNone)r   r   r   Ú_floatr   úset[DNSRecord]r/   r0   )r   r   r   r1   r   r2   r/   Úbool)r   r1   r/   r0   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r(   r   © r   r   r   r   &   s$   „ Ù/óLó7ó:ó((óô9r   r   N)r7   Ú
__future__r   Ú_dnsr   r   Úconstr   r   r	   Úfloatr1   r   r8   r   r   ú<module>r=      s/   ðñõ, #ç (÷ñ ð 
€÷F9ò F9r   