mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-03-30 10:38:18 -04:00
Node announce handling.
This commit is contained in:
parent
f0fae68e31
commit
a3f7fa03eb
@ -2,6 +2,7 @@ import os
|
|||||||
import RNS
|
import RNS
|
||||||
import LXMF
|
import LXMF
|
||||||
import time
|
import time
|
||||||
|
import nomadnet
|
||||||
import RNS.vendor.umsgpack as msgpack
|
import RNS.vendor.umsgpack as msgpack
|
||||||
|
|
||||||
class Directory:
|
class Directory:
|
||||||
@ -13,9 +14,11 @@ class Directory:
|
|||||||
app = nomadnet.NomadNetworkApp.get_shared_instance()
|
app = nomadnet.NomadNetworkApp.get_shared_instance()
|
||||||
destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
|
destination_hash_text = RNS.hexrep(destination_hash, delimit=False)
|
||||||
|
|
||||||
|
associated_peer = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", announced_identity)
|
||||||
|
|
||||||
# TODO: REMOVE
|
# TODO: REMOVE
|
||||||
RNS.log("Received node announce from: "+destination_hash_text)
|
RNS.log("Received node announce for node: "+destination_hash_text+" from "+RNS.prettyhexrep(associated_peer))
|
||||||
app.directory.lxmf_announce_received(destination_hash, app_data)
|
app.directory.node_announce_received(destination_hash, app_data, associated_peer)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
@ -62,16 +65,7 @@ class Directory:
|
|||||||
|
|
||||||
self.directory_entries = entries
|
self.directory_entries = entries
|
||||||
|
|
||||||
# TODO: Revert back to this simpler method instead of checking
|
self.announce_stream = unpacked_directory["announce_stream"]
|
||||||
# for the old format
|
|
||||||
# self.announce_stream = unpacked_directory["announce_stream"]
|
|
||||||
|
|
||||||
for entry in unpacked_directory["announce_stream"]:
|
|
||||||
RNS.log(str(entry))
|
|
||||||
if len(entry) < 4:
|
|
||||||
entry = (entry[0], entry[1], entry[2], False)
|
|
||||||
|
|
||||||
self.announce_stream.append(entry)
|
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -83,12 +77,16 @@ class Directory:
|
|||||||
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
|
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
|
||||||
self.announce_stream.pop()
|
self.announce_stream.pop()
|
||||||
|
|
||||||
def node_announce_received(self, source_hash, app_data):
|
def node_announce_received(self, source_hash, app_data, associated_peer):
|
||||||
timestamp = time.time()
|
timestamp = time.time()
|
||||||
self.announce_stream.insert(0, (timestamp, source_hash, app_data, True))
|
self.announce_stream.insert(0, (timestamp, source_hash, app_data, True))
|
||||||
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
|
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
|
||||||
self.announce_stream.pop()
|
self.announce_stream.pop()
|
||||||
|
|
||||||
|
if self.trust_level(associated_peer) == DirectoryEntry.TRUSTED:
|
||||||
|
node_entry = DirectoryEntry(source_hash, display_name=app_data.decode("utf-8"), trust_level=DirectoryEntry.TRUSTED, hosts_node=True)
|
||||||
|
self.remember(node_entry)
|
||||||
|
|
||||||
def display_name(self, source_hash):
|
def display_name(self, source_hash):
|
||||||
if source_hash in self.directory_entries:
|
if source_hash in self.directory_entries:
|
||||||
return self.directory_entries[source_hash].display_name
|
return self.directory_entries[source_hash].display_name
|
||||||
|
@ -156,7 +156,7 @@ class NomadNetworkApp:
|
|||||||
|
|
||||||
RNS.log("LXMF Router ready to receive on: "+RNS.prettyhexrep(self.lxmf_destination.hash))
|
RNS.log("LXMF Router ready to receive on: "+RNS.prettyhexrep(self.lxmf_destination.hash))
|
||||||
|
|
||||||
self.directory = nomadnet.Directory.Directory(self)
|
self.directory = nomadnet.Directory(self)
|
||||||
|
|
||||||
if self.enable_node:
|
if self.enable_node:
|
||||||
self.node = nomadnet.Node(self)
|
self.node = nomadnet.Node(self)
|
||||||
|
@ -3,6 +3,7 @@ import glob
|
|||||||
|
|
||||||
from .NomadNetworkApp import NomadNetworkApp
|
from .NomadNetworkApp import NomadNetworkApp
|
||||||
from .Conversation import Conversation
|
from .Conversation import Conversation
|
||||||
|
from .Directory import Directory
|
||||||
from .Node import Node
|
from .Node import Node
|
||||||
from .ui import *
|
from .ui import *
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user