Index: src/networks/donkey/donkeyFiles.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyFiles.ml,v
retrieving revision 1.16
diff -u -r1.16 donkeyFiles.ml
--- src/networks/donkey/donkeyFiles.ml	7 Nov 2005 20:11:42 -0000	1.16
+++ src/networks/donkey/donkeyFiles.ml	17 Dec 2005 14:08:39 -0000
@@ -81,7 +81,7 @@
 (*      let len_int = Int32.to_int len in *)
       try
         if !verbose then begin
-            lprintf "send_small_block(%s-%s) %Ld %d\n"
+            lprintf "send_small_block(%s-%s) %Ld %d "
               c.client_name (brand_to_string c.client_brand)
             (begin_pos) (len_int);
           end;
@@ -114,9 +114,9 @@
               impl.impl_shared_uploaded <- 
                 impl.impl_shared_uploaded ++ uploaded);
         if c.client_connected then
-          printf_string "U[OUT]"
+          printf_string "U[OUT]\n"
         else
-          printf_string "U[IN]";
+          printf_string "U[IN]\n";
         
         write_string sock upload_buffer;
         check_end_upload c sock
Index: src/networks/donkey/donkeyOvernet.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyOvernet.ml,v
retrieving revision 1.60
diff -u -r1.60 donkeyOvernet.ml
--- src/networks/donkey/donkeyOvernet.ml	14 Dec 2005 21:17:46 -0000	1.60
+++ src/networks/donkey/donkeyOvernet.ml	17 Dec 2005 14:08:40 -0000
@@ -301,6 +301,8 @@
       val overnet_tcpport : int Options.option_record
       val overnet_section : Options.options_section
 
+      val checking_kind_timeout : int
+
       val redirector_section : string
       val options_section_name : string
       val command_prefix : string
@@ -333,7 +335,7 @@
 let max_peers_per_bucket = 20
 let max_peers_per_prebucket = 40
 (* how many peers a search may ask for more search peers *)
-let max_search_queries = 64 
+let max_search_queries = 50 
 (* how many peers we ask for results *)
 let max_search_requests = 20 
 let max_boot_peers = 200
@@ -428,7 +430,7 @@
     peer_kind = 0;
     peer_expire = 0;
     peer_last_send = 0;
-    peer_created = last_time ();
+    peer_created = 0;
   }
 
 let connected_peers = ref 0
@@ -716,7 +718,7 @@
   if (last_time () - p.peer_last_send) < 10 ||
      p.peer_kind = 4 then () else begin
     p.peer_kind <- p.peer_kind + 1;
-    p.peer_expire <- last_time () + 120;
+    p.peer_expire <- last_time () + Proto.checking_kind_timeout;
   end;
   ()
   
@@ -761,14 +763,15 @@
   let ip = p.peer_ip in
   let port = p.peer_port in
  
-  if ip <> Ip.localhost && is_overnet_ip ip && port <> 0 then
-
     try
       let pp = KnownPeers.find known_peers p in
       (* TODO: check for changes in ip:port? Or Hash? *)
       pp
     with _ ->
-    
+
+   if ip <> Ip.localhost && is_overnet_ip ip 
+     && port <> 0 && p.peer_created <> 0 then
+   
         let bucket = bucket_number p.peer_md4 in
 
 (* Add the peer to the table of known peers *)
@@ -909,7 +912,7 @@
 
 let add_search_peer s p =
   if p.peer_ip <> Ip.localhost && is_overnet_ip p.peer_ip && 
-     p.peer_port <> 0 then begin
+     p.peer_port <> 0 && p.peer_created <> 0 then begin
     let nbits = common_bits p.peer_md4 s.search_md4 in
     begin
       try
@@ -925,7 +928,8 @@
 
 let create_search kind md4 =
   if !verbose_overnet then lprintf_nl () "create_search";
