[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Mldonkey-commits] Changes to mldonkey/src/networks/bittorrent/bTComplex
From: |
mldonkey-commits |
Subject: |
[Mldonkey-commits] Changes to mldonkey/src/networks/bittorrent/bTComplexOptions.ml |
Date: |
Sun, 10 Jul 2005 19:19:20 -0400 |
Index: mldonkey/src/networks/bittorrent/bTComplexOptions.ml
diff -u mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.19
mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.20
--- mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.19 Thu Jul 7
00:25:46 2005
+++ mldonkey/src/networks/bittorrent/bTComplexOptions.ml Sun Jul 10
23:19:16 2005
@@ -19,9 +19,10 @@
open Int64ops
open Printf2
+open BasicSocket
open Md4
open Options
-
+
open CommonGlobals
open CommonDownloads
open CommonTypes
@@ -46,11 +47,11 @@
let client_port = get_value "client_port" value_to_int in
let client_uid = get_value "client_uid" (from_value Sha1.option) in
let c = new_client file client_uid (client_ip, client_port) in
-
+
c
| _ -> failwith "Options: Not a client"
-
-
+
+
let client_to_value c =
let (ip,port) = c.client_host in
Options.Module [
@@ -61,24 +62,24 @@
let to_value = client_to_value
let of_value = value_to_client
-
+
end
let value_to_file file_size file_state assocs =
let get_value name conv = conv (List.assoc name assocs) in
- let get_value_nil name conv =
+ let get_value_nil name conv =
try conv (List.assoc name assocs) with _ -> []
in
-
- let file_trackers =
+
+ let file_trackers =
try
get_value "file_trackers" (value_to_list value_to_string)
- with _ ->
+ with _ ->
try
[get_value "file_tracker" value_to_string]
with _ -> failwith "Bad file_tracker"
in
-
+
let file_id, torrent, torrent_diskname =
try
let torrent_diskname = get_value "file_torrent_name" value_to_string in
@@ -86,7 +87,7 @@
let file_id, torrent = BTTorrent.decode_torrent s in
file_id, torrent, torrent_diskname
with _ ->
-
+
let file_name = get_value "file_name" value_to_string in
let file_id =
try
@@ -94,17 +95,17 @@
with _ -> failwith "Bad file_id"
in
let file_piece_size = try
- value_to_int64 (List.assoc "file_piece_size" assocs)
+ value_to_int64 (List.assoc "file_piece_size" assocs)
with _ -> failwith "Bad file size"
in
- let file_chunks =
+ let file_chunks =
get_value "file_hashes" (value_to_array
(from_value Sha1.option))
in
let file_size = get_value "file_size" value_to_int64 in
- let file_files =
+ let file_files =
try
- let file_files = (get_value "file_files"
+ let file_files = (get_value "file_files"
(value_to_list (fun v ->
match v with
SmallList [name; p1]
@@ -121,33 +122,33 @@
torrent_piece_size = file_piece_size;
torrent_files = file_files;
torrent_length = file_size;
- torrent_announce =
+ torrent_announce =
(
try
(List.hd file_trackers)
with _ -> ""
);
} in
- let torrent_diskname = Filename.concat downloads_directory
+ let torrent_diskname = Filename.concat downloads_directory
(file_name ^ ".torrent") in
file_id, torrent, torrent_diskname
-
+
in
let file_temp = try
get_value "file_temp" value_to_string
with Not_found ->
- let file_temp = Filename.concat !!DO.temp_directory
+ let file_temp = Filename.concat !!DO.temp_directory
(Printf.sprintf "BT-%s" (Sha1.to_string file_id)) in
- file_temp
+ file_temp
in
let file = new_file file_id torrent torrent_diskname file_temp file_state in
-
+
let file_uploaded = try
- value_to_int64 (List.assoc "file_uploaded" assocs)
+ value_to_int64 (List.assoc "file_uploaded" assocs)
with _ -> zero
in
file.file_uploaded <- file_uploaded;
-
+
(match file.file_swarmer with
None -> ()
| Some swarmer ->
@@ -158,13 +159,13 @@
ignore
(get_value "file_sources" (
value_to_list (ClientOption.of_value file)))
- with e ->
+ with e ->
lprintf_nl "[BT]: Exception %s while loading sources"
- (Printexc2.to_string e);
+ (Printexc2.to_string e);
);
as_file file
-
+
let file_to_value file =
try
let sources = Hashtbl2.to_list file.file_clients in
@@ -175,15 +176,15 @@
"file_name", string_to_value file.file_name;
"file_uploaded", int64_to_value (file.file_uploaded);
"file_id", string_to_value (Sha1.to_string file.file_id);
- "file_trackers", (list_to_value string_to_value)
+ "file_trackers", (list_to_value string_to_value)
(List.map (fun t -> t.tracker_url) file.file_trackers);
(* OK, but I still don't like the idea of forgetting all the clients.
We should have a better strategy, ie rating the clients and connecting
to them depending on the results of our last connections. And then,
if we could not download enough in the last interval, ask the tracker to
send us more clients.
-
- "file_sources",
+
+ "file_sources",
list_to_value "BT Sources" (fun c ->
ClientOption.to_value c) sources
;
@@ -192,7 +193,7 @@
in
let assocs =
("file_torrent_name", string_to_value file.file_torrent_diskname) ::
- ("file_hashes", array_to_value
+ ("file_hashes", array_to_value
(to_value Sha1.option) file.file_chunks) ::
("file_files", list_to_value
(fun (name, p1) ->
@@ -201,7 +202,7 @@
assocs
in
match file.file_swarmer with
- None -> assocs
+ None -> assocs
| Some swarmer ->
Int64Swarmer.swarmer_to_value swarmer assocs
with
@@ -209,11 +210,11 @@
lprintf_nl "BTComplexOptions: exception %s in file_to_value"
(Printexc2.to_string e); raise e
-let old_files =
+let old_files =
define_option bittorrent_section ["old_files"]
"" (list_option (tuple2_option (string_option, int64_option))) []
-
-
+
+
let save_config () =
Options.save_with_help bittorrent_ini