Procházet zdrojové kódy

fud: fix `add_to_router`, add `file_hash` to MissingChunks

darkfi před 1 rokem
rodič
revize
011b80e071
2 změnil soubory, kde provedl 15 přidání a 4 odebrání
  1. 1 0
      bin/fud/fud/src/dht.rs
  2. 14 4
      bin/fud/fud/src/rpc.rs

+ 1 - 0
bin/fud/fud/src/dht.rs

@@ -534,6 +534,7 @@ pub trait DhtHandler {
 
         // Add to router
         if let Some(k) = key_r {
+            k.retain(|it| !router_items.contains(it));
             k.extend(router_items.clone());
         } else {
             let mut hs = HashSet::new();

+ 14 - 4
bin/fud/fud/src/rpc.rs

@@ -299,7 +299,9 @@ pub struct FileNotFound {
     pub file_hash: blake3::Hash,
 }
 #[derive(Clone, Debug)]
-pub struct MissingChunks {}
+pub struct MissingChunks {
+    pub file_hash: blake3::Hash,
+}
 #[derive(Clone, Debug)]
 pub struct DownloadError {
     pub file_hash: blake3::Hash,
@@ -363,6 +365,13 @@ impl From<FileNotFound> for JsonValue {
         json_map([("file_hash", JsonValue::String(hash_to_string(&info.file_hash)))])
     }
 }
+impl From<MissingChunks> for JsonValue {
+    fn from(info: MissingChunks) -> JsonValue {
+        json_map([
+            ("file_hash", JsonValue::String(hash_to_string(&info.file_hash))),
+        ])
+    }
+}
 impl From<DownloadError> for JsonValue {
     fn from(info: DownloadError) -> JsonValue {
         json_map([
@@ -392,7 +401,7 @@ impl From<FudEvent> for JsonValue {
             FudEvent::FileNotFound(info) => {
                 json_map([("event", json_str("file_not_found")), ("info", info.into())])
             }
-            FudEvent::MissingChunks(_) => json_map([("event", json_str("missing_chunks"))]),
+            FudEvent::MissingChunks(info) => json_map([("event", json_str("missing_chunks")), ("info", info.into())]),
             FudEvent::DownloadError(info) => {
                 json_map([("event", json_str("download_error")), ("info", info.into())])
             }
@@ -498,8 +507,9 @@ impl Fud {
         // We fetched all chunks, but the file is not complete
         // (some chunks were missing from all seeders)
         if !chunked_file.is_complete() {
-            self.download_publisher.notify(FudEvent::MissingChunks(MissingChunks {})).await;
-            return;
+            self.download_publisher.notify(FudEvent::MissingChunks(MissingChunks {
+                file_hash: *file_hash,
+            })).await;
         }
 
         match self.geode.assemble_file(file_hash, &chunked_file, file_path).await {