X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fhttp%2Fnodeinfo.py;h=5626812a29c776532d7408a0a456ec39c89b207b;hb=fb6107960d03c756d707a356a0e0bc10d2656b06;hp=724c87501d45d7784a1eafb761a5b66ad63a33d2;hpb=bcb74a15969c5e29681466a379a02a7084077f30;p=fba.git diff --git a/fba/http/nodeinfo.py b/fba/http/nodeinfo.py index 724c875..5626812 100644 --- a/fba/http/nodeinfo.py +++ b/fba/http/nodeinfo.py @@ -14,15 +14,13 @@ # along with this program. If not, see . import logging -import validators from urllib.parse import urlparse -from fba import csrf - from fba.helpers import config from fba.helpers import domain as domain_helper +from fba.http import csrf from fba.http import network from fba.models import instances @@ -32,20 +30,16 @@ _DEPTH = 0 logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -def fetch(domain: str, path: str = None, nodeinfo_url: str = None) -> dict: - logger.debug("domain='%s',path='%s',nodeinfo_url='%s' - CALLED!", domain, path, nodeinfo_url) +def fetch(domain: str, path: str = None, update_mode: bool = True) -> dict: + logger.debug("domain='%s',path='%s',update_mode='%s' - CALLED!", domain, path, update_mode) domain_helper.raise_on(domain) if not isinstance(path, str) and path is not None: raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'") - elif not isinstance(nodeinfo_url, str) and nodeinfo_url is not None: - raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not of type 'str'") - - logger.debug("nodeinfo_url='%s'", nodeinfo_url) - is_url = nodeinfo_url is not None and validators.url(nodeinfo_url) + elif not isinstance(update_mode, bool) and update_mode is not None: + raise ValueError(f"Parameter update_mode[]='{type(update_mode)}' is not of type 'bool'") - logger.debug("is_url='%s'", is_url) - if not is_url: + if path is None and update_mode: logger.debug("Fetching well-known nodeinfo from domain='%s' ...", domain) data = fetch_wellknown_nodeinfo(domain) @@ -92,7 +86,7 @@ def fetch(domain: str, path: str = None, nodeinfo_url: str = None) -> dict: https_url = f"https://{domain}{str(path) if path is not None else '/'}" logger.debug("path[%s]='%s',request='%s',http_url='%s',https_url='%s'", type(path), path, request, http_url, https_url) - if (path is None and nodeinfo_url is None) or path in [request, http_url, https_url] or (is_url and nodeinfo_url.endswith(request)): + if path is None or path in [request, http_url, https_url]: logger.debug("Fetching request='%s' from domain='%s' ...", request, domain) data = network.get_json_api( domain, @@ -105,8 +99,9 @@ def fetch(domain: str, path: str = None, nodeinfo_url: str = None) -> dict: if "error_message" not in data and "json" in data: logger.debug("Success: request='%s' - Setting detection_mode=STATIC_CHECK ...", request) instances.set_last_nodeinfo(domain) - instances.set_detection_mode(domain, "STATIC_CHECK") - instances.set_nodeinfo_url(domain, request) + if update_mode: + instances.set_detection_mode(domain, "STATIC_CHECK") + instances.set_nodeinfo_url(domain, "https://{domain}{request}") break logger.warning("Failed fetching nodeinfo from domain='%s',status_code='%s',error_message='%s'", domain, data['status_code'], data['error_message']) @@ -202,7 +197,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: # Default is that 'href' has a complete URL, but some hosts don't send that logger.debug("link[rel]='%s' matches niid='%s'", link["rel"], niid) - url = link["href"] + url = link["href"].lower() components = urlparse(url) logger.debug("components[%s]='%s'", type(components), components) @@ -215,9 +210,10 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: url = f"{components.scheme}://{domain}{components.path}" components = urlparse(url) - logger.debug("components.netloc[]='%s'", type(components.netloc)) - if not domain_helper.is_wanted(components.netloc): - logger.debug("components.netloc='%s' is not wanted - SKIPPED!", components.netloc) + domain2 = components.netloc.lower().split(":")[0] + logger.debug("domain2='%s'", domain2) + if not domain_helper.is_wanted(domain2): + logger.debug("domain2='%s' is not wanted - SKIPPED!", domain2) continue logger.debug("Fetching nodeinfo from url='%s' ...", url)