2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2008 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
);
44 class CECAuthPacket
: public CECPacket
{
46 CECAuthPacket(const wxString
& pass
);
49 //#warning Kry TODO - move to abstract layer.
50 class CRemoteConnect
: public CECMuleSocket
{
52 // State enums for connection SM ( client side ) in case of async processing
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"
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
;
69 wxEvtHandler
* m_notifier
;
71 wxString m_connectionPassword
;
72 wxString m_server_reply
;
76 void WriteDoneAndQueueEmpty();
78 // The event handler is used for notifying connect/close
79 CRemoteConnect(wxEvtHandler
* evt_handler
);
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 ********************/
107 // Handles a ED2K link
108 void Ed2kLink(wxString
* link
);
113 // Connects Kad network
116 // Disconnects Kad network
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();
133 void AddServer(uint32 ip
,
136 // Remove specific server
137 // Returns: Error message or empty string for no error
138 void RemoveServer(uint32 ip
,
141 // Returns ED2K server list
142 void GetServerList();
144 // Updates ED2K server from a URL
145 void UpdateServerList(wxString url
);
153 // Stops current search
156 // Returns search progress in %%
157 void GetSearchProgress();
159 // Add 1 or more of found files to download queue
160 void DownloadSearchResult(uint32
* file
);
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
);
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
);
211 void Stop(CMD4Hash
* file
);
213 // Sets priority for a download
214 void SetPriority(CMD4Hash
* file
,
217 // Deletes a download
218 void Delete(CMD4Hash
* file
);
220 // Sets category for a download
221 void SetCategory(CMD4Hash
* file
,
227 // Returns a list of shared files
228 void GetSharedFiles();
230 // Sets priority for 1 or more shared files
231 void SetSharedPriority(CMD4Hash
* file
,
234 // Reloads shared file list
235 void ReloadSharedFiles();
237 // Adds a directory to shared file list
238 void AddDirectoryToSharedFiles(wxString dir
);
241 void RenameFile(CMD4Hash file
,
247 // Adds a new debug log line
250 // Adds a new debug log line
251 void AddDebugLogLine();
256 // Returns the last log line.
257 void GetLastLogLine();
259 // Retrieves the debug log
262 // Retrieves the server info log
263 void GetServerInfo();
268 // Clears the debug log
269 void ClearDebugLog();
271 // Clears server info log
272 void ClearServerInfo();
277 // Request for Preferences
278 void GetPreferences();
280 // Setting the preferences
281 void SetPreferencesCategories();
282 void SetPreferencesGeneral(wxString userNick
,
284 void SetPreferencesConnections(uint32 LineDownloadCapacity
,
285 uint32 LineUploadCapacity
,
286 uint16 MaxDownloadSpeed
,
287 uint16 MaxUploadSpeed
,
288 uint16 UploadSlotAllocation
,
292 uint16 MaxSourcesPerFile
,
293 uint16 MaxConnections
,
294 bool EnableAutoConnect
,
295 bool EnableReconnect
,
296 bool EnableNetworkED2K
,
297 bool EnableNetworkKademlia
);
298 void SetPreferencesMessageFilter(bool Enabled
,
300 bool AllowFromFriends
,
301 bool FilterFromUnknownClients
,
302 bool FilterByKeyword
,
304 void SetPreferencesRemoteCrtl(bool RunOnStartup
,
307 CMD4Hash GuestPasswdHash
,
309 uint32 RefreshInterval
,
311 void SetPreferencesOnlineSig(bool Enabled
);
312 void SetPreferencesServers(bool RemoveDeadServers
,
313 uint16 RetriesDeadServers
,
315 // bool URLList, TODO: Implement this!
318 bool UsePrioritySystem
,
319 bool SmartLowIDCheck
,
320 bool SafeServerConnection
,
321 bool AutoConnectStaticOnly
,
322 bool ManualHighPriority
);
323 void SetPreferencesFiles(bool ICHEnabled
,
326 bool NewDownloadAutoPriority
,
327 bool PreviewPriority
,
328 bool NewAutoULPriotiry
,
329 bool UploadFullChunks
,
330 bool StartNextPaused
,
331 bool ResumeSameCategory
,
333 bool ExtractMetadata
,
334 bool AllocateFullChunks
,
335 bool AllocateFullSize
,
337 uint32 MinFreeSpace
);
338 void SetPreferencesSrcDrop(uint8 NoNeeded
,
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
,
352 bool IPFilterFilterLAN
,
354 void SetPreferencesCoreTweaks(uint16 MaxConnectionsPerFive
,
358 uint32 SRVKeepAliveTimeout
);
360 // Creates new category
361 void CreateCategory(uint32 category
,
368 // Updates existing category
369 void UpdateCategory(uint32 category
,
376 // Deletes existing category
377 void DeleteCategory(uint32 category
);
379 // Retrieves the statistics graphs
380 void GetStatsGraphs();
382 // Retrieves the statistics tree
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
{
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
)
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
; }
406 wxString m_server_reply
;
409 #endif // REMOTECONNECT_H
411 // File_checked_for_headers