304 |
|
|
305 |
open Proto |
open Proto |
306 |
|
|
307 |
|
let lprintf_nl () = |
308 |
|
lprintf "[%s]: " redirector_section; lprintf_nl |
309 |
|
|
310 |
let lprintf () = |
let lprintf () = |
311 |
lprintf "[%s] " |
lprintf "[%s] " |
312 |
(if Proto.redirector_section = "DKKO" then "Overnet" else "Kademlia"); lprintf |
(if Proto.redirector_section = "DKKO" then "Overnet" else "Kademlia"); lprintf |
313 |
|
|
314 |
(******************************************************************** |
(******************************************************************** |
315 |
|
|
316 |
STATIC MEMORY |
STATIC MEMORY |
755 |
Fifo.put fifo p; |
Fifo.put fifo p; |
756 |
if p.peer_last_recv <> 0 then begin |
if p.peer_last_recv <> 0 then begin |
757 |
if !verbose_overnet then begin |
if !verbose_overnet then begin |
758 |
lprintf () "Adding good search peer %s:%d\n" |
lprintf_nl () "Adding good search peer %s:%d" |
759 |
(Ip.to_string p.peer_ip) p.peer_port; |
(Ip.to_string p.peer_ip) p.peer_port; |
760 |
end; |
end; |
761 |
decr nb; |
decr nb; |
834 |
end |
end |
835 |
|
|
836 |
let create_search kind md4 = |
let create_search kind md4 = |
837 |
if !verbose_overnet then lprintf () "create_search\n"; |
if !verbose_overnet then lprintf_nl () "create_search"; |
838 |
let s = { |
let s = { |
839 |
search_md4 = md4; |
search_md4 = md4; |
840 |
search_kind = kind; |
search_kind = kind; |
850 |
search_results = Hashtbl.create 13; |
search_results = Hashtbl.create 13; |
851 |
} in |
} in |
852 |
List.iter (add_search_peer s) (get_closest_peers md4 max_search_queries); |
List.iter (add_search_peer s) (get_closest_peers md4 max_search_queries); |
853 |
if !verbose_overnet then lprintf () "create_search done\n"; |
if !verbose_overnet then lprintf_nl () "create_search done"; |
854 |
overnet_searches := s :: !overnet_searches; |
overnet_searches := s :: !overnet_searches; |
855 |
s |
s |
856 |
|
|
879 |
let other_ip = ip_of_udp_packet p in |
let other_ip = ip_of_udp_packet p in |
880 |
let other_port = port_of_udp_packet p in |
let other_port = port_of_udp_packet p in |
881 |
if !verbose_overnet then |
if !verbose_overnet then |
882 |
lprintf () "UDP FROM %s:%d:\n %s " |
lprintf_nl () "UDP FROM %s:%d:\n %s" |
883 |
(Ip.to_string other_ip) other_port |
(Ip.to_string other_ip) other_port |
884 |
(message_to_string t); |
(message_to_string t); |
885 |
match t with |
match t with |
898 |
new_peer_message p; |
new_peer_message p; |
899 |
if other_port <> p.peer_port || other_ip <> p.peer_ip then |
if other_port <> p.peer_port || other_ip <> p.peer_ip then |
900 |
if !verbose_overnet then |
if !verbose_overnet then |
901 |
lprintf () "Bad IP or port\n"; |
lprintf_nl () "Bad IP or port"; |
902 |
let p = new_peer p in |
let p = new_peer p in |
903 |
() |
() |
904 |
| p :: tail -> |
| p :: tail -> |
945 |
if !verbose_hidden_errors then |
if !verbose_hidden_errors then |
946 |
begin |
begin |
947 |
lprintf () "Unknown message from %s:%d " (Ip.to_string other_ip) other_port; |
lprintf () "Unknown message from %s:%d " (Ip.to_string other_ip) other_port; |
948 |
lprintf () "\tCode: %d" opcode; dump s; |
lprintf_nl () "\tCode: %d" opcode; dump s; |
|
lprintf () "\n" |
|
949 |
end |
end |
950 |
|
|
951 |
| OvernetSearchFilesResults (md4, results) -> |
| OvernetSearchFilesResults (md4, results) -> |
971 |
incr search_hits; |
incr search_hits; |
972 |
s.search_hits <- s.search_hits + 1; |
s.search_hits <- s.search_hits + 1; |
973 |
Hashtbl.add s.search_results r_md4 r_tags; |
Hashtbl.add s.search_results r_md4 r_tags; |
|
|
|
974 |
if !verbose_overnet then begin |
if !verbose_overnet then begin |
975 |
lprintf () "FILE FOUND, TAGS:\n "; |
lprintf_nl () "FILE FOUND, TAGS:"; |
976 |
print_tags r_tags; lprint_newline () |
print_tags r_tags; |
977 |
end; |
lprintf_nl () "" |
978 |
|
end; |
979 |
|
|
980 |
DonkeyOneFile.search_found true sss r_md4 r_tags; |
DonkeyOneFile.search_found true sss r_md4 r_tags; |
981 |
end |
end |
982 |
) results |
) results |
1321 |
) ss; |
) ss; |
1322 |
List.length ss |
List.length ss |
1323 |
with e -> |
with e -> |
1324 |
lprintf () "Exception %s while loading %s\n" (Printexc2.to_string e) |
lprintf_nl () "Exception %s while loading %s" (Printexc2.to_string e) |
1325 |
filename; |
filename; |
1326 |
0 |
0 |
1327 |
|
|
1483 |
(Ip.of_string ip) |
(Ip.of_string ip) |
1484 |
(int_of_string port) |
(int_of_string port) |
1485 |
(OvernetUnknown (opcode,msg)); |
(OvernetUnknown (opcode,msg)); |
1486 |
lprintf () "Sending UDP message %d to %s:%s\n" opcode ip port; |
lprintf_nl () "Sending UDP message %d to %s:%s" opcode ip port; |
1487 |
dump msg; lprintf () "\n"; "Sending UDP message" |
dump msg; lprintf_nl () ""; "Sending UDP message" |
1488 |
with _ -> |
with _ -> |
1489 |
lprintf () "Unable to send UDP message\n"; "Unable to send UDP message" |
lprintf_nl () "Unable to send UDP message"; "Unable to send UDP message" |
1490 |
), ":\t\t\t\tsend UDP message (<ip> <port> <msg in hex>)"; |
), ":\t\t\t\tsend UDP message (<ip> <port> <msg in hex>)"; |
1491 |
|
|
1492 |
"buckets", Arg_none (fun o -> |
"buckets", Arg_none (fun o -> |
1518 |
let overnet_search (ss : search) = |
let overnet_search (ss : search) = |
1519 |
if !!overnet_search_keyword && !!enable_overnet then |
if !!overnet_search_keyword && !!enable_overnet then |
1520 |
let q = ss.search_query in |
let q = ss.search_query in |
1521 |
if !verbose then lprintf () "========= overnet_search =========\n"; |
if !verbose then lprintf_nl () "========= overnet_search ========="; |
1522 |
let ws = keywords_of_query q in |
let ws = keywords_of_query q in |
1523 |
List.iter (fun w -> |
List.iter (fun w -> |
1524 |
if !verbose then lprintf () "overnet_search for %s\n" w; |
if !verbose then lprintf_nl () "overnet_search for %s" w; |
1525 |
let s = create_keyword_search w ss in |
let s = create_keyword_search w ss in |
1526 |
Hashtbl.iter (fun r_md4 r_tags -> |
Hashtbl.iter (fun r_md4 r_tags -> |
1527 |
DonkeyOneFile.search_found true ss r_md4 r_tags) s.search_results; |
DonkeyOneFile.search_found true ss r_md4 r_tags) s.search_results; |