6 let lprintf_nl fmt = lprintf_nl2 "[NODES]" fmt
8 (* see http://wiki.amule.org/index.php/Nodes.dat_file *)
10 let parse filename f =
11 bitmatch bitstring_of_file filename with
12 | { 0l : 32; 02l : 32 : littleendian; count : 32 : littleendian, bind(Int32.to_int count);
13 nodes : 34 * 8 * count : bitstring ; rest : -1 : bitstring
14 } when bitstring_length rest = 0
16 let () = for i = 0 to pred count do
17 (bitmatch subbitstring nodes (34 * 8 * i) (34 * 8) with
18 | { id : 16 * 8 : string;
19 ip1 : 8; ip2 : 8; ip3 : 8; ip4 : 8; (* littleendian *)
20 udp : 16 : littleendian;
21 tcp : 16 : littleendian;
26 let ip = Ip.of_ints (ip4,ip3,ip2,ip1) in
27 if !verbose_overnet then
28 lprintf_nl "v2: id %S ip %s udp %d tcp %d ver %d key %S chk %d"
29 id (Ip.to_string ip) udp tcp version key verified;
31 | { } -> failwith "v2: bad contact"
34 | { count : 32 : littleendian, bind(Int32.to_int count);
35 nodes : 25 * 8 * count : bitstring;
37 } when bitstring_length rest = 0
39 let () = for i = 0 to pred count do
40 (bitmatch subbitstring nodes (25 * 8 * i) (25 * 8) with
41 | { id : 16 * 8 : string;
42 ip1 : 8; ip2 : 8; ip3 : 8; ip4 : 8; (* littleendian *)
43 udp : 16 : littleendian;
44 tcp : 16 : littleendian;
47 let ip = Ip.of_ints (ip4,ip3,ip2,ip1) in
48 if !verbose_overnet then
49 lprintf_nl "v0: id %S ip %s udp %d tcp %d typ %d" id (Ip.to_string ip) udp tcp typ;
51 | { } -> failwith "v0: bad contact"
54 | { } -> failwith "nodes.dat bad header"