lacuscore 1.10.10__py3-none-any.whl → 1.10.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lacuscore/lacuscore.py CHANGED
@@ -23,7 +23,8 @@ from typing import Literal, Any, overload, cast, Iterator
23
23
  from uuid import uuid4
24
24
  from urllib.parse import urlsplit
25
25
 
26
- from dns import resolver
26
+ from dns.resolver import Cache
27
+ from dns.asyncresolver import Resolver
27
28
  from dns.exception import DNSException
28
29
  from dns.exception import Timeout as DNSTimeout
29
30
 
@@ -98,8 +99,8 @@ class LacusCore():
98
99
  self.tor_proxy = tor_proxy
99
100
  self.only_global_lookups = only_global_lookups
100
101
  self.max_retries = max_retries
101
- self.dnsresolver: resolver.Resolver = resolver.Resolver()
102
- self.dnsresolver.cache = resolver.Cache(30)
102
+ self.dnsresolver: Resolver = Resolver()
103
+ self.dnsresolver.cache = Cache(900)
103
104
  self.dnsresolver.timeout = 2
104
105
  self.dnsresolver.lifetime = 3
105
106
 
@@ -414,7 +415,7 @@ class LacusCore():
414
415
  except ValueError:
415
416
  # not an IP, try resolving
416
417
  try:
417
- ips_to_check = self.__get_ips(logger, splitted_url.hostname)
418
+ ips_to_check = await self.__get_ips(logger, splitted_url.hostname)
418
419
  except DNSTimeout as e:
419
420
  # for a timeout, we do not want to retry, as it is likely to timeout again
420
421
  result = {'error': f'DNS Timeout for "{splitted_url.hostname}": {e}'}
@@ -733,22 +734,40 @@ class LacusCore():
733
734
  p.zrem('lacus:ongoing', uuid)
734
735
  p.execute()
735
736
 
736
- def __get_ips(self, logger: LacusCoreLogAdapter, hostname: str) -> list[IPv4Address | IPv6Address]:
737
+ async def __get_ips(self, logger: LacusCoreLogAdapter, hostname: str) -> list[IPv4Address | IPv6Address]:
737
738
  # We need to use dnspython for resolving because socket.getaddrinfo will sometimes be stuck for ~10s
738
739
  # It is happening when the error code is NoAnswer
739
740
  resolved_ips = []
740
- try:
741
- answers_a = self.dnsresolver.resolve(hostname, 'A')
742
- resolved_ips += [ip_address(str(answer)) for answer in answers_a]
743
- except DNSTimeout as e:
744
- raise e
745
- except DNSException as e:
746
- logger.info(f'No A record for "{hostname}": {e}')
747
- try:
748
- answers_aaaa = self.dnsresolver.resolve(hostname, 'AAAA')
749
- resolved_ips += [ip_address(str(answer)) for answer in answers_aaaa]
750
- except DNSTimeout as e:
751
- raise e
752
- except DNSException as e:
753
- logger.info(f'No AAAA record for "{hostname}": {e}')
741
+ max_timeout_retries = 3
742
+ _current_retries = 0
743
+ while _current_retries < max_timeout_retries:
744
+ _current_retries += 1
745
+ try:
746
+ answers_a = await self.dnsresolver.resolve(hostname, 'A')
747
+ resolved_ips += [ip_address(str(answer)) for answer in answers_a]
748
+ except DNSTimeout as e:
749
+ if _current_retries < max_timeout_retries:
750
+ logger.info(f'DNS Timeout for "{hostname}" (A record), retrying.')
751
+ await asyncio.sleep(1)
752
+ continue
753
+ raise e
754
+ except DNSException as e:
755
+ logger.info(f'No A record for "{hostname}": {e}')
756
+ break
757
+
758
+ _current_retries = 0
759
+ while _current_retries < max_timeout_retries:
760
+ _current_retries += 1
761
+ try:
762
+ answers_aaaa = await self.dnsresolver.resolve(hostname, 'AAAA')
763
+ resolved_ips += [ip_address(str(answer)) for answer in answers_aaaa]
764
+ except DNSTimeout as e:
765
+ if _current_retries < max_timeout_retries:
766
+ logger.info(f'DNS Timeout for "{hostname}" (AAAA record), retrying.')
767
+ await asyncio.sleep(1)
768
+ continue
769
+ raise e
770
+ except DNSException as e:
771
+ logger.info(f'No AAAA record for "{hostname}": {e}')
772
+ break
754
773
  return resolved_ips
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lacuscore
3
- Version: 1.10.10
3
+ Version: 1.10.12
4
4
  Summary: Core of Lacus, usable as a module
5
5
  Home-page: https://github.com/ail-project/LacusCore
6
6
  License: BSD-3-Clause
@@ -30,7 +30,7 @@ Requires-Dist: async-timeout (>=4.0.3,<5.0.0) ; python_version < "3.11"
30
30
  Requires-Dist: defang (>=0.5.3,<0.6.0)
31
31
  Requires-Dist: dnspython (>=2.6.1,<3.0.0)
32
32
  Requires-Dist: eval-type-backport (>=0.2.0,<0.3.0) ; python_version < "3.10"
33
- Requires-Dist: playwrightcapture[recaptcha] (>=1.25.11,<2.0.0)
33
+ Requires-Dist: playwrightcapture[recaptcha] (>=1.25.14,<2.0.0)
34
34
  Requires-Dist: pydantic (>=2.8.2,<3.0.0)
35
35
  Requires-Dist: redis[hiredis] (>=5.0.8,<6.0.0)
36
36
  Requires-Dist: requests (>=2.32.3,<3.0.0)
@@ -1,10 +1,10 @@
1
1
  lacuscore/__init__.py,sha256=aLBshQPT9IBDKn5qWrX9A_exqtLFPyLsQiPWdfpAFjA,537
2
2
  lacuscore/helpers.py,sha256=qAB_E1wVisl-YgN41zTD35PzJc0i_CoA1sPAb73gzck,10855
3
3
  lacuscore/lacus_monitoring.py,sha256=UOfE_1-_rhVeKJXQ_m9XxYkr7VwyQnA6iK-x_tcXJfo,2775
4
- lacuscore/lacuscore.py,sha256=73yGF9hbLXg-HutLubIgx3CY4e7gVra-VT4PPtwUoDc,39489
4
+ lacuscore/lacuscore.py,sha256=ae4Mt_DT_ALlySt_I3oiTKoVU6z4lm9LFCS3oWPqFcA,40330
5
5
  lacuscore/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  lacuscore/task_logger.py,sha256=kWBThqfv_alu1YA3jEqP4GsqXIVKLbzyI7w14aJ2g9I,1908
7
- lacuscore-1.10.10.dist-info/LICENSE,sha256=4C4hLYrIkUD96Ggk-y_Go1Qf7PBZrEm9PSeTGe2nd4s,1516
8
- lacuscore-1.10.10.dist-info/METADATA,sha256=1Ha38GM8uu-uqAO8O40FxRCi81bQXeaGdYl-Us70za8,2859
9
- lacuscore-1.10.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
- lacuscore-1.10.10.dist-info/RECORD,,
7
+ lacuscore-1.10.12.dist-info/LICENSE,sha256=4C4hLYrIkUD96Ggk-y_Go1Qf7PBZrEm9PSeTGe2nd4s,1516
8
+ lacuscore-1.10.12.dist-info/METADATA,sha256=sTwBsBrmH4AcIrs9jSqZWrN5HIuYJMdniqNbb6voghQ,2859
9
+ lacuscore-1.10.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
+ lacuscore-1.10.12.dist-info/RECORD,,