[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Mldonkey-commits] Changes to mldonkey/src/networks/donkey/donkeyOvernet
From: |
mldonkey-commits |
Subject: |
[Mldonkey-commits] Changes to mldonkey/src/networks/donkey/donkeyOvernet.ml |
Date: |
Sat, 17 Sep 2005 05:39:08 -0400 |
Index: mldonkey/src/networks/donkey/donkeyOvernet.ml
diff -u mldonkey/src/networks/donkey/donkeyOvernet.ml:1.47
mldonkey/src/networks/donkey/donkeyOvernet.ml:1.48
--- mldonkey/src/networks/donkey/donkeyOvernet.ml:1.47 Tue Sep 13 09:52:03 2005
+++ mldonkey/src/networks/donkey/donkeyOvernet.ml Sat Sep 17 09:39:07 2005
@@ -332,6 +332,7 @@
let max_searches_for_publish = 5
let max_search_queries = 64
let max_search_requests = 20
+let max_boot_peers = 200
let is_enabled = ref false
@@ -452,6 +453,15 @@
Hashtbl.remove t.objects_table key
end
+ let get t =
+ let key = Fifo.take t.objects_fifo in
+ Hashtbl.remove t.objects_table key;
+ key
+
+ let clear t =
+ Fifo.clear t.objects_fifo;
+ Hashtbl.clear t.objects_table
+
let to_list t =
Fifo.to_list t.objects_fifo
@@ -493,9 +503,10 @@
let boot_peers = define_option servers_section
[Proto.options_section_name; "boot_peers"]
"List of IP addresses to use to boot Kademlia networks"
- LimitedList.option (LimitedList.create 2000)
+ LimitedList.option (LimitedList.create max_boot_peers)
-let boot_peers_copy = ref []
+(* peers we may ping *)
+let unknown_peers = LimitedList.create 2000
(* the total number of buckets used. We must fill a bucket before using the
next one. When a bucket is full, and we want to add a new peer, we must
@@ -696,15 +707,9 @@
udp_send_direct p.peer_ip p.peer_port msg
let bootstrap ip port =
- if !!overnet_update_nodes && Ip.valid ip && Ip.reachable ip && port <> 0
then begin
- LimitedList.add !!boot_peers (ip,port);
- boot_peers_copy := (ip,port) :: !boot_peers_copy;
-(* Limit boot_peers_copy, if needed by the timer it will be set to
- LimitedList.to_list !!boot_peers there *)
- if (List.length !boot_peers_copy) > (2 * LimitedList.length !!boot_peers)
- then
- boot_peers_copy := (ip,port) :: [];
- end
+ if !!overnet_update_nodes && Ip.valid ip && Ip.reachable ip &&
+ port <> 0 && not (Hashtbl.mem known_peers (ip,port)) then
+ LimitedList.add unknown_peers (ip,port)
let new_peer p =
let ip = p.peer_ip in
@@ -1266,6 +1271,28 @@
end
done;
+(* boot_peers will be saved, so we choose max_boot_peers good peers
+from the active buckets and prebuckets *)
+ LimitedList.clear !!boot_peers;
+ let n = ref 0 in
+ try
+ let addtol p =
+ if p.peer_last_recv <> 0 then begin
+ LimitedList.add !!boot_peers (p.peer_ip, p.peer_port);
+ incr n;
+ if !n = max_boot_peers then raise Exit
+ end
+ in
+
+ for i = 0 to !n_used_buckets do
+ Fifo.iter addtol buckets.(i)
+ done;
+
+ for i = 0 to !n_used_buckets do
+ Fifo.iter addtol prebuckets.(i)
+ done;
+ with Exit -> ();
+
()
let enable () =
@@ -1278,6 +1305,11 @@
udp_sock := Some sock;
UdpSocket.set_write_controler sock udp_write_controler;
+(* copy all boot_peers to unknown_peers *)
+ LimitedList.iter (fun (ip, port) ->
+ LimitedList.add unknown_peers (ip, port)
+ ) !!boot_peers;
+
add_session_timer enabler 1. (fun _ ->
if !!enable_overnet then
let my_peer = my_peer () in
@@ -1294,20 +1326,13 @@
(* ping unknown peers *)
begin
- match !boot_peers_copy with
- [] ->
- boot_peers_copy := LimitedList.to_list !!boot_peers
- | _ ->
+ try
if !connected_peers < 100 then
for i = 1 to 5 do
- match !boot_peers_copy with
- [] -> ()
- | (ip, port) :: tail ->
- boot_peers_copy := tail;
- udp_send_ping ip port (OvernetConnect my_peer);
- ()
-
+ let (ip, port) = LimitedList.get unknown_peers in
+ udp_send_ping ip port (OvernetConnect my_peer);
done
+ with _ -> ()
end;
);
@@ -1860,8 +1885,9 @@
(fun level buf ->
Printf.bprintf buf "%s statistics:\n"
(if Proto.redirector_section = "DKKO" then "Overnet" else "Kademlia");
- Printf.bprintf buf " boot_peers: %d\n" (LimitedList.length
!!boot_peers);
+ Printf.bprintf buf " unknown_peers: %d\n" (LimitedList.length
unknown_peers);
update_buckets ();
+ Printf.bprintf buf " boot_peers: %d\n" (LimitedList.length
!!boot_peers);
Printf.bprintf buf " %d buckets with %d peers and %d prebucket peers\n"
!n_used_buckets !connected_peers !pre_connected_peers;