Fix for libraries being compiled unconditionally
[amule.git] / src / updownclient.h
blob09b5115449c9137732fd1e1f368158f771eba7eb
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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 UPDOWNCLIENT_H
27 #define UPDOWNCLIENT_H
29 #include "GetTickCount.h" // Needed for GetTickCount
30 #include "MD4Hash.h"
31 #include <common/StringFunctions.h>
32 #include "NetworkFunctions.h"
33 #include "OtherStructs.h"
34 #include "ClientCredits.h" // Needed for EIdentState
35 #include <ec/cpp/ECID.h> // Needed for CECID
36 #include "BitVector.h" // Needed for BitVector
38 #include <map>
41 class CPartFile;
42 class CClientTCPSocket;
43 class CPacket;
44 class CFriend;
45 class CKnownFile;
46 class CMemFile;
47 class CAICHHash;
50 // uploadstate
51 #define US_UPLOADING 0
52 #define US_ONUPLOADQUEUE 1
53 #define US_WAITCALLBACK 2
54 #define US_CONNECTING 3
55 #define US_PENDING 4
56 #define US_LOWTOLOWIP 5
57 #define US_BANNED 6
58 #define US_ERROR 7
59 #define US_NONE 8
61 // downloadstate
62 enum EDownloadState {
63 DS_DOWNLOADING = 0,
64 DS_ONQUEUE,
65 DS_CONNECTED,
66 DS_CONNECTING,
67 DS_WAITCALLBACK,
68 DS_WAITCALLBACKKAD,
69 DS_REQHASHSET,
70 DS_NONEEDEDPARTS,
71 DS_TOOMANYCONNS,
72 DS_TOOMANYCONNSKAD,
73 DS_LOWTOLOWIP,
74 DS_BANNED,
75 DS_ERROR,
76 DS_NONE,
77 DS_REMOTEQUEUEFULL // not used yet, except in statistics
80 // m_byChatstate
81 enum {
82 MS_NONE = 0,
83 MS_CHATTING,
84 MS_CONNECTING,
85 MS_UNABLETOCONNECT
88 enum ESourceFrom {
89 SF_NONE,
90 SF_LOCAL_SERVER,
91 SF_REMOTE_SERVER,
92 SF_KADEMLIA,
93 SF_SOURCE_EXCHANGE,
94 SF_PASSIVE,
95 SF_LINK,
96 SF_SOURCE_SEEDS,
97 SF_SEARCH_RESULT
100 enum EChatCaptchaState {
101 CA_NONE = 0,
102 CA_CHALLENGESENT,
103 CA_CAPTCHASOLVED,
104 CA_ACCEPTING,
105 CA_CAPTCHARECV,
106 CA_SOLUTIONSENT
109 enum ESecureIdentState {
110 IS_UNAVAILABLE = 0,
111 IS_ALLREQUESTSSEND = 0,
112 IS_SIGNATURENEEDED = 1,
113 IS_KEYANDSIGNEEDED = 2
116 enum EInfoPacketState {
117 IP_NONE = 0,
118 IP_EDONKEYPROTPACK = 1,
119 IP_EMULEPROTPACK = 2,
120 IP_BOTH = 3
123 enum EKadState {
124 KS_NONE,
125 KS_QUEUED_FWCHECK,
126 KS_CONNECTING_FWCHECK,
127 KS_CONNECTED_FWCHECK,
128 KS_QUEUED_BUDDY,
129 KS_INCOMING_BUDDY,
130 KS_CONNECTING_BUDDY,
131 KS_CONNECTED_BUDDY,
132 KS_QUEUED_FWCHECK_UDP,
133 KS_FWCHECK_UDP,
134 KS_CONNECTING_FWCHECK_UDP
137 //! Used to keep track of the state of the client
138 enum ClientState
140 //! New is for clients that have just been created.
141 CS_NEW = 0,
142 //! Listed is for clients that are on the clientlist
143 CS_LISTED,
144 //! Dying signifies clients that have been queued for deletion
145 CS_DYING
148 // Obfuscation status
149 enum EObfuscationState {
150 OBST_UNDEFINED = 0,
151 OBST_ENABLED,
152 OBST_SUPPORTED,
153 OBST_NOT_SUPPORTED,
154 OBST_DISABLED
157 // This is fixed on ed2k v1, but can be any number on ED2Kv2
158 #define STANDARD_BLOCKS_REQUEST 3
160 class CUpDownClient : public CECID
162 friend class CClientList;
163 friend class CUpDownClientListRem;
164 private:
166 * Please note that only the ClientList is allowed to delete the clients.
167 * To schedule a client for deletion, call the CClientList::AddToDeleteQueue
168 * funtion, which will safely remove dead clients once every second.
170 ~CUpDownClient();
172 public:
173 #ifdef CLIENT_GUI
174 CUpDownClient(class CEC_UpDownClient_Tag *);
175 #else
176 //base
177 CUpDownClient(CClientTCPSocket* sender = 0);
178 CUpDownClient(uint16 in_port, uint32 in_userid, uint32 in_serverup, uint16 in_serverport,CPartFile* in_reqfile, bool ed2kID, bool checkfriend);
179 #endif
181 * This function should be called when the client object is to be deleted.
182 * It'll close the socket of the client and add it to the deletion queue
183 * owned by the CClientList class. However, if the CUpDownClient isn't on
184 * the normal clientlist, it will be deleted immediatly.
186 * The purpose of this is to avoid clients suddenly being removed due to
187 * asyncronous events, such as socket errors, which can result in the
188 * problems, as each CUpDownClient object is often kept in multiple lists,
189 * and instantly removing the client poses the risk of invalidating
190 * currently used iterators and/or creating dangling pointers.
192 * @see CClientList::AddToDeleteQueue
193 * @see CClientList::Process
195 void Safe_Delete();
198 * Specifies if the client has been queued for deletion.
200 * @return True if Safe_Delete has been called, false otherwise.
202 bool HasBeenDeleted() { return m_clientState == CS_DYING; }
204 ClientState GetClientState() { return m_clientState; }
206 bool Disconnected(const wxString& strReason, bool bFromSocket = false);
207 bool TryToConnect(bool bIgnoreMaxCon = false);
208 bool Connect();
209 void ConnectionEstablished();
210 const wxString& GetUserName() const { return m_Username; }
211 //Only use this when you know the real IP or when your clearing it.
212 void SetIP( uint32 val );
213 uint32 GetIP() const { return m_dwUserIP; }
214 bool HasLowID() const { return IsLowID(m_nUserIDHybrid); }
215 wxString GetFullIP() const { return Uint32toStringIP(m_FullUserIP); }
216 uint32 GetConnectIP() const { return m_nConnectIP; }
217 uint32 GetUserIDHybrid() const { return m_nUserIDHybrid; }
218 void SetUserIDHybrid(uint32 val);
219 uint16_t GetUserPort() const { return m_nUserPort; }
220 void SetUserPort(uint16_t port) { m_nUserPort = port; }
221 uint64 GetTransferredDown() const { return m_nTransferredDown; }
222 uint32 GetServerIP() const { return m_dwServerIP; }
223 void SetServerIP(uint32 nIP) { m_dwServerIP = nIP; }
224 uint16 GetServerPort() const { return m_nServerPort; }
225 void SetServerPort(uint16 nPort) { m_nServerPort = nPort; }
226 const CMD4Hash& GetUserHash() const { return m_UserHash; }
227 void SetUserHash(const CMD4Hash& userhash);
228 void ValidateHash() { m_HasValidHash = !m_UserHash.IsEmpty(); }
229 bool HasValidHash() const { return m_HasValidHash; }
230 uint32 GetVersion() const { return m_nClientVersion;}
231 uint8 GetMuleVersion() const { return m_byEmuleVersion;}
232 bool ExtProtocolAvailable() const { return m_bEmuleProtocol;}
233 bool IsEmuleClient() const { return (m_byEmuleVersion > 0);}
234 bool IsBanned() const;
235 const wxString& GetClientFilename() const { return m_clientFilename; }
236 uint16 GetUDPPort() const { return m_nUDPPort; }
237 void SetUDPPort(uint16 nPort) { m_nUDPPort = nPort; }
238 uint8 GetUDPVersion() const { return m_byUDPVer; }
239 uint8 GetExtendedRequestsVersion() const { return m_byExtendedRequestsVer; }
240 bool IsFriend() const { return m_Friend != NULL; }
241 bool IsML() const { return m_bIsML; }
242 bool IsHybrid() const { return m_bIsHybrid; }
243 uint32 GetCompatibleClient() const { return m_byCompatibleClient; }
245 void ClearDownloadBlockRequests();
246 void RequestSharedFileList();
247 void ProcessSharedFileList(const byte* pachPacket, uint32 nSize, wxString& pszDirectory);
249 wxString GetUploadFileInfo();
251 void SetUserName(const wxString& NewName) { m_Username = NewName; }
253 uint8 GetClientSoft() const { return m_clientSoft; }
254 void ReGetClientSoft();
255 bool ProcessHelloAnswer(const byte* pachPacket, uint32 nSize);
256 bool ProcessHelloPacket(const byte* pachPacket, uint32 nSize);
257 void SendHelloAnswer();
258 bool SendHelloPacket();
259 void SendMuleInfoPacket(bool bAnswer, bool OSInfo = false);
260 bool ProcessMuleInfoPacket(const byte* pachPacket, uint32 nSize);
261 void ProcessMuleCommentPacket(const byte* pachPacket, uint32 nSize);
262 bool Compare(const CUpDownClient* tocomp, bool bIgnoreUserhash = false) const;
263 void SetLastSrcReqTime() { m_dwLastSourceRequest = ::GetTickCount(); }
264 void SetLastSrcAnswerTime() { m_dwLastSourceAnswer = ::GetTickCount(); }
265 void SetLastAskedForSources() { m_dwLastAskedForSources = ::GetTickCount(); }
266 uint32 GetLastSrcReqTime() const { return m_dwLastSourceRequest; }
267 uint32 GetLastSrcAnswerTime() const { return m_dwLastSourceAnswer; }
268 uint32 GetLastAskedForSources() const { return m_dwLastAskedForSources; }
269 bool GetFriendSlot() const { return m_bFriendSlot; }
270 void SetFriendSlot(bool bNV) { m_bFriendSlot = bNV; }
271 void SetCommentDirty(bool bDirty = true) { m_bCommentDirty = bDirty; }
272 uint8 GetSourceExchange1Version() const { return m_bySourceExchange1Ver; }
273 bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2; }
275 bool SafeSendPacket(CPacket* packet);
277 void ProcessRequestPartsPacket(const byte* pachPacket, uint32 nSize, bool largeblocks);
278 void ProcessRequestPartsPacketv2(const CMemFile& data);
280 void SendPublicKeyPacket();
281 void SendSignaturePacket();
282 void ProcessPublicKeyPacket(const byte* pachPacket, uint32 nSize);
283 void ProcessSignaturePacket(const byte* pachPacket, uint32 nSize);
284 uint8 GetSecureIdentState();
286 void SendSecIdentStatePacket();
287 void ProcessSecIdentStatePacket(const byte* pachPacket, uint32 nSize);
289 uint8 GetInfoPacketsReceived() const { return m_byInfopacketsReceived; }
290 void InfoPacketsReceived();
292 //upload
293 uint8 GetUploadState() const { return m_nUploadState; }
294 void SetUploadState(uint8 news);
295 uint32 GetTransferredUp() const { return m_nTransferredUp; }
296 uint32 GetSessionUp() const { return m_nTransferredUp - m_nCurSessionUp; }
297 void ResetSessionUp();
298 uint32 GetUploadDatarate() const { return m_nUpDatarate; }
300 #ifndef CLIENT_GUI
301 //uint32 GetWaitTime() const { return m_dwUploadTime - GetWaitStartTime(); }
302 uint32 GetUpStartTimeDelay() const { return ::GetTickCount() - m_dwUploadTime; }
303 uint32 GetWaitStartTime() const;
304 #else
305 //uint32 m_WaitTime, m_UpStartTimeDelay, m_WaitStartTime;
306 //uint32 GetWaitTime() const { return m_WaitTime; }
307 //uint32 GetUpStartTimeDelay() const { return m_UpStartTimeDelay; }
308 //uint32 GetWaitStartTime() const { return m_WaitStartTime; }
309 #endif
311 bool IsDownloading() const { return (m_nUploadState == US_UPLOADING); }
313 #ifndef CLIENT_GUI
314 uint32 GetScore(
315 bool sysvalue,
316 bool isdownloading = false,
317 bool onlybasevalue = false) const;
318 uint32 GetRating() const { return GetScore(false, IsDownloading(), true); }
319 uint8 GetObfuscationStatus() const;
320 uint16 GetUploadQueueWaitingPosition() const;
321 uint16 GetNextRequestedPart() const;
322 #else
323 uint32 m_score;
324 uint32 GetScore(
325 bool WXUNUSED(sysvalue),
326 bool WXUNUSED(isdownloading) = false,
327 bool onlybasevalue = false) const
329 return onlybasevalue ? m_rating : m_score;
331 uint16 m_waitingPosition;
332 uint16 GetUploadQueueWaitingPosition() const { return m_waitingPosition; }
333 uint32 m_rating;
334 uint32 GetRating() const { return m_rating; }
335 EIdentState m_identState;
336 uint8 GetObfuscationStatus() const { return m_obfuscationStatus; }
337 uint8 m_obfuscationStatus;
338 uint16 m_nextRequestedPart;
339 uint16 GetNextRequestedPart() const { return m_nextRequestedPart; }
340 #endif
342 void AddReqBlock(Requested_Block_Struct* reqblock);
343 void CreateNextBlockPackage();
344 void SetUpStartTime() { m_dwUploadTime = ::GetTickCount(); }
345 void SetWaitStartTime();
346 void ClearWaitStartTime();
347 void SendHashsetPacket(const CMD4Hash& forfileid);
348 bool SupportMultiPacket() const { return m_bMultiPacket; }
349 bool SupportExtMultiPacket() const { return m_fExtMultiPacket; }
351 void SetUploadFileID(CKnownFile *newreqfile);
354 *Gets the file actually on upload
357 const CKnownFile* GetUploadFile() const { return m_uploadingfile; }
359 void SendOutOfPartReqsAndAddToWaitingQueue();
360 void ProcessExtendedInfo(const CMemFile *data, CKnownFile *tempreqfile);
361 void ProcessFileInfo(const CMemFile* data, const CPartFile* file);
362 void ProcessFileStatus(bool bUdpPacket, const CMemFile* data, const CPartFile* file);
364 const CMD4Hash& GetUploadFileID() const { return m_requpfileid; }
365 void SetUploadFileID(const CMD4Hash& new_id);
366 void ClearUploadFileID() { m_requpfileid.Clear(); m_uploadingfile = NULL;};
367 uint32 SendBlockData();
368 void ClearUploadBlockRequests();
369 #ifndef CLIENT_GUI
370 uint16 GetRankingInfo() const;
371 #else
372 uint16 m_rankingInfo;
373 uint16 GetRankingInfo() const { return m_rankingInfo; }
374 #endif
375 void SendRankingInfo();
376 void SendCommentInfo(CKnownFile *file);
377 bool IsDifferentPartBlock() const;
378 void UnBan();
379 void Ban();
380 bool m_bAddNextConnect; // VQB Fix for LowID slots only on connection
381 uint32 GetAskedCount() const { return m_cAsked; }
382 void AddAskedCount() { m_cAsked++; }
383 void ClearAskedCount() { m_cAsked = 1; } // 1, because it's cleared *after* the first request...
384 void FlushSendBlocks(); // call this when you stop upload,
385 // or the socket might be not able to send
386 void SetLastUpRequest() { m_dwLastUpRequest = ::GetTickCount(); }
387 uint32 GetLastUpRequest() const { return m_dwLastUpRequest; }
388 size_t GetUpPartCount() const { return m_upPartStatus.size(); }
391 //download
392 void SetRequestFile(CPartFile* reqfile);
393 CPartFile* GetRequestFile() const { return m_reqfile; }
395 uint8 GetDownloadState() const { return m_nDownloadState; }
396 void SetDownloadState(uint8 byNewState);
397 uint32 GetLastAskedTime() const { return m_dwLastAskedTime; }
398 void ResetLastAskedTime() { m_dwLastAskedTime = 0; }
400 bool IsPartAvailable(uint16 iPart) const
401 { return ( iPart < m_downPartStatus.size() ) ? m_downPartStatus.get(iPart) : 0; }
402 bool IsUpPartAvailable(uint16 iPart) const
403 { return ( iPart < m_upPartStatus.size() ) ? m_upPartStatus.get(iPart) : 0;}
405 const BitVector& GetPartStatus() const { return m_downPartStatus; }
406 const BitVector& GetUpPartStatus() const { return m_upPartStatus; }
407 float GetKBpsDown() const { return kBpsDown; }
408 float CalculateKBpsDown();
409 uint16 GetRemoteQueueRank() const { return m_nRemoteQueueRank; }
410 uint16 GetOldRemoteQueueRank() const { return m_nOldRemoteQueueRank; }
411 void SetRemoteQueueFull(bool flag) { m_bRemoteQueueFull = flag; }
412 bool IsRemoteQueueFull() const { return m_bRemoteQueueFull; }
413 void SetRemoteQueueRank(uint16 nr);
414 bool AskForDownload();
415 void SendStartupLoadReq();
416 void SendFileRequest();
417 void ProcessHashSet(const byte* packet, uint32 size);
418 bool AddRequestForAnotherFile(CPartFile* file);
419 bool DeleteFileRequest(CPartFile* file);
420 void DeleteAllFileRequests();
421 void SendBlockRequests();
422 void ProcessBlockPacket(const byte* packet, uint32 size, bool packed, bool largeblocks);
424 #ifndef CLIENT_GUI
425 uint16 GetAvailablePartCount() const;
426 #else
427 uint16 m_AvailPartCount;
428 uint16 GetAvailablePartCount() const { return m_AvailPartCount; }
429 #endif
431 bool SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile = NULL);
432 void UDPReaskACK(uint16 nNewQR);
433 void UDPReaskFNF();
434 void UDPReaskForDownload();
435 bool IsSourceRequestAllowed();
436 uint16 GetUpCompleteSourcesCount() const { return m_nUpCompleteSourcesCount; }
437 void SetUpCompleteSourcesCount(uint16 n) { m_nUpCompleteSourcesCount = n; }
439 //chat
440 uint8 GetChatState() { return m_byChatstate; }
441 void SetChatState(uint8 nNewS) { m_byChatstate = nNewS; }
442 EChatCaptchaState GetChatCaptchaState() const { return (EChatCaptchaState)m_nChatCaptchaState; }
443 void ProcessCaptchaRequest(CMemFile* data);
444 void ProcessCaptchaReqRes(uint8 nStatus);
445 void ProcessChatMessage(wxString message);
446 // message filtering
447 uint8 GetMessagesReceived() const { return m_cMessagesReceived; }
448 void IncMessagesReceived() { m_cMessagesReceived < 255 ? ++m_cMessagesReceived : 255; }
449 uint8 GetMessagesSent() const { return m_cMessagesSent; }
450 void IncMessagesSent() { m_cMessagesSent < 255 ? ++m_cMessagesSent : 255; }
451 bool IsSpammer() const { return m_fIsSpammer; }
452 void SetSpammer(bool bVal);
453 bool IsMessageFiltered(const wxString& message);
455 //File Comment
456 const wxString& GetFileComment() const { return m_strComment; }
457 uint8 GetFileRating() const { return m_iRating; }
459 const wxString& GetSoftStr() const { return m_clientSoftString; }
460 const wxString& GetSoftVerStr() const { return m_clientVerString; }
461 #ifndef CLIENT_GUI
462 const wxString GetServerName() const;
463 #else
464 wxString m_ServerName;
465 const wxString& GetServerName() const { return m_ServerName; }
466 #endif
468 uint16 GetKadPort() const { return m_nKadPort; }
469 void SetKadPort(uint16 nPort) { m_nKadPort = nPort; }
471 // Kry - AICH import
472 void SetReqFileAICHHash(CAICHHash* val);
473 CAICHHash* GetReqFileAICHHash() const {return m_pReqFileAICHHash;}
474 bool IsSupportingAICH() const {return m_fSupportsAICH & 0x01;}
475 void SendAICHRequest(CPartFile* pForFile, uint16 nPart);
476 bool IsAICHReqPending() const {return m_fAICHRequested; }
477 void ProcessAICHAnswer(const byte* packet, uint32 size);
478 void ProcessAICHRequest(const byte* packet, uint32 size);
479 void ProcessAICHFileHash(CMemFile* data, const CPartFile* file);
481 EUtf8Str GetUnicodeSupport() const;
483 // Barry - Process zip file as it arrives, don't need to wait until end of block
484 int unzip(Pending_Block_Struct *block, byte *zipped, uint32 lenZipped, byte **unzipped, uint32 *lenUnzipped, int iRecursion = 0);
485 void UpdateDisplayedInfo(bool force = false);
486 int GetFileListRequested() const { return m_iFileListRequested; }
487 void SetFileListRequested(int iFileListRequested) { m_iFileListRequested = iFileListRequested; }
489 void ResetFileStatusInfo();
491 bool CheckHandshakeFinished() const;
493 bool GetSentCancelTransfer() const { return m_fSentCancelTransfer; }
494 void SetSentCancelTransfer(bool bVal) { m_fSentCancelTransfer = bVal; }
496 wxString GetClientFullInfo();
497 wxString GetClientShortInfo();
499 const wxString& GetClientOSInfo() const { return m_sClientOSInfo; }
501 void ProcessPublicIPAnswer(const byte* pbyData, uint32 uSize);
502 void SendPublicIPRequest();
505 * Sets the current socket of the client.
507 * @param socket The pointer to the new socket, can be NULL.
509 * Please note that this function DOES NOT delete the old socket.
511 void SetSocket(CClientTCPSocket* socket);
514 * Function for accessing the socket owned by a client.
516 * @return The pointer (can be NULL) to the socket used by this client.
518 * Please note that the socket object is quite volatile and can be removed
519 * from one function call to the next, therefore, you should normally use
520 * the safer functions below, which all check if the socket is valid before
521 * deferring it.
523 CClientTCPSocket* GetSocket() const { return m_socket; }
526 * Safe function for checking if the socket is connected.
528 * @return True if the socket exists and is connected, false otherwise.
530 #ifndef CLIENT_GUI
531 bool IsConnected() const;
532 #else
533 bool m_IsConnected;
534 bool IsConnected() const { return m_IsConnected; }
535 #endif
538 * Safe function for sending packets.
540 * @return True if the socket exists and the packet was sent, false otherwise.
542 bool SendPacket(CPacket* packet, bool delpacket = true, bool controlpacket = true);
545 * Safe function for setting the download limit of the socket.
547 * @return Current download speed of the client.
549 float SetDownloadLimit(uint32 reducedownload);
552 * Sends a message to a client
554 * @return True if sent, false if connecting
556 bool SendChatMessage(const wxString& message);
558 bool HasBlocks() const { return !m_BlockRequests_queue.empty(); }
560 /* Source comes from? */
561 ESourceFrom GetSourceFrom() const { return (ESourceFrom)m_nSourceFrom; }
562 void SetSourceFrom(ESourceFrom val) { m_nSourceFrom = val; }
564 /* Kad buddy support */
565 // ID
566 const byte* GetBuddyID() const { return m_achBuddyID; }
567 void SetBuddyID(const byte* m_achTempBuddyID);
568 bool HasValidBuddyID() const { return m_bBuddyIDValid; }
569 /* IP */
570 void SetBuddyIP( uint32 val ) { m_nBuddyIP = val; }
571 uint32 GetBuddyIP() const { return m_nBuddyIP; }
572 /* Port */
573 void SetBuddyPort( uint16 val ) { m_nBuddyPort = val; }
574 uint16 GetBuddyPort() const { return m_nBuddyPort; }
576 //KadIPCheck
577 bool SendBuddyPingPong() { return m_dwLastBuddyPingPongTime < ::GetTickCount(); }
578 bool AllowIncomeingBuddyPingPong() { return m_dwLastBuddyPingPongTime < (::GetTickCount()-(3*60*1000)); }
579 void SetLastBuddyPingPongTime() { m_dwLastBuddyPingPongTime = (::GetTickCount()+(10*60*1000)); }
580 EKadState GetKadState() const { return m_nKadState; }
581 void SetKadState(EKadState nNewS) { m_nKadState = nNewS; }
582 uint8 GetKadVersion() { return m_byKadVersion; }
583 void ProcessFirewallCheckUDPRequest(CMemFile *data);
584 // Kad added by me
585 bool SendBuddyPing();
587 /* Returns the client hash type (SO_EMULE, mldonkey, etc) */
588 int GetHashType() const;
591 * Checks that a client isn't aggressively re-asking for files.
593 * Call this when a file is requested. If the time since the last request is
594 * less than MIN_REQUESTTIME, 3 is added to the m_Aggressiveness variable.
595 * If the time since the last request is >= MIN_REQUESTTIME, the variable is
596 * decremented by 1. The client is banned if the variable reaches 10 or above.
598 * To check if a client is aggressive use the IsClientAggressive() function.
600 * Currently this function is called when the following packets are received:
601 * - OP_STARTUPLOADREQ
602 * - OP_REASKFILEPING
604 void CheckForAggressive();
606 const wxString& GetClientModString() const { return m_strModVersion; }
608 const wxString& GetClientVerString() const { return m_fullClientVerString; }
610 const wxString& GetVersionString() const { return m_clientVersionString; }
612 void UpdateStats();
614 /* Returns a pointer to the credits, only for hash purposes */
615 void* GetCreditsHash() const { return (void*)credits; }
617 uint16 GetLastDownloadingPart() const { return m_lastDownloadingPart; }
619 bool GetOSInfoSupport() const { return m_fOsInfoSupport; }
621 bool GetVBTTags() const { return m_fValueBasedTypeTags; }
623 uint16 GetLastPartAsked() const { return m_lastPartAsked; }
625 void SetLastPartAsked(uint16 nPart) { m_lastPartAsked = nPart; }
627 CFriend* GetFriend() const { return m_Friend; }
629 void SetFriend(CFriend* newfriend) { m_Friend = newfriend; }
631 bool IsIdentified() const;
633 bool IsBadGuy() const;
635 bool SUIFailed() const;
637 bool SUINeeded() const;
639 bool SUINotSupported() const;
641 uint64 GetDownloadedTotal() const;
643 uint64 GetUploadedTotal() const;
645 double GetScoreRatio() const;
647 uint32 GetCreationTime() const { return m_nCreationTime; }
649 bool SupportsLargeFiles() const { return m_fSupportsLargeFiles; }
651 EIdentState GetCurrentIdentState() const { return credits ? credits->GetCurrentIdentState(GetIP()) : IS_NOTAVAILABLE; }
653 #ifdef __DEBUG__
654 /* Kry - Debug. See connection_reason definition comment below */
655 void SetConnectionReason(const wxString& reason) { connection_reason = reason; }
656 #endif
658 // Encryption / Obfuscation / ConnectOptions
659 bool SupportsCryptLayer() const { return m_fSupportsCryptLayer; }
660 bool RequestsCryptLayer() const { return SupportsCryptLayer() && m_fRequestsCryptLayer; }
661 bool RequiresCryptLayer() const { return RequestsCryptLayer() && m_fRequiresCryptLayer; }
662 bool SupportsDirectUDPCallback() const { return m_fDirectUDPCallback != 0 && HasValidHash() && GetKadPort() != 0; }
663 uint32_t GetDirectCallbackTimeout() const { return m_dwDirectCallbackTimeout; }
664 bool HasObfuscatedConnectionBeenEstablished() const { return m_hasbeenobfuscatinglately; }
666 void SetCryptLayerSupport(bool bVal) { m_fSupportsCryptLayer = bVal ? 1 : 0; }
667 void SetCryptLayerRequest(bool bVal) { m_fRequestsCryptLayer = bVal ? 1 : 0; }
668 void SetCryptLayerRequires(bool bVal) { m_fRequiresCryptLayer = bVal ? 1 : 0; }
669 void SetDirectUDPCallbackSupport(bool bVal) { m_fDirectUDPCallback = bVal ? 1 : 0; }
670 void SetConnectOptions(uint8_t options, bool encryption = true, bool callback = true); // shortcut, sets crypt, callback, etc from the tagvalue we receive
671 bool ShouldReceiveCryptUDPPackets() const;
673 bool HasDisabledSharedFiles() const { return m_fNoViewSharedFiles; }
675 private:
677 CClientCredits *credits;
678 CFriend *m_Friend;
680 uint64 m_nTransferredUp;
681 sint64 m_nCurQueueSessionPayloadUp;
682 sint64 m_addedPayloadQueueSession;
684 struct TransferredData {
685 uint32 datalen;
686 uint32 timestamp;
689 //////////////////////////////////////////////////////////
690 // Upload data rate computation
692 uint32 m_nUpDatarate;
693 uint32 m_nSumForAvgUpDataRate;
694 std::list<TransferredData> m_AvarageUDR_list;
698 * This struct is used to keep track of CPartFiles which this source shares.
700 struct A4AFStamp {
701 //! Signifies if this sources has needed parts for this file.
702 bool NeededParts;
703 //! This is set when we wish to avoid swapping to this file for a while.
704 uint32 timestamp;
707 //! I typedef in the name of readability!
708 typedef std::map<CPartFile*, A4AFStamp> A4AFList;
709 //! This list contains all PartFiles which this client can be used as a source for.
710 A4AFList m_A4AF_list;
713 * Helper function used by SwapToAnotherFile().
715 * @param it The iterator of the PartFile to be examined.
716 * @param ignorenoneeded Do not check for the status NoNeededParts when checking the file.
717 * @param ignoresuspended Do not check the timestamp when checking the file.
718 * @return True if the file is a viable target, false otherwise.
720 * This function is used to perform checks to see if we should consider
721 * this file a viable target for A4AF swapping. Unless ignoresuspended is
722 * true, it will examine the timestamp of the file and reset it if needed.
724 bool IsValidSwapTarget( A4AFList::iterator it, bool ignorenoneeded = false, bool ignoresuspended = false );
726 CPartFile* m_reqfile;
728 // base
729 void Init();
730 bool ProcessHelloTypePacket(const CMemFile& data);
731 void SendHelloTypePacket(CMemFile* data);
732 void SendFirewallCheckUDPRequest();
733 void ClearHelloProperties(); // eMule 0.42
735 uint32 m_dwUserIP;
736 uint32 m_nConnectIP; // holds the supposed IP or (after we had a connection) the real IP
737 uint32 m_dwServerIP;
738 uint32 m_nUserIDHybrid;
739 uint16_t m_nUserPort;
740 int16 m_nServerPort;
741 uint32 m_nClientVersion;
742 uint32 m_cSendblock;
743 uint8 m_byEmuleVersion;
744 uint8 m_byDataCompVer;
745 bool m_bEmuleProtocol;
746 wxString m_Username;
747 uint32 m_FullUserIP;
748 CMD4Hash m_UserHash;
749 bool m_HasValidHash;
750 uint16 m_nUDPPort;
751 uint8 m_byUDPVer;
752 uint8 m_bySourceExchange1Ver;
753 uint8 m_byAcceptCommentVer;
754 uint8 m_byExtendedRequestsVer;
755 uint8 m_clientSoft;
756 uint32 m_dwLastSourceRequest;
757 uint32 m_dwLastSourceAnswer;
758 uint32 m_dwLastAskedForSources;
759 int m_iFileListRequested;
760 bool m_bFriendSlot;
761 bool m_bCommentDirty;
762 bool m_bIsHybrid;
763 bool m_bIsML;
764 bool m_bSupportsPreview;
765 bool m_bUnicodeSupport;
766 uint16 m_nKadPort;
767 bool m_bMultiPacket;
768 ClientState m_clientState;
769 CClientTCPSocket* m_socket;
770 bool m_fNeedOurPublicIP; // we requested our IP from this client
772 // Kry - Secure User Ident import
773 ESecureIdentState m_SecureIdentState;
774 uint8 m_byInfopacketsReceived; // have we received the edonkeyprot and emuleprot packet already (see InfoPacketsReceived() )
775 uint32 m_dwLastSignatureIP;
776 uint8 m_bySupportSecIdent;
778 uint32 m_byCompatibleClient;
779 std::list<CPacket*> m_WaitingPackets_list;
780 uint32 m_lastRefreshedDLDisplay;
782 //upload
783 void CreateStandardPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
784 void CreatePackedPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
786 uint8 m_nUploadState;
787 uint32 m_dwUploadTime;
788 uint32 m_cAsked;
789 uint32 m_dwLastUpRequest;
790 uint32 m_nCurSessionUp;
791 uint16 m_nUpPartCount;
792 CMD4Hash m_requpfileid;
793 uint16 m_nUpCompleteSourcesCount;
795 //! This vector contains the avilability of parts for the file that the user
796 //! is requesting. When changing it, be sure to call CKnownFile::UpdatePartsFrequency
797 //! so that the files know the actual availability of parts.
798 BitVector m_upPartStatus;
799 uint16 m_lastPartAsked;
800 wxString m_strModVersion;
802 std::list<Requested_Block_Struct*> m_BlockRequests_queue;
803 std::list<Requested_Block_Struct*> m_DoneBlocks_list;
805 //download
806 bool m_bRemoteQueueFull;
807 uint8 m_nDownloadState;
808 uint16 m_nPartCount;
809 uint32 m_dwLastAskedTime;
810 wxString m_clientFilename;
811 uint64 m_nTransferredDown;
812 uint16 m_lastDownloadingPart; // last Part that was downloading
813 uint16 m_cShowDR;
814 uint32 m_dwLastBlockReceived;
815 uint16 m_nRemoteQueueRank;
816 uint16 m_nOldRemoteQueueRank;
817 bool m_bCompleteSource;
818 bool m_bReaskPending;
819 bool m_bUDPPending;
820 bool m_bHashsetRequested;
822 std::list<Pending_Block_Struct*> m_PendingBlocks_list;
823 std::list<Requested_Block_Struct*> m_DownloadBlocks_list;
825 // download speed calculation
826 float kBpsDown;
827 uint32 msReceivedPrev;
828 uint32 bytesReceivedCycle;
829 // chat
830 wxString m_strComment;
831 uint8 m_byChatstate;
832 uint8 m_nChatCaptchaState;
833 uint8 m_cCaptchasSent;
834 int8 m_iRating;
835 uint8 m_cMessagesReceived; // count of chatmessages he sent to me
836 uint8 m_cMessagesSent; // count of chatmessages I sent to him
837 wxString m_strCaptchaChallenge;
838 wxString m_strCaptchaPendingMsg;
840 unsigned int
841 m_fHashsetRequesting : 1, // we have sent a hashset request to this client
842 m_fNoViewSharedFiles : 1, // client has disabled the 'View Shared Files' feature,
843 // if this flag is not set, we just know that we don't know
844 // for sure if it is enabled
845 m_fSupportsPreview : 1,
846 m_fIsSpammer : 1,
847 m_fSentCancelTransfer: 1, // we have sent an OP_CANCELTRANSFER in the current connection
848 m_fSharedDirectories : 1, // client supports OP_ASKSHAREDIRS opcodes
849 m_fSupportsAICH : 3,
850 m_fAICHRequested : 1,
851 m_fSupportsLargeFiles: 1,
852 m_fSentOutOfPartReqs : 1,
853 m_fExtMultiPacket : 1,
854 m_fRequestsCryptLayer: 1,
855 m_fSupportsCryptLayer: 1,
856 m_fRequiresCryptLayer: 1,
857 m_fSupportsSourceEx2 : 1,
858 m_fSupportsCaptcha : 1,
859 m_fDirectUDPCallback : 1;
861 unsigned int
862 m_fOsInfoSupport : 1,
863 m_fValueBasedTypeTags : 1;
865 /* Razor 1a - Modif by MikaelB */
867 bool m_bHelloAnswerPending;
869 //! This vector contains the avilability of parts for the file we requested
870 //! from this user. When changing it, be sure to call CPartFile::UpdatePartsFrequency
871 //! so that the files know the actual availability of parts.
872 BitVector m_downPartStatus;
874 CAICHHash* m_pReqFileAICHHash;
876 ESourceFrom m_nSourceFrom;
878 /* Kad Stuff */
879 byte m_achBuddyID[16];
880 bool m_bBuddyIDValid;
881 uint32 m_nBuddyIP;
882 uint16 m_nBuddyPort;
884 EKadState m_nKadState;
886 uint8 m_byKadVersion;
887 uint32 m_dwLastBuddyPingPongTime;
888 uint32_t m_dwDirectCallbackTimeout;
890 //! This keeps track of aggressive requests for files.
891 uint16 m_Aggressiveness;
892 //! This tracks the time of the last time since a file was requested
893 uint32 m_LastFileRequest;
895 bool m_OSInfo_sent;
897 wxString m_clientSoftString; /* software name */
898 wxString m_clientVerString; /* version + optional mod name */
899 wxString m_clientVersionString; /* version string */
900 wxString m_fullClientVerString; /* full info string */
901 wxString m_sClientOSInfo;
902 wxString m_pendingMessage;
904 int SecIdentSupRec;
906 CKnownFile* m_uploadingfile;
908 uint8 m_MaxBlockRequests;
910 // needed for stats
911 uint32 m_lastClientSoft;
912 uint32 m_lastClientVersion;
913 wxString m_lastOSInfo;
915 /* For buddies timeout */
916 uint32 m_nCreationTime;
918 /* Calculation of last average speed */
919 uint32 m_lastaverage;
920 uint32 m_last_block_start;
922 /* Save the encryption status for display when disconnected */
923 bool m_hasbeenobfuscatinglately;
925 /* Kry - Debug thing. Clients created just to check their data
926 have this string set to the reason we want to check them.
927 Obviously, once checked, we disconnect them. Take that, sucker.
928 This debug code is just for me I'm afraid. */
929 #ifdef __DEBUG__
930 wxString connection_reason;
931 #endif
935 #define MAKE_CLIENT_VERSION(mjr, min, upd) \
936 ((uint32)(mjr)*100U*10U*100U + (uint32)(min)*100U*10U + (uint32)(upd)*100U)
939 #endif // UPDOWNCLIENT_H
940 // File_checked_for_headers