mldonkey-commits
[Top][All Lists]
Advanced

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

[Mldonkey-commits] mldonkey distrib/ChangeLog src/networks/bittorr...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distrib/ChangeLog src/networks/bittorr...
Date: Sat, 27 Mar 2010 13:24:50 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       10/03/27 13:24:50

Modified files:
        distrib        : ChangeLog 
        src/networks/bittorrent: bTClients.ml bTGlobals.ml 
                                 bTInteractive.ml 
Added files:
        src/networks/bittorrent: TODO 

Log message:
        patch #7139

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1411&r2=1.1412
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTClients.ml?cvsroot=mldonkey&r1=1.100&r2=1.101
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTGlobals.ml?cvsroot=mldonkey&r1=1.84&r2=1.85
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/bTInteractive.ml?cvsroot=mldonkey&r1=1.148&r2=1.149
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/networks/bittorrent/TODO?cvsroot=mldonkey&rev=1.1

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1411
retrieving revision 1.1412
diff -u -b -r1.1411 -r1.1412
--- distrib/ChangeLog   27 Mar 2010 13:22:35 -0000      1.1411
+++ distrib/ChangeLog   27 Mar 2010 13:24:49 -0000      1.1412
@@ -15,6 +15,13 @@
 =========
 
 2010/03/27
+7139: BT: Some improvements and fixes (ygrek)
+- Don't request sources from tracker (set numwant=0) if we don't need them e.g.
+  'stopped' event or when sharing
+- Prevent client from repeatedly sending 'started' events for shared files
+- Check that peer addresses, returned from tracker in compact format, are valid
+  and not blocked (same check as for non-compact format)
+- Show torrent info_hash in html ui
 7138: BT: Recognize more client brands (ygrek)
 7137: Fix error in calculating average upload speed for client (ygrek)
 7136: GTK2 GUI: start downloads from search results items

Index: src/networks/bittorrent/bTClients.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTClients.ml,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -b -r1.100 -r1.101
--- src/networks/bittorrent/bTClients.ml        20 Mar 2010 13:36:54 -0000      
1.100
+++ src/networks/bittorrent/bTClients.ml        27 Mar 2010 13:24:50 -0000      
1.101
@@ -84,10 +84,14 @@
    Everything else will be ok for a second connection to the tracker.
    Be careful to the spelling of this event
   @param f The function used to parse the result of the connection.
-   The function will get a file as an argument (@see
-   get_sources_from_tracker for an example)
+   The function will get a file as an argument (@see talk_to_tracker 
+   for an example)
+
+  If we have less than !!ask_tracker_threshold sources
+  and if we respect the file_tracker_interval then
+  we really ask sources to the tracker
 *)
-let connect_trackers file event f =
+let connect_trackers file event need_sources f =
 
   (* reset session statistics when sending 'started' event *)
   if event = "started" then
@@ -118,8 +122,13 @@
   in
 
   let args = ("no_peer_id", "1") :: ("compact", "1") :: args in
-  let args = if !!numwant > -1 then
-      ("numwant", string_of_int !!numwant) :: args else args
+  let args = 
+    if not need_sources then
+      ("numwant", "0") :: args
+    else if !!numwant > -1 then
+      ("numwant", string_of_int !!numwant) :: args 
+    else 
+      args
   in
   let args = if !!send_key then
       ("key", Sha1.to_hexa !!client_uid) :: args else args
@@ -173,8 +182,8 @@
       then
         begin
           (* if we already tried to connect but failed, disable tracker, but 
allow re-enabling *)
-          if file.file_tracker_connected && t.tracker_last_clients_num = 0 &&
-            t.tracker_last_conn < 1 then begin
+          if file.file_tracker_connected && t.tracker_last_clients_num = 0 && 
t.tracker_last_conn < 1 then 
+          begin
               if !verbose_msg_servers then
                 lprintf_nl "Request error from tracker: disabling %s" 
t.tracker_url;
              t.tracker_status <- Disabled (intern "MLDonkey: Request error 
from tracker")
@@ -188,7 +197,7 @@
                   ("key", t.tracker_key) :: args else args
               in
               if !verbose_msg_servers then
-                lprintf_nl "get_sources_from_tracker: tracker_connected:%s 
id:%s key:%s last_clients:%i last_conn-last_time:%i file: %s"
+                lprintf_nl "connect_trackers: tracker_connected:%s id:%s 
key:%s last_clients:%i last_conn-last_time:%i file: %s"
                   (string_of_bool file.file_tracker_connected)
                   t.tracker_id t.tracker_key t.tracker_last_clients_num
                   (t.tracker_last_conn - last_time()) file.file_name;
@@ -354,7 +363,7 @@
 let download_finished file =
     if List.memq file !current_files then
       begin
-        connect_trackers file "completed" (fun _ _ -> ()); (*must be called 
before swarmer gets removed from file*)
+        connect_trackers file "completed" false (fun _ _ -> ()); (*must be 
called before swarmer gets removed from file*)
         (*CommonComplexOptions.file_completed*)
         file_completed (as_file file);
         (* Remove the swarmer for this file as it is not useful anymore... *)
@@ -1321,16 +1330,29 @@
      0
    end
 
+(** Check that client is valid and record it *)
+let maybe_new_client file id ip port =
+  let cc = Geoip.get_country_code_option ip in
+  if id <> !!client_uid
+     && ip != Ip.null
+     && port <> 0
+     && (match !Ip.banned (ip, cc) with
+         | None -> true
+         | Some reason ->
+           if !verbose_connect then
+             lprintf_file_nl (as_file file) "%s:%d blocked: %s" (Ip.to_string 
ip) port reason;
+           false)
+  then
+    ignore (new_client file id (ip,port) cc);
+    if !verbose_sources > 1 then
+      lprintf_file_nl (as_file file) "Received %s:%d" (Ip.to_string ip) port;
+    ()
 
-(** In this function we initiate a connection to the file tracker
-  to get sources.
+(** In this function we interact with the tracker
   @param file The file for which we want some sources
-  @param url Url of the tracker
-  If we have less than !!ask_tracker_threshold sources
-  and if we respect the file_tracker_interval then
-  we really ask sources to the tracker
+  @param need_sources whether we need any sources
 *)
-let get_sources_from_tracker file =
+let talk_to_tracker file need_sources =
   let f t filename =
     (*This is the function which will be called by the http client
       for parsing the response
@@ -1350,7 +1372,7 @@
     in
     t.tracker_interval <- 600;
     t.tracker_min_interval <- 600;
-    t.tracker_last_clients_num <- 0;
+    if need_sources then t.tracker_last_clients_num <- 0;
     match v with
       Dictionary list ->
         List.iter (fun (key,value) ->
@@ -1413,11 +1435,10 @@
                   lprintf_file_nl (as_file file) "%s in file: %s has tracker 
id %s" t.tracker_url file.file_name n
 
             | String "peers", List list ->
+                if need_sources then
                 List.iter (fun v ->
                     match v with
-                      Dictionary list ->
-                        t.tracker_last_clients_num <- 
t.tracker_last_clients_num + 1;
-
+                    | Dictionary list ->
                         let peer_id = ref Sha1.null in
                         let peer_ip = ref Ip.null in
                         let port = ref 0 in
@@ -1433,25 +1454,9 @@
                             | _ -> ()
                         ) list;
 
-                        (* Only record valid clients *)
-                        let cc = Geoip.get_country_code_option !peer_ip in
-                        if !peer_id != Sha1.null &&
-                          !peer_id <> !!client_uid &&
-                          !peer_ip != Ip.null &&
-                          !port <> 0 &&
-                          (match !Ip.banned (!peer_ip, cc) with
-                              None -> true
-                            | Some reason ->
-                                if !verbose_connect then
-                                  lprintf_file_nl (as_file file) "%s:%d 
blocked: %s"
-                                    (Ip.to_string !peer_ip) !port reason;
-                                false)
-                        then
-                          ignore (new_client file !peer_id (!peer_ip,!port) 
cc);
-                          if !verbose_sources > 1 then
-                            lprintf_file_nl (as_file file) "Received %s:%d"
-                              (Ip.to_string !peer_ip) !port;
-                          ()
+                        t.tracker_last_clients_num <- 
t.tracker_last_clients_num + 1;
+                        maybe_new_client file !peer_id !peer_ip !port
+
                     | _ -> assert false
                 ) list
             | String "peers", String p ->
@@ -1461,11 +1466,12 @@
                         get_uint8 s (pos+2),get_uint8 s (pos+3))
                     and port = get_int16 s (pos+4)
                     in
-                    ignore (new_client file Sha1.null (ip,port) None);
                     t.tracker_last_clients_num <- t.tracker_last_clients_num + 
1;
+                    maybe_new_client file Sha1.null ip port;
 
                     iter_comp s (pos+6) l
                 in
+                if need_sources then 
                 iter_comp p 0 (String.length p)
             | String "private", Int n -> ()
               (* TODO: if set to 1, disable peer exchange *)
@@ -1475,9 +1481,9 @@
        (*Now, that we have added new clients to a file, it's time
          to connect to them*)
         if !verbose_sources > 0 then
-          lprintf_file_nl (as_file file) "get_sources_from_tracker: got %i 
source(s) for file %s"
+          lprintf_file_nl (as_file file) "talk_to_tracker: got %i source(s) 
for file %s"
             t.tracker_last_clients_num file.file_name;
-        resume_clients file
+        if need_sources then resume_clients file
 
     | _ -> assert false
   in
@@ -1485,13 +1491,15 @@
     if file.file_tracker_connected then ""
     else "started"
   in
-  connect_trackers file event f
+  connect_trackers file event need_sources f
 
 
 (** Check to see if file is finished, if not
   try to get sources for it
 *)
 let recover_files () =
+  if !verbose_share then
+    lprintf_nl "recover_files";
   List.iter (fun file ->
       match file.file_swarmer with
         None -> ()
@@ -1499,12 +1507,15 @@
           (try check_finished swarmer file with e -> ());
           match file_state file with
             FileDownloading ->
-              (try get_sources_from_tracker file with _ -> ())
+              if !verbose_share then
+                lprintf_file_nl (as_file file) "recover downloading";
+              (try talk_to_tracker file true with _ -> ())
           | FileShared ->
-              (try
-                  connect_trackers file "" (fun _ _ -> ()) with _ -> ())
+              if !verbose_share then
+                lprintf_file_nl (as_file file) "recover shared";
+              (try talk_to_tracker file false with _ -> ())
           | FilePaused -> () (*when we are paused we do nothing, not even 
logging this vvvv*)
-          | s -> lprintf_file_nl (as_file file) "Other state %s!!" 
(string_of_state s)
+          | s -> lprintf_file_nl (as_file file) "recover: Other state %s!!" 
(string_of_state s)
       ) !current_files
 
 let upload_buffer = String.create 100000
@@ -1593,7 +1604,7 @@
     | Enabled | Disabled_mld _ -> ()
     | Disabled_failure _ | Disabled _ -> t.tracker_status <- Enabled
   ) file.file_trackers;
-  (try get_sources_from_tracker file  with _ -> ())
+  (try talk_to_tracker file true with _ -> ())
 
 
 
@@ -1604,7 +1615,7 @@
 let file_stop file =
     if file.file_tracker_connected then
     begin
-      connect_trackers file "stopped" (fun _ _ ->
+      connect_trackers file "stopped" false (fun _ _ ->
           lprintf_file_nl (as_file file) "Tracker return: stopped %s" 
file.file_name;
           file.file_tracker_connected <- false)
     end

Index: src/networks/bittorrent/bTGlobals.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTGlobals.ml,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -b -r1.84 -r1.85

Index: src/networks/bittorrent/bTInteractive.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/networks/bittorrent/bTInteractive.ml,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -b -r1.148 -r1.149
--- src/networks/bittorrent/bTInteractive.ml    20 Mar 2010 13:36:54 -0000      
1.148
+++ src/networks/bittorrent/bTInteractive.ml    27 Mar 2010 13:24:50 -0000      
1.149
@@ -184,6 +184,11 @@
 
   Printf.bprintf buf "\\</tr\\>\\<tr class=\\\"dl-%d\\\"\\>" (html_mods_cntr 
());
   html_mods_td buf [
+    ("Torrent metadata hash", "sr", "Hash");
+    ("", "sr", Sha1.to_hexa file.file_id) ];
+
+  Printf.bprintf buf "\\</tr\\>\\<tr class=\\\"dl-%d\\\"\\>" (html_mods_cntr 
());
+  html_mods_td buf [
     ("Search for other possible Torrent Files", "sr br", "Torrent Srch");
     ("", "sr", Printf.sprintf "\\<a target=\\\"_blank\\\" 
href=\\\"http://isohunt.com/%s\\\"\\>IsoHunt\\</a\\>"
          (file.file_name)
@@ -673,7 +678,7 @@
     lprintf_nl "Starting torrent download with diskname: %s"
         torrent_diskname;
   let file = new_download file_id torrent torrent_diskname user group in
-  BTClients.get_sources_from_tracker file;
+  BTClients.talk_to_tracker file true;
   CommonInteractive.start_download (file_find (file_num file));
   file
 
@@ -688,6 +693,7 @@
     Sys.remove filename;
   ignore (load_torrent_string s user group)
 
+(*
 let parse_tracker_reply file t filename =
 (*This is the function which will be called by the http client
 for parsing the response*)
@@ -723,6 +729,7 @@
           | _ -> ()
       ) list;
   | _ -> assert false
+*)
 
 let try_share_file torrent_diskname =
   if !verbose_share then lprintf_nl "try_share_file: %s" torrent_diskname;
@@ -754,9 +761,10 @@
     let user = CommonUserDb.admin_user () in
     let file = new_file file_id torrent torrent_diskname
         filename FileShared user user.user_default_group in
-    if !verbose_share then lprintf_file_nl (as_file file) "Sharing file %s" 
filename;
-    BTClients.connect_trackers file "started"
-      (parse_tracker_reply file)
+
+    if !verbose_share then 
+      lprintf_file_nl (as_file file) "Sharing file %s" filename;
+    BTClients.talk_to_tracker file false
   with
   | Not_found ->
       (* if the torrent is still there while the file is gone, remove the 
torrent *)

Index: src/networks/bittorrent/TODO
===================================================================
RCS file: src/networks/bittorrent/TODO
diff -N src/networks/bittorrent/TODO
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/networks/bittorrent/TODO        27 Mar 2010 13:24:50 -0000      1.1
@@ -0,0 +1,2 @@
+* filter out duplicate trackers in metainfo (NB no port equals to :80 for http)
+* file_tracker_connected should be the property of tracker




reply via email to

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