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"
38 typedef std::vector
<bool> BitVector
;
41 class CClientTCPSocket
;
51 #define US_UPLOADING 0
52 #define US_ONUPLOADQUEUE 1
53 #define US_WAITCALLBACK 2
54 #define US_CONNECTING 3
56 #define US_LOWTOLOWIP 5
77 DS_REMOTEQUEUEFULL
// not used yet, except in statistics
100 enum ESecureIdentState
{
102 IS_ALLREQUESTSSEND
= 0,
103 IS_SIGNATURENEEDED
= 1,
104 IS_KEYANDSIGNEEDED
= 2
107 enum EInfoPacketState
{
109 IP_EDONKEYPROTPACK
= 1,
110 IP_EMULEPROTPACK
= 2,
117 KS_CONNECTING_FWCHECK
,
118 KS_CONNECTED_FWCHECK
,
123 KS_QUEUED_FWCHECK_UDP
,
125 KS_CONNECTING_FWCHECK_UDP
128 //! Used to keep track of the state of the client
131 //! New is for clients that have just been created.
133 //! Listed is for clients that are on the clientlist
135 //! Dying signifies clients that have been queued for deletion
139 // This is fixed on ed2k v1, but can be any number on ED2Kv2
140 #define STANDARD_BLOCKS_REQUEST 3
144 friend class CClientList
;
145 friend class CUpDownClientListRem
;
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.
156 CUpDownClient(class CEC_UpDownClient_Tag
*);
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
);
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
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);
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 wxString
GetFullIP() const { return Uint32toStringIP(m_FullUserIP
); }
198 uint32
GetConnectIP() const { return m_nConnectIP
; }
199 uint32
GetUserIDHybrid() const { return m_nUserIDHybrid
; }
200 void SetUserIDHybrid(uint32 val
);
201 uint16_t GetUserPort() const { return m_nUserPort
; }
202 void SetUserPort(uint16_t port
) { m_nUserPort
= port
; }
203 uint32
GetTransferredDown() const { return m_nTransferredDown
; }
204 uint32
GetServerIP() const { return m_dwServerIP
; }
205 void SetServerIP(uint32 nIP
) { m_dwServerIP
= nIP
; }
206 uint16
GetServerPort() const { return m_nServerPort
; }
207 void SetServerPort(uint16 nPort
) { m_nServerPort
= nPort
; }
208 const CMD4Hash
& GetUserHash() const { return m_UserHash
; }
209 void SetUserHash(const CMD4Hash
& userhash
);
210 void ValidateHash() { m_HasValidHash
= !m_UserHash
.IsEmpty(); }
211 bool HasValidHash() const { return m_HasValidHash
; }
212 uint32
GetVersion() const { return m_nClientVersion
;}
213 uint8
GetMuleVersion() const { return m_byEmuleVersion
;}
214 bool ExtProtocolAvailable() const { return m_bEmuleProtocol
;}
215 bool IsEmuleClient() const { return (m_byEmuleVersion
> 0);}
216 bool IsBanned() const;
217 const wxString
& GetClientFilename() const { return m_clientFilename
; }
218 uint16
GetUDPPort() const { return m_nUDPPort
; }
219 void SetUDPPort(uint16 nPort
) { m_nUDPPort
= nPort
; }
220 uint8
GetUDPVersion() const { return m_byUDPVer
; }
221 uint8
GetExtendedRequestsVersion() const { return m_byExtendedRequestsVer
; }
222 bool IsFriend() const { return m_Friend
!= NULL
; }
223 bool IsML() const { return m_bIsML
; }
224 bool IsHybrid() const { return m_bIsHybrid
; }
225 uint32
GetCompatibleClient() const { return m_byCompatibleClient
; }
227 void ClearDownloadBlockRequests();
228 void RequestSharedFileList();
229 void ProcessSharedFileList(const byte
* pachPacket
, uint32 nSize
, wxString
& pszDirectory
);
231 wxString
GetUploadFileInfo();
233 void SetUserName(const wxString
& NewName
) { m_Username
= NewName
; }
235 uint8
GetClientSoft() const { return m_clientSoft
; }
236 void ReGetClientSoft();
237 bool ProcessHelloAnswer(const byte
* pachPacket
, uint32 nSize
);
238 bool ProcessHelloPacket(const byte
* pachPacket
, uint32 nSize
);
239 void SendHelloAnswer();
240 bool SendHelloPacket();
241 void SendMuleInfoPacket(bool bAnswer
, bool OSInfo
= false);
242 bool ProcessMuleInfoPacket(const byte
* pachPacket
, uint32 nSize
);
243 void ProcessMuleCommentPacket(const byte
* pachPacket
, uint32 nSize
);
244 bool Compare(const CUpDownClient
* tocomp
, bool bIgnoreUserhash
= false) const;
245 void SetLastSrcReqTime() { m_dwLastSourceRequest
= ::GetTickCount(); }
246 void SetLastSrcAnswerTime() { m_dwLastSourceAnswer
= ::GetTickCount(); }
247 void SetLastAskedForSources() { m_dwLastAskedForSources
= ::GetTickCount(); }
248 uint32
GetLastSrcReqTime() const { return m_dwLastSourceRequest
; }
249 uint32
GetLastSrcAnswerTime() const { return m_dwLastSourceAnswer
; }
250 uint32
GetLastAskedForSources() const { return m_dwLastAskedForSources
; }
251 bool GetFriendSlot() const { return m_bFriendSlot
; }
252 void SetFriendSlot(bool bNV
) { m_bFriendSlot
= bNV
; }
253 void SetCommentDirty(bool bDirty
= true) { m_bCommentDirty
= bDirty
; }
254 uint8
GetSourceExchange1Version() const { return m_bySourceExchange1Ver
; }
255 bool SupportsSourceExchange2() const { return m_fSupportsSourceEx2
; }
257 bool SafeSendPacket(CPacket
* packet
);
259 void ProcessRequestPartsPacket(const byte
* pachPacket
, uint32 nSize
, bool largeblocks
);
260 void ProcessRequestPartsPacketv2(const CMemFile
& data
);
262 void SendPublicKeyPacket();
263 void SendSignaturePacket();
264 void ProcessPublicKeyPacket(const byte
* pachPacket
, uint32 nSize
);
265 void ProcessSignaturePacket(const byte
* pachPacket
, uint32 nSize
);
266 uint8
GetSecureIdentState();
268 void SendSecIdentStatePacket();
269 void ProcessSecIdentStatePacket(const byte
* pachPacket
, uint32 nSize
);
271 uint8
GetInfoPacketsReceived() const { return m_byInfopacketsReceived
; }
272 void InfoPacketsReceived();
275 uint8
GetUploadState() const { return m_nUploadState
; }
276 void SetUploadState(uint8 news
);
277 uint32
GetTransferredUp() const { return m_nTransferredUp
; }
278 uint32
GetSessionUp() const { return m_nTransferredUp
- m_nCurSessionUp
; }
279 void ResetSessionUp() {
280 m_nCurSessionUp
= m_nTransferredUp
;
281 m_addedPayloadQueueSession
= 0;
282 m_nCurQueueSessionPayloadUp
= 0;
284 uint32
GetUploadDatarate() const { return m_nUpDatarate
; }
287 uint32
GetWaitTime() const { return m_dwUploadTime
- GetWaitStartTime(); }
288 uint32
GetUpStartTimeDelay() const { return ::GetTickCount() - m_dwUploadTime
; }
289 uint32
GetWaitStartTime() const;
291 uint32 m_WaitTime
, m_UpStartTimeDelay
, m_WaitStartTime
;
292 uint32
GetWaitTime() const { return m_WaitTime
; }
293 uint32
GetUpStartTimeDelay() const { return m_UpStartTimeDelay
; }
294 uint32
GetWaitStartTime() const { return m_WaitStartTime
; }
297 bool IsDownloading() const { return (m_nUploadState
== US_UPLOADING
); }
302 bool isdownloading
= false,
303 bool onlybasevalue
= false) const;
307 bool WXUNUSED(sysvalue
),
308 bool WXUNUSED(isdownloading
) = false,
309 bool WXUNUSED(onlybasevalue
) = false) const
313 uint16 m_waitingPosition
;
314 uint16
GetWaitingPosition() const { return m_waitingPosition
; }
316 double GetRating() const
318 return (double)GetScore(false, IsDownloading(), true);
321 void AddReqBlock(Requested_Block_Struct
* reqblock
);
322 void CreateNextBlockPackage();
323 void SetUpStartTime() { m_dwUploadTime
= ::GetTickCount(); }
324 void SetWaitStartTime();
325 void ClearWaitStartTime();
326 void SendHashsetPacket(const CMD4Hash
& forfileid
);
327 bool SupportMultiPacket() const { return m_bMultiPacket
; }
328 bool SupportExtMultiPacket() const { return m_fExtMultiPacket
; }
330 void SetUploadFileID(CKnownFile
*newreqfile
);
333 *Gets the file actually on upload
336 const CKnownFile
* GetUploadFile() const { return m_uploadingfile
; }
338 void SendOutOfPartReqsAndAddToWaitingQueue();
339 void ProcessExtendedInfo(const CMemFile
*data
, CKnownFile
*tempreqfile
);
340 void ProcessFileInfo(const CMemFile
* data
, const CPartFile
* file
);
341 void ProcessFileStatus(bool bUdpPacket
, const CMemFile
* data
, const CPartFile
* file
);
343 const CMD4Hash
& GetUploadFileID() const { return m_requpfileid
; }
344 void SetUploadFileID(const CMD4Hash
& new_id
);
345 void ClearUploadFileID() { m_requpfileid
.Clear(); m_uploadingfile
= NULL
;};
346 uint32
SendBlockData();
347 void ClearUploadBlockRequests();
348 void SendRankingInfo();
349 void SendCommentInfo(CKnownFile
*file
);
350 bool IsDifferentPartBlock() const;
353 bool m_bAddNextConnect
; // VQB Fix for LowID slots only on connection
354 uint32
GetAskedCount() const { return m_cAsked
; }
355 void AddAskedCount() { m_cAsked
++; }
356 void ClearAskedCount() { m_cAsked
= 1; } // 1, because it's cleared *after* the first request...
357 void FlushSendBlocks(); // call this when you stop upload,
358 // or the socket might be not able to send
359 void SetLastUpRequest() { m_dwLastUpRequest
= ::GetTickCount(); }
360 uint32
GetLastUpRequest() const { return m_dwLastUpRequest
; }
361 size_t GetUpPartCount() const { return m_upPartStatus
.size(); }
365 void SetRequestFile(CPartFile
* reqfile
);
366 CPartFile
* GetRequestFile() const { return m_reqfile
; }
368 uint8
GetDownloadState() const { return m_nDownloadState
; }
369 void SetDownloadState(uint8 byNewState
);
370 uint32
GetLastAskedTime() const { return m_dwLastAskedTime
; }
372 bool IsPartAvailable(uint16 iPart
) const
373 { return ( iPart
< m_downPartStatus
.size() ) ? m_downPartStatus
[iPart
] : 0; }
374 bool IsUpPartAvailable(uint16 iPart
) const
375 { return ( iPart
< m_upPartStatus
.size() ) ? m_upPartStatus
[iPart
] : 0;}
377 const BitVector
& GetPartStatus() const { return m_downPartStatus
; }
378 const BitVector
& GetUpPartStatus() const { return m_upPartStatus
; }
379 float GetKBpsDown() const { return kBpsDown
; }
380 float CalculateKBpsDown();
381 uint16
GetRemoteQueueRank() const { return m_nRemoteQueueRank
; }
382 uint16
GetOldRemoteQueueRank() const { return m_nOldRemoteQueueRank
; }
383 void SetRemoteQueueFull(bool flag
) { m_bRemoteQueueFull
= flag
; }
384 bool IsRemoteQueueFull() const { return m_bRemoteQueueFull
; }
385 void SetRemoteQueueRank(uint16 nr
);
386 bool AskForDownload();
387 void SendStartupLoadReq();
388 void SendFileRequest();
389 void ProcessHashSet(const byte
* packet
, uint32 size
);
390 bool AddRequestForAnotherFile(CPartFile
* file
);
391 bool DeleteFileRequest(CPartFile
* file
);
392 void DeleteAllFileRequests();
393 void SendBlockRequests();
394 void ProcessBlockPacket(const byte
* packet
, uint32 size
, bool packed
, bool largeblocks
);
397 uint16
GetAvailablePartCount() const;
399 uint16 m_AvailPartCount
;
400 uint16
GetAvailablePartCount() const { return m_AvailPartCount
; }
403 bool SwapToAnotherFile(bool bIgnoreNoNeeded
, bool ignoreSuspensions
, bool bRemoveCompletely
, CPartFile
* toFile
= NULL
);
404 void UDPReaskACK(uint16 nNewQR
);
406 void UDPReaskForDownload();
407 bool IsSourceRequestAllowed();
408 uint16
GetUpCompleteSourcesCount() const { return m_nUpCompleteSourcesCount
; }
409 void SetUpCompleteSourcesCount(uint16 n
) { m_nUpCompleteSourcesCount
= n
; }
412 uint8
GetChatState() { return m_byChatstate
; }
413 void SetChatState(uint8 nNewS
) { m_byChatstate
= nNewS
; }
416 const wxString
& GetFileComment() const { return m_strComment
; }
417 uint8
GetFileRating() const { return m_iRating
; }
419 const wxString
& GetSoftStr() const { return m_clientSoftString
; }
420 const wxString
& GetSoftVerStr() const { return m_clientVerString
; }
422 const wxString
GetServerName() const;
424 wxString m_ServerName
;
425 const wxString
& GetServerName() const { return m_ServerName
; }
428 uint16
GetKadPort() const { return m_nKadPort
; }
429 void SetKadPort(uint16 nPort
) { m_nKadPort
= nPort
; }
432 void SetReqFileAICHHash(CAICHHash
* val
);
433 CAICHHash
* GetReqFileAICHHash() const {return m_pReqFileAICHHash
;}
434 bool IsSupportingAICH() const {return m_fSupportsAICH
& 0x01;}
435 void SendAICHRequest(CPartFile
* pForFile
, uint16 nPart
);
436 bool IsAICHReqPending() const {return m_fAICHRequested
; }
437 void ProcessAICHAnswer(const byte
* packet
, uint32 size
);
438 void ProcessAICHRequest(const byte
* packet
, uint32 size
);
439 void ProcessAICHFileHash(CMemFile
* data
, const CPartFile
* file
);
441 EUtf8Str
GetUnicodeSupport() const;
443 // Barry - Process zip file as it arrives, don't need to wait until end of block
444 int unzip(Pending_Block_Struct
*block
, byte
*zipped
, uint32 lenZipped
, byte
**unzipped
, uint32
*lenUnzipped
, int iRecursion
= 0);
445 // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
446 wxString
ShowDownloadingParts() const;
447 void UpdateDisplayedInfo(bool force
= false);
448 int GetFileListRequested() const { return m_iFileListRequested
; }
449 void SetFileListRequested(int iFileListRequested
) { m_iFileListRequested
= iFileListRequested
; }
451 void ResetFileStatusInfo();
453 bool CheckHandshakeFinished(uint32 protocol
, uint32 opcode
) const;
455 bool GetSentCancelTransfer() const { return m_fSentCancelTransfer
; }
456 void SetSentCancelTransfer(bool bVal
) { m_fSentCancelTransfer
= bVal
; }
458 wxString
GetClientFullInfo();
460 const wxString
& GetClientOSInfo() const { return m_sClientOSInfo
; }
462 void ProcessPublicIPAnswer(const byte
* pbyData
, uint32 uSize
);
463 void SendPublicIPRequest();
466 * Sets the current socket of the client.
468 * @param socket The pointer to the new socket, can be NULL.
470 * Please note that this function DOES NOT delete the old socket.
472 void SetSocket(CClientTCPSocket
* socket
);
475 * Function for accessing the socket owned by a client.
477 * @return The pointer (can be NULL) to the socket used by this client.
479 * Please note that the socket object is quite volatile and can be removed
480 * from one function call to the next, therefore, you should normally use
481 * the safer functions below, which all check if the socket is valid before
484 CClientTCPSocket
* GetSocket() const { return m_socket
; }
487 * Safe function for checking if the socket is connected.
489 * @return True if the socket exists and is connected, false otherwise.
492 bool IsConnected() const;
495 bool IsConnected() const { return m_IsConnected
; }
499 * Safe function for sending packets.
501 * @return True if the socket exists and the packet was sent, false otherwise.
503 bool SendPacket(CPacket
* packet
, bool delpacket
= true, bool controlpacket
= true);
506 * Safe function for setting the download limit of the socket.
508 * @return Current download speed of the client.
510 float SetDownloadLimit(uint32 reducedownload
);
513 * Sends a message to a client
515 * @return True if sent, false if connecting
517 bool SendMessage(const wxString
& message
);
519 uint32
GetPayloadInBuffer() const { return m_addedPayloadQueueSession
- GetQueueSessionPayloadUp(); }
520 uint32
GetQueueSessionPayloadUp() const { return m_nCurQueueSessionPayloadUp
; }
521 bool HasBlocks() const { return !m_BlockRequests_queue
.empty(); }
523 /* Source comes from? */
524 ESourceFrom
GetSourceFrom() const { return (ESourceFrom
)m_nSourceFrom
; }
525 void SetSourceFrom(ESourceFrom val
) { m_nSourceFrom
= val
; }
527 /* Kad buddy support */
529 const byte
* GetBuddyID() const { return m_achBuddyID
; }
530 void SetBuddyID(const byte
* m_achTempBuddyID
);
531 bool HasValidBuddyID() const { return m_bBuddyIDValid
; }
533 void SetBuddyIP( uint32 val
) { m_nBuddyIP
= val
; }
534 uint32
GetBuddyIP() const { return m_nBuddyIP
; }
536 void SetBuddyPort( uint16 val
) { m_nBuddyPort
= val
; }
537 uint16
GetBuddyPort() const { return m_nBuddyPort
; }
540 bool SendBuddyPingPong() { return m_dwLastBuddyPingPongTime
< ::GetTickCount(); }
541 bool AllowIncomeingBuddyPingPong() { return m_dwLastBuddyPingPongTime
< (::GetTickCount()-(3*60*1000)); }
542 void SetLastBuddyPingPongTime() { m_dwLastBuddyPingPongTime
= (::GetTickCount()+(10*60*1000)); }
543 EKadState
GetKadState() const { return m_nKadState
; }
544 void SetKadState(EKadState nNewS
) { m_nKadState
= nNewS
; }
545 uint8
GetKadVersion() { return m_byKadVersion
; }
546 void ProcessFirewallCheckUDPRequest(CMemFile
*data
);
548 bool SendBuddyPing();
550 /* Returns the client hash type (SO_EMULE, mldonkey, etc) */
551 int GetHashType() const;
554 * Checks that a client isn't aggressively re-asking for files.
556 * Call this when a file is requested. If the time since the last request is
557 * less than MIN_REQUESTTIME, 3 is added to the m_Aggressiveness variable.
558 * If the time since the last request is >= MIN_REQUESTTIME, the variable is
559 * decremented by 1. The client is banned if the variable reaches 10 or above.
561 * To check if a client is aggressive use the IsClientAggressive() function.
563 * Currently this function is called when the following packets are received:
564 * - OP_STARTUPLOADREQ
567 void CheckForAggressive();
569 const wxString
& GetClientModString() const { return m_strModVersion
; }
571 const wxString
& GetClientVerString() const { return m_fullClientVerString
; }
573 const wxString
& GetVersionString() const { return m_clientVersionString
; }
577 /* Returns a pointer to the credits, only for hash purposes */
578 void* GetCreditsHash() const { return (void*)credits
; }
580 uint32
GetLastBlockOffset() const { return m_nLastBlockOffset
; }
582 bool GetOSInfoSupport() const { return m_fOsInfoSupport
; }
584 bool GetVBTTags() const { return m_fValueBasedTypeTags
; }
586 uint16
GetLastPartAsked() const { return m_lastPartAsked
; }
588 void SetLastPartAsked(uint16 nPart
) { m_lastPartAsked
= nPart
; }
590 CFriend
* GetFriend() const { return m_Friend
; }
592 void SetFriend(CFriend
* newfriend
) { m_Friend
= newfriend
; }
594 bool IsIdentified() const;
596 bool IsBadGuy() const;
598 bool SUIFailed() const;
600 bool SUINeeded() const;
602 bool SUINotSupported() const;
604 uint64
GetDownloadedTotal() const;
606 uint64
GetUploadedTotal() const;
608 double GetScoreRatio() const;
610 uint32
GetCreationTime() const { return m_nCreationTime
; }
612 bool SupportsLargeFiles() const { return m_fSupportsLargeFiles
; }
615 /* Kry - Debug. See connection_reason definition comment below */
616 void SetConnectionReason(const wxString
& reason
) { connection_reason
= reason
; }
619 // Encryption / Obfuscation / ConnectOptions
620 bool SupportsCryptLayer() const { return m_fSupportsCryptLayer
; }
621 bool RequestsCryptLayer() const { return SupportsCryptLayer() && m_fRequestsCryptLayer
; }
622 bool RequiresCryptLayer() const { return RequestsCryptLayer() && m_fRequiresCryptLayer
; }
623 bool SupportsDirectUDPCallback() const { return m_fDirectUDPCallback
!= 0 && HasValidHash() && GetKadPort() != 0; }
624 uint32_t GetDirectCallbackTimeout() const { return m_dwDirectCallbackTimeout
; }
625 bool HasObfuscatedConnectionBeenEstablished() const { return m_hasbeenobfuscatinglately
; }
627 void SetCryptLayerSupport(bool bVal
) { m_fSupportsCryptLayer
= bVal
? 1 : 0; }
628 void SetCryptLayerRequest(bool bVal
) { m_fRequestsCryptLayer
= bVal
? 1 : 0; }
629 void SetCryptLayerRequires(bool bVal
) { m_fRequiresCryptLayer
= bVal
? 1 : 0; }
630 void SetDirectUDPCallbackSupport(bool bVal
) { m_fDirectUDPCallback
= bVal
? 1 : 0; }
631 void SetConnectOptions(uint8_t options
, bool encryption
= true, bool callback
= true); // shortcut, sets crypt, callback, etc from the tagvalue we receive
632 bool ShouldReceiveCryptUDPPackets() const;
634 bool HasDisabledSharedFiles() const { return m_fNoViewSharedFiles
; }
638 CClientCredits
*credits
;
641 uint32 m_nTransferredUp
;
642 uint32 m_nCurQueueSessionPayloadUp
;
643 uint32 m_addedPayloadQueueSession
;
645 struct TransferredData
{
650 //////////////////////////////////////////////////////////
651 // Upload data rate computation
653 uint32 m_nUpDatarate
;
654 uint32 m_nSumForAvgUpDataRate
;
655 std::list
<TransferredData
> m_AvarageUDR_list
;
659 * This struct is used to keep track of CPartFiles which this source shares.
662 //! Signifies if this sources has needed parts for this file.
664 //! This is set when we wish to avoid swapping to this file for a while.
668 //! I typedef in the name of readability!
669 typedef std::map
<CPartFile
*, A4AFStamp
> A4AFList
;
670 //! This list contains all PartFiles which this client can be used as a source for.
671 A4AFList m_A4AF_list
;
674 * Helper function used by SwapToAnotherFile().
676 * @param it The iterator of the PartFile to be examined.
677 * @param ignorenoneeded Do not check for the status NoNeededParts when checking the file.
678 * @param ignoresuspended Do not check the timestamp when checking the file.
679 * @return True if the file is a viable target, false otherwise.
681 * This function is used to perform checks to see if we should consider
682 * this file a viable target for A4AF swapping. Unless ignoresuspended is
683 * true, it will examine the timestamp of the file and reset it if needed.
685 bool IsValidSwapTarget( A4AFList::iterator it
, bool ignorenoneeded
= false, bool ignoresuspended
= false );
687 CPartFile
* m_reqfile
;
691 bool ProcessHelloTypePacket(const CMemFile
& data
);
692 void SendHelloTypePacket(CMemFile
* data
);
693 void SendFirewallCheckUDPRequest();
694 void ClearHelloProperties(); // eMule 0.42
696 uint32 m_nConnectIP
; // holds the supposed IP or (after we had a connection) the real IP
698 uint32 m_nUserIDHybrid
;
699 uint16_t m_nUserPort
;
701 uint32 m_nClientVersion
;
703 uint8 m_byEmuleVersion
;
704 uint8 m_byDataCompVer
;
705 bool m_bEmuleProtocol
;
712 uint8 m_bySourceExchange1Ver
;
713 uint8 m_byAcceptCommentVer
;
714 uint8 m_byExtendedRequestsVer
;
716 uint32 m_dwLastSourceRequest
;
717 uint32 m_dwLastSourceAnswer
;
718 uint32 m_dwLastAskedForSources
;
719 int m_iFileListRequested
;
721 bool m_bCommentDirty
;
724 bool m_bSupportsPreview
;
725 bool m_bUnicodeSupport
;
728 ClientState m_clientState
;
729 CClientTCPSocket
* m_socket
;
730 bool m_fNeedOurPublicIP
; // we requested our IP from this client
732 // Kry - Secure User Ident import
733 ESecureIdentState m_SecureIdentState
;
734 uint8 m_byInfopacketsReceived
; // have we received the edonkeyprot and emuleprot packet already (see InfoPacketsReceived() )
735 uint32 m_dwLastSignatureIP
;
736 uint8 m_bySupportSecIdent
;
738 uint32 m_byCompatibleClient
;
739 std::list
<CPacket
*> m_WaitingPackets_list
;
740 uint32 m_lastRefreshedDLDisplay
;
743 void CreateStandartPackets(const unsigned char* data
,uint32 togo
, Requested_Block_Struct
* currentblock
);
744 void CreatePackedPackets(const unsigned char* data
,uint32 togo
, Requested_Block_Struct
* currentblock
);
746 uint8 m_nUploadState
;
747 uint32 m_dwUploadTime
;
749 uint32 m_dwLastUpRequest
;
750 uint32 m_nCurSessionUp
;
751 uint16 m_nUpPartCount
;
752 CMD4Hash m_requpfileid
;
753 uint16 m_nUpCompleteSourcesCount
;
755 //! This vector contains the avilability of parts for the file that the user
756 //! is requesting. When changing it, be sure to call CKnownFile::UpdatePartsFrequency
757 //! so that the files know the actual availability of parts.
758 BitVector m_upPartStatus
;
759 uint16 m_lastPartAsked
;
760 wxString m_strModVersion
;
762 std::list
<Requested_Block_Struct
*> m_BlockRequests_queue
;
763 std::list
<Requested_Block_Struct
*> m_DoneBlocks_list
;
766 bool m_bRemoteQueueFull
;
767 uint8 m_nDownloadState
;
769 uint32 m_dwLastAskedTime
;
770 wxString m_clientFilename
;
771 uint32 m_nTransferredDown
;
772 uint32 m_nLastBlockOffset
; // Patch for show parts that you download [Cax2]
774 uint32 m_dwLastBlockReceived
;
775 uint16 m_nRemoteQueueRank
;
776 uint16 m_nOldRemoteQueueRank
;
777 bool m_bCompleteSource
;
778 bool m_bReaskPending
;
780 bool m_bHashsetRequested
;
782 std::list
<Pending_Block_Struct
*> m_PendingBlocks_list
;
783 std::list
<Requested_Block_Struct
*> m_DownloadBlocks_list
;
785 // download speed calculation
787 uint32 msReceivedPrev
;
788 uint32 bytesReceivedCycle
;
791 wxString m_strComment
;
795 m_fHashsetRequesting
: 1, // we have sent a hashset request to this client
796 m_fNoViewSharedFiles
: 1, // client has disabled the 'View Shared Files' feature,
797 // if this flag is not set, we just know that we don't know
798 // for sure if it is enabled
799 m_fSupportsPreview
: 1,
800 m_fSentCancelTransfer
: 1, // we have sent an OP_CANCELTRANSFER in the current connection
801 m_fSharedDirectories
: 1, // client supports OP_ASKSHAREDIRS opcodes
803 m_fAICHRequested
: 1,
804 m_fSupportsLargeFiles
: 1,
805 m_fSentOutOfPartReqs
: 1,
806 m_fExtMultiPacket
: 1,
807 m_fRequestsCryptLayer
: 1,
808 m_fSupportsCryptLayer
: 1,
809 m_fRequiresCryptLayer
: 1,
810 m_fSupportsSourceEx2
: 1,
811 m_fDirectUDPCallback
: 1;
814 m_fOsInfoSupport
: 1,
815 m_fValueBasedTypeTags
: 1;
817 /* Razor 1a - Modif by MikaelB */
819 bool m_bHelloAnswerPending
;
821 //! This vector contains the avilability of parts for the file we requested
822 //! from this user. When changing it, be sure to call CPartFile::UpdatePartsFrequency
823 //! so that the files know the actual availability of parts.
824 BitVector m_downPartStatus
;
826 CAICHHash
* m_pReqFileAICHHash
;
828 ESourceFrom m_nSourceFrom
;
831 byte m_achBuddyID
[16];
832 bool m_bBuddyIDValid
;
836 EKadState m_nKadState
;
838 uint8 m_byKadVersion
;
839 uint32 m_dwLastBuddyPingPongTime
;
840 uint32_t m_dwDirectCallbackTimeout
;
842 //! This keeps track of aggressive requests for files.
843 uint16 m_Aggressiveness
;
844 //! This tracks the time of the last time since a file was requested
845 uint32 m_LastFileRequest
;
849 wxString m_clientSoftString
; /* software name */
850 wxString m_clientVerString
; /* version + optional mod name */
851 wxString m_clientVersionString
; /* version string */
852 wxString m_fullClientVerString
; /* full info string */
853 wxString m_sClientOSInfo
;
854 wxString m_pendingMessage
;
858 CKnownFile
* m_uploadingfile
;
860 uint8 m_MaxBlockRequests
;
863 uint32 m_lastClientSoft
;
864 uint32 m_lastClientVersion
;
865 wxString m_lastOSInfo
;
867 /* For buddies timeout */
868 uint32 m_nCreationTime
;
870 /* Calculation of last average speed */
871 uint32 m_lastaverage
;
872 uint32 m_last_block_start
;
874 /* Save the encryption status for display when disconnected */
875 bool m_hasbeenobfuscatinglately
;
877 /* Kry - Debug thing. Clients created just to check their data
878 have this string set to the reason we want to check them.
879 Obviously, once checked, we disconect them. Take that, sucker.
880 This debug code is just for me I'm afraid. */
882 wxString connection_reason
;
887 #define MAKE_CLIENT_VERSION(mjr, min, upd) \
888 ((uint32)(mjr)*100U*10U*100U + (uint32)(min)*100U*10U + (uint32)(upd)*100U)
891 #endif // UPDOWNCLIENT_H
892 // File_checked_for_headers