-  let s = {
+  let starttime = last_time () + (2 * List.length !overnet_searches) in
+  let s = ref {
       search_md4 = md4;
       search_kind = kind;
       search_queries = 0;
@@ -933,17 +937,28 @@
       search_waiting_peers = Array.init 129 (fun _ -> Fifo.create ());
       search_asked_peers = Array.init 129 (fun _ -> Fifo.create ());
       search_ok_peers = Array.init 129 (fun _ -> Fifo.create ());
-      search_start = last_time ();
-      search_last_query = last_time () + 
-        ((List.length !overnet_searches) mod (int_of_float !!overnet_query_peer_period));
+      search_start = (match kind with
+                       KeywordSearch s -> last_time ()
+                     | FillBuckets -> last_time ()
+                     | FileSearch s -> starttime);
+      search_last_query = (match kind with
+                       KeywordSearch s -> last_time ()
+                     | FillBuckets -> last_time ()
+                     | FileSearch s -> starttime);
       search_hits = 0;
       search_nresults = 0;
-      search_results = Hashtbl.create 13;
+      search_results = Hashtbl.create 64;
     } in
-  List.iter (add_search_peer s) (get_closest_peers md4 max_search_queries);
+  List.iter (fun ss ->
+    if ss.search_md4 = !s.search_md4 && ss.search_kind = !s.search_kind then begin
+     ss.search_start <- !s.search_start;
+     s := ss;
+    end
+  ) !overnet_searches;
+  List.iter (add_search_peer !s) (get_closest_peers md4 max_search_queries);
   if !verbose_overnet then lprintf_nl () "create_search done";
-  overnet_searches := s :: !overnet_searches;
-  s
+  overnet_searches := !s :: !overnet_searches;
+  !s
 
 let create_keyword_search w s =
   let md4 = Md4.string w in
@@ -976,7 +991,8 @@
 
   | OvernetConnect p ->
       if is_overnet_ip sender.peer_ip && sender.peer_port <> 0 then
-        let sender = new_peer { p with peer_port = other_port ; peer_ip = other_ip } in
+        let sender = new_peer { p with peer_ip = other_ip } in
+        (* let sender = new_peer { p with peer_port = other_port ; peer_ip = other_ip } in *)
         new_peer_message sender;
         udp_send sender (OvernetConnectReply (get_any_peers 20))
        else
@@ -993,7 +1009,7 @@
         match list with
           [] -> ()
         | [p] ->
-            let sender = new_peer { p with peer_port = other_port ; peer_ip = other_ip } in
+            let sender = new_peer { p with peer_ip = other_ip } in
             new_peer_message sender
         | p :: tail ->
             let _ = new_peer p in
@@ -1002,7 +1018,7 @@
       iter ps;
 
   | OvernetPublicize p ->
-      let sender = new_peer { p with peer_port = other_port ; peer_ip = other_ip } in
+      let sender = new_peer { p with peer_ip = other_ip } in
       new_peer_message sender;
       if is_overnet_ip sender.peer_ip && sender.peer_port <> 0 then
         udp_send sender (OvernetPublicized (Some (my_peer ())))
@@ -1168,6 +1184,7 @@
                 if p.peer_ip = peer.peer_ip && 
                     p.peer_port = peer.peer_port then begin
                   decr pre_connected_peers;
+                  KnownPeers.remove known_peers dp;
                 end else Fifo.put b p
               done;
             done;
@@ -1219,7 +1236,11 @@
       if s.search_last_query < timeout then begin
         s.search_last_query <- s.search_last_query + overnet_query_peer_period;
 (* Query next search peers *)
-        iter 128 2;
+        if s.search_queries < max_search_queries then
+          (if s.search_queries = 0 then
+            iter 128 3
+          else
+            iter 128 2);
 (* Request next results *)
         if s.search_requests < max_search_requests then begin
            let nrequests =
@@ -1275,6 +1296,7 @@
       else
       begin
         decr connected_peers;
+        KnownPeers.remove known_peers p;
         if !verbose_overnet then lprintf_nl () "update_bucket1: removing %s:%d" (Ip.to_string p.peer_ip) p.peer_port;
       end;
     done
@@ -1301,6 +1323,7 @@
             (* bad peers are removed *)    
             end else if p.peer_kind = 4 && p.peer_expire <= last_time () then begin
               decr pre_connected_peers;
+              KnownPeers.remove known_peers p;
               if !verbose_overnet then lprintf_nl () "update_bucket2: removing %s:%d" (Ip.to_string p.peer_ip) p.peer_port;
             end else
             (* the rest returns in prebuckets *)
@@ -1435,8 +1458,8 @@
 
           compute_to_ping ();
 
-          let l = last_time () - 300 in
-(* remove searches that are older than 5 minutes *)
+          let l = last_time () - 180 in
+(* remove searches that are older than 3 minutes *)
           overnet_searches := List.filter (fun s ->
               s.search_requests < max_search_requests &&
               s.search_start > l
Index: src/networks/donkey/donkeyOvernet.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyOvernet.mli,v
retrieving revision 1.6
diff -u -r1.6 donkeyOvernet.mli
--- src/networks/donkey/donkeyOvernet.mli	31 Oct 2005 18:07:11 -0000	1.6
+++ src/networks/donkey/donkeyOvernet.mli	17 Dec 2005 14:08:40 -0000
@@ -107,7 +107,9 @@
       val overnet_port : int Options.option_record
       val overnet_tcpport : int Options.option_record
       val overnet_section : Options.options_section
-      
+
+      val checking_kind_timeout : int
+
       val redirector_section : string
       val options_section_name : string
       val command_prefix : string
Index: src/networks/donkey/donkeyProtoKademlia.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyProtoKademlia.ml,v
retrieving revision 1.17
diff -u -r1.17 donkeyProtoKademlia.ml
--- src/networks/donkey/donkeyProtoKademlia.ml	15 Dec 2005 19:41:46 -0000	1.17
+++ src/networks/donkey/donkeyProtoKademlia.ml	17 Dec 2005 14:08:40 -0000
@@ -482,6 +482,8 @@
           );
       | _ -> ()
 
+    let checking_kind_timeout = 120
+
     let redirector_section = "DKKA"
     let options_section_name = "Kademlia"
 
Index: src/networks/donkey/donkeyProtoKademlia.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyProtoKademlia.mli,v
retrieving revision 1.2
diff -u -r1.2 donkeyProtoKademlia.mli
--- src/networks/donkey/donkeyProtoKademlia.mli	5 Aug 2004 15:52:12 -0000	1.2
+++ src/networks/donkey/donkeyProtoKademlia.mli	17 Dec 2005 14:08:40 -0000
@@ -17,29 +17,6 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)
 
