Upstream tarball 9597
[amule.git] / src / libs / ec / cpp / RemoteConnect.h
blob1d4179d5c321d2f239418959211db6094d664333
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2008 Angel Vidal ( kry@amule.org )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef REMOTECONNECT_H
27 #define REMOTECONNECT_H
30 #include "ECMuleSocket.h"
31 #include "ECPacket.h" // Needed for CECPacket
33 class CECPacketHandlerBase {
34 public:
35 virtual ~CECPacketHandlerBase() { }
36 virtual void HandlePacket(const CECPacket *) = 0;
39 class CECLoginPacket : public CECPacket {
40 public:
41 CECLoginPacket(const wxString& client, const wxString& version);
44 class CECAuthPacket : public CECPacket {
45 public:
46 CECAuthPacket(const wxString& pass);
49 //#warning Kry TODO - move to abstract layer.
50 class CRemoteConnect : public CECMuleSocket {
51 private:
52 // State enums for connection SM ( client side ) in case of async processing
53 enum {
54 EC_INIT, // initial state
55 EC_CONNECT_SENT, // socket connect request sent
56 EC_REQ_SENT, // sent auth request to core, waiting for reply
57 EC_SALT_RECEIVED,// received salt from core
58 EC_PASSWD_SENT, // sent password to core, waiting for OK
59 EC_OK, // core replied "ok"
60 EC_FAIL // core replied "bad"
61 } m_ec_state;
63 // fifo of handlers for on-the-air requests. all EC concept is working in fcfs
64 // order, so it is ok to assume that order of replies is same as order of requests
65 std::list<CECPacketHandlerBase *> m_req_fifo;
66 int m_req_count;
67 int m_req_fifo_thr;
69 wxEvtHandler* m_notifier;
71 wxString m_connectionPassword;
72 wxString m_server_reply;
73 wxString m_client;
74 wxString m_version;
76 void WriteDoneAndQueueEmpty();
77 public:
78 // The event handler is used for notifying connect/close
79 CRemoteConnect(wxEvtHandler* evt_handler);
81 bool ConnectToCore(
82 const wxString &host, int port,
83 const wxString& login, const wxString &pass,
84 const wxString& client, const wxString& version);
86 const wxString& GetServerReply() const { return m_server_reply; }
88 bool RequestFifoFull()
90 return m_req_count > m_req_fifo_thr;
93 virtual void OnConnect(); // To override connection events
94 virtual void OnLost(); // To override close events
96 void SendRequest(CECPacketHandlerBase *handler, CECPacket *request);
97 void SendPacket(CECPacket *request);
99 /********************* EC API ********************/
102 /* Misc */
104 // Shuts down aMule
105 void ShutDown();
107 // Handles a ED2K link
108 void Ed2kLink(wxString* link);
111 /* Kad */
113 // Connects Kad network
114 void StartKad();
116 // Disconnects Kad network
117 void StopKad();
120 /* ED2K */
122 // Connects to ED2K. If ip and port are not 0, connect
123 // to the specific port. Otherwise, connect to any.
124 void ConnectED2K(uint32 ip, uint16 port);
126 // Disconnects from ED2K
127 void DisconnectED2K();
130 /* Servers */
132 // Adds a server
133 void AddServer(uint32 ip,
134 uint16 port);
136 // Remove specific server
137 // Returns: Error message or empty string for no error
138 void RemoveServer(uint32 ip,
139 uint16 port);
141 // Returns ED2K server list
142 void GetServerList();
144 // Updates ED2K server from a URL
145 void UpdateServerList(wxString url);
148 /* Search */
150 // Starts new search
151 void StartSearch();
153 // Stops current search
154 void StopSearch();
156 // Returns search progress in %%
157 void GetSearchProgress();
159 // Add 1 or more of found files to download queue
160 void DownloadSearchResult(uint32* file);
163 /* Statistics */
165 // Returns aMule statistics
166 void GetStatistics();
168 // Returns aMule connection status
169 void GetConnectionState();
172 /* Queue/File handling */
174 // Returns downloads queue
175 void GetDlQueue(CMD4Hash* file);
177 // Returns uploads queue
178 void GetUpQueue(CMD4Hash* file);
180 // Returns waiting queue
181 void GetWtQueue(CMD4Hash* file);
183 // Drops no needed sources
184 void DropNoNeededSources(CMD4Hash* file);
186 // Drops full queue sources
187 void DropFullQueueSources(CMD4Hash* file);
189 // Drops high queue rating sources
190 void DropHighQueueSources(CMD4Hash* file);
192 // Cleans up sources
193 void CleanUpSources(CMD4Hash* file);
195 // Swaps A4AF to a file
196 void SwapA4AFThis(CMD4Hash* file);
198 // Swaps A4AF to a file (auto)
199 void SwapA4AFThisAuto(CMD4Hash* file);
201 // Swaps A4AF to any other files
202 void SwapA4AFOthers(CMD4Hash* file);
204 // Pauses download(s)
205 void Pause(CMD4Hash* file);
207 // Resumes download(s)
208 void Resume(CMD4Hash* file);
210 // Stops download(s)
211 void Stop(CMD4Hash* file);
213 // Sets priority for a download
214 void SetPriority(CMD4Hash* file,
215 uint8 priority);
217 // Deletes a download
218 void Delete(CMD4Hash* file);
220 // Sets category for a download
221 void SetCategory(CMD4Hash* file,
222 wxString category);
225 /* Shared files */
227 // Returns a list of shared files
228 void GetSharedFiles();
230 // Sets priority for 1 or more shared files
231 void SetSharedPriority(CMD4Hash* file,
232 uint8 priority);
234 // Reloads shared file list
235 void ReloadSharedFiles();
237 // Adds a directory to shared file list
238 void AddDirectoryToSharedFiles(wxString dir);
240 // Renames a file
241 void RenameFile(CMD4Hash file,
242 wxString name);
245 /* Logging */
247 // Adds a new debug log line
248 void AddLogline();
250 // Adds a new debug log line
251 void AddDebugLogLine();
253 // Retrieves the log
254 void GetLog();
256 // Returns the last log line.
257 void GetLastLogLine();
259 // Retrieves the debug log
260 void GetDebugLog();
262 // Retrieves the server info log
263 void GetServerInfo();
265 // Clears the log
266 void ClearLog();
268 // Clears the debug log
269 void ClearDebugLog();
271 // Clears server info log
272 void ClearServerInfo();
275 /* Preferences */
277 // Request for Preferences
278 void GetPreferences();
280 // Setting the preferences
281 void SetPreferencesCategories();
282 void SetPreferencesGeneral(wxString userNick,
283 CMD4Hash userHash);
284 void SetPreferencesConnections(uint32 LineDownloadCapacity,
285 uint32 LineUploadCapacity,
286 uint16 MaxDownloadSpeed,
287 uint16 MaxUploadSpeed,
288 uint16 UploadSlotAllocation,
289 uint16 TCPPort,
290 uint16 UDPPort,
291 bool DisableUDP,
292 uint16 MaxSourcesPerFile,
293 uint16 MaxConnections,
294 bool EnableAutoConnect,
295 bool EnableReconnect,
296 bool EnableNetworkED2K,
297 bool EnableNetworkKademlia);
298 void SetPreferencesMessageFilter(bool Enabled,
299 bool FilterAll,
300 bool AllowFromFriends,
301 bool FilterFromUnknownClients,
302 bool FilterByKeyword,
303 wxString Keywords);
304 void SetPreferencesRemoteCrtl(bool RunOnStartup,
305 uint16 Port,
306 bool Guest,
307 CMD4Hash GuestPasswdHash,
308 bool UseGzip,
309 uint32 RefreshInterval,
310 wxString Template);
311 void SetPreferencesOnlineSig(bool Enabled);
312 void SetPreferencesServers(bool RemoveDeadServers,
313 uint16 RetriesDeadServers,
314 bool AutoUpdate,
315 // bool URLList, TODO: Implement this!
316 bool AddFromServer,
317 bool AddFromClient,
318 bool UsePrioritySystem,
319 bool SmartLowIDCheck,
320 bool SafeServerConnection,
321 bool AutoConnectStaticOnly,
322 bool ManualHighPriority);
323 void SetPreferencesFiles(bool ICHEnabled,
324 bool AIHCTrust,
325 bool NewPaused,
326 bool NewDownloadAutoPriority,
327 bool PreviewPriority,
328 bool NewAutoULPriotiry,
329 bool UploadFullChunks,
330 bool StartNextPaused,
331 bool ResumeSameCategory,
332 bool SaveSources,
333 bool ExtractMetadata,
334 bool AllocateFullChunks,
335 bool AllocateFullSize,
336 bool CheckFreeSpace,
337 uint32 MinFreeSpace);
338 void SetPreferencesSrcDrop(uint8 NoNeeded,
339 bool DropFQS,
340 bool DropHQRS,
341 uint16 HQRSValue,
342 uint16 AutodropTimer);
343 void SetPreferencesDirectories();
344 void SetPreferencesStatistics();
345 void SetPreferencesSecurity(uint8 CanSeeShares,
346 uint32 FilePermissions,
347 uint32 DirPermissions,
348 bool IPFilterEnabled,
349 bool IPFilterAutoUpdate,
350 wxString IPFilterUpdateURL,
351 uint8 IPFilterLevel,
352 bool IPFilterFilterLAN,
353 bool UseSecIdent);
354 void SetPreferencesCoreTweaks(uint16 MaxConnectionsPerFive,
355 bool Verbose,
356 uint32 FileBuffer,
357 uint32 ULQueue,
358 uint32 SRVKeepAliveTimeout);
360 // Creates new category
361 void CreateCategory(uint32 category,
362 wxString title,
363 wxString folder,
364 wxString comment,
365 uint32 color,
366 uint8 priority);
368 // Updates existing category
369 void UpdateCategory(uint32 category,
370 wxString title,
371 wxString folder,
372 wxString comment,
373 uint32 color,
374 uint8 priority);
376 // Deletes existing category
377 void DeleteCategory(uint32 category);
379 // Retrieves the statistics graphs
380 void GetStatsGraphs();
382 // Retrieves the statistics tree
383 void GetStatsTree();
385 private:
386 virtual const CECPacket *OnPacketReceived(const CECPacket *packet);
387 bool ProcessAuthPacket(const CECPacket *reply);
390 DECLARE_LOCAL_EVENT_TYPE(wxEVT_EC_CONNECTION, wxEVT_USER_FIRST + 1000)
392 class wxECSocketEvent : public wxEvent {
393 public:
394 wxECSocketEvent(int id, int event_id) : wxEvent(event_id, id) {}
395 wxECSocketEvent(int id) : wxEvent(-1, id) {}
396 wxECSocketEvent(int id, bool result, const wxString& reply) : wxEvent(-1, id)
398 m_value = result;
399 m_server_reply = reply;
401 wxEvent *Clone(void) const { return new wxECSocketEvent(*this); }
402 bool GetResult() const { return m_value; }
403 const wxString& GetServerReply() const { return m_server_reply; }
404 private:
405 bool m_value;
406 wxString m_server_reply;
409 #endif // REMOTECONNECT_H
411 // File_checked_for_headers