2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org )
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
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.
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
{
35 virtual ~CECPacketHandlerBase() { }
36 virtual void HandlePacket(const CECPacket
*) = 0;
39 class CECLoginPacket
: public CECPacket
{
41 CECLoginPacket(const wxString
& client
, const wxString
& version
,
42 bool canZLIB
= true, bool canUTF8numbers
= true, bool canNotify
= false);
45 class CECAuthPacket
: public CECPacket
{
47 CECAuthPacket(const wxString
& pass
);
50 //#warning Kry TODO - move to abstract layer.
51 class CRemoteConnect
: public CECMuleSocket
{
53 // State enums for connection SM ( client side ) in case of async processing
55 EC_INIT
, // initial state
56 EC_CONNECT_SENT
, // socket connect request sent
57 EC_REQ_SENT
, // sent auth request to core, waiting for reply
58 EC_SALT_RECEIVED
,// received salt from core
59 EC_PASSWD_SENT
, // sent password to core, waiting for OK
60 EC_OK
, // core replied "ok"
61 EC_FAIL
// core replied "bad"
64 // fifo of handlers for on-the-air requests. all EC concept is working in fcfs
65 // order, so it is ok to assume that order of replies is same as order of requests
66 std::list
<CECPacketHandlerBase
*> m_req_fifo
;
70 wxEvtHandler
* m_notifier
;
72 wxString m_connectionPassword
;
73 wxString m_server_reply
;
78 bool m_canUTF8numbers
;
81 void WriteDoneAndQueueEmpty();
83 // The event handler is used for notifying connect/close
84 CRemoteConnect(wxEvtHandler
* evt_handler
);
86 void SetCapabilities(bool canZLIB
, bool canUTF8numbers
, bool canNotify
);
89 const wxString
&host
, int port
,
90 const wxString
& login
, const wxString
&pass
,
91 const wxString
& client
, const wxString
& version
);
93 const wxString
& GetServerReply() const { return m_server_reply
; }
95 bool RequestFifoFull()
97 return m_req_count
> m_req_fifo_thr
;
100 virtual void OnConnect(); // To override connection events
101 virtual void OnLost(); // To override close events
103 void SendRequest(CECPacketHandlerBase
*handler
, const CECPacket
*request
);
104 void SendPacket(const CECPacket
*request
);
106 /********************* EC API ********************/
114 // Handles a ED2K link
115 void Ed2kLink(wxString
* link
);
120 // Connects Kad network
123 // Disconnects Kad network
129 // Connects to ED2K. If ip and port are not 0, connect
130 // to the specific port. Otherwise, connect to any.
131 void ConnectED2K(uint32 ip
, uint16 port
);
133 // Disconnects from ED2K
134 void DisconnectED2K();
140 void AddServer(uint32 ip
,
143 // Remove specific server
144 // Returns: Error message or empty string for no error
145 void RemoveServer(uint32 ip
,
148 // Returns ED2K server list
149 void GetServerList();
151 // Updates ED2K server from a URL
152 void UpdateServerList(wxString url
);
160 // Stops current search
163 // Returns search progress in %%
164 void GetSearchProgress();
166 // Add 1 or more of found files to download queue
167 void DownloadSearchResult(uint32
* file
);
172 // Returns aMule statistics
173 void GetStatistics();
175 // Returns aMule connection status
176 void GetConnectionState();
179 /* Queue/File handling */
181 // Returns downloads queue
182 void GetDlQueue(CMD4Hash
* file
);
184 // Returns uploads queue
185 void GetUpQueue(CMD4Hash
* file
);
187 // Returns waiting queue
188 void GetWtQueue(CMD4Hash
* file
);
190 // Drops no needed sources
191 void DropNoNeededSources(CMD4Hash
* file
);
193 // Drops full queue sources
194 void DropFullQueueSources(CMD4Hash
* file
);
196 // Drops high queue rating sources
197 void DropHighQueueSources(CMD4Hash
* file
);
200 void CleanUpSources(CMD4Hash
* file
);
202 // Swaps A4AF to a file
203 void SwapA4AFThis(CMD4Hash
* file
);
205 // Swaps A4AF to a file (auto)
206 void SwapA4AFThisAuto(CMD4Hash
* file
);
208 // Swaps A4AF to any other files
209 void SwapA4AFOthers(CMD4Hash
* file
);
211 // Pauses download(s)
212 void Pause(CMD4Hash
* file
);
214 // Resumes download(s)
215 void Resume(CMD4Hash
* file
);
218 void Stop(CMD4Hash
* file
);
220 // Sets priority for a download
221 void SetPriority(CMD4Hash
* file
,
224 // Deletes a download
225 void Delete(CMD4Hash
* file
);
227 // Sets category for a download
228 void SetCategory(CMD4Hash
* file
,
234 // Returns a list of shared files
235 void GetSharedFiles();
237 // Sets priority for 1 or more shared files
238 void SetSharedPriority(CMD4Hash
* file
,
241 // Reloads shared file list
242 void ReloadSharedFiles();
244 // Adds a directory to shared file list
245 void AddDirectoryToSharedFiles(wxString dir
);
248 void RenameFile(CMD4Hash file
,
254 // Adds a new debug log line
257 // Adds a new debug log line
258 void AddDebugLogLine();
263 // Returns the last log line.
264 void GetLastLogLine();
266 // Retrieves the debug log
269 // Retrieves the server info log
270 void GetServerInfo();
275 // Clears the debug log
276 void ClearDebugLog();
278 // Clears server info log
279 void ClearServerInfo();
284 // Request for Preferences
285 void GetPreferences();
287 // Setting the preferences
288 void SetPreferencesCategories();
289 void SetPreferencesGeneral(wxString userNick
,
291 void SetPreferencesConnections(uint32 LineDownloadCapacity
,
292 uint32 LineUploadCapacity
,
293 uint16 MaxDownloadSpeed
,
294 uint16 MaxUploadSpeed
,
295 uint16 UploadSlotAllocation
,
299 uint16 MaxSourcesPerFile
,
300 uint16 MaxConnections
,
301 bool EnableAutoConnect
,
302 bool EnableReconnect
,
303 bool EnableNetworkED2K
,
304 bool EnableNetworkKademlia
);
305 void SetPreferencesMessageFilter(bool Enabled
,
307 bool AllowFromFriends
,
308 bool FilterFromUnknownClients
,
309 bool FilterByKeyword
,
311 void SetPreferencesRemoteCrtl(bool RunOnStartup
,
314 CMD4Hash GuestPasswdHash
,
316 uint32 RefreshInterval
,
318 void SetPreferencesOnlineSig(bool Enabled
);
319 void SetPreferencesServers(bool RemoveDeadServers
,
320 uint16 RetriesDeadServers
,
322 // bool URLList, TODO: Implement this!
325 bool UsePrioritySystem
,
326 bool SmartLowIDCheck
,
327 bool SafeServerConnection
,
328 bool AutoConnectStaticOnly
,
329 bool ManualHighPriority
);
330 void SetPreferencesFiles(bool ICHEnabled
,
333 bool NewDownloadAutoPriority
,
334 bool PreviewPriority
,
335 bool NewAutoULPriotiry
,
336 bool UploadFullChunks
,
337 bool StartNextPaused
,
338 bool ResumeSameCategory
,
340 bool ExtractMetadata
,
341 bool AllocateFullChunks
,
342 bool AllocateFullSize
,
344 uint32 MinFreeSpace
);
345 void SetPreferencesSrcDrop(uint8 NoNeeded
,
349 uint16 AutodropTimer
);
350 void SetPreferencesDirectories();
351 void SetPreferencesStatistics();
352 void SetPreferencesSecurity(uint8 CanSeeShares
,
353 uint32 FilePermissions
,
354 uint32 DirPermissions
,
355 bool IPFilterEnabled
,
356 bool IPFilterAutoUpdate
,
357 wxString IPFilterUpdateURL
,
359 bool IPFilterFilterLAN
,
361 void SetPreferencesCoreTweaks(uint16 MaxConnectionsPerFive
,
365 uint32 SRVKeepAliveTimeout
);
367 // Creates new category
368 void CreateCategory(uint32 category
,
375 // Updates existing category
376 void UpdateCategory(uint32 category
,
383 // Deletes existing category
384 void DeleteCategory(uint32 category
);
386 // Retrieves the statistics graphs
387 void GetStatsGraphs();
389 // Retrieves the statistics tree
392 // Check if connection goes to local machine
393 bool IsConnectedToLocalHost();
396 virtual const CECPacket
*OnPacketReceived(const CECPacket
*packet
, uint32 trueSize
);
397 bool ProcessAuthPacket(const CECPacket
*reply
);
400 DECLARE_LOCAL_EVENT_TYPE(wxEVT_EC_CONNECTION
, wxEVT_USER_FIRST
+ 1000)
402 class wxECSocketEvent
: public wxEvent
{
404 wxECSocketEvent(int id
, int event_id
) : wxEvent(event_id
, id
) {}
405 wxECSocketEvent(int id
) : wxEvent(-1, id
) {}
406 wxECSocketEvent(int id
, bool result
, const wxString
& reply
) : wxEvent(-1, id
)
409 m_server_reply
= reply
;
411 wxEvent
*Clone(void) const { return new wxECSocketEvent(*this); }
412 bool GetResult() const { return m_value
; }
413 const wxString
& GetServerReply() const { return m_server_reply
; }
416 wxString m_server_reply
;
419 #endif // REMOTECONNECT_H
421 // File_checked_for_headers