Improve speed of category tab title updates
[amule.git] / src / updownclient.h
blobf48b105b7987454cb138c28b73fbd131e5d1bc51
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 "Constants.h" // Needed for ESourceFrom
30 #include "GetTickCount.h" // Needed for GetTickCount
31 #include "MD4Hash.h"
32 #include <common/StringFunctions.h>
33 #include "NetworkFunctions.h"
34 #include "OtherStructs.h"
35 #include "ClientCredits.h" // Needed for EIdentState
36 #include <ec/cpp/ECID.h> // Needed for CECID
37 #include "BitVector.h" // Needed for BitVector
38 #include "ClientRef.h" // Needed for debug defines
40 #include <map>
43 class CPartFile;
44 class CClientTCPSocket;
45 class CPacket;
46 class CFriend;
47 class CKnownFile;
48 class CMemFile;
49 class CAICHHash;
52 enum EChatCaptchaState {
53 CA_NONE = 0,
54 CA_CHALLENGESENT,
55 CA_CAPTCHASOLVED,
56 CA_ACCEPTING,
57 CA_CAPTCHARECV,
58 CA_SOLUTIONSENT
61 enum ESecureIdentState {
62 IS_UNAVAILABLE = 0,
63 IS_ALLREQUESTSSEND = 0,
64 IS_SIGNATURENEEDED = 1,
65 IS_KEYANDSIGNEEDED = 2
68 enum EInfoPacketState {
69 IP_NONE = 0,
70 IP_EDONKEYPROTPACK = 1,
71 IP_EMULEPROTPACK = 2,
72 IP_BOTH = 3
75 enum EKadState {
76 KS_NONE,
77 KS_QUEUED_FWCHECK,
78 KS_CONNECTING_FWCHECK,
79 KS_CONNECTED_FWCHECK,
80 KS_QUEUED_BUDDY,
81 KS_INCOMING_BUDDY,
82 KS_CONNECTING_BUDDY,
83 KS_CONNECTED_BUDDY,
84 KS_QUEUED_FWCHECK_UDP,
85 KS_FWCHECK_UDP,
86 KS_CONNECTING_FWCHECK_UDP
89 //! Used to keep track of the state of the client
90 enum ClientState
92 //! New is for clients that have just been created.
93 CS_NEW = 0,
94 //! Listed is for clients that are on the clientlist
95 CS_LISTED,
96 //! Dying signifies clients that have been queued for deletion
97 CS_DYING
100 // This is fixed on ed2k v1, but can be any number on ED2Kv2
101 #define STANDARD_BLOCKS_REQUEST 3
103 class CUpDownClient : public CECID
105 friend class CClientList;
106 friend class CClientRef;
107 private:
109 * Please note that only the ClientList is allowed to delete the clients.
110 * To schedule a client for deletion, call the CClientList::AddToDeleteQueue
111 * funtion, which will safely remove dead clients once every second.
113 ~CUpDownClient();
116 * Reference count which is increased whenever client is linked to a clientref.
117 * Clients are to be stored only by ClientRefs, CUpDownClient * are for temporary
118 * use only.
119 * Linking is done only by CClientRef which is friend, so methods are private.
121 uint16 m_linked;
122 #ifdef DEBUG_ZOMBIE_CLIENTS
123 bool m_linkedDebug;
124 std::multiset<wxString> m_linkedFrom;
125 void Link(const wxString& from) { m_linked++; m_linkedFrom.insert(from); }
126 void Unlink(const wxString& from);
127 wxString GetLinkedFrom() {
128 wxString ret;
129 for (std::multiset<wxString>::iterator it = m_linkedFrom.begin(); it != m_linkedFrom.end(); it++) {
130 ret += *it + wxT(", ");
132 return ret;
134 #else
135 void Link() { m_linked++; }
136 void Unlink();
137 #endif
139 public:
140 //base
141 CUpDownClient(CClientTCPSocket* sender = 0);
142 CUpDownClient(uint16 in_port, uint32 in_userid, uint32 in_serverup, uint16 in_serverport,CPartFile* in_reqfile, bool ed2kID, bool checkfriend);
145 * This function is to be called when the client object is to be deleted.
146 * It'll close the socket of the client and remove it from various lists
147 * that can own it.
149 * The client will really be deleted only after thelast reference to it
150 * is unlinked;
152 void Safe_Delete();
155 * Specifies if the client has been queued for deletion.
157 * @return True if Safe_Delete has been called, false otherwise.
159 bool HasBeenDeleted() { return m_clientState == CS_DYING; }
161 ClientState GetClientState() { return m_clientState; }
163 bool Disconnected(const wxString& strReason, bool bFromSocket = false);
164 bool TryToConnect(bool bIgnoreMaxCon = false);
165 bool Connect();
166 void ConnectionEstablished();
167 const wxString& GetUserName() const { return m_Username; }
168 //Only use this when you know the real IP or when your clearing it.
169 void SetIP( uint32 val );
170 uint32 GetIP() const { return m_dwUserIP; }
171 bool HasLowID() const { return IsLowID(m_nUserIDHybrid); }
172 wxString GetFullIP() const { return Uint32toStringIP(m_FullUserIP); }
173 uint32 GetConnectIP() const { return m_nConnectIP; }
174 uint32 GetUserIDHybrid() const { return m_nUserIDHybrid; }
175 void SetUserIDHybrid(uint32 val);
176 uint16_t GetUserPort() const { return m_nUserPort; }
177 void SetUserPort(uint16_t port) { m_nUserPort = port; }
178 uint64 GetTransferredDown() const { return m_nTransferredDown; }
179 uint32 GetServerIP() const { return m_dwServerIP; }
180 void SetServerIP(uint32 nIP) { m_dwServerIP = nIP; }
181 uint16 GetServerPort() const { return m_nServerPort; }
182 void SetServerPort(uint16 nPort) { m_nServerPort = nPort; }
183 const CMD4Hash& GetUserHash() const { return m_UserHash; }
184 void SetUserHash(const CMD4Hash& userhash);
185 void ValidateHash() { m_HasValidHash = !m_UserHash.IsEmpty(); }
186 bool HasValidHash() const { return m_HasValidHash; }
187 uint32 GetVersion() const { return m_nClientVersion;}
188 uint8 GetMuleVersion() const { return m_byEmuleVersion;}
189 bool ExtProtocolAvailable() const { return m_bEmuleProtocol;}
190 bool IsEmuleClient() const { return (m_byEmuleVersion > 0);}
191 bool IsBanned() const;
192 const wxString& GetClientFilename() const { return m_clientFilename; }
193 uint16 GetUDPPort() const { return m_nUDPPort; }
194 void SetUDPPort(uint16 nPort) { m_nUDPPort = nPort; }
195 uint8 GetUDPVersion() const { return m_byUDPVer; }
196 uint8 GetExtendedRequestsVersion() const { return m_byExtendedRequestsVer; }
197 bool IsFriend() const { return m_Friend != NULL; }
198 bool IsML() const { return m_bIsML; }
199 bool IsHybrid() const { return m_bIsHybrid; }
200 uint32 GetCompatibleClient() const { return m_byCompatibleClient; }
202 void ClearDownloadBlockRequests();
203 void RequestSharedFileList();
204 void ProcessSharedFileList(const byte* pachPacket, uint32 nSize, wxString& pszDirectory);
206 wxString GetUploadFileInfo();
208 void SetUserName(const wxString& NewName) { m_Username = NewName; }
210 uint8 GetClientSoft() const { return m_clientSoft; }
211 void ReGetClientSoft();
212 bool ProcessHelloAnswer(const byte* pachPacket, uint32 nSize);
213 bool ProcessHelloPacket(const byte* pachPacket, uint32 nSize);
214 void SendHelloAnswer();
215 bool SendHelloPacket();
216 void SendMuleInfoPacket(bool bAnswer, bool OSInfo = false);
217 bool ProcessMuleInfoPacket(const byte* pachPacket, uint32 nSize);
218 void ProcessMuleCommentPacket(const byte* pachPacket, uint32 nSize);
219 bool Compare(const CUpDownClient* tocomp, bool bIgnoreUserhash = false) const;
220 void SetLastSrcReqTime() { m_dwLastSourceRequest = ::GetTickCount(); }
221 void SetLastSrcAnswerTime() { m_dwLastSourceAnswer = ::GetTickCount(); }
222 void SetLastAskedForSources() { m_dwLastAskedForSources = ::GetTickCount(); }
223 uint32 GetLastSrcReqTime() const { return m_dwLastSourceRequest; }
224 uint32 GetLastSrcAnswerTime() const { return m_dwLastSourceAnswer; }
225 uint32 GetLastAskedForSources() const { return m_dwLastAskedForSources; }
226 bool GetFriendSlot() const { return m_bFriendSlot; }
227 void SetFriendSlot(bool bNV) { m_bFriendSlot = bNV; }
228 void SetCommentDirty(bool bDirty = true) { m_bCommentDirty = bDirty; }
229 uint8 GetSourceExchange1Version() const { return m_bySourceExchange1Ver; }
230 bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2; }
232 bool SafeSendPacket(CPacket* packet);
234 void ProcessRequestPartsPacket(const byte* pachPacket, uint32 nSize, bool largeblocks);
235 void ProcessRequestPartsPacketv2(const CMemFile& data);
237 void SendPublicKeyPacket();
238 void SendSignaturePacket();
239 void ProcessPublicKeyPacket(const byte* pachPacket, uint32 nSize);
240 void ProcessSignaturePacket(const byte* pachPacket, uint32 nSize);
241 uint8 GetSecureIdentState();
243 void SendSecIdentStatePacket();
244 void ProcessSecIdentStatePacket(const byte* pachPacket, uint32 nSize);
246 uint8 GetInfoPacketsReceived() const { return m_byInfopacketsReceived; }
247 void InfoPacketsReceived();
249 //upload
250 uint8 GetUploadState() const { return m_nUploadState; }
251 void SetUploadState(uint8 news);
252 uint64 GetTransferredUp() const { return m_nTransferredUp; }
253 uint64 GetSessionUp() const { return m_nTransferredUp - m_nCurSessionUp; }
254 void ResetSessionUp();
255 uint32 GetUploadDatarate() const { return m_nUpDatarate; }
257 //uint32 GetWaitTime() const { return m_dwUploadTime - GetWaitStartTime(); }
258 uint32 GetUpStartTimeDelay() const { return ::GetTickCount() - m_dwUploadTime; }
259 uint32 GetWaitStartTime() const;
261 bool IsDownloading() const { return (m_nUploadState == US_UPLOADING); }
263 uint32 GetScore() const { return m_score; }
264 uint32 CalculateScore() { m_score = CalculateScoreInternal(); return m_score; }
265 void ClearScore() { m_score = 0; }
266 uint16 GetUploadQueueWaitingPosition() const { return m_waitingPosition; }
267 void SetUploadQueueWaitingPosition(uint16 pos) { m_waitingPosition = pos; }
268 uint8 GetObfuscationStatus() const;
269 uint16 GetNextRequestedPart() const;
271 void AddReqBlock(Requested_Block_Struct* reqblock);
272 void CreateNextBlockPackage();
273 void SetUpStartTime() { m_dwUploadTime = ::GetTickCount(); }
274 void SetWaitStartTime();
275 void ClearWaitStartTime();
276 void SendHashsetPacket(const CMD4Hash& forfileid);
277 bool SupportMultiPacket() const { return m_bMultiPacket; }
278 bool SupportExtMultiPacket() const { return m_fExtMultiPacket; }
280 void SetUploadFileID(CKnownFile *newreqfile);
283 *Gets the file actually on upload
286 const CKnownFile* GetUploadFile() const { return m_uploadingfile; }
288 void SendOutOfPartReqsAndAddToWaitingQueue();
289 void ProcessExtendedInfo(const CMemFile *data, CKnownFile *tempreqfile);
290 void ProcessFileInfo(const CMemFile* data, const CPartFile* file);
291 void ProcessFileStatus(bool bUdpPacket, const CMemFile* data, const CPartFile* file);
293 const CMD4Hash& GetUploadFileID() const { return m_requpfileid; }
294 void SetUploadFileID(const CMD4Hash& new_id);
295 void ClearUploadFileID() { m_requpfileid.Clear(); m_uploadingfile = NULL;}
296 uint32 SendBlockData();
297 void ClearUploadBlockRequests();
298 void SendRankingInfo();
299 void SendCommentInfo(CKnownFile *file);
300 bool IsDifferentPartBlock() const;
301 void UnBan();
302 void Ban();
303 bool m_bAddNextConnect; // VQB Fix for LowID slots only on connection
304 uint32 GetAskedCount() const { return m_cAsked; }
305 void AddAskedCount() { m_cAsked++; }
306 void ClearAskedCount() { m_cAsked = 1; } // 1, because it's cleared *after* the first request...
307 void FlushSendBlocks(); // call this when you stop upload,
308 // or the socket might be not able to send
309 void SetLastUpRequest() { m_dwLastUpRequest = ::GetTickCount(); }
310 uint32 GetLastUpRequest() const { return m_dwLastUpRequest; }
311 size_t GetUpPartCount() const { return m_upPartStatus.size(); }
314 //download
315 void SetRequestFile(CPartFile* reqfile);
316 CPartFile* GetRequestFile() const { return m_reqfile; }
318 uint8 GetDownloadState() const { return m_nDownloadState; }
319 void SetDownloadState(uint8 byNewState);
320 uint32 GetLastAskedTime() const { return m_dwLastAskedTime; }
321 void ResetLastAskedTime() { m_dwLastAskedTime = 0; }
323 bool IsPartAvailable(uint16 iPart) const
324 { return ( iPart < m_downPartStatus.size() ) ? m_downPartStatus.get(iPart) : 0; }
325 bool IsUpPartAvailable(uint16 iPart) const
326 { return ( iPart < m_upPartStatus.size() ) ? m_upPartStatus.get(iPart) : 0;}
328 const BitVector& GetPartStatus() const { return m_downPartStatus; }
329 const BitVector& GetUpPartStatus() const { return m_upPartStatus; }
330 float GetKBpsDown() const { return kBpsDown; }
331 float CalculateKBpsDown();
332 uint16 GetRemoteQueueRank() const { return m_nRemoteQueueRank; }
333 uint16 GetOldRemoteQueueRank() const { return m_nOldRemoteQueueRank; }
334 void SetRemoteQueueFull(bool flag) { m_bRemoteQueueFull = flag; }
335 bool IsRemoteQueueFull() const { return m_bRemoteQueueFull; }
336 void SetRemoteQueueRank(uint16 nr);
337 bool AskForDownload();
338 void SendStartupLoadReq();
339 void SendFileRequest();
340 void ProcessHashSet(const byte* packet, uint32 size);
341 bool AddRequestForAnotherFile(CPartFile* file);
342 bool DeleteFileRequest(CPartFile* file);
343 void DeleteAllFileRequests();
344 void SendBlockRequests();
345 void ProcessBlockPacket(const byte* packet, uint32 size, bool packed, bool largeblocks);
346 uint16 GetAvailablePartCount() const;
348 bool SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile = NULL);
349 void UDPReaskACK(uint16 nNewQR);
350 void UDPReaskFNF();
351 void UDPReaskForDownload();
352 bool IsSourceRequestAllowed();
353 uint16 GetUpCompleteSourcesCount() const { return m_nUpCompleteSourcesCount; }
354 void SetUpCompleteSourcesCount(uint16 n) { m_nUpCompleteSourcesCount = n; }
356 //chat
357 uint8 GetChatState() { return m_byChatstate; }
358 void SetChatState(uint8 nNewS) { m_byChatstate = nNewS; }
359 EChatCaptchaState GetChatCaptchaState() const { return (EChatCaptchaState)m_nChatCaptchaState; }
360 void ProcessCaptchaRequest(CMemFile* data);
361 void ProcessCaptchaReqRes(uint8 nStatus);
362 void ProcessChatMessage(wxString message);
363 // message filtering
364 uint8 GetMessagesReceived() const { return m_cMessagesReceived; }
365 void IncMessagesReceived() { m_cMessagesReceived < 255 ? ++m_cMessagesReceived : 255; }
366 uint8 GetMessagesSent() const { return m_cMessagesSent; }
367 void IncMessagesSent() { m_cMessagesSent < 255 ? ++m_cMessagesSent : 255; }
368 bool IsSpammer() const { return m_fIsSpammer; }
369 void SetSpammer(bool bVal);
370 bool IsMessageFiltered(const wxString& message);
372 //File Comment
373 const wxString& GetFileComment() const { return m_strComment; }
374 uint8 GetFileRating() const { return m_iRating; }
376 const wxString& GetSoftStr() const { return m_clientSoftString; }
377 const wxString& GetSoftVerStr() const { return m_clientVerString; }
378 const wxString GetServerName() const;
380 uint16 GetKadPort() const { return m_nKadPort; }
381 void SetKadPort(uint16 nPort) { m_nKadPort = nPort; }
383 // Kry - AICH import
384 void SetReqFileAICHHash(CAICHHash* val);
385 CAICHHash* GetReqFileAICHHash() const {return m_pReqFileAICHHash;}
386 bool IsSupportingAICH() const {return m_fSupportsAICH & 0x01;}
387 void SendAICHRequest(CPartFile* pForFile, uint16 nPart);
388 bool IsAICHReqPending() const {return m_fAICHRequested; }
389 void ProcessAICHAnswer(const byte* packet, uint32 size);
390 void ProcessAICHRequest(const byte* packet, uint32 size);
391 void ProcessAICHFileHash(CMemFile* data, const CPartFile* file);
393 EUtf8Str GetUnicodeSupport() const;
395 // Barry - Process zip file as it arrives, don't need to wait until end of block
396 int unzip(Pending_Block_Struct *block, byte *zipped, uint32 lenZipped, byte **unzipped, uint32 *lenUnzipped, int iRecursion = 0);
397 void UpdateDisplayedInfo(bool force = false);
398 int GetFileListRequested() const { return m_iFileListRequested; }
399 void SetFileListRequested(int iFileListRequested) { m_iFileListRequested = iFileListRequested; }
401 void ResetFileStatusInfo();
403 bool CheckHandshakeFinished() const;
405 bool GetSentCancelTransfer() const { return m_fSentCancelTransfer; }
406 void SetSentCancelTransfer(bool bVal) { m_fSentCancelTransfer = bVal; }
408 wxString GetClientFullInfo();
409 wxString GetClientShortInfo();
411 const wxString& GetClientOSInfo() const { return m_sClientOSInfo; }
413 void ProcessPublicIPAnswer(const byte* pbyData, uint32 uSize);
414 void SendPublicIPRequest();
417 * Sets the current socket of the client.
419 * @param socket The pointer to the new socket, can be NULL.
421 * Please note that this function DOES NOT delete the old socket.
423 void SetSocket(CClientTCPSocket* socket);
426 * Function for accessing the socket owned by a client.
428 * @return The pointer (can be NULL) to the socket used by this client.
430 * Please note that the socket object is quite volatile and can be removed
431 * from one function call to the next, therefore, you should normally use
432 * the safer functions below, which all check if the socket is valid before
433 * deferring it.
435 CClientTCPSocket* GetSocket() const { return m_socket; }
438 * Safe function for checking if the socket is connected.
440 * @return True if the socket exists and is connected, false otherwise.
442 bool IsConnected() const;
445 * Safe function for sending packets.
447 * @return True if the socket exists and the packet was sent, false otherwise.
449 bool SendPacket(CPacket* packet, bool delpacket = true, bool controlpacket = true);
452 * Safe function for setting the download limit of the socket.
454 * @return Current download speed of the client.
456 float SetDownloadLimit(uint32 reducedownload);
459 * Sends a message to a client
461 * @return True if sent, false if connecting
463 bool SendChatMessage(const wxString& message);
465 bool HasBlocks() const { return !m_BlockRequests_queue.empty(); }
467 /* Source comes from? */
468 ESourceFrom GetSourceFrom() const { return m_nSourceFrom; }
469 void SetSourceFrom(ESourceFrom val) { m_nSourceFrom = val; }
471 /* Kad buddy support */
472 // ID
473 const byte* GetBuddyID() const { return m_achBuddyID; }
474 void SetBuddyID(const byte* m_achTempBuddyID);
475 bool HasValidBuddyID() const { return m_bBuddyIDValid; }
476 /* IP */
477 void SetBuddyIP( uint32 val ) { m_nBuddyIP = val; }
478 uint32 GetBuddyIP() const { return m_nBuddyIP; }
479 /* Port */
480 void SetBuddyPort( uint16 val ) { m_nBuddyPort = val; }
481 uint16 GetBuddyPort() const { return m_nBuddyPort; }
483 //KadIPCheck
484 bool SendBuddyPingPong() { return m_dwLastBuddyPingPongTime < ::GetTickCount(); }
485 bool AllowIncomeingBuddyPingPong() { return m_dwLastBuddyPingPongTime < (::GetTickCount()-(3*60*1000)); }
486 void SetLastBuddyPingPongTime() { m_dwLastBuddyPingPongTime = (::GetTickCount()+(10*60*1000)); }
487 EKadState GetKadState() const { return m_nKadState; }
488 void SetKadState(EKadState nNewS) { m_nKadState = nNewS; }
489 uint8 GetKadVersion() { return m_byKadVersion; }
490 void ProcessFirewallCheckUDPRequest(CMemFile *data);
491 // Kad added by me
492 bool SendBuddyPing();
494 /* Returns the client hash type (SO_EMULE, mldonkey, etc) */
495 int GetHashType() const;
498 * Checks that a client isn't aggressively re-asking for files.
500 * Call this when a file is requested. If the time since the last request is
501 * less than MIN_REQUESTTIME, 3 is added to the m_Aggressiveness variable.
502 * If the time since the last request is >= MIN_REQUESTTIME, the variable is
503 * decremented by 1. The client is banned if the variable reaches 10 or above.
505 * To check if a client is aggressive use the IsClientAggressive() function.
507 * Currently this function is called when the following packets are received:
508 * - OP_STARTUPLOADREQ
509 * - OP_REASKFILEPING
511 void CheckForAggressive();
513 const wxString& GetClientModString() const { return m_strModVersion; }
515 const wxString& GetClientVerString() const { return m_fullClientVerString; }
517 const wxString& GetVersionString() const { return m_clientVersionString; }
519 void UpdateStats();
521 /* Returns a pointer to the credits, only for hash purposes */
522 void* GetCreditsHash() const { return (void*)credits; }
524 uint16 GetLastDownloadingPart() const { return m_lastDownloadingPart; }
526 bool GetOSInfoSupport() const { return m_fOsInfoSupport; }
528 bool GetVBTTags() const { return m_fValueBasedTypeTags; }
530 uint16 GetLastPartAsked() const { return m_lastPartAsked; }
532 void SetLastPartAsked(uint16 nPart) { m_lastPartAsked = nPart; }
534 CFriend* GetFriend() const { return m_Friend; }
536 void SetFriend(CFriend* newfriend) { m_Friend = newfriend; }
538 bool IsIdentified() const;
540 bool IsBadGuy() const;
542 bool SUIFailed() const;
544 bool SUINeeded() const;
546 bool SUINotSupported() const;
548 uint64 GetDownloadedTotal() const;
550 uint64 GetUploadedTotal() const;
552 double GetScoreRatio() const;
554 uint32 GetCreationTime() const { return m_nCreationTime; }
556 bool SupportsLargeFiles() const { return m_fSupportsLargeFiles; }
558 EIdentState GetCurrentIdentState() const { return credits ? credits->GetCurrentIdentState(GetIP()) : IS_NOTAVAILABLE; }
560 #ifdef __DEBUG__
561 /* Kry - Debug. See connection_reason definition comment below */
562 void SetConnectionReason(const wxString& reason) { connection_reason = reason; }
563 #endif
565 // Encryption / Obfuscation / ConnectOptions
566 bool SupportsCryptLayer() const { return m_fSupportsCryptLayer; }
567 bool RequestsCryptLayer() const { return SupportsCryptLayer() && m_fRequestsCryptLayer; }
568 bool RequiresCryptLayer() const { return RequestsCryptLayer() && m_fRequiresCryptLayer; }
569 bool SupportsDirectUDPCallback() const { return m_fDirectUDPCallback != 0 && HasValidHash() && GetKadPort() != 0; }
570 uint32_t GetDirectCallbackTimeout() const { return m_dwDirectCallbackTimeout; }
571 bool HasObfuscatedConnectionBeenEstablished() const { return m_hasbeenobfuscatinglately; }
573 void SetCryptLayerSupport(bool bVal) { m_fSupportsCryptLayer = bVal ? 1 : 0; }
574 void SetCryptLayerRequest(bool bVal) { m_fRequestsCryptLayer = bVal ? 1 : 0; }
575 void SetCryptLayerRequires(bool bVal) { m_fRequiresCryptLayer = bVal ? 1 : 0; }
576 void SetDirectUDPCallbackSupport(bool bVal) { m_fDirectUDPCallback = bVal ? 1 : 0; }
577 void SetConnectOptions(uint8_t options, bool encryption = true, bool callback = true); // shortcut, sets crypt, callback, etc from the tagvalue we receive
578 bool ShouldReceiveCryptUDPPackets() const;
580 bool HasDisabledSharedFiles() const { return m_fNoViewSharedFiles; }
582 private:
584 CClientCredits *credits;
585 CFriend *m_Friend;
587 uint64 m_nTransferredUp;
588 sint64 m_nCurQueueSessionPayloadUp;
589 sint64 m_addedPayloadQueueSession;
591 struct TransferredData {
592 uint32 datalen;
593 uint32 timestamp;
596 //////////////////////////////////////////////////////////
597 // Upload data rate computation
599 uint32 m_nUpDatarate;
600 uint32 m_nSumForAvgUpDataRate;
601 std::list<TransferredData> m_AvarageUDR_list;
605 * This struct is used to keep track of CPartFiles which this source shares.
607 struct A4AFStamp {
608 //! Signifies if this sources has needed parts for this file.
609 bool NeededParts;
610 //! This is set when we wish to avoid swapping to this file for a while.
611 uint32 timestamp;
614 //! I typedef in the name of readability!
615 typedef std::map<CPartFile*, A4AFStamp> A4AFList;
616 //! This list contains all PartFiles which this client can be used as a source for.
617 A4AFList m_A4AF_list;
620 * Helper function used by SwapToAnotherFile().
622 * @param it The iterator of the PartFile to be examined.
623 * @param ignorenoneeded Do not check for the status NoNeededParts when checking the file.
624 * @param ignoresuspended Do not check the timestamp when checking the file.
625 * @return True if the file is a viable target, false otherwise.
627 * This function is used to perform checks to see if we should consider
628 * this file a viable target for A4AF swapping. Unless ignoresuspended is
629 * true, it will examine the timestamp of the file and reset it if needed.
631 bool IsValidSwapTarget( A4AFList::iterator it, bool ignorenoneeded = false, bool ignoresuspended = false );
633 CPartFile* m_reqfile;
635 // base
636 void Init();
637 bool ProcessHelloTypePacket(const CMemFile& data);
638 void SendHelloTypePacket(CMemFile* data);
639 void SendFirewallCheckUDPRequest();
640 void ClearHelloProperties(); // eMule 0.42
642 uint32 m_dwUserIP;
643 uint32 m_nConnectIP; // holds the supposed IP or (after we had a connection) the real IP
644 uint32 m_dwServerIP;
645 uint32 m_nUserIDHybrid;
646 uint16_t m_nUserPort;
647 int16 m_nServerPort;
648 uint32 m_nClientVersion;
649 uint32 m_cSendblock;
650 uint8 m_byEmuleVersion;
651 uint8 m_byDataCompVer;
652 bool m_bEmuleProtocol;
653 wxString m_Username;
654 uint32 m_FullUserIP;
655 CMD4Hash m_UserHash;
656 bool m_HasValidHash;
657 uint16 m_nUDPPort;
658 uint8 m_byUDPVer;
659 uint8 m_bySourceExchange1Ver;
660 uint8 m_byAcceptCommentVer;
661 uint8 m_byExtendedRequestsVer;
662 uint8 m_clientSoft;
663 uint32 m_dwLastSourceRequest;
664 uint32 m_dwLastSourceAnswer;
665 uint32 m_dwLastAskedForSources;
666 int m_iFileListRequested;
667 bool m_bFriendSlot;
668 bool m_bCommentDirty;
669 bool m_bIsHybrid;
670 bool m_bIsML;
671 bool m_bSupportsPreview;
672 bool m_bUnicodeSupport;
673 uint16 m_nKadPort;
674 bool m_bMultiPacket;
675 ClientState m_clientState;
676 CClientTCPSocket* m_socket;
677 bool m_fNeedOurPublicIP; // we requested our IP from this client
679 // Kry - Secure User Ident import
680 ESecureIdentState m_SecureIdentState;
681 uint8 m_byInfopacketsReceived; // have we received the edonkeyprot and emuleprot packet already (see InfoPacketsReceived() )
682 uint32 m_dwLastSignatureIP;
683 uint8 m_bySupportSecIdent;
685 uint32 m_byCompatibleClient;
686 std::list<CPacket*> m_WaitingPackets_list;
687 uint32 m_lastRefreshedDLDisplay;
689 //upload
690 void CreateStandardPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
691 void CreatePackedPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
692 uint32 CalculateScoreInternal();
694 uint8 m_nUploadState;
695 uint32 m_dwUploadTime;
696 uint32 m_cAsked;
697 uint32 m_dwLastUpRequest;
698 uint32 m_nCurSessionUp;
699 uint16 m_nUpPartCount;
700 CMD4Hash m_requpfileid;
701 uint16 m_nUpCompleteSourcesCount;
702 uint32 m_score;
703 uint16 m_waitingPosition;
705 //! This vector contains the avilability of parts for the file that the user
706 //! is requesting. When changing it, be sure to call CKnownFile::UpdatePartsFrequency
707 //! so that the files know the actual availability of parts.
708 BitVector m_upPartStatus;
709 uint16 m_lastPartAsked;
710 wxString m_strModVersion;
712 std::list<Requested_Block_Struct*> m_BlockRequests_queue;
713 std::list<Requested_Block_Struct*> m_DoneBlocks_list;
715 //download
716 bool m_bRemoteQueueFull;
717 uint8 m_nDownloadState;
718 uint16 m_nPartCount;
719 uint32 m_dwLastAskedTime;
720 wxString m_clientFilename;
721 uint64 m_nTransferredDown;
722 uint16 m_lastDownloadingPart; // last Part that was downloading
723 uint16 m_cShowDR;
724 uint32 m_dwLastBlockReceived;
725 uint16 m_nRemoteQueueRank;
726 uint16 m_nOldRemoteQueueRank;
727 bool m_bCompleteSource;
728 bool m_bReaskPending;
729 bool m_bUDPPending;
730 bool m_bHashsetRequested;
732 std::list<Pending_Block_Struct*> m_PendingBlocks_list;
733 std::list<Requested_Block_Struct*> m_DownloadBlocks_list;
735 // download speed calculation
736 float kBpsDown;
737 uint32 msReceivedPrev;
738 uint32 bytesReceivedCycle;
739 // chat
740 wxString m_strComment;
741 uint8 m_byChatstate;
742 uint8 m_nChatCaptchaState;
743 uint8 m_cCaptchasSent;
744 int8 m_iRating;
745 uint8 m_cMessagesReceived; // count of chatmessages he sent to me
746 uint8 m_cMessagesSent; // count of chatmessages I sent to him
747 wxString m_strCaptchaChallenge;
748 wxString m_strCaptchaPendingMsg;
750 unsigned int
751 m_fHashsetRequesting : 1, // we have sent a hashset request to this client
752 m_fNoViewSharedFiles : 1, // client has disabled the 'View Shared Files' feature,
753 // if this flag is not set, we just know that we don't know
754 // for sure if it is enabled
755 m_fSupportsPreview : 1,
756 m_fIsSpammer : 1,
757 m_fSentCancelTransfer: 1, // we have sent an OP_CANCELTRANSFER in the current connection
758 m_fSharedDirectories : 1, // client supports OP_ASKSHAREDIRS opcodes
759 m_fSupportsAICH : 3,
760 m_fAICHRequested : 1,
761 m_fSupportsLargeFiles: 1,
762 m_fSentOutOfPartReqs : 1,
763 m_fExtMultiPacket : 1,
764 m_fRequestsCryptLayer: 1,
765 m_fSupportsCryptLayer: 1,
766 m_fRequiresCryptLayer: 1,
767 m_fSupportsSourceEx2 : 1,
768 m_fSupportsCaptcha : 1,
769 m_fDirectUDPCallback : 1;
771 unsigned int
772 m_fOsInfoSupport : 1,
773 m_fValueBasedTypeTags : 1;
775 /* Razor 1a - Modif by MikaelB */
777 bool m_bHelloAnswerPending;
779 //! This vector contains the avilability of parts for the file we requested
780 //! from this user. When changing it, be sure to call CPartFile::UpdatePartsFrequency
781 //! so that the files know the actual availability of parts.
782 BitVector m_downPartStatus;
784 CAICHHash* m_pReqFileAICHHash;
786 ESourceFrom m_nSourceFrom;
788 /* Kad Stuff */
789 byte m_achBuddyID[16];
790 bool m_bBuddyIDValid;
791 uint32 m_nBuddyIP;
792 uint16 m_nBuddyPort;
794 EKadState m_nKadState;
796 uint8 m_byKadVersion;
797 uint32 m_dwLastBuddyPingPongTime;
798 uint32_t m_dwDirectCallbackTimeout;
800 //! This keeps track of aggressive requests for files.
801 uint16 m_Aggressiveness;
802 //! This tracks the time of the last time since a file was requested
803 uint32 m_LastFileRequest;
805 bool m_OSInfo_sent;
807 wxString m_clientSoftString; /* software name */
808 wxString m_clientVerString; /* version + optional mod name */
809 wxString m_clientVersionString; /* version string */
810 wxString m_fullClientVerString; /* full info string */
811 wxString m_sClientOSInfo;
812 wxString m_pendingMessage;
814 int SecIdentSupRec;
816 CKnownFile* m_uploadingfile;
818 uint8 m_MaxBlockRequests;
820 // needed for stats
821 uint32 m_lastClientSoft;
822 uint32 m_lastClientVersion;
823 wxString m_lastOSInfo;
825 /* For buddies timeout */
826 uint32 m_nCreationTime;
828 /* Calculation of last average speed */
829 uint32 m_lastaverage;
830 uint32 m_last_block_start;
832 /* Save the encryption status for display when disconnected */
833 bool m_hasbeenobfuscatinglately;
835 /* Kry - Debug thing. Clients created just to check their data
836 have this string set to the reason we want to check them.
837 Obviously, once checked, we disconnect them. Take that, sucker.
838 This debug code is just for me I'm afraid. */
839 #ifdef __DEBUG__
840 wxString connection_reason;
841 #endif
845 #define MAKE_CLIENT_VERSION(mjr, min, upd) \
846 ((uint32)(mjr)*100U*10U*100U + (uint32)(min)*100U*10U + (uint32)(upd)*100U)
849 #endif // UPDOWNCLIENT_H
850 // File_checked_for_headers