init reticulum before sanic, otherwise sanic threads break global vars

This commit is contained in:
liamcottle 2024-04-29 17:54:39 +12:00
parent 4dac4e1f23
commit e1be1126a8

24
web.py
View file

@ -50,37 +50,29 @@ def main():
print("Reticulum Identity has been randomly generated.")
print(identity)
# run sanic app
app.run(
host=args.host,
port=args.port,
)
def start_reticulum():
# init reticulum
global reticulum
reticulum = RNS.Reticulum(None)
# init lxmf router
global message_router
message_router = LXMF.LXMRouter(identity=identity, storagepath="storage/lxmf")
# register lxmf identity
global local_lxmf_destination
local_lxmf_destination = message_router.register_delivery_identity(identity, display_name="ReticulumWebChat")
# set a callback for when an lxmf message is received
message_router.register_delivery_callback(lxmf_delivery)
# set a callback for when an lxmf announce is received
RNS.Transport.register_announce_handler(LXMFAnnounceHandler(on_lxmf_announce_received))
@app.after_server_start
async def after_server_start(*_):
start_reticulum()
# run sanic app
app.run(
host=args.host,
port=args.port,
)
@app.get("/")