mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...
Date: Sun, 08 Oct 2006 14:20:22 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       06/10/08 14:20:22

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonFile.ml commonFile.mli commonServer.ml 
                           commonShared.ml commonShared.mli 
                           commonUploads.ml guiDecoding.ml guiTypes.ml 
        src/daemon/driver: driverCommands.ml driverInteractive.ml 
        src/networks/bittorrent: bTInteractive.ml bTShare.ml 
        src/networks/donkey: donkeyClient.ml donkeyGlobals.ml 
                             donkeyInteractive.ml donkeyMain.ml 
                             donkeyOneFile.ml donkeyOptions.ml 
                             donkeyProtoCom.ml donkeyServers.ml 
                             donkeyShare.ml donkeyTypes.ml 

Log message:
        patch #5430

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1045&r2=1.1046
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonFile.ml?cvsroot=mldonkey&r1=1.64&r2=1.65
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonFile.mli?cvsroot=mldonkey&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonServer.ml?cvsroot=mldonkey&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonShared.ml?cvsroot=mldonkey&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonShared.mli?cvsroot=mldonkey&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonUploads.ml?cvsroot=mldonkey&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/guiDecoding.ml?cvsroot=mldonkey&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/guiTypes.ml?cvsroot=mldonkey&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverCommands.ml?cvsroot=mldonkey&r1=1.180&r2=1.181
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverInteractive.ml?cvsroot=mldonkey&r1=1.107&r2=1.108
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTInteractive.ml?cvsroot=mldonkey&r1=1.116&r2=1.117
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTShare.ml?cvsroot=mldonkey&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyClient.ml?cvsroot=mldonkey&r1=1.102&r2=1.103
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyGlobals.ml?cvsroot=mldonkey&r1=1.100&r2=1.101
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyInteractive.ml?cvsroot=mldonkey&r1=1.128&r2=1.129
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyMain.ml?cvsroot=mldonkey&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyOneFile.ml?cvsroot=mldonkey&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyOptions.ml?cvsroot=mldonkey&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyProtoCom.ml?cvsroot=mldonkey&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyServers.ml?cvsroot=mldonkey&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyShare.ml?cvsroot=mldonkey&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyTypes.ml?cvsroot=mldonkey&r1=1.48&r2=1.49

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1045
retrieving revision 1.1046
diff -u -b -r1.1045 -r1.1046
--- distrib/ChangeLog   8 Oct 2006 14:12:13 -0000       1.1045
+++ distrib/ChangeLog   8 Oct 2006 14:20:21 -0000       1.1046
@@ -15,6 +15,20 @@
 =========
 
 2006/10/08
+5430: EDK: Improve file publishing
+- publish no more than 200 files/minute to avoid server-side blacklisting,
+  eMule uses the same limit,
+  least published files are published first (thx to pango)
+- respect server hard_limit, never publish more files to servers
+- HTML: in server list display number of files published by server, by clicking
+  on this number the list of files is displayed (new command server_shares num)
+- HTML: diplay master server status, only master server are used for publishing
+- HTML: in upstats display number of server the file was published to,
+  also display server name + IP in javascript popup
+- bug fix: properly update DonkeyGlobals.master_server to be used in 
+  DonkeyClient.read_first_message, this is used when replying to non-Overnet
+  clients so they know to which server MLdonkey is connected to,
+- remove development option become_master_delay
 5445: Self-test charset conversion, disable conversion if test fails
 5444: BT: Correctly display client connected time,
       also allow correct upload speed calculation (tradie)

Index: src/daemon/common/commonFile.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonFile.ml,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- src/daemon/common/commonFile.ml     1 Oct 2006 17:47:11 -0000       1.64
+++ src/daemon/common/commonFile.ml     8 Oct 2006 14:20:21 -0000       1.65
@@ -78,6 +78,7 @@
 has been changed. The method should not perform the move, just know that
 it will happen soon. *)
     mutable op_file_save_as : ('a -> string -> unit);
+    mutable op_file_shared : ('a -> CommonTypes.shared option);
     mutable op_file_to_option : ('a -> (string * option_value) list);
     mutable op_file_cancel : ('a -> unit);
     mutable op_file_pause : ('a -> unit);
@@ -209,6 +210,10 @@
   let file = as_file_impl file in
   file.impl_file_ops.op_file_save_as file.impl_file_val name
 
+let file_shared (file : file) =
+  let file = as_file_impl file in
+  file.impl_file_ops.op_file_shared file.impl_file_val
+
 let file_comment (file : file) =
   let file = as_file_impl file in
   file.impl_file_ops.op_file_comment file.impl_file_val
@@ -997,6 +1002,7 @@
       op_file_commit = (fun _ _ -> ni_ok network "file_commit");
       op_file_save_as = (fun _ _ -> ni_ok network "file_save_as");
 (*    op_file_print = (fun _ _ -> ni_ok network "file_print"); *)
+      op_file_shared = (fun _ -> None);
       op_file_to_option = (fun _ -> fni network "file_to_option");
       op_file_cancel = (fun _ -> ni_ok network "file_cancel");
       op_file_info = (fun _ -> fni network "file_info");
@@ -1036,6 +1042,8 @@
         lprintf_nl "op_file_commit";
       if c.op_file_save_as == cc.op_file_save_as then
         lprintf_nl "op_file_save_as";
+      if c.op_file_shared == cc.op_file_shared then
+        lprintf_nl "op_file_shared";
       if c.op_file_cancel == cc.op_file_cancel then
         lprintf_nl "op_file_cancel";
       if c.op_file_pause == cc.op_file_pause then

Index: src/daemon/common/commonFile.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonFile.mli,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- src/daemon/common/commonFile.mli    3 Oct 2006 15:23:08 -0000       1.26
+++ src/daemon/common/commonFile.mli    8 Oct 2006 14:20:21 -0000       1.27
@@ -45,6 +45,7 @@
   mutable op_file_network : CommonTypes.network;
   mutable op_file_commit : 'a -> string -> unit;
   mutable op_file_save_as : 'a -> string -> unit;
+  mutable op_file_shared : 'a -> CommonTypes.shared option;
   mutable op_file_to_option : 'a -> (string * Options.option_value) list;
   mutable op_file_cancel : 'a -> unit;
   mutable op_file_pause : 'a -> unit;
@@ -79,6 +80,7 @@
 val update_file_state : 'a file_impl -> CommonTypes.file_state -> unit
 val file_to_option : CommonTypes.file -> (string * Options.option_value) list
 val file_save_as : CommonTypes.file -> string -> unit
+val file_shared : CommonTypes.file -> CommonTypes.shared option
 val file_comment : CommonTypes.file -> string
 val file_network : CommonTypes.file -> CommonTypes.network
 val file_info : CommonTypes.file -> GuiTypes.file_info

Index: src/daemon/common/commonServer.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonServer.ml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- src/daemon/common/commonServer.ml   23 Sep 2006 20:29:46 -0000      1.34
+++ src/daemon/common/commonServer.ml   8 Oct 2006 14:20:21 -0000       1.35
@@ -53,6 +53,7 @@
     mutable op_server_connect : ('a -> unit);
     mutable op_server_disconnect : ('a -> unit);
     mutable op_server_users : ('a -> user list);
+    mutable op_server_published : ('a -> file list);
     mutable op_server_query_users : ('a -> unit);
     mutable op_server_find_user : ('a -> string -> unit);
     mutable op_server_cid : ('a -> Ip.t);
@@ -108,12 +109,14 @@
     T.server_users = None;
     T.server_banner = "";
     T.server_preferred = false;
+    T.server_master = false;
     T.server_version = "";
     T.server_max_users = 0L;
     T.server_soft_limit = 0L;
     T.server_hard_limit = 0L;
     T.server_lowid_users = 0L;
     T.server_ping = 0;
+    T.server_published_files = 0;
   }
 
 let server_num s =
@@ -183,6 +186,10 @@
   let s = as_server_impl s in
   s.impl_server_ops.op_server_users s.impl_server_val
 
+let server_published s =
+  let s = as_server_impl s in
+  s.impl_server_ops.op_server_published s.impl_server_val
+
 let server_cid s =
   let s = as_server_impl s in
   s.impl_server_ops.op_server_cid s.impl_server_val
@@ -212,6 +219,7 @@
       op_server_disconnect = (fun _ -> ni_ok network "server_disconnect");
       op_server_find_user = (fun _ -> fni network "find_user");
       op_server_query_users = (fun _ -> ni_ok network "query_users");
+      op_server_published = (fun _ -> fni network "published");
       op_server_users = (fun _ -> fni network "users");
       op_server_cid = (fun _ -> fni network "cid");
       op_server_low_id = (fun _ -> fni network "low_id");
@@ -367,6 +375,7 @@
     ( "0", "srh", "Connect|Disconnect", "C/D" ) ;
     ( "0", "srh", "Remove", "Rem" ) ;
     ( "0", "srh", "Preferred", "P" ) ;
+    ( "0", "srh", "Master servers", "M" ) ;
     ( "0", "srh", "[Hi]gh or [Lo]w ID", "ID" ) ;
     ( "0", "srh", "Network name", "Network" ) ;
     ( "0", "srh", "Connection status", "Status" ) ;
@@ -375,11 +384,12 @@
     ( "1", "srh ar", "Number of connected users", "Users" ) ;
     ( "1", "srh ar br", "Max number of users", "MaxUsers" ) ;
     ( "1", "srh ar br", "LowID users", "LowID" ) ;
-    ( "1", "srh ar br", "Number of files indexed on server", "Files" ) ;
+    ( "1", "srh ar", "Number of files indexed on server", "Files" );
+    ( "1", "srh ar br", "Number of published files on server", "Publ" );
     ( "1", "srh ar", "Soft file limit", "Soft" ) ;
     ( "1", "srh ar br", "Hard file limit", "Hard" ) ;
     ( "0", "srh ar br", "Ping (ms)", "Ping" ) ;
-    ( "0", "srh", "Server version", "Version" ) ;
+    ( "0", "srh br", "Server version", "Version" ) ;
     ( "0", "srh", "Server name", "Name" ) ;
     ( "0", "srh", "Server details", "Details" ) ])
 
@@ -496,6 +506,7 @@
 
     let cc,cn = Geoip.get_country (Ip.ip_of_addr info.G.server_addr) in
     html_mods_td buf ([
+      ("", "srb", if info.G.server_master then "T" else "F");
       (id_title, "sr", id_text);
       ("", "sr", n.network_name);
       ("", "sr", server_state_string);
@@ -504,7 +515,18 @@
       ("", "sr ar", Printf.sprintf "%Ld" info.G.server_nusers);
       ("", "sr ar br", Printf.sprintf "%Ld" info.G.server_max_users);
       ("", "sr ar br", Printf.sprintf "%Ld" info.G.server_lowid_users);
-      ("", "sr ar br", Printf.sprintf "%Ld" info.G.server_nfiles);
+      ("", "sr ar", Printf.sprintf "%Ld" info.G.server_nfiles)]);
+
+    if info.G.server_published_files = 0 then
+      html_mods_td buf ([("", "sr br", "")])
+    else
+      Printf.bprintf buf
+"\\<TD class=\\\"sr br\\\" onMouseOver=\\\"mOvr(this);\\\"
+onMouseOut=\\\"mOut(this);\\\" title=\\\"Show published files\\\"
+onClick=\\\"location.href='submit?q=server_shares+%d'\\\"\\>%d\\</TD\\>"
+       snum info.G.server_published_files;
+
+    html_mods_td buf ([
       ("", "sr ar", Printf.sprintf "%Ld" info.G.server_soft_limit);
       ("", "sr ar br", Printf.sprintf "%Ld" info.G.server_hard_limit);
       ("", "sr ar br", Printf.sprintf "%d" info.G.server_ping);

Index: src/daemon/common/commonShared.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonShared.ml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- src/daemon/common/commonShared.ml   23 Sep 2006 20:29:46 -0000      1.34
+++ src/daemon/common/commonShared.ml   8 Oct 2006 14:20:21 -0000       1.35
@@ -43,7 +43,8 @@
     mutable impl_shared_size : int64;
     mutable impl_shared_id : Md4.t;
     mutable impl_shared_requests : int;
-    mutable impl_shared_magic : string option
+    mutable impl_shared_magic : string option;
+    mutable impl_shared_servers : CommonTypes.server list;
   }
   
 and 'a shared_ops = {
@@ -214,6 +215,7 @@
     impl_shared_id = Md4.null;
     impl_shared_requests = 0;
     impl_shared_magic = None;
+    impl_shared_servers = []
   }
   
   

Index: src/daemon/common/commonShared.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonShared.mli,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- src/daemon/common/commonShared.mli  12 Jun 2006 20:47:21 -0000      1.7
+++ src/daemon/common/commonShared.mli  8 Oct 2006 14:20:21 -0000       1.8
@@ -9,7 +9,8 @@
   mutable impl_shared_size : int64;
   mutable impl_shared_id : Md4.Md4.t;
   mutable impl_shared_requests : int;
-  mutable impl_shared_magic : string option
+  mutable impl_shared_magic : string option;
+  mutable impl_shared_servers : CommonTypes.server list;
 } 
 and 'a shared_ops = {
   mutable op_shared_info : 'a -> GuiTypes.shared_info;

Index: src/daemon/common/commonUploads.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonUploads.ml,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- src/daemon/common/commonUploads.ml  22 Sep 2006 17:39:51 -0000      1.46
+++ src/daemon/common/commonUploads.ml  8 Oct 2006 14:20:21 -0000       1.47
@@ -695,7 +695,8 @@
           impl_shared_ops = shared_ops;
           impl_shared_val = sh;
           impl_shared_requests = 0;
-          impl_shared_magic = None
+          impl_shared_magic = None;
+          impl_shared_servers = [];
         }
       and sh = {
           shared_info = index;

Index: src/daemon/common/guiDecoding.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/guiDecoding.ml,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- src/daemon/common/guiDecoding.ml    23 Sep 2006 20:29:46 -0000      1.60
+++ src/daemon/common/guiDecoding.ml    8 Oct 2006 14:20:21 -0000       1.61
@@ -750,12 +750,14 @@
     server_banner = "";
     server_users = None;
     server_preferred = preferred;
+    server_master = false;
     server_version = ve; 
     server_max_users = ma;
     server_lowid_users = lo;
     server_soft_limit = so;
     server_hard_limit = ha;
     server_ping = pi;
+    server_published_files = 0;
   }, pos
 
 let get_client_type s pos = 

Index: src/daemon/common/guiTypes.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/guiTypes.ml,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- src/daemon/common/guiTypes.ml       23 Sep 2006 20:29:46 -0000      1.30
+++ src/daemon/common/guiTypes.ml       8 Oct 2006 14:20:21 -0000       1.31
@@ -169,12 +169,14 @@
     mutable server_users : int list option;
     mutable server_banner : string;
     mutable server_preferred : bool;
+    mutable server_master : bool;
     mutable server_version : string;
     mutable server_max_users : int64;
     mutable server_soft_limit : int64;
     mutable server_hard_limit : int64;
     mutable server_lowid_users : int64;
     mutable server_ping : int;
+    mutable server_published_files : int;
 
   } 
 

Index: src/daemon/driver/driverCommands.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverCommands.ml,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -b -r1.180 -r1.181
--- src/daemon/driver/driverCommands.ml 1 Oct 2006 17:53:59 -0000       1.180
+++ src/daemon/driver/driverCommands.ml 8 Oct 2006 14:20:21 -0000       1.181
@@ -764,6 +764,23 @@
         ""
     ), "<num> :\t\t\tprint banner of connected server <num>";
 
+    "server_shares", Arg_one (fun num o ->
+       if user2_is_admin o.conn_user.ui_user_name then
+        let s = server_find (int_of_string num) in
+        (match server_state s with
+           Connected _ -> let list = ref [] in
+           List.iter (fun f -> 
+             match file_shared f with
+               None -> ()
+             | Some sh -> list := (as_shared_impl sh) :: !list)
+             (server_published s);
+           print_upstats o !list (Some s)
+         | _ -> ()
+       )
+       else print_command_result o o.conn_buf "You are not allowed to use this 
command";
+       _s ""
+    ), "<num> :\t\t\tshow list of files published on server <num>";
+
     "c", Arg_multiple (fun args o ->
         let buf = o.conn_buf in
         match args with
@@ -2188,108 +2205,16 @@
               html_mods_table_one_row buf "upstatsTable" "upstats" [
                 ("", "srh", "You are not allowed to see upload statistics") ]
             else
-              Printf.bprintf buf "You are not allowed to see upload 
statistics\n"
+              print_command_result o buf "You are not allowed to see upload 
statistics"
           end
         else
         begin
-
-        if use_html_mods o then begin
-
-if !!html_mods_use_js_tooltips then Printf.bprintf buf 
-"\\<div id=\\\"object1\\\" style=\\\"position:absolute; 
background-color:FFFFDD;color:black;border-color:black;border-width:20;font-size:8pt;
 visibility:show; left:25px; top:
--100px; z-index:+1\\\" onmouseover=\\\"overdiv=1;\\\"  
onmouseout=\\\"overdiv=0; 
setTimeout(\\\'hideLayer()\\\',1000)\\\"\\>\\&nbsp;\\</div\\>";
-
-            Printf.bprintf buf "\\<div class=\\\"upstats\\\"\\>";
-            html_mods_table_one_row buf "upstatsTable" "upstats" [
-              ("", "srh", Printf.sprintf "Session: %s uploaded | Shared(%d): 
%s\n"
-                (size_of_int64 !upload_counter) !nshared_files (size_of_int64 
!nshared_bytes)); ]
-          end
-        else begin
-            Printf.bprintf buf "Upload statistics:\n";
-            Printf.bprintf buf "Session: %s uploaded | Shared(%d): %s\n"
-              (size_of_int64 !upload_counter) !nshared_files (size_of_int64 
!nshared_bytes)
-          end;
         let list = ref [] in
         shared_iter (fun s ->
             let impl = as_shared_impl s in
             list := impl :: !list
         );
-
-        if use_html_mods o then
-          html_mods_table_header buf "upstatsTable" "upstats" [
-            ( "1", "srh", "Total file requests", "Reqs" ) ;
-            ( "1", "srh", "Total bytes sent", "Total" ) ;
-            ( "1", "srh", "Upload Ratio", "UPRatio" ) ;
-            ( "0", "srh", "Preview", "P" ) ;
-            ( "0", "srh", "Filename", "Filename" );
-            ( "0", "srh", "Statistic links", "Stats" ) ]
-        else
-          begin
-            Printf.bprintf buf " Requests |  Bytes   | Uploaded | File\n";
-            Printf.bprintf buf 
"----------+----------+----------+----------------------------------------------------\n";
-          end;
-
-        let counter = ref 0 in
-
-        let list = Sort.list (fun f1 f2 ->
-              (f1.impl_shared_requests = f2.impl_shared_requests &&
-                f1.impl_shared_uploaded > f2.impl_shared_uploaded) ||
-              (f1.impl_shared_requests > f2.impl_shared_requests )
-          ) !list in
-
-        List.iter (fun impl ->
-            if use_html_mods o then
-              begin
-                incr counter;
-
-                let ed2k = file_print_ed2k_link
-                    (Filename.basename impl.impl_shared_codedname)
-                  impl.impl_shared_size impl.impl_shared_id in
-
-                Printf.bprintf buf "\\<tr class=\\\"%s\\\""
-                  (if (!counter mod 2 == 0) then "dl-1" else "dl-2";);
-
-          (if !!html_mods_use_js_tooltips then
-                        Printf.bprintf buf " 
onMouseOver=\\\"mOvr(this);setTimeout('popLayer(\\\\\'%s<br>%s\\\\\')',%d);setTimeout('hideLayer()',%d);return
 true;\\\" 
onMouseOut=\\\"mOut(this);hideLayer();setTimeout('hideLayer()',%d)\\\"\\>"
-                        (Http_server.html_real_escaped (Filename.basename 
impl.impl_shared_codedname))
-                       (match impl.impl_shared_magic with
-                          None -> ""
-                        | Some magic -> "File type: " ^ 
(Http_server.html_real_escaped magic) ^ "<br>")
-                       !!html_mods_js_tooltips_wait
-                       !!html_mods_js_tooltips_timeout
-                       !!html_mods_js_tooltips_wait
-                        else Printf.bprintf buf " 
onMouseOver=\\\"mOvr(this);return true;\\\" onMouseOut=\\\"mOut(this);\\\"\\>");
-
-                let uploaded = Int64.to_float impl.impl_shared_uploaded in
-                let size = Int64.to_float impl.impl_shared_size in
-
-                html_mods_td buf [
-                  ("", "sr ar", Printf.sprintf "%d" impl.impl_shared_requests);
-                  ("", "sr ar", size_of_int64 impl.impl_shared_uploaded);
-                  ("", "sr ar", Printf.sprintf "%5.1f" ( if size < 1.0 then 
0.0 else (uploaded *. 100.) /. size));
-                  ("", "sr", Printf.sprintf "\\<a 
href=\\\"preview_upload?q=%d\\\"\\>P\\</a\\>"
-                       impl.impl_shared_num);
-                  ("", "sr", (if impl.impl_shared_id = Md4.null then
-                    (Filename.basename impl.impl_shared_codedname)
-                  else
-                    Printf.sprintf "\\<a href=\\\"%s\\\"\\>%s\\</a\\>"
-                      ed2k (shorten (Filename.basename 
impl.impl_shared_codedname) !!max_name_len)));
-                  ("", "sr", (if impl.impl_shared_id = Md4.null then "" else
-                    Printf.sprintf "\\<a 
href=\\\"http://tothbenedek.hu/ed2kstats/ed2k?hash=%s\\\"\\>%s\\</a\\>
-\\<a href=\\\"http://bitzi.com/lookup/ed2k:%s\\\"\\>%s\\</a\\>"
-                      (Md4.to_string impl.impl_shared_id) "T1"
-                      (Md4.to_string impl.impl_shared_id) "B")) ];
-                Printf.bprintf buf "\\</tr\\>\n";
-              end
-            else
-              Printf.bprintf buf "%9d | %8s | %7s%% | %-50s\n"
-               (impl.impl_shared_requests)
-              (size_of_int64 impl.impl_shared_uploaded)
-              (Printf.sprintf "%3.1f" ((Int64.to_float 
impl.impl_shared_uploaded *. 100.) /. Int64.to_float impl.impl_shared_size))
-              (shorten (Filename.basename impl.impl_shared_codedname) 
!!max_name_len);
-        ) list;
-
-        if use_html_mods o then Printf.bprintf buf 
"\\</table\\>\\</div\\>\\</div\\>"
+           print_upstats o !list None;
         end;
         _s ""
     ), ":\t\t\t\tstatistics on upload";

Index: src/daemon/driver/driverInteractive.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverInteractive.ml,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -b -r1.107 -r1.108
--- src/daemon/driver/driverInteractive.ml      8 Oct 2006 14:12:13 -0000       
1.107
+++ src/daemon/driver/driverInteractive.ml      8 Oct 2006 14:20:21 -0000       
1.108
@@ -21,6 +21,8 @@
 
 open Printf2
 open CommonClient
+open CommonShared
+open CommonServer
 open CommonNetwork
 open CommonResult
 open CommonFile
@@ -2383,3 +2385,117 @@
        shorten fileinfo.file_name 80;
        string_of_int nc |]
     ) sorted_score_list)
+
+let print_upstats o list server =
+  let buf = o.conn_buf in
+  if use_html_mods o then
+    begin
+      if !!html_mods_use_js_tooltips then Printf.bprintf buf 
+"\\<div id=\\\"object1\\\" style=\\\"position:absolute; 
background-color:FFFFDD;color:black;border-color:black;border-width:20;font-size:8pt;
 visibility:show; left:25px; top:
+-100px; z-index:+1\\\" onmouseover=\\\"overdiv=1;\\\"  
onmouseout=\\\"overdiv=0; 
setTimeout(\\\'hideLayer()\\\',1000)\\\"\\>\\&nbsp;\\</div\\>";
+
+      Printf.bprintf buf "\\<div class=\\\"upstats\\\"\\>";
+      match server with
+       None ->
+         html_mods_table_one_row buf "upstatsTable" "upstats" [
+           ("", "srh", Printf.sprintf "Session: %s uploaded | Shared(%d): %s\n"
+           (size_of_int64 !upload_counter) !nshared_files (size_of_int64 
!nshared_bytes)); ]
+      | Some s -> let info = server_info s in
+         html_mods_table_one_row buf "upstatsTable" "upstats" [
+           ("", "srh", Printf.sprintf "%d files shared on %s (%s:%s)"
+              info.G.server_published_files info.G.server_name
+              (Ip.string_of_addr info.G.server_addr)
+              (string_of_int info.G.server_port)); ]
+    end
+  else
+    begin
+      Printf.bprintf buf "Upload statistics:\n";
+      Printf.bprintf buf "Session: %s uploaded | Shared(%d): %s\n"
+       (size_of_int64 !upload_counter) !nshared_files (size_of_int64 
!nshared_bytes)
+    end;
+
+  if use_html_mods o then
+    html_mods_table_header buf "upstatsTable" "upstats" [
+      ( "1", "srh", "Total file requests", "Reqs" ) ;
+      ( "1", "srh", "Total bytes sent", "Total" ) ;
+      ( "1", "srh", "Upload Ratio", "UPRatio" ) ;
+      ( "0", "srh", "Preview", "P" ) ;
+      ( "0", "srh", "Filename", "Filename" );
+      ( "0", "srh", "Statistic links", "Stats" );
+      ( "0", "srh", "Published on servers", "Publ" ) ]
+  else
+    begin
+      Printf.bprintf buf " Requests |  Bytes   | Uploaded | File\n";
+      Printf.bprintf buf 
"----------+----------+----------+----------------------------------------------------\n";
+    end;
+
+  html_mods_cntr_init ();
+  let list = Sort.list (fun f1 f2 ->
+      (f1.impl_shared_requests = f2.impl_shared_requests &&
+       f1.impl_shared_uploaded > f2.impl_shared_uploaded) ||
+      (f1.impl_shared_requests > f2.impl_shared_requests )
+    ) list in
+
+  List.iter (fun impl ->
+    if use_html_mods o then
+      begin
+       let published = List.length impl.impl_shared_servers in
+       let ed2k = file_print_ed2k_link
+         (Filename.basename impl.impl_shared_codedname)
+         impl.impl_shared_size impl.impl_shared_id in
+
+       Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"" (html_mods_cntr ());
+       (if !!html_mods_use_js_tooltips then
+          Printf.bprintf buf " 
onMouseOver=\\\"mOvr(this);setTimeout('popLayer(\\\\\'%s<br>%s%s\\\\\')',%d);setTimeout('hideLayer()',%d);return
 true;\\\" 
onMouseOut=\\\"mOut(this);hideLayer();setTimeout('hideLayer()',%d)\\\"\\>"
+           (Http_server.html_real_escaped (Filename.basename 
impl.impl_shared_codedname))
+           (match impl.impl_shared_magic with
+              None -> ""
+            | Some magic -> "File type: " ^ (Http_server.html_real_escaped 
magic) ^ "<br>")
+           (if impl.impl_shared_servers = [] then "" else
+              Printf.sprintf "<br>Published on %d %s<br>%s"
+               published (if published = 1 then "server" else "servers")
+               (let listbuf = Buffer.create 100 in
+                  List.iter (fun s -> let info = server_info s in
+                    Printf.bprintf listbuf "%s (%s:%s%s)<br>"
+                       info.server_name
+                       (Ip.string_of_addr info.server_addr)
+                       (string_of_int info.server_port)
+                       (if info.server_realport <> 0
+                          then "(" ^ (string_of_int info.server_realport) ^ 
")" else "")
+                       ) impl.impl_shared_servers;
+                Buffer.contents listbuf))
+               !!html_mods_js_tooltips_wait
+               !!html_mods_js_tooltips_timeout
+               !!html_mods_js_tooltips_wait
+        else Printf.bprintf buf " onMouseOver=\\\"mOvr(this);return true;\\\" 
onMouseOut=\\\"mOut(this);\\\"\\>");
+
+       let uploaded = Int64.to_float impl.impl_shared_uploaded in
+       let size = Int64.to_float impl.impl_shared_size in
+
+       html_mods_td buf [
+         ("", "sr ar", Printf.sprintf "%d" impl.impl_shared_requests);
+         ("", "sr ar", size_of_int64 impl.impl_shared_uploaded);
+         ("", "sr ar", Printf.sprintf "%5.1f" ( if size < 1.0 then 0.0 else 
(uploaded *. 100.) /. size));
+         ("", "sr", Printf.sprintf "\\<a 
href=\\\"preview_upload?q=%d\\\"\\>P\\</a\\>" impl.impl_shared_num);
+         ("", "sr", (if impl.impl_shared_id = Md4.null then
+                       (Filename.basename impl.impl_shared_codedname)
+                     else
+                       Printf.sprintf "\\<a href=\\\"%s\\\"\\>%s\\</a\\>"
+                         ed2k (shorten (Filename.basename 
impl.impl_shared_codedname) !!max_name_len)));
+         ("", "sr", (if impl.impl_shared_id = Md4.null then "" else
+                       Printf.sprintf "\\<a 
href=\\\"http://tothbenedek.hu/ed2kstats/ed2k?hash=%s\\\"\\>%s\\</a\\>
+\\<a href=\\\"http://bitzi.com/lookup/ed2k:%s\\\"\\>%s\\</a\\>"
+                      (Md4.to_string impl.impl_shared_id) "T1"
+                      (Md4.to_string impl.impl_shared_id) "B"));
+         ("", "sr ar", Printf.sprintf "%d" published ) ];
+       Printf.bprintf buf "\\</tr\\>\n";
+      end
+    else
+      Printf.bprintf buf "%9d | %8s | %7s%% | %-50s\n"
+       (impl.impl_shared_requests)
+       (size_of_int64 impl.impl_shared_uploaded)
+       (Printf.sprintf "%3.1f" ((Int64.to_float impl.impl_shared_uploaded *. 
100.) /. Int64.to_float impl.impl_shared_size))
+       (shorten (Filename.basename impl.impl_shared_codedname) !!max_name_len)
+  ) list;
+
+  if use_html_mods o then Printf.bprintf buf "\\</table\\>\\</div\\>\\</div\\>"

Index: src/networks/bittorrent/bTInteractive.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTInteractive.ml,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -b -r1.116 -r1.117
--- src/networks/bittorrent/bTInteractive.ml    8 Oct 2006 14:02:05 -0000       
1.116
+++ src/networks/bittorrent/bTInteractive.ml    8 Oct 2006 14:20:22 -0000       
1.117
@@ -1172,6 +1172,11 @@
   file_ops.op_file_cancel <- op_file_cancel;
   file_ops.op_file_info <- op_file_info;
   file_ops.op_file_save_as <- (fun file name -> ());
+  file_ops.op_file_shared <- (fun file ->
+      match file.file_shared with
+        None -> None
+      | Some sh -> Some (as_shared sh)
+  );
 
   network.op_network_gui_message <- op_gui_message;
   network.op_network_connected <- op_network_connected;

Index: src/networks/bittorrent/bTShare.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTShare.ml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- src/networks/bittorrent/bTShare.ml  12 May 2006 21:08:30 -0000      1.3
+++ src/networks/bittorrent/bTShare.ml  8 Oct 2006 14:20:22 -0000       1.4
@@ -45,6 +45,7 @@
           impl_shared_val = file;
           impl_shared_requests = 0;
           impl_shared_magic = None;
+          impl_shared_servers = [];
         } in
         file.file_shared <- Some impl;
         incr CommonGlobals.nshared_files;

Index: src/networks/donkey/donkeyClient.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyClient.ml,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -b -r1.102 -r1.103
--- src/networks/donkey/donkeyClient.ml 1 Oct 2006 17:54:00 -0000       1.102
+++ src/networks/donkey/donkeyClient.ml 8 Oct 2006 14:20:22 -0000       1.103
@@ -2473,11 +2473,11 @@
           (if is_connecting_server then
             ( try 
                 let s = Hashtbl.find servers_by_key from_ip in
-                Printf.sprintf " %s (%s)" s.server_name (Ip.to_string 
s.server_ip)
+                Printf.sprintf " %s (%s)" s.server_name (string_of_server s)
               with _ ->
                 try 
                   let s = Hashtbl.find servers_by_key connecting_server in
-                  Printf.sprintf " %s (%s)" s.server_name (Ip.to_string 
s.server_ip)
+                  Printf.sprintf " %s (%s)" s.server_name (string_of_server s)
                 with _ -> "Unknown server"
             )
            else ""

Index: src/networks/donkey/donkeyGlobals.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyGlobals.ml,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -b -r1.100 -r1.101
--- src/networks/donkey/donkeyGlobals.ml        1 Oct 2006 17:54:00 -0000       
1.100
+++ src/networks/donkey/donkeyGlobals.ml        8 Oct 2006 14:20:22 -0000       
1.101
@@ -183,7 +183,6 @@
 let udp_sock = ref (None: UdpSocket.t option)
 let listen_sock = ref (None : TcpServerSocket.t option)
 let porttest_sock = ref (None : TcpBufferedSocket.t option)
-let new_shared = ref false
 
 (*************************************************************************)
 (*                                                                       *)
@@ -228,7 +227,6 @@
 let shared_files_info = (Hashtbl.create 127
     : (string * int64 * float, shared_file_info) Hashtbl.t)
 let shared_files = ref ([] : file_to_share list)
-let new_shared_files = ref []
 
 let udp_servers_replies = (Hashtbl.create 127 : (Md4.t, server) Hashtbl.t)
 
@@ -428,10 +426,7 @@
                 Verification (Array.of_list (List.map (fun md4 -> Ed2k md4) 
md4s))
             );
             CommonSwarming.set_verified swarmer (fun nblocks num ->
-                if nblocks = 1 then begin
-                    new_shared_files := file :: !new_shared_files;
-                    file_must_update file
-                  end)
+                if nblocks = 1 then file_must_update file)
       );
 
       update_best_name file;
@@ -518,6 +513,7 @@
         server_lowid_users = None;
         server_soft_limit = None;
         server_hard_limit = None;
+        server_sent_shared = [];
         server_max_users = None;
         server_last_ping = 0.;
         server_ping = 0;
@@ -700,6 +696,8 @@
     | Invalid_address _ -> ""
   )
 
+let string_of_server s =
+  Printf.sprintf "%s:%d" (Ip.to_string s.server_ip) s.server_port
 
 let set_client_name c name md4 =
   if name <> c.client_name || c.client_md4 <> md4 then begin
@@ -811,7 +809,6 @@
   Printf.bprintf buf "  udp_servers_list: %d\n" (List.length 
!udp_servers_list);
   Printf.bprintf buf "  interesting_clients: %d\n" (List.length 
!interesting_clients);
   Printf.bprintf buf "  shared_files: %d\n" (List.length !shared_files);
-  Printf.bprintf buf "  new_shared_files: %d\n" (List.length 
!new_shared_files);
   Printf.bprintf buf "  servers_by_key: %d\n" (Hashtbl.length servers_by_key);
   Printf.bprintf buf "  banned_ips: %d\n" (Hashtbl.length banned_ips);
   Printf.bprintf buf "  old_requests: %d\n" (Hashtbl.length old_requests);

Index: src/networks/donkey/donkeyInteractive.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyInteractive.ml,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -b -r1.128 -r1.129
--- src/networks/donkey/donkeyInteractive.ml    1 Oct 2006 17:54:00 -0000       
1.128
+++ src/networks/donkey/donkeyInteractive.ml    8 Oct 2006 14:20:22 -0000       
1.129
@@ -725,8 +725,8 @@
     "id", Arg_none (fun o ->
         let buf = o.conn_buf in
         List.iter (fun s ->
-            Printf.bprintf buf "For %s:%d (%s) --->   %s\n"
-              (Ip.to_string s.server_ip) s.server_port s.server_name
+            Printf.bprintf buf "For %s (%s) --->   %s\n"
+              (string_of_server s) s.server_name
               (match s.server_cid with
                 None -> "waiting"
               | Some ip ->
@@ -1078,6 +1078,8 @@
           P.server_description = s.server_description;
           P.server_banner = s.server_banner;
           P.server_preferred = s.server_preferred;
+          P.server_master = s.server_master;
+          P.server_published_files = (List.length s.server_sent_shared);
           P.server_version = s.server_version;
           P.server_max_users = (match s.server_max_users with None -> 0L | 
Some v -> v);
           P.server_soft_limit = (match s.server_soft_limit with None -> 0L | 
Some v -> v);
@@ -1177,6 +1179,9 @@
   server_ops.op_server_users <- (fun s ->
       List2.tail_map (fun u -> as_user u.user_user) s.server_users)    ;
 
+  server_ops.op_server_published <- (fun s ->
+      List.map (fun f -> as_file f) s.server_sent_shared);
+
   server_ops.op_server_cid <- (fun s -> ip_of_server_cid s);
 
   server_ops.op_server_low_id <- (fun s -> low_id (ip_of_server_cid s));
@@ -1196,6 +1201,11 @@
       add_file_filenames (as_file file) name;
       set_file_best_name (as_file file) name "" 0
   );
+  file_ops.op_file_shared <- (fun file ->
+      match file.file_shared with
+       None -> None
+      | Some sh -> Some (as_shared sh)
+  );
   file_ops.op_file_set_format <- (fun file format ->
       file.file_format <- format);
   file_ops.op_file_check <- op_file_check;

Index: src/networks/donkey/donkeyMain.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyMain.ml,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- src/networks/donkey/donkeyMain.ml   1 Oct 2006 17:54:00 -0000       1.58
+++ src/networks/donkey/donkeyMain.ml   8 Oct 2006 14:20:22 -0000       1.59
@@ -69,7 +69,6 @@
   clean_join_queue_tables ()
 
 let fivemin_timer timer =
-  DonkeyShare.send_new_shared ();
   clients_root := []
 
 let second_timer timer =
@@ -95,10 +94,7 @@
  (try
       DonkeyServers.query_locations_timer ();
     with _ -> ());
-  (List.iter (fun file -> DonkeyShare.must_share_file file) !new_shared_files;
-  new_shared_files := [])
-(*  DonkeyIndexer.add_to_local_index_timer () *)
-
+  DonkeyShare.send_new_shared ()
 
 let local_login () =
   if !!login = "" then !!global_login else !!login

Index: src/networks/donkey/donkeyOneFile.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyOneFile.ml,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- src/networks/donkey/donkeyOneFile.ml        19 Sep 2006 17:07:43 -0000      
1.43
+++ src/networks/donkey/donkeyOneFile.ml        8 Oct 2006 14:20:22 -0000       
1.44
@@ -111,8 +111,11 @@
   match file.file_shared with
     None -> ()
   | Some s -> 
-      if !verbose_share then
-        lprintf_nl "unshare_file %s" file.file_diskname;
+      if !verbose_share || !verbose then
+        lprintf_nl "Unsharing file %s" (file_best_name file);
+      List.iter (fun s ->
+        s.server_sent_shared <- List2.removeq file s.server_sent_shared;
+      ) (connected_servers ());
       file.file_shared <- None;
       decr nshared_files;
       CommonShared.shared_calculate_total_bytes ();

Index: src/networks/donkey/donkeyOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyOptions.ml,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- src/networks/donkey/donkeyOptions.ml        4 Sep 2006 21:30:27 -0000       
1.52
+++ src/networks/donkey/donkeyOptions.ml        8 Oct 2006 14:20:22 -0000       
1.53
@@ -100,8 +100,7 @@
     int_option 1
 
 let walker_server_lifetime = define_expert_option donkey_section 
["walker_server_lifetime"]
-  "The maximal delay a connection with a server should last when walking
-  through the list (should be greater than become_master_delay)"
+  "The maximal delay a connection with a server should last when walking 
through the list"
     int_option 300
 
 let log_clients_on_console = define_expert_option donkey_section 
["log_clients_on_console"]
@@ -260,10 +259,6 @@
   "port for overnet"
     int_option (2000 + Random.int 20000)
 
-let become_master_delay = define_expert_option donkey_section 
["become_master_delay"]
-  "(only for development tests)"
-    int_option 120
-
 let options_version = define_expert_option donkey_section ["options_version"]
   "(internal option)"
     int_option 3

Index: src/networks/donkey/donkeyProtoCom.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyProtoCom.ml,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- src/networks/donkey/donkeyProtoCom.ml       19 May 2006 23:43:54 -0000      
1.32
+++ src/networks/donkey/donkeyProtoCom.ml       8 Oct 2006 14:20:22 -0000       
1.33
@@ -341,7 +341,7 @@
       if !verbose_share || !verbose then
          lprintf_nl "Sending %d share(s) to server %s:%d%s"
           nfiles (Ip.to_string (peer_ip sock)) (peer_port sock)
-          (if compressed then "(zlib)" else "");
+          (if compressed then " (zlib)" else "");
       Buffer.reset buf;
       let s_c =
         if compressed then

Index: src/networks/donkey/donkeyServers.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyServers.ml,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- src/networks/donkey/donkeyServers.ml        1 Sep 2006 16:25:15 -0000       
1.59
+++ src/networks/donkey/donkeyServers.ml        8 Oct 2006 14:20:22 -0000       
1.60
@@ -34,6 +34,7 @@
 open CommonOptions
 open CommonGlobals
 open CommonSources
+open CommonShared
 
 open DonkeyMftp
 open DonkeyImport
@@ -210,6 +211,30 @@
 
 
 let disconnect_server s reason =
+  let choose_new_master_server s =
+    match !DonkeyGlobals.master_server with
+      Some ss when s == ss ->
+       DonkeyGlobals.master_server := None;
+        (try
+         DonkeyGlobals.master_server :=
+           Some (List.find (fun s -> s.server_master) !servers_list);
+         lprintf_nl "changed main master server from %s to %s"
+           (string_of_server ss) (string_of_server s)
+        with Not_found -> ())
+    | _ -> ();
+  in
+(* remove this server from the list of servers a file was published to *)
+  let remove_server_from_shared_files s =
+    List.iter (fun file ->
+      shared_iter (fun sh ->
+        let impl = as_shared_impl sh in
+         impl.impl_shared_servers <-
+           List2.removeq (as_server s.server_server) impl.impl_shared_servers)
+    ) s.server_sent_shared;
+    s.server_sent_shared <- []
+  in
+  choose_new_master_server s;
+  remove_server_from_shared_files s;
   match s.server_sock with
       NoConnection -> ()
     | ConnectionWaiting token ->
@@ -225,16 +250,11 @@
         s.server_users <- [];
         set_server_state s (NotConnected (reason, -1));
         s.server_master <- false;
-        (match !DonkeyGlobals.master_server with
-          | Some ss when s == ss ->
-              DonkeyGlobals.master_server := None;
-          | _ -> ());
         s.server_banner <- "";
         s.server_sent_all_queries <- false;
         remove_connecting_server s;
         remove_connected_server s
 
-
 let server_handler s sock event =
   match event with
       BASIC_EVENT (CLOSED r) ->
@@ -282,8 +302,8 @@
 
   | M.MessageReq msg ->
       if !last_message_sender <> server_num s then begin
-          let server_header = Printf.sprintf "\n+-- From server %s [%s:%d] 
------"
-              s.server_name (Ip.to_string s.server_ip) s.server_port in
+          let server_header = Printf.sprintf "\n+-- From server %s [%s] ------"
+              s.server_name (string_of_server s) in
           CommonEvent.add_event (Console_message_event (Printf.sprintf "%s\n" 
server_header));
           if !CommonOptions.verbose_msg_servers then
       lprintf_nl "%s" server_header;
@@ -297,7 +317,7 @@
 
   | M.ServerListReq l ->
       if !!update_server_list_server then begin
-        if !verbose_msg_servers then lprintf_nl "Received serverlist from 
server";
+        if !verbose_msg_servers then lprintf_nl "Received %d servers from 
server" (List.length l);
         let module Q = M.ServerList in
         List.iter (fun s ->
             safe_add_server s.Q.ip s.Q.port
@@ -339,8 +359,8 @@
       s.server_nfiles <- Some (Int64.of_int files);
       if (users < !!min_users_on_server && not s.server_preferred) then
         begin
-          lprintf_nl "%s:%d remove server min_users_on_server limit hit!"
-            (Ip.to_string s.server_ip) s.server_port;
+          lprintf_nl "%s remove server min_users_on_server limit hit!"
+            (string_of_server s);
 
           disconnect_server s Closed_for_timeout;
           server_remove (as_server s.server_server);
@@ -618,8 +638,7 @@
         if ls < min_last_conn && s.server_sock = NoConnection
           && not s.server_preferred then begin
           if !verbose then
-            lprintf_nl "old servers: Server too old: %s:%d"
-              (Ip.to_string s.server_ip) s.server_port;
+            lprintf_nl "old servers: Server too old: %s" (string_of_server s);
 
           to_remove := s :: !to_remove
         end
@@ -674,16 +693,14 @@
                   if connection_can_try s.server_connection_control then
                     begin
                       if !verbose then
-                        lprintf_nl "WALKER: try connect %s"
-                          (Ip.to_string s.server_ip);
+                        lprintf_nl "WALKER: try connect %s" (string_of_server 
s);
                       connect_server s
                     end
                   else
                     begin
                       delayed_list := s :: !delayed_list;
                       if !verbose then
-                        lprintf_nl "WALKER: connect %s delayed"
-                          (Ip.to_string s.server_ip);
+                        lprintf_nl "WALKER: connect %s delayed" 
(string_of_server s);
                     end
               | _ -> ()
 
@@ -754,7 +771,7 @@
     tag1 := false;
     tag2 := false
         end;
-        lprintf " %s" (Ip.to_string s.server_ip)
+             lprintf " %s" (string_of_server s)
       end;
             masters := s :: !masters
         | _ -> s.server_master <- false
@@ -772,8 +789,7 @@
         masters := s :: !masters;
         masters := List.rev (List.sort compare_servers !masters);
 
-        server_send_share s.server_has_zlib sock
-          (DonkeyShare.all_shared ())
+       DonkeyGlobals.master_server := Some s;
     )
   in
 
@@ -786,7 +802,7 @@
     if !nconnected_servers > max_allowed_connected_servers then
       begin
         if !verbose_location then
-            lprintf_nl "master servers: disconnect %s" (Ip.to_string 
s.server_ip);
+            lprintf_nl "master servers: disconnect %s" (string_of_server s);
         nconnected_servers := !nconnected_servers - 3;
         do_if_connected  s.server_sock (fun sock ->
             (* We will disconnect from this server.
@@ -805,23 +821,14 @@
             - connection_last_conn s.server_connection_control
           in
           if !verbose_location then
-              lprintf_nl "master servers: Checking ip:%s, users: %Ld, ct:%d"
-          (Ip.to_string s.server_ip)
+              lprintf_nl "master servers: Checking %s, users: %Ld, ct:%d"
+               (string_of_server s)
          (match s.server_nusers with None -> 0L | Some v -> v)
          connection_time;
-          if not s.server_master
-            && (s.server_preferred
-                 || connection_time > !!become_master_delay
-               )
-            then
+          if not s.server_master && s.server_preferred then
               begin
                 if (!nmasters < max_allowed_connected_servers) then
-                  begin
-                    if !verbose_location then
-                        lprintf_nl "master servers: raising  %s"
-                                  (Ip.to_string s.server_ip);
                     make_master s
-                  end
                 else if s.server_sent_all_queries then
                   match !masters with
                       [] -> disconnect_old_server s
@@ -847,7 +854,7 @@
                               if !verbose_location then
                                 lprintf_nl
                                   "master servers: raising %s, disconnected %s"
-                                  (Ip.to_string s.server_ip) (Ip.to_string 
ss.server_ip);
+                                  (string_of_server s) (string_of_server ss);
                               ss.server_master <- false;
                               masters := tail;
                               make_master s

Index: src/networks/donkey/donkeyShare.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyShare.ml,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- src/networks/donkey/donkeyShare.ml  25 Sep 2006 22:37:57 -0000      1.53
+++ src/networks/donkey/donkeyShare.ml  8 Oct 2006 14:20:22 -0000       1.54
@@ -39,13 +39,10 @@
 
 module VB = VerificationBitmap
 
-let new_shared_files = ref []
-
 let must_share_file file codedname has_old_impl =
   match file.file_shared with
   | Some _ -> ()
   | None ->
-      new_shared := true;
       let full_name = file_disk_name file in
       let magic =
         match Magic.M.magic_fileinfo full_name false with
@@ -65,9 +62,9 @@
           impl_shared_val = file;
           impl_shared_requests = 0;
           impl_shared_magic = magic;
+          impl_shared_servers = []
         } in
       file.file_shared <- Some impl;
-      new_shared_files := file :: !new_shared_files;
       incr CommonGlobals.nshared_files;
       CommonShared.shared_calculate_total_bytes ();
       match has_old_impl with
@@ -162,41 +159,72 @@
         None -> ()
       | Some _ ->  shared_files := file :: !shared_files
   ) files_by_md4;
-  if !verbose_share then lprintf_nl "%d files shared" (List.length 
!shared_files);
+  if !verbose_share then lprintf_nl "scanned shared files, %d files found" 
(List.length !shared_files);
   !shared_files
 
-(* Check whether new files are shared, and send them to connected servers.
-   Do it only once per 5 minutes to prevent sending to many times all files.
-   Change: Just send *new* shared files to servers, they never forget a
-     clients files until disconnection.
-   Should I only do it for master servers, no ?
-*)
+(* publish shared files to servers, called once per minute *)
 let send_new_shared () =
-  let tag = ref false in
-  if !new_shared then
-    begin
-      new_shared := false;
-      if !new_shared_files <> [] then
-        begin
+(* emule sends 200 files in this period to avoid server blacklist *)
+  let limit_per_minute = 200 in
+
+(* sort list to publish least published files first *)
+  let ( |> ) x f = f x in
+  let all_shared =
+    all_shared ()
+    |> List.map (fun e -> 
+       (match e.file_shared with
+         Some s -> List.length s.impl_shared_servers
+        | _ -> 0) , e)
+    |> List.sort (fun (a,_) (b,_) -> compare a b)
+    |> List.map snd
+  in
+
+(* iter through connected servers *)
           List.iter (fun s ->
-            if s.server_master then
+
+(* publish files only on master servers and do not publish more files than 
hard limit allows *)
+    if s.server_master &&
+      (match s.server_hard_limit with
+         Some v when (Int64.to_int v) < List.length s.server_sent_shared -> 
false
+       | _ -> true) then
+
+(* iter through all shared files and check if the file is already published on 
the current server
+   build a list of files_to_send with yet unpublished files *)
+      begin
+       let files_to_send = ref [] in
+        List.iter (fun f ->
+          match f.file_shared with
+           Some impl ->
+             if not (List.mem (CommonServer.as_server s.server_server) 
impl.impl_shared_servers)
+               && List.length !files_to_send < limit_per_minute then
+             files_to_send := f :: !files_to_send
+           | _ -> () (* this case never happens *)
+       ) all_shared;
+
+       if !files_to_send <> [] then
               begin
                 if !verbose_share || !verbose then
-                  lprintf_nl "send_new_shared: found master server %s:%d"
-                   (Ip.to_string s.server_ip) s.server_port;
-                tag := true;
+             lprintf_nl "publishing %d new files to %s (holds %d files)"
+               (List.length !files_to_send) (string_of_server s)
+               (List.length s.server_sent_shared);
+
+(* publish files on server *)
                 do_if_connected s.server_sock (fun sock ->
-                  server_send_share s.server_has_zlib sock !new_shared_files)
-              end
-          ) (connected_servers ());
-          if !tag && (!verbose_share || !verbose) then
-              lprintf_nl "send_new_shared: Sent %d new shared files to servers"
-                (List.length !new_shared_files);
-          new_shared_files := []
+             server_send_share s.server_has_zlib sock !files_to_send);
+
+(* append new published files to server structure *)
+           s.server_sent_shared <- !files_to_send @ s.server_sent_shared;
+
+(* iter through published files and append current server *)
+           List.iter (fun file ->
+             match file.file_shared with
+               Some impl -> impl.impl_shared_servers <-
+                 impl.impl_shared_servers @ [(CommonServer.as_server 
s.server_server)]
+             | _ -> ()) !files_to_send
+
         end
-      else
-          lprintf_nl "donkey send_new_share: No new shared files to send to 
servers"
     end
+  ) (connected_servers ());
 
 (*
 The problem: sh.shared_fd might be closed during the execution of the
@@ -326,6 +354,7 @@
               impl_shared_val = pre_shared;
               impl_shared_requests = 0;
               impl_shared_magic = magic;
+              impl_shared_servers = [];
             } and
             pre_shared = {
               shared_shared = impl;

Index: src/networks/donkey/donkeyTypes.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyTypes.ml,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- src/networks/donkey/donkeyTypes.ml  23 Sep 2006 20:29:47 -0000      1.48
+++ src/networks/donkey/donkeyTypes.ml  8 Oct 2006 14:20:22 -0000       1.49
@@ -430,7 +430,21 @@
         | Invalid_address _ -> failwith "Invalid address"
     end)
 
-type server = (*[]*){
+type file = {
+    file_file : file CommonFile.file_impl;
+    file_md4 : Md4.t;
+    mutable file_swarmer : CommonSwarming.t option;
+    mutable file_nchunks : int;
+    mutable file_nchunk_hashes : int;
+    mutable file_diskname : string;
+    mutable file_computed_md4s : Md4.t array;
+    mutable file_format : format;
+    mutable file_shared : file CommonShared.shared_impl option;
+    mutable file_sources : DonkeySources.file_sources_manager;
+    mutable file_comments : (Ip.t * string * int * string) list;
+  }
+
+and server = (*[]*){
     mutable server_server : server CommonServer.server_impl;
     mutable server_ip : Ip.t;
     mutable server_cid : Ip.t option;
@@ -470,6 +484,7 @@
     mutable server_soft_limit : int64 option;
     mutable server_hard_limit : int64 option;
     mutable server_max_users : int64 option;
+    mutable server_sent_shared : file list
   }
 
 
@@ -579,20 +594,6 @@
   int * (* last connection attempt *)
   int   (* booked client num *)
 
-and file = {
-    file_file : file CommonFile.file_impl;
-    file_md4 : Md4.t;
-    mutable file_swarmer : CommonSwarming.t option;
-    mutable file_nchunks : int;
-    mutable file_nchunk_hashes : int;
-    mutable file_diskname : string;
-    mutable file_computed_md4s : Md4.t array;
-    mutable file_format : format;
-    mutable file_shared : file CommonShared.shared_impl option;
-    mutable file_sources : DonkeySources.file_sources_manager;
-    mutable file_comments : (Ip.t * string * int * string) list;
-  }
-
 and file_to_share = {
     shared_name : string;
     shared_size : int64;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]