patch #7442
[mldonkey.git] / src / networks / bittorrent / bTTypes.ml
blobdb54b0e7c1ac21a4135e67140a969b9eeeabd80c
1 (* Copyright 2001, 2002 b52_simon :), b8_bavard, b8_fee_carabine, INRIA *)
2 (*
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 open Md4
22 open CommonTypes
23 open CommonDownloads
24 open CommonStats
25 open BTRate
28 type torrent = {
29 mutable torrent_name : string;
30 mutable torrent_name_utf8 : string;
31 mutable torrent_filename : string;
32 mutable torrent_length : int64;
33 mutable torrent_announce : string;
34 mutable torrent_announce_list : string list;
35 mutable torrent_piece_size : int64;
36 mutable torrent_files : (string * int64) list;
37 mutable torrent_pieces : Sha1.t array;
38 mutable torrent_comment : string;
39 mutable torrent_created_by : string;
40 mutable torrent_creation_date : int64;
41 mutable torrent_modified_by : string;
42 mutable torrent_encoding : string;
43 mutable torrent_private : bool;
45 mutable torrent_nodes : string;
49 type brand =
50 Brand_unknown
51 | Brand_abc
52 | Brand_arctic
53 | Brand_azureus
54 | Brand_bitbuddy
55 | Brand_bitcomet
56 | Brand_bitkitten
57 | Brand_bitlord
58 | Brand_bitsonwheels
59 | Brand_bitspirit
60 | Brand_bittornado
61 | Brand_bittorrentx
62 | Brand_btplus
63 | Brand_bitrocket
64 | Brand_btslave
65 | Brand_btugaxp
66 | Brand_burst
67 | Brand_ctorrent
68 | Brand_deadmanwalking
69 | Brand_exeem
70 | Brand_experimental
71 | Brand_g3torrent
72 | Brand_libtorrent
73 | Brand_mainline
74 | Brand_martiniman
75 | Brand_mldonkey
76 | Brand_moonlighttorrent
77 | Brand_plus
78 | Brand_shadow
79 | Brand_sharenet
80 | Brand_shareaza
81 | Brand_simplebt
82 | Brand_snark
83 | Brand_swarmscope
84 | Brand_swarmy
85 | Brand_swiftbit
86 | Brand_teeweety
87 | Brand_torrentdotnet
88 | Brand_torrentstorm
89 | Brand_turbobt
90 | Brand_upnp
91 | Brand_xantorrent
92 | Brand_xbt
93 | Brand_ziptorrent
94 | Brand_moopolice
95 | Brand_utorrent_mac
96 | Brand_utorrent
97 | Brand_opera
98 | Brand_torrenttopia
99 | Brand_greedbt
100 | Brand_btgetit
101 | Brand_ktorrent
102 | Brand_lphant
103 | Brand_transmission
104 | Brand_hydranode
105 | Brand_jvtorrent
106 | Brand_retriever
107 | Brand_osprey
108 | Brand_rufus
109 | Brand_tribler
110 | Brand_cachelogic
111 | Brand_electricsheep
112 | Brand_qbittorrent
113 | Brand_qt4
114 | Brand_uleecher
115 | Brand_flashget
116 | Brand_xtorrent
117 | Brand_limewire
118 | Brand_btpd
119 | Brand_btyrant
120 | Brand_ares
121 | Brand_bitpump
122 | Brand_deluge
123 | Brand_btuga
124 | Brand_tuotu
125 | Brand_xunlei
126 | Brand_foxtorrent
127 | Brand_bitflu
128 | Brand_oneswarm
129 | Brand_halite
130 | Brand_miro
131 | Brand_pando
133 let brand_list = [
134 ( Brand_unknown , "unknown" , "unk" ) ;
135 ( Brand_abc , "ABC" , "abc" ) ;
136 ( Brand_arctic , "Arctic" , "arc" ) ;
137 ( Brand_azureus , "Azureus" , "azu" ) ;
138 ( Brand_bitbuddy , "Bitbuddy" , "bud" ) ;
139 ( Brand_bitcomet , "BitComet" , "com" ) ;
140 ( Brand_bitkitten , "BitKitten (libTorrent)" , "kit" ) ;
141 ( Brand_bitlord , "BitLord" , "lor" ) ;
142 ( Brand_bitsonwheels , "BitsOnWheels" , "bow" ) ;
143 ( Brand_bitspirit , "BitSpirit" , "spi" ) ;
144 ( Brand_bittornado , "BitTornado" , "trn" ) ;
145 ( Brand_bittorrentx , "BitTorrent X" , "btx" ) ;
146 ( Brand_btplus , "BitTorrent Plus!" , "plu" ) ;
147 ( Brand_bitrocket , "BitRocket" , "roc" ) ;
148 ( Brand_btslave , "BTSlave" , "sla" ) ;
149 ( Brand_btugaxp , "BTugaXP" , "uga" ) ;
150 ( Brand_burst , "Burst !" , "brs" ) ;
151 ( Brand_ctorrent , "CTorrent" , "cto" ) ;
152 ( Brand_deadmanwalking , "Deadman Walking" , "dmw" ) ;
153 ( Brand_exeem , "eXeem" , "exm" ) ;
154 ( Brand_experimental , "Experimental" , "exp" ) ;
155 ( Brand_g3torrent , "G3 Torrent" , "g3t" ) ;
156 ( Brand_libtorrent , "libTorrent" , "lib" ) ;
157 ( Brand_mainline , "Mainline" , "mai" ) ;
158 ( Brand_martiniman , "Martini Man" , "mar" ) ;
159 ( Brand_mldonkey , "MLdonkey" , "mld" ) ;
160 ( Brand_moonlighttorrent , "MoonlightTorrent" , "mlt" ) ;
161 ( Brand_plus , "Plus" , "plu" ) ;
162 ( Brand_shadow , "Shad0w" , "sdo" ) ;
163 ( Brand_sharenet , "Sharenet" , "shn" ) ;
164 ( Brand_shareaza , "Shareaza" , "shz" ) ;
165 ( Brand_simplebt , "SimpleBT" , "sbt" ) ;
166 ( Brand_snark , "Snark" , "snk" ) ;
167 ( Brand_swarmscope , "SwarmScope" , "sws" ) ;
168 ( Brand_swarmy , "Swarmy" , "swy" ) ;
169 ( Brand_swiftbit , "SwiftBit" , "swb" ) ;
170 ( Brand_teeweety , "Teeweety" , "twt" ) ;
171 ( Brand_torrentdotnet , "Torrent.NET" , "t.n" ) ;
172 ( Brand_torrentstorm , "TorrentStorm" , "sto" ) ;
173 ( Brand_turbobt , "TurboBT" , "tbt" ) ;
174 ( Brand_upnp , "UPNP" , "upn" ) ;
175 ( Brand_xantorrent , "XanTorrent" , "xat" ) ;
176 ( Brand_xbt , "XBT" , "xbt" ) ;
177 ( Brand_ziptorrent , "ZipTorrent" , "zit" ) ;
178 ( Brand_moopolice , "MooPolice" , "moo" ) ;
179 ( Brand_utorrent_mac , "uTorrent for Mac" , "uTm" ) ;
180 ( Brand_utorrent , "uTorrent" , "uTo" ) ;
181 ( Brand_opera , "Opera" , "opr" ) ;
182 ( Brand_torrenttopia , "TorrentTopia" , "tt" ) ;
183 ( Brand_greedbt , "GreedBT" , "gbt" ) ;
184 ( Brand_btgetit , "BTGetit" , "btg" ) ;
185 ( Brand_ktorrent , "KTorrent" , "kto" ) ;
186 ( Brand_lphant , "Lphant" , "lph" ) ;
187 ( Brand_transmission , "Transmission" , "tra" ) ;
188 ( Brand_hydranode , "Hydranode" , "hyd" ) ;
189 ( Brand_jvtorrent , "JVtorrent" , "jvt" ) ;
190 ( Brand_retriever , "Retriever" , "ret" ) ;
191 ( Brand_osprey , "Osprey permaseed" , "osp" ) ;
192 ( Brand_rufus , "Rufus" , "ruf" ) ;
193 ( Brand_tribler , "Tribler" , "trb" ) ;
194 ( Brand_cachelogic , "CacheLogic" , "cl" ) ;
195 ( Brand_electricsheep , "Electric sheep" , "els" ) ;
196 ( Brand_qbittorrent , "qBittorrent" , "qbt" ) ;
197 ( Brand_qt4 , "QT4" , "qt4" ) ;
198 ( Brand_uleecher , "uLeecher!" , "ul!" ) ;
199 ( Brand_flashget , "FlashGet" , "flg" ) ;
200 ( Brand_xtorrent , "Xtorrent" , "xto" ) ;
201 ( Brand_limewire , "LimeWire" , "lwi" ) ;
202 ( Brand_btpd , "BT Protocol Daemon" , "bpd" ) ;
203 ( Brand_btyrant , "BitTyrant" , "bty" ) ;
204 ( Brand_ares , "Ares" , "are" ) ;
205 ( Brand_bitpump , "BitPump" , "bpu" ) ;
206 ( Brand_deluge , "Deluge" , "del" ) ;
207 ( Brand_btuga , "BTuga Revolution" , "btr" ) ;
208 ( Brand_tuotu , "Tuotu" , "tuo" ) ;
209 ( Brand_xunlei , "XunLei" , "xun" ) ;
210 ( Brand_foxtorrent , "FoxTorrent" , "fox" ) ;
211 ( Brand_bitflu , "BitFlu" , "flu" ) ;
212 ( Brand_oneswarm , "OneSwarm" , "osw" ) ;
213 ( Brand_halite , "Halite" , "hal" ) ;
214 ( Brand_miro , "Miro" , "mir" ) ;
215 ( Brand_pando , "Pando" , "pan" ) ;
218 let brand_count = List.length brand_list
220 let brand_to_string brand =
221 find_brand_to_string brand brand_list false
223 let brand_to_string_short brand =
224 find_brand_to_string brand brand_list true
226 let brand_to_int brand =
227 find_int_of_brand brand brand_list
229 type tracker_status =
230 Enabled
231 | Disabled of string
232 | Disabled_mld of string
233 | Disabled_failure of (int * string)
235 type tracker_url =
236 [ `Http of string (* url *)
237 | `Udp of string * int (* host and port *)
238 | `Other of string ]
240 type client = {
241 client_client : client CommonClient.client_impl;
242 mutable client_file : file;
243 mutable client_connection_control : connection_control;
244 mutable client_sock : tcp_connection;
245 mutable client_host : Ip.t * int;
246 mutable client_country_code : int option;
247 mutable client_chunks : (int64 * int64) list;
248 mutable client_uploader : CommonSwarming.uploader option;
249 mutable client_ranges_sent : (int64 * int64 * CommonSwarming.range) list;
250 mutable client_range_waiting :
251 (int64 * int64 * CommonSwarming.range) option;
252 mutable client_chunk : (int * CommonSwarming.uploader_block list) option;
254 mutable client_received_peer_id : bool;
255 mutable client_sent_choke : bool; (* we sent a Choke to the client *)
256 mutable client_choked : bool; (* we received a Choke from the client *)
257 mutable client_interested : bool;
258 mutable client_uid : Sha1.t;
260 mutable client_brand : brand;
261 mutable client_release : string;
263 mutable client_bitmap : Bitv.t option;
264 mutable client_new_chunks : int list;
266 mutable client_upload_requests : (int * int64 * int64) list;
267 mutable client_allowed_to_write : int64;
268 mutable client_upload_rate : Rate.t;
269 mutable client_downloaded_rate : Rate.t;
270 mutable client_total_downloaded : int64;
271 mutable client_total_uploaded : int64;
272 mutable client_session_downloaded : int64;
273 mutable client_session_uploaded : int64;
274 mutable client_connect_time : int;
276 mutable client_blocks_sent : int list;
277 mutable client_good : bool;
278 mutable client_num_try : int;
279 mutable client_alrd_sent_interested : bool;
280 mutable client_alrd_sent_notinterested : bool;
281 mutable client_interesting : bool;
282 mutable client_incoming : bool;
283 mutable client_registered_bitfield : bool;
284 mutable client_last_optimist : int;
286 mutable client_dht : bool;
287 mutable client_cache_extension : bool;
288 mutable client_fast_extension : bool;
289 mutable client_utorrent_extension : bool;
290 mutable client_azureus_messaging_protocol : bool;
294 and tracker_info = {
295 tracker_url : tracker_url;
296 mutable tracker_interval : int;
297 mutable tracker_min_interval : int;
298 mutable tracker_last_conn : int;
299 mutable tracker_last_clients_num : int;
300 mutable tracker_torrent_downloaded : int;
301 mutable tracker_torrent_complete : int;
302 mutable tracker_torrent_incomplete : int;
303 mutable tracker_torrent_total_clients_count : int;
304 mutable tracker_torrent_last_dl_req : int;
305 mutable tracker_id : string;
306 mutable tracker_key : string;
307 mutable tracker_status : tracker_status;
310 and file = {
311 file_file : file CommonFile.file_impl;
312 file_piece_size : int64;
313 file_id : Sha1.t;
314 file_name : string;
315 file_comment : string;
316 file_created_by : string;
317 file_creation_date : int64;
318 file_modified_by : string;
319 file_encoding : string;
320 mutable file_swarmer : CommonSwarming.t option;
321 mutable file_clients : ((Ip.t*int), client) Hashtbl.t ;
322 mutable file_clients_num : int ;
323 mutable file_chunks : Sha1.t array;
324 mutable file_files : (string * int64 * string option) list;
325 mutable file_blocks_downloaded : int list;
326 (* vvv probably a network specific value vvv ?what about file_downloaded?*)
327 mutable file_uploaded : int64;
328 mutable file_torrent_diskname : string;
329 mutable file_trackers : tracker_info list;
330 mutable file_tracker_connected : bool;
331 mutable file_completed_hook : (file -> unit);
332 mutable file_shared : file CommonShared.shared_impl option;
333 (** session uploaded and downloaded bytes, for statistics reporting *)
334 mutable file_session_uploaded : int64;
335 mutable file_session_downloaded : int64;
336 (** DHT specific *)
337 mutable file_last_dht_announce : int;
338 file_private : bool;
341 and ft = {
342 ft_file : ft CommonFile.file_impl;
343 ft_id : int;
344 ft_filename : string;
345 mutable ft_retry : (ft -> unit);