mirror of
https://github.com/markqvist/NomadNet.git
synced 2024-10-01 01:26:07 -04:00
Added destination ignore functionality
This commit is contained in:
parent
13484a665a
commit
f92858866a
@ -14,20 +14,25 @@ class Conversation:
|
||||
@staticmethod
|
||||
def received_announce(destination_hash, announced_identity, app_data):
|
||||
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
|
||||
# stream logger
|
||||
app.directory.lxmf_announce_received(destination_hash, app_data)
|
||||
if not destination_hash in app.ignored_list:
|
||||
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
|
||||
# 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
|
||||
def query_for_peer(source_hash):
|
||||
|
@ -12,12 +12,17 @@ class Directory:
|
||||
@staticmethod
|
||||
def received_announce(destination_hash, announced_identity, app_data):
|
||||
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)
|
||||
app.autoselect_propagation_node()
|
||||
associated_peer = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", announced_identity)
|
||||
|
||||
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):
|
||||
|
@ -65,6 +65,7 @@ class NomadNetworkApp:
|
||||
self.rns = RNS.Reticulum(configdir = rnsconfigdir)
|
||||
|
||||
self.configpath = self.configdir+"/config"
|
||||
self.ignoredpath = self.configdir+"/ignored"
|
||||
self.logfilepath = self.configdir+"/logfile"
|
||||
self.errorfilepath = self.configdir+"/errors"
|
||||
self.storagepath = self.configdir+"/storage"
|
||||
@ -202,12 +203,36 @@ class NomadNetworkApp:
|
||||
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
|
||||
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.message_router = LXMF.LXMRouter(identity = self.identity, storagepath = self.storagepath, autopeer = True)
|
||||
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.set_default_app_data(self.get_display_name_bytes)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user