-(*
-module P :
-  sig
-    val write : Buffer.t -> DonkeyOvernet.t -> unit
-    val udp_buf : Buffer.t
-    val kademlia_header_code : char
-    val kademlia_packed_header_code : char
-    val kademlia_header : string
-    val kademlia_packed_header : string
-    val udp_send : UdpSocket.t -> Ip.t -> int -> DonkeyOvernet.t -> unit
-    val parse : 'a -> 'b
-    val udp_handler :
-      ('a -> UdpSocket.udp_packet -> unit) ->
-      UdpSocket.t -> UdpSocket.event -> unit
-    val redirector_section : string
-    val options_section_name : string
-    val enable_overnet : bool Options.option_record
-    val overnet_section : Options.options_section
-    val overnet_port : int Options.option_record
-    val overnet_tcpport : int Options.option_record
-    val command_prefix : string
-  end
-  *)
 module Kademlia :
   sig
     val overnet_search : CommonTypes.search -> unit
Index: src/networks/donkey/donkeyProtoOvernet.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyProtoOvernet.ml,v
retrieving revision 1.25
diff -u -r1.25 donkeyProtoOvernet.ml
--- src/networks/donkey/donkeyProtoOvernet.ml	15 Dec 2005 19:41:46 -0000	1.25
+++ src/networks/donkey/donkeyProtoOvernet.ml	17 Dec 2005 14:08:40 -0000
@@ -411,6 +411,8 @@
           );
       | _ -> ()
 
+    let checking_kind_timeout = 180
+
     let redirector_section = "DKKO"
     let options_section_name = overnet_options_section_name
     let overnet_section = overnet_section
