Added daemon mode

pull/6/head
Mark Qvist 2022-05-17 13:11:04 +02:00
parent 34b377bafe
commit c6e26e7f7f
10 changed files with 46 additions and 14 deletions

View File

@ -66,7 +66,8 @@ class Conversation:
except Exception as e:
pass
Conversation.created_callback()
if Conversation.created_callback != None:
Conversation.created_callback()
return ingested_path

View File

@ -86,7 +86,9 @@ class Directory:
self.announce_stream.insert(0, (timestamp, source_hash, app_data, False))
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
self.announce_stream.pop()
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
if hasattr(self.app.ui, "main_display"):
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
def node_announce_received(self, source_hash, app_data, associated_peer):
if app_data != None:
@ -101,7 +103,8 @@ class Directory:
node_entry = DirectoryEntry(source_hash, display_name=app_data.decode("utf-8"), trust_level=DirectoryEntry.TRUSTED, hosts_node=True)
self.remember(node_entry)
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
if hasattr(self.app.ui, "main_display"):
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
def remove_announce_with_timestamp(self, timestamp):
selected_announce = None

View File

@ -46,7 +46,7 @@ class NomadNetworkApp:
if issubclass(e_type, KeyboardInterrupt):
sys.__excepthook__(e_type, e_value, e_traceback)
def __init__(self, configdir = None, rnsconfigdir = None):
def __init__(self, configdir = None, rnsconfigdir = None, daemon = False):
self.version = __version__
self.enable_client = False
self.enable_node = False
@ -239,6 +239,10 @@ class NomadNetworkApp:
job_thread.setDaemon(True)
job_thread.start()
# Override UI choice from config on --daemon switch
if daemon:
self.uimode = nomadnet.ui.UI_NONE
# This stderr redirect is needed to stop urwid
# from spewing KeyErrors to the console and thus,
# messing up the UI. A pull request to fix the

View File

@ -1 +1 @@
__version__ = "0.1.7"
__version__ = "0.1.8"

View File

@ -7,14 +7,15 @@ import argparse
import nomadnet
def program_setup(configdir, rnsconfigdir):
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir)
def program_setup(configdir, rnsconfigdir, daemon):
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir, daemon = daemon)
def main():
try:
parser = argparse.ArgumentParser(description="Nomad Network Client")
parser.add_argument("--config", action="store", default=None, help="path to alternative Nomad Network config directory", type=str)
parser.add_argument("--rnsconfig", action="store", default=None, help="path to alternative Reticulum config directory", type=str)
parser.add_argument("-d", "--daemon", action="store_true", default=False, help="run Nomad Network in daemon mode")
parser.add_argument("--version", action="version", version="Nomad Network Client {version}".format(version=__version__))
args = parser.parse_args()
@ -29,7 +30,7 @@ def main():
else:
rnsconfigarg = None
program_setup(configarg, rnsconfigarg)
program_setup(configarg, rnsconfigarg, args.daemon)
except KeyboardInterrupt:
print("")

View File

@ -4,5 +4,5 @@ import nomadnet
class MenuUI:
def __init__(self):
RNS.log("Menu UI not implemented", RNS.LOG_ERROR)
RNS.log("Menu UI not implemented", RNS.LOG_ERROR, _override_destination=True)
nomadnet.panic()

View File

@ -0,0 +1,16 @@
import RNS
import nomadnet
import time
from nomadnet import NomadNetworkApp
class NoneUI:
def __init__(self):
self.app = NomadNetworkApp.get_shared_instance()
self.app.ui = self
RNS.log("Nomad Network started in daemon mode, all further messages are logged to "+str(self.app.logfilepath), RNS.LOG_INFO, _override_destination=True)
while True:
time.sleep(1)

View File

@ -12,11 +12,15 @@ UI_MENU = 0x01
UI_TEXT = 0x02
UI_GRAPHICAL = 0x03
UI_WEB = 0x04
UI_MODES = [UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
UI_MODES = [UI_NONE, UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
def spawn(uimode):
if uimode in UI_MODES:
RNS.log("Starting user interface...", RNS.LOG_INFO)
if uimode == UI_NONE:
RNS.log("Starting Nomad Network daemon...", RNS.LOG_INFO)
else:
RNS.log("Starting user interface...", RNS.LOG_INFO)
if uimode == UI_MENU:
from .MenuUI import MenuUI
return MenuUI()
@ -29,8 +33,11 @@ def spawn(uimode):
elif uimode == UI_WEB:
from .WebUI import WebUI
return WebUI()
elif uimode == UI_NONE:
from .NoneUI import NoneUI
return NoneUI()
else:
return None
else:
RNS.log("Invalid UI mode", RNS.LOG_ERROR)
RNS.log("Invalid UI mode", RNS.LOG_ERROR, _override_destination=True)
nomadnet.panic()

View File

@ -563,7 +563,7 @@ class KnownNodes(urwid.WidgetWrap):
self.pile = urwid.Pile([urwid.Text(("warning_text", g["info"]+"\n"), align="center"), SelectText(("warning_text", "Currently, no nodes are known\n\n"), align="center")])
self.display_widget = urwid.Filler(self.pile, valign="top", height="pack")
urwid.WidgetWrap.__init__(self, urwid.AttrMap(urwid.LineBox(self.display_widget, title="Known Nodes"), widget_style))
urwid.WidgetWrap.__init__(self, urwid.AttrMap(urwid.LineBox(self.display_widget, title="Saved Nodes"), widget_style))
def keypress(self, size, key):
if key == "up" and (self.no_content or self.ilb.first_item_is_selected()):

View File

@ -23,6 +23,6 @@ setuptools.setup(
entry_points= {
'console_scripts': ['nomadnet=nomadnet.nomadnet:main']
},
install_requires=['rns>=0.3.4', 'lxmf>=0.1.4', 'urwid>=2.1.2'],
install_requires=['rns>=0.3.6', 'lxmf>=0.1.6', 'urwid>=2.1.2'],
python_requires='>=3.6',
)