patch #7310
[mldonkey.git] / src / networks / donkey / donkeyTypes.ml
blob917488c897ae52cf50893a8de770b54b5a571a4d
1 (* Copyright 2001, 2002 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
20 open Queues
21 open Md4
22 open CommonDownloads
23 open CommonTypes
24 open CommonStats
25 open Printf2
27 let log_prefix = "[EDK]"
29 let lprintf_nl fmt =
30 lprintf_nl2 log_prefix fmt
32 let lprintf_n fmt =
33 lprintf2 log_prefix fmt
35 exception Donkey_large_file
37 type emule_proto = {
38 mutable emule_version : int;
39 mutable emule_release : string;
40 mutable emule_osinfosupport : int;
41 mutable emule_features : int;
43 (* emule_miscoptions1 *)
44 mutable received_miscoptions1 : bool;
45 mutable emule_aich : int;
46 mutable emule_unicode : int;
47 mutable emule_udpver : int;
48 mutable emule_compression : int;
49 mutable emule_secident : int;
50 mutable emule_sourceexchange : int;
51 mutable emule_extendedrequest : int;
52 mutable emule_comments : int;
53 mutable emule_peercache : int;
54 mutable emule_noviewshared : int;
55 mutable emule_multipacket : int;
56 mutable emule_supportpreview : int;
58 (* emule_miscoptions2 *)
59 mutable received_miscoptions2 : bool;
60 mutable emule_require_crypt : int;
61 mutable emule_request_crypt : int;
62 mutable emule_support_crypt : int;
63 mutable emule_extmultipacket : int;
64 mutable emule_largefiles : int;
65 mutable emule_kad_version : int;
68 type emule_tag_name =
69 | ET_COMPRESSION
70 | ET_UDPPORT
71 | ET_UDPVER
72 | ET_SOURCEEXCHANGE
73 | ET_COMMENTS
74 | ET_EXTENDEDREQUEST
75 | ET_COMPATIBLECLIENT
76 | ET_MOD_FEATURESET
77 | ET_MOD_PROTOCOL
78 | ET_MOD_VERSION
79 | ET_MOD_TAROD
80 | ET_TAROD_VERSION
81 | ET_MOD_PLUS
83 type request_record = {
84 mutable last_request : int;
85 mutable nwarnings : int;
88 type reliability =
89 Reliability_neutral
90 | Reliability_reliable
91 | Reliability_suspicious of int
93 type brand =
94 Brand_unknown
95 | Brand_edonkey
96 | Brand_cdonkey
97 | Brand_mldonkey1
98 | Brand_mldonkey2
99 | Brand_mldonkey3
100 | Brand_overnet
101 | Brand_newemule
102 | Brand_lmule
103 | Brand_shareaza
104 | Brand_server
105 | Brand_amule
106 | Brand_lphant
107 | Brand_emuleplus
108 | Brand_hydranode
109 | Brand_verycd
110 | Brand_imp
112 let brand_list = [
113 ( Brand_unknown , "unknown" , "unk" ) ;
114 ( Brand_edonkey , "eDonkey" , "eDK" ) ;
115 ( Brand_mldonkey1 , "old mldonkey" , "oML" ) ;
116 ( Brand_mldonkey2 , "new mldonkey" , "nML" ) ;
117 ( Brand_overnet , "Overnet" , "OVR" ) ;
118 ( Brand_newemule , "eMule" , "eMU" ) ;
119 ( Brand_server , "server" , "SER" ) ;
120 ( Brand_mldonkey3 , "trusted mld" , "tML" ) ;
121 ( Brand_cdonkey , "cDonkey" , "cDK" ) ;
122 ( Brand_lmule , "xMule" , "xMU" ) ;
123 ( Brand_shareaza , "shareaza" , "sZA" ) ;
124 ( Brand_amule , "aMule" , "aMU" ) ;
125 ( Brand_lphant , "lPhant" , "lPH" ) ;
126 ( Brand_emuleplus , "ePlus" , "eM+" ) ;
127 ( Brand_hydranode , "Hydra" , "Hyd" ) ;
128 ( Brand_verycd , "VeryCD" , "VCD" ) ;
129 ( Brand_imp , "IMPmule" , "IMP" ) ;
132 let brand_count = List.length brand_list
134 type brand_mod =
135 Brand_mod_unknown
136 | Brand_mod_extasy
137 | Brand_mod_hunter
138 | Brand_mod_sivka
139 | Brand_mod_ice
140 | Brand_mod_plus
141 | Brand_mod_lsd
142 | Brand_mod_maella
143 | Brand_mod_pille
144 | Brand_mod_morphkad
145 | Brand_mod_efmod
146 | Brand_mod_xtreme
147 | Brand_mod_bionic
148 | Brand_mod_pawcio
149 | Brand_mod_zzul
150 | Brand_mod_blackhand
151 | Brand_mod_lovelace
152 | Brand_mod_morphnext
153 | Brand_mod_fincan
154 | Brand_mod_ewombat
155 | Brand_mod_morph
156 | Brand_mod_mortillo
157 | Brand_mod_lh
158 | Brand_mod_emulespana
159 | Brand_mod_blackrat
160 | Brand_mod_enkeydev
161 | Brand_mod_gnaddelwarz
162 | Brand_mod_phoenixkad
163 | Brand_mod_koizo
164 | Brand_mod_ed2kfiles
165 | Brand_mod_athlazan
166 | Brand_mod_cryptum
167 | Brand_mod_lamerzchoice
168 | Brand_mod_notdead
169 | Brand_mod_peace
170 | Brand_mod_goldicryptum
171 | Brand_mod_eastshare
172 | Brand_mod_mfck
173 | Brand_mod_echanblard
174 | Brand_mod_sp4rk
175 | Brand_mod_powermule
176 | Brand_mod_bloodymad
177 | Brand_mod_roman2k
178 | Brand_mod_gammaoh
179 | Brand_mod_elfenwombat
180 | Brand_mod_o2
181 | Brand_mod_dm
182 | Brand_mod_sfiom
183 | Brand_mod_magic_elseve
184 | Brand_mod_schlumpmule
185 | Brand_mod_lc
186 | Brand_mod_noamson
187 | Brand_mod_stormit
188 | Brand_mod_omax
189 | Brand_mod_mison
190 | Brand_mod_phoenix
191 | Brand_mod_spiders
192 | Brand_mod_iberica
193 | Brand_mod_mortimer
194 | Brand_mod_stonehenge
195 | Brand_mod_xlillo
196 | Brand_mod_imperator
197 | Brand_mod_raziboom
198 | Brand_mod_khaos
199 | Brand_mod_hardmule
200 | Brand_mod_sc
201 | Brand_mod_cy4n1d
202 | Brand_mod_dmx
203 | Brand_mod_ketamine
204 | Brand_mod_blackmule
205 | Brand_mod_morphxt
206 | Brand_mod_ngdonkey
207 | Brand_mod_hawkstar
208 | Brand_mod_neomule
209 | Brand_mod_cyrex
210 | Brand_mod_aldo
211 | Brand_mod_emulede
212 | Brand_mod_zx
213 | Brand_mod_ibericaxt
214 | Brand_mod_candymule
215 | Brand_mod_ackronic
216 | Brand_mod_rappis
217 | Brand_mod_overdose
218 | Brand_mod_hebmule
219 | Brand_mod_senfei
220 | Brand_mod_spoofmod
221 | Brand_mod_fusspilz
222 | Brand_mod_rocket
223 | Brand_mod_warezfaw
224 | Brand_mod_emusicmule
225 | Brand_mod_aideadsl
226 | Brand_mod_epo
227 | Brand_mod_kalitsch
228 | Brand_mod_raynz
229 | Brand_mod_serverclient
230 | Brand_mod_bl4ckbird
231 | Brand_mod_bl4ckf0x
232 | Brand_mod_rt
233 | Brand_mod_airionix
234 | Brand_mod_ionix
235 | Brand_mod_tornado
236 | Brand_mod_antifaker
237 | Brand_mod_netf
238 | Brand_mod_nextemf
239 | Brand_mod_proemule
240 | Brand_mod_szemule
241 | Brand_mod_darkmule
242 | Brand_mod_miragemod
243 | Brand_mod_nextevolution
244 | Brand_mod_pootzgrila
245 | Brand_mod_freeangel
246 | Brand_mod_enos
247 | Brand_mod_webys
249 let brand_mod_list = [
250 ( Brand_mod_unknown , "unknown" , "" ) ;
251 ( Brand_mod_extasy , "Extasy" , "ext" ) ;
252 ( Brand_mod_hunter , "Hunter" , "hun" ) ;
253 ( Brand_mod_sivka , "Sivka" , "siv" ) ;
254 ( Brand_mod_ice , "IcE" , "ice" ) ;
255 ( Brand_mod_plus , "Plus" , "plu" ) ;
256 ( Brand_mod_lsd , "LSD" , "lsd" ) ;
257 ( Brand_mod_maella , "Maella" , "mae" ) ;
258 ( Brand_mod_pille , "Pille" , "pil" ) ;
259 ( Brand_mod_morphkad , "MorphKad" , "mo1" ) ;
260 ( Brand_mod_efmod , "eF-MOD" , "efm" ) ;
261 ( Brand_mod_xtreme , "Xtreme" , "xtr" ) ;
262 ( Brand_mod_bionic , "Bionic" , "bio" ) ;
263 ( Brand_mod_pawcio , "Pawcio" , "paw" ) ;
264 ( Brand_mod_zzul , "ZZUL" , "zzu" ) ;
265 ( Brand_mod_blackhand , "Black Hand" , "bla" ) ;
266 ( Brand_mod_lovelace , "lovelace" , "lov" ) ;
267 ( Brand_mod_morphnext , "MorphNext" , "mo2" ) ;
268 ( Brand_mod_fincan , "fincan" , "fin" ) ;
269 ( Brand_mod_ewombat , "eWombat" , "ewo" ) ;
270 ( Brand_mod_morph , "Morph" , "mo3" ) ;
271 ( Brand_mod_mortillo , "MorTillo" , "mot" ) ;
272 ( Brand_mod_lh , "LionHeart" , "lh" ) ;
273 ( Brand_mod_emulespana , "emulEspa\241a" , "esp" ) ;
274 ( Brand_mod_blackrat , "BlackRat" , "blr" ) ;
275 ( Brand_mod_enkeydev , "enkeyDev" , "ekd" ) ;
276 ( Brand_mod_gnaddelwarz , "Gnaddelwarz" , "gna" ) ;
277 ( Brand_mod_phoenixkad , "pHoeniX-KAD" , "pkd" ) ;
278 ( Brand_mod_koizo , "koizo" , "koi" ) ;
279 ( Brand_mod_ed2kfiles , "ed2kFiles" , "edf" ) ;
280 ( Brand_mod_athlazan , "Athlazan" , "ath" ) ;
281 ( Brand_mod_cryptum , "Cryptum" , "cry" ) ;
282 ( Brand_mod_lamerzchoice , "LamerzChoice" , "lam" ) ;
283 ( Brand_mod_notdead , "NotDead" , "nod" ) ;
284 ( Brand_mod_peace , "peace" , "pea" ) ;
285 ( Brand_mod_goldicryptum , "GoldiCryptum" , "gcr" ) ;
286 ( Brand_mod_eastshare , "EastShare" , "eas" ) ;
287 ( Brand_mod_mfck , "[MFCK]" , "mfc" ) ;
288 ( Brand_mod_echanblard , "eChanblard" , "ech" ) ;
289 ( Brand_mod_sp4rk , "Sp4rK" , "sp4" ) ;
290 ( Brand_mod_powermule , "PowerMule" , "pow" ) ;
291 ( Brand_mod_bloodymad , "bloodymad" , "blo" ) ;
292 ( Brand_mod_roman2k , "Roman2K" , "rom" ) ;
293 ( Brand_mod_gammaoh , "GaMMaOH" , "gam" ) ;
294 ( Brand_mod_elfenwombat , "ElfenWombat" , "elf" ) ;
295 ( Brand_mod_o2 , "O2" , "o2" ) ;
296 ( Brand_mod_dm , "DM" , "DM" ) ;
297 ( Brand_mod_sfiom , "SF-IOM" , "SFI" ) ;
298 ( Brand_mod_magic_elseve , "Magic-Elseve" , "MEl" ) ;
299 ( Brand_mod_schlumpmule , "SchlumpMule" , "sch" ) ;
300 ( Brand_mod_lc , "LC" , "LC" ) ;
301 ( Brand_mod_noamson , "NoamSon" , "NoS" ) ;
302 ( Brand_mod_stormit , "Stormit" , "Sto" ) ;
303 ( Brand_mod_omax , "OMaX" , "OMX" ) ;
304 ( Brand_mod_mison , "Mison" , "Mis" ) ;
305 ( Brand_mod_phoenix , "Phoenix" , "pPho" ) ;
306 ( Brand_mod_spiders , "Spiders" , "spi" ) ;
307 ( Brand_mod_iberica , "Ib\233rica" , "Ib" ) ;
308 ( Brand_mod_mortimer , "Mortimer" , "mor" ) ;
309 ( Brand_mod_stonehenge , "Stonehenge" , "sto" ) ;
310 ( Brand_mod_xlillo , "Xlillo" , "Xli" ) ;
311 ( Brand_mod_imperator , "ImperatoR" , "Imp" ) ;
312 ( Brand_mod_raziboom , "Raziboom" , "Raz" ) ;
313 ( Brand_mod_khaos , "Khaos" , "Kha" ) ;
314 ( Brand_mod_hardmule , "Hardmule" , "Har" ) ;
315 ( Brand_mod_sc , "SC" , "SC" ) ;
316 ( Brand_mod_cy4n1d , "Cy4n1d" , "Cy4" ) ;
317 ( Brand_mod_dmx , "DMX" , "DMX" ) ;
318 ( Brand_mod_ketamine , "Ketamine" , "Ket" ) ;
319 ( Brand_mod_blackmule , "Blackmule" , "blm" ) ;
320 ( Brand_mod_morphxt , "MorphXT" , "Mxt" ) ;
321 ( Brand_mod_ngdonkey , "ngdonkey" , "ngd" ) ;
322 ( Brand_mod_cyrex , "Cyrex" , "haw" ) ;
323 ( Brand_mod_hawkstar , "Hawkstar" , "neo" ) ;
324 ( Brand_mod_neomule , "Neo Mule" , "cyr" ) ;
325 ( Brand_mod_aldo , "aldo" , "ald" ) ;
326 ( Brand_mod_emulede , "emule.de" , "ede" ) ;
327 ( Brand_mod_zx , "zx" , "zx" ) ;
328 ( Brand_mod_ibericaxt , "ib\233ricaxt" , "iBx" ) ;
329 ( Brand_mod_candymule , "candy-mule" , "can" ) ;
330 ( Brand_mod_ackronic , "ackronic" , "ack" ) ;
331 ( Brand_mod_rappis , "rappis" , "rap" ) ;
332 ( Brand_mod_overdose , "overdose" , "ove" ) ;
333 ( Brand_mod_hebmule , "hebmule" , "heb" ) ;
334 ( Brand_mod_senfei , "senfei" , "sen" ) ;
335 ( Brand_mod_spoofmod , "spoofmod" , "spo" ) ;
336 ( Brand_mod_fusspilz , "fusspilz" , "fus" ) ;
337 ( Brand_mod_rocket , "rocket" , "roc" ) ;
338 ( Brand_mod_warezfaw , "warezfaw" , "war" ) ;
339 ( Brand_mod_emusicmule , "emusicmule" , "emm" ) ;
340 ( Brand_mod_aideadsl , "aideadsl" , "aid" ) ;
341 ( Brand_mod_epo , "epo" , "epo" ) ;
342 ( Brand_mod_kalitsch , "kalitsch" , "kal" ) ;
343 ( Brand_mod_raynz , "raynz" , "ray" ) ;
344 ( Brand_mod_serverclient , "serverclient" , "sc" ) ;
345 ( Brand_mod_bl4ckbird , "bl4ckbird" , "b4b" ) ;
346 ( Brand_mod_bl4ckf0x , "bl4ckf0x" , "b4f" ) ;
347 ( Brand_mod_rt , "rt" , "rt" ) ;
348 ( Brand_mod_airionix , "air-ionix" , "aio" ) ;
349 ( Brand_mod_ionix , "ionix" , "ion" ) ;
350 ( Brand_mod_tornado , "tornado" , "tor" ) ;
351 ( Brand_mod_antifaker , "anti-faker" , "anf" ) ;
352 ( Brand_mod_netf , "netf" , "nef" ) ;
353 ( Brand_mod_nextemf , "nextemf" , "nxf" ) ;
354 ( Brand_mod_proemule , "proemule" , "pem" ) ;
355 ( Brand_mod_szemule , "szemule" , "sze" ) ;
356 ( Brand_mod_darkmule , "darkmule" , "dar" ) ;
357 ( Brand_mod_miragemod , "miragemod" , "mir" ) ;
358 ( Brand_mod_nextevolution , "nextevolution" , "nxe" ) ;
359 ( Brand_mod_pootzgrila , "pootzgrila" , "poo" ) ;
360 ( Brand_mod_freeangel , "freeangel" , "fre" ) ;
361 ( Brand_mod_enos , "enos" , "eno" ) ;
362 ( Brand_mod_webys , "webys" , "wys" ) ;
365 let brand_mod_count = List.length brand_mod_list
367 let brand_to_string brand =
368 find_brand_to_string brand brand_list false
370 let brand_to_string_short brand =
371 find_brand_to_string brand brand_list true
373 let brand_mod_to_string brand =
374 find_brand_to_string brand brand_mod_list false
376 let brand_mod_to_string_short brand =
377 find_brand_to_string brand brand_mod_list true
379 let brand_to_int brand =
380 find_int_of_brand brand brand_list
382 let brand_mod_to_int brand =
383 find_int_of_brand brand brand_mod_list
385 type source_uid =
386 Direct_address of Ip.t * int
387 | Indirect_address of Ip.t * int * int64 * int * Ip.t
388 | Invalid_address of string * string
390 let id_of_ip ip = Ip.to_int64 (Ip.rev ip)
391 let ip_of_id id = Ip.rev (Ip.of_int64 id)
393 module DonkeySources = CommonSources.Make(struct
395 open Options
397 type source_brand = bool
398 let value_to_source_brand = value_to_bool
399 let source_brand_to_value = bool_to_value
400 let dummy_source_brand = false
402 type t = source_uid
403 type source_uid = t
405 let module_name = "DonkeySources"
407 let direct_source s =
408 match s with Direct_address _ -> true | _ -> false
410 let indirect_source s =
411 match s with Indirect_address _ -> true | _ -> false
413 let dummy_source_uid = Direct_address (Ip.null, 0)
415 let value_to_source_uid v =
416 match v with
417 List [ip;port] | SmallList [ip;port] ->
418 let ip = Ip.of_string (value_to_string ip) in
419 let port = value_to_int port in
420 Direct_address (ip, port)
421 | List [ip;port; id] | SmallList [ip;port;id] ->
422 let ip = Ip.of_string (value_to_string ip) in
423 let port = value_to_int port in
424 let id = try id_of_ip (Ip.of_string (value_to_string id))
425 with _ -> value_to_int64 id in
426 Indirect_address (ip, port, id, 0, Ip.null)
427 | _ ->
428 failwith "bad client address"
430 let source_uid_to_value s =
431 match s with
432 Direct_address (ip, port) ->
433 SmallList [string_to_value (Ip.to_string ip); int_to_value port]
434 | Indirect_address (server_ip, server_port, id, port, _) ->
435 SmallList [
436 string_to_value (Ip.to_string server_ip);
437 int_to_value server_port;
438 int64_to_value id;
440 | Invalid_address _ -> failwith "Invalid address"
441 end)
443 type file = {
444 file_file : file CommonFile.file_impl;
445 file_md4 : Md4.t;
446 mutable file_swarmer : CommonSwarming.t option;
447 mutable file_nchunks : int;
448 mutable file_nchunk_hashes : int;
449 mutable file_diskname : string;
450 mutable file_computed_md4s : Md4.t array;
451 mutable file_format : format;
452 mutable file_shared : file CommonShared.shared_impl option;
453 mutable file_sources : DonkeySources.file_sources_manager;
454 mutable file_comments : (Ip.t * string * int * string) list;
457 and server = (*[]*){
458 mutable server_server : server CommonServer.server_impl;
459 mutable server_ip : Ip.t;
460 mutable server_cid : Ip.t option;
461 mutable server_port : int;
462 mutable server_realport : int option; (* in case we connect through auxport; this is the true one *)
463 mutable server_country_code : int option;
464 mutable server_sock : tcp_connection;
465 mutable server_search_queries : CommonTypes.search Fifo.t;
466 mutable server_users_queries : bool Fifo.t;
467 mutable server_connection_control : connection_control;
468 mutable server_score : int;
469 mutable server_tags : CommonTypes.tag list;
470 mutable server_nusers : int64 option;
471 mutable server_nfiles : int64 option;
472 mutable server_name : string;
473 mutable server_description : string;
474 mutable server_banner : string;
475 mutable server_users: user list;
476 mutable server_next_udp : int;
477 mutable server_master : bool;
478 mutable server_preferred : bool;
479 mutable server_last_ping : float; (* time last PingServerUdpReq was sent *)
480 mutable server_next_ping : float; (* time next PingServerUdpReq will be sent *)
481 mutable server_descping_counter : int;
482 mutable server_ping : int;
483 mutable server_udp_ping_challenge : int64 option;
484 mutable server_udp_desc_challenge : int64 option;
485 (* reset after answer received, increased after UDP ping sent, server deleted after 10 attempts *)
486 mutable server_failed_count : int;
488 mutable server_id_requests : file option Fifo.t;
490 mutable server_queries_credit : int;
491 mutable server_waiting_queries : file list;
492 mutable server_sent_all_queries : bool;
493 mutable server_has_zlib : bool;
494 mutable server_has_newtags : bool;
495 mutable server_has_unicode : bool;
496 mutable server_has_related_search : bool;
497 mutable server_has_tag_integer : bool;
498 mutable server_has_largefiles : bool;
499 mutable server_obfuscation_tcp : int option;
500 mutable server_obfuscation_udp : int option;
501 mutable server_dynip : string;
502 mutable server_auxportslist : string;
503 mutable server_has_get_sources : bool;
504 mutable server_has_get_files : bool;
505 mutable server_has_get_sources2 : bool;
507 mutable server_flags : int;
508 mutable server_version : string;
509 mutable server_lowid_users : int64 option;
510 mutable server_soft_limit : int64 option;
511 mutable server_hard_limit : int64 option;
512 mutable server_max_users : int64 option;
513 mutable server_sent_shared : file list
517 and user = {
518 user_user : user CommonUser.user_impl;
519 user_md4 : Md4.t;
520 mutable user_name : string;
521 user_ip : Ip.t;
522 user_port : int;
523 user_tags : CommonTypes.tag list;
524 user_server : server;
527 and search_event =
528 (* Result of result *)
529 | Waiting of int
531 and file_change_kind =
532 NoFileChange
533 | FileAvailabilityChange
534 | FileInfoChange
536 and client_change_kind =
537 NoClientChange
538 | ClientStateChange
539 | ClientFriendChange
540 | ClientInfoChange
541 | ClientFilesChange
543 and server_change_kind =
544 NoServerChange
545 | ServerStateChange
546 | ServerUsersChange
547 | ServerInfoChange
548 | ServerBusyChange
550 and client = {
551 client_client : client CommonClient.client_impl;
552 mutable client_kind : source_uid;
553 client_source : DonkeySources.source;
554 mutable client_md4 : Md4.t;
555 mutable client_ip : Ip.t;
556 mutable client_country_code : int option;
557 mutable client_download : (file * CommonSwarming.uploader) option;
558 mutable client_file_queue : (
559 file * (* has displayed when connected *)
560 Bitv.t *
561 CommonSwarming.uploader
562 ) list;
563 mutable client_all_files : result list option;
564 mutable client_tags: CommonTypes.tag list;
565 mutable client_name : string;
566 mutable client_rating : int ;
567 mutable client_upload : upload_info option;
568 mutable client_checked : bool;
569 mutable client_connected : bool;
570 (* statistics *)
571 mutable client_session_downloaded : Int64.t;
572 mutable client_session_uploaded : Int64.t;
573 mutable client_total_downloaded : Int64.t;
574 mutable client_total_uploaded : Int64.t;
575 mutable client_brand : brand;
576 mutable client_brand_mod : brand_mod;
577 mutable client_osinfo_sent : bool;
578 mutable client_osinfo : string option;
579 mutable client_banned : bool;
580 mutable client_rank : int;
581 mutable client_connect_time : int;
582 mutable client_requests_received : int;
583 mutable client_requests_sent: int;
584 mutable client_slot : slot_status;
585 mutable client_debug : bool;
586 mutable client_pending_messages: string list;
587 client_emule_proto : emule_proto;
588 mutable client_comp : compressed_parts option;
589 mutable client_connection_time : int;
590 mutable client_sent_challenge : Int64.t;
591 mutable client_req_challenge : Int64.t;
592 mutable client_public_key : string option;
593 mutable client_sui_verified : bool option;
594 mutable client_last_file_req_md4 : Md4.t option;
597 and compressed_parts = {
598 comp_md4 : Md4.t;
599 comp_pos : int64;
600 comp_total : int;
601 mutable comp_len : int;
602 mutable comp_blocs : string list;
605 and slot_status =
606 SlotNotAsked
607 | SlotAsked
608 | SlotReceived
610 and upload_info = {
611 mutable up_file : file;
612 mutable up_pos : int64;
613 mutable up_end_chunk : int64;
614 mutable up_chunks : (int64 * int64) list;
615 (* zones sent but not yet received by other peer, oldest first *)
616 mutable up_flying_chunks : (int64 * int64) list;
617 mutable up_current : int64;
618 mutable up_finish : bool;
619 mutable up_waiting : bool;
622 and client_kind =
623 SourceClient of client
624 | SourceLastConnection of
625 int *
626 int * (* last connection attempt *)
627 int (* booked client num *)
629 and file_to_share = {
630 shared_name : string;
631 shared_size : int64;
632 mutable shared_list : Md4.t list;
633 mutable shared_pos : int64;
634 mutable shared_chunk : int;
635 mutable shared_fd : Unix32.t;
636 shared_shared : file_to_share CommonShared.shared_impl;
639 module UdpClientMap = Map.Make(struct
640 type t = source_uid
641 let compare = compare
642 end)
644 type udp_client = {
645 udp_client_ip : Ip.t;
646 udp_client_port : int;
647 udp_client_can_receive : bool;
648 mutable udp_client_last_conn : int;
651 and file_group = {
652 mutable group : udp_client UdpClientMap.t;
655 type old_result = result
657 exception NoSpecifiedFile
658 exception Already_done
660 type shared_file_info = {
661 sh_name : string;
662 sh_md4s : Md4.t array;
663 sh_mtime : float;
664 sh_size : int64;
667 open CommonFile
668 open CommonClient
669 open CommonServer
670 open CommonResult
672 let set_client_state c s =
673 let cc = as_client c.client_client in
674 set_client_state cc s
676 let set_client_disconnected c =
677 let cc = as_client c.client_client in
678 set_client_disconnected cc
680 let set_server_state s state =
681 let ss = as_server s.server_server in
682 if server_state ss <> state then begin
683 set_server_state ss state;
686 let file_state file =
687 CommonFile.file_state (as_file file.file_file)
689 let file_last_seen file = file.file_file.impl_file_last_seen
691 let file_must_update file =
692 file_must_update (as_file file.file_file)
694 let client_state client =
695 CommonClient.client_state (as_client client.client_client)
697 let client_new_file client r =
698 client_new_file (as_client client.client_client) ""
701 let server_state server =
702 CommonServer.server_state (as_server server.server_server)
704 let dummy_emule_proto = {
705 emule_version = 0;
706 emule_release = "";
707 emule_osinfosupport = 0;
708 emule_features = 0;
710 (* emule_miscoptions1 *)
711 received_miscoptions1 = false;
712 emule_aich = 0;
713 emule_unicode = 0;
714 emule_udpver = 0;
715 emule_compression = 0; (* 1 *)
716 emule_secident = 0;
717 emule_sourceexchange = 0; (* 3 *)
718 emule_extendedrequest = 0; (* 2 *)
719 emule_comments = 0;
720 emule_peercache = 0;
721 emule_noviewshared = 0;
722 emule_multipacket = 0;
723 emule_supportpreview = 0;
725 (* emule_miscoptions2 *)
726 received_miscoptions2 = false;
727 emule_require_crypt = 0;
728 emule_request_crypt = 0;
729 emule_support_crypt = 0;
730 emule_extmultipacket = 0;
731 emule_largefiles = 0;
732 emule_kad_version = 0;
735 let emule_proto () =
736 { dummy_emule_proto with emule_version = 0 }
738 let old_max_emule_file_size = 4290048000L
739 (* #define OLD_MAX_EMULE_FILE_SIZE 4290048000ui64 // (4294967295/PARTSIZE)*PARTSIZE = ~4GB *)
741 let max_emule_file_size = 0x4000000000L
742 (* #define MAX_EMULE_FILE_SIZE 0x4000000000ui64 // = 2^38 = 256GB *)