Index: src/daemon/common/commonGlobals.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonGlobals.ml,v
retrieving revision 1.88
diff -u -r1.88 commonGlobals.ml
--- src/daemon/common/commonGlobals.ml	20 Oct 2007 20:02:13 -0000	1.88
+++ src/daemon/common/commonGlobals.ml	14 Dec 2007 19:06:00 -0000
@@ -183,6 +183,9 @@
 let connection_was_tried cc =
   cc.control_last_try > 0
 
+let connection_retries cc =
+  cc.control_state
+
 let print_control c =
   lprintf_nl "Connection Control: ok = %d seconds ago, state = %d, last tried = %d seconds ago, delay = %d, next in %d seconds"
     (last_time () - c.control_last_ok) c.control_state (last_time () - c.control_last_try) c.control_min_reask (connection_next_try c - last_time ())
Index: src/networks/bittorrent/bTClients.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTClients.ml,v
retrieving revision 1.97
diff -u -r1.97 bTClients.ml
--- src/networks/bittorrent/bTClients.ml	1 Sep 2007 13:53:31 -0000	1.97
+++ src/networks/bittorrent/bTClients.ml	14 Dec 2007 19:06:01 -0000
@@ -260,8 +260,10 @@
   @param reason The reason for the disconnection (see in BasicSocket.ml)
 *)
 let disconnect_client c reason =
+  let (ip,port) = c.client_host in
   if !verbose_msg_clients then
-    lprintf_nl "Client %d: disconnected: %s" (client_num c) (string_of_reason reason);
+    lprintf_nl "Client %d(%s:%d): disconnected: %s" (client_num c) 
+      (Ip.to_string ip) port (string_of_reason reason);
   begin
     match c.client_sock with
       NoConnection -> ()
@@ -273,24 +275,25 @@
         try
 (*          List.iter (fun r -> CommonSwarming.free_range r) c.client_ranges; *)
           set_client_disconnected c reason;
+          connection_failed c.client_connection_control;
+          c.client_choked <- true;
+          c.client_sent_choke <- false;
+          c.client_interested <- false;
+          (* c.client_chunks <- []; *)
+          (* c.client_new_chunks <- []; *)
+          c.client_upload_requests <- [];
+          c.client_ranges_sent <- [];
+          c.client_range_waiting <- [];
           c.client_session_downloaded <- 0L;
           c.client_session_uploaded <- 0L;
           (try if c.client_good then count_seen c with _ -> ());
-          (* this is not useful already done in the match
-          (try close sock reason with _ -> ());   *)
-(*---------not needed ?? VvvvvV---------------
-          c.client_ranges <- [];
-          c.client_block <- None;
-          if not c.client_good then
-            connection_failed c.client_connection_control;
+          c.client_num_try <- connection_retries c.client_connection_control;
           c.client_good <- false;
           c.client_sock <- NoConnection;
-          c.client_chunks <- [];
           c.client_allowed_to_write <- zero;
-          c.client_new_chunks <- [];
           c.client_interesting <- false;
           c.client_alrd_sent_interested <- false;
-    -------------------^^^^^--------------------*)
+          c.client_alrd_sent_notinterested <- false;
           if (c.client_registered_bitfield) then
             begin
               match c.client_uploader with
@@ -302,23 +305,24 @@
                      (Useful for availability)
                   *)
                   CommonSwarming.unregister_uploader up
-(*        c.client_registered_bitfield <- false;
-          for i = 0 to String.length c.client_bitmap - 1 do
-            c.client_bitmap.[0] <- '0';
-          done*)
             end;
           (* Don't test if a client have an upload slot because
              it don't have one (removed during earlier in
           set_client_disconnected c reason)
           *)
