mirror of
https://github.com/markqvist/NomadNet.git
synced 2024-10-01 01:26:07 -04:00
Added node list sorting
This commit is contained in:
parent
2322a254a8
commit
0fb9e180ba
@ -66,7 +66,7 @@ class Directory:
|
|||||||
packed_list = []
|
packed_list = []
|
||||||
for source_hash in self.directory_entries:
|
for source_hash in self.directory_entries:
|
||||||
e = self.directory_entries[source_hash]
|
e = self.directory_entries[source_hash]
|
||||||
packed_list.append((e.source_hash, e.display_name, e.trust_level, e.hosts_node, e.preferred_delivery, e.identify))
|
packed_list.append((e.source_hash, e.display_name, e.trust_level, e.hosts_node, e.preferred_delivery, e.identify, e.sort_rank))
|
||||||
|
|
||||||
directory = {
|
directory = {
|
||||||
"entry_list": packed_list,
|
"entry_list": packed_list,
|
||||||
@ -106,13 +106,17 @@ class Directory:
|
|||||||
else:
|
else:
|
||||||
identify = False
|
identify = False
|
||||||
|
|
||||||
entries[e[0]] = DirectoryEntry(e[0], e[1], e[2], hosts_node, preferred_delivery=preferred_delivery, identify_on_connect=identify)
|
if len(e) > 6:
|
||||||
|
sort_rank = e[6]
|
||||||
|
else:
|
||||||
|
sort_rank = None
|
||||||
|
|
||||||
|
entries[e[0]] = DirectoryEntry(e[0], e[1], e[2], hosts_node, preferred_delivery=preferred_delivery, identify_on_connect=identify, sort_rank=sort_rank)
|
||||||
|
|
||||||
self.directory_entries = entries
|
self.directory_entries = entries
|
||||||
|
|
||||||
self.announce_stream = unpacked_directory["announce_stream"]
|
self.announce_stream = unpacked_directory["announce_stream"]
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not load directory from disk. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Could not load directory from disk. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
@ -220,7 +224,14 @@ class Directory:
|
|||||||
def simplest_display_str(self, source_hash):
|
def simplest_display_str(self, source_hash):
|
||||||
trust_level = self.trust_level(source_hash)
|
trust_level = self.trust_level(source_hash)
|
||||||
if trust_level == DirectoryEntry.WARNING or trust_level == DirectoryEntry.UNTRUSTED:
|
if trust_level == DirectoryEntry.WARNING or trust_level == DirectoryEntry.UNTRUSTED:
|
||||||
return "<"+RNS.hexrep(source_hash, delimit=False)+">"
|
if source_hash in self.directory_entries:
|
||||||
|
dn = self.directory_entries[source_hash].display_name
|
||||||
|
if dn == None:
|
||||||
|
return RNS.prettyhexrep(source_hash)
|
||||||
|
else:
|
||||||
|
return dn+" <"+RNS.hexrep(source_hash, delimit=False)+">"
|
||||||
|
else:
|
||||||
|
return "<"+RNS.hexrep(source_hash, delimit=False)+">"
|
||||||
else:
|
else:
|
||||||
if source_hash in self.directory_entries:
|
if source_hash in self.directory_entries:
|
||||||
dn = self.directory_entries[source_hash].display_name
|
dn = self.directory_entries[source_hash].display_name
|
||||||
@ -253,6 +264,12 @@ class Directory:
|
|||||||
else:
|
else:
|
||||||
return DirectoryEntry.UNKNOWN
|
return DirectoryEntry.UNKNOWN
|
||||||
|
|
||||||
|
def sort_rank(self, source_hash):
|
||||||
|
if source_hash in self.directory_entries:
|
||||||
|
return self.directory_entries[source_hash].sort_rank
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def preferred_delivery(self, source_hash):
|
def preferred_delivery(self, source_hash):
|
||||||
if source_hash in self.directory_entries:
|
if source_hash in self.directory_entries:
|
||||||
return self.directory_entries[source_hash].preferred_delivery
|
return self.directory_entries[source_hash].preferred_delivery
|
||||||
@ -312,6 +329,7 @@ class Directory:
|
|||||||
if e.hosts_node:
|
if e.hosts_node:
|
||||||
node_list.append(e)
|
node_list.append(e)
|
||||||
|
|
||||||
|
node_list.sort(key = lambda e: (e.sort_rank if e.sort_rank != None else 2^32, DirectoryEntry.TRUSTED-e.trust_level, e.display_name))
|
||||||
return node_list
|
return node_list
|
||||||
|
|
||||||
def number_of_known_nodes(self):
|
def number_of_known_nodes(self):
|
||||||
@ -336,10 +354,11 @@ class DirectoryEntry:
|
|||||||
DIRECT = 0x01
|
DIRECT = 0x01
|
||||||
PROPAGATED = 0x02
|
PROPAGATED = 0x02
|
||||||
|
|
||||||
def __init__(self, source_hash, display_name=None, trust_level=UNKNOWN, hosts_node=False, preferred_delivery=None, identify_on_connect=False):
|
def __init__(self, source_hash, display_name=None, trust_level=UNKNOWN, hosts_node=False, preferred_delivery=None, identify_on_connect=False, sort_rank=None):
|
||||||
if len(source_hash) == RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
if len(source_hash) == RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
||||||
self.source_hash = source_hash
|
self.source_hash = source_hash
|
||||||
self.display_name = display_name
|
self.display_name = display_name
|
||||||
|
self.sort_rank = sort_rank
|
||||||
|
|
||||||
if preferred_delivery == None:
|
if preferred_delivery == None:
|
||||||
self.preferred_delivery = DirectoryEntry.DIRECT
|
self.preferred_delivery = DirectoryEntry.DIRECT
|
||||||
|
@ -984,7 +984,7 @@ class ConversationWidget(urwid.WidgetWrap):
|
|||||||
urwid.Pile([
|
urwid.Pile([
|
||||||
urwid.Text("The paper message was saved to:\n\n"+str(path)+"\n", align="center"),
|
urwid.Text("The paper message was saved to:\n\n"+str(path)+"\n", align="center"),
|
||||||
urwid.Columns([("weight", 0.6, urwid.Text("")), ("weight", 0.4, urwid.Button("OK", on_press=dismiss_dialog))])
|
urwid.Columns([("weight", 0.6, urwid.Text("")), ("weight", 0.4, urwid.Button("OK", on_press=dismiss_dialog))])
|
||||||
]), title=g["page"]
|
]), title=g["papermsg"].replace(" ", "")
|
||||||
)
|
)
|
||||||
dialog.delegate = self
|
dialog.delegate = self
|
||||||
bottom = self.messagelist
|
bottom = self.messagelist
|
||||||
|
@ -480,6 +480,12 @@ class KnownNodeInfo(urwid.WidgetWrap):
|
|||||||
trust_level = self.app.directory.trust_level(source_hash)
|
trust_level = self.app.directory.trust_level(source_hash)
|
||||||
trust_str = ""
|
trust_str = ""
|
||||||
node_entry = self.app.directory.find(source_hash)
|
node_entry = self.app.directory.find(source_hash)
|
||||||
|
sort_str = self.app.directory.sort_rank(source_hash)
|
||||||
|
if sort_str == None:
|
||||||
|
sort_str = "None"
|
||||||
|
else:
|
||||||
|
sort_str = str(sort_str)
|
||||||
|
|
||||||
if node_entry == None:
|
if node_entry == None:
|
||||||
display_str = self.app.directory.simplest_display_str(source_hash)
|
display_str = self.app.directory.simplest_display_str(source_hash)
|
||||||
else:
|
else:
|
||||||
@ -540,6 +546,7 @@ class KnownNodeInfo(urwid.WidgetWrap):
|
|||||||
r_trusted = urwid.RadioButton(trust_button_group, "Trusted", state=trusted_selected)
|
r_trusted = urwid.RadioButton(trust_button_group, "Trusted", state=trusted_selected)
|
||||||
|
|
||||||
e_name = urwid.Edit(caption="Name : ",edit_text=display_str)
|
e_name = urwid.Edit(caption="Name : ",edit_text=display_str)
|
||||||
|
e_sort = urwid.Edit(caption="Sort Rank : ",edit_text=sort_str)
|
||||||
|
|
||||||
node_ident = RNS.Identity.recall(source_hash)
|
node_ident = RNS.Identity.recall(source_hash)
|
||||||
op_hash = None
|
op_hash = None
|
||||||
@ -604,8 +611,16 @@ class KnownNodeInfo(urwid.WidgetWrap):
|
|||||||
trust_level = DirectoryEntry.TRUSTED
|
trust_level = DirectoryEntry.TRUSTED
|
||||||
|
|
||||||
display_str = e_name.get_edit_text()
|
display_str = e_name.get_edit_text()
|
||||||
|
sort_rank = e_sort.get_edit_text()
|
||||||
|
try:
|
||||||
|
if int(sort_rank) >= 0:
|
||||||
|
sort_rank = int(sort_rank)
|
||||||
|
else:
|
||||||
|
sort_rank = None
|
||||||
|
except:
|
||||||
|
sort_rank = None
|
||||||
|
|
||||||
node_entry = DirectoryEntry(source_hash, display_name=display_str, trust_level=trust_level, hosts_node=True, identify_on_connect=connect_identify_checkbox.get_state())
|
node_entry = DirectoryEntry(source_hash, display_name=display_str, trust_level=trust_level, hosts_node=True, identify_on_connect=connect_identify_checkbox.get_state(), sort_rank=sort_rank)
|
||||||
self.app.directory.remember(node_entry)
|
self.app.directory.remember(node_entry)
|
||||||
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
||||||
|
|
||||||
@ -626,6 +641,7 @@ class KnownNodeInfo(urwid.WidgetWrap):
|
|||||||
urwid.Text("Type : "+type_string, align="left"),
|
urwid.Text("Type : "+type_string, align="left"),
|
||||||
e_name,
|
e_name,
|
||||||
urwid.Text("Node Addr : "+addr_str, align="left"),
|
urwid.Text("Node Addr : "+addr_str, align="left"),
|
||||||
|
e_sort,
|
||||||
urwid.Divider(g["divider1"]),
|
urwid.Divider(g["divider1"]),
|
||||||
urwid.Text(lxmf_addr_str, align="center"),
|
urwid.Text(lxmf_addr_str, align="center"),
|
||||||
urwid.Divider(g["divider1"]),
|
urwid.Divider(g["divider1"]),
|
||||||
|
Loading…
Reference in New Issue
Block a user