33 |
open CommonTypes |
open CommonTypes |
34 |
|
|
35 |
let is_enabled = ref false |
let is_enabled = ref false |
36 |
|
|
37 |
let disable enabler () = |
let disable enabler () = |
38 |
if !enabler then begin |
if !enabler then begin |
39 |
is_enabled := false; |
is_enabled := false; |
40 |
enabler := false; |
enabler := false; |
41 |
List.iter (fun file -> |
List.iter (fun file -> |
42 |
Hashtbl2.safe_iter (fun c -> disconnect_client c Closed_by_user) |
Hashtbl2.safe_iter (fun c -> disconnect_client c Closed_by_user) |
43 |
file.file_clients) !current_files; |
file.file_clients) !current_files; |
44 |
(match !listen_sock with None -> () |
(match !listen_sock with None -> () |
45 |
| Some sock -> |
| Some sock -> |
46 |
listen_sock := None; |
listen_sock := None; |
47 |
TcpServerSocket.close sock Closed_by_user); |
TcpServerSocket.close sock Closed_by_user); |
48 |
BTTracker.stop_tracker (); |
BTTracker.stop_tracker (); |
49 |
if !!enable_bittorrent then enable_bittorrent =:= false |
if !!enable_bittorrent then enable_bittorrent =:= false |
50 |
end |
end |
51 |
|
|
52 |
let enable () = |
let enable () = |
53 |
(* lprintf "enable\n"; *) |
(* lprintf "enable\n"; *) |
54 |
if not !is_enabled then |
if not !is_enabled then |
66 |
Unix2.can_write_to_directory old_directory; |
Unix2.can_write_to_directory old_directory; |
67 |
is_enabled := true; |
is_enabled := true; |
68 |
if !!BTTracker.tracker_port > 0 then ( |
if !!BTTracker.tracker_port > 0 then ( |
69 |
try BTTracker.start_tracker () |
try BTTracker.start_tracker () |
70 |
with e -> |
with e -> |
71 |
lprintf "Exception in BTTracker.start_tracker: %s\n" |
lprintf "Exception in BTTracker.start_tracker: %s\n" |
72 |
(Printexc2.to_string e)); |
(Printexc2.to_string e)); |
76 |
add_timer 10. BTInteractive.share_files; |
add_timer 10. BTInteractive.share_files; |
77 |
add_session_timer enabler 600. BTInteractive.retry_all_ft; |
add_session_timer enabler 600. BTInteractive.retry_all_ft; |
78 |
network.op_network_disable <- disable enabler; |
network.op_network_disable <- disable enabler; |
79 |
|
|
80 |
if not !!enable_bittorrent then enable_bittorrent =:= true; |
if not !!enable_bittorrent then enable_bittorrent =:= true; |
81 |
(* |
(* |
82 |
List.iter (fun s -> |
List.iter (fun s -> |
93 |
current_files := file :: !current_files |
current_files := file :: !current_files |
94 |
) files_by_key; |
) files_by_key; |
95 |
*) |
*) |
|
|
|
96 |
|
|
97 |
BTClients.recover_files (); |
|
98 |
|
BTClients.recover_files (); |
99 |
add_session_timer enabler 60.0 (fun timer -> |
add_session_timer enabler 60.0 (fun timer -> |
100 |
BTClients.recover_files (); |
BTClients.recover_files (); |
101 |
); |
); |
102 |
|
|
103 |
add_session_timer enabler 120.0 (fun timer -> |
add_session_timer enabler 120.0 (fun timer -> |
104 |
BTClients.send_pings (); |
BTClients.send_pings (); |
105 |
); |
); |
106 |
|
|
|
|
|
107 |
add_session_timer enabler 10.0 (fun timer -> |
add_session_timer enabler 10.0 (fun timer -> |
108 |
BTClients.recompute_uploaders()); |
BTClients.recompute_uploaders()); |
109 |
|
|
110 |
CommonGlobals.do_at_exit ( fun _ -> |
CommonGlobals.do_at_exit ( fun _ -> |
111 |
List.iter (fun file -> |
List.iter (fun file -> |
112 |
BTClients.file_stop file |
BTClients.file_stop file |
115 |
|
|
116 |
BTClients.listen (); |
BTClients.listen (); |
117 |
() |
() |
118 |
|
|
119 |
let _ = |
let _ = |
120 |
network.op_network_is_enabled <- (fun _ -> !!CommonOptions.enable_bittorrent); |
network.op_network_is_enabled <- (fun _ -> !!CommonOptions.enable_bittorrent); |
121 |
option_hook enable_bittorrent (fun _ -> |
option_hook enable_bittorrent (fun _ -> |
124 |
else network_disable network); |
else network_disable network); |
125 |
(* |
(* |
126 |
network.op_network_save_simple_options <- BTComplexOptions.save_config; |
network.op_network_save_simple_options <- BTComplexOptions.save_config; |
127 |
network.op_network_load_simple_options <- |
network.op_network_load_simple_options <- |
128 |
(fun _ -> |
(fun _ -> |
129 |
try |
try |
130 |
Options.load bittorrent_ini; |
Options.load bittorrent_ini; |
131 |
with Sys_error _ -> |
with Sys_error _ -> |
136 |
network.network_config_file <- [bittorrent_ini]; |
network.network_config_file <- [bittorrent_ini]; |
137 |
check_client_uid (); |
check_client_uid (); |
138 |
network.op_network_info <- (fun n -> |
network.op_network_info <- (fun n -> |
139 |
{ |
{ |
140 |
network_netnum = network.network_num; |
network_netnum = network.network_num; |
141 |
network_config_filename = (match network.network_config_file with |
network_config_filename = (match network.network_config_file with |
142 |
[] -> "" | opfile :: _ -> options_file_name opfile); |
[] -> "" | opfile :: _ -> options_file_name opfile); |
147 |
network_downloaded = Int64.zero; |
network_downloaded = Int64.zero; |
148 |
network_connected = 0; |
network_connected = 0; |
149 |
}); |
}); |
150 |
CommonInteractive.register_gui_options_panel "BitTorrent" |
CommonInteractive.register_gui_options_panel "BitTorrent" |
151 |
gui_bittorrent_options_panel |
gui_bittorrent_options_panel |
152 |
|
|
|
|
|
153 |
let main (toto: int) = () |
let main (toto: int) = () |
|
|
|