Просмотр исходного кода

dnet+lilith: enable hostlist debugging

display lilith's whitelist, greylist and anchorlist in dnet
draoi 2 лет назад
Родитель
Сommit
716af31848
4 измененных файлов с 65 добавлено и 8 удалено
  1. 8 2
      bin/dnet/src/model.py
  2. 24 4
      bin/dnet/src/view.py
  3. 23 2
      bin/lilith/src/main.rs
  4. 10 0
      src/net/hosts/store.rs

+ 8 - 2
bin/dnet/src/model.py

@@ -153,6 +153,7 @@ class Model:
 
 
     def add_lilith(self, lilith):
+        logging.debug(f'adding lilith {lilith}')
         key = list(lilith.keys())[0]
         values = list(lilith.values())[0]
         info = values['result']
@@ -164,10 +165,15 @@ class Model:
         for (i, spawn) in enumerate(spawns):
             name = spawn['name']
             urls = spawn['urls']
-            hosts = spawn['hosts']
+            whitelist = spawn['whitelist']
+            greylist = spawn['greylist']
+            anchorlist = spawn['greylist']
+
             spawn = self.liliths[key]['spawns'][name] = {}
             spawn['urls'] = urls
-            spawn['hosts'] = hosts
+            spawn['whitelist'] = whitelist
+            spawn['greylist'] = greylist
+            spawn['anchorlist'] = anchorlist
 
     def __repr__(self):
         return f'{self.nodes}'

+ 24 - 4
bin/dnet/src/view.py

@@ -209,12 +209,32 @@ class View():
                         f"  {url}"),
                         self.pile.options()))
 
-            if info['hosts']:
-                hosts = info['hosts']
+            if info['whitelist']:
+                whitelist = info['whitelist']
                 self.pile.contents.append((urwid.Text(
-                    f"Hosts:"),
+                    f"Whitelist:"),
                     self.pile.options()))
-                for host in hosts:
+                for host in whitelist:
+                    self.pile.contents.append((urwid.Text(
+                        f"  {host}"),
+                        self.pile.options()))
+
+            if info['greylist']:
+                greylist = info['greylist']
+                self.pile.contents.append((urwid.Text(
+                    f"Greylist:"),
+                    self.pile.options()))
+                for host in greylist:
+                    self.pile.contents.append((urwid.Text(
+                        f"  {host}"),
+                        self.pile.options()))
+
+            if info['anchorlist']:
+                anchorlist = info['anchorlist']
+                self.pile.contents.append((urwid.Text(
+                    f"Anchorlist:"),
+                    self.pile.options()))
+                for host in anchorlist:
                     self.pile.contents.append((urwid.Text(
                         f"  {host}"),
                         self.pile.options()))

+ 23 - 2
bin/lilith/src/main.rs

@@ -85,7 +85,7 @@ struct Spawn {
 }
 
 impl Spawn {
-    async fn addresses(&self) -> Vec<JsonValue> {
+    async fn get_whitelist(&self) -> Vec<JsonValue> {
         self.p2p
             .hosts()
             .whitelist_fetch_all()
@@ -95,6 +95,25 @@ impl Spawn {
             .collect()
     }
 
+    async fn get_greylist(&self) -> Vec<JsonValue> {
+        self.p2p
+            .hosts()
+            .greylist_fetch_all()
+            .await
+            .iter()
+            .map(|(addr, _url)| JsonValue::String(addr.to_string()))
+            .collect()
+    }
+
+    async fn get_anchorlist(&self) -> Vec<JsonValue> {
+        self.p2p
+            .hosts()
+            .anchorlist_fetch_all()
+            .await
+            .iter()
+            .map(|(addr, _url)| JsonValue::String(addr.to_string()))
+            .collect()
+    }
     async fn info(&self) -> JsonValue {
         let mut addr_vec = vec![];
         for addr in &self.p2p.settings().inbound_addrs {
@@ -104,7 +123,9 @@ impl Spawn {
         JsonValue::Object(HashMap::from([
             ("name".to_string(), JsonValue::String(self.name.clone())),
             ("urls".to_string(), JsonValue::Array(addr_vec)),
-            ("hosts".to_string(), JsonValue::Array(self.addresses().await)),
+            ("whitelist".to_string(), JsonValue::Array(self.get_whitelist().await)),
+            ("greylist".to_string(), JsonValue::Array(self.get_greylist().await)),
+            ("anchorlist".to_string(), JsonValue::Array(self.get_anchorlist().await)),
         ]))
     }
 }

+ 10 - 0
src/net/hosts/store.rs

@@ -769,6 +769,16 @@ impl Hosts {
         self.whitelist.read().await.iter().cloned().collect()
     }
 
+    /// Return all known greylisted hosts
+    pub async fn greylist_fetch_all(&self) -> Vec<(Url, u64)> {
+        self.greylist.read().await.iter().cloned().collect()
+    }
+
+    /// Return all known anchorlisted hosts
+    pub async fn anchorlist_fetch_all(&self) -> Vec<(Url, u64)> {
+        self.anchorlist.read().await.iter().cloned().collect()
+    }
+
     /// Return all greylist and anchorlist hosts. Called on stop().
     /// Note: we do not return whitelist entries here since whitelist entries must go via the
     /// greylist refinery in the lifetime of the p2p network.