+
+          if (c.client_uid = !!client_uid) then (
+(* TIMTIM           if !verbose_msg_clients then *)
+              lprintf_nl "Client %d: Our uid, removing client" (client_num c) ;
+            remove_client c;
+          );
+          if connection_retries c.client_connection_control > 2 then (
+            if !verbose_msg_clients then
+              lprintf_nl "Client %d: maximum number of retries, removing client" (client_num c) ;
+            remove_client c;
+          );
           if (List.mem c !current_uploaders) then
-            begin
-(*BTGlobals.remove_client*)
-              remove_client c;
               recompute_uploaders ();
-            end
-          else  
-            remove_client c;
         with _ -> ()
   end
 
@@ -378,7 +382,7 @@
   let i = n lsr 3 in
   s.[i] <- Char.unsafe_chr (Char.code s.[i] lor bits.(n land 7))
 
-(* Official client seems to use max_range_request 5 and max_range_len 2^14 *)
+(* Official client seems to use max_range_request 5 and max_range_len 2^15 *)
 (* How much requests in the 'pipeline' *)
 let max_range_requests = 5
 (* How much bytes we can request in one Piece *)
@@ -467,7 +471,10 @@
       match ccc with
         None ->
           let c = new_client file Sha1.null (TcpBufferedSocket.peer_addr sock) cc_country_code in
-          if !verbose_connect then lprintf_file_nl (as_file file) "Client %d: incoming connection" (client_num c);
+          if !verbose_connect then (
+            let (ip,port) = c.client_host in
+            lprintf_file_nl (as_file file) "Client %d(%s:%d): incoming connection"
+              (client_num c) (Ip.to_string ip) port;);
           cc := (Some c), cc_country_code;
           c
       | Some c ->
@@ -485,9 +492,9 @@
            *)
 
 (*          if c.client_uid <> peer_id then begin
-              lprintf "Unexpected client by UID\n";
+              lprintf_nl "Unexpected client by UID";
               let ccc = new_client file peer_id (TcpBufferedSocket.host sock) in
-              lprintf "CLIENT %d: testing instead of %d\n"
+              lprintf_nl "Client %d: testing instead of %d"
                 (client_num ccc) (client_num c);
               (match ccc.client_sock with
                   Connection _ ->
@@ -506,9 +513,9 @@
 
     if !verbose_msg_clients then begin
         let (ip,port) = c.client_host in
-          lprintf_nl "Client %d: Connected from %s:%d" (client_num c)
+          lprintf_nl "Client %d(%s:%d): Connected" (client_num c)
             (Ip.to_string ip) port;
-      end;
+    end;
 
     parse_reserved rbits c;
 
@@ -516,7 +523,8 @@
         NoConnection ->
           if !verbose_msg_clients then begin
               let (ip,port) = c.client_host in
-              lprintf_nl "No connection to client (%s:%d)!!!" (Ip.to_string ip) port;
+              lprintf_nl "Client %d(%s:%d): No connection to client!!!"
+              (client_num c) (Ip.to_string ip) port;
             end;
           c.client_sock <- Connection sock
       | ConnectionWaiting token ->
@@ -525,8 +533,10 @@
             lprintf_nl "Waiting for connection to client !!!";
           c.client_sock <- Connection sock
       | Connection s when s != sock ->
-          if !verbose_msg_clients then
-            lprintf_nl "CLIENT %d: IMMEDIATE RECONNECTION" (client_num c);
+          if !verbose_msg_clients then (
+            let (ip,port) = c.client_host in
+            lprintf_nl "Client %d(%s:%d): IMMEDIATE RECONNECTION" 
+              (client_num c) (Ip.to_string ip) port;);
           disconnect_client c (Closed_for_error "Reconnected");
           c.client_sock <- Connection sock;
       | Connection _  -> ()
@@ -572,7 +582,7 @@
       | Not_found ->
           let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
           if !verbose_unexpected_messages then
-            lprintf_nl "Client %s:%d requested a file that is not shared [%s]"
+            lprintf_nl "unexpected: the client %s:%d: requested a file that is not shared [%s]"
               (Ip.to_string ip) port (Sha1.to_hexa file_id)
       | e ->
           lprintf_nl "Exception %s in client_parse_header" (Printexc2.to_string e);
@@ -586,37 +596,39 @@
 and update_client_bitmap c =
   let file = c.client_file in
   
-  let swarmer = match file.file_swarmer with
-      None -> assert false
-    | Some swarmer -> swarmer 
-  in
+  try
+    let swarmer = match file.file_swarmer with
+        None -> raise Exit (* we may be choked or unchoked, when we just finished the download *)
+     | Some swarmer -> swarmer 
+    in
   
-  let up =
-    match c.client_uploader with
-      None ->
-        let up = CommonSwarming.register_uploader swarmer (as_client c)
-          (AvailableIntervals []) in
-        c.client_uploader <- Some up;
-        up
-    | Some up ->
-        up
-  in
+    let up =
+      match c.client_uploader with
+        None ->
+          let up = CommonSwarming.register_uploader swarmer (as_client c)
+            (AvailableIntervals []) in
+          c.client_uploader <- Some up;
+          up
+      | Some up ->
+          up
+    in
 
-  let bitmap = match c.client_bitmap with
-      None ->
-        let len = CommonSwarming.partition_size swarmer in
-        let bitmap = Bitv.create len false in
-        c.client_bitmap <- Some bitmap;
-        bitmap
-    | Some bitmap -> bitmap
-  in
+    let bitmap = match c.client_bitmap with
+        None ->
+          let len = CommonSwarming.partition_size swarmer in
+          let bitmap = Bitv.create len false in
+          c.client_bitmap <- Some bitmap;
+          bitmap
+      | Some bitmap -> bitmap
+    in
 
-  if c.client_new_chunks <> [] then begin
-    let chunks = c.client_new_chunks in
-    c.client_new_chunks <- [];
-    List.iter (fun n -> Bitv.set bitmap n true) chunks;
-    CommonSwarming.update_uploader_intervals up (AvailableBitv bitmap);
-  end
+    if c.client_new_chunks <> [] then begin
+      let chunks = c.client_new_chunks in
+      c.client_new_chunks <- [];
+      List.iter (fun n -> Bitv.set bitmap n true) chunks;
+      CommonSwarming.update_uploader_intervals up (AvailableBitv bitmap);
+    end
+  with Exit -> ()
 
 
 (** In this function we decide which piece we must request from client.
@@ -625,6 +637,7 @@
 *)
 and get_from_client sock (c: client) =
   let file = c.client_file in
+  let (ip,port) = c.client_host in
   (* Check if there's not enough requests in the 'pipeline'
      and if a request can be send (not choked and file is downloading) *)
   if List.length c.client_ranges_sent < max_range_requests 
@@ -644,14 +657,15 @@
     let num, x,y, r =
 
       if !verbose_msg_clients then
-        lprintf_file_nl (as_file file) "CLIENT %d: Finding new range to send" (client_num c);
+        lprintf_file_nl (as_file file) "Client %d(%s:%d): Finding new range to send"
+        (client_num c) (Ip.to_string ip) port;
 
       if !verbose_swarming then begin
         lprintf_n "Current download:\n  Current chunks: ";
 
-        try
-          List.iter (fun (x,y) -> lprintf "%Ld-%Ld " x y) c.client_chunks
-        with _ -> lprintf "No Chunks";
+        (try
+          List.iter (fun (x,y) -> lprintf "%Ld-%Ld " x y) c.client_chunks;
+        with _ -> lprintf "No Chunks";);
           
         lprint_newline ();
           
@@ -659,21 +673,23 @@
           
         List.iter (fun (p1,p2, r) ->
           let (x,y) = CommonSwarming.range_range r in
-          lprintf "%Ld-%Ld[%Ld-%Ld] " p1 p2 x y
+          lprintf "%Ld-%Ld[%Ld-%Ld] " p1 p2 x y;
         ) c.client_ranges_sent;
 
-        match c.client_range_waiting with
-        | None -> ()
-        | Some (x,y,r) -> lprintf "Waiting %Ld-%Ld" x y;
+        lprint_newline ();
+
+        List.iter (fun (x,y,r) ->
+          lprintf "Waiting %Ld-%Ld" x y;
+        ) c.client_range_waiting;
 
         lprint_newline ();
           
         lprintf_n "Current blocks: ";
           
-        match c.client_chunk with
-        | None -> lprintf "none"
+        (match c.client_chunk with
+        | None -> lprintf "none";
         | Some (chunk, blocks) -> List.iter (fun b -> 
-	    CommonSwarming.print_block b.up_block) blocks;
+	    CommonSwarming.print_block b.up_block) blocks;);
 
         lprint_newline ();
       
@@ -723,17 +739,17 @@
                 (*Given a block find a range inside*)
                 let (x,y,r) =
                   match c.client_range_waiting with
-		  | Some (x,y,r) ->
-                        c.client_range_waiting <- None;
+		  | (x,y,r) :: tail ->
+                        c.client_range_waiting <- tail;
                         (x,y,r)
-                  | None -> 
+                  | [] -> 
                         CommonSwarming.find_range up (min max_range_len file.file_piece_size)
                 in
 
                 let (x,y,r) =
                   
                   if y -- x > max_range_len then begin
-                      c.client_range_waiting <- Some (x ++ max_range_len, y, r);
+                      c.client_range_waiting <- c.client_range_waiting @ [x ++ max_range_len, y, r];
                       (x, x ++ max_range_len, r)
                   end else 
                       (x,y,r) 
@@ -773,20 +789,22 @@
           *)
           if !verbose_swarming then
             lprintf_nl "Unable to get a block !!";
