mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
dnet: cleanup and add TODOs
This commit is contained in:
@@ -18,6 +18,14 @@
|
||||
import logging, time
|
||||
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# TODO:
|
||||
# * on first get_info call, initialize data structure
|
||||
# * use channel id as key
|
||||
# * e.g. outbound[id] = [info1, info2, ...]
|
||||
# * create unique null id if not connected
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
class Model:
|
||||
|
||||
def __init__(self):
|
||||
@@ -75,45 +83,51 @@ class Model:
|
||||
event = params[0].get("event")
|
||||
info = params[0].get("info")
|
||||
|
||||
if "chan" in info:
|
||||
t = info.get("time")
|
||||
cmd = info.get("cmd")
|
||||
chan = info.get("chan")
|
||||
addr = chan.get("addr")
|
||||
t = time.localtime()
|
||||
current_time = time.strftime("%H:%M:%S", t)
|
||||
|
||||
self.info.update_msg(addr, (t, event, cmd))
|
||||
else:
|
||||
t = time.localtime()
|
||||
current_time = time.strftime("%H:%M:%S", t)
|
||||
logging.debug(current_time)
|
||||
|
||||
match event:
|
||||
case "inbound_connected":
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} inbound (connect): {addr}")
|
||||
case "inbound_disconnected":
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} inbound (disconnect): {addr}")
|
||||
case "outbound_slot_sleeping":
|
||||
slot = info["slot"]
|
||||
logging.debug(f"{current_time} slot {slot}: sleeping")
|
||||
case "outbound_slot_connecting":
|
||||
slot = info["slot"]
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} slot {slot}: connecting addr={addr}")
|
||||
case "outbound_slot_connected":
|
||||
slot = info["slot"]
|
||||
addr = info["addr"]
|
||||
channel_id = info["channel_id"]
|
||||
logging.debug(f"{current_time} slot {slot}: connected addr={addr}")
|
||||
case "outbound_slot_disconnected":
|
||||
slot = info["slot"]
|
||||
err = info["err"]
|
||||
logging.debug(f"{current_time} slot {slot}: disconnected err='{err}'")
|
||||
case "outbound_peer_discovery":
|
||||
attempt = info["attempt"]
|
||||
state = info["state"]
|
||||
logging.debug(f"{current_time} peer_discovery: {state} (attempt {attempt})")
|
||||
match event:
|
||||
case "send_msg":
|
||||
t = info.get("time")
|
||||
cmd = info.get("cmd")
|
||||
chan = info.get("chan")
|
||||
addr = info.get("addr")
|
||||
logging.debug(f"{t} {addr} {event} {cmd}")
|
||||
self.info.update_msg(addr, (t, event, cmd))
|
||||
case "recv_msg":
|
||||
t = info.get("time")
|
||||
cmd = info.get("cmd")
|
||||
chan = info.get("chan")
|
||||
addr = info.get("addr")
|
||||
logging.debug(f"{t} {addr} {event} {cmd}")
|
||||
self.info.update_msg(addr, (t, event, cmd))
|
||||
case "inbound_connected":
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} inbound (connect): {addr}")
|
||||
case "inbound_disconnected":
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} inbound (disconnect): {addr}")
|
||||
case "outbound_slot_sleeping":
|
||||
slot = info["slot"]
|
||||
logging.debug(f"{current_time} slot {slot}: sleeping")
|
||||
self.info.append_outbound(str(slot), "sleeping")
|
||||
case "outbound_slot_connecting":
|
||||
slot = info["slot"]
|
||||
addr = info["addr"]
|
||||
logging.debug(f"{current_time} slot {slot}: connecting addr={addr}")
|
||||
case "outbound_slot_connected":
|
||||
slot = info["slot"]
|
||||
addr = info["addr"]
|
||||
channel_id = info["channel_id"]
|
||||
logging.debug(f"{current_time} slot {slot}: connected addr={addr}")
|
||||
case "outbound_slot_disconnected":
|
||||
slot = info["slot"]
|
||||
err = info["err"]
|
||||
logging.debug(f"{current_time} slot {slot}: disconnected")
|
||||
case "outbound_peer_discovery":
|
||||
attempt = info["attempt"]
|
||||
state = info["state"]
|
||||
logging.debug(f"{current_time} peer_discovery: {state} (attempt {attempt})")
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.nodes}"
|
||||
@@ -129,7 +143,7 @@ class Info:
|
||||
self.msgs = {}
|
||||
|
||||
def update_outbound(self, key, value):
|
||||
self.outbounds[key] = value
|
||||
self.outbounds[key] = [value]
|
||||
|
||||
def update_inbound(self, key, value):
|
||||
self.inbound[key] = value
|
||||
@@ -146,6 +160,10 @@ class Info:
|
||||
else:
|
||||
self.msgs[key] = [value]
|
||||
|
||||
def append_outbound(self, key, value):
|
||||
if value not in self.outbounds[key]:
|
||||
self.outbounds[key].append(value)
|
||||
|
||||
def __repr__(self):
|
||||
return (f"outbound: {self.outbounds}"
|
||||
f"inbound: {self.inbound}"
|
||||
|
||||
@@ -23,6 +23,15 @@ import datetime as dt
|
||||
from scroll import ScrollBar, Scrollable
|
||||
from model import Model
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# TODO:
|
||||
# * create a dictionary that stores:
|
||||
# * channel[id] = index
|
||||
# * index = listwalker.contents[i]
|
||||
# * sort data by ID, constantly update listwalker_contents[i]
|
||||
# * if it's a null id, render empty info
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
event_loop = asyncio.get_event_loop()
|
||||
|
||||
|
||||
@@ -148,13 +157,21 @@ class View():
|
||||
names.append(name)
|
||||
|
||||
for name, values in self.model.nodes.items():
|
||||
# Update events
|
||||
if name in names:
|
||||
continue
|
||||
for key, value in values.outbounds.items():
|
||||
if len(value) == 1:
|
||||
continue
|
||||
else:
|
||||
slot = SlotView(f" {key}: {str(value[1])}")
|
||||
self.listwalker.contents[int(key)] = widget
|
||||
# Update get_info()
|
||||
else:
|
||||
widget = NodeView(name)
|
||||
self.listwalker.contents.append(widget)
|
||||
|
||||
outbounds = values.outbounds
|
||||
logging.debug("outbounds", outbounds)
|
||||
inbound = values.inbound
|
||||
manual = values.manual
|
||||
seed = values.seed
|
||||
@@ -162,8 +179,8 @@ class View():
|
||||
if len(outbounds) != 0:
|
||||
widget = ConnectView(" outbound")
|
||||
self.listwalker.contents.append(widget)
|
||||
for num, name in outbounds.items():
|
||||
widget = SlotView(f" {num}: {name}")
|
||||
for num, info in outbounds.items():
|
||||
widget = SlotView(f" {num}: {info[0]}")
|
||||
self.listwalker.contents.append(widget)
|
||||
|
||||
if len(inbound) != 0:
|
||||
|
||||
Reference in New Issue
Block a user