Added destination ignore functionality

This commit is contained in:
Mark Qvist 2022-05-17 19:21:14 +02:00
parent 13484a665a
commit f92858866a
3 changed files with 52 additions and 17 deletions

View File

@ -14,20 +14,25 @@ class Conversation:
@staticmethod @staticmethod
def received_announce(destination_hash, announced_identity, app_data): def received_announce(destination_hash, announced_identity, app_data):
app = nomadnet.NomadNetworkApp.get_shared_instance() app = nomadnet.NomadNetworkApp.get_shared_instance()
destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
# Check if the announced destination is in
# our list of conversations
if destination_hash_text in [e[0] for e in Conversation.conversation_list(app)]:
if app.directory.find(destination_hash):
if Conversation.created_callback != None:
Conversation.created_callback()
else:
if Conversation.created_callback != None:
Conversation.created_callback()
# Add the announce to the directory announce if not destination_hash in app.ignored_list:
# stream logger destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
app.directory.lxmf_announce_received(destination_hash, app_data) # Check if the announced destination is in
# our list of conversations
if destination_hash_text in [e[0] for e in Conversation.conversation_list(app)]:
if app.directory.find(destination_hash):
if Conversation.created_callback != None:
Conversation.created_callback()
else:
if Conversation.created_callback != None:
Conversation.created_callback()
# Add the announce to the directory announce
# stream logger
app.directory.lxmf_announce_received(destination_hash, app_data)
else:
RNS.log("Ignored announce from "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
@staticmethod @staticmethod
def query_for_peer(source_hash): def query_for_peer(source_hash):

View File

@ -12,12 +12,17 @@ class Directory:
@staticmethod @staticmethod
def received_announce(destination_hash, announced_identity, app_data): def received_announce(destination_hash, announced_identity, app_data):
app = nomadnet.NomadNetworkApp.get_shared_instance() app = nomadnet.NomadNetworkApp.get_shared_instance()
destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
associated_peer = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", announced_identity) if not destination_hash in app.ignored_list:
destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
app.directory.node_announce_received(destination_hash, app_data, associated_peer) associated_peer = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", announced_identity)
app.autoselect_propagation_node()
app.directory.node_announce_received(destination_hash, app_data, associated_peer)
app.autoselect_propagation_node()
else:
RNS.log("Ignored announce from "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
def __init__(self, app): def __init__(self, app):

View File

@ -65,6 +65,7 @@ class NomadNetworkApp:
self.rns = RNS.Reticulum(configdir = rnsconfigdir) self.rns = RNS.Reticulum(configdir = rnsconfigdir)
self.configpath = self.configdir+"/config" self.configpath = self.configdir+"/config"
self.ignoredpath = self.configdir+"/ignored"
self.logfilepath = self.configdir+"/logfile" self.logfilepath = self.configdir+"/logfile"
self.errorfilepath = self.configdir+"/errors" self.errorfilepath = self.configdir+"/errors"
self.storagepath = self.configdir+"/storage" self.storagepath = self.configdir+"/storage"
@ -202,12 +203,36 @@ class NomadNetworkApp:
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR) RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
nomadnet.panic() nomadnet.panic()
self.ignored_list = []
if os.path.isfile(self.ignoredpath):
try:
fh = open(self.ignoredpath, "rb")
ignored_input = fh.read()
fh.close()
ignored_hash_strs = ignored_input.splitlines()
for hash_str in ignored_hash_strs:
if len(hash_str) == RNS.Identity.TRUNCATED_HASHLENGTH//8*2:
try:
ignored_hash = bytes.fromhex(hash_str.decode("utf-8"))
self.ignored_list.append(ignored_hash)
except Exception as e:
RNS.log("Could not decode RNS Identity hash from: "+str(hash_str), RNS.LOG_DEBUG)
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
except Exception as e:
RNS.log("Error while fetching loading list of ignored destinations: "+str(e), RNS.LOG_ERROR)
self.directory = nomadnet.Directory(self) self.directory = nomadnet.Directory(self)
self.message_router = LXMF.LXMRouter(identity = self.identity, storagepath = self.storagepath, autopeer = True) self.message_router = LXMF.LXMRouter(identity = self.identity, storagepath = self.storagepath, autopeer = True)
self.message_router.register_delivery_callback(self.lxmf_delivery) self.message_router.register_delivery_callback(self.lxmf_delivery)
for destination_hash in self.ignored_list:
self.message_router.ignore_destination(destination_hash)
self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.peer_settings["display_name"]) self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.peer_settings["display_name"])
self.lxmf_destination.set_default_app_data(self.get_display_name_bytes) self.lxmf_destination.set_default_app_data(self.get_display_name_bytes)