872 |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
873 |
let rec iter bitmap chunks i len = |
let rec iter bitmap chunks i len = |
874 |
if i = len then false else |
if i = len then false else |
875 |
if chunks.(i) && bitmap.[i] < '2' then true else |
if Bitv.get chunks i && bitmap.[i] < '2' then true else |
876 |
iter bitmap chunks (i+1) len |
iter bitmap chunks (i+1) len |
877 |
in |
in |
878 |
iter bitmap chunks 0 (String.length bitmap) |
iter bitmap chunks 0 (String.length bitmap) |
890 |
end; |
end; |
891 |
|
|
892 |
let chunks = |
let chunks = |
893 |
if file_size file <= block_size then [| true |] |
if file_size file <= block_size then Bitv.create 1 true |
894 |
else |
else |
895 |
if chunks = [||] then |
if Bitv.length chunks = 0 then |
896 |
Array.create file.file_nchunks true |
Bitv.create file.file_nchunks true |
897 |
else |
else |
898 |
if Array.length chunks <> file.file_nchunks then begin |
if Bitv.length chunks <> file.file_nchunks then begin |
899 |
lprintf_nl () "BAD BAD BAD: number of chunks is different %d/%d for %s:%Ld on peer" (Array.length chunks) file.file_nchunks (Md4.to_string file.file_md4) (file_size file); |
lprintf_nl () "BAD: number of chunks is different %d/%d for %s:%Ld on peer" |
900 |
|
(Bitv.length chunks) |
901 |
|
file.file_nchunks |
902 |
|
(Md4.to_string file.file_md4) |
903 |
|
(file_size file); |
904 |
lprintf_nl () "Peer info: name=[%s] md4=[%s] overnet=[%s] brand=[%s]" |
lprintf_nl () "Peer info: name=[%s] md4=[%s] overnet=[%s] brand=[%s]" |
905 |
c.client_name |
c.client_name |
906 |
(Md4.to_string c.client_md4) |
(Md4.to_string c.client_md4) |
907 |
(string_of_bool (DonkeySources.source_brand c.client_source)) |
(string_of_bool (DonkeySources.source_brand c.client_source)) |
908 |
(brand_to_string c.client_brand) |
(brand_to_string c.client_brand); |
909 |
; |
Bitv.create file.file_nchunks false |
|
Array.create file.file_nchunks false |
|
910 |
(* What should we do ? |
(* What should we do ? |
911 |
|
|
912 |
1) Try to recover the correct size of the file: we can use |
1) Try to recover the correct size of the file: we can use |
1327 |
v |
v |
1328 |
in |
in |
1329 |
List.iter (fun (file, chunks) -> |
List.iter (fun (file, chunks) -> |
1330 |
let chunks = Array.copy chunks in |
let chunks = Bitv.copy chunks in |
1331 |
DonkeyOneFile.add_client_chunks c file chunks) files; |
DonkeyOneFile.add_client_chunks c file chunks) files; |
1332 |
(* DonkeyOneFile.restart_download c *) |
(* DonkeyOneFile.restart_download c *) |
1333 |
with _ -> |
with _ -> |
1449 |
end; |
end; |
1450 |
|
|
1451 |
if file_size file <= block_size then begin |
if file_size file <= block_size then begin |
1452 |
client_is_useful c file [|true|] |
client_is_useful c file (Bitv.create 1 true) |
1453 |
end else begin |
end else begin |
1454 |
|
|
1455 |
if file.file_computed_md4s = [||] then begin |
if file.file_computed_md4s = [||] then begin |
1930 |
(* file was found, if we have no swarmer, we have |
(* file was found, if we have no swarmer, we have |
1931 |
the file complete and share it! it's save to |
the file complete and share it! it's save to |
1932 |
asume that we have all chunks! *) |
asume that we have all chunks! *) |
1933 |
Array.create file.file_nchunks true |
Bitv.create file.file_nchunks true |
1934 |
| Some swarmer -> |
| Some swarmer -> |
1935 |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
1936 |
Array.init (String.length bitmap) |
Bitv.init (String.length bitmap) |
1937 |
(fun i -> bitmap.[i] = '3') |
(fun i -> bitmap.[i] = '3') |
1938 |
(* This is not very smart, as we might get banned for this request. |
(* This is not very smart, as we might get banned for this request. |
1939 |
TODO We should probably check if we don't know already this source... |
TODO We should probably check if we don't know already this source... |
2506 |
| Some swarmer -> |
| Some swarmer -> |
2507 |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
let bitmap = Int64Swarmer.verified_bitmap swarmer in |
2508 |
let chunks = |
let chunks = |
2509 |
Array.init (String.length bitmap) |
Bitv.init (String.length bitmap) |
2510 |
(fun i -> bitmap.[i] = '3') |
(fun i -> bitmap.[i] = '3') |
2511 |
in |
in |
2512 |
let ncompletesources = if extendedrequest > 1 then |
let ncompletesources = if extendedrequest > 1 then |
2522 |
(* TODO build the extension if needed *) |
(* TODO build the extension if needed *) |
2523 |
M.QueryFile.emule_extension = emule_extension; |
M.QueryFile.emule_extension = emule_extension; |
2524 |
}); |
}); |
2525 |
let know_file_chunks = ref false in |
let know_file_chunks = List.exists (fun (f,_,_) -> f == file) c.client_file_queue in |
2526 |
List.iter (fun (f,_,_) -> |
if not know_file_chunks then |
|
if f == file then know_file_chunks := true |
|
|
) c.client_file_queue; |
|
|
|
|
|
if not !know_file_chunks then |
|
2527 |
DonkeyProtoCom.client_send c ( |
DonkeyProtoCom.client_send c ( |
2528 |
let module M = DonkeyProtoClient in |
let module M = DonkeyProtoClient in |
2529 |
M.QueryChunksReq file.file_md4); |
M.QueryChunksReq file.file_md4); |