lacuscore 1.10.9__tar.gz → 1.10.11__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lacuscore
3
- Version: 1.10.9
3
+ Version: 1.10.11
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.10,<2.0.0)
33
+ Requires-Dist: playwrightcapture[recaptcha] (>=1.25.13,<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)
@@ -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,11 +99,14 @@ 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
 
107
+ # Enable new chromium headless by default.
108
+ os.environ["PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW"] = "1"
109
+
106
110
  # NOTE: Remove in 1.8.* - clear old ongoing captures queue in case of need
107
111
  if self.redis.type('lacus:ongoing') in ['set', b'set']: # type: ignore[no-untyped-call]
108
112
  self.redis.delete('lacus:ongoing')
@@ -411,7 +415,7 @@ class LacusCore():
411
415
  except ValueError:
412
416
  # not an IP, try resolving
413
417
  try:
414
- ips_to_check = self.__get_ips(logger, splitted_url.hostname)
418
+ ips_to_check = await self.__get_ips(logger, splitted_url.hostname)
415
419
  except DNSTimeout as e:
416
420
  # for a timeout, we do not want to retry, as it is likely to timeout again
417
421
  result = {'error': f'DNS Timeout for "{splitted_url.hostname}": {e}'}
@@ -730,22 +734,40 @@ class LacusCore():
730
734
  p.zrem('lacus:ongoing', uuid)
731
735
  p.execute()
732
736
 
733
- def __get_ips(self, logger: LacusCoreLogAdapter, hostname: str) -> list[IPv4Address | IPv6Address]:
737
+ async def __get_ips(self, logger: LacusCoreLogAdapter, hostname: str) -> list[IPv4Address | IPv6Address]:
734
738
  # We need to use dnspython for resolving because socket.getaddrinfo will sometimes be stuck for ~10s
735
739
  # It is happening when the error code is NoAnswer
736
740
  resolved_ips = []
737
- try:
738
- answers_a = self.dnsresolver.resolve(hostname, 'A')
739
- resolved_ips += [ip_address(str(answer)) for answer in answers_a]
740
- except DNSTimeout as e:
741
- raise e
742
- except DNSException as e:
743
- logger.info(f'No A record for "{hostname}": {e}')
744
- try:
745
- answers_aaaa = self.dnsresolver.resolve(hostname, 'AAAA')
746
- resolved_ips += [ip_address(str(answer)) for answer in answers_aaaa]
747
- except DNSTimeout as e:
748
- raise e
749
- except DNSException as e:
750
- 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
751
773
  return resolved_ips
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "lacuscore"
3
- version = "1.10.9"
3
+ version = "1.10.11"
4
4
  description = "Core of Lacus, usable as a module"
5
5
  authors = ["Raphaël Vinot <raphael.vinot@circl.lu>"]
6
6
  license = "BSD-3-Clause"
@@ -35,7 +35,7 @@ Sphinx = [
35
35
  {version = "^7.2", python = ">=3.9,<3.10", optional = true},
36
36
  {version = "^8", python = ">=3.10", optional = true}
37
37
  ]
38
- playwrightcapture = {extras = ["recaptcha"], version = "^1.25.10"}
38
+ playwrightcapture = {extras = ["recaptcha"], version = "^1.25.13"}
39
39
  defang = "^0.5.3"
40
40
  ua-parser = "^0.18.0"
41
41
  redis = {version = "^5.0.8", extras = ["hiredis"]}
@@ -48,7 +48,7 @@ eval-type-backport = {version = "^0.2.0", python = "<3.10"}
48
48
  docs = ["Sphinx"]
49
49
 
50
50
  [tool.poetry.group.dev.dependencies]
51
- types-redis = {version = "^4.6.0.20240726"}
51
+ types-redis = {version = "^4.6.0.20240806"}
52
52
  mypy = "^1.11.1"
53
53
  types-requests = "^2.32.0.20240712"
54
54
  types-beautifulsoup4 = "^4.12.0.20240511"
File without changes
File without changes