-          CommonSwarming.compute_bitmap swarmer;
-          check_finished swarmer file;
+          (* CommonSwarming.compute_bitmap swarmer;
+          check_finished swarmer file; *)
           raise Not_found
     in
 
     send_client c (Request (num,x,y));
 
     if !verbose_msg_clients then
-      lprintf_file_nl (as_file file) "CLIENT %d: Asking %s For Range %Ld-%Ld"
-        (client_num c) (Sha1.to_string c.client_uid) x y
+      lprintf_file_nl (as_file file) "Client %d(%s:%d): Asking %s For Range %Ld-%Ld"
+        (client_num c) (Ip.to_string ip) port (Sha1.to_string c.client_uid) x y
 
   with Not_found ->
-        if not (CommonSwarming.check_finished swarmer) && !verbose_download then
-          lprintf_file_nl (as_file file) "BTClient.get_from_client ERROR: can't find a block to download and file is not yet finished for file : %s..." file.file_name
+        ()
+        (* if not (CommonSwarming.check_finished swarmer) && !verbose_swarming then
+          lprintf_file_nl (as_file file) "Client %d(%s:%d): Can't find a block to download and file is not yet finished for file. This Client has no blocks we need." 
+            (client_num c) (Ip.to_string ip) port *)
 
 
 (** In this function we match a message sent by a client
@@ -799,7 +817,7 @@
   if !verbose_msg_clients then begin
       let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
       let (timeout, next) = get_rtimeout sock in
-      lprintf_nl "CLIENT %d(%s:%d): (%d, %d,%d) Received %s"
+      lprintf_nl "Client %d(%s:%d): (%d, %d,%d) Received %s"
         (client_num c) (Ip.to_string ip) port
       (last_time ())
       (int_of_float timeout)
@@ -896,8 +914,6 @@
           let brand, release = parse_software p in
           c.client_brand <- brand;
           c.client_release <- release;
-          send_client c Choke;
-          c.client_sent_choke <- true;
         end
       else
         disconnect_client c Closed_by_user
@@ -1001,20 +1017,10 @@
         begin
           set_client_state (c) (Connected (-1));
           (* remote peer will clear the list of range we sent *)
-          begin
-           match c.client_uploader with
-              None ->
-                (* Afaik this is no protocol violation and happens if the client
-                   didn't send a client bitmap after the handshake. *)
-                let (ip,port) = c.client_host in
-                  if !verbose_msg_clients then lprintf_file_nl (as_file file) "%s:%d with software %s : Choke send, but no client bitmap"
-                    (Ip.to_string ip) port (brand_to_string c.client_brand)
-            | Some up ->
-                CommonSwarming.clear_uploader_intervals up
-          end;
+          c.client_range_waiting <- c.client_range_waiting @ c.client_ranges_sent;
           c.client_ranges_sent <- [];
-          c.client_range_waiting <- None;
           c.client_choked <- true;
+          update_client_bitmap c;
         end
 
     | NotInterested ->
@@ -1023,6 +1029,7 @@
     | Unchoke ->
         begin
           c.client_choked <- false;
+          update_client_bitmap c;
           (* remote peer cleared our request : re-request *)
           for i = 1 to max_range_requests -
             List.length c.client_ranges_sent do
@@ -1032,7 +1039,7 @@
 
     | Request (n, pos, len) ->
         if len > max_request_len then begin
-            close sock (Closed_for_error "Request longer than 1<<16");
+            close sock (Closed_for_error "Request longer than 1<<17");
             raise Exit
           end;
 
@@ -1103,11 +1110,10 @@
       let token =
         add_pending_connection connection_manager (fun token ->
             try
-              if !verbose_msg_clients then
-                lprintf_nl "CLIENT %d: connect_client" (client_num c);
               let (ip,port) = c.client_host in
               if !verbose_msg_clients then
-                lprintf_nl "connecting %s:%d" (Ip.to_string ip) port;
+                lprintf_nl "Client %d(%s:%d): try connecting"
+                  (client_num c) (Ip.to_string ip) port;
               connection_try c.client_connection_control;
                 begin
                   let sock = connect token "bittorrent download"
@@ -1116,12 +1122,13 @@
                         match event with
                           BASIC_EVENT LTIMEOUT ->
                             if !verbose_msg_clients then
-                              lprintf_nl "CLIENT %d: LIFETIME" (client_num c);
+                              lprintf_nl "Client %d(%s:%d): LIFETIME" 
+                                (client_num c) (Ip.to_string ip) port;
                             close sock Closed_for_timeout
                         | BASIC_EVENT RTIMEOUT ->
                             if !verbose_msg_clients then
-                              lprintf_nl "CLIENT %d: RTIMEOUT (%d)" (client_num c)
-                              (last_time ())
+                              lprintf_nl "Client %d(%s:%d): RTIMEOUT (%d)" (client_num c)
+                              (Ip.to_string ip) port (last_time ())
                               ;
                             close sock Closed_for_timeout
                         | BASIC_EVENT (CLOSED r) ->
@@ -1288,11 +1295,9 @@
                *)
                if connection_can_try c.client_connection_control then
                  connect_client c
-               else
-                 print_control c.client_connection_control
              with _ -> ())
       with e ->
-          if !verbose_connect then
+          if !verbose_connect || !verbose_msg_clients then
             lprintf_file_nl (as_file file) "Exception %s in resume_clients"   (Printexc2.to_string e)
   ) file.file_clients
 
