1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
2 (* Copyright 2005 beedauchon *)
4 This file is part of mldonkey.
6 mldonkey is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 mldonkey is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with mldonkey; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 let dump_file filename
=
32 Unix2.tryopen_read_bin filename
(fun ic
->
33 let s = String.create
20 in
35 lprintf
"file: %s\n" filename
;
38 let n = input ic
s 0 20 in
39 lprintf
"pos = %d\n" !pos;
40 if n = 0 then raise Exit
;
41 dump
(String.sub
s 0 n);
44 with End_of_file
-> ())
66 let rec read_peers s pos left
=
67 if pos + 22 >= String.length
s then List.rev left
else
70 let md4 = get_md4 s pos in
71 let ip = get_ip
s (pos+16) in
72 let port = get_port s (pos+20) in
73 let kind = get_kind s (pos+22) in
75 lprintf "{ pos = %d " pos;
76 lprintf "md4 = %s " (Md4.to_string md4);
77 lprintf "ip = %s " (Ip.to_string ip);
78 lprintf "port = %d " port;
79 lprintf "type = %d}\n" kind;
90 let len = String.length s - pos in
91 lprintf "Error while reading peer %s (left %d)\n"
92 (Printexc2.to_string e) len;
93 dump (String.sub s pos len);
99 read_peers s pos (peer
:: left
)
106 buf_int buf (List.length t);
113 lprintf
"contact.dat: %d peers found\n" (List.length t
);
115 lprintf
" peer %s:%d\n" (Ip.to_string
s.ip) s.port;