2 // This file is part of the aMule Project.
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 )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef UPDOWNCLIENT_H
27 #define UPDOWNCLIENT_H
29 #include "GetTickCount.h" // Needed for GetTickCount
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
40 typedef std::vector
<bool> BitVector
;
43 class CClientTCPSocket
;
52 #define US_UPLOADING 0
53 #define US_ONUPLOADQUEUE 1
54 #define US_WAITCALLBACK 2
55 #define US_CONNECTING 3
57 #define US_LOWTOLOWIP 5
78 DS_REMOTEQUEUEFULL
// not used yet, except in statistics
101 enum EChatCaptchaState
{
110 enum ESecureIdentState
{
112 IS_ALLREQUESTSSEND
= 0,
113 IS_SIGNATURENEEDED
= 1,
114 IS_KEYANDSIGNEEDED
= 2
117 enum EInfoPacketState
{
119 IP_EDONKEYPROTPACK
= 1,
120 IP_EMULEPROTPACK
= 2,
127 KS_CONNECTING_FWCHECK
,
128 KS_CONNECTED_FWCHECK
,
133 KS_QUEUED_FWCHECK_UDP
,
135 KS_CONNECTING_FWCHECK_UDP
138 //! Used to keep track of the state of the client
141 //! New is for clients that have just been created.
143 //! Listed is for clients that are on the clientlist
145 //! Dying signifies clients that have been queued for deletion
149 // This is fixed on ed2k v1, but can be any number on ED2Kv2
150 #define STANDARD_BLOCKS_REQUEST 3
152 class CUpDownClient
: public CECID
154 friend class CClientList
;
155 friend class CUpDownClientListRem
;
158 * Please note that only the ClientList is allowed to delete the clients.
159 * To schedule a client for deletion, call the CClientList::AddToDeleteQueue
160 * funtion, which will safely remove dead clients once every second.
166 CUpDownClient(class CEC_UpDownClient_Tag
*);
169 CUpDownClient(CClientTCPSocket
* sender
= 0);
170 CUpDownClient(uint16 in_port
, uint32 in_userid
, uint32 in_serverup
, uint16 in_serverport
,CPartFile
* in_reqfile
, bool ed2kID
, bool checkfriend
);
173 * This function should be called when the client object is to be deleted.
174 * It'll close the socket of the client and add it to the deletion queue
175 * owned by the CClientList class. However, if the CUpDownClient isn't on
176 * the normal clientlist, it will be deleted immediatly.
178 * The purpose of this is to avoid clients suddenly being removed due to
179 * asyncronous events, such as socket errors, which can result in the
180 * problems, as each CUpDownClient object is often kept in multiple lists,
181 * and instantly removing the client poses the risk of invalidating
182 * currently used iterators and/or creating dangling pointers.
184 * @see CClientList::AddToDeleteQueue
185 * @see CClientList::Process
190 * Specifies if the client has been queued for deletion.
192 * @return True if Safe_Delete has been called, false otherwise.
194 bool HasBeenDeleted() { return m_clientState
== CS_DYING
; }
196 ClientState
GetClientState() { return m_clientState
; }
198 bool Disconnected(const wxString
& strReason
, bool bFromSocket
= false);
199 bool TryToConnect(bool bIgnoreMaxCon
= false);
201 void ConnectionEstablished();
202 const wxString
& GetUserName() const { return m_Username
; }
203 //Only use this when you know the real IP or when your clearing it.
204 void SetIP( uint32 val
);
205 uint32
GetIP() const { return m_dwUserIP
; }
206 bool HasLowID() const { return IsLowID(m_nUserIDHybrid
); }
207 wxString
GetFullIP() const { return Uint32toStringIP(m_FullUserIP
); }
208 uint32
GetConnectIP() const { return m_nConnectIP
; }
209 uint32
GetUserIDHybrid() const { return m_nUserIDHybrid
; }
210 void SetUserIDHybrid(uint32 val
);
211 uint16_t GetUserPort() const { return m_nUserPort
; }
212 void SetUserPort(uint16_t port
) { m_nUserPort
= port
; }
213 uint64
GetTransferredDown() const { return m_nTransferredDown
; }
214 uint32
GetServerIP() const { return m_dwServerIP
; }
215 void SetServerIP(uint32 nIP
) { m_dwServerIP
= nIP
; }
216 uint16
GetServerPort() const { return m_nServerPort
; }
217 void SetServerPort(uint16 nPort
) { m_nServerPort
= nPort
; }
218 const CMD4Hash
& GetUserHash() const { return m_UserHash
; }
219 void SetUserHash(const CMD4Hash
& userhash
);
220 void ValidateHash() { m_HasValidHash
= !m_UserHash
.IsEmpty(); }
221 bool HasValidHash() const { return m_HasValidHash
; }
222 uint32
GetVersion() const { return m_nClientVersion
;}
223 uint8
GetMuleVersion() const { return m_byEmuleVersion
;}
224 bool ExtProtocolAvailable() const { return m_bEmuleProtocol
;}
225 bool IsEmuleClient() const { return (m_byEmuleVersion
> 0);}
226 bool IsBanned() const;
227 const wxString
& GetClientFilename() const { return m_clientFilename
; }
228 uint16
GetUDPPort() const { return m_nUDPPort
; }
229 void SetUDPPort(uint16 nPort
) { m_nUDPPort
= nPort
; }
230 uint8
GetUDPVersion() const { return m_byUDPVer
; }
231 uint8
GetExtendedRequestsVersion() const { return m_byExtendedRequestsVer
; }
232 bool IsFriend() const { return m_Friend
!= NULL
; }
233 bool IsML() const { return m_bIsML
; }
234 bool IsHybrid() const { return m_bIsHybrid
; }
235 uint32
GetCompatibleClient() const { return m_byCompatibleClient
; }
237 void ClearDownloadBlockRequests();
238 void RequestSharedFileList();
239 void ProcessSharedFileList(const byte
* pachPacket
, uint32 nSize
, wxString
& pszDirectory
);
241 wxString
GetUploadFileInfo();
243 void SetUserName(const wxString
& NewName
) { m_Username
= NewName
; }
245 uint8
GetClientSoft() const { return m_clientSoft
; }
246 void ReGetClientSoft();
247 bool ProcessHelloAnswer(const byte
* pachPacket
, uint32 nSize
);
248 bool ProcessHelloPacket(const byte
* pachPacket
, uint32 nSize
);
249 void SendHelloAnswer();
250 bool SendHelloPacket();
251 void SendMuleInfoPacket(bool bAnswer
, bool OSInfo
= false);
252 bool ProcessMuleInfoPacket(const byte
* pachPacket
, uint32 nSize
);
253 void ProcessMuleCommentPacket(const byte
* pachPacket
, uint32 nSize
);
254 bool Compare(const CUpDownClient
* tocomp
, bool bIgnoreUserhash
= false) const;
255 void SetLastSrcReqTime() { m_dwLastSourceRequest
= ::GetTickCount(); }
256 void SetLastSrcAnswerTime() { m_dwLastSourceAnswer
= ::GetTickCount(); }
257 void SetLastAskedForSources() { m_dwLastAskedForSources
= ::GetTickCount(); }
258 uint32
GetLastSrcReqTime() const { return m_dwLastSourceRequest
; }
259 uint32
GetLastSrcAnswerTime() const { return m_dwLastSourceAnswer
; }
260 uint32
GetLastAskedForSources() const { return m_dwLastAskedForSources
; }
261 bool GetFriendSlot() const { return m_bFriendSlot
; }
262 void SetFriendSlot(bool bNV
) { m_bFriendSlot
= bNV
; }
263 void SetCommentDirty(bool bDirty
= true) { m_bCommentDirty
= bDirty
; }
264 uint8
GetSourceExchange1Version() const { return m_bySourceExchange1Ver
; }
265 bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2
; }
267 bool SafeSendPacket(CPacket
* packet
);
269 void ProcessRequestPartsPacket(const byte
* pachPacket
, uint32 nSize
, bool largeblocks
);
270 void ProcessRequestPartsPacketv2(const CMemFile
& data
);
272 void SendPublicKeyPacket();
273 void SendSignaturePacket();
274 void ProcessPublicKeyPacket(const byte
* pachPacket
, uint32 nSize
);
275 void ProcessSignaturePacket(const byte
* pachPacket
, uint32 nSize
);
276 uint8
GetSecureIdentState();
278 void SendSecIdentStatePacket();
279 void ProcessSecIdentStatePacket(const byte
* pachPacket
, uint32 nSize
);
281 uint8
GetInfoPacketsReceived() const { return m_byInfopacketsReceived
; }
282 void InfoPacketsReceived();
285 uint8
GetUploadState() const { return m_nUploadState
; }
286 void SetUploadState(uint8 news
);
287 uint32
GetTransferredUp() const { return m_nTransferredUp
; }
288 uint32
GetSessionUp() const { return m_nTransferredUp
- m_nCurSessionUp
; }
289 void ResetSessionUp();
290 uint32
GetUploadDatarate() const { return m_nUpDatarate
; }
293 uint32
GetWaitTime() const { return m_dwUploadTime
- GetWaitStartTime(); }
294 uint32
GetUpStartTimeDelay() const { return ::GetTickCount() - m_dwUploadTime
; }
295 uint32
GetWaitStartTime() const;
297 uint32 m_WaitTime
, m_UpStartTimeDelay
, m_WaitStartTime
;
298 uint32
GetWaitTime() const { return m_WaitTime
; }
299 uint32
GetUpStartTimeDelay() const { return m_UpStartTimeDelay
; }
300 uint32
GetWaitStartTime() const { return m_WaitStartTime
; }
303 bool IsDownloading() const { return (m_nUploadState
== US_UPLOADING
); }
308 bool isdownloading
= false,
309 bool onlybasevalue
= false) const;
310 uint32
GetRating() const { return GetScore(false, IsDownloading(), true); }
314 bool WXUNUSED(sysvalue
),
315 bool WXUNUSED(isdownloading
) = false,
316 bool onlybasevalue
= false) const
318 return onlybasevalue
? m_rating
: m_score
;
320 uint16 m_waitingPosition
;
321 uint16
GetWaitingPosition() const { return m_waitingPosition
; }
323 uint32
GetRating() const { return m_rating
; }
324 EIdentState m_identState
;
327 void AddReqBlock(Requested_Block_Struct
* reqblock
);
328 void CreateNextBlockPackage();
329 void SetUpStartTime() { m_dwUploadTime
= ::GetTickCount(); }
330 void SetWaitStartTime();
331 void ClearWaitStartTime();
332 void SendHashsetPacket(const CMD4Hash
& forfileid
);
333 bool SupportMultiPacket() const { return m_bMultiPacket
; }
334 bool SupportExtMultiPacket() const { return m_fExtMultiPacket
; }
336 void SetUploadFileID(CKnownFile
*newreqfile
);
339 *Gets the file actually on upload
342 const CKnownFile
* GetUploadFile() const { return m_uploadingfile
; }
344 void SendOutOfPartReqsAndAddToWaitingQueue();
345 void ProcessExtendedInfo(const CMemFile
*data
, CKnownFile
*tempreqfile
);
346 void ProcessFileInfo(const CMemFile
* data
, const CPartFile
* file
);
347 void ProcessFileStatus(bool bUdpPacket
, const CMemFile
* data
, const CPartFile
* file
);
349 const CMD4Hash
& GetUploadFileID() const { return m_requpfileid
; }
350 void SetUploadFileID(const CMD4Hash
& new_id
);
351 void ClearUploadFileID() { m_requpfileid
.Clear(); m_uploadingfile
= NULL
;};
352 uint32
SendBlockData();
353 void ClearUploadBlockRequests();
354 void SendRankingInfo();
355 void SendCommentInfo(CKnownFile
*file
);
356 bool IsDifferentPartBlock() const;
359 bool m_bAddNextConnect
; // VQB Fix for LowID slots only on connection
360 uint32
GetAskedCount() const { return m_cAsked
; }
361 void AddAskedCount() { m_cAsked
++; }
362 void ClearAskedCount() { m_cAsked
= 1; } // 1, because it's cleared *after* the first request...
363 void FlushSendBlocks(); // call this when you stop upload,
364 // or the socket might be not able to send
365 void SetLastUpRequest() { m_dwLastUpRequest
= ::GetTickCount(); }
366 uint32
GetLastUpRequest() const { return m_dwLastUpRequest
; }
367 size_t GetUpPartCount() const { return m_upPartStatus
.size(); }
371 void SetRequestFile(CPartFile
* reqfile
);
372 CPartFile
* GetRequestFile() const { return m_reqfile
; }
374 uint8
GetDownloadState() const { return m_nDownloadState
; }
375 void SetDownloadState(uint8 byNewState
);
376 uint32
GetLastAskedTime() const { return m_dwLastAskedTime
; }
377 void ResetLastAskedTime() { m_dwLastAskedTime
= 0; }
379 bool IsPartAvailable(uint16 iPart
) const
380 { return ( iPart
< m_downPartStatus
.size() ) ? m_downPartStatus
[iPart
] : 0; }
381 bool IsUpPartAvailable(uint16 iPart
) const
382 { return ( iPart
< m_upPartStatus
.size() ) ? m_upPartStatus
[iPart
] : 0;}
384 const BitVector
& GetPartStatus() const { return m_downPartStatus
; }
385 const BitVector
& GetUpPartStatus() const { return m_upPartStatus
; }
386 float GetKBpsDown() const { return kBpsDown
; }
387 float CalculateKBpsDown();
388 uint16
GetRemoteQueueRank() const { return m_nRemoteQueueRank
; }
389 uint16
GetOldRemoteQueueRank() const { return m_nOldRemoteQueueRank
; }
390 void SetRemoteQueueFull(bool flag
) { m_bRemoteQueueFull
= flag
; }
391 bool IsRemoteQueueFull() const { return m_bRemoteQueueFull
; }
392 void SetRemoteQueueRank(uint16 nr
);
393 bool AskForDownload();
394 void SendStartupLoadReq();
395 void SendFileRequest();
396 void ProcessHashSet(const byte
* packet
, uint32 size
);
397 bool AddRequestForAnotherFile(CPartFile
* file
);
398 bool DeleteFileRequest(CPartFile
* file
);
399 void DeleteAllFileRequests();
400 void SendBlockRequests();
401 void ProcessBlockPacket(const byte
* packet
, uint32 size
, bool packed
, bool largeblocks
);
404 uint16
GetAvailablePartCount() const;
406 uint16 m_AvailPartCount
;
407 uint16
GetAvailablePartCount() const { return m_AvailPartCount
; }
410 bool SwapToAnotherFile(bool bIgnoreNoNeeded
, bool ignoreSuspensions
, bool bRemoveCompletely
, CPartFile
* toFile
= NULL
);
411 void UDPReaskACK(uint16 nNewQR
);
413 void UDPReaskForDownload();
414 bool IsSourceRequestAllowed();
415 uint16
GetUpCompleteSourcesCount() const { return m_nUpCompleteSourcesCount
; }
416 void SetUpCompleteSourcesCount(uint16 n
) { m_nUpCompleteSourcesCount
= n
; }
419 uint8
GetChatState() { return m_byChatstate
; }
420 void SetChatState(uint8 nNewS
) { m_byChatstate
= nNewS
; }
421 EChatCaptchaState
GetChatCaptchaState() const { return (EChatCaptchaState
)m_nChatCaptchaState
; }
422 void ProcessCaptchaRequest(CMemFile
* data
);
423 void ProcessCaptchaReqRes(uint8 nStatus
);
424 void ProcessChatMessage(wxString message
);
426 uint8
GetMessagesReceived() const { return m_cMessagesReceived
; }
427 void IncMessagesReceived() { m_cMessagesReceived
< 255 ? ++m_cMessagesReceived
: 255; }
428 uint8
GetMessagesSent() const { return m_cMessagesSent
; }
429 void IncMessagesSent() { m_cMessagesSent
< 255 ? ++m_cMessagesSent
: 255; }
430 bool IsSpammer() const { return m_fIsSpammer
; }
431 void SetSpammer(bool bVal
);
432 bool IsMessageFiltered(const wxString
& message
);
435 const wxString
& GetFileComment() const { return m_strComment
; }
436 uint8
GetFileRating() const { return m_iRating
; }
438 const wxString
& GetSoftStr() const { return m_clientSoftString
; }
439 const wxString
& GetSoftVerStr() const { return m_clientVerString
; }
441 const wxString
GetServerName() const;
443 wxString m_ServerName
;
444 const wxString
& GetServerName() const { return m_ServerName
; }
447 uint16
GetKadPort() const { return m_nKadPort
; }
448 void SetKadPort(uint16 nPort
) { m_nKadPort
= nPort
; }
451 void SetReqFileAICHHash(CAICHHash
* val
);
452 CAICHHash
* GetReqFileAICHHash() const {return m_pReqFileAICHHash
;}
453 bool IsSupportingAICH() const {return m_fSupportsAICH
& 0x01;}
454 void SendAICHRequest(CPartFile
* pForFile
, uint16 nPart
);
455 bool IsAICHReqPending() const {return m_fAICHRequested
; }
456 void ProcessAICHAnswer(const byte
* packet
, uint32 size
);
457 void ProcessAICHRequest(const byte
* packet
, uint32 size
);
458 void ProcessAICHFileHash(CMemFile
* data
, const CPartFile
* file
);
460 EUtf8Str
GetUnicodeSupport() const;
462 // Barry - Process zip file as it arrives, don't need to wait until end of block
463 int unzip(Pending_Block_Struct
*block
, byte
*zipped
, uint32 lenZipped
, byte
**unzipped
, uint32
*lenUnzipped
, int iRecursion
= 0);
464 // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
465 wxString
ShowDownloadingParts() const;
466 void UpdateDisplayedInfo(bool force
= false);
467 int GetFileListRequested() const { return m_iFileListRequested
; }
468 void SetFileListRequested(int iFileListRequested
) { m_iFileListRequested
= iFileListRequested
; }
470 void ResetFileStatusInfo();
472 bool CheckHandshakeFinished() const;
474 bool GetSentCancelTransfer() const { return m_fSentCancelTransfer
; }
475 void SetSentCancelTransfer(bool bVal
) { m_fSentCancelTransfer
= bVal
; }
477 wxString
GetClientFullInfo();
478 wxString
GetClientShortInfo();
480 const wxString
& GetClientOSInfo() const { return m_sClientOSInfo
; }
482 void ProcessPublicIPAnswer(const byte
* pbyData
, uint32 uSize
);
483 void SendPublicIPRequest();
486 * Sets the current socket of the client.
488 * @param socket The pointer to the new socket, can be NULL.
490 * Please note that this function DOES NOT delete the old socket.
492 void SetSocket(CClientTCPSocket
* socket
);
495 * Function for accessing the socket owned by a client.
497 * @return The pointer (can be NULL) to the socket used by this client.
499 * Please note that the socket object is quite volatile and can be removed
500 * from one function call to the next, therefore, you should normally use
501 * the safer functions below, which all check if the socket is valid before
504 CClientTCPSocket
* GetSocket() const { return m_socket
; }
507 * Safe function for checking if the socket is connected.
509 * @return True if the socket exists and is connected, false otherwise.
512 bool IsConnected() const;
515 bool IsConnected() const { return m_IsConnected
; }
519 * Safe function for sending packets.
521 * @return True if the socket exists and the packet was sent, false otherwise.
523 bool SendPacket(CPacket
* packet
, bool delpacket
= true, bool controlpacket
= true);
526 * Safe function for setting the download limit of the socket.
528 * @return Current download speed of the client.
530 float SetDownloadLimit(uint32 reducedownload
);
533 * Sends a message to a client
535 * @return True if sent, false if connecting
537 bool SendChatMessage(const wxString
& message
);
539 bool HasBlocks() const { return !m_BlockRequests_queue
.empty(); }
541 /* Source comes from? */
542 ESourceFrom
GetSourceFrom() const { return (ESourceFrom
)m_nSourceFrom
; }
543 void SetSourceFrom(ESourceFrom val
) { m_nSourceFrom
= val
; }
545 /* Kad buddy support */
547 const byte
* GetBuddyID() const { return m_achBuddyID
; }
548 void SetBuddyID(const byte
* m_achTempBuddyID
);
549 bool HasValidBuddyID() const { return m_bBuddyIDValid
; }
551 void SetBuddyIP( uint32 val
) { m_nBuddyIP
= val
; }
552 uint32
GetBuddyIP() const { return m_nBuddyIP
; }
554 void SetBuddyPort( uint16 val
) { m_nBuddyPort
= val
; }
555 uint16
GetBuddyPort() const { return m_nBuddyPort
; }
558 bool SendBuddyPingPong() { return m_dwLastBuddyPingPongTime
< ::GetTickCount(); }
559 bool AllowIncomeingBuddyPingPong() { return m_dwLastBuddyPingPongTime
< (::GetTickCount()-(3*60*1000)); }
560 void SetLastBuddyPingPongTime() { m_dwLastBuddyPingPongTime
= (::GetTickCount()+(10*60*1000)); }
561 EKadState
GetKadState() const { return m_nKadState
; }
562 void SetKadState(EKadState nNewS
) { m_nKadState
= nNewS
; }
563 uint8
GetKadVersion() { return m_byKadVersion
; }
564 void ProcessFirewallCheckUDPRequest(CMemFile
*data
);
566 bool SendBuddyPing();
568 /* Returns the client hash type (SO_EMULE, mldonkey, etc) */
569 int GetHashType() const;
572 * Checks that a client isn't aggressively re-asking for files.
574 * Call this when a file is requested. If the time since the last request is
575 * less than MIN_REQUESTTIME, 3 is added to the m_Aggressiveness variable.
576 * If the time since the last request is >= MIN_REQUESTTIME, the variable is
577 * decremented by 1. The client is banned if the variable reaches 10 or above.
579 * To check if a client is aggressive use the IsClientAggressive() function.
581 * Currently this function is called when the following packets are received:
582 * - OP_STARTUPLOADREQ
585 void CheckForAggressive();
587 const wxString
& GetClientModString() const { return m_strModVersion
; }
589 const wxString
& GetClientVerString() const { return m_fullClientVerString
; }
591 const wxString
& GetVersionString() const { return m_clientVersionString
; }
595 /* Returns a pointer to the credits, only for hash purposes */
596 void* GetCreditsHash() const { return (void*)credits
; }
598 uint32
GetLastBlockOffset() const { return m_nLastBlockOffset
; }
600 bool GetOSInfoSupport() const { return m_fOsInfoSupport
; }
602 bool GetVBTTags() const { return m_fValueBasedTypeTags
; }
604 uint16
GetLastPartAsked() const { return m_lastPartAsked
; }
606 void SetLastPartAsked(uint16 nPart
) { m_lastPartAsked
= nPart
; }
608 CFriend
* GetFriend() const { return m_Friend
; }
610 void SetFriend(CFriend
* newfriend
) { m_Friend
= newfriend
; }
612 bool IsIdentified() const;
614 bool IsBadGuy() const;
616 bool SUIFailed() const;
618 bool SUINeeded() const;
620 bool SUINotSupported() const;
622 uint64
GetDownloadedTotal() const;
624 uint64
GetUploadedTotal() const;
626 double GetScoreRatio() const;
628 uint32
GetCreationTime() const { return m_nCreationTime
; }
630 bool SupportsLargeFiles() const { return m_fSupportsLargeFiles
; }
632 EIdentState
GetCurrentIdentState() const { return credits
? credits
->GetCurrentIdentState(GetIP()) : IS_NOTAVAILABLE
; }
635 /* Kry - Debug. See connection_reason definition comment below */
636 void SetConnectionReason(const wxString
& reason
) { connection_reason
= reason
; }
639 // Encryption / Obfuscation / ConnectOptions
640 bool SupportsCryptLayer() const { return m_fSupportsCryptLayer
; }
641 bool RequestsCryptLayer() const { return SupportsCryptLayer() && m_fRequestsCryptLayer
; }
642 bool RequiresCryptLayer() const { return RequestsCryptLayer() && m_fRequiresCryptLayer
; }
643 bool SupportsDirectUDPCallback() const { return m_fDirectUDPCallback
!= 0 && HasValidHash() && GetKadPort() != 0; }
644 uint32_t GetDirectCallbackTimeout() const { return m_dwDirectCallbackTimeout
; }
645 bool HasObfuscatedConnectionBeenEstablished() const { return m_hasbeenobfuscatinglately
; }
647 void SetCryptLayerSupport(bool bVal
) { m_fSupportsCryptLayer
= bVal
? 1 : 0; }
648 void SetCryptLayerRequest(bool bVal
) { m_fRequestsCryptLayer
= bVal
? 1 : 0; }
649 void SetCryptLayerRequires(bool bVal
) { m_fRequiresCryptLayer
= bVal
? 1 : 0; }
650 void SetDirectUDPCallbackSupport(bool bVal
) { m_fDirectUDPCallback
= bVal
? 1 : 0; }
651 void SetConnectOptions(uint8_t options
, bool encryption
= true, bool callback
= true); // shortcut, sets crypt, callback, etc from the tagvalue we receive
652 bool ShouldReceiveCryptUDPPackets() const;
654 bool HasDisabledSharedFiles() const { return m_fNoViewSharedFiles
; }
658 CClientCredits
*credits
;
661 uint64 m_nTransferredUp
;
662 sint64 m_nCurQueueSessionPayloadUp
;
663 sint64 m_addedPayloadQueueSession
;
665 struct TransferredData
{
670 //////////////////////////////////////////////////////////
671 // Upload data rate computation
673 uint32 m_nUpDatarate
;
674 uint32 m_nSumForAvgUpDataRate
;
675 std::list
<TransferredData
> m_AvarageUDR_list
;
679 * This struct is used to keep track of CPartFiles which this source shares.
682 //! Signifies if this sources has needed parts for this file.
684 //! This is set when we wish to avoid swapping to this file for a while.
688 //! I typedef in the name of readability!
689 typedef std::map
<CPartFile
*, A4AFStamp
> A4AFList
;
690 //! This list contains all PartFiles which this client can be used as a source for.
691 A4AFList m_A4AF_list
;
694 * Helper function used by SwapToAnotherFile().
696 * @param it The iterator of the PartFile to be examined.
697 * @param ignorenoneeded Do not check for the status NoNeededParts when checking the file.
698 * @param ignoresuspended Do not check the timestamp when checking the file.
699 * @return True if the file is a viable target, false otherwise.
701 * This function is used to perform checks to see if we should consider
702 * this file a viable target for A4AF swapping. Unless ignoresuspended is
703 * true, it will examine the timestamp of the file and reset it if needed.
705 bool IsValidSwapTarget( A4AFList::iterator it
, bool ignorenoneeded
= false, bool ignoresuspended
= false );
707 CPartFile
* m_reqfile
;
711 bool ProcessHelloTypePacket(const CMemFile
& data
);
712 void SendHelloTypePacket(CMemFile
* data
);
713 void SendFirewallCheckUDPRequest();
714 void ClearHelloProperties(); // eMule 0.42
717 uint32 m_nConnectIP
; // holds the supposed IP or (after we had a connection) the real IP
719 uint32 m_nUserIDHybrid
;
720 uint16_t m_nUserPort
;
722 uint32 m_nClientVersion
;
724 uint8 m_byEmuleVersion
;
725 uint8 m_byDataCompVer
;
726 bool m_bEmuleProtocol
;
733 uint8 m_bySourceExchange1Ver
;
734 uint8 m_byAcceptCommentVer
;
735 uint8 m_byExtendedRequestsVer
;
737 uint32 m_dwLastSourceRequest
;
738 uint32 m_dwLastSourceAnswer
;
739 uint32 m_dwLastAskedForSources
;
740 int m_iFileListRequested
;
742 bool m_bCommentDirty
;
745 bool m_bSupportsPreview
;
746 bool m_bUnicodeSupport
;
749 ClientState m_clientState
;
750 CClientTCPSocket
* m_socket
;
751 bool m_fNeedOurPublicIP
; // we requested our IP from this client
753 // Kry - Secure User Ident import
754 ESecureIdentState m_SecureIdentState
;
755 uint8 m_byInfopacketsReceived
; // have we received the edonkeyprot and emuleprot packet already (see InfoPacketsReceived() )
756 uint32 m_dwLastSignatureIP
;
757 uint8 m_bySupportSecIdent
;
759 uint32 m_byCompatibleClient
;
760 std::list
<CPacket
*> m_WaitingPackets_list
;
761 uint32 m_lastRefreshedDLDisplay
;
764 void CreateStandartPackets(const unsigned char* data
,uint32 togo
, Requested_Block_Struct
* currentblock
);
765 void CreatePackedPackets(const unsigned char* data
,uint32 togo
, Requested_Block_Struct
* currentblock
);
767 uint8 m_nUploadState
;
768 uint32 m_dwUploadTime
;
770 uint32 m_dwLastUpRequest
;
771 uint32 m_nCurSessionUp
;
772 uint16 m_nUpPartCount
;
773 CMD4Hash m_requpfileid
;
774 uint16 m_nUpCompleteSourcesCount
;
776 //! This vector contains the avilability of parts for the file that the user
777 //! is requesting. When changing it, be sure to call CKnownFile::UpdatePartsFrequency
778 //! so that the files know the actual availability of parts.
779 BitVector m_upPartStatus
;
780 uint16 m_lastPartAsked
;
781 wxString m_strModVersion
;
783 std::list
<Requested_Block_Struct
*> m_BlockRequests_queue
;
784 std::list
<Requested_Block_Struct
*> m_DoneBlocks_list
;
787 bool m_bRemoteQueueFull
;
788 uint8 m_nDownloadState
;
790 uint32 m_dwLastAskedTime
;
791 wxString m_clientFilename
;
792 uint64 m_nTransferredDown
;
793 uint32 m_nLastBlockOffset
; // Patch for show parts that you download [Cax2]
795 uint32 m_dwLastBlockReceived
;
796 uint16 m_nRemoteQueueRank
;
797 uint16 m_nOldRemoteQueueRank
;
798 bool m_bCompleteSource
;
799 bool m_bReaskPending
;
801 bool m_bHashsetRequested
;
803 std::list
<Pending_Block_Struct
*> m_PendingBlocks_list
;
804 std::list
<Requested_Block_Struct
*> m_DownloadBlocks_list
;
806 // download speed calculation
808 uint32 msReceivedPrev
;
809 uint32 bytesReceivedCycle
;
811 wxString m_strComment
;
813 uint8 m_nChatCaptchaState
;
814 uint8 m_cCaptchasSent
;
816 uint8 m_cMessagesReceived
; // count of chatmessages he sent to me
817 uint8 m_cMessagesSent
; // count of chatmessages I sent to him
818 wxString m_strCaptchaChallenge
;
819 wxString m_strCaptchaPendingMsg
;
822 m_fHashsetRequesting
: 1, // we have sent a hashset request to this client
823 m_fNoViewSharedFiles
: 1, // client has disabled the 'View Shared Files' feature,
824 // if this flag is not set, we just know that we don't know
825 // for sure if it is enabled
826 m_fSupportsPreview
: 1,
828 m_fSentCancelTransfer
: 1, // we have sent an OP_CANCELTRANSFER in the current connection
829 m_fSharedDirectories
: 1, // client supports OP_ASKSHAREDIRS opcodes
831 m_fAICHRequested
: 1,
832 m_fSupportsLargeFiles
: 1,
833 m_fSentOutOfPartReqs
: 1,
834 m_fExtMultiPacket
: 1,
835 m_fRequestsCryptLayer
: 1,
836 m_fSupportsCryptLayer
: 1,
837 m_fRequiresCryptLayer
: 1,
838 m_fSupportsSourceEx2
: 1,
839 m_fSupportsCaptcha
: 1,
840 m_fDirectUDPCallback
: 1;
843 m_fOsInfoSupport
: 1,
844 m_fValueBasedTypeTags
: 1;
846 /* Razor 1a - Modif by MikaelB */
848 bool m_bHelloAnswerPending
;
850 //! This vector contains the avilability of parts for the file we requested
851 //! from this user. When changing it, be sure to call CPartFile::UpdatePartsFrequency
852 //! so that the files know the actual availability of parts.
853 BitVector m_downPartStatus
;
855 CAICHHash
* m_pReqFileAICHHash
;
857 ESourceFrom m_nSourceFrom
;
860 byte m_achBuddyID
[16];
861 bool m_bBuddyIDValid
;
865 EKadState m_nKadState
;
867 uint8 m_byKadVersion
;
868 uint32 m_dwLastBuddyPingPongTime
;
869 uint32_t m_dwDirectCallbackTimeout
;
871 //! This keeps track of aggressive requests for files.
872 uint16 m_Aggressiveness
;
873 //! This tracks the time of the last time since a file was requested
874 uint32 m_LastFileRequest
;
878 wxString m_clientSoftString
; /* software name */
879 wxString m_clientVerString
; /* version + optional mod name */
880 wxString m_clientVersionString
; /* version string */
881 wxString m_fullClientVerString
; /* full info string */
882 wxString m_sClientOSInfo
;
883 wxString m_pendingMessage
;
887 CKnownFile
* m_uploadingfile
;
889 uint8 m_MaxBlockRequests
;
892 uint32 m_lastClientSoft
;
893 uint32 m_lastClientVersion
;
894 wxString m_lastOSInfo
;
896 /* For buddies timeout */
897 uint32 m_nCreationTime
;
899 /* Calculation of last average speed */
900 uint32 m_lastaverage
;
901 uint32 m_last_block_start
;
903 /* Save the encryption status for display when disconnected */
904 bool m_hasbeenobfuscatinglately
;
906 /* Kry - Debug thing. Clients created just to check their data
907 have this string set to the reason we want to check them.
908 Obviously, once checked, we disconnect them. Take that, sucker.
909 This debug code is just for me I'm afraid. */
911 wxString connection_reason
;
916 #define MAKE_CLIENT_VERSION(mjr, min, upd) \
917 ((uint32)(mjr)*100U*10U*100U + (uint32)(min)*100U*10U + (uint32)(upd)*100U)
920 #endif // UPDOWNCLIENT_H
921 // File_checked_for_headers