Forráskód Böngészése

bin/dnet: dnet improvements

- fix dnet crash when the analyzed service is shutdown
- add default config for darkfid and fud
- send dnet switch off rpc message when dnet tui is closed
oars 1 éve
szülő
commit
07d2b1a630
3 módosított fájl, 54 hozzáadás és 17 törlés
  1. 15 5
      bin/dnet/dnet
  2. 34 10
      bin/dnet/dnet_config.toml
  3. 5 2
      bin/dnet/src/view.py

+ 15 - 5
bin/dnet/dnet

@@ -43,6 +43,7 @@ class Dnetview:
 
         self.model = Model()
         self.view = View(self.model)
+        self.rpc_conns = []
 
     async def subscribe(self, rpc, node):
         name = node['name']
@@ -68,8 +69,6 @@ class Dnetview:
                     await self.connect_loop(rpc, node, info)
                     await self.get_info(rpc, node, info)
 
-            await rpc.dnet_switch(False)
-    
         if type == 'LILITH':
             while True:
                 await asyncio.sleep(1)
@@ -79,8 +78,6 @@ class Dnetview:
                     logging.debug(f'{name} RPC on port {port} disconnected {e}')
                     await self.connect_loop(rpc, node, info)
 
-        await rpc.stop()
-
     async def lilith_spawns(self, rpc, node, info):
         name = node['name']
         host = node['host']
@@ -133,6 +130,7 @@ class Dnetview:
         async with asyncio.TaskGroup() as tg:
             for i, node in enumerate(nodes):
                 rpc = JsonRpc()
+                self.rpc_conns.append(rpc)
                 subscribe = tg.create_task(self.subscribe(
                             rpc, node))
                 nodes = tg.create_task(self.update_info())
@@ -189,7 +187,11 @@ class Dnetview:
         self.ev.create_task(self.start_connect_slots(nodes))
         self.ev.create_task(self.view.update_view(self.ev, loop))
 
-        loop.run()
+        try:
+            loop.run()
+        finally:
+            self.ev.run_until_complete(self.shutdown())
+
 
     def unhandled_input(self, key):
         if isinstance(key, tuple):
@@ -199,6 +201,14 @@ class Dnetview:
                 task.cancel()
             raise urwid.ExitMainLoop()
 
+    async def shutdown(self):
+        for rpc in self.rpc_conns:
+            try:
+                await rpc.dnet_switch(False)
+                await rpc.stop()
+            except:
+                pass
+
 if __name__ == '__main__':
     dnet = Dnetview()
     dnet.main()

+ 34 - 10
bin/dnet/dnet_config.toml

@@ -1,14 +1,38 @@
-[[nodes]]
-name = "darkirc"
-host = "localhost"
-port = 26660
-type = "NORMAL"
+#[[nodes]]
+#name = "darkirc"
+#host = "localhost"
+#port = 26660
+#type = "NORMAL"
+
+#[[nodes]]
+#name = "taud"
+#host = "localhost"
+#port = 23330
+#type = "NORMAL"
+
+#[[nodes]]
+#name = "fud"
+#host = "localhost"
+#port = 13336
+#type = "NORMAL"
 
-[[nodes]]
-name = "taud"
-host = "localhost"
-port = 23330
-type = "NORMAL"
+#[[nodes]]
+#name = "darkfid-testnet"
+#host = "localhost"
+#port = 8340
+#type = "NORMAL"
+
+#[[nodes]]
+#name = "darkfid-mainnet"
+#host = "localhost"
+#port = 8440
+#type = "NORMAL"
+
+#[[nodes]]
+#name = "darkfid-localnet"
+#host = "localhost"
+#port = 8240
+#type = "NORMAL"
 
 #[[nodes]]
 #name = "evgrd"

+ 5 - 2
bin/dnet/src/view.py

@@ -203,7 +203,7 @@ class View():
             case "outbound":
                 key = (focus_w[0].name, "outbound")
                 info = self.model.nodes.get(focus_w[0].name)
-                if key in info['event']:
+                if info and key in info['event']:
                     ev = info['event'].get(key)
                     self.pile.contents.append((
                         urwid.Text(f" {ev}"),
@@ -214,7 +214,7 @@ class View():
                 name = focus_w[0].name
                 info = self.model.nodes.get(name)
 
-                if addr in info['msgs']:
+                if info and addr in info['msgs']:
                     msg = info['msgs'].get(addr)
                     for m in msg:
                         time = m[0]
@@ -228,6 +228,9 @@ class View():
                 spawn_name = focus_w[0].id
                 lilith = self.model.liliths.get(name)
                 spawns = lilith.get('spawns')
+                if spawns is None:
+                    return
+
                 info = spawns.get(spawn_name)
 
                 if info['urls']: