parse ADCGET list, prepare to answer
[mldonkey.git] / src / networks / direct_connect / dcTypes.ml
blobd53ca3020ef1f38664fac1f365eef2578a9f1c7e
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 Md4
21 open CommonTypes
23 (* TODO
24 - directory download...
25 - remove download list is not working
26 - normal mynick: Search unknown names by ip ?
27 - blink users if they have messages
28 - there is no method to clear message memory atm
30 verbose_msg_clients
31 verbose_msg_servers
32 "mr" | "raw" -> verbose_msg_raw := true
33 "mct" -> verbose_msg_clienttags := true
34 "ms" -> verbose_msg_servers := true
35 "verb" -> verbose := true
36 "sm" -> incr verbose_sources
37 "file" -> Unix32.verbose := true
38 "gui" -> GuiProto.verbose_gui_decoding := true
39 "no-login" -> verbose_no_login := true
40 "do" -> verbose_download := true
41 "up" -> verbose_upload := true
42 "unk" -> verbose_unknown_messages := true
43 "ov" -> verbose_overnet := true
44 "loc" -> verbose_location := true
45 "share" -> verbose_share := true
46 "md4" -> verbose_md4 := true
47 "connect" -> verbose_connect := true
48 "udp" -> verbose_udp := true
49 "ultra" | "super" -> verbose_supernode := true
50 "swarming" -> verbose_swarming := true
51 "hc" -> Http_client.verbose := true
52 "hs" -> Http_server.verbose := true
53 "act" -> verbose_activity := true
54 "bw" -> incr BasicSocket.verbose_bandwidth
55 "unexp" -> verbose_unexpected_messages := true
56 verbose_sources := 1;
58 mc : debug client messages
59 mr|raw : debug raw messages
60 mct : debug emule clients tags
61 ms : debug server messages
62 sm : debug source management
63 net : debug net
64 gui : debug gui
65 no-login : disable login messages
66 file : debug file handling
67 do : some download warnings
68 up : some upload warnings
69 unk : unknown messages
70 ov : overnet
71 loc : debug source research/master servers
72 share: debug sharing
73 md4 : md4 computation
74 connect : debug connections
75 udp : udp messages
76 ultra|super : debug supernode
77 swarming : debug swarming
78 hc : http_client messages
79 hs : http_server messages
80 act : debug activity
81 bw : debug bandwidth
82 unexp : debug unexpected messages
86 type server = {
87 server_server: server CommonServer.server_impl;
88 server_connection_control : CommonTypes.connection_control;
89 mutable server_connection_time: float;
90 mutable server_name : string;
91 mutable server_addr : Ip.addr;
92 mutable server_ip : Ip.t;
93 mutable server_port : int;
94 mutable server_supports : dc_hub_supports option;
95 mutable server_hub_state: dc_hub_state;
96 mutable server_info : string;
97 mutable server_sock : tcp_connection;
98 mutable server_autoconnect : bool;
99 mutable server_last_nick : string;
100 mutable server_search : search option;
101 mutable server_search_timeout : int;
102 mutable server_users : user list;
103 mutable server_topic : string;
104 mutable server_messages : (int * string * room_message) list;
105 mutable server_read_messages : int;
109 and result = {
110 result_result : result CommonResult.result_impl;
111 result_name : string;
112 result_size : int64;
113 mutable result_sources : (user * string) list;
117 and user = {
118 user_user : user CommonUser.user_impl;
119 mutable user_nick : string;
120 mutable user_ip : Ip.addr; (* $IpUser *)
121 mutable user_servers : server list;
122 mutable user_clients : client list;
123 mutable user_link : string;
124 mutable user_uploaded : int64;
125 mutable user_downloaded : int64;
126 mutable user_myinfo : dc_myinfo;
127 mutable user_data : float;
128 mutable user_type : dc_usertype;
129 mutable user_state : dc_userstate;
130 mutable user_messages : (int * string * room_message) list;
131 mutable user_read_messages : int;
134 and file = {
135 file_file : file CommonFile.file_impl;
136 mutable file_unchecked_tiger_root : string;
137 mutable file_directory : string;
138 mutable file_name : string;
139 (*mutable file_tiger_array : TigerTree.t array;*)
140 mutable file_clients : client list;
141 mutable file_search : (CommonTypes.search * float) option; (* search , time *)
142 mutable file_autosearch_count : int;
145 and dc_shared_file = {
146 mutable dc_shared_fullname : string;
147 mutable dc_shared_codedname : string;
148 mutable dc_shared_searchname : string;
149 mutable dc_shared_size : int64;
150 mutable dc_shared_tiger_list : TigerTree.t list;
151 mutable dc_shared_tiger_root : string;
152 (*mutable dc_shared_tiger_array : TigerTree.t array;*)
153 mutable dc_shared_pos : int64;
154 mutable dc_shared_chunks : int;
157 and client = { (* remember DcGlobals.new_copy_client if add anything *)
158 client_client : client CommonClient.client_impl;
159 mutable client_name : string option;
160 mutable client_addr : (Ip.t * int) option;
161 mutable client_sock : tcp_connection;
162 mutable client_supports : dc_client_supports option;
163 mutable client_lock : string;
164 mutable client_file : file option;
165 mutable client_state : dc_clientstate;
166 mutable client_error : dc_client_error; (* last error message *)
167 mutable client_error_count : int; (* error message count *)
168 mutable client_preread_bytes_left : int;
169 mutable client_pos : int64;
170 mutable client_endpos : int64;
171 mutable client_receiving : int64;
172 mutable client_user : user option;
173 mutable client_connection_control : connection_control;
174 client_connect_time : int;
175 mutable client_downloaded : int64;
176 mutable client_uploaded : int64;
179 and dc_result = { (* rst of the info (filename & size) are on Commonresults.result_info *)
180 user : user;
181 tth : string;
182 directory : string;
185 and dc_direction = Upload of int | Download of int
187 and dc_connection_style = (* dc_direction is what client wants/needs to do *)
188 | ClientActive of dc_direction
189 | MeActive of dc_direction
191 (* Client to client procedure: S=Server M=Me C=Client
192 Me in Active mode - Client in Active/Passive mode: Me want to download
193 FROM______________________________________TO__USER_STATE________________CLIENT_STATE______________
194 UserIdle (No client yet)
195 UserActiveMeInitiating DcDownloadWaiting file
196 M ConnectToMe -> S . .
197 C MyNick -> M UserIdle DcConnectionStyle MeActive Upload 0
198 C |Lock -> M . .
199 M MyNick|Lock|Supports|Direction|Key -> C . .
200 C Supports|Direction -> M . If direction conflict loss
201 DcConnectionStyle MeActive Download 65535
202 C | Key -> M . If direction conflict loss
203 Wait client commands for uploading
204 else
205 DcDownload file
206 M Get/AdcGet -> C .
207 C Filelength/AdcSnd -> M .
208 M Send (if not ADC) -> C .
210 Me in Passive mode - Client in Active: Me want to download
211 FROM______________________________________TO__USER_STATE________________CLIENT_STATE______________
212 UserIdle (No client yet)
213 UserActiveUserInitiating DcDownloadWaiting file
214 M RevConnectToMe -> S . .
215 S ConnectToMe -> M . DcConnectionStyle ClientActive Upload 0
216 M MyNick|Lock -> C . .
217 C MyNick -> M UserIdle DcConnectionStyle ClientActive Upload 0
218 C |Lock|Supports|Direction -> M . If direction conflict loss
219 DcConnectionStyle ClientActive Download 65535
220 C |Key -> M . If direction conflict loss
221 Wait client commands for uploading
222 M Supports -> C . DcConnectionStyle ClientActive Upload level
223 M |Direction|Key -> C . DcDownload file
224 M |Get/AdcGet -> C .
225 C Filelength/AdcSnd -> M .
226 M Send ((if not ADC) -> C .
228 Me in Active/Passive mode - Client in Active: Client wants to download
229 FROM______________________________________TO__USER_STATE________________CLIENT_STATE______________
230 UserIdle (No client yet)
231 S ConnectToMe -> M . DcConnectionStyle ClientActive Upload 0
232 M MyNick|Lock -> C . .
233 C MyNick -> M UserIdle DcConnectionStyle ClientActive Download 0
234 C |Lock|Supports|Direction -> M . .
235 C |Key -> M . .
236 M Supports -> C . DcConnectionStyle ClientActive Download level
237 M |Direction|Key -> C . .
238 C Get/AdcGet -> M . If filelist loading
239 DcUploadListStarting
240 else
241 DcUploadStarting
242 M Filelength/AdcSnd -> C . .
243 C Send (if not ADC) -> M . DcUpload/DcUploadList
246 Me in Active mode - Client in Passive: Client wants to download
247 FROM______________________________________TO__USER_STATE________________CLIENT_STATE______________
248 UserIdle (No client yet)
249 S RevConnectToMe -> M UserPassiveUserInitiating (No client yet)
250 M ConnectToMe -> S . (No client yet)
251 C MyNick -> M . DcConnectionStyle MeActive Download 0
252 C |Lock -> M . .
253 M MyNick|Lock|Supports -> C . DcConnectionStyle MeActive Download 0
254 M |Direction|Key -> C . .
255 C Supports|Direction|Key -> M . .
256 C Get/AdcGet -> M . If filelist loading
257 DcUploadListStarting
258 else
259 DcUploadStarting
260 M Filelength/AdcSnd -> C . .
261 C Send (if not ADC) -> M . DcUpload/DcUploadList
265 and dc_clientstate =
266 | DcIdle (* client is doing nothing *)
267 | DcDownloadWaiting of file (* client is waiting for downloading slot *)
268 | DcDownloadConnecting of (file * float) (* client has passed from waiting state to initializing state *)
269 | DcDownloadListWaiting (* client is waiting a slot for list downloading *)
270 | DcDownloadListConnecting of (int * bool * float)(* client has passed waiting state to initializing state, *)
271 (* int = $Direction level , bool = firewalled state , timeout *)
272 | DcConnectionStyle of (dc_connection_style) (* how the initialization is processed with clients *)
273 | DcDownload of file (* we are downloading a file from client, switched on $Get *)
274 | DcDownloadList of Unix32.t (* we are downloading a file list from client *)
275 | DcUploadStarting of (dc_shared_file * int64 * int64) (* we are starting to upload file to client *)
276 | DcUpload of (dc_shared_file * Unix32.t * int64 * int64) (* we are uploading a file to client *)
277 | DcUploadListStarting of string (* we are starting to upload file with file name *)
278 | DcUploadList of Unix32.t (* we are uploading file list to client *)
279 | DcUploadDoneWaitingForMore (* upload is complete and we are waiting for more *)
281 and dc_userstate = (* used for determining states with users/clients *)
282 | UserIdle
283 | TryingToSendFirstContact
284 | UserActiveMeInitiating (* We have sent ConnectToMe to active client *)
285 | UserActiveUserInitiating (* We have sent RevConnect *)
286 | UserPassiveUserInitiating of float (* User has sent RevConnect and we have answered, time of reveiving *)
288 and dc_client_error =
289 | NoError
290 | NoFreeSlots
291 | FileNotAvailable
292 | UserNotReachable
293 | ClosedOnInit
294 | ConnectionResetByPeer
295 | UploadError
296 | UserDontReplyOnTime
298 (* Type for keeping and manipulation hublist *)
299 and dc_hub = {
300 mutable dc_name : string;
301 mutable dc_ip : Ip.addr;
302 mutable dc_port : int;
303 mutable dc_info : string;
304 mutable dc_nusers : int;
307 and sizelimit =
308 | AtLeast of int64
309 | AtMost of int64
310 | NoLimit
312 (* Type for $Supports usage with hubs *)
313 and dc_hub_supports = {
314 nogetinfo : bool;
315 nohello : bool;
316 userip2 : bool;
317 usercommand : bool;
318 tthsearch : bool;
319 opplus : bool;
320 feed : bool;
321 mcto : bool;
322 hubtopic : bool;
325 (* Type for $Supports usage with clients *)
326 and dc_client_supports = {
327 bzlist : bool;
328 minislots : bool;
329 getzblock : bool;
330 xmlbzlist : bool;
331 adcget : bool;
332 tthl : bool;
333 tthf : bool;
334 zlig : bool;
335 clientid : bool;
336 chunk : bool;
337 gettestzblock : bool;
338 getcid : bool;
341 and dc_supports =
342 | ClientSupports of dc_client_supports
343 | HubSupports of dc_hub_supports
345 and dc_hub_state =
346 | Waiting
347 | User
348 | Vipped
349 | Opped
352 and dc_usertype =
353 | Normal
354 | Vip
355 | Op
357 and dc_myinfo = {
358 mutable dest : string;
359 mutable nick : string;
360 mutable description : string;
361 mutable client_brand : string;
362 mutable version: string;
363 mutable mode : char;
364 mutable hubs : int * int * int;
365 mutable slots : int;
366 mutable open_upload_slot : int;
367 mutable conn_speed : string;
368 mutable flag : int;
369 mutable email : string;
370 mutable sharesize : int64;
371 mutable bwlimit : int;
374 and dc_mylistnode = (* type for mylist parsing *)
375 | MylistDirectory of (string * dc_mylistnode list ref)
376 | MylistFile of (string * string) (* filename * size *)
378 and adc_name =
379 (* | NameShared of string list (* shared filename - path from root *) *)
380 | NameSpecial of string (* rootless filename - filelists, future extensions *)
381 | NameTTH of string (* TTH/ *)
383 and adc_type =
384 | AdcFile of adc_name
385 (* | AdcTthl of string (* tth *) *)
386 | AdcList of string * bool (* path * recursive *)
388 and dc_shared_tree =
390 shared_dirname : string;
391 mutable shared_files : dc_shared_file list;
392 mutable shared_dirs : (string * dc_shared_tree) list;