"last_blocked" : {},
# Last nodeinfo (fetched)
"last_nodeinfo" : {},
+ # Last response time
+ "last_response_time" : {},
# Last status code
"last_status_code" : {},
# Last error details
"last_error_details" : {},
# Wether obfuscation has been used
"has_obfuscation" : {},
- # Determined software
+ # Original software
+ "original_software" : {},
+ # Aliased software
"software" : {},
}
raise ValueError("Parameter 'key' is empty")
elif not key in _pending:
raise ValueError(f"key='{key}' not found in _pending")
+ elif blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function has been invoked")
elif not utils.is_primitive(value):
raise ValueError(f"value[]='{type(value)}' is not a primitive type")
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if not is_registered(domain):
+ raise ValueError(f"domain='{domain}' is not registered but function was invoked.")
+ elif blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function has been invoked")
+
has = False
+ logger.debug("Checking %d _pending array elements ...", len(_pending))
for key in _pending:
- logger.debug("key='%s',domain='%s',_pending[key]()=%d", key, domain, len(_pending[key]))
+ logger.debug("domain='%s',_pending[%s]()=%d", domain, key, len(_pending[key]))
if domain in _pending[key]:
+ logger.debug("domain='%s' at key='%s' has pending data ...", domain, key)
has = True
break
def update(domain: str):
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- if not has_pending(domain):
- raise Exception(f"domain='{domain}' has no pending instance data, but function invoked")
- elif not is_registered(domain):
+
+ if not is_registered(domain):
raise Exception(f"domain='{domain}' cannot be updated while not being registered")
+ elif not has_pending(domain):
+ raise Exception(f"domain='{domain}' has no pending instance data, but function invoked")
+ elif blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function has been invoked")
- logger.debug("Updating instance data for domain='%s' ...", domain)
sql_string = ""
fields = list()
+
+ logger.debug("Checking %d _pending array elements ...", len(_pending))
for key in _pending:
logger.debug("Checking key='%s',domain='%s'", key, domain)
if domain in _pending[key]:
raise ValueError(f"path[]='{type(path)}' is not of type 'str'")
elif path == "":
raise ValueError("Parameter 'path' is empty")
+ elif path is not None and not path.startswith("/"):
+ raise ValueError(f"path='{path}' does not start with / but should")
elif not isinstance(software, str) and software is not None:
raise ValueError(f"software[]='{type(software)}' is not of type 'str'")
elif software == "":
logger.debug("Determined software='%s'", software)
if software == "lemmy" and domain.find("/c/") > 0:
domain = domain.split("/c/")[0]
+
+ logger.debug("domain='%s' - LEMMY /c/ !", domain)
if is_registered(domain):
logger.warning("domain='%s' already registered after cutting off user part. - EXIT!", domain)
return
- logger.info("Adding instance domain='%s',origin='%s',software='%s',command='%s'", domain, origin, software, command)
+ logger.info("Adding instance domain='%s',origin='%s',software='%s',command='%s' ...", domain, origin, software, command)
database.cursor.execute(
- "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
+ "INSERT INTO instances (domain, origin, command, hash, software, original_software, first_seen) VALUES (?, ?, ?, ?, ?, ?, ?)",
(
domain,
origin,
command,
utils.get_hash(domain),
software,
+ software,
time.time()
),
)
logger.debug("Setting last_error_details='%s' (error_message)", error['error_message'])
_set_data("last_status_code" , domain, error["status_code"])
_set_data("last_error_details", domain, error["error_message"] if error["error_message"] != "" else None)
+ elif "json" in error and "error" in error["json"] and "msg" in error["json"]:
+ logger.debug("Setting last_error_details='%s' (json,error)", error["json"]["msg"])
+ _set_data("last_status_code" , domain, error["status_code"])
+ _set_data("last_error_details", domain, error["json"]["msg"] if error["json"]["msg"] != "" else None)
+ elif "json" in error and "error" in error["json"] and "message" in error["json"]["error"]:
+ logger.debug("Setting last_error_details='%s' (json,error)", error["json"]["error"]["message"])
+ _set_data("last_status_code" , domain, error["status_code"])
+ _set_data("last_error_details", domain, error["json"]["error"]["message"] if error["json"]["error"]["message"] != "" else None)
elif "json" in error and "error" in error["json"]:
logger.debug("Setting last_error_details='%s' (json,error)", error["json"]["error"])
_set_data("last_status_code" , domain, error["status_code"])
def is_registered(domain: str, skip_raise = False) -> bool:
logger.debug("domain='%s',skip_raise='%s' - CALLED!", domain, skip_raise)
- if not isinstance(skip_raise, bool):
+ domain_helper.raise_on(domain)
+
+ if blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function has been invoked")
+ elif not isinstance(skip_raise, bool):
raise ValueError(f"skip_raise[]='{type(skip_raise)}' is not type of 'bool'")
if not skip_raise:
raise ValueError(f"char='{char}' not found in domain='{domain}' but function invoked")
elif not isinstance(domain, str):
raise ValueError(f"Parameter domain[]='{type(domain)}'")
- elif domain == "":
- raise ValueError("Parameter 'domain' is empty")
elif not isinstance(blocked_hash, str) and blocked_hash is not None:
raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not of type 'str'")
_set_data("last_instance_fetch", domain, time.time())
logger.debug("EXIT!")
+def set_last_response_time(domain: str, response_time: float):
+ logger.debug("domain='%s',response_time=%d - CALLED!", domain, response_time)
+ domain_helper.raise_on(domain)
+
+ if not isinstance(response_time, float):
+ raise ValueError(f"response_time[]='{type(response_time)}' is not of type 'float'")
+ elif response_time < 0:
+ raise ValueError(f"response_time={response_time} is below zero")
+
+ # Set timestamp
+ _set_data("last_response_time", domain, response_time)
+ logger.debug("EXIT!")
+
def set_total_peers(domain: str, peers: list):
logger.debug("domain='%s',peers()=%d - CALLED!", domain, len(peers))
domain_helper.raise_on(domain)
raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
elif url == "":
raise ValueError("Parameter 'url' is empty")
+ elif url is not None and not validators.url(url):
+ raise ValueError(f"Parameter url='{url}' is not a valid URL")
# Set timestamp
_set_data("nodeinfo_url", domain, url)
_set_data("has_obfuscation", domain, status)
logger.debug("EXIT!")
+def set_original_software(domain: str, software: str):
+ logger.debug("domain='%s',software='%s' - CALLED!", domain, software)
+ domain_helper.raise_on(domain)
+
+ if not isinstance(software, str) and software is not None:
+ raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
+ elif software == "":
+ raise ValueError("Parameter 'software' is empty")
+
+ # Set original software
+ _set_data("original_software", domain, software)
+ logger.debug("EXIT!")
+
+
def set_software(domain: str, software: str):
logger.debug("domain='%s',software='%s' - CALLED!", domain, software)
domain_helper.raise_on(domain)
elif software == "":
raise ValueError("Parameter 'software' is empty")
- # Set timestamp
+ # Set software (maybe aliased to generic name)
_set_data("software", domain, software)
logger.debug("EXIT!")
logger.warning("Deleting row[%s]='%s' as translated='%s' already exist", column, row[column], translated)
database.cursor.execute(f"DELETE FROM instances WHERE {column} = ? LIMIT 1", [row[column]])
else:
+ logger.debug("Updating row[%s]='%s' to translated='%s' ...", column, row[column], translated)
database.cursor.execute(f"UPDATE instances SET {column} = ? WHERE {column} = ? LIMIT 1", [translated, row[column]])
logger.debug("Invoking commit() ...")