diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/daemon/common/commonSwarming.ml ./src/daemon/common/commonSwarming.ml
--- ./src/daemon/common/commonSwarming.ml	2006-09-14 19:34:34.000000000 +0200
+++ ./src/daemon/common/commonSwarming.ml	2006-11-21 00:14:17.000000000 +0100
@@ -1354,7 +1354,7 @@
 	print_s "VERIFIED" s
     end;
     t.t_verified t.t_nverified_chunks j in
-    if j = 0 && !Autoconf.magic_works then check_magic t.t_file;
+  if j = 0 && !Autoconf.magic_works then check_magic t.t_file;
   match VB.get t.t_converted_verified_bitmap j with
   | VB.State_missing | VB.State_partial ->
       t.t_ncomplete_chunks <- t.t_ncomplete_chunks + 1;
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyGlobals.ml ./src/networks/donkey/donkeyGlobals.ml
--- ./src/networks/donkey/donkeyGlobals.ml	2006-11-20 23:48:43.000000000 +0100
+++ ./src/networks/donkey/donkeyGlobals.ml	2006-11-21 00:40:07.000000000 +0100
@@ -204,7 +204,6 @@
 
 (* let remaining_time_for_clients = ref (60 * 15) *)
 
-let current_files = ref ([] : file list)
 let xs_servers_list = ref ([] : server list)
 let connected_server_list = ref ([]  : server list)
 let connecting_server_list = ref ([] : server list)
@@ -425,8 +424,6 @@
               (if md4s = [] then VerificationNotAvailable else
                 Verification (Array.of_list (List.map (fun md4 -> Ed2k md4) md4s))
             );
-            CommonSwarming.set_verified swarmer (fun nblocks num ->
-                if nblocks = 1 then file_must_update file)
       );
 
       update_best_name file;
@@ -811,7 +808,6 @@
   Printf.bprintf buf "   Disconnected aliases: %d\n" !disconnected_alias;
 
   Printf.bprintf buf "Number of old files: %d\n" (List.length !!old_files);
-  Printf.bprintf buf "Current files: %d\n" (List.length !current_files);
 
   let counter = ref 0 in
   UdpClientWHashtbl.iter (fun _ -> incr counter) udp_clients;
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyInteractive.ml ./src/networks/donkey/donkeyInteractive.ml
--- ./src/networks/donkey/donkeyInteractive.ml	2006-11-20 23:48:43.000000000 +0100
+++ ./src/networks/donkey/donkeyInteractive.ml	2006-11-21 00:46:37.000000000 +0100
@@ -231,6 +231,21 @@
 exception Already_downloading of string
 exception Already_shared of string
 
+let set_verifiers file =
+  match file.file_swarmer with
+  | None -> ()
+  | Some swarmer -> CommonSwarming.set_verified swarmer (fun nblocks num ->
+(* things to do when the file was completed *)
+    if swarmer.CommonSwarming.t_nchunks = nblocks then
+      DonkeyOneFile.declare_completed_file file;
+
+(* things to do when the first chunk (independent of position),
+   was verified, the file can now be shared *)
+    if nblocks = 1 then begin
+      DonkeyShare.must_share_file file;
+      file_must_update file
+    end)
+
 let really_query_download filename size md4 location old_file absents user =
 
   begin
@@ -241,9 +256,9 @@
     with Not_found -> ()
   end;
 
-  List.iter (fun file ->
+  Hashtbl.iter (fun _ file ->
       if file.file_md4 = md4 then raise already_done)
-  !current_files;
+  files_by_md4;
 
   let file_diskname = Filename.concat !!temp_directory
     (file_string_of_uid (Ed2k md4)) in
@@ -270,6 +285,7 @@
 
 (* TODO RESULT  let other_names = DonkeyIndexer.find_names md4 in *)
   let file = new_file file_diskname FileDownloading md4 size filename true user in
+  set_verifiers file;
   begin
     match absents with
       None -> ()
@@ -287,10 +303,6 @@
   DonkeyProtoOvernet.Overnet.recover_file file;
   DonkeyProtoKademlia.Kademlia.recover_file file;
 
-  current_files := file :: !current_files;
-(*  !file_change_hook file; *)
-(*  set_file_size file (file_size file); *)
-
   List.iter (fun s ->
       add_query_location file s
   ) (connected_servers());
@@ -782,7 +794,7 @@
 
         List.iter (fun arg ->
             let num = int_of_string arg in
-            List.iter (fun file ->
+            Hashtbl.iter (fun _ file ->
                 if file_num file = num then begin
                     match file.file_swarmer with
                       None -> ()
@@ -796,7 +808,7 @@
                         (file_best_name file)
 
                   end
-            ) !current_files
+            ) files_by_md4
         ) args;
         ""
     ) , "<f1> < f2> ... :\t\ttry to recover these files at byte level";
@@ -1529,7 +1541,6 @@
       CommonSwarming.remove_swarmer file.file_swarmer;
       file.file_swarmer <- None;
       Hashtbl.remove files_by_md4 file.file_md4;
-      current_files := List2.removeq file !current_files;
       DonkeySources.remove_file_sources_manager file.file_sources;
       if !!keep_cancelled_in_old_files &&
         not (List.mem file.file_md4 !!old_files) then
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyMain.ml ./src/networks/donkey/donkeyMain.ml
--- ./src/networks/donkey/donkeyMain.ml	2006-10-31 16:40:06.000000000 +0100
+++ ./src/networks/donkey/donkeyMain.ml	2006-11-21 00:36:03.000000000 +0100
@@ -84,7 +84,6 @@
 let five_second_timer timer =
   DonkeyServers.check_server_connections ();
   DonkeyServers.walker_timer ();
-  DonkeyOneFile.check_files_downloaded ();
   DonkeyShare.check_shared_files ()
 
 let min_timer timer =
@@ -213,10 +212,7 @@
       
       Hashtbl.iter (fun _ file ->
           try
-            if file_state file <> FileDownloaded then begin (* add not finished files *)
-                current_files := file :: !current_files;
-(*                set_file_size file (file_size file) *)
-              end else begin
+            if file_state file = FileDownloaded then begin
                 try
                   let file_disk_name = file_disk_name file in
                   if Unix32.file_exists file_disk_name &&
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyOneFile.ml ./src/networks/donkey/donkeyOneFile.ml
--- ./src/networks/donkey/donkeyOneFile.ml	2006-10-25 13:12:38.000000000 +0200
+++ ./src/networks/donkey/donkeyOneFile.ml	2006-11-21 00:01:41.000000000 +0100
@@ -141,57 +141,6 @@
           (file_disk_name file) in
       file.file_format <- format
     with _ -> ())
-  
-(** What to do when a file is finished
-  @param file the finished file
-*)         
-let download_finished file = 
-  if List.memq file !current_files then begin      
-      current_files := List2.removeq file !current_files;
-      declare_completed_file file
-    end
-
-(** Check if a file is finished or not.
-  A file is finished if all blocks are verified.
-  @param file The file to check status
-*)
-let check_file_downloaded file = 
-  match file_state file with
-    FileCancelled | FileShared | FileDownloaded -> ()
-  | _ ->
-      match file.file_swarmer with
-        None -> ()
-      | Some swarmer ->
-          let bitmap = CommonSwarming.chunks_verified_bitmap swarmer in
-(*          lprintf "Verified bitmap: [%s]\n" bitmap; *)
-	  let verified = VB.for_all (( = ) VB.State_verified) bitmap in
-          
-          let downloaded = CommonSwarming.downloaded swarmer in
-          if file_downloaded file <> downloaded then begin
-              lprintf_nl "ERROR: file_downloaded file (%Ld) <> downloaded swarmer (%Ld)"
-                (file_downloaded file) downloaded
-            end;
-          
-          if verified then begin
-              if (file_size file <> downloaded)
-              then
-                lprintf_nl "Downloaded size differs after complete verification";
-              download_finished file
-            end
-            
-let check_files_downloaded () =
-  List.iter check_file_downloaded !current_files;
-  Hashtbl.iter (fun file_md4 file ->
-      match file.file_shared with 
-        Some _ -> ()
-      | None ->
-          match file.file_swarmer with
-            None -> ()
-          | Some swarmer ->
-              let bitmap = CommonSwarming.chunks_verified_bitmap swarmer in
-	      if VB.existsi (fun _ s -> s = VB.State_verified) bitmap then
-                DonkeyShare.must_share_file file
-  ) files_by_md4
 
 let add_client_chunks c file client_chunks =
   match file.file_swarmer with
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyOneFile.mli ./src/networks/donkey/donkeyOneFile.mli
--- ./src/networks/donkey/donkeyOneFile.mli	2005-11-12 12:20:21.000000000 +0100
+++ ./src/networks/donkey/donkeyOneFile.mli	2006-11-21 00:03:25.000000000 +0100
@@ -23,7 +23,6 @@
 val clean_current_download : DonkeyTypes.client -> unit
 val get_from_client : DonkeyTypes.client -> unit
 val request_slot : DonkeyTypes.client -> unit
-val check_files_downloaded : unit -> unit
   val block_received :
     DonkeyTypes.client -> Md4.t -> int64 -> string -> int -> int -> unit
 val add_client_chunks : DonkeyTypes.client -> DonkeyTypes.file -> Bitv.t -> unit
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyOvernet.ml ./src/networks/donkey/donkeyOvernet.ml
--- ./src/networks/donkey/donkeyOvernet.ml	2006-11-14 17:35:53.000000000 +0100
+++ ./src/networks/donkey/donkeyOvernet.ml	2006-11-21 00:30:00.000000000 +0100
@@ -1327,7 +1327,7 @@
     ignore (create_search (FileSearch file) file.file_md4)
 
 let check_current_downloads () =
-  List.iter recover_file !DonkeyGlobals.current_files
+  Hashtbl.iter (fun _ f -> recover_file f) DonkeyGlobals.files_by_md4
 
 let update_buckets () =
 
diff -a -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x '*.cmi' -x '*.cma' -x '*.cmo' -x '*.cmx' -x '*.cmxa' -x '*.a' -x '*.o' -x .depend -x Makefile -x mlnet -x ocamlpp.byte -N -r -u ./src/networks/donkey/donkeyServers.ml ./src/networks/donkey/donkeyServers.ml
--- ./src/networks/donkey/donkeyServers.ml	2006-11-20 00:02:18.000000000 +0100
+++ ./src/networks/donkey/donkeyServers.ml	2006-11-21 00:28:49.000000000 +0100
@@ -68,16 +68,17 @@
 
 
 let fill_query_queue server =
-  let downloading = List.filter ( fun f ->
-    file_state f = FileDownloading
-  ) !current_files in
+  let downloading = ref [] in
+  Hashtbl.iter (fun _ f ->
+    if file_state f = FileDownloading then
+      downloading := f :: !downloading) files_by_md4;
 
   (* shuffle list so we don't ask all Servers for the same file at once *)
   let rand_prio = List.map (fun f ->
     file_priority f + Random.int 100
-  ) downloading in
+  ) !downloading in
 
-  let joined = List.combine downloading rand_prio in
+  let joined = List.combine !downloading rand_prio in
   let queries, _ = List.split (
     List.sort (
       fun (_,p1) (_,p2) -> p2 - p1