@@ -1491,7 +1496,8 @@
           (try check_finished swarmer file with e -> ());
           match file_state file with
             FileDownloading ->
-              (try get_sources_from_tracker file with _ -> ())
+              (try get_sources_from_tracker file with _ -> ());
+              resume_clients file
           | FileShared ->
               (try
                   connect_trackers file "" (fun _ _ -> ()) with _ -> ())
@@ -1618,7 +1624,9 @@
   );
   file_ops.op_file_queue <- file_ops.op_file_pause;
   client_ops.op_client_enter_upload_queue <- (fun c ->
-      if !verbose_msg_clients then
-        lprintf_nl "Client %d: client_enter_upload_queue" (client_num c);
+      if !verbose_msg_clients then (
+        let (ip,port) = c.client_host in
+        lprintf_nl "Client %d(%s:%d): client_enter_upload_queue" 
+          (client_num c) (Ip.to_string ip) port;);
       ready_for_upload (as_client c));
   network.op_network_connected_servers <- (fun _ -> []);
Index: src/networks/bittorrent/bTComplexOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTComplexOptions.ml,v
retrieving revision 1.42
diff -u -r1.42 bTComplexOptions.ml
--- src/networks/bittorrent/bTComplexOptions.ml	3 Aug 2007 22:12:58 -0000	1.42
+++ src/networks/bittorrent/bTComplexOptions.ml	14 Dec 2007 19:06:01 -0000
@@ -305,6 +305,21 @@
 
 let guptime () = !!guptime - !diff_time
 
+let rec update_options () =
+  let update v =
+      lprintf_nl "Updating options to version %i" v;
+      options_version =:= v;
+      update_options ()
+  in
+
+  match !!options_version with
+    0 ->
+      if !!client_timeout = 90. then
+        client_timeout =:= 130.;
+      update 1
+    | _ -> ()
+
+
 let _ =
   network.op_network_file_of_option <- value_to_file;
   file_ops.op_file_to_option <- file_to_value;
@@ -312,5 +327,5 @@
   (* Shut up message "Network.save/load_complex_options not implemented by BitTorrent" *)
   network.op_network_load_complex_options <- load;
   network.op_network_save_complex_options <- save;
-  network.op_network_update_options <- (fun _ -> ());
+  network.op_network_update_options <- update_options;
   network.op_network_save_sources <- (fun _ -> ())
Index: src/networks/bittorrent/bTGlobals.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTGlobals.ml,v
retrieving revision 1.82
diff -u -r1.82 bTGlobals.ml
--- src/networks/bittorrent/bTGlobals.ml	3 Aug 2007 22:12:58 -0000	1.82
+++ src/networks/bittorrent/bTGlobals.ml	14 Dec 2007 19:06:02 -0000
@@ -44,9 +44,6 @@
 open CommonNetwork
 open TcpMessages
 
-
-let send_client c m = send_client c.client_sock m
-
 let as_ft file = as_file file.ft_file
 let ft_num file = file_num (as_ft file)
 let ft_size file = file.ft_file.impl_file_size
@@ -155,8 +152,8 @@
 
 let files_by_uid = Hashtbl.create 13
 
-let max_range_len = Int64.of_int (1 lsl 14)
-let max_request_len = Int64.of_int (1 lsl 16)
+let max_range_len = Int64.of_int (1 lsl 15)
+let max_request_len = Int64.of_int (1 lsl 17)
 
 let bt_download_counter = ref Int64.zero
 let bt_upload_counter = ref Int64.zero
@@ -186,8 +183,8 @@
             let x,y = CommonSwarming.range_range r in
             x < y) c.client_ranges_sent = []) &&
       (match c.client_range_waiting with
-          None -> true
-        | Some (x,y,r) ->
+          [] -> true
+        | (x,y,r) :: _ ->
             let x,y = CommonSwarming.range_range r in
             x < y) &&
 (* The current blocks are also useless *)
@@ -810,7 +807,7 @@
           client_uploader = None;
           client_chunks = [];
           client_ranges_sent = [];
-          client_range_waiting = None;
+          client_range_waiting = [];
           client_chunk = None;
           client_uid = peer_id;
           client_brand = brand;
Index: src/networks/bittorrent/bTOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTOptions.ml,v
retrieving revision 1.35
diff -u -r1.35 bTOptions.ml
--- src/networks/bittorrent/bTOptions.ml	1 Jul 2007 21:58:08 -0000	1.35
+++ src/networks/bittorrent/bTOptions.ml	14 Dec 2007 19:06:02 -0000
@@ -138,7 +138,7 @@
 
 let client_timeout = define_option bittorrent_section ["client_timeout"]
   "Timeout on client connections"
-    float_option 90.
+    float_option 130.
 
 let user_agent = define_option bittorrent_section ["user_agent"]
   "User agent string (default = \"default\")"
@@ -147,7 +147,7 @@
 let options_version = define_option bittorrent_section ["options_version"]
   ~internal: true
   "(internal option)"
-    int_option 0
+    int_option 1
 
 let old_files = define_option bittorrent_section ["old_files"]
   ""
Index: src/networks/bittorrent/bTProtocol.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTProtocol.ml,v
retrieving revision 1.27
diff -u -r1.27 bTProtocol.ml
--- src/networks/bittorrent/bTProtocol.ml	1 Oct 2006 17:54:00 -0000	1.27
+++ src/networks/bittorrent/bTProtocol.ml	14 Dec 2007 19:06:02 -0000
@@ -223,6 +223,7 @@
 open CommonTypes
 open Printf2
 open CommonOptions
+open CommonClient
 open Options
 open Md4
 open CommonGlobals
@@ -479,8 +480,9 @@
             buf_used b b.len;
             close sock Closed_by_user;
           end
-        else if msg_len > 20000 then
-          (* We NEVER request pieces greater than size 20000, this client is
+        (* else if (Int64.of_int msg_len) > max_request_len then *)
+        else if msg_len > 131072 then (* 1 lsl 17 *)
+          (* We NEVER request pieces greater than size max_request_len, this client is
              trying to waste our bandwidth ? *)
           begin
             let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
@@ -613,18 +615,27 @@
           int: length (power of 2, 2 ^ 15)
 *)
 
-let send_client client_sock msg =
+let send_client c msg =
+  let client_sock = c.client_sock in
     do_if_connected  client_sock (fun sock ->
       try
         let s = TcpMessages.write msg in
         if !verbose_msg_clients then begin
-            lprintf_nl "send message: %s" (TcpMessages.to_string msg);
+            let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
+            let (timeout, next) = get_rtimeout sock in
+            lprintf_nl "Client %d(%s:%d): (%d, %d,%d) Send %s"
+              (client_num (as_client c.client_client)) (Ip.to_string ip) port
+            (last_time ())
+            (int_of_float timeout)
+            (int_of_float next)
+            (TcpMessages.to_string msg);
           end;
 (*        dump s; *)
         write_string sock s
   with e ->
-      lprintf_nl "CLIENT : Error %s in send_client"
-        (Printexc2.to_string e)
+      let (ip,port) = c.client_host in
+      lprintf_nl "Client %d(%s:%d): Error %s in send_client"
+        (client_num (as_client c.client_client)) (Ip.to_string ip) port (Printexc2.to_string e)
 )
 
 let zero8 = String.make 8 '\000'
Index: src/networks/bittorrent/bTTypes.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTTypes.ml,v
retrieving revision 1.45
diff -u -r1.45 bTTypes.ml
--- src/networks/bittorrent/bTTypes.ml	9 Jul 2007 23:50:54 -0000	1.45
+++ src/networks/bittorrent/bTTypes.ml	14 Dec 2007 19:06:02 -0000
@@ -232,8 +232,7 @@
     mutable client_chunks : (int64 * int64) list;
     mutable client_uploader : CommonSwarming.uploader option;
     mutable client_ranges_sent : (int64 * int64 * CommonSwarming.range) list;
-    mutable client_range_waiting :
-    (int64 * int64 * CommonSwarming.range) option;
+    mutable client_range_waiting : (int64 * int64 * CommonSwarming.range) list;
     mutable client_chunk : (int * CommonSwarming.uploader_block list) option;
 
     mutable client_received_peer_id : bool;
