[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Mldonkey-commits] Changes to mldonkey/src/networks/fileTP/fileTPClients
From: |
mldonkey-commits |
Subject: |
[Mldonkey-commits] Changes to mldonkey/src/networks/fileTP/fileTPClients.ml |
Date: |
Tue, 26 Jul 2005 19:16:49 -0400 |
Index: mldonkey/src/networks/fileTP/fileTPClients.ml
diff -u mldonkey/src/networks/fileTP/fileTPClients.ml:1.9
mldonkey/src/networks/fileTP/fileTPClients.ml:1.10
--- mldonkey/src/networks/fileTP/fileTPClients.ml:1.9 Thu Jul 7 00:25:46 2005
+++ mldonkey/src/networks/fileTP/fileTPClients.ml Tue Jul 26 23:16:48 2005
@@ -37,8 +37,8 @@
open CommonTypes
open CommonFile
open CommonGlobals
-open CommonDownloads
-
+open CommonDownloads
+
open FileTPTypes
open FileTPOptions
open FileTPGlobals
@@ -55,16 +55,16 @@
*)
let max_queued_ranges = 1
-let nranges file =
- Int64.to_int (Int64.div (file_size file)
+let nranges file =
+ Int64.to_int (Int64.div (file_size file)
min_range_size) + 5
-
+
let disconnect_client c r =
match c.client_sock with
- | Connection sock ->
+ | Connection sock ->
(try
if !verbose_msg_clients then begin
- lprintf "Disconnected from source\n";
+ lprintf "Disconnected from source\n";
end;
c.client_requests <- [];
connection_failed c.client_connection_control;
@@ -90,7 +90,7 @@
) c.client_downloads;
match c.client_connected_for with
None -> ()
- | Some file ->
+ | Some file ->
file.file_nconnected_clients <- file.file_nconnected_clients - 1;
(*
lprintf "For file %s, %d/%d clients connected (disconnected from
%d)\n"
@@ -98,25 +98,25 @@
(client_num (as_client c.client_client));
*)
c.client_connected_for <- None
- with e ->
+ with e ->
lprintf "Exception %s in disconnect_client\n"
(Printexc2.to_string e))
- | ConnectionWaiting token ->
+ | ConnectionWaiting token ->
cancel_token token;
c.client_sock <- NoConnection;
(match c.client_connected_for with
None -> ()
- | Some file ->
+ | Some file ->
file.file_nconnected_clients <- file.file_nconnected_clients - 1
);
c.client_connected_for <- None;
| _ -> ()
-
-let download_finished file =
+
+let download_finished file =
if List.memq file !current_files then begin
file_completed (as_file file);
FileTPGlobals.remove_file file;
- List.iter (fun c ->
+ List.iter (fun c ->
List.iter (fun d ->
if d.download_file == file then
old_files =:= d.download_url :: !!old_files
@@ -130,12 +130,12 @@
(file_size file = Int64Swarmer.downloaded swarmer) then begin
download_finished file
end
-
+
let get_from_client sock (c: client) =
-
+
let rec iter downloads =
match downloads with
- [] ->
+ [] ->
if !verbose_msg_clients then
lprintf "No other download to start\n";
raise Not_found
@@ -151,19 +151,19 @@
if !verbose_msg_clients then begin
lprintf "FILE FOUND, ASKING\n";
end;
-
+
if !verbose_swarming then begin
- lprintf "Current download:\n Current chunks: ";
+ lprintf "Current download:\n Current chunks: ";
List.iter (fun (x,y) -> lprintf "%Ld-%Ld " x y)
d.download_chunks;
lprintf "\n Current ranges: ";
List.iter (fun (x,y,r) ->
-(* let (x,y) = Int64Swarmer.range_range r in *)
+(* let (x,y) = Int64Swarmer.range_range r in *)
lprintf "%Ld-%Ld " x y) d.download_ranges;
lprintf "\n Current blocks: ";
(* List.iter (fun b -> Int64Swarmer.print_block b)
d.download_blocks; *)
lprintf "\n\nFinding Range: \n";
end;
- let range =
+ let range =
match d.download_uploader with
None -> assert false
| Some up ->
@@ -173,55 +173,54 @@
try
let rec iter () =
match d.download_block with
- None ->
+ None ->
if !verbose_swarming then lprintf "No block\n";
let b = Int64Swarmer.find_block up in
-
+
(* lprintf "GOT BLOCK:\n"; *)
Int64Swarmer.print_uploaders swarmer;
-
+
if !verbose_swarming then begin
lprintf "Block Found: ";
Int64Swarmer.print_block b;
end;
d.download_block <- Some b;
iter ()
| Some b ->
-
+
if !verbose_swarming then begin
lprintf "Current Block: ";
Int64Swarmer.print_block b;
end;
try
let (x,y,r) = Int64Swarmer.find_range up in
-
+
(* lprintf "GOT RANGE:\n"; *)
Int64Swarmer.print_uploaders swarmer;
-
+
d.download_ranges <- d.download_ranges @ [x,y,r];
(* Int64Swarmer.alloc_range r; *)
(x,y)
with Not_found ->
- if !verbose_swarming then
+ if !verbose_swarming then
lprintf "Could not find range in current
block\n";
(* d.download_blocks <- List2.removeq b
d.download_blocks; *)
d.download_block <- None;
iter ()
in
iter ()
- with Not_found ->
+ with Not_found ->
lprintf "Unable to get a block !!";
check_finished swarmer file;
raise Not_found
in
c.client_proto.proto_send_range_request c range sock d;
-
end
in
iter c.client_downloads
-
+
let init_client c sock =
TcpBufferedSocket.set_read_controler sock download_control;
TcpBufferedSocket.set_write_controler sock upload_control
-
+
let connect_client c =
(* lprintf "connect_client...\n"; *)
match c.client_sock with
@@ -235,25 +234,25 @@
if file_state file = FileDownloading then
begin
c.client_connected_for <- Some file;
- file.file_nconnected_clients <-
+ file.file_nconnected_clients <-
file.file_nconnected_clients + 1;
(*
lprintf "For file %s, %d/%d clients connected (connecting
%d)\n"
(file.file_name)
- file.file_nconnected_clients (nranges file)
+ file.file_nconnected_clients (nranges file)
(client_num (as_client c.client_client)); *)
raise Exit;
end
) c.client_downloads with _ -> ());
(* lprintf "...\n"; *)
(* lprintf "connect_client... pending\n"; *)
- let token =
+ let token =
add_pending_connection connection_manager (fun token ->
lprintf "Connection accepted\n";
if List.exists (fun d ->
let file = d.download_file in
- file_state file = FileDownloading
- ) c.client_downloads
+ file_state file = FileDownloading
+ ) c.client_downloads
then
try
if !verbose_msg_clients then begin
@@ -261,11 +260,11 @@
end;
if !verbose_msg_clients then begin
lprintf "connecting %s:%d\n" c.client_hostname
- c.client_port;
+ c.client_port;
end;
c.client_reconnect <- false;
let sock = c.client_proto.proto_connect token c (fun sock ->
-
+
List.iter (fun d ->
let file = d.download_file in
if file_size file <> zero then
@@ -273,15 +272,15 @@
None -> assert false | Some sw -> sw
in
let chunks = [ Int64.zero, file_size file ] in
- let up = Int64Swarmer.register_uploader swarmer
+ let up = Int64Swarmer.register_uploader swarmer
(as_client c)
(AvailableRanges chunks) in
d.download_uploader <- Some up
) c.client_downloads;
-
- init_client c sock;
+
+ init_client c sock;
get_from_client sock c
-
+
)
in
set_client_state c Connecting;
@@ -293,24 +292,22 @@
if !verbose_msg_clients then begin
lprintf "READY TO DOWNLOAD FILE\n";
end;
-
+
c.client_proto.proto_set_sock_handler c sock
-
+
with e ->
- lprintf "Exception %s while connecting to client\n"
+ lprintf "Exception %s while connecting to client\n"
(Printexc2.to_string e);
disconnect_client c (Closed_for_exception e)
else
disconnect_client c Closed_by_user
) in
c.client_sock <- ConnectionWaiting token
- | ConnectionWaiting _ ->
+ | ConnectionWaiting _ ->
(* lprintf "ConnectionWaiting...\n" *) ()
| Connection _ ->
(* lprintf "Already connected\n" *) ()
-
-
let get_file_from_source c file =
(* lprintf " get_file_from_source\n"; *)
if connection_can_try c.client_connection_control then begin
@@ -334,16 +331,15 @@
(* lprintf "done\n"; *)
()
-
-let nranges file =
- Int64.to_int (Int64.div (file_size file)
+let nranges file =
+ Int64.to_int (Int64.div (file_size file)
min_range_size) + 5
-
-let manage_hosts () =
+
+let manage_hosts () =
List.iter (fun file ->
if file_state file = FileDownloading then
try
-(* For each file, we allow only (nranges+5) simultaneous communications,
+(* For each file, we allow only (nranges+5) simultaneous communications,
to prevent too many clients from saturing the line for only one file. *)
let max_nconnected_clients = nranges file in
(* lprintf "max_nconnected_clients: %d > %d\n" max_nconnected_clients
@@ -352,8 +348,7 @@
let (_,c) = Queue.take file.file_clients_queue in
if !verbose then lprintf "One client\n";
c.client_in_queues <- List2.removeq file c.client_in_queues;
-
-
+
if file_size file = zero then
let proto = c.client_proto in
List.iter (fun d ->
@@ -369,4 +364,3 @@
done
with _ -> ()
) !current_files
-
\ No newline at end of file