mldonkey-commits
[Top][All Lists]
Advanced

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

[Mldonkey-commits] Changes to mldonkey/src/networks/bittorrent/bTTorrent


From: mldonkey-commits
Subject: [Mldonkey-commits] Changes to mldonkey/src/networks/bittorrent/bTTorrent.ml
Date: Sun, 10 Jul 2005 19:19:20 -0400

Index: mldonkey/src/networks/bittorrent/bTTorrent.ml
diff -u mldonkey/src/networks/bittorrent/bTTorrent.ml:1.4 
mldonkey/src/networks/bittorrent/bTTorrent.ml:1.5
--- mldonkey/src/networks/bittorrent/bTTorrent.ml:1.4   Thu Jul  7 00:25:46 2005
+++ mldonkey/src/networks/bittorrent/bTTorrent.ml       Sun Jul 10 23:19:16 2005
@@ -56,16 +56,16 @@
 
   *)
 
-    
-let chunk_size = Int64.of_int (256 * 1024)    
+
+let chunk_size = Int64.of_int (256 * 1024)
   
 let decode_torrent s =
-  if !verbose_msg_servers then lprintf ".torrent file loaded\n";
+  if !verbose_msg_servers then lprintf_nl "[BT]: .torrent file loaded\n";
 (*            lprintf "Loaded: %s\n" (String.escaped s); *)
   let v = Bencode.decode s in
 (*            lprintf "Decoded file: %s\n" (Bencode.print v);  *)
-  
-  
+
+
   let announce = ref "" in
   let file_info = ref (List []) in
   let file_name = ref "" in
@@ -73,7 +73,7 @@
   let file_pieces = ref "" in
   let length = ref zero in
   let file_files = ref [] in
-  
+
   let parse_files files =
     let current_pos = ref zero in
     List.iter (fun v ->
@@ -86,39 +86,39 @@
             List.iter (fun (key, value) ->
                 match key, value with
                   String "path", List path ->
-                    current_file := 
+                    current_file :=
                     Filepath.path_to_string '/'
                       (List.map (fun v ->
                           match v with
                             String s -> s
                           | _ -> assert false
                       ) path)
-                
+
                 | String "length", Int n ->
                     length := !length ++ n;
                     current_length := n;
                     length_set := true
-                
-                | String key, _ -> 
+
+                | String key, _ ->
                     if !verbose_msg_servers then lprintf "other field [%s] in 
files\n" key
-                | _ -> 
-                    lprintf "other field in files\n"
+                | _ ->
+                    lprintf_nl "[BT]: other field in files\n"
             ) list;
-            
+
             assert (!length_set);
             assert (!current_file <> "");
             file_files := (!current_file, !current_length) :: !file_files;
             current_pos := !current_pos ++ !current_length
-        
+
         | _ -> assert false
     ) files;
   in
-  
+
   begin
     match v with
       Dictionary list ->
         List.iter (fun (key, value) ->
-            match key, value with 
+            match key, value with
               String "announce", String tracker_url ->
                 announce := tracker_url
             | String "info", ((Dictionary list) as info) ->
@@ -127,8 +127,8 @@
                 List.iter (fun (key, value) ->
                     match key, value with
                     | String "files", List files ->
-                        parse_files files                    
-                    | String "length", Int n -> 
+                        parse_files files
+                    | String "length", Int n ->
                         length := n
                     | String "name", String name ->
                         file_name := name
@@ -140,22 +140,22 @@
                         if !verbose_msg_servers then lprintf "other field [%s] 
in info\n" key
                     | _ -> 
                         lprintf "other field in info\n"
-                ) list            
-            | String key, _ -> 
+                ) list
+            | String key, _ ->
                 if !verbose_msg_servers then lprintf "other field [%s] after 
info\n" key
-            | _ -> 
+            | _ ->
                 lprintf "other field after info\n"
         ) list
     | _ -> assert false
   end;
-  
+
   assert (!announce <> "");
   assert (!file_name <> "");
   assert (!file_piece_size <> zero);
   assert (!file_pieces <> "");
-  
+
   assert (!file_info = Bencode.decode (Bencode.encode !file_info));
-  
+
   let file_id = Sha1.string (Bencode.encode !file_info) in
   let npieces =
     1+ Int64.to_int ((!length -- one) // !file_piece_size)
@@ -170,7 +170,7 @@
 (*  if !file_files <> [] && not (String2.check_suffix !file_name ".torrent") 
then
     file_name := !file_name ^ ".torrent";*)
   file_files := List.rev !file_files;
-  
+
   file_id, {
     torrent_name = !file_name;
     torrent_length = !length;
@@ -179,9 +179,9 @@
     torrent_files = !file_files;
     torrent_pieces = pieces;
   }
-  
+
 let encode_torrent torrent =
-  
+
   let npieces = Array.length torrent.torrent_pieces in
   let pieces = String.create (20 * npieces) in
   for i = 0 to npieces - 1 do
@@ -191,21 +191,21 @@
 
   let encode_file (filename, size) =
     Dictionary [
-      String "path", List (List.map 
+      String "path", List (List.map
           (fun s -> String s)(Filepath.string_to_path '/' filename));
       String "length", Int size;
     ]
   in
-  
-  let files = 
+
+  let files =
     match torrent.torrent_files with 
-      [] ->       
+      [] ->
         String "length", Int torrent.torrent_length
     | _ ->
-        String "files", 
+        String "files",
         List (List.map encode_file torrent.torrent_files)
   in
-  
+
   let info =
     Dictionary [
       files;
@@ -214,7 +214,7 @@
       String "pieces", String pieces;
     ]
   in
-  
+
   let info_encoded = Bencode.encode info in
   let file_id = Sha1.string info_encoded in
   file_id, 
@@ -222,15 +222,15 @@
     String "announce", String torrent.torrent_announce;
     String "info", info;
   ]
-    
-let make_torrent announce filename = 
+
+let make_torrent announce filename =
   let basename = Filename.basename filename in
   let files, t =
     if Unix2.is_directory filename then
       let rec iter_directory list dirname =
         let files = Unix2.list_directory (Filename.concat filename dirname) in
         iter_files list dirname files
-      
+
       and iter_files list dirname files =
         match files with
           [] -> list
@@ -251,23 +251,23 @@
     else
       [], Unix32.create_ro filename
   in
-  
+
   Unix32.flush_fd t;
   let length = Unix32.getsize64 t false in
   let npieces = 1+ Int64.to_int ((length -- one) // chunk_size) in
   let pieces = Array.create npieces Sha1.null in
   for i = 0 to npieces - 1 do
     let begin_pos = chunk_size *.. i in
-    
+
     let end_pos = begin_pos ++ chunk_size in
     let end_pos = 
       if end_pos > length then length else end_pos in
-    
+
     let sha1 = Sha1.digest_subfile t
         begin_pos (end_pos -- begin_pos) in
     pieces.(i) <- sha1
   done;
-  
+
   {
     torrent_name = basename;
     torrent_length = length;




reply via email to

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