From: Roland Häder Date: Sat, 20 May 2023 13:07:40 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=05747f5ef74dd43bb2ce096b8522d5d5194ea9b4;p=fba.git Continued: - added origin to track which instance has referenced this one --- diff --git a/blocks_empty.db b/blocks_empty.db index dc11b35..14ad7e8 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/fba.py b/fba.py index 78f6b8b..8c708e9 100644 --- a/fba.py +++ b/fba.py @@ -233,18 +233,22 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str, fi print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen) sys.exit(255) -def add_instance(domain: str): - # NOISY-DEBUG: print("DEBUG: domain:", domain) +def add_instance(domain: str, origin: str): + # NOISY-DEBUG: print("DEBUG: domain,origin:", domain, origin) if domain.find("@") > 0: print("WARNING: Bad domain name:", domain) raise + elif origin is not None and origin.find("@") > 0: + print("WARNING: Bad origin name:", origin) + raise - print("--- Adding new instance:", domain) + print("--- Adding new instance:", domain, origin) try: c.execute( - "INSERT INTO instances (domain,hash,software) VALUES (?, ?, ?)", + "INSERT INTO instances (domain,origin,hash,software) VALUES (?, ?, ?, ?)", ( domain, + origin, get_hash(domain), determine_software(domain) ), diff --git a/fetch_blocks.py b/fetch_blocks.py index 2a13023..cc2b0ec 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -75,8 +75,8 @@ for blocker, software in fba.c.fetchall(): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked) - fba.add_instance(blocked) + # NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked, blocker) + fba.add_instance(blocked, blocker) timestamp = int(time.time()) fba.c.execute( @@ -228,8 +228,8 @@ for blocker, software in fba.c.fetchall(): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked) - fba.add_instance(blocked) + # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker) + fba.add_instance(blocked, blocker) else: # Doing the hash search for instance names as well to tidy up DB fba.c.execute( @@ -319,8 +319,8 @@ for blocker, software in fba.c.fetchall(): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked) - fba.add_instance(blocked) + # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker) + fba.add_instance(blocked, blocker) timestamp = int(time.time()) fba.c.execute( @@ -382,8 +382,8 @@ for blocker, software in fba.c.fetchall(): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked) - fba.add_instance(blocked) + # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason) + fba.update_block_reason(reason, blocker, blocked, block_level) fba.c.execute( "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?", diff --git a/fetch_instances.py b/fetch_instances.py index cc855e6..9237fc1 100644 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -4,8 +4,8 @@ import json import time import fba -def fetch_instances(domain: str): - # NOISY-DEBUG: print("DEBUG: Fetching instances for domain:", domain) +def fetch_instances(domain: str, origin: str): + # NOISY-DEBUG: print("DEBUG: Fetching instances for domain:", domain, origin) peerlist = fba.get_peers(domain) if (peerlist is None): @@ -16,8 +16,8 @@ def fetch_instances(domain: str): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Adding new domain:", domain) - fba.add_instance(domain) + # NOISY-DEBUG: print("DEBUG: Adding new domain:", domain, origin) + fba.add_instance(domain, origin) fba.conn.commit() return @@ -44,8 +44,8 @@ def fetch_instances(domain: str): ) if fba.c.fetchone() == None: - # NOISY-DEBUG: print("DEBUG: Adding new instance:", instance) - fba.add_instance(instance) + # NOISY-DEBUG: print("DEBUG: Adding new instance:", instance, domain) + fba.add_instance(instance, domain) fba.conn.commit() @@ -56,7 +56,7 @@ def fetch_instances(domain: str): instance = sys.argv[1] # Initial fetch -fetch_instances(instance) +fetch_instances(instance, None) # Loop through some instances fba.c.execute( @@ -74,6 +74,6 @@ for instance in fba.c.fetchall(): continue print("INFO: Fetching instances for instance:", instance[0]) - fetch_instances(instance[0]) + fetch_instances(instance[0], None) fba.conn.close()