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: Fri, 12 May 2006 21:02:39 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Branch:         
Changes by:     spiralvoice <address@hidden>    06/05/12 21:02:39

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonResult.ml commonResult.mli 
        src/networks/fasttrack: fasttrackGlobals.ml fasttrackHandler.ml 
                                fasttrackProtocol.ml 
        src/networks/gnutella: gnutellaClients.ml 
                               gnutellaComplexOptions.ml 
                               gnutellaGlobals.ml gnutellaHandler.ml 
                               gnutellaInteractive.ml gnutellaOptions.ml 
                               gnutellaProtocol.ml gnutellaRedirector.ml 
        src/utils/net  : http_client.ml 

Log message:
        patch #5088

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/distrib/ChangeLog.diff?tr1=1.818&tr2=1.819&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonResult.ml.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonResult.mli.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fasttrack/fasttrackGlobals.ml.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fasttrack/fasttrackHandler.ml.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fasttrack/fasttrackProtocol.ml.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaClients.ml.diff?tr1=1.39&tr2=1.40&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaGlobals.ml.diff?tr1=1.36&tr2=1.37&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaHandler.ml.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaInteractive.ml.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaOptions.ml.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaProtocol.ml.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaRedirector.ml.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/utils/net/http_client.ml.diff?tr1=1.28&tr2=1.29&r1=text&r2=text

Patches:
Index: mldonkey/distrib/ChangeLog
diff -u mldonkey/distrib/ChangeLog:1.818 mldonkey/distrib/ChangeLog:1.819
--- mldonkey/distrib/ChangeLog:1.818    Thu May 11 21:24:41 2006
+++ mldonkey/distrib/ChangeLog  Fri May 12 21:02:38 2006
@@ -14,6 +14,10 @@
 ChangeLog
 =========
 
+2006/05/12
+5088: Gnutella/FT/http_client fixes (zet)
+- Gnutella (G1) is working again
+
 2006/05/11
 5087: HTML, upstats: new tooltip with complete filename,
       respect max_name_len for filename
Index: mldonkey/src/daemon/common/commonResult.ml
diff -u mldonkey/src/daemon/common/commonResult.ml:1.7 
mldonkey/src/daemon/common/commonResult.ml:1.8
--- mldonkey/src/daemon/common/commonResult.ml:1.7      Thu Jan 19 00:44:47 2006
+++ mldonkey/src/daemon/common/commonResult.ml  Fri May 12 21:02:38 2006
@@ -166,7 +166,39 @@
       r.result_modified <- false;
       IndexedResults.update_result rs r
     end
-  
+
+let rec find_avail tags =
+  match tags with
+    [] -> raise Not_found
+  | tag :: tail -> begin
+    match tag with
+      { tag_name = Field_Availability ; tag_value = tag_value } ->
+      tag
+    | _ -> find_avail tail
+  end
+
+let increment_avail r =
+  let rr = IndexedResults.get_result r in
+  begin
+    try
+      let tag = find_avail rr.result_tags in
+      let x = int64_of_tagvalue tag.tag_value in
+      tag.tag_value <- Uint64 (x ++ 1L);
+     with Not_found -> ();
+    end;
+  update_result_num rr
+
+let update_or_create_avail tags =
+  let tag =
+    try
+      let tag = find_avail tags in
+      let x = int64_of_tagvalue tag.tag_value in
+      tag.tag_value <- Uint64 (x ++ 1L);
+      tag
+   with Not_found ->
+      { tag_name = Field_Availability; tag_value = Uint64 1L } 
+  in
+  tag :: tags
   
 let _ = 
   Heap.add_memstat "CommonResult" (fun level buf ->
Index: mldonkey/src/daemon/common/commonResult.mli
diff -u mldonkey/src/daemon/common/commonResult.mli:1.4 
mldonkey/src/daemon/common/commonResult.mli:1.5
--- mldonkey/src/daemon/common/commonResult.mli:1.4     Mon Nov  1 11:22:59 2004
+++ mldonkey/src/daemon/common/commonResult.mli Fri May 12 21:02:38 2006
@@ -83,3 +83,5 @@
 val update_result : StoredResult.result -> unit
 val update_result2 :
   StoredResult.stored_result -> StoredResult.result -> unit
+val increment_avail : StoredResult.stored_result -> StoredResult.stored_result
+val update_or_create_avail : CommonTypes.tag list -> CommonTypes.tag list
Index: mldonkey/src/networks/fasttrack/fasttrackGlobals.ml
diff -u mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.35 
mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.36
--- mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.35    Tue May  9 
17:17:08 2006
+++ mldonkey/src/networks/fasttrack/fasttrackGlobals.ml Fri May 12 21:02:38 2006
@@ -239,13 +239,15 @@
     end
 
 let new_result file_name file_size tags hashes _ =
-
+ 
   match hashes with
   | [ hash ] ->
       let r =
         try
-          Hashtbl.find results_by_uid hash
+          let r = Hashtbl.find results_by_uid hash in
+          increment_avail r
         with _ ->
+            let tags = update_or_create_avail tags in
             let r = { dummy_result with
                 result_names = [file_name];
                 result_size = file_size;
Index: mldonkey/src/networks/fasttrack/fasttrackHandler.ml
diff -u mldonkey/src/networks/fasttrack/fasttrackHandler.ml:1.18 
mldonkey/src/networks/fasttrack/fasttrackHandler.ml:1.19
--- mldonkey/src/networks/fasttrack/fasttrackHandler.ml:1.18    Tue May  9 
08:40:25 2006
+++ mldonkey/src/networks/fasttrack/fasttrackHandler.ml Fri May 12 21:02:38 2006
@@ -174,8 +174,9 @@
         let s = Hashtbl.find searches_by_uid id in
 
         List.iter (fun (user, meta) ->
-            let user = new_user (Known_location (
+            let fuser = new_user (Known_location (
                   user.M.user_ip, user.M.user_port)) in
+            fuser.user_nick <- user.M.user_name;
 (*
           let url = Printf.sprintf
             "FastTrack://%s:%d/.hash=%s" (Ip.to_string user_ip)
@@ -193,7 +194,7 @@
                       result_name
                       meta.M.meta_size
                       meta.M.meta_tags [meta.M.meta_hash] [] in
-                  add_source rs user;
+                  add_source rs fuser;
                   CommonInteractive.search_add_result false sss rs
 
               | FileUidSearch (file, file_hash) -> ()
@@ -209,7 +210,7 @@
 
             try
               let file = Hashtbl.find files_by_uid meta.M.meta_hash in
-              let c = new_client user.user_kind in
+              let c = new_client fuser.user_kind in
               add_download file c ()(* (FileByUrl url) *);
 
               if not (List.mem_assoc result_name file.file_filenames) then
Index: mldonkey/src/networks/fasttrack/fasttrackProtocol.ml
diff -u mldonkey/src/networks/fasttrack/fasttrackProtocol.ml:1.12 
mldonkey/src/networks/fasttrack/fasttrackProtocol.ml:1.13
--- mldonkey/src/networks/fasttrack/fasttrackProtocol.ml:1.12   Fri May  5 
22:08:00 2006
+++ mldonkey/src/networks/fasttrack/fasttrackProtocol.ml        Fri May 12 
21:02:38 2006
@@ -154,6 +154,21 @@
 
 let parse_headers c first_line headers =
 
+  begin
+    try
+      let (server,_) = List.assoc "server" headers in
+      c.client_user.user_vendor <- server;
+    with Not_found -> ()
+  end;
+
+  begin
+    try
+      let (username,_) = List.assoc "x-kazaa-username" headers in
+      c.client_user.user_nick <- username;
+    with Not_found -> ()
+  end;
+
+
   if !verbose_unknown_messages then begin
       let unknown_header = ref false in
       List.iter (fun (header, _) ->
Index: mldonkey/src/networks/gnutella/gnutellaClients.ml
diff -u mldonkey/src/networks/gnutella/gnutellaClients.ml:1.39 
mldonkey/src/networks/gnutella/gnutellaClients.ml:1.40
--- mldonkey/src/networks/gnutella/gnutellaClients.ml:1.39      Fri May  5 
22:08:01 2006
+++ mldonkey/src/networks/gnutella/gnutellaClients.ml   Fri May 12 21:02:38 2006
@@ -553,7 +553,7 @@
                 in
                 iter ()
               with Not_found -> 
-               if !verbose_unknown_messages then
+    if !verbose_unknown_messages then
                   lprintf_nl () "Unable to get a block !!";
                   check_finished swarmer file;
                   raise Not_found
@@ -758,7 +758,11 @@
           try
             Hashtbl.find clients_by_uid (Known_location (ip,port))
           with _ ->
-              new_client  (Indirect_location ("", uid, ip, port))
+              let c = new_client  (Indirect_location ("", uid, ip, port)) in
+              if String.length c.client_user.user_nick == 0 then
+                c.client_user.user_nick <- (Md4.to_string uid);
+              c
+            
     in
     c.client_host <- Some (ip, port);
     match c.client_sock with
Index: mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml
diff -u mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.26 
mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.27
--- mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.26       Sun Apr 
 9 00:27:04 2006
+++ mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml    Fri May 12 
21:02:38 2006
@@ -57,6 +57,7 @@
           let client_port = get_value "client_port" value_to_int in
           let client_uid = get_value "client_uid" (from_value Md4.option) in
           let c = new_client (Known_location(client_ip, client_port)) in
+          c.client_user.user_nick <- (Md4.to_string client_uid);
           
           (try
               c.client_user.user_speed <- get_value "client_speed" 
value_to_int 
Index: mldonkey/src/networks/gnutella/gnutellaGlobals.ml
diff -u mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.36 
mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.37
--- mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.36      Sun Apr  9 
00:27:04 2006
+++ mldonkey/src/networks/gnutella/gnutellaGlobals.ml   Fri May 12 21:02:38 2006
@@ -232,7 +232,7 @@
       ss := (key, last_time ()) :: !ss
     end
 
-let new_result file_name file_size tags (uids : Uid.t list) sources =
+let new_result file_name file_size (tags : CommonTypes.tag list) (uids : Uid.t 
list) sources =
   match uids with
     [] -> (*
         lprintf "New result by key\n"; 
@@ -257,8 +257,12 @@
         lprintf "New result by UID\n"; 
       let rs = 
         try
-          Hashtbl.find results_by_uid (Uid.to_uid uid)
+          let r = Hashtbl.find results_by_uid (Uid.to_uid uid) in
+          increment_avail r
         with _ -> 
+
+            let tags = update_or_create_avail tags in 
+
             let r = { dummy_result with
                 result_names = [file_name];
                 result_size = file_size;
@@ -429,7 +433,7 @@
           dummy_client_impl with
           impl_client_val = c;
           impl_client_ops = client_ops;
-         impl_client_upload = None;
+    impl_client_upload = None;
         } in
       new_client impl;
       Hashtbl.add clients_by_uid kind c;
Index: mldonkey/src/networks/gnutella/gnutellaHandler.ml
diff -u mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.11 
mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.12
--- mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.11      Sun Apr  9 
00:27:04 2006
+++ mldonkey/src/networks/gnutella/gnutellaHandler.ml   Fri May 12 21:02:38 2006
@@ -54,6 +54,7 @@
         Some true ->  Indirect_location ("", t.Q.guid, t.Q.ip, t.Q.port)
       | _ -> Known_location(t.Q.ip, t.Q.port))
   in
+  user.user_nick <- (Md4.to_string t.Q.guid);
   user.user_speed <- t.Q.speed;
   user
   
@@ -70,6 +71,7 @@
       | _ -> Known_location(t.Q.ip, t.Q.port))
   in
   
+  c.client_user.user_nick <- (Md4.to_string t.Q.guid);
   c.client_user.user_speed <- t.Q.speed;
   c
   
@@ -116,10 +118,12 @@
   | PongReq t ->
       
       let module P = Pong in
-(*      lprintf "FROM %s:%d" (Ip.to_string t.P.ip) t.P.port; *)
+      (*      lprintf "FROM %s:%d" (Ip.to_string t.P.ip) t.P.port; *)
       if p.pkt_uid = s.server_ping_last then begin
           s.server_nfiles_last <- Int64.add s.server_nfiles_last (Int64.of_int 
t.P.nfiles);
           s.server_nkb_last <- s.server_nkb_last + t.P.nkb;
+          s.server_nfiles <- (Int64.of_int t.P.nfiles);
+          s.server_nkb <- t.P.nkb;
           server_must_update (as_server s.server_server)
         end
   
@@ -243,12 +247,12 @@
           
           let uids = ref [] in
           List.iter (fun s ->
-              if s.[0] = '{' || s.[0] = '<' then begin
+              if String.length s > 20 && String2.starts_with s "urn:" then
+                uids := (GnutellaGlobals.extract_uids s) @ !uids
 (* probably XML. print to remember that we should be able to use this
 information. *)
-                  lprintf "xml of result: %s\n" (String.escaped s);
-                end else
-                uids := (GnutellaGlobals.extract_uids s) @ !uids
+              else
+                  lprintf "info: %s\n" (String.escaped s);
           ) f.Q.info;
           
           if !verbose then
Index: mldonkey/src/networks/gnutella/gnutellaInteractive.ml
diff -u mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.51 
mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.52
--- mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.51  Sun Apr  9 
00:27:04 2006
+++ mldonkey/src/networks/gnutella/gnutellaInteractive.ml       Fri May 12 
21:02:38 2006
@@ -64,7 +64,7 @@
 | QHasMinVal of string * int64
 | QHasMaxVal of string * int64
 | QNone (** temporary, used when no value is available ;
-          must be simplified before transforming into strings *)
+     must be simplified before transforming into strings *)
 *)
 
 let recover_file file =
@@ -400,7 +400,10 @@
         P.client_network = network.network_num;
         P.client_kind = c.client_user.user_kind;
         P.client_type = client_type c;
-        P.client_name = c.client_user.user_nick;
+        P.client_name = if c.client_user.user_speed > 0 
+                          then Printf.sprintf "%s (%d)" 
c.client_user.user_nick c.client_user.user_speed
+                          else c.client_user.user_nick;
+        P.client_software = c.client_user.user_vendor;
 
       }
   );
Index: mldonkey/src/networks/gnutella/gnutellaOptions.ml
diff -u mldonkey/src/networks/gnutella/gnutellaOptions.ml:1.19 
mldonkey/src/networks/gnutella/gnutellaOptions.ml:1.20
--- mldonkey/src/networks/gnutella/gnutellaOptions.ml:1.19      Fri May  5 
22:08:01 2006
+++ mldonkey/src/networks/gnutella/gnutellaOptions.ml   Fri May 12 21:02:38 2006
@@ -50,31 +50,29 @@
   "A list of GWCache urls"
     (list_option string_option)
   [
-    "http://cache.kicks-ass.net:8000";;
-    "http://gwc.jooz.net:8010/gwc";;
-    "http://gwc.mine.nu:3333";;
-    "http://gwc1.nouiz.org/servlet/GWebCache/req";;
+    "http://cache.kicks-ass.net:8000/";;
+    "http://g2cache.theg2.net/gwcache/lynnx.asp";;
+    "http://galvatron.dyndns.org:59009/gwcache";;
+    "http://gcache.sexter.com:8080/gwc/";;
     "http://gwcrab.sarcastro.com:8001";;
-    "http://kisama.ath.cx:8080";;
+    "http://gwebcache.bearshare.net/";;
+    "http://gwebcache.bearshare.net/gcache.php";;
+    "http://intense.homelinux.coww.xolox.nl/gwebcache/";;
+    "http://kisama.ath.cx:8080/";;
     "http://krill.shacknet.nu:20095/gwc";;
-    "http://overbeer.ghostwhitecrab.de";;
-    "http://pokerface.bishopston.net:3558";;
+    "http://loot.alumnigroup.org/";;
+    "http://pokerface.ibiza.bishopston.net:3558/";;
+    "http://t.az.is.teh.r0x0r.gtkg.de/";;
+    "http://tribaldance.ibiza.bishopston.net:3558/";;
+    "http://www.deepnetexplorer.co.uk/webcache/";;
   ]
 
 let urlfiles = define_option gnutella_section 
     ["urlfiles"]
-  "A list of GWCache urls"
+  "A list of urlfile urls"
     (list_option string_option)
   [
-    "http://cache.kicks-ass.net:8000";;
-    "http://gwc.jooz.net:8010/gwc";;
-    "http://gwc.mine.nu:3333";;
-    "http://gwc1.nouiz.org/servlet/GWebCache/req";;
-    "http://gwcrab.sarcastro.com:8001";;
-    "http://kisama.ath.cx:8080";;
-    "http://krill.shacknet.nu:20095/gwc";;
-    "http://overbeer.ghostwhitecrab.de";;
-    "http://pokerface.bishopston.net:3558";;
+    "http://loot.alumnigroup.org/";;
   ]
   
 let redirectors = define_option gnutella_section 
@@ -100,7 +98,7 @@
 let client_uid = define_option gnutella_section ["client_uid"]
     "The UID of this client" Md4.option (Md4.random ())
   
-  let _         =
+  let _  =
   option_hook client_uid (fun _ ->
      let s = Md4.direct_to_string !!client_uid in
      s.[8] <- '\255';
Index: mldonkey/src/networks/gnutella/gnutellaProtocol.ml
diff -u mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.21 
mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.22
--- mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.21     Fri May  5 
22:08:01 2006
+++ mldonkey/src/networks/gnutella/gnutellaProtocol.ml  Fri May 12 21:02:38 2006
@@ -311,6 +311,19 @@
 
       try
         
+        begin
+          try 
+            let (server,_) = List.assoc "server" headers in
+            c.client_user.user_vendor <- server;
+          with Not_found -> ()
+        end;
+        begin
+          try 
+            let (useragent,_) = List.assoc "user-agent" headers in
+            c.client_user.user_vendor <- useragent;
+          with Not_found -> ()
+        end;
+
         let (locations,_) = 
           List.assoc "x-gnutella-alternate-location" headers in
         let locations = String2.split locations ',' in
Index: mldonkey/src/networks/gnutella/gnutellaRedirector.ml
diff -u mldonkey/src/networks/gnutella/gnutellaRedirector.ml:1.11 
mldonkey/src/networks/gnutella/gnutellaRedirector.ml:1.12
--- mldonkey/src/networks/gnutella/gnutellaRedirector.ml:1.11   Fri May  5 
22:08:01 2006
+++ mldonkey/src/networks/gnutella/gnutellaRedirector.ml        Fri May 12 
21:02:38 2006
@@ -43,22 +43,37 @@
 let redirectors_urlfiles = ref []
 let redirectors_hostfiles = ref []
   
-let parse_urlfile file = 
+let parse_urlfile file url_string = 
   let s = File.to_string file in
+  (* Http_client.wget does not delete the temp file anymore *)
+  (try Sys.remove file with _ -> ());
+  if !verbose then lprintf_nl () "Parsing urlfile from %s:\n%s" url_string s;
   clean_file s;
   let lines = String2.split_simplify s '\n' in
   List.iter (fun line ->
-      if not (List.mem line !!gnutella_hostfiles) then
-        gnutella_hostfiles =:= line :: !!gnutella_hostfiles
+      if not (List.mem line !!gnutella_hostfiles) then begin
+        gnutella_hostfiles =:= line :: !!gnutella_hostfiles;
+        if !verbose then lprintf_nl () "Added GWebCache %s" line;
+      end
   ) lines;
   redirectors_hostfiles := !!gnutella_hostfiles
 
+let next_urlfile_access = ref 0
+
 let connect_urlfile () = 
   match !redirectors_urlfiles with
     [] ->
-      redirectors_urlfiles := !!urlfiles
+      if !next_urlfile_access < last_time () then begin
+          (* 12 hour interval between urlfile re-connection attempts *)
+          next_urlfile_access := last_time () + (3600*12);
+          redirectors_urlfiles := !!urlfiles;
+          lprintf_nl () "added %d urlfiles" (List.length !!urlfiles);
+      end else begin
+        if !verbose then lprintf_nl () "connect_urlfile: no urlfiles, too 
soon";
+      end
   | url :: tail ->
       redirectors_urlfiles := tail;
+      let url_string = url in
       let module H = Http_client in
       let url = Printf.sprintf "%s?urlfile=1&client=MLDK&version=%s"
           url Autoconf.current_version in
@@ -69,21 +84,34 @@
           H.req_user_agent = get_user_agent ();
         } in
       if !verbose then
-        lprintf "Connecting Gnutella %s\n" url;
-      H.wget r parse_urlfile    
+        lprintf_nl () "Connecting to urlfile %s\n" url;
+      H.wget r (fun filename -> parse_urlfile filename url_string)
       
-let parse_hostfile file = 
+let parse_hostfile file url_string = 
   let s = File.to_string file in
-  clean_file s;
-  let lines = String2.split_simplify s '\n' in
-  List.iter (fun line ->
+  (* Http_client.wget does not delete the temp file anymore *)
+  (try Sys.remove file with _ -> ());
+  if String2.starts_with s "ERROR" || String2.starts_with s "<" then begin
+    if !verbose then lprintf_nl () "Malformed response content:\n%s" s;
+    if List.mem url_string !!gnutella_hostfiles then begin
+      gnutella_hostfiles =:= List.filter (fun h -> h <> url_string) 
!!gnutella_hostfiles;
+      redirectors_hostfiles := !!gnutella_hostfiles;
+      if !verbose then lprintf_nl () "Removing %s from hostfiles" url_string;
+    end;
+  end
+  else begin
+    clean_file s;
+    let lines = String2.split_simplify s '\n' in
+    if !verbose then lprintf_nl () "Parsing response from %s:\n%s" url_string 
s;
+    List.iter (fun line ->
       try
         let ip, port = String2.cut_at line ':' in
         if !verbose then
-          lprintf "gnutella1: adding ultrapeer from hostfile\n";
+          lprintf_nl () "Adding ultrapeer from hostfile %s %s" ip port;
         ignore (H.new_host (Ip.addr_of_string ip) (int_of_string port) 
Ultrapeer)
       with _ -> ()
-  ) lines
+    ) lines
+  end
 
 let next_redirector_access = ref 0
   
@@ -91,17 +119,18 @@
   match !redirectors_hostfiles with
     [] ->
       if !next_redirector_access < last_time () then begin
-          (* We should only contact the redirectors
-             if we don't have enough hosts.
-             Changed it to once every day,
-             so we don't hurt the network. *)
-          next_redirector_access := last_time () + (3600*24);
-          connect_urlfile ();
+          (* 12 hour interval between redirector re-connection attempts *)
+          next_redirector_access := last_time () + (3600*12);
           redirectors_hostfiles := !!gnutella_hostfiles
-        end;
+      end 
+      else begin
+        if !verbose then lprintf_nl () "connect_hostfile: no gwebcaches, too 
soon";
+      end;
+      connect_urlfile ();
   | url :: tail ->
       redirectors_hostfiles := tail;
       let module H = Http_client in
+      let url_string = url in
       let url = Printf.sprintf "%s?hostfile=1&client=MLDK&version=%s"
           url Autoconf.current_version in
       let r = {
@@ -111,8 +140,8 @@
           H.req_user_agent = get_user_agent ();
         } in
       if !verbose then
-        lprintf "Connecting Gnutella %s\n" url;
-      H.wget r parse_hostfile    
+        lprintf_nl () "Connecting to hostfile %s" url;
+      H.wget r (fun filename -> parse_hostfile filename url_string)
       
 let connect _ = 
   connect_hostfile ()
Index: mldonkey/src/utils/net/http_client.ml
diff -u mldonkey/src/utils/net/http_client.ml:1.28 
mldonkey/src/utils/net/http_client.ml:1.29
--- mldonkey/src/utils/net/http_client.ml:1.28  Mon Apr  3 20:50:09 2006
+++ mldonkey/src/utils/net/http_client.ml       Fri May 12 21:02:39 2006
@@ -87,8 +87,8 @@
       then  Url.to_string_no_args url
       else url.short_file
     in
-       (* I get a lot more bittorrent urls with this line: *)
-       let url = (Str.global_replace (Str.regexp " ") "%20" url) in
+  (* I get a lot more bittorrent urls with this line: *)
+  let url = (Str.global_replace (Str.regexp " ") "%20" url) in
     let url = if is_real_post then url else
         Url.put_args url args
     in
@@ -287,7 +287,7 @@
 
     | 301 | 302 | 304 ->
         if !verbose then lprintf_nl () "%d: Redirect" ans_code;
-       let retrynum = r.req_retry in
+  let retrynum = r.req_retry in
         if retrynum < r.req_max_retry then
           begin
             try
@@ -308,10 +308,10 @@
               in
               if !verbose then lprintf_nl () "Redirected to %s" url;
               let r = { r with
-                       req_url = Url.of_string url;
-                       req_retry = retrynum+1 }
-             in
-             get_page r content_handler f
+      req_url = Url.of_string url;
+      req_retry = retrynum+1 }
+        in
+        get_page r content_handler f
             
             with e ->
                 lprintf_nl () "error understanding redirect response %d" 
ans_code;
@@ -330,17 +330,17 @@
 
     | 502 | 503 | 504 ->
         if !verbose then lprintf_nl () "%d: Unavailable" ans_code;
-       let retrynum = r.req_retry in
+  let retrynum = r.req_retry in
         if retrynum < r.req_max_retry then
           begin
             if !verbose then
               print_headers ();
-           let seconds = (retrynum+1)*10 in
+      let seconds = (retrynum+1)*10 in
               lprintf_nl () "retry %d/%d in %d seconds for %s"
-               (retrynum+1) r.req_max_retry seconds (Url.to_string_no_args 
r.req_url);
-           let r = { r with req_retry = retrynum+1 } in
-             add_timer (float(seconds)) (fun t -> get_page r content_handler f)
-         end
+          (retrynum+1) r.req_max_retry seconds (Url.to_string_no_args 
r.req_url);
+      let r = { r with req_retry = retrynum+1 } in
+        add_timer (float(seconds)) (fun t -> get_page r content_handler f)
+    end
         else 
           lprintf_nl () "more than %d retries, aborting." r.req_max_retry;
           raise Not_found
@@ -364,8 +364,7 @@
   let file_size = ref 0 in
   
   try
-  get_page r
-    (fun maxlen headers sock nread ->
+  get_page r (fun maxlen headers sock nread ->
 (*      lprintf "received %d\n" nread; *)
       let buf = TcpBufferedSocket.buf sock in
       
@@ -380,30 +379,44 @@
           file_size := !file_size + left;
           if nread > left then
             TcpBufferedSocket.close sock Closed_by_user
-        end)
+        end
+  )
   (fun _ ->  
       let s = Buffer.contents file_buf in
       if s = "" then begin
           lprintf_nl () "Empty content for url %s"
             (Url.to_string r.req_url);
-        end;
+      end;
+      
       let webinfos_dir = "web_infos" in
-        Unix2.safe_mkdir webinfos_dir;
-       Unix2.can_write_to_directory webinfos_dir;
-      let filename = Filename.concat webinfos_dir 
-       (Filename.basename r.req_url.Url.short_file) in
+      Unix2.safe_mkdir webinfos_dir;
+      Unix2.can_write_to_directory webinfos_dir;
+      
+      let base = Filename.basename r.req_url.Url.short_file in
+      (* Base could be "." for http://site.com/ *)
+      let base = if base = "." 
+        then begin
+          let prng = Random.State.make_self_init () in
+          let rnd = (Random.State.bits prng) land 0xFFFFFF in
+          Printf.sprintf "http_%06x.tmp" rnd 
+        end else base 
+      in
+
+      let filename = Filename.concat webinfos_dir base in
+      if !verbose then lprintf_nl () "Filename: %s" filename;
       Unix2.tryopen_write_bin filename (fun oc -> output_string oc s);
       if r.req_save_to_file_time <> 0. then
-       Unix.utimes filename r.req_save_to_file_time r.req_save_to_file_time;
+        Unix.utimes filename r.req_save_to_file_time r.req_save_to_file_time;
       try
-        (f filename : unit)
-      with e ->  lprintf_nl ()
-            "Exception %s in loading downloaded file %s"
-            (Printexc2.to_string e) filename;
-          Sys.remove filename;
-          raise Not_found
+        (f filename : unit);
+      with e ->  
+        lprintf_nl () "Exception %s in loading downloaded file %s" 
(Printexc2.to_string e) filename;
+        Sys.remove filename;
+        raise Not_found
   )
-  with e -> lprintf_nl () "Exception %s in wget" (Printexc2.to_string e); 
raise Not_found
+  with e -> 
+    lprintf_nl () "Exception %s in wget" (Printexc2.to_string e); 
+    raise Not_found
 
 let whead r f = 
   




reply via email to

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