X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Ffederation.py;h=da7277cbce40668754ef15c8d802595a7ad23ff9;hb=c8b6b6a4aea21b3fefc8fd4900391d59751ff814;hp=ee839c78ca17bd0212161fb932fc28e58f388d74;hpb=3b97ae4ffc2c29d73f8afa16f11d830ed69b72f6;p=fba.git diff --git a/fba/federation.py b/fba/federation.py index ee839c7..da7277c 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -60,7 +60,10 @@ def fetch_instances(domain: str, origin: str, software: str, script: str, path: elif domain == "": raise ValueError("Parameter 'domain' is empty") - if not instances.is_registered(domain): + if domain.split(".")[-1] == "arpa": + print(f"WARNING: domain='{domain}' is a reversed .arpa domain and should not be used generally.") + return + elif not instances.is_registered(domain): # DEBUG: print("DEBUG: Adding new domain:", domain, origin) instances.add(domain, origin, script, path) @@ -74,8 +77,9 @@ def fetch_instances(domain: str, origin: str, software: str, script: str, path: # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo data, flushing ...") instances.update_data(domain) - print(f"INFO: Checking {len(peerlist)} instances from {domain} ...") + print(f"INFO: Checking {len(peerlist)} instances from domain='{domain}' ...") for instance in peerlist: + # DEBUG: print(f"DEBUG: instance='{instance}'") if instance is None: # Skip "None" types as tidup.domain() cannot parse them continue @@ -85,17 +89,23 @@ def fetch_instances(domain: str, origin: str, software: str, script: str, path: # DEBUG: print(f"DEBUG: instance='{instance}' - AFTER") if instance == "": - print("WARNING: Empty instance after tidyup.domain(), domain:", domain) + print(f"WARNING: Empty instance after tidyup.domain(), domain='{domain}'") continue elif not validators.domain(instance.split("/")[0]): print(f"WARNING: Bad instance='{instance}' from domain='{domain}',origin='{origin}',software='{software}'") continue + elif instance.split(".")[-1] == "arpa": + print(f"WARNING: instance='{instance}' is a reversed .arpa domain and should not be used generally.") + continue elif blacklist.is_blacklisted(instance): # DEBUG: print("DEBUG: instance is blacklisted:", instance) continue # DEBUG: print("DEBUG: Handling instance:", instance) - if not instances.is_registered(instance): + if instance.split(".")[-1] == "arpa": + print(f"WARNING: instance='{instance}' is a reversed .arpa domain and should not be used generally.") + continue + elif not instances.is_registered(instance): # DEBUG: print("DEBUG: Adding new instance:", instance, domain) instances.add(instance, domain, script) @@ -186,10 +196,10 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: # DEBUG: print(f"DEBUG: Fetching nodeinfo from domain='{domain}' ...") nodeinfo = fetch_wellknown_nodeinfo(domain) - # DEBUG: print(f"DEBUG: nodeinfo[{type(nodeinfo)}]='{nodeinfo}'") - if "error_message" in nodeinfo: - print(f"WARNING: Error during fetching nodeinfo: '{nodeinfo['error_message']}' - EXIT!") - return nodeinfo + # DEBUG: print(f"DEBUG: nodeinfo[{type(nodeinfo)}]()='{len(nodeinfo)}'") + if "error_message" not in nodeinfo and "json" in nodeinfo and len(nodeinfo["json"]) > 0: + # DEBUG: print(f"DEBUG: Found nodeinfo[json]()={len(nodeinfo['json'])} - EXIT!") + return nodeinfo["json"] # No CSRF by default, you don't have to add network.api_headers by yourself here headers = tuple() @@ -200,7 +210,11 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: headers = csrf.determine(domain, dict()) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during checking CSRF (nodeinfo,{__name__}) - EXIT!") - return dict() + return { + "status_code" : 500, + "error_message": f"exception[{type(exception)}]='{str(exception)}'", + "exception" : exception, + } request_paths = [ "/nodeinfo/2.1.json", @@ -212,7 +226,7 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: ] for request in request_paths: - # DEBUG: print(f"DEBUG: path[{type(path)}]='{path}',request='{request'}") + # DEBUG: print(f"DEBUG: path[{type(path)}]='{path}',request='{request}'") if path is not None and path != "" and path != request: # DEBUG: print(f"DEBUG: path='{path}' does not match request='{request}' - SKIPPED!") continue @@ -254,7 +268,8 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: print(f"WARNING: Exception '{type(exception)}' during checking CSRF (fetch_wellknown,{__name__}) - EXIT!") return { "status_code" : 500, - "error_message": type(exception) + "error_message": type(exception), + "exception" : exception, } # DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain) @@ -374,27 +389,28 @@ def determine_software(domain: str, path: str = None) -> str: data = fetch_nodeinfo(domain, path) # DEBUG: print(f"DEBUG: data[{type(data)}]='{data}'") - if "error_message" in data: - # DEBUG: print("DEBUG: Could not determine software type:", domain) + if "exception" in data: + # Continue raising it + raise data["exception"] + elif "error_message" in data: + # DEBUG: print(f"DEBUG: Returned error_message during fetching nodeinfo: '{data['error_message']}',status_code='{data['status_code']}'") return fetch_generator_from_path(domain) - - # DEBUG: print("DEBUG: data():", len(data), data) - if "status" in data["json"] and data["json"]["status"] == "error" and "message" in data["json"]: - print("WARNING: JSON response is an error:", data["json"]["message"]) - instances.update_last_error(domain, data["json"]["message"]) + elif "status" in data and data["status"] == "error" and "message" in data: + print("WARNING: JSON response is an error:", data["message"]) + instances.update_last_error(domain, data["message"]) return fetch_generator_from_path(domain) - elif "message" in data["json"]: + elif "message" in data: print("WARNING: JSON response contains only a message:", data["message"]) - instances.update_last_error(domain, data["json"]["message"]) + instances.update_last_error(domain, data["message"]) return fetch_generator_from_path(domain) - elif "software" not in data["json"] or "name" not in data["json"]["software"]: + elif "software" not in data or "name" not in data["software"]: # DEBUG: print(f"DEBUG: JSON response from domain='{domain}' does not include [software][name], fetching / ...") software = fetch_generator_from_path(domain) # DEBUG: print(f"DEBUG: Generator for domain='{domain}' is: {software}, EXIT!") return software - software = tidyup.domain(data["json"]["software"]["name"]) + software = tidyup.domain(data["software"]["name"]) # DEBUG: print("DEBUG: sofware after tidyup.domain():", software) if software in ["akkoma", "rebased"]: