36 |
open DonkeyComplexOptions |
open DonkeyComplexOptions |
37 |
open DonkeyGlobals |
open DonkeyGlobals |
38 |
|
|
39 |
|
let lprintf_nl () = |
40 |
|
lprintf "%s[EDK]: " |
41 |
|
(log_time ()); lprintf_nl2 |
42 |
|
|
43 |
let new_shared_files = ref [] |
let new_shared_files = ref [] |
44 |
|
|
45 |
let must_share_file file codedname has_old_impl = |
let must_share_file file codedname has_old_impl = |
89 |
in |
in |
90 |
|
|
91 |
if !verbose_share then |
if !verbose_share then |
92 |
lprintf_nl "EDK: Sharing file with MD4: %s" (Md4.to_string md4); |
lprintf_nl () "Sharing file with MD4: %s" (Md4.to_string md4); |
93 |
|
|
94 |
let file = new_file sh.sh_name FileShared md4 sh.sh_size |
let file = new_file sh.sh_name FileShared md4 sh.sh_size |
95 |
[Filename.basename sh.sh_name, GuiTypes.noips()] |
[Filename.basename sh.sh_name, GuiTypes.noips()] |
129 |
Int64Swarmer.verify_all_blocks s true; |
Int64Swarmer.verify_all_blocks s true; |
130 |
*) |
*) |
131 |
if !verbose_share then |
if !verbose_share then |
132 |
lprintf_nl "EDK: verified map of %s = %s" |
lprintf_nl () "verified map of %s = %s" |
133 |
(codedname) (Int64Swarmer.verified_bitmap s)) |
(codedname) (Int64Swarmer.verified_bitmap s)) |
134 |
| None -> if !verbose_share then lprintf_nl "EDK: no swarmer for %s" codedname; |
| None -> if !verbose_share then lprintf_nl () "no swarmer for %s" codedname; |
135 |
(try |
(try |
136 |
file.file_format <- CommonMultimedia.get_info |
file.file_format <- CommonMultimedia.get_info |
137 |
(file_disk_name file) |
(file_disk_name file) |
143 |
lprintf "DonkeyOvernet.publish_file: %s" (Printexc2.to_string e); |
lprintf "DonkeyOvernet.publish_file: %s" (Printexc2.to_string e); |
144 |
lprint_newline ()); |
lprint_newline ()); |
145 |
*) |
*) |
146 |
if !verbose_share then begin |
if !verbose_share then |
147 |
lprintf_nl "EDK: Sharing %s" sh.sh_name; |
lprintf_nl () "EDK: Sharing %s" sh.sh_name; |
|
end; |
|
148 |
with e -> |
with e -> |
149 |
lprintf_nl "EDK: Exception %s while sharing %s" (Printexc2.to_string e) |
lprintf_nl () "EDK: Exception %s while sharing %s" (Printexc2.to_string e) |
150 |
sh.sh_name |
sh.sh_name |
151 |
|
|
152 |
|
|
157 |
None -> () |
None -> () |
158 |
| Some _ -> shared_files := file :: !shared_files |
| Some _ -> shared_files := file :: !shared_files |
159 |
) files_by_md4; |
) files_by_md4; |
160 |
if !verbose_share then lprintf "%d files shared\n" (List.length !shared_files); |
if !verbose_share then lprintf_nl () "%d files shared" (List.length !shared_files); |
161 |
!shared_files |
!shared_files |
162 |
|
|
163 |
(* Check whether new files are shared, and send them to connected servers. |
(* Check whether new files are shared, and send them to connected servers. |
177 |
if s.server_master then |
if s.server_master then |
178 |
begin |
begin |
179 |
if !verbose_share then |
if !verbose_share then |
180 |
lprintf "donkey send_new_shared: found master server\n"; |
lprintf_nl () "donkey send_new_shared: found master server"; |
181 |
do_if_connected s.server_sock (fun sock -> |
do_if_connected s.server_sock (fun sock -> |
182 |
server_send_share s.server_has_zlib sock !new_shared_files) |
server_send_share s.server_has_zlib sock !new_shared_files) |
183 |
end |
end |
184 |
) |
) |
185 |
(connected_servers ()); |
(connected_servers ()); |
186 |
if !verbose_share then |
if !verbose_share then |
187 |
lprintf "donkey send_new_shared: Sent %d new shared files to servers\n" |
lprintf_nl () "donkey send_new_shared: Sent %d new shared files to servers" |
188 |
(List.length !new_shared_files); |
(List.length !new_shared_files); |
189 |
new_shared_files := [] |
new_shared_files := [] |
190 |
end |
end |
191 |
else |
else |
192 |
lprintf "donkey send_new_share: No new shared files to send to servers\n" |
lprintf_nl () "donkey send_new_share: No new shared files to send to servers" |
193 |
end |
end |
194 |
|
|
195 |
(* |
(* |
214 |
let rec job_creater _ = |
let rec job_creater _ = |
215 |
try |
try |
216 |
if not (Sys.file_exists sh.shared_name) then begin |
if not (Sys.file_exists sh.shared_name) then begin |
217 |
lprintf "Shared file doesn't exist\n"; |
lprintf_nl () "Shared file doesn't exist"; |
218 |
raise Not_found; |
raise Not_found; |
219 |
end; |
end; |
220 |
if Unix32.getsize sh.shared_name false <> sh.shared_size then begin |
if Unix32.getsize sh.shared_name false <> sh.shared_size then begin |
221 |
lprintf "Bad shared file size\n" ; |
lprintf_nl () "Bad shared file size"; |
222 |
raise Not_found; |
raise Not_found; |
223 |
end; |
end; |
224 |
computation := true; |
computation := true; |
232 |
(fun job -> |
(fun job -> |
233 |
computation := false; |
computation := false; |
234 |
if job.M.job_error then begin |
if job.M.job_error then begin |
235 |
lprintf "Error prevent sharing %s\n" sh.shared_name |
lprintf_nl () "Error prevent sharing %s" sh.shared_name |
236 |
end else |
end else |
237 |
let _ = () in |
let _ = () in |
238 |
(* lprintf "md4 computed"; lprint_newline (); *) |
(* lprintf "md4 computed"; lprint_newline (); *) |
247 |
sh_md4s = Array.of_list (List.rev sh.shared_list); |
sh_md4s = Array.of_list (List.rev sh.shared_list); |
248 |
sh_mtime = Unix32.mtime sh.shared_name; |
sh_mtime = Unix32.mtime sh.shared_name; |
249 |
} in |
} in |
250 |
lprintf "Donkey: NEW SHARED FILE %s\n" sh.shared_name; |
lprintf_nl () "New shared file %s" sh.shared_name; |
251 |
Hashtbl.add shared_files_info |
Hashtbl.add shared_files_info |
252 |
(s.sh_name, s.sh_size, s.sh_mtime) s; |
(s.sh_name, s.sh_size, s.sh_mtime) s; |
253 |
known_shared_files =:= s :: !!known_shared_files; |
known_shared_files =:= s :: !!known_shared_files; |
256 |
else |
else |
257 |
job_creater ()) |
job_creater ()) |
258 |
with e -> |
with e -> |
259 |
lprintf "Exception %s prevents sharing\n" |
lprintf_nl () "Exception %s prevents sharing" |
260 |
(Printexc2.to_string e); |
(Printexc2.to_string e); |
261 |
in |
in |
262 |
job_creater () |
job_creater () |
266 |
let _ = |
let _ = |
267 |
network.op_network_share <- (fun fullname codedname size -> |
network.op_network_share <- (fun fullname codedname size -> |
268 |
if !verbose_share then |
if !verbose_share then |
269 |
lprintf "donkeyShare: Sharing %s\n" fullname; |
lprintf_nl () "Sharing %s" fullname; |
270 |
try |
try |
271 |
(* |
(* |
272 |
lprintf "Searching %s" fullname; lprint_newline (); |
lprintf "Searching %s" fullname; lprint_newline (); |
276 |
(fullname, size, mtime) in |
(fullname, size, mtime) in |
277 |
(* if s.sh_mtime = mtime && s.sh_size = size then begin *) |
(* if s.sh_mtime = mtime && s.sh_size = size then begin *) |
278 |
if !verbose_share then begin |
if !verbose_share then begin |
279 |
lprintf "donkeyShare: Using old MD4s for %s\n" fullname; |
lprintf_nl () "donkeyShare: Using old MD4s for %s" fullname; |
280 |
end; |
end; |
281 |
new_file_to_share s codedname None |
new_file_to_share s codedname None |
282 |
(* end else begin |
(* end else begin |
289 |
end *) |
end *) |
290 |
with Not_found -> |
with Not_found -> |
291 |
if !verbose_share then begin |
if !verbose_share then begin |
292 |
lprintf "donkeyShare: No info on %s\n" fullname; |
lprintf_nl () "donkeyShare: No info on %s" fullname; |
293 |
end; |
end; |
294 |
|
|
295 |
let rec iter list left = |
let rec iter list left = |
338 |
Unix32.mtime disk_name |
Unix32.mtime disk_name |
339 |
with _ -> |
with _ -> |
340 |
if !verbose_hidden_errors then |
if !verbose_hidden_errors then |
341 |
lprintf "Trying mtime on new name\n"; |
lprintf_nl () "Trying mtime on new name"; |
342 |
Unix32.mtime new_name |
Unix32.mtime new_name |
343 |
in |
in |
344 |
|
|
345 |
if !verbose_share then begin |
if !verbose_share then begin |
346 |
lprintf "Remember %s\n" new_name; |
lprintf_nl () "Remember %s" new_name; |
347 |
end; |
end; |
348 |
|
|
349 |
let size = file_size file in |
let size = file_size file in |
359 |
known_shared_files =:= s :: !!known_shared_files; |
known_shared_files =:= s :: !!known_shared_files; |
360 |
Hashtbl.add shared_files_info (new_name, size, mtime) s |
Hashtbl.add shared_files_info (new_name, size, mtime) s |
361 |
with e -> |
with e -> |
362 |
lprintf "Exception %s in remember_shared_info\n" |
lprintf_nl () "Exception %s in remember_shared_info" |
363 |
(Printexc2.to_string e) |
(Printexc2.to_string e) |
364 |
|
|
365 |
let must_share_file file = must_share_file file (file_best_name file) None |
let must_share_file file = must_share_file file (file_best_name file) None |