714 |
end; |
end; |
715 |
|
|
716 |
let file = c.client_file in |
let file = c.client_file in |
717 |
|
|
718 |
|
(* Sending the "Have" message was moved to bTGlobals so this is useless *) |
719 |
(* if c.client_blocks_sent != file.file_blocks_downloaded then begin |
(* if c.client_blocks_sent != file.file_blocks_downloaded then begin |
720 |
let rec iter list = |
let rec iter list = |
721 |
match list with |
match list with |
765 |
(*Update rate and amount of data received from client*) |
(*Update rate and amount of data received from client*) |
766 |
c.client_downloaded <- c.client_downloaded ++ |
c.client_downloaded <- c.client_downloaded ++ |
767 |
(new_downloaded -- old_downloaded); |
(new_downloaded -- old_downloaded); |
768 |
|
(* use len here with max_dr quickfix *) |
769 |
Rate.update c.client_downloaded_rate (float_of_int len); |
Rate.update c.client_downloaded_rate (float_of_int len); |
770 |
(* update the stats *) |
(* update the stats *) |
771 |
let len64 = Int64.of_int len in |
let len64 = Int64.of_int len in |
795 |
c.client_ranges_sent <- tail; |
c.client_ranges_sent <- tail; |
796 |
end; |
end; |
797 |
get_from_client sock c; |
get_from_client sock c; |
798 |
if (List.length !current_uploaders < (!!max_uploaders_per_torrent-1)) && |
if (List.length !current_uploaders < (!!max_bt_uploaders-1)) && |
799 |
(List.mem c (!current_uploaders)) == false && c.client_interested then |
(List.mem c (!current_uploaders)) == false && c.client_interested then |
800 |
begin |
begin |
801 |
(*we are probably an optimistic uploaders for this client |
(*we are probably an optimistic uploaders for this client |
804 |
current_uploaders := c::(!current_uploaders); |
current_uploaders := c::(!current_uploaders); |
805 |
c.client_sent_choke <- false; |
c.client_sent_choke <- false; |
806 |
set_client_has_a_slot (as_client c) true; |
set_client_has_a_slot (as_client c) true; |
807 |
|
Rate.update_no_change c.client_downloaded_rate; |
808 |
|
Rate.update_no_change c.client_upload_rate; |
809 |
|
c.client_last_optimist <- last_time(); |
810 |
client_enter_upload_queue (as_client c); |
client_enter_upload_queue (as_client c); |
811 |
send_client c Unchoke; |
send_client c Unchoke; |
812 |
end; |
end; |
815 |
check_if_interesting file c |
check_if_interesting file c |
816 |
|
|
817 |
| PeerID p -> |
| PeerID p -> |
818 |
c.client_brand <- (parse_brand p); |
(* Disconnect if that is ourselves. *) |
819 |
c.client_software <- (parse_software p); |
if not (c.client_uid = !!client_uid) then |
820 |
|
begin |
821 |
|
c.client_brand <- (parse_brand p); |
822 |
|
c.client_software <- (parse_software p); |
823 |
(* TODO : enable it |
(* TODO : enable it |
824 |
c.client_release <- (parse_release p c.client_brand); |
c.client_release <- (parse_release p c.client_brand); |
825 |
*) |
*) |
826 |
c.client_uid <- Sha1.direct_of_string p; |
c.client_uid <- Sha1.direct_of_string p; |
827 |
(* Disconnect if that is ourselves. *) |
|
828 |
if c.client_uid = !!client_uid then disconnect_client c Closed_by_user |
if (List.length !current_uploaders < (!!max_bt_uploaders-1)) && |
829 |
|
(List.mem c (!current_uploaders)) == false then |
830 |
|
begin |
831 |
|
(*we are probably an optimistic uploader for this client |
832 |
|
don't miss the opportunity if we can *) |
833 |
|
current_uploaders := c::(!current_uploaders); |
834 |
|
c.client_sent_choke <- false; |
835 |
|
set_client_has_a_slot (as_client c) true; |
836 |
|
Rate.update_no_change c.client_downloaded_rate; |
837 |
|
Rate.update_no_change c.client_upload_rate; |
838 |
|
c.client_last_optimist <- last_time(); |
839 |
|
client_enter_upload_queue (as_client c); |
840 |
|
send_client c Unchoke; |
841 |
|
end |
842 |
|
else |
843 |
|
begin |
844 |
|
send_client c Choke; |
845 |
|
c.client_sent_choke <- true; |
846 |
|
end |
847 |
|
end |
848 |
|
else |
849 |
|
disconnect_client c Closed_by_user |
850 |
|
|
851 |
|
|
852 |
| BitField p -> |
| BitField p -> |
853 |
(*A bitfield is a summary of what a client have*) |
(*A bitfield is a summary of what a client have*) |
1460 |
CommonUploads.consume_bandwidth len; |
CommonUploads.consume_bandwidth len; |
1461 |
(* lprintf "Unix32.read: offset %Ld len %d\n" offset len; *) |
(* lprintf "Unix32.read: offset %Ld len %d\n" offset len; *) |
1462 |
Unix32.read (file_fd file) offset upload_buffer 0 len; |
Unix32.read (file_fd file) offset upload_buffer 0 len; |
1463 |
(* update upload rate from len bytes *) |
(* update upload rate from len bytes *) |
1464 |
|
(* will be reverted to len instead of len / 2 when rate bug will be fixed *) |
1465 |
Rate.update c.client_upload_rate (float_of_int (len / 2)); |
Rate.update c.client_upload_rate (float_of_int (len / 2)); |
1466 |
file.file_uploaded <- file.file_uploaded ++ (Int64.of_int len); |
file.file_uploaded <- file.file_uploaded ++ (Int64.of_int len); |
1467 |
let _ = |
let _ = |