From b709b4715ba2f30d7d2213e91c8856145558d6f7 Mon Sep 17 00:00:00 2001 From: spiralvoice Date: Mon, 9 Jul 2007 23:45:44 +0000 Subject: [PATCH] patch #6065 --- distrib/ChangeLog | 1 + src/daemon/common/commonOptions.ml | 10 +- src/networks/direct_connect/dcGlobals.ml | 3 +- src/networks/direct_connect/dcInteractive.ml | 170 ++++++++++++++------------- 4 files changed, 98 insertions(+), 86 deletions(-) diff --git a/distrib/ChangeLog b/distrib/ChangeLog index 3dcbccbb..9d16f80c 100644 --- a/distrib/ChangeLog +++ b/distrib/ChangeLog @@ -15,6 +15,7 @@ ChangeLog ========= 2007/07/10 +6065: DirectConnect: Support dc++ hublist in web_infos 6063: BT: Better detect single-file torrents 2007/07/03 diff --git a/src/daemon/common/commonOptions.ml b/src/daemon/common/commonOptions.ml index f11b631c..92d9e1b0 100644 --- a/src/daemon/common/commonOptions.ml +++ b/src/daemon/common/commonOptions.ml @@ -1019,9 +1019,11 @@ let web_infos = define_option current_section ["web_infos"] EXAMPLE: web_infos = [ (\"server.met\", 0, \"http://www.gruk.org/server.met.gz\"); + (\"hublist\", 0, \"http://dchublist.com/hublist.config.bz2\"); (\"guarding.p2p\", 96, \"http://www.bluetack.co.uk/config/level1.gz\"); (\"ocl\", 24, \"http://members.lycos.co.uk/appbyhp2/FlockHelpApp/contact-files/contact.ocl\"); (\"contact.dat\", 168, \"http://download.overnet.org/contact.dat\"); + (\"geoip.dat\", 168, \"http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz\"); ] " (list_option (tuple3_option (string_option, int_option, string_option))) @@ -1036,6 +1038,8 @@ let web_infos = define_option current_section ["web_infos"] "http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz"); ("nodes.gzip", 0, "http://update.kceasy.com/update/fasttrack/nodes.gzip"); + ("hublist", 0, + "http://dchublist.com/hublist.config.bz2"); (* ("slsk_boot", 0, "http://www.slsknet.org/slskinfo2"); @@ -1602,7 +1606,7 @@ let max_displayed_results = define_expert_option current_section ["max_displayed let options_version = define_expert_option current_section ["options_version"] ~internal: true "(internal option)" - int_option 17 + int_option 18 let max_comments_per_file = define_expert_option current_section ["max_comments_per_file"] "Maximum number of comments per file" @@ -2173,4 +2177,8 @@ let rec update_options () = if !!download_sample_size = 10 then download_sample_size =:= 100; update 17 + | 17 -> + web_infos_add "hublist" 0 "http://dchublist.com/hublist.config.bz2"; + update 18 + | _ -> () diff --git a/src/networks/direct_connect/dcGlobals.ml b/src/networks/direct_connect/dcGlobals.ml index f17f813a..3fdb932a 100644 --- a/src/networks/direct_connect/dcGlobals.ml +++ b/src/networks/direct_connect/dcGlobals.ml @@ -110,8 +110,7 @@ let dc_total_uploaded = ref Int64.zero (*let current_open_slots = ref 0*) (*let clients_by_name = Hashtbl.create 113*) let clients_list = ref ([] : client list) -(*let dc_hublist = ref ([] : dc_hub list)*) (* list for DC servers *) -let dc_hublistfile = ref "" +let dc_hublist = ref ([] : dc_hub list) (* list for DC servers *) let temp_nick = ref "unknown" let temp_nick_num = ref 0 (* this is used to name temporary users always with different name *) let used_slots = ref 0 diff --git a/src/networks/direct_connect/dcInteractive.ml b/src/networks/direct_connect/dcInteractive.ml index b07cc5b0..091102bf 100644 --- a/src/networks/direct_connect/dcInteractive.ml +++ b/src/networks/direct_connect/dcInteractive.ml @@ -617,13 +617,9 @@ let commands = [ \\\\\\\\"; Printf.bprintf buf "\\
+ action=\\\"javascript:parent.output.location.href='submit?q=dchublist'\\\"\\> \\\\\\\\"; - Printf.bprintf buf "\\ - \\\\\\\\"; Printf.bprintf buf "\\ \\\\ let buf = o.conn_buf in - let failtxt = "dchublist show [filtertext] | load - bad arguments" in + let filter = ref [] in + let print_hublist () = + if use_html_mods o then + begin + html_mods_table_one_row buf "serversTable" "servers" [ + (empty_string, "srh", Printf.sprintf "Showing hublist"); ]; + Printf.bprintf buf "\\\\" + end + else + Printf.bprintf buf "Showing hublist"; + html_mods_cntr_init (); + let nb_hubs = ref 0 in + if use_html_mods o then dc_hublist_print_html_header buf empty_string; + let show_all = if (!filter = []) then true else false in + List.iter (fun h -> + let hub_has_string searched = + if String2.contains (Ip.string_of_addr h.dc_ip) searched || + String2.contains (string_of_int h.dc_port) searched || + String2.contains h.dc_info searched || + String2.contains h.dc_name searched then true + else false in + let print_hub () = + (try + hublist_print h !nb_hubs o; + incr nb_hubs; + with e -> + if !verbose_msg_servers then + lprintf_nl "Exception %s in hub_print\n" (Printexc2.to_string e)) + in + if show_all then + print_hub () + else + begin + let print = ref false in + let finished = ref false in + let counter = ref 0 in + let filters_length = List.length !filter in + while (!print = false) && (!finished = false) do + if (!counter = filters_length) || (!counter > 5) then + finished := true + else + if (hub_has_string (List.nth !filter !counter)) then print := true; + incr counter + done; + if (!print = true) then print_hub () + end + ) !dc_hublist; + let txt = if show_all then "(showing all hubs from hublist)" else "(filtered)" in + if use_html_mods o then + begin + Printf.bprintf buf "\\\\"; + html_mods_table_one_row buf "serversTable" "servers" [ + (empty_string, "srh", Printf.sprintf "Hubs: %d known %s" !nb_hubs txt); ] + end + else + Printf.bprintf buf "Hubs: %d known %s" !nb_hubs txt + in (match args with - | cmd :: rest_args -> - (match cmd with - | "load" -> - let url = - if (!!servers_list_url = empty_string) then failwith "No valid url" - else - { url = !!servers_list_url; - kind = ""; - period = 0; - state = None; - } - in - CommonWeb.mldonkey_wget url (fun _ -> () ); - Printf.bprintf buf "Trying to load %s\n" url.url; - | "show" -> - let filename = Filename.concat "web_infos" (Filename.basename !!servers_list_url) in - if !verbose_msg_servers then lprintf_nl "Loading hublist with filename (%s) " filename; - let hublist = - (try - (match Filename2.last_extension filename with - | ".bz2" -> DcServers.make_hublist_from_file (Misc2.bz2_extract filename) - | _ -> DcServers.make_hublist_from_file filename ) - with e -> - if !verbose_msg_servers then lprintf_nl "(%s) in loading/parsing serverlist" (Printexc2.to_string e); - raise Not_found ) - in - if use_html_mods o then begin - html_mods_table_one_row buf "serversTable" "servers" [ - (empty_string, "srh", Printf.sprintf "Showing hublist %s" !!servers_list_url); ]; - Printf.bprintf buf "\\\\"; - end else Printf.bprintf buf "Showing hublist %s" !!servers_list_url; - - html_mods_cntr_init (); - let nb_hubs = ref 0 in - if use_html_mods o then dc_hublist_print_html_header buf empty_string; - let show_all = if (rest_args = []) then true else false in - List.iter (fun h -> - let hub_has_string searched = - if String2.contains (Ip.string_of_addr h.dc_ip) searched || - String2.contains (string_of_int h.dc_port) searched || - String2.contains h.dc_info searched || - String2.contains h.dc_name searched then true - else false in - let print_hub () = - (try - hublist_print h !nb_hubs o; - incr nb_hubs; - with e -> - if !verbose_msg_servers then - lprintf_nl "Exception %s in hub_print\n" (Printexc2.to_string e) ) - in - if show_all then print_hub () - else begin - let print = ref false in - let finished = ref false in - let counter = ref 0 in - let filters_length = List.length rest_args in - while (!print = false) && (!finished = false) do - if (!counter = filters_length) || (!counter > 5) then finished := true - else if (hub_has_string (List.nth rest_args !counter)) then print := true; - incr counter - done; - if (!print = true) then print_hub (); - end; - ) hublist; - let txt = - if show_all then "(showing all hubs from hublist)" else "(filtered)" - in - if use_html_mods o then begin - Printf.bprintf buf "\\\\"; - html_mods_table_one_row buf "serversTable" "servers" [ - (empty_string, "srh", Printf.sprintf "Hubs: %d known %s" !nb_hubs txt); ] - end else Printf.bprintf buf "Hubs: %d known %s" !nb_hubs txt; - | _ -> failwith failtxt ) - | _ -> failwith failtxt ); + | [] -> () + | rest_args -> filter := rest_args + ); + print_hublist (); empty_string - ), "\rFor example: dchublist show fin - filters hubs with text fin\rdchublist load - loads hublist from address in options"; + ), "[filtertext]: dchublist fin - filters hubs with text fin"; (* 'dcuserip name' query user-ip from hub *) "dcuserip", Arg_multiple (fun args o -> @@ -1570,10 +1551,33 @@ let _ = file_ops.op_file_resume <- (fun _ -> ()); file_ops.op_file_set_format <- (fun _ _ -> ()); file_ops.op_file_check <- (fun _ -> ()); - file_ops.op_file_recover <- (fun _ -> ()); + file_ops.op_file_recover <- (fun _ -> ()) (*file_ops.op_file_print_html <- (fun _ _ -> lprintf_nl "Received (op_file_print_html)"; ());*) (*file_ops.op_file_print_sources_html <- (fun _ _ -> lprintf_nl "Received (op_file_print_sources_html)"; ())*) (* mutable op_file_files : ('a -> 'a file_impl -> file list); mutable op_file_debug : ('a -> string); mutable op_file_proposed_filenames : ('a -> string list); *) + +let _ = + CommonWeb.add_web_kind "hublist" "DirectConnect hublist" + (fun url filename -> + if !!enable_directconnect then + begin + try + dc_hublist := ( + match Filename2.last_extension filename with + | ".bz2" -> DcServers.make_hublist_from_file (Misc2.bz2_extract filename) + | _ -> DcServers.make_hublist_from_file filename); + lprintf_nl "loaded dc++ hublist, %d entries" (List.length !dc_hublist) + with e -> + if !verbose_msg_servers then + lprintf_nl "(%s) in loading/parsing serverlist" (Printexc2.to_string e); + raise Not_found + end + else + begin + lprintf_nl "DirectConnect module is disabled, ignoring..."; + raise Not_found + end + ) -- 2.11.4.GIT