496 |
set_client_state (c) (Connected (-1)); |
set_client_state (c) (Connected (-1)); |
497 |
if not init_sent then |
if not init_sent then |
498 |
begin |
begin |
499 |
c.client_incoming<-true; |
c.client_incoming <- true; |
500 |
send_init !!client_uid file_id sock; |
send_init !!client_uid file_id sock; |
501 |
end; |
end; |
502 |
connection_ok c.client_connection_control; |
connection_ok c.client_connection_control; |
511 |
in common swarmer -> compare : partition -> partition -> bool |
in common swarmer -> compare : partition -> partition -> bool |
512 |
*) |
*) |
513 |
|
|
|
(* send_client c Unchoke; *) |
|
|
|
|
514 |
set_rtimeout sock !!client_timeout; |
set_rtimeout sock !!client_timeout; |
515 |
(*Once parse succesfully we define the function |
(* Once parsed succesfully we define the function client_to_client |
516 |
client_to_client to be the function used when a message |
to be the function used when a message is read *) |
|
is read*) |
|
517 |
gconn.gconn_handler <- Reader (fun gconn sock -> |
gconn.gconn_handler <- Reader (fun gconn sock -> |
518 |
bt_handler TcpMessages.parsing (client_to_client c) c sock |
bt_handler TcpMessages.parsing (client_to_client c) c sock |
519 |
); |
); |
573 |
*) |
*) |
574 |
and get_from_client sock (c: client) = |
and get_from_client sock (c: client) = |
575 |
let file = c.client_file in |
let file = c.client_file in |
576 |
(*Check if there's not enough requests in the 'pipeline' |
(* Check if there's not enough requests in the 'pipeline' |
577 |
and if a request can be send (not choked and file is downloading) *) |
and if a request can be send (not choked and file is downloading) *) |
578 |
if List.length c.client_ranges_sent < max_range_requests && |
if List.length c.client_ranges_sent < max_range_requests && |
579 |
file_state file = FileDownloading && (c.client_choked == false) then |
file_state file = FileDownloading && (c.client_choked == false) then |
580 |
(*num is the number of the piece, x and y are the position |
(* num is the number of the piece, x and y are the position |
581 |
of the subpiece in the piece(!), r is a (CommonSwarmer) range *) |
of the subpiece in the piece(!), r is a (CommonSwarmer) range *) |
582 |
|
|
583 |
let up = match c.client_uploader with |
let up = match c.client_uploader with |
584 |
None -> assert false |
None -> assert false |
746 |
[] -> lprintf_nl () "EMPTY Ranges !!!" |
[] -> lprintf_nl () "EMPTY Ranges !!!" |
747 |
| (p1,p2,r) :: _ -> |
| (p1,p2,r) :: _ -> |
748 |
let (x,y) = Int64Swarmer.range_range r in |
let (x,y) = Int64Swarmer.range_range r in |
749 |
lprintf_nl () "Current range %Ld [%d] (asked %Ld-%Ld[%Ld-%Ld])" |
lprintf_nl () "Current range from %s : %Ld [%d] (asked %Ld-%Ld[%Ld-%Ld])" |
750 |
position len |
c.client_software position len |
751 |
p1 p2 x y |
p1 p2 x y |
752 |
); |
); |
753 |
|
|
842 |
|
|
843 |
let verified = Int64Swarmer.verified_bitmap swarmer in |
let verified = Int64Swarmer.verified_bitmap swarmer in |
844 |
let npieces = Int64Swarmer.partition_size swarmer in |
let npieces = Int64Swarmer.partition_size swarmer in |
845 |
|
(* parse the pieces to see if the client is interesting *) |
846 |
for i = 0 to npieces -1 do |
for i = 0 to npieces -1 do |
847 |
(* lprintf "bitmap: %c, verified: %c" bitmap.[i] verified.[i]; *) |
(* lprintf "bitmap: %c, verified: %c" bitmap.[i] verified.[i]; *) |
848 |
if bitmap.[i] = '1' && verified.[i] < '2' then |
if bitmap.[i] = '1' && verified.[i] < '2' then |
880 |
let n = Int64.to_int n in |
let n = Int64.to_int n in |
881 |
let verified = Int64Swarmer.verified_bitmap swarmer in |
let verified = Int64Swarmer.verified_bitmap swarmer in |
882 |
(* lprintf_nl "verified: %c;" verified.[n]; *) |
(* lprintf_nl "verified: %c;" verified.[n]; *) |
883 |
|
(* if the peer has a chunk we don't, tell him we're interested and update his bitmap *) |
884 |
if verified.[n] < '2' then begin |
if verified.[n] < '2' then begin |
885 |
c.client_interesting <- true; |
c.client_interesting <- true; |
886 |
send_interested c; |
send_interested c; |
966 |
[] -> |
[] -> |
967 |
CommonUploads.ready_for_upload (as_client c); |
CommonUploads.ready_for_upload (as_client c); |
968 |
| _ -> ()); |
| _ -> ()); |
969 |
c.client_upload_requests <- |
c.client_upload_requests <- c.client_upload_requests @ [n,pos,len]; |
|
c.client_upload_requests @ [n,pos,len]; |
|
970 |
let file = c.client_file in |
let file = c.client_file in |
971 |
match file.file_shared with |
match file.file_shared with |
972 |
None -> () |
None -> () |
1156 |
) in |
) in |
1157 |
listen_sock := Some s; |
listen_sock := Some s; |
1158 |
() |
() |
1159 |
with e -> |
with e -> |
1160 |
if !verbose_connect then |
if !verbose_connect then |
1161 |
lprintf_nl () "Exception %s while init bittorrent server" |
lprintf_nl () "Exception %s while init bittorrent server" |
1162 |
(Printexc2.to_string e) |
(Printexc2.to_string e) |
1241 |
File.to_string filename |
File.to_string filename |
1242 |
with e -> lprintf_nl () "Empty reply from tracker"; "" |
with e -> lprintf_nl () "Empty reply from tracker"; "" |
1243 |
in |
in |
1244 |
let v = |
let v = |
1245 |
match tracker_reply with |
match tracker_reply with |
1246 |
| "" -> |
| "" -> |
1247 |
if !verbose_connect then |
if !verbose_connect then |