| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,21 +79,17 @@ def __eq__(self, other: Any) -> bool: | |||
| 79 | 79 | """Equal when key, type and class match.""" | |
| 80 | 80 | return isinstance(other, DNSEntry) and self._dns_entry_matches(other) | |
| 81 | 81 | ||
| 82 | - @property | ||
| 83 | - def type_label(self) -> str: | ||
| 84 | - """Human readable label for the record type.""" | ||
| 85 | - return _type_label(self.type) | ||
| 86 | - | ||
| 87 | 82 | @property | |
| 88 | 83 | def class_label(self) -> str: | |
| 89 | 84 | """Human readable label for the record class.""" | |
| 90 | 85 | return _class_label(self.class_) | |
| 91 | 86 | ||
| 92 | - def _display_fields(self) -> list[tuple[str, str]]: | ||
| 93 | - fields = [("name", self.name), ("type", self.type_label), ("class", self.class_label)] | ||
| 94 | - if self.unique: | ||
| 95 | - fields.append(("", "unique")) | ||
| 96 | - return fields | ||
| 87 | + def entry_to_string(self, hdr: str, other: bytes | str | None) -> str: | ||
| 88 | + """Compatibility alias rendering through the display formatter.""" | ||
| 89 | + fields = self._display_fields() | ||
| 90 | + if other is not None: | ||
| 91 | + fields.append(("data", str(other))) | ||
| 92 | + return _format_display(hdr, fields) | ||
| 97 | 93 | ||
| 98 | 94 | @staticmethod | |
| 99 | 95 | def get_class_(class_: int) -> str: | |
@@ -105,12 +101,16 @@ def get_type(t: int) -> str: | |||
| 105 | 101 | """Compatibility alias for the type_label property.""" | |
| 106 | 102 | return _type_label(t) | |
| 107 | 103 | ||
| 108 | - def entry_to_string(self, hdr: str, other: bytes | str | None) -> str: | ||
| 109 | - """Compatibility alias rendering through the display formatter.""" | ||
| 110 | - fields = self._display_fields() | ||
| 111 | - if other is not None: | ||
| 112 | - fields.append(("data", str(other))) | ||
| 113 | - return _format_display(hdr, fields) | ||
| 104 | + @property | ||
| 105 | + def type_label(self) -> str: | ||
| 106 | + """Human readable label for the record type.""" | ||
| 107 | + return _type_label(self.type) | ||
| 108 | + | ||
| 109 | + def _display_fields(self) -> list[tuple[str, str]]: | ||
| 110 | + fields = [("name", self.name), ("type", self.type_label), ("class", self.class_label)] | ||
| 111 | + if self.unique: | ||
| 112 | + fields.append(("", "unique")) | ||
| 113 | + return fields | ||
| 114 | 114 | ||
| 115 | 115 | def _dns_entry_matches(self, other: DNSEntry) -> bool: | |
| 116 | 116 | return self.key == other.key and self.type == other.type and self.class_ == other.class_ | |
@@ -222,35 +222,35 @@ def suppressed_by(self, msg: DNSIncoming) -> bool: | |||
| 222 | 222 | return True | |
| 223 | 223 | return False | |
| 224 | 224 | ||
| 225 | + def to_string(self, other: bytes | str) -> str: | ||
| 226 | + """Compatibility alias rendering through the display formatter.""" | ||
| 227 | + return self._repr_with(("data", str(other))) | ||
| 228 | + | ||
| 225 | 229 | def write(self, out: DNSOutgoing) -> None: | |
| 226 | 230 | raise AbstractMethodException(f"{type(self).__name__} is missing write") | |
| 227 | 231 | ||
| 232 | + def _display_fields(self) -> list[tuple[str, str]]: | ||
| 233 | + remaining = int(self.get_remaining_ttl(current_time_millis())) | ||
| 234 | + return [*DNSEntry._display_fields(self), ("ttl", f"{self.ttl} ({remaining} remaining)")] | ||
| 235 | + | ||
| 228 | 236 | def _fast_init_record(self, name: str, type_: _int, class_: _int, ttl: _int, created: _float) -> None: | |
| 229 | 237 | """Fast init for reuse.""" | |
| 230 | 238 | self._fast_init_entry(name, type_, class_) | |
| 231 | 239 | self.ttl = ttl | |
| 232 | 240 | self.created = created | |
| 233 | 241 | ||
| 242 | + def _repr_with(self, *details: tuple[str, str]) -> str: | ||
| 243 | + return _format_display(type(self).__name__, [*self._display_fields(), *details]) | ||
| 244 | + | ||
| 234 | 245 | def _set_created_ttl(self, created: _float, ttl: _int) -> None: | |
| 235 | 246 | """Set the created and ttl of a record.""" | |
| 236 | 247 | # It would be better if we made a copy instead of mutating the record | |
| 237 | 248 | # in place, but records currently don't have a copy method. | |
| 238 | 249 | self.created = created | |
| 239 | 250 | self.ttl = ttl | |
| 240 | 251 | ||
| 241 | - def _display_fields(self) -> list[tuple[str, str]]: | ||
| 242 | - remaining = int(self.get_remaining_ttl(current_time_millis())) | ||
| 243 | - return [*DNSEntry._display_fields(self), ("ttl", f"{self.ttl} ({remaining} remaining)")] | ||
| 244 | - | ||
| 245 | - def _repr_with(self, *details: tuple[str, str]) -> str: | ||
| 246 | - return _format_display(type(self).__name__, [*self._display_fields(), *details]) | ||
| 247 | - | ||
| 248 | - def to_string(self, other: bytes | str) -> str: | ||
| 249 | - """Compatibility alias rendering through the display formatter.""" | ||
| 250 | - return self._repr_with(("data", str(other))) | ||
| 251 | - | ||
| 252 | 252 | def _suppressed_by_answer(self, answer: DNSRecord) -> bool: | |
| 253 | - """True when the answer matches this record with at least half its TTL left.""" | ||
| 253 | + """RFC 6762 section 7.1 known answer test: an equal record whose TTL is at least half of ours.""" | ||
| 254 | 254 | return self == answer and self.ttl / 2 < answer.ttl | |
| 255 | 255 | ||
| 256 | 256 | ||
@@ -618,17 +618,17 @@ def lookup_set(self) -> set[DNSRecord]: | |||
| 618 | 618 | """Return the lookup table as aset.""" | |
| 619 | 619 | return set(self._get_lookup()) | |
| 620 | 620 | ||
| 621 | - def _get_lookup(self) -> dict[DNSRecord, DNSRecord]: | ||
| 622 | - """Return the lookup table, building it if needed.""" | ||
| 623 | - if self._lookup is None: | ||
| 624 | - # Build the hash table so we can lookup the record ttl | ||
| 625 | - self._lookup = {record: record for record in self._records} | ||
| 626 | - return self._lookup | ||
| 627 | - | ||
| 628 | 621 | def suppresses(self, record: _DNSRecord) -> bool: | |
| 629 | 622 | """True when the set holds a match with over half the record's TTL left.""" | |
| 630 | 623 | lookup = self._get_lookup() | |
| 631 | 624 | other = lookup.get(record) | |
| 632 | 625 | if other is None: | |
| 633 | 626 | return False | |
| 634 | 627 | return other.ttl > (record.ttl / 2) | |
| 628 | + | ||
| 629 | + def _get_lookup(self) -> dict[DNSRecord, DNSRecord]: | ||
| 630 | + """Return the lookup table, building it if needed.""" | ||
| 631 | + if self._lookup is None: | ||
| 632 | + # Build the hash table so we can lookup the record ttl | ||
| 633 | + self._lookup = {record: record for record in self._records} | ||
| 634 | + return self._lookup | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -399,7 +399,7 @@ def _read_name(self) -> str: | |||
| 399 | 399 | return name | |
| 400 | 400 | ||
| 401 | 401 | def _read_others(self) -> None: | |
| 402 | - """Read the answer, authority and additional sections.""" | ||
| 402 | + """Parse everything after the question section in one pass.""" | ||
| 403 | 403 | self._did_read_others = True | |
| 404 | 404 | buf = self._buf | |
| 405 | 405 | answers = self._answers | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -326,7 +326,7 @@ def write_name(self, name: str_) -> None: | |||
| 326 | 326 | self._write_byte(0) | |
| 327 | 327 | ||
| 328 | 328 | def write_short(self, value: int_) -> None: | |
| 329 | - """Append an unsigned short.""" | ||
| 329 | + """Append a 16 bit value in network order.""" | ||
| 330 | 330 | self.data.append(self._get_short(value)) | |
| 331 | 331 | self.size += 2 | |
| 332 | 332 | ||
@@ -361,7 +361,7 @@ def _check_data_limit_or_rollback(self, start_data_length: int_, start_size: int | |||
| 361 | 361 | return False | |
| 362 | 362 | ||
| 363 | 363 | def _get_short(self, value: int_) -> bytes: | |
| 364 | - """Convert an unsigned short to 2 bytes.""" | ||
| 364 | + """Encode a 16 bit value as two network order bytes.""" | ||
| 365 | 365 | return SHORT_LOOKUP[value] if value < SHORT_CACHE_MAX else PACK_SHORT(value) | |
| 366 | 366 | ||
| 367 | 367 | def _has_more_to_add( | |
@@ -380,11 +380,11 @@ def _has_more_to_add( | |||
| 380 | 380 | ) | |
| 381 | 381 | ||
| 382 | 382 | def _insert_short_at_start(self, value: int_) -> None: | |
| 383 | - """Prepend an unsigned short as the first chunk.""" | ||
| 383 | + """Prepend a 16 bit value as the first chunk.""" | ||
| 384 | 384 | self.data.insert(0, self._get_short(value)) | |
| 385 | 385 | ||
| 386 | 386 | def _replace_short(self, index: int_, value: int_) -> None: | |
| 387 | - """Overwrite the chunk at index with an unsigned short.""" | ||
| 387 | + """Overwrite the chunk at index with a 16 bit value.""" | ||
| 388 | 388 | self.data[index] = self._get_short(value) | |
| 389 | 389 | ||
| 390 | 390 | def _reset_for_next_packet(self) -> None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,11 +10,11 @@ | |||
| 10 | 10 | import re | |
| 11 | 11 | import socket | |
| 12 | 12 | ||
| 13 | - _UNREGISTER_TIME = 125 # ms | ||
| 13 | + _BROWSER_TIME = 10000 # ms | ||
| 14 | 14 | _CHECK_TIME = 500 # ms | |
| 15 | - _REGISTER_TIME = 225 # ms | ||
| 16 | 15 | _LISTENER_TIME = 200 # ms | |
| 17 | - _BROWSER_TIME = 10000 # ms | ||
| 16 | + _REGISTER_TIME = 225 # ms | ||
| 17 | + _UNREGISTER_TIME = 125 # ms | ||
| 18 | 18 | _DUPLICATE_PACKET_SUPPRESSION_INTERVAL = 1000 # ms | |
| 19 | 19 | # Per-listener bounded recency window. 16 is large enough to defeat | |
| 20 | 20 | # the alternating-payload bypass (RFC 6762 §6.2, issue #1724 — even a | |
@@ -94,16 +94,16 @@ | |||
| 94 | 94 | _MAX_MSG_TYPICAL = 1460 | |
| 95 | 95 | ||
| 96 | 96 | # DNS header flag bits, RFC 1035 section 4.1.1 and RFC 6762 section 18 | |
| 97 | + _FLAGS_AA = 0x0400 | ||
| 98 | + _FLAGS_AD = 0x0020 | ||
| 99 | + _FLAGS_CD = 0x0010 | ||
| 97 | 100 | _FLAGS_QR_MASK = 0x8000 | |
| 98 | 101 | _FLAGS_QR_QUERY = 0x0000 | |
| 99 | 102 | _FLAGS_QR_RESPONSE = 0x8000 | |
| 100 | - _FLAGS_AA = 0x0400 | ||
| 101 | - _FLAGS_TC = 0x0200 | ||
| 102 | - _FLAGS_RD = 0x0100 | ||
| 103 | 103 | _FLAGS_RA = 0x8000 | |
| 104 | + _FLAGS_RD = 0x0100 | ||
| 105 | + _FLAGS_TC = 0x0200 | ||
| 104 | 106 | _FLAGS_Z = 0x0040 | |
| 105 | - _FLAGS_AD = 0x0020 | ||
| 106 | - _FLAGS_CD = 0x0010 | ||
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | 109 | _CLASS_IN = 1 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments