/[mldonkey]/mldonkey/src/networks/donkey/donkeyOvernet.ml
ViewVC logotype

Diff of /mldonkey/src/networks/donkey/donkeyOvernet.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.47 by spiralvoice, Tue Sep 13 09:52:03 2005 UTC revision 1.48 by spiralvoice, Sat Sep 17 09:39:07 2005 UTC
# Line 332  let min_peers_before_connect = 5 Line 332  let min_peers_before_connect = 5
332  let max_searches_for_publish = 5  let max_searches_for_publish = 5
333  let max_search_queries = 64  let max_search_queries = 64
334  let max_search_requests = 20  let max_search_requests = 20
335    let max_boot_peers = 200
336    
337  let is_enabled = ref false  let is_enabled = ref false
338    
# Line 452  module LimitedList = struct Line 453  module LimitedList = struct
453              Hashtbl.remove t.objects_table key              Hashtbl.remove t.objects_table key
454          end          end
455    
456        let get t =
457          let key = Fifo.take t.objects_fifo in
458          Hashtbl.remove t.objects_table key;
459          key
460    
461        let clear t =
462          Fifo.clear t.objects_fifo;
463          Hashtbl.clear t.objects_table
464    
465      let to_list t =      let to_list t =
466        Fifo.to_list t.objects_fifo        Fifo.to_list t.objects_fifo
467    
# Line 493  module LimitedList = struct Line 503  module LimitedList = struct
503  let boot_peers = define_option servers_section  let boot_peers = define_option servers_section
504      [Proto.options_section_name; "boot_peers"]      [Proto.options_section_name; "boot_peers"]
505      "List of IP addresses to use to boot Kademlia networks"      "List of IP addresses to use to boot Kademlia networks"
506      LimitedList.option (LimitedList.create 2000)      LimitedList.option (LimitedList.create max_boot_peers)
507    
508  let boot_peers_copy = ref []  (* peers we may ping *)
509    let unknown_peers = LimitedList.create 2000
510    
511  (* the total number of buckets used. We must fill a bucket before using the  (* the total number of buckets used. We must fill a bucket before using the
512  next one. When a bucket is full, and we want to add a new peer, we must  next one. When a bucket is full, and we want to add a new peer, we must
# Line 696  let udp_send p msg = Line 707  let udp_send p msg =
707    udp_send_direct p.peer_ip p.peer_port msg    udp_send_direct p.peer_ip p.peer_port msg
708    
709  let bootstrap ip port =  let bootstrap ip port =
710    if !!overnet_update_nodes && Ip.valid ip && Ip.reachable ip && port <> 0 then begin    if !!overnet_update_nodes && Ip.valid ip && Ip.reachable ip &&
711        LimitedList.add !!boot_peers (ip,port);       port <> 0 && not (Hashtbl.mem known_peers (ip,port)) then
712        boot_peers_copy := (ip,port) :: !boot_peers_copy;         LimitedList.add unknown_peers (ip,port)
 (* 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  
713    
714  let new_peer p =  let new_peer p =
715    let ip = p.peer_ip in    let ip = p.peer_ip in
# Line 1266  let update_buckets () = Line 1271  let update_buckets () =
1271        end        end
1272    done;    done;
1273    
1274    (* boot_peers will be saved, so we choose max_boot_peers good peers
1275    from the active buckets and prebuckets *)
1276      LimitedList.clear !!boot_peers;
1277      let n = ref 0 in
1278      try
1279        let addtol p =
1280          if p.peer_last_recv <> 0 then begin
1281            LimitedList.add !!boot_peers (p.peer_ip, p.peer_port);
1282            incr n;
1283            if !n = max_boot_peers then raise Exit
1284          end
1285        in
1286    
1287        for i = 0 to !n_used_buckets do
1288          Fifo.iter addtol buckets.(i)
1289        done;
1290    
1291        for i = 0 to !n_used_buckets do
1292          Fifo.iter addtol prebuckets.(i)
1293        done;
1294      with Exit -> ();
1295    
1296    ()    ()
1297    
1298  let enable () =  let enable () =
# Line 1278  let enable () = Line 1305  let enable () =
1305        udp_sock := Some sock;        udp_sock := Some sock;
1306        UdpSocket.set_write_controler sock udp_write_controler;        UdpSocket.set_write_controler sock udp_write_controler;
1307    
1308    (* copy all boot_peers to unknown_peers *)
1309          LimitedList.iter (fun (ip, port) ->
1310              LimitedList.add unknown_peers (ip, port)
1311              ) !!boot_peers;
1312    
1313        add_session_timer enabler 1. (fun _ ->        add_session_timer enabler 1. (fun _ ->
1314            if !!enable_overnet then            if !!enable_overnet then
1315              let my_peer = my_peer () in              let my_peer = my_peer () in
# Line 1294  let enable () = Line 1326  let enable () =
1326    
1327  (* ping unknown peers *)  (* ping unknown peers *)
1328              begin              begin
1329                match !boot_peers_copy with                try
                 [] ->  
                   boot_peers_copy := LimitedList.to_list !!boot_peers  
               | _ ->  
1330                    if !connected_peers < 100 then                    if !connected_peers < 100 then
1331                      for i = 1 to 5 do                      for i = 1 to 5 do
1332                        match !boot_peers_copy with                        let (ip, port) = LimitedList.get unknown_peers in
1333                          [] -> ()                        udp_send_ping ip port (OvernetConnect my_peer);
                       | (ip, port) :: tail ->  
                           boot_peers_copy := tail;  
                           udp_send_ping ip port (OvernetConnect my_peer);  
                           ()  
   
1334                      done                      done
1335                  with _ -> ()
1336              end;              end;
1337        );        );
1338    
# Line 1860  Define a function to be called when the Line 1885  Define a function to be called when the
1885      (fun level buf ->      (fun level buf ->
1886        Printf.bprintf buf "%s statistics:\n"        Printf.bprintf buf "%s statistics:\n"
1887        (if Proto.redirector_section = "DKKO" then "Overnet" else "Kademlia");        (if Proto.redirector_section = "DKKO" then "Overnet" else "Kademlia");
1888        Printf.bprintf buf "  boot_peers: %d\n" (LimitedList.length !!boot_peers);        Printf.bprintf buf "  unknown_peers: %d\n" (LimitedList.length unknown_peers);
1889        update_buckets ();        update_buckets ();
1890          Printf.bprintf buf "  boot_peers: %d\n" (LimitedList.length !!boot_peers);
1891        Printf.bprintf buf "  %d buckets with %d peers and %d prebucket peers\n"        Printf.bprintf buf "  %d buckets with %d peers and %d prebucket peers\n"
1892              !n_used_buckets !connected_peers !pre_connected_peers;              !n_used_buckets !connected_peers !pre_connected_peers;
1893    

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26