Skip to content

Commit 321c152

Browse files
ui,nodes: improved adding nodes to the db
When a node connected to the gui for the first time, we were not updating the db accordingly. We were doing it when populating the stats or adding events. Unfortunately, not all fields are available when a node subscribes to the GUI, they're sent when the node posts new events. Because of this, some fields may appear blank until the node send new events. It'll be fixed in future releases.
1 parent 74a7cb8 commit 321c152

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ui/opensnitch/nodes.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def add(self, _peer, client_config=None):
5353

5454
self._nodes[peer]['online'] = True
5555
self.add_data(peer, client_config)
56-
self.update(peer)
56+
self.insert(peer)
5757

5858
self.nodesUpdated.emit(self.count())
5959

@@ -373,6 +373,22 @@ def stop_notifications(self, addr=None):
373373
return
374374
self.send_notifications(exit_ntf)
375375

376+
def insert(self, peer, status=ONLINE):
377+
try:
378+
proto, addr = self.get_addr(peer)
379+
naddr = "{0}:{1}".format(proto, addr)
380+
print(self._nodes[naddr]['data'])
381+
self._db.insert(
382+
"nodes",
383+
"(addr, status, hostname, daemon_version, daemon_uptime, " \
384+
"daemon_rules, cons, cons_dropped, version, last_connection)",
385+
(naddr, status, self._nodes[naddr]['data'].name, "", self._nodes[naddr]['last_seen'],
386+
0, 0, 0,
387+
self._nodes[naddr]['data'].version, datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
388+
)
389+
except Exception as e:
390+
print(self.LOG_TAG + " exception adding the DB: ", e, peer)
391+
376392
def update(self, peer, status=ONLINE):
377393
try:
378394
proto, addr = self.get_addr(peer)

0 commit comments

Comments
 (0)