Upstream tarball 20080418
[amule.git] / src / updownclient.h
blob5ddf5f4e7dc1696a5c5efd3db12f9109508031e2
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 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"
35 #include <map>
38 typedef std::vector<bool> BitVector;
40 class CPartFile;
41 class CClientTCPSocket;
42 class CClientCredits;
43 class CPacket;
44 class CFriend;
45 class CKnownFile;
46 class CMemFile;
47 class CMemFile;
48 class CAICHHash;
51 // uploadstate
52 #define US_UPLOADING 0
53 #define US_ONUPLOADQUEUE 1
54 #define US_WAITCALLBACK 2
55 #define US_CONNECTING 3
56 #define US_PENDING 4
57 #define US_LOWTOLOWIP 5
58 #define US_BANNED 6
59 #define US_ERROR 7
60 #define US_NONE 8
62 // downloadstate
63 enum EDownloadState {
64 DS_DOWNLOADING = 0,
65 DS_ONQUEUE,
66 DS_CONNECTED,
67 DS_CONNECTING,
68 DS_WAITCALLBACK,
69 DS_WAITCALLBACKKAD,
70 DS_REQHASHSET,
71 DS_NONEEDEDPARTS,
72 DS_TOOMANYCONNS,
73 DS_TOOMANYCONNSKAD,
74 DS_LOWTOLOWIP,
75 DS_BANNED,
76 DS_ERROR,
77 DS_NONE,
78 DS_REMOTEQUEUEFULL // not used yet, except in statistics
81 // m_byChatstate
82 enum {
83 MS_NONE = 0,
84 MS_CHATTING,
85 MS_CONNECTING,
86 MS_UNABLETOCONNECT
89 enum ESourceFrom {
90 SF_NONE,
91 SF_LOCAL_SERVER,
92 SF_REMOTE_SERVER,
93 SF_KADEMLIA,
94 SF_SOURCE_EXCHANGE,
95 SF_PASSIVE,
96 SF_LINK,
97 SF_SOURCE_SEEDS
100 enum ESecureIdentState{
101 IS_UNAVAILABLE = 0,
102 IS_ALLREQUESTSSEND = 0,
103 IS_SIGNATURENEEDED = 1,
104 IS_KEYANDSIGNEEDED = 2
107 enum EInfoPacketState{
108 IP_NONE = 0,
109 IP_EDONKEYPROTPACK = 1,
110 IP_EMULEPROTPACK = 2,
111 IP_BOTH = 3
114 enum EKadState{
115 KS_NONE,
116 KS_QUEUED_FWCHECK,
117 KS_CONNECTING_FWCHECK,
118 KS_CONNECTED_FWCHECK,
119 KS_QUEUED_BUDDY,
120 KS_INCOMING_BUDDY,
121 KS_CONNECTING_BUDDY,
122 KS_CONNECTED_BUDDY,
123 KS_NONE_LOWID,
124 KS_WAITCALLBACK_LOWID,
125 KS_QUEUE_LOWID
128 //! Used to keep track of the state of the client
129 enum ClientState
131 //! New is for clients that have just been created.
132 CS_NEW = 0,
133 //! Listed is for clients that are on the clientlist
134 CS_LISTED,
135 //! Dying signifies clients that have been queued for deletion
136 CS_DYING
139 // This is fixed on ed2k v1, but can be any number on ED2Kv2
140 #define STANDARD_BLOCKS_REQUEST 3
142 class CUpDownClient
144 friend class CClientList;
145 friend class CUpDownClientListRem;
146 private:
148 * Please note that only the ClientList is allowed to delete the clients.
149 * To schedule a client for deletion, call the CClientList::AddToDeleteQueue
150 * funtion, which will safely remove dead clients once every second.
152 ~CUpDownClient();
154 public:
155 #ifdef CLIENT_GUI
156 CUpDownClient(class CEC_UpDownClient_Tag *);
157 #else
158 //base
159 CUpDownClient(CClientTCPSocket* sender = 0);
160 CUpDownClient(uint16 in_port, uint32 in_userid, uint32 in_serverup, uint16 in_serverport,CPartFile* in_reqfile, bool ed2kID, bool checkfriend);
161 #endif
163 * This function should be called when the client object is to be deleted.
164 * It'll close the socket of the client and add it to the deletion queue
165 * owned by the CClientList class. However, if the CUpDownClient isn't on
166 * the normal clientlist, it will be deleted immediatly.
168 * The purpose of this is to avoid clients suddenly being removed due to
169 * asyncronous events, such as socket errors, which can result in the
170 * problems, as each CUpDownClient object is often kept in multiple lists,
171 * and instantly removing the client poses the risk of invalidating
172 * currently used iterators and/or creating dangling pointers.
174 * @see CClientList::AddToDeleteQueue
175 * @see CClientList::Process
177 void Safe_Delete();
180 * Specifies if the client has been queued for deletion.
182 * @return True if Safe_Delete has been called, false otherwise.
184 bool HasBeenDeleted() { return m_clientState == CS_DYING; }
186 ClientState GetClientState() { return m_clientState; }
188 bool Disconnected(const wxString& strReason, bool bFromSocket = false);
189 bool TryToConnect(bool bIgnoreMaxCon = false);
190 bool Connect();
191 void ConnectionEstablished();
192 const wxString& GetUserName() const { return m_Username; }
193 //Only use this when you know the real IP or when your clearing it.
194 void SetIP( uint32 val );
195 uint32 GetIP() const { return m_dwUserIP; }
196 bool HasLowID() const { return IsLowID(m_nUserIDHybrid); }
197 const wxString& GetFullIP() const { return m_FullUserIP; }
198 uint32 GetConnectIP() const { return m_nConnectIP; }
199 uint32 GetUserIDHybrid() const { return m_nUserIDHybrid; }
200 void SetUserIDHybrid(uint32 val);
201 uint32 GetUserPort() const { return m_nUserPort; }
202 uint32 GetTransferredDown() const { return m_nTransferredDown; }
203 uint32 GetServerIP() const { return m_dwServerIP; }
204 void SetServerIP(uint32 nIP) { m_dwServerIP = nIP; }
205 uint16 GetServerPort() const { return m_nServerPort; }
206 void SetServerPort(uint16 nPort) { m_nServerPort = nPort; }
207 const CMD4Hash& GetUserHash() const { return m_UserHash; }
208 void SetUserHash(const CMD4Hash& userhash);
209 void ValidateHash() { m_HasValidHash = !m_UserHash.IsEmpty(); }
210 bool HasValidHash() const { return m_HasValidHash; }
211 uint32 GetVersion() const { return m_nClientVersion;}
212 uint8 GetMuleVersion() const { return m_byEmuleVersion;}
213 bool ExtProtocolAvailable() const { return m_bEmuleProtocol;}
214 bool IsEmuleClient() const { return (m_byEmuleVersion > 0);}
215 bool IsBanned() const;
216 const wxString& GetClientFilename() const { return m_clientFilename; }
217 uint16 GetUDPPort() const { return m_nUDPPort; }
218 void SetUDPPort(uint16 nPort) { m_nUDPPort = nPort; }
219 uint8 GetUDPVersion() const { return m_byUDPVer; }
220 uint8 GetExtendedRequestsVersion() const { return m_byExtendedRequestsVer; }
221 bool IsFriend() const { return m_Friend != NULL; }
222 bool IsML() const { return m_bIsML; }
223 bool IsHybrid() const { return m_bIsHybrid; }
224 uint32 GetCompatibleClient() const { return m_byCompatibleClient; }
226 void ClearDownloadBlockRequests();
227 void RequestSharedFileList();
228 void ProcessSharedFileList(const byte* pachPacket, uint32 nSize, wxString& pszDirectory);
230 wxString GetUploadFileInfo();
232 void SetUserName(const wxString& NewName) { m_Username = NewName; }
234 uint8 GetClientSoft() const { return m_clientSoft; }
235 void ReGetClientSoft();
236 bool ProcessHelloAnswer(const byte* pachPacket, uint32 nSize);
237 bool ProcessHelloPacket(const byte* pachPacket, uint32 nSize);
238 void SendHelloAnswer();
239 bool SendHelloPacket();
240 void SendMuleInfoPacket(bool bAnswer, bool OSInfo = false);
241 bool ProcessMuleInfoPacket(const byte* pachPacket, uint32 nSize);
242 void ProcessMuleCommentPacket(const byte* pachPacket, uint32 nSize);
243 bool Compare(const CUpDownClient* tocomp, bool bIgnoreUserhash = false) const;
244 void SetLastSrcReqTime() { m_dwLastSourceRequest = ::GetTickCount(); }
245 void SetLastSrcAnswerTime() { m_dwLastSourceAnswer = ::GetTickCount(); }
246 void SetLastAskedForSources() { m_dwLastAskedForSources = ::GetTickCount(); }
247 uint32 GetLastSrcReqTime() const { return m_dwLastSourceRequest; }
248 uint32 GetLastSrcAnswerTime() const { return m_dwLastSourceAnswer; }
249 uint32 GetLastAskedForSources() const { return m_dwLastAskedForSources; }
250 bool GetFriendSlot() const { return m_bFriendSlot; }
251 void SetFriendSlot(bool bNV) { m_bFriendSlot = bNV; }
252 void SetCommentDirty(bool bDirty = true) { m_bCommentDirty = bDirty; }
253 uint8 GetSourceExchange1Version() const { return m_bySourceExchange1Ver; }
254 bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2; }
256 bool SafeSendPacket(CPacket* packet);
258 void ProcessRequestPartsPacket(const byte* pachPacket, uint32 nSize, bool largeblocks);
259 void ProcessRequestPartsPacketv2(const CMemFile& data);
261 void SendPublicKeyPacket();
262 void SendSignaturePacket();
263 void ProcessPublicKeyPacket(const byte* pachPacket, uint32 nSize);
264 void ProcessSignaturePacket(const byte* pachPacket, uint32 nSize);
265 uint8 GetSecureIdentState();
267 void SendSecIdentStatePacket();
268 void ProcessSecIdentStatePacket(const byte* pachPacket, uint32 nSize);
270 uint8 GetInfoPacketsReceived() const { return m_byInfopacketsReceived; }
271 void InfoPacketsReceived();
273 //upload
274 uint8 GetUploadState() const { return m_nUploadState; }
275 void SetUploadState(uint8 news);
276 uint32 GetTransferredUp() const { return m_nTransferredUp; }
277 uint32 GetSessionUp() const { return m_nTransferredUp - m_nCurSessionUp; }
278 void ResetSessionUp() {
279 m_nCurSessionUp = m_nTransferredUp;
280 m_addedPayloadQueueSession = 0;
281 m_nCurQueueSessionPayloadUp = 0;
283 uint32 GetUploadDatarate() const { return m_nUpDatarate; }
285 #ifndef CLIENT_GUI
286 uint32 GetWaitTime() const { return m_dwUploadTime - GetWaitStartTime(); }
287 uint32 GetUpStartTimeDelay() const { return ::GetTickCount() - m_dwUploadTime; }
288 uint32 GetWaitStartTime() const;
289 #else
290 uint32 m_WaitTime, m_UpStartTimeDelay, m_WaitStartTime;
291 uint32 GetWaitTime() const { return m_WaitTime; }
292 uint32 GetUpStartTimeDelay() const { return m_UpStartTimeDelay; }
293 uint32 GetWaitStartTime() const { return m_WaitStartTime; }
294 #endif
296 bool IsDownloading() const { return (m_nUploadState == US_UPLOADING); }
298 #ifndef CLIENT_GUI
299 uint32 GetScore(
300 bool sysvalue,
301 bool isdownloading = false,
302 bool onlybasevalue = false) const;
303 #else
304 uint32 m_score;
305 uint32 GetScore(
306 bool WXUNUSED(sysvalue),
307 bool WXUNUSED(isdownloading) = false,
308 bool WXUNUSED(onlybasevalue) = false) const
310 return m_score;
312 uint16 m_waitingPosition;
313 uint16 GetWaitingPosition() const { return m_waitingPosition; }
314 #endif
315 double GetRating() const
317 return (double)GetScore(false, IsDownloading(), true);
320 void AddReqBlock(Requested_Block_Struct* reqblock);
321 void CreateNextBlockPackage();
322 void SetUpStartTime() { m_dwUploadTime = ::GetTickCount(); }
323 void SetWaitStartTime();
324 void ClearWaitStartTime();
325 void SendHashsetPacket(const CMD4Hash& forfileid);
326 bool SupportMultiPacket() const { return m_bMultiPacket; }
327 bool SupportExtMultiPacket() const { return m_fExtMultiPacket; }
329 void SetUploadFileID(CKnownFile *newreqfile);
332 *Gets the file actually on upload
335 const CKnownFile* GetUploadFile() const { return m_uploadingfile; }
337 void SendOutOfPartReqsAndAddToWaitingQueue();
338 void ProcessExtendedInfo(const CMemFile *data, CKnownFile *tempreqfile);
339 void ProcessFileInfo(const CMemFile* data, const CPartFile* file);
340 void ProcessFileStatus(bool bUdpPacket, const CMemFile* data, const CPartFile* file);
342 const CMD4Hash& GetUploadFileID() const { return m_requpfileid; }
343 void SetUploadFileID(const CMD4Hash& new_id);
344 void ClearUploadFileID() { m_requpfileid.Clear(); m_uploadingfile = NULL;};
345 uint32 SendBlockData();
346 void ClearUploadBlockRequests();
347 void SendRankingInfo();
348 void SendCommentInfo(CKnownFile *file);
349 bool IsDifferentPartBlock() const;
350 void UnBan();
351 void Ban();
352 bool m_bAddNextConnect; // VQB Fix for LowID slots only on connection
353 uint32 GetAskedCount() const { return m_cAsked; }
354 void AddAskedCount() { m_cAsked++; }
355 void ClearAskedCount() { m_cAsked = 1; } // 1, because it's cleared *after* the first request...
356 void FlushSendBlocks(); // call this when you stop upload,
357 // or the socket might be not able to send
358 void SetLastUpRequest() { m_dwLastUpRequest = ::GetTickCount(); }
359 uint32 GetLastUpRequest() const { return m_dwLastUpRequest; }
360 size_t GetUpPartCount() const { return m_upPartStatus.size(); }
363 //download
364 void SetRequestFile(CPartFile* reqfile);
365 CPartFile* GetRequestFile() const { return m_reqfile; }
367 uint8 GetDownloadState() const { return m_nDownloadState; }
368 void SetDownloadState(uint8 byNewState);
369 uint32 GetLastAskedTime() const { return m_dwLastAskedTime; }
371 bool IsPartAvailable(uint16 iPart) const
372 { return ( iPart < m_downPartStatus.size() ) ? m_downPartStatus[iPart] : 0; }
373 bool IsUpPartAvailable(uint16 iPart) const
374 { return ( iPart < m_upPartStatus.size() ) ? m_upPartStatus[iPart] : 0;}
376 const BitVector& GetPartStatus() const { return m_downPartStatus; }
377 const BitVector& GetUpPartStatus() const { return m_upPartStatus; }
378 float GetKBpsDown() const { return kBpsDown; }
379 float CalculateKBpsDown();
380 uint16 GetRemoteQueueRank() const { return m_nRemoteQueueRank; }
381 uint16 GetOldRemoteQueueRank() const { return m_nOldRemoteQueueRank; }
382 void SetRemoteQueueFull(bool flag) { m_bRemoteQueueFull = flag; }
383 bool IsRemoteQueueFull() const { return m_bRemoteQueueFull; }
384 void SetRemoteQueueRank(uint16 nr);
385 bool AskForDownload();
386 void SendStartupLoadReq();
387 void SendFileRequest();
388 void ProcessHashSet(const byte* packet, uint32 size);
389 bool AddRequestForAnotherFile(CPartFile* file);
390 bool DeleteFileRequest(CPartFile* file);
391 void DeleteAllFileRequests();
392 void SendBlockRequests();
393 void ProcessBlockPacket(const byte* packet, uint32 size, bool packed, bool largeblocks);
395 #ifndef CLIENT_GUI
396 uint16 GetAvailablePartCount() const;
397 #else
398 uint16 m_AvailPartCount;
399 uint16 GetAvailablePartCount() const { return m_AvailPartCount; }
400 #endif
402 bool SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile = NULL);
403 void UDPReaskACK(uint16 nNewQR);
404 void UDPReaskFNF();
405 void UDPReaskForDownload();
406 bool IsSourceRequestAllowed();
407 uint16 GetUpCompleteSourcesCount() const { return m_nUpCompleteSourcesCount; }
408 void SetUpCompleteSourcesCount(uint16 n) { m_nUpCompleteSourcesCount = n; }
410 //chat
411 uint8 GetChatState() { return m_byChatstate; }
412 void SetChatState(uint8 nNewS) { m_byChatstate = nNewS; }
414 //File Comment
415 const wxString& GetFileComment() const { return m_strComment; }
416 uint8 GetFileRating() const { return m_iRating; }
418 const wxString& GetSoftStr() const { return m_clientSoftString; }
419 const wxString& GetSoftVerStr() const { return m_clientVerString; }
420 #ifndef CLIENT_GUI
421 const wxString GetServerName() const;
422 #else
423 wxString m_ServerName;
424 const wxString& GetServerName() const { return m_ServerName; }
425 #endif
427 uint16 GetKadPort() const { return m_nKadPort; }
428 void SetKadPort(uint16 nPort) { m_nKadPort = nPort; }
430 // Kry - AICH import
431 void SetReqFileAICHHash(CAICHHash* val);
432 CAICHHash* GetReqFileAICHHash() const {return m_pReqFileAICHHash;}
433 bool IsSupportingAICH() const {return m_fSupportsAICH & 0x01;}
434 void SendAICHRequest(CPartFile* pForFile, uint16 nPart);
435 bool IsAICHReqPending() const {return m_fAICHRequested; }
436 void ProcessAICHAnswer(const byte* packet, uint32 size);
437 void ProcessAICHRequest(const byte* packet, uint32 size);
438 void ProcessAICHFileHash(CMemFile* data, const CPartFile* file);
440 EUtf8Str GetUnicodeSupport() const;
442 // Barry - Process zip file as it arrives, don't need to wait until end of block
443 int unzip(Pending_Block_Struct *block, byte *zipped, uint32 lenZipped, byte **unzipped, uint32 *lenUnzipped, int iRecursion = 0);
444 // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
445 wxString ShowDownloadingParts() const;
446 void UpdateDisplayedInfo(bool force = false);
447 int GetFileListRequested() const { return m_iFileListRequested; }
448 void SetFileListRequested(int iFileListRequested) { m_iFileListRequested = iFileListRequested; }
450 void ResetFileStatusInfo();
452 bool CheckHandshakeFinished(uint32 protocol, uint32 opcode) const;
454 bool GetSentCancelTransfer() const { return m_fSentCancelTransfer; }
455 void SetSentCancelTransfer(bool bVal) { m_fSentCancelTransfer = bVal; }
457 wxString GetClientFullInfo();
459 const wxString& GetClientOSInfo() const { return m_sClientOSInfo; }
461 void ProcessPublicIPAnswer(const byte* pbyData, uint32 uSize);
462 void SendPublicIPRequest();
465 * Sets the current socket of the client.
467 * @param socket The pointer to the new socket, can be NULL.
469 * Please note that this function DOES NOT delete the old socket.
471 void SetSocket(CClientTCPSocket* socket);
474 * Function for accessing the socket owned by a client.
476 * @return The pointer (can be NULL) to the socket used by this client.
478 * Please note that the socket object is quite volatile and can be removed
479 * from one function call to the next, therefore, you should normally use
480 * the safer functions below, which all check if the socket is valid before
481 * deferring it.
483 CClientTCPSocket* GetSocket() const { return m_socket; }
486 * Safe function for checking if the socket is connected.
488 * @return True if the socket exists and is connected, false otherwise.
490 #ifndef CLIENT_GUI
491 bool IsConnected() const;
492 #else
493 bool m_IsConnected;
494 bool IsConnected() const { return m_IsConnected; }
495 #endif
498 * Safe function for sending packets.
500 * @return True if the socket exists and the packet was sent, false otherwise.
502 bool SendPacket(CPacket* packet, bool delpacket = true, bool controlpacket = true);
505 * Safe function for setting the download limit of the socket.
507 * @return Current download speed of the client.
509 float SetDownloadLimit(uint32 reducedownload);
512 * Sends a message to a client
514 * @return True if sent, false if connecting
516 bool SendMessage(const wxString& message);
518 uint32 GetPayloadInBuffer() const { return m_addedPayloadQueueSession - GetQueueSessionPayloadUp(); }
519 uint32 GetQueueSessionPayloadUp() const { return m_nCurQueueSessionPayloadUp; }
520 bool HasBlocks() const { return !m_BlockRequests_queue.empty(); }
522 /* Source comes from? */
523 ESourceFrom GetSourceFrom() const { return (ESourceFrom)m_nSourceFrom; }
524 void SetSourceFrom(ESourceFrom val) { m_nSourceFrom = val; }
526 /* Kad buddy support */
527 // ID
528 const byte* GetBuddyID() const { return m_achBuddyID; }
529 void SetBuddyID(const byte* m_achTempBuddyID);
530 bool HasValidBuddyID() const { return m_bBuddyIDValid; }
531 /* IP */
532 void SetBuddyIP( uint32 val ) { m_nBuddyIP = val; }
533 uint32 GetBuddyIP() const { return m_nBuddyIP; }
534 /* Port */
535 void SetBuddyPort( uint16 val ) { m_nBuddyPort = val; }
536 uint16 GetBuddyPort() const { return m_nBuddyPort; }
538 //KadIPCheck
539 bool SendBuddyPingPong() { return m_dwLastBuddyPingPongTime < ::GetTickCount(); }
540 bool AllowIncomeingBuddyPingPong() { return m_dwLastBuddyPingPongTime < (::GetTickCount()-(3*60*1000)); }
541 void SetLastBuddyPingPongTime() { m_dwLastBuddyPingPongTime = (::GetTickCount()+(10*60*1000)); }
542 EKadState GetKadState() const { return m_nKadState; }
543 void SetKadState(EKadState nNewS) { m_nKadState = nNewS; }
544 uint8 GetKadVersion() { return m_byKadVersion; }
545 // Kad added by me
546 bool SendBuddyPing();
548 /* Returns the client hash type (SO_EMULE, mldonkey, etc) */
549 int GetHashType() const;
552 * Checks that a client isn't aggressively re-asking for files.
554 * Call this when a file is requested. If the time since the last request is
555 * less than MIN_REQUESTTIME, 3 is added to the m_Aggressiveness variable.
556 * If the time since the last request is >= MIN_REQUESTTIME, the variable is
557 * decremented by 1. The client is banned if the variable reaches 10 or above.
559 * To check if a client is aggressive use the IsClientAggressive() function.
561 * Currently this function is called when the following packets are received:
562 * - OP_STARTUPLOADREQ
563 * - OP_REASKFILEPING
565 void CheckForAggressive();
567 const wxString& GetClientModString() const { return m_strModVersion; }
569 const wxString& GetClientVerString() const { return m_fullClientVerString; }
571 const wxString& GetVersionString() const { return m_clientVersionString; }
573 void UpdateStats();
575 /* Returns a pointer to the credits, only for hash purposes */
576 void* GetCreditsHash() const { return (void*)credits; }
578 uint32 GetLastBlockOffset() const { return m_nLastBlockOffset; }
580 bool GetOSInfoSupport() const { return m_fOsInfoSupport; }
582 bool GetVBTTags() const { return m_fValueBasedTypeTags; }
584 uint16 GetLastPartAsked() const { return m_lastPartAsked; }
586 void SetLastPartAsked(uint16 nPart) { m_lastPartAsked = nPart; }
588 CFriend* GetFriend() const { return m_Friend; }
590 void SetFriend(CFriend* newfriend) { m_Friend = newfriend; }
592 bool IsIdentified() const;
594 bool IsBadGuy() const;
596 bool SUIFailed() const;
598 bool SUINeeded() const;
600 bool SUINotSupported() const;
602 uint64 GetDownloadedTotal() const;
604 uint64 GetUploadedTotal() const;
606 double GetScoreRatio() const;
608 uint32 GetCreationTime() const { return m_nCreationTime; }
610 bool SupportsLargeFiles() const { return m_fSupportsLargeFiles; }
612 #ifdef __DEBUG__
613 /* Kry - Debug. See connection_reason definition comment below */
614 void SetConnectionReason(const wxString& reason) { connection_reason = reason; }
615 #endif
617 // Encryption / Obfuscation
618 bool SupportsCryptLayer() const { return m_fSupportsCryptLayer; }
619 bool RequestsCryptLayer() const { return SupportsCryptLayer() && m_fRequestsCryptLayer; }
620 bool RequiresCryptLayer() const { return RequestsCryptLayer() && m_fRequiresCryptLayer; }
621 bool HasObfuscatedConnectionBeenEstablished() const { return m_hasbeenobfuscatinglately; }
623 void SetCryptLayerSupport(bool bVal) { m_fSupportsCryptLayer = bVal ? 1 : 0; }
624 void SetCryptLayerRequest(bool bVal) { m_fRequestsCryptLayer = bVal ? 1 : 0; }
625 void SetCryptLayerRequires(bool bVal) { m_fRequiresCryptLayer = bVal ? 1 : 0; }
626 bool ShouldReceiveCryptUDPPackets() const;
628 bool HasDisabledSharedFiles() const { return m_fNoViewSharedFiles; }
630 private:
632 CClientCredits *credits;
633 CFriend *m_Friend;
635 uint32 m_nTransferredUp;
636 uint32 m_nCurQueueSessionPayloadUp;
637 uint32 m_addedPayloadQueueSession;
639 struct TransferredData {
640 uint32 datalen;
641 uint32 timestamp;
644 //////////////////////////////////////////////////////////
645 // Upload data rate computation
647 uint32 m_nUpDatarate;
648 uint32 m_nSumForAvgUpDataRate;
649 std::list<TransferredData> m_AvarageUDR_list;
653 * This struct is used to keep track of CPartFiles which this source shares.
655 struct A4AFStamp {
656 //! Signifies if this sources has needed parts for this file.
657 bool NeededParts;
658 //! This is set when we wish to avoid swapping to this file for a while.
659 uint32 timestamp;
662 //! I typedef in the name of readability!
663 typedef std::map<CPartFile*, A4AFStamp> A4AFList;
664 //! This list contains all PartFiles which this client can be used as a source for.
665 A4AFList m_A4AF_list;
668 * Helper function used by SwapToAnotherFile().
670 * @param it The iterator of the PartFile to be examined.
671 * @param ignorenoneeded Do not check for the status NoNeededParts when checking the file.
672 * @param ignoresuspended Do not check the timestamp when checking the file.
673 * @return True if the file is a viable target, false otherwise.
675 * This function is used to perform checks to see if we should consider
676 * this file a viable target for A4AF swapping. Unless ignoresuspended is
677 * true, it will examine the timestamp of the file and reset it if needed.
679 bool IsValidSwapTarget( A4AFList::iterator it, bool ignorenoneeded = false, bool ignoresuspended = false );
681 CPartFile* m_reqfile;
683 // base
684 void Init();
685 bool ProcessHelloTypePacket(const CMemFile& data);
686 void SendHelloTypePacket(CMemFile* data);
687 void ClearHelloProperties(); // eMule 0.42
688 uint32 m_dwUserIP;
689 uint32 m_nConnectIP; // holds the supposed IP or (after we had a connection) the real IP
690 uint32 m_dwServerIP;
691 uint32 m_nUserIDHybrid;
692 int16 m_nUserPort;
693 int16 m_nServerPort;
694 uint32 m_nClientVersion;
695 uint32 m_cSendblock;
696 uint8 m_byEmuleVersion;
697 uint8 m_byDataCompVer;
698 bool m_bEmuleProtocol;
699 wxString m_Username;
700 wxString m_FullUserIP;
701 CMD4Hash m_UserHash;
702 bool m_HasValidHash;
703 uint16 m_nUDPPort;
704 uint8 m_byUDPVer;
705 uint8 m_bySourceExchange1Ver;
706 uint8 m_byAcceptCommentVer;
707 uint8 m_byExtendedRequestsVer;
708 uint8 m_clientSoft;
709 uint32 m_dwLastSourceRequest;
710 uint32 m_dwLastSourceAnswer;
711 uint32 m_dwLastAskedForSources;
712 int m_iFileListRequested;
713 bool m_bFriendSlot;
714 bool m_bCommentDirty;
715 bool m_bIsHybrid;
716 bool m_bIsML;
717 bool m_bSupportsPreview;
718 bool m_bUnicodeSupport;
719 uint16 m_nKadPort;
720 bool m_bMultiPacket;
721 ClientState m_clientState;
722 CClientTCPSocket* m_socket;
723 bool m_fNeedOurPublicIP; // we requested our IP from this client
725 // Kry - Secure User Ident import
726 ESecureIdentState m_SecureIdentState;
727 uint8 m_byInfopacketsReceived; // have we received the edonkeyprot and emuleprot packet already (see InfoPacketsReceived() )
728 uint32 m_dwLastSignatureIP;
729 uint8 m_bySupportSecIdent;
731 uint32 m_byCompatibleClient;
732 std::list<CPacket*> m_WaitingPackets_list;
733 uint32 m_lastRefreshedDLDisplay;
735 //upload
736 void CreateStandartPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
737 void CreatePackedPackets(const unsigned char* data,uint32 togo, Requested_Block_Struct* currentblock);
739 uint8 m_nUploadState;
740 uint32 m_dwUploadTime;
741 uint32 m_cAsked;
742 uint32 m_dwLastUpRequest;
743 uint32 m_nCurSessionUp;
744 uint16 m_nUpPartCount;
745 CMD4Hash m_requpfileid;
746 uint16 m_nUpCompleteSourcesCount;
748 //! This vector contains the avilability of parts for the file that the user
749 //! is requesting. When changing it, be sure to call CKnownFile::UpdatePartsFrequency
750 //! so that the files know the actual availability of parts.
751 BitVector m_upPartStatus;
752 uint16 m_lastPartAsked;
753 wxString m_strModVersion;
755 std::list<Requested_Block_Struct*> m_BlockRequests_queue;
756 std::list<Requested_Block_Struct*> m_DoneBlocks_list;
758 //download
759 bool m_bRemoteQueueFull;
760 uint8 m_nDownloadState;
761 uint16 m_nPartCount;
762 uint32 m_dwLastAskedTime;
763 wxString m_clientFilename;
764 uint32 m_nTransferredDown;
765 uint32 m_nLastBlockOffset; // Patch for show parts that you download [Cax2]
766 uint16 m_cShowDR;
767 uint32 m_dwLastBlockReceived;
768 uint16 m_nRemoteQueueRank;
769 uint16 m_nOldRemoteQueueRank;
770 bool m_bCompleteSource;
771 bool m_bReaskPending;
772 bool m_bUDPPending;
773 bool m_bHashsetRequested;
775 std::list<Pending_Block_Struct*> m_PendingBlocks_list;
776 std::list<Requested_Block_Struct*> m_DownloadBlocks_list;
778 float kBpsDown;
779 float fDownAvgFilter;
780 uint32 msReceivedPrev;
781 uint32 bytesReceivedCycle;
782 // chat
783 uint8 m_byChatstate;
784 wxString m_strComment;
785 int8 m_iRating;
786 unsigned int
787 m_fHashsetRequesting : 1, // we have sent a hashset request to this client
788 m_fNoViewSharedFiles : 1, // client has disabled the 'View Shared Files' feature,
789 // if this flag is not set, we just know that we don't know
790 // for sure if it is enabled
791 m_fSupportsPreview : 1,
792 m_fSentCancelTransfer: 1, // we have sent an OP_CANCELTRANSFER in the current connection
793 m_fSharedDirectories : 1, // client supports OP_ASKSHAREDIRS opcodes
794 m_fSupportsAICH : 3,
795 m_fAICHRequested : 1,
796 m_fSupportsLargeFiles : 1,
797 m_fSentOutOfPartReqs : 1,
798 m_fExtMultiPacket : 1,
799 m_fRequestsCryptLayer: 1,
800 m_fSupportsCryptLayer: 1,
801 m_fRequiresCryptLayer: 1,
802 m_fSupportsSourceEx2 : 1;
804 unsigned int
805 m_fOsInfoSupport : 1,
806 m_fValueBasedTypeTags : 1;
808 /* Razor 1a - Modif by MikaelB */
810 bool m_bHelloAnswerPending;
812 //! This vector contains the avilability of parts for the file we requested
813 //! from this user. When changing it, be sure to call CPartFile::UpdatePartsFrequency
814 //! so that the files know the actual availability of parts.
815 BitVector m_downPartStatus;
817 CAICHHash* m_pReqFileAICHHash;
819 ESourceFrom m_nSourceFrom;
821 /* Kad Stuff */
822 byte m_achBuddyID[16];
823 bool m_bBuddyIDValid;
824 uint32 m_nBuddyIP;
825 uint16 m_nBuddyPort;
827 EKadState m_nKadState;
829 uint8 m_byKadVersion;
830 uint32 m_dwLastBuddyPingPongTime;
832 //! This keeps track of aggressive requests for files.
833 uint16 m_Aggressiveness;
834 //! This tracks the time of the last time since a file was requested
835 uint32 m_LastFileRequest;
837 bool m_OSInfo_sent;
839 wxString m_clientSoftString; /* software name */
840 wxString m_clientVerString; /* version + optional mod name */
841 wxString m_clientVersionString; /* version string */
842 wxString m_fullClientVerString; /* full info string */
843 wxString m_sClientOSInfo;
844 wxString m_pendingMessage;
846 int SecIdentSupRec;
848 CKnownFile* m_uploadingfile;
850 uint8 m_MaxBlockRequests;
852 // needed for stats
853 uint32 m_lastClientSoft;
854 uint32 m_lastClientVersion;
855 wxString m_lastOSInfo;
857 /* For buddies timeout */
858 uint32 m_nCreationTime;
860 /* Calculation of last average speed */
861 uint32 m_lastaverage;
862 uint32 m_last_block_start;
864 /* Save the encryption status for display when disconnected */
865 bool m_hasbeenobfuscatinglately;
867 /* Kry - Debug thing. Clients created just to check their data
868 have this string set to the reason we want to check them.
869 Obviously, once checked, we disconect them. Take that, sucker.
870 This debug code is just for me I'm afraid. */
871 #ifdef __DEBUG__
872 wxString connection_reason;
873 #endif
877 #define MAKE_CLIENT_VERSION(mjr, min, upd) \
878 ((uint32)(mjr)*100U*10U*100U + (uint32)(min)*100U*10U + (uint32)(upd)*100U)
881 #endif // UPDOWNCLIENT_H
882 // File_checked_for_headers