40 |
open DonkeyComplexOptions |
open DonkeyComplexOptions |
41 |
open DonkeyOptions |
open DonkeyOptions |
42 |
open CommonOptions |
open CommonOptions |
43 |
open DonkeyClient |
open DonkeyClient |
44 |
open CommonGlobals |
open CommonGlobals |
45 |
open DonkeyStats |
open DonkeyStats |
46 |
|
|
47 |
module Udp = DonkeyProtoUdp |
module Udp = DonkeyProtoUdp |
48 |
|
|
49 |
let search_handler s t = |
let search_handler s t = |
50 |
let waiting = s.search_waiting - 1 in |
let waiting = s.search_waiting - 1 in |
88 |
let module M = DonkeyProtoServer in |
let module M = DonkeyProtoServer in |
89 |
let module Q = M.Query in |
let module Q = M.Query in |
90 |
udp_server_send s ( |
udp_server_send s ( |
91 |
(* By default, send the MultipleUdp !!! we have to set |
(* By default, send the MultipleUdp !!! we have to set |
92 |
server_send_multiple_replies to true by default, and change it to false |
server_send_multiple_replies to true by default, and change it to false |
93 |
when receiving an old ping. |
when receiving an old ping. |
94 |
|
|
101 |
if !verbose_overnet then lprintf "===================== STARTING SEARCH ON OVERNET =========\n"; |
if !verbose_overnet then lprintf "===================== STARTING SEARCH ON OVERNET =========\n"; |
102 |
DonkeyProtoOvernet.Overnet.overnet_search ss; |
DonkeyProtoOvernet.Overnet.overnet_search ss; |
103 |
DonkeyProtoKademlia.Kademlia.overnet_search ss |
DonkeyProtoKademlia.Kademlia.overnet_search ss |
|
|
|
104 |
|
|
105 |
let extent_search () = |
let extent_search () = |
106 |
try |
try |
113 |
(* |
(* |
114 |
start removed by savannah patch #3616 |
start removed by savannah patch #3616 |
115 |
let files = ref [] in |
let files = ref [] in |
116 |
List.iter (fun file -> |
List.iter (fun file -> |
117 |
if file_state file = FileDownloading then |
if file_state file = FileDownloading then |
118 |
files := file :: !files) !current_files; |
files := file :: !files) !current_files; |
119 |
|
|
120 |
if !files <> [] then |
if !files <> [] then |
126 |
while !nservers < !!max_udp_sends && |
while !nservers < !!max_udp_sends && |
127 |
match !udp_servers_list with |
match !udp_servers_list with |
128 |
[] -> false |
[] -> false |
129 |
| s :: tail -> |
| s :: tail -> |
130 |
udp_servers_list := tail; |
udp_servers_list := tail; |
131 |
(match s.server_sock with |
(match s.server_sock with |
132 |
Connection _ -> () |
Connection _ -> () |
133 |
| _ -> |
| _ -> |
134 |
if |
if |
135 |
connection_last_conn s.server_connection_control + 3600*8 > last_time () && |
connection_last_conn s.server_connection_control + 3600*8 > last_time () && |
136 |
s.server_next_udp <= last_time () then begin |
s.server_next_udp <= last_time () then begin |
137 |
(if server_accept_multiple_getsources s then |
(if server_accept_multiple_getsources s then |
155 |
) !new_servers |
) !new_servers |
156 |
end; |
end; |
157 |
|
|
158 |
if !old_servers <> [] then |
if !old_servers <> [] then |
159 |
List.iter (fun file -> |
List.iter (fun file -> |
160 |
if file_state file = FileDownloading then begin |
if file_state file = FileDownloading then begin |
161 |
(*(* USELESS NOW *) |
(*(* USELESS NOW *) |
162 |
Intmap.iter (fun _ c -> |
Intmap.iter (fun _ c -> |
163 |
try connect_client !!client_ip [file] c with _ -> ()) |
try connect_client !!client_ip [file] c with _ -> ()) |
164 |
file.file_known_locations; |
file.file_known_locations; |
165 |
*) |
*) |
166 |
|
|
167 |
(* now, it is done in donkeySources |
(* now, it is done in donkeySources |
168 |
List.iter (fun s -> |
List.iter (fun s -> |
172 |
(try DonkeyServers.query_location file sock with _ -> ()) |
(try DonkeyServers.query_location file sock with _ -> ()) |
173 |
) (connected_servers()); |
) (connected_servers()); |
174 |
*) |
*) |
175 |
|
|
176 |
List.iter (fun s -> |
List.iter (fun s -> |
177 |
if |
if |
178 |
connection_last_conn s.server_connection_control + 3600*8 > last_time () && |
connection_last_conn s.server_connection_control + 3600*8 > last_time () && |
179 |
s.server_next_udp <= last_time () then |
s.server_next_udp <= last_time () then |
180 |
match s.server_sock with |
match s.server_sock with |
189 |
) !old_servers; |
) !old_servers; |
190 |
if !udp_servers_list = [] then |
if !udp_servers_list = [] then |
191 |
udp_servers_list := Hashtbl2.to_list servers_by_key; |
udp_servers_list := Hashtbl2.to_list servers_by_key; |
192 |
|
|
193 |
end removed by savannah patch #3616 |
end removed by savannah patch #3616 |
194 |
*) |
*) |
195 |
|
|
196 |
with e -> |
with e -> |
197 |
lprintf "extent_search: %s\n" (Printexc2.to_string e) |
lprintf "extent_search: %s\n" (Printexc2.to_string e) |
198 |
|
|
199 |
let add_user_friend s u = |
let add_user_friend s u = |
200 |
let kind = |
let kind = |
201 |
if Ip.valid u.user_ip && ip_reachable u.user_ip then |
if Ip.valid u.user_ip && ip_reachable u.user_ip then |
202 |
Direct_address (u.user_ip, u.user_port) |
Direct_address (u.user_ip, u.user_port) |
203 |
else |
else |
215 |
set_client_name c u.user_name u.user_md4; |
set_client_name c u.user_name u.user_md4; |
216 |
friend_add c |
friend_add c |
217 |
|
|
|
|
|
|
|
|
218 |
let udp_client_handler t p = |
let udp_client_handler t p = |
219 |
if !verbose_udp then |
if !verbose_udp then |
220 |
lprintf "Received UDP message:\n%s\n" (Udp.print t); |
lprintf "Received UDP message:\n%s\n" (Udp.print t); |
225 |
let ip = Ip.of_inet_addr ip in |
let ip = Ip.of_inet_addr ip in |
226 |
if !!update_server_list_server then |
if !!update_server_list_server then |
227 |
let s = check_add_server ip (port-4) in |
let s = check_add_server ip (port-4) in |
228 |
(* set last_conn, but add a 2 minutes offset to prevent |
(* set last_conn, but add a 2 minutes offset to prevent |
229 |
staying connected to this server *) |
staying connected to this server *) |
230 |
connection_set_last_conn s.server_connection_control ( |
connection_set_last_conn s.server_connection_control ( |
231 |
last_time () - 121); |
last_time () - 121); |
232 |
s.server_score <- s.server_score + 3; |
s.server_score <- s.server_score + 3; |
233 |
s |
s |
234 |
else |
else |
235 |
find_server ip (port-4) |
find_server ip (port-4) |
236 |
| _ -> raise Not_found |
| _ -> raise Not_found |
237 |
in |
in |
240 |
(* lprintf "Received location by UDP\n"; *) |
(* lprintf "Received location by UDP\n"; *) |
241 |
let s = udp_from_server p in |
let s = udp_from_server p in |
242 |
List.iter (query_locations_reply s) t |
List.iter (query_locations_reply s) t |
243 |
|
|
244 |
| Udp.QueryReplyUdpReq t -> |
| Udp.QueryReplyUdpReq t -> |
245 |
(* lprintf "Received file by UDP\n"; *) |
(* lprintf "Received file by UDP\n"; *) |
246 |
if !xs_last_search >= 0 then |
if !xs_last_search >= 0 then |
258 |
s.server_last_message <- last_time (); |
s.server_last_message <- last_time (); |
259 |
s.server_nfiles <- Int64.of_int t.M.files; |
s.server_nfiles <- Int64.of_int t.M.files; |
260 |
s.server_nusers <- Int64.of_int t.M.users; |
s.server_nusers <- Int64.of_int t.M.users; |
261 |
(match t.M.max_users with |
(match t.M.max_users with |
262 |
Some x -> s.server_max_users <- x |
Some x -> s.server_max_users <- x |
263 |
| None -> ()); |
| None -> ()); |
264 |
(match t.M.flags with |
(match t.M.flags with |
265 |
Some x -> s.server_flags <- x |
Some x -> s.server_flags <- x |
266 |
| None -> ()) |
| None -> ()) |
267 |
|
|
268 |
| Udp.EmuleReaskFilePingUdpReq t -> () |
| Udp.EmuleReaskFilePingUdpReq t -> () |
269 |
|
|
270 |
|
| _ -> |
|
| _ -> |
|
271 |
if !verbose_unexpected_messages then |
if !verbose_unexpected_messages then |
272 |
lprintf "Unexpected UDP message: %s\n" |
lprintf "Unexpected UDP message: %s\n" |
273 |
(DonkeyProtoUdp.print t) |
(DonkeyProtoUdp.print t) |