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: Tue, 06 Mar 2007 19:31:27 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       07/03/06 19:31:26

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonMessages.ml commonStats.ml 
                           commonTypes.ml 
        src/daemon/driver: driverCommands.ml driverInteractive.ml 
                           driverMain.ml 
        src/networks/bittorrent: bTStats.ml 
        src/networks/donkey: donkeyStats.ml 
        src/utils/net  : geoip.ml 

Log message:
        patch #5773

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1196&r2=1.1197
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonMessages.ml?cvsroot=mldonkey&r1=1.62&r2=1.63
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonStats.ml?cvsroot=mldonkey&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonTypes.ml?cvsroot=mldonkey&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverCommands.ml?cvsroot=mldonkey&r1=1.222&r2=1.223
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverInteractive.ml?cvsroot=mldonkey&r1=1.128&r2=1.129
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverMain.ml?cvsroot=mldonkey&r1=1.136&r2=1.137
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTStats.ml?cvsroot=mldonkey&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/donkey/donkeyStats.ml?cvsroot=mldonkey&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/net/geoip.ml?cvsroot=mldonkey&r1=1.6&r2=1.7

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1196
retrieving revision 1.1197
diff -u -b -r1.1196 -r1.1197
--- distrib/ChangeLog   4 Mar 2007 22:18:16 -0000       1.1196
+++ distrib/ChangeLog   6 Mar 2007 19:31:26 -0000       1.1197
@@ -14,6 +14,20 @@
 ChangeLog
 =========
 
+2007/03/06
+5773: Geoip: Country-based up-/download statistics
+- new ini file statistics.ini, to be used later for all statistics
+- new command "costats", accepts parameters:
+  without parameter it displays all countries where data was transfered to
+  parameter "all" displays all seen countries, countries where MLDonkey never
+  saw a client are not part of the statistics data
+  regular expressions can be used for country names/codes and continents,
+  like "costats *aus*" (Austria and Australia), "costats *europe* *africa*"
+- new command "countries" to print country database
+- new command "reset_costats" to reset country statistics
+- mem_stats support for modules CommonStats & Geoip
+- updated country database based on GeoIP 1.4.2 C-library
+
 2007/03/04
 5765: Change hard-coded maximum value for client_buffer_size
 - default stays at 500.000

Index: src/daemon/common/commonMessages.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonMessages.ml,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- src/daemon/common/commonMessages.ml 28 Jan 2007 20:39:59 -0000      1.62
+++ src/daemon/common/commonMessages.ml 6 Mar 2007 19:31:26 -0000       1.63
@@ -1067,6 +1067,9 @@
 <TD class=\"bu bbig\" title=\"Gnutella2 statistics\"
 onMouseOver=\"mOvr(this,'mOvr1');\" onMouseOut=\"mOut(this);\"
 onClick=\"mSub('fstatus','bw_stats');mSub('output','g2stats')\">Gnutella2</TD>
+<TD class=\"bu bbig\" title=\"Country statistics - all seen\"
+onMouseOver=\"mOvr(this,'mOvr1');\" onMouseOut=\"mOut(this);\"
+onClick=\"mSub('fstatus','bw_stats');mSub('output','costats 
all')\">Countries</TD>
 <TD class=\"bu bbig\" title=\"Memory statistics\"
 onMouseOver=\"mOvr(this,'mOvr1');\" onMouseOut=\"mOut(this);\"
 onClick=\"mSub('fstatus','bw_stats');mSub('output','mem_stats 0')\">Memory</TD>

Index: src/daemon/common/commonStats.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonStats.ml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- src/daemon/common/commonStats.ml    4 Mar 2007 21:26:35 -0000       1.5
+++ src/daemon/common/commonStats.ml    6 Mar 2007 19:31:26 -0000       1.6
@@ -17,7 +17,9 @@
 *)      
 
 open Int64ops
+open Gettext
 open Printf2
+open Options
 open CommonTypes
 open CommonGlobals
 open CommonInteractive
@@ -25,12 +27,115 @@
 
 type style = Old | New
 
-let global_count_upload n v =
+let _s x = _s "CommonStats" x
+let _b x = _b "CommonStats" x
+
+let define_option a b ?desc ?restart ?public ?internal c d e =
+  match desc with
+    None -> define_option a b (_s c) d e ?restart ?public ?internal
+  | Some desc -> define_option a b ~desc: (_s desc) (_s c) d e ?restart 
?public ?internal
+
+let statistics_ini = create_options_file "statistics.ini"
+
+let country_stats_section = file_section statistics_ini
+    ["Country statistics"] "Country-based traffic statistics"
+
+module CountryStatsOption = struct
+
+    let value_to_country v =
+      match v with
+      | Options.Module assocs ->
+          let int64v s = try value_to_int64 (List.assoc s assocs) with 
Not_found -> 0L in
+          let cc = value_to_string (List.assoc "country_code" assocs) in
+          let cn = try
+              Geoip.country_name_array.(Hashtbl.find Geoip.country_index cc)
+            with Not_found -> "??" in
+          let co = try
+              Geoip.country_continent_name_array.(Hashtbl.find 
Geoip.country_index cc)
+            with Not_found -> "??" in
+          { country_code = cc;
+            country_name = cn;
+            country_continent = co;
+            country_total_upload = int64v "country_upload";
+            country_total_download = int64v "country_download";
+            country_total_seen = int64v "country_seen";
+            country_session_upload = 0L;
+            country_session_download = 0L;
+            country_session_seen = 0L;
+          }
+      | _ -> failwith "Options: invalid country statistics"
+
+    let country_to_value c =
+      Options.Module (
+        ["country_code", string_to_value c.country_code] @
+        (if c.country_total_upload = 0L then [] else
+        ["country_upload", int64_to_value c.country_total_upload]) @
+        (if c.country_total_download = 0L then [] else
+        ["country_download", int64_to_value c.country_total_download]) @
+        (if c.country_total_seen = 0L then [] else
+        ["country_seen", int64_to_value c.country_total_seen])
+      )
+
+    let t = define_option_class "CountryStats" value_to_country 
country_to_value
+
+  end
+
+let country_stats_uptime = define_option country_stats_section ["guptime"]
+  "Uptime" int_option 0
+
+let country_stats = define_option country_stats_section ["country_stats"]
+  "Country-based traffic statistics" (list_option CountryStatsOption.t) []
+
+let country_stats_find cc =
+  try
+    List.find (fun c -> c.country_code = cc) !!country_stats
+  with Not_found ->
+    let rec cs = {
+      country_code = cc;
+      country_name = Geoip.country_name_array.(Hashtbl.find 
Geoip.country_index cc);
+      country_continent = Geoip.country_continent_name_array.(Hashtbl.find 
Geoip.country_index cc);
+      country_total_upload = 0L;
+      country_total_download = 0L;
+      country_total_seen = 0L;
+      country_session_upload = 0L;
+      country_session_download = 0L;
+      country_session_seen = 0L;
+    } in
+    country_stats =:= cs :: !!country_stats;
+    cs
+
+let country_upload ip v =
+  try
+    let cc,_ = Geoip.get_country ip in
+    let c = country_stats_find cc in
+    c.country_session_upload <- c.country_session_upload ++ v;
+    c.country_total_upload <- c.country_total_upload ++ v
+  with _ -> ()
+
+let country_download ip v =
+  try
+    let cc,_ = Geoip.get_country ip in
+    let c = country_stats_find cc in
+    c.country_session_download <- c.country_session_download ++ v;
+    c.country_total_download <- c.country_total_download ++ v
+  with _ -> ()
+
+let country_seen ip =
+  try
+    let cc,_ = Geoip.get_country ip in
+    let c = country_stats_find cc in
+    c.country_session_seen <- c.country_session_seen ++ 1L;
+    c.country_total_seen <- c.country_total_seen ++ 1L
+  with _ -> ()
+
+let global_count_upload n ip v =
   upload_counter := !upload_counter ++ v;
+  country_upload ip v;
   network_must_update n
 
-let global_count_download n v =
+let global_count_download n ip v =
   download_counter := !download_counter ++ v;
+  country_download ip v;
   network_must_update n
 
 let find_int_of_brand brand brand_list =
@@ -325,3 +430,38 @@
   html_mods_big_header_end buf;
   Buffer.add_string buf "\\<P\\>\n"
 
+let start_time = ref (BasicSocket.last_time ())
+let diff_time = ref 0
+let guptime () = !!country_stats_uptime - !diff_time
+let config_files_loaded = ref false
+
+let load () =
+  Options.load statistics_ini;
+  config_files_loaded := true
+
+let save () =
+  if !config_files_loaded then begin
+      let time_diff = BasicSocket.last_time () - BasicSocket.start_time in
+      country_stats_uptime =:= !!country_stats_uptime + time_diff - !diff_time;
+      diff_time := time_diff;
+    Options.save statistics_ini
+  end
+
+let country_reset () =
+  country_stats =:= [];
+  country_stats_uptime =:= 0;
+  diff_time := 0;
+  start_time := BasicSocket.last_time ();
+  save ()
+
+let _ =
+  option_hook country_stats (fun _ ->
+    try
+      ignore (List.find (fun c -> c.country_name = "??") !!country_stats);
+      country_stats =:= List.filter (fun c -> c.country_name <> "??") 
!!country_stats;
+    with Not_found -> ());
+  Heap.add_memstat "CommonStats" (fun level buf ->
+    Printf.bprintf buf "  countries: %d%s\n"
+      (List.length !!country_stats)
+      (if not !Geoip.active then " - Geoip not active" else "");
+   )

Index: src/daemon/common/commonTypes.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonTypes.ml,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- src/daemon/common/commonTypes.ml    4 Mar 2007 21:26:35 -0000       1.67
+++ src/daemon/common/commonTypes.ml    6 Mar 2007 19:31:26 -0000       1.68
@@ -927,6 +927,19 @@
     brand_upload = 0L;
   }
 
+type country_stats =
+  {
+    country_code : string;
+    country_name : string;
+    country_continent : string;
+    mutable country_session_upload : int64;
+    mutable country_session_download : int64;
+    mutable country_session_seen : int64;
+    mutable country_total_upload : int64;
+    mutable country_total_download : int64;
+    mutable country_total_seen : int64;
+  }
+
 type kind_type = {
   f : string -> string -> unit;
   description : string

Index: src/daemon/driver/driverCommands.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverCommands.ml,v
retrieving revision 1.222
retrieving revision 1.223
diff -u -b -r1.222 -r1.223
--- src/daemon/driver/driverCommands.ml 4 Mar 2007 21:31:40 -0000       1.222
+++ src/daemon/driver/driverCommands.ml 6 Mar 2007 19:31:26 -0000       1.223
@@ -1118,6 +1118,177 @@
        ""
     ), ":\t\t\t\ttoggle between the two rate sets";
 
+    "costats", Arg_multiple (fun args o ->
+        let filter cs =
+          match (List.map String.lowercase args) with
+          | [] -> cs.country_total_upload <> 0L || cs.country_total_download 
<> 0L
+          | ["all"] -> true
+         | args ->
+              let match_star = Str.regexp "\\*" in
+              let regexp = Str.regexp ("^\\("
+                ^ (List.fold_left (fun acc a -> acc
+                ^ (if acc <> "" then "\\|" else "")
+                ^ (Str.global_replace match_star ".*" a)) "" args)
+                ^ "\\)$") in
+              let check_string s =
+                Str.string_match regexp (String.lowercase s) 0 in
+              check_string cs.country_code ||
+              check_string cs.country_name ||
+              check_string cs.country_continent
+        in
+        let buf = o.conn_buf in
+        if use_html_mods o then
+          begin
+            let u1 = BasicSocket.last_time () - !CommonStats.start_time in
+            let u2 = (CommonStats.guptime () + u1) in
+            let t1 = Printf.sprintf "Session uptime: %s" (Date.time_to_string 
u1 "verbose") in
+            let t2 = Printf.sprintf "Total uptime: %s" (Date.time_to_string u2 
"verbose") in
+            html_mods_big_header_start buf "shares" [t1;t2];
+
+            html_mods_table_header buf "sharesTable" "shares" [
+               ( "0", "srh", "Country name", "Country" ) ;
+               ( "0", "srh", "Country code", "Code" ) ;
+               ( "0", "srh", "Continent", "Con" ) ;
+               ( "0", "srh ar", "Session uploaded", "sUl" ) ;
+               ( "0", "srh ar", "Session downloaded", "sDl" ) ;
+               ( "0", "srh ar", "Session seen", "sSe" ) ;
+               ( "0", "srh ar", "Total uploaded", "tUl" ) ;
+               ( "0", "srh ar", "Total downloaded", "tDl" ) ;
+               ( "0", "srh ar", "Total seen", "tSe" ) ;
+            ];
+            html_mods_cntr_init ();
+            let csu = ref 0L in
+            let csd = ref 0L in
+            let css = ref 0L in
+            let ctu = ref 0L in
+            let ctd = ref 0L in
+            let cts = ref 0L in
+            List.iter (fun cs ->
+              if filter cs then begin
+                Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"\\>" 
(html_mods_cntr ());
+                html_mods_td buf [
+                   ("", "sr", cs.country_name);
+                   ("", "sr", cs.country_code);
+                   ("", "sr", cs.country_continent);
+                   ("", "sr ar", size_of_int64 cs.country_session_upload);
+                   ("", "sr ar", size_of_int64 cs.country_session_download);
+                   ("", "sr ar", Printf.sprintf "%Ld" cs.country_session_seen);
+                   ("", "sr ar", size_of_int64 cs.country_total_upload);
+                   ("", "sr ar", size_of_int64 cs.country_total_download);
+                   ("", "sr ar", Printf.sprintf "%Ld" cs.country_total_seen);
+                   ];
+                Printf.bprintf buf "\\</tr\\>\n";
+                csu := !csu ++ cs.country_session_upload;
+                csd := !csd ++ cs.country_session_download;
+                css := !css ++ cs.country_session_seen;
+                ctu := !ctu ++ cs.country_total_upload;
+                ctd := !ctd ++ cs.country_total_download;
+                cts := !cts ++ cs.country_total_seen;
+              end
+              ) (List.sort (fun c1 c2 -> compare c1.country_code 
c2.country_code) !!CommonStats.country_stats);
+              Printf.bprintf buf "\\</tr\\>\n";
+
+              html_mods_td buf [ (* Display totals *)
+               ("", "sr", "Total");
+               ("", "sr", "");
+               ("", "sr", "");
+               ("", "sr ar", size_of_int64 !csu);
+               ("", "sr ar", size_of_int64 !csd);
+               ("", "sr ar", Printf.sprintf "%Ld" !css);
+               ("", "sr ar", size_of_int64 !ctu);
+               ("", "sr ar", size_of_int64 !ctd);
+               ("", "sr ar", Printf.sprintf "%Ld" !cts);
+               ];
+              Printf.bprintf buf "\\</tr\\>\n"
+          end
+        else
+          begin
+            let list = ref [] in
+            List.iter (fun cs ->
+              if filter cs then list := [|
+                cs.country_name;
+                cs.country_code;
+                cs.country_continent;
+                size_of_int64 cs.country_session_upload;
+                size_of_int64 cs.country_session_download;
+                Printf.sprintf "%Ld" cs.country_session_seen;
+                size_of_int64 cs.country_total_upload;
+                size_of_int64 cs.country_total_download;
+                Printf.sprintf "%Ld" cs.country_total_seen;
+              |] :: !list
+            ) (List.sort (fun c1 c2 -> compare c1.country_code 
c2.country_code) !!CommonStats.country_stats);
+            print_table_text buf
+            [|
+              Align_Left; Align_Left; Align_Left; Align_Right; Align_Right; 
Align_Right; Align_Right; Align_Right; Align_Right |]
+            [|
+              "Country";
+              "Code";
+              "Con";
+              "sUL";
+              "sDL";
+              "sSeen";
+              "tUL";
+              "tDL";
+              "tSeen";
+            |] (List.rev !list)
+          end;
+      _s ""), "[<all|regex>]:\t\t\tdisplay country based transfer statistics 
for countries with data transfered,\n\t\t\t\t\tuse arg 'all' for all countries 
seen\n\t\t\t\t\tor * as wildcard for country name, code and continent";
+
+    "countries", Arg_none (fun o ->
+        let buf = o.conn_buf in
+        if use_html_mods o then
+          begin
+            html_mods_table_header buf "sharesTable" "shares" [
+               ( "0", "srh ar", "Number", "Num" ) ;
+               ( "0", "srh", "Country name", "Country" ) ;
+               ( "0", "srh", "Country code", "Code" ) ;
+               ( "0", "srh", "Continent code", "Con" ) ;
+               ( "0", "srh", "Continent name", "Continent" ) ;
+            ];
+            html_mods_cntr_init ();
+            Array.iteri (fun i _ ->
+              Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"\\>" 
(html_mods_cntr ());
+              html_mods_td buf [
+                ("", "sr ar", Printf.sprintf "%d" i);
+                ("", "sr", Geoip.country_code_array.(i));
+                ("", "sr", Geoip.country_name_array.(i));
+                ("", "sr", Geoip.country_continent_code_array.(i));
+                ("", "sr", Geoip.country_continent_name_array.(i));
+              ];
+              Printf.bprintf buf "\\</tr\\>\n"
+            ) Geoip.country_code_array;
+            Printf.bprintf buf "\\</tr\\>\n";
+          end
+        else
+          begin
+            let list = ref [] in
+            Array.iteri (fun i _ ->
+              list := [|
+                Printf.sprintf "%d" i;
+                Geoip.country_code_array.(i);
+                Geoip.country_name_array.(i);
+                Geoip.country_continent_code_array.(i);
+                Geoip.country_continent_name_array.(i);
+              |] :: !list
+            ) Geoip.country_code_array;
+            print_table_text buf
+            [|
+              Align_Right; Align_Left; Align_Left; Align_Left; Align_Left |]
+            [|
+              "Num";
+              "Country";
+              "Code";
+              "Con";
+              "Continent";
+            |] (List.rev !list)
+          end;
+      _s ""), ":\t\t\t\tdisplay country database";
+
+    "reset_costats", Arg_none (fun o ->
+        CommonStats.country_reset ();
+        print_command_result o (_s "country statistics resetted");
+      _s ""), ":\t\t\t\treset country based transfer statistics and save 
statistics.ini";
+
     "stats", Arg_none (fun o ->
         CommonInteractive.network_display_stats o;
         if use_html_mods o then

Index: src/daemon/driver/driverInteractive.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverInteractive.ml,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -b -r1.128 -r1.129
--- src/daemon/driver/driverInteractive.ml      4 Mar 2007 21:26:35 -0000       
1.128
+++ src/daemon/driver/driverInteractive.ml      6 Mar 2007 19:31:26 -0000       
1.129
@@ -313,6 +313,7 @@
       Options.save_with_help_private users_ini;
       CommonComplexOptions.save ();
       CommonUploads.save ();
+      CommonStats.save ();
       networks_iter_all (fun r ->
           List.iter (fun opfile ->
               Options.save_with_help opfile

Index: src/daemon/driver/driverMain.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverMain.ml,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -b -r1.136 -r1.137
--- src/daemon/driver/driverMain.ml     18 Feb 2007 00:13:08 -0000      1.136
+++ src/daemon/driver/driverMain.ml     6 Mar 2007 19:31:26 -0000       1.137
@@ -411,6 +411,7 @@
 (*  lprintf "(1) CommonComplexOptions.load\n"; *)
   CommonComplexOptions.load ();
   CommonUploads.load ();
+  CommonStats.load ();
 
 (*  lprintf "(2) CommonComplexOptions.load done\n"; *)
   begin

Index: src/networks/bittorrent/bTStats.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTStats.ml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- src/networks/bittorrent/bTStats.ml  4 Mar 2007 21:26:35 -0000       1.10
+++ src/networks/bittorrent/bTStats.ml  6 Mar 2007 19:31:26 -0000       1.11
@@ -39,6 +39,7 @@
 
 let count_seen c =
   let i = brand_to_int c.client_brand in
+  CommonStats.country_seen (fst c.client_host);
   stats_array.(i).brand_seen <- stats_array.(i).brand_seen + 1;
   !!gstats_array.(i).brand_seen <- !!gstats_array.(i).brand_seen + 1
 
@@ -60,7 +61,7 @@
   c.client_total_downloaded <- c.client_total_downloaded ++ v;
   c.client_session_downloaded <- c.client_session_downloaded ++ v;
   bt_download_counter := !bt_download_counter ++ v;
-  global_count_download network v
+  global_count_download network (fst c.client_host) v
 
 let count_upload c v =
   let i = brand_to_int c.client_brand in
@@ -70,7 +71,7 @@
   c.client_total_uploaded <- c.client_total_uploaded ++ v;
   c.client_session_uploaded <- c.client_session_uploaded ++ v;
   bt_upload_counter := !bt_upload_counter ++ v;
-  global_count_upload network v
+  global_count_upload network (fst c.client_host) v
 
 let print_stats o style = 
   let buf = o.conn_buf in

Index: src/networks/donkey/donkeyStats.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/donkey/donkeyStats.ml,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- src/networks/donkey/donkeyStats.ml  4 Mar 2007 21:26:35 -0000       1.27
+++ src/networks/donkey/donkeyStats.ml  6 Mar 2007 19:31:26 -0000       1.28
@@ -45,6 +45,7 @@
   let i = brand_to_int c.client_brand in
   stats_array.(i).brand_seen <- stats_array.(i).brand_seen + 1;
   !!gstats_array.(i).brand_seen <- !!gstats_array.(i).brand_seen + 1;
+  CommonStats.country_seen c.client_ip;
   
   if !!emule_mods_count then begin
     let i = brand_mod_to_int c.client_brand_mod in
@@ -88,7 +89,7 @@
   c.client_total_downloaded <- c.client_total_downloaded ++ v;
   c.client_session_downloaded <- c.client_session_downloaded ++ v;
   donkey_download_counter := !donkey_download_counter ++ v;
-  global_count_download network v
+  global_count_download network c.client_ip v
 
 let count_upload c v =
   let i = brand_to_int c.client_brand in
@@ -104,7 +105,7 @@
   c.client_total_uploaded <- c.client_total_uploaded ++ v;
   c.client_session_uploaded <- c.client_session_uploaded ++ v;
   donkey_upload_counter := !donkey_upload_counter ++ v;
-  global_count_upload network v
+  global_count_upload network c.client_ip v
 
 let print_stats_mods o style =
   let buf = o.conn_buf in

Index: src/utils/net/geoip.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/net/geoip.ml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- src/utils/net/geoip.ml      14 Jul 2006 13:24:24 -0000      1.6
+++ src/utils/net/geoip.ml      6 Mar 2007 19:31:26 -0000       1.7
@@ -44,6 +44,10 @@
 let databaseInfo_CITY_EDITION_REV1 = 2
 let databaseInfo_ORG_EDITION = 5
 let databaseInfo_ISP_EDITION = 4
+let databaseInfo_PROXY_EDITION = 8
+let databaseInfo_ASNUM_EDITION = 9
+let databaseInfo_NETSPEED_EDITION = 10
+let databaseInfo_DOMAIN_EDITION = 11
 
 let country_code_array = [|
   "--";"AP";"EU";"AD";"AE";"AF";"AG";"AI";"AL";"AM";"AN";"AO";"AQ";"AR";
@@ -61,9 +65,9 @@
   "PA";"PE";"PF";"PG";"PH";"PK";"PL";"PM";"PN";"PR";"PS";"PT";"PW";"PY";
   "QA";"RE";"RO";"RU";"RW";"SA";"SB";"SC";"SD";"SE";"SG";"SH";"SI";"SJ";
   "SK";"SL";"SM";"SN";"SO";"SR";"ST";"SV";"SY";"SZ";"TC";"TD";"TF";"TG";
-  "TH";"TJ";"TK";"TM";"TN";"TO";"TP";"TR";"TT";"TV";"TW";"TZ";"UA";"UG";
+  "TH";"TJ";"TK";"TM";"TN";"TO";"TL";"TR";"TT";"TV";"TW";"TZ";"UA";"UG";
   "UM";"US";"UY";"UZ";"VA";"VC";"VE";"VG";"VI";"VN";"VU";"WF";"WS";"YE";
-  "YT";"YU";"ZA";"ZM";"ZR";"ZW";"A1";"A2";"O1";
+  "YT";"RS";"ZA";"ZM";"ME";"ZW";"A1";"A2";"O1";"AX";"GG";"IM";"JE";
 |]
 
 let country_name_array = [|
@@ -109,21 +113,64 @@
   "Senegal";"Somalia";"Suriname";"Sao Tome and Principe";"El Salvador";
   "Syrian Arab Republic";"Swaziland";"Turks and Caicos Islands";"Chad";
   "French Southern Territories";"Togo";"Thailand";"Tajikistan";"Tokelau";
-  "Turkmenistan";"Tunisia";"Tonga";"East Timor";"Turkey";"Trinidad and Tobago";
+  "Turkmenistan";"Tunisia";"Tonga";"Timor-Leste";"Turkey";"Trinidad and 
Tobago";
   "Tuvalu";"Taiwan";"Tanzania; United Republic of";"Ukraine";"Uganda";
   "United States Minor Outlying Islands";"United 
States";"Uruguay";"Uzbekistan";
   "Holy See (Vatican City State)";"Saint Vincent and the Grenadines";
   "Venezuela";"Virgin Islands; British";"Virgin Islands; U.S.";"Vietnam";
-  "Vanuatu";"Wallis and Futuna";"Samoa";"Yemen";"Mayotte";"Yugoslavia";
-  "South Africa";"Zambia";"Zaire";"Zimbabwe";"Anonymous Proxy";
-  "Satellite Provider";"Other";
+  "Vanuatu";"Wallis and Futuna";"Samoa";"Yemen";"Mayotte";"Serbia";
+  "South Africa";"Zambia";"Montenegro";"Zimbabwe";"Anonymous Proxy";
+  "Satellite Provider";"Other";"Aland Islands";"Guernsey";"Isle of 
Man";"Jersey";
 |]
 
-let country_index = Hashtbl.create 10
+let country_continent_code_array = [| "--";
+  "AS";"EU";"EU";"AS";"AS";"SA";"SA";"EU";"AS";"SA";
+  "AF";"AN";"SA";"OC";"EU";"OC";"SA";"AS";"EU";"SA";
+  "AS";"EU";"AF";"EU";"AS";"AF";"AF";"SA";"AS";"SA";
+  "SA";"SA";"AS";"AF";"AF";"EU";"SA";"NA";"AS";"AF";
+  "AF";"AF";"EU";"AF";"OC";"SA";"AF";"AS";"SA";"SA";
+  "SA";"AF";"AS";"AS";"EU";"EU";"AF";"EU";"SA";"SA";
+  "AF";"SA";"EU";"AF";"AF";"AF";"EU";"AF";"EU";"OC";
+  "SA";"OC";"EU";"EU";"EU";"AF";"EU";"SA";"AS";"SA";
+  "AF";"EU";"SA";"AF";"AF";"SA";"AF";"EU";"SA";"SA";
+  "OC";"AF";"SA";"AS";"AF";"SA";"EU";"SA";"EU";"AS";
+  "EU";"AS";"AS";"AS";"AS";"AS";"EU";"EU";"SA";"AS";
+  "AS";"AF";"AS";"AS";"OC";"AF";"SA";"AS";"AS";"AS";
+  "SA";"AS";"AS";"AS";"SA";"EU";"AS";"AF";"AF";"EU";
+  "EU";"EU";"AF";"AF";"EU";"EU";"AF";"OC";"EU";"AF";
+  "AS";"AS";"AS";"OC";"SA";"AF";"SA";"EU";"AF";"AS";
+  "AF";"NA";"AS";"AF";"AF";"OC";"AF";"OC";"AF";"SA";
+  "EU";"EU";"AS";"OC";"OC";"OC";"AS";"SA";"SA";"OC";
+  "OC";"AS";"AS";"EU";"SA";"OC";"SA";"AS";"EU";"OC";
+  "SA";"AS";"AF";"EU";"EU";"AF";"AS";"OC";"AF";"AF";
+  "EU";"AS";"AF";"EU";"EU";"EU";"AF";"EU";"AF";"AF";
+  "SA";"AF";"SA";"AS";"AF";"SA";"AF";"AF";"AF";"AS";
+  "AS";"OC";"AS";"AF";"OC";"AS";"AS";"SA";"OC";"AS";
+  "AF";"EU";"AF";"OC";"NA";"SA";"AS";"EU";"SA";"SA";
+  "SA";"SA";"AS";"OC";"OC";"OC";"AS";"AF";"EU";"AF";
+  "AF";"EU";"AF";"--";"--";"--";"EU";"EU";"EU";"EU";
+|]
+
+let country_continent_name_array =
+  Array.make (Array.length country_continent_code_array) "N/A"
+
+let country_index = Hashtbl.create 250
 let _ =
   Array.iteri (fun i cc -> 
     Hashtbl.add country_index cc i
-  ) country_code_array
+  ) country_code_array;
+  Array.iteri (fun i ccc ->
+    country_continent_name_array.(i) <- (
+      match ccc with
+      | "AF" -> "Africa"
+      | "AN" -> "Antarctica"
+      | "AS" -> "Asia"
+      | "EU" -> "Europe"
+      | "NA" -> "North America"
+      | "OC" -> "Oceania"
+      | "SA" -> "South America"
+      | _    -> "N/A"
+    )) country_continent_code_array
 
 let unknown_country = ("--", "N/A")
 let file = ref (Obj.magic 0)
@@ -132,6 +179,31 @@
 let database_segments = ref 0
 let record_length = ref 0
 
+let database_name () =
+  if !database_type = databaseInfo_COUNTRY_EDITION then
+  "country edition" else
+  if !database_type = databaseInfo_REGION_EDITION_REV0 then
+  "region edition v0" else
+  if !database_type = databaseInfo_REGION_EDITION_REV1 then
+  "region edition v1" else
+  if !database_type = databaseInfo_CITY_EDITION_REV0 then
+  "city edition v0" else
+  if !database_type = databaseInfo_CITY_EDITION_REV1 then
+  "city edition v1" else
+  if !database_type = databaseInfo_ORG_EDITION then
+  "org edition" else
+  if !database_type = databaseInfo_ISP_EDITION then
+  "isp edition" else
+  if !database_type = databaseInfo_PROXY_EDITION then
+  "proxy edition" else
+  if !database_type = databaseInfo_ASNUM_EDITION then
+  "asnum edition" else
+  if !database_type = databaseInfo_NETSPEED_EDITION then
+  "netspeed edition" else
+  if !database_type = databaseInfo_DOMAIN_EDITION then
+  "domain edition" else
+  "unknown edition"
+
 let unpack filename =
   let ext = String.lowercase (Filename2.extension filename) in
     let last_ext = String.lowercase (Filename2.last_extension filename) in
@@ -227,6 +299,7 @@
                  || !database_type = databaseInfo_CITY_EDITION_REV1
                  || !database_type = databaseInfo_ORG_EDITION 
                  || !database_type = databaseInfo_ISP_EDITION
+                 || !database_type = databaseInfo_ASNUM_EDITION
                   then begin
              
             database_segments := 0;
@@ -258,13 +331,16 @@
 
     setup_types 0;
 
-    if !database_type = databaseInfo_COUNTRY_EDITION then begin
+    if !database_type = databaseInfo_COUNTRY_EDITION ||
+       !database_type = databaseInfo_PROXY_EDITION ||
+       !database_type = databaseInfo_NETSPEED_EDITION
+    then begin
       database_segments := country_begin;
       record_length := standard_record_length;
     end;
 
     active := true; 
-    lprintf_nl (_b "[GeoIP] database loaded")
+    lprintf_nl (_b "[GeoIP] %s database loaded") (database_name ())
   with _ -> 
     active := false
 
@@ -320,3 +396,14 @@
     with _ -> 
       unknown_country
   end
+
+let _ =
+  Heap.add_memstat "GeoIp" (fun level buf ->
+    if !active then
+      begin
+        Printf.bprintf buf "  countries: %d\n" (Array.length 
country_code_array);
+        Printf.bprintf buf "  database_type: %s\n" (database_name ());
+      end
+    else
+      Printf.bprintf buf "  module not active\n"
+  )




reply via email to

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