📄 updownclient.h
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( merkur-@users.sourceforge.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef __UP_DOWN_CLIENT_H__
#define __UP_DOWN_CLIENT_H__
#pragma once
#include "loggable.h"
#include "BarShader.h"
class CClientReqSocket;
class CPeerCacheDownSocket;
class CPeerCacheUpSocket;
class CFriend;
class CPartFile;
class CClientCredits;
class CAbstractFile;
class CKnownFile;
class Packet;
class CxImage;
struct Requested_Block_Struct;
class CSafeMemFile;
struct Pending_Block_Struct{
Requested_Block_Struct* block;
struct z_stream_s* zStream; // Barry - Used to unzip packets
uint32 totalUnzipped; // Barry - This holds the total unzipped bytes for all packets so far
UINT fZStreamError : 1,
fRecovered : 1;
};
#pragma pack(1)
struct Requested_File_Struct{
uchar fileid[16];
uint32 lastasked;
uint8 badrequests;
};
#pragma pack()
enum EUploadState{
US_UPLOADING,
US_ONUPLOADQUEUE,
US_WAITCALLBACK,
US_CONNECTING,
US_PENDING,
US_LOWTOLOWIP,
US_BANNED,
US_ERROR,
US_NONE
};
enum EDownloadState{
DS_DOWNLOADING,
DS_ONQUEUE,
DS_CONNECTED,
DS_CONNECTING,
DS_WAITCALLBACK,
DS_REQHASHSET,
DS_NONEEDEDPARTS,
DS_TOOMANYCONNS,
DS_LOWTOLOWIP,
DS_BANNED,
DS_ERROR,
DS_NONE,
DS_REMOTEQUEUEFULL // not used yet, except in statistics
};
enum EPeerCacheDownState{
PCDS_NONE = 0,
PCDS_WAIT_CLIENT_REPLY,
PCDS_WAIT_CACHE_REPLY,
PCDS_DOWNLOADING
};
enum EPeerCacheUpState{
PCUS_NONE = 0,
PCUS_WAIT_CACHE_REPLY,
PCUS_UPLOADING
};
enum EChatState{
MS_NONE,
MS_CHATTING,
MS_CONNECTING,
MS_UNABLETOCONNECT
};
enum EKadState{
KS_NONE,
KS_QUEUED_FWCHECK,
KS_CONNECTING_FWCHECK,
KS_CONNECTED_FWCHECK,
KS_QUEUED_BUDDY,
KS_CONNECTED_BUDDY
};
enum EClientSoftware{
SO_EMULE = 0, // default
SO_CDONKEY = 1, // ET_COMPATIBLECLIENT
SO_XMULE = 2, // ET_COMPATIBLECLIENT
SO_AMULE = 3, // ET_COMPATIBLECLIENT
SO_SHAREAZA = 4, // ET_COMPATIBLECLIENT
SO_MLDONKEY = 10, // ET_COMPATIBLECLIENT
SO_LPHANT = 20, // ET_COMPATIBLECLIENT
// other client types which are not identified with ET_COMPATIBLECLIENT
SO_EDONKEYHYBRID = 50,
SO_EDONKEY,
SO_OLDEMULE,
SO_URL,
SO_UNKNOWN
};
enum ESecureIdentState{
IS_UNAVAILABLE = 0,
IS_ALLREQUESTSSEND = 0,
IS_SIGNATURENEEDED = 1,
IS_KEYANDSIGNEEDED = 2,
};
enum EInfoPacketState{
IP_NONE = 0,
IP_EDONKEYPROTPACK = 1,
IP_EMULEPROTPACK = 2,
IP_BOTH = 3,
};
enum ESourceFrom{
SF_SERVER = 0,
SF_KADEMLIA = 1,
SF_SOURCE_EXCHANGE = 2,
SF_PASSIVE = 3,
SF_LINK = 4
};
struct PartFileStamp {
CPartFile* file;
DWORD timestamp;
};
#define MAKE_CLIENT_VERSION(mjr, min, upd) \
((UINT)(mjr)*100U*10U*100U + (UINT)(min)*100U*10U + (UINT)(upd)*100U)
//#pragma pack(2)
class CUpDownClient: public CLoggable
,public CObject
{
DECLARE_DYNAMIC(CUpDownClient)
friend class CUploadQueue;
public:
//base
CUpDownClient(CClientReqSocket* sender = 0);
CUpDownClient(CPartFile* in_reqfile, uint16 in_port, uint32 in_userid, uint32 in_serverup, uint16 in_serverport, bool ed2kID = false);
virtual ~CUpDownClient();
///////////////////////////////////////////////////////////////////////////
// PeerCache client
//
int m_iHttpSendState;
uint32 m_uPeerCacheDownloadPushId;
uint32 m_uPeerCacheUploadPushId;
CPeerCacheDownSocket* m_pPCDownSocket;
CPeerCacheUpSocket* m_pPCUpSocket;
uint32 m_uPeerCacheRemoteIP;
EPeerCacheDownState m_ePeerCacheDownState;
EPeerCacheUpState m_ePeerCacheUpState;
bool m_bPeerCacheDownHit;
bool m_bPeerCacheUpHit;
bool IsDownloadingFromPeerCache() const;
bool IsUploadingToPeerCache() const;
void SetPeerCacheDownState(EPeerCacheDownState eState);
void SetPeerCacheUpState(EPeerCacheUpState eState);
bool SendPeerCacheFileRequest();
bool ProcessPeerCacheQuery(const char* packet, UINT size);
bool ProcessPeerCacheAnswer(const char* packet, UINT size);
bool ProcessPeerCacheAcknowledge(const char* packet, UINT size);
void OnPeerCacheDownSocketClosed(int nErrorCode);
bool OnPeerCacheDownSocketTimeout();
bool ProcessPeerCacheDownHttpResponse(const CStringAArray& astrHeaders);
bool ProcessPeerCacheDownHttpResponseBody(const BYTE* pucData, UINT uSize);
bool ProcessPeerCacheUpHttpResponse(const CStringAArray& astrHeaders);
UINT ProcessPeerCacheUpHttpRequest(const CStringAArray& astrHeaders);
virtual bool ProcessHttpDownResponse(const CStringAArray& astrHeaders);
virtual bool ProcessHttpDownResponseBody(const BYTE* pucData, UINT uSize);
void StartDownload();
virtual void SendCancelTransfer(Packet* packet = NULL);
virtual void CheckDownloadTimeout();
virtual bool IsEd2kClient() const { return true; }
virtual bool Disconnected(LPCTSTR pszReason, bool bFromSocket = false);
virtual bool TryToConnect(bool bIgnoreMaxCon = false, CRuntimeClass* pClassSocket = NULL);
virtual bool Connect();
virtual void ConnectionEstablished();
virtual void OnSocketConnected(int nErrorCode);
bool CheckHandshakeFinished(UINT protocol, UINT opcode) const;
void CheckFailedFileIdReqs(const uchar* aucFileHash);
uint32 GetUserIDHybrid() const
{
return m_nUserIDHybrid;
}
void SetUserIDHybrid(uint32 val)
{
m_nUserIDHybrid = val;
}
LPCTSTR GetUserName() const
{
return m_pszUsername;
}
void SetUserName(LPCTSTR pszNewName);
uint32 GetIP() const
{
return m_dwUserIP;
}
bool HasLowID() const;
uint32 GetConnectIP() const {return m_nConnectIP;}
uint16 GetUserPort() const
{
return m_nUserPort;
}
void SetUserPort(uint16 val)
{
m_nUserPort = val;
}
uint32 GetTransferedUp() const
{
return m_nTransferedUp;
}
uint32 GetTransferedDown() const
{
return m_nTransferedDown;
}
uint32 GetServerIP() const
{
return m_dwServerIP;
}
void SetServerIP(uint32 nIP)
{
m_dwServerIP = nIP;
}
uint16 GetServerPort() const
{
return m_nServerPort;
}
void SetServerPort(uint16 nPort)
{
m_nServerPort = nPort;
}
const uchar* GetUserHash() const
{
return (uchar*)m_achUserHash;
}
void SetUserHash(const uchar* m_achTempUserHash);
bool HasValidHash() const
{
return ((const int*)m_achUserHash[0]) != 0 || ((const int*)m_achUserHash[1]) != 0 || ((const int*)m_achUserHash[2]) != 0 || ((const int*)m_achUserHash[3]) != 0;
}
int GetHashType() const;
EClientSoftware GetClientSoft() const
{
return (EClientSoftware)m_clientSoft;
}
const CString& GetClientSoftVer() const
{
return m_strClientSoftware;
}
const CString& GetClientModVer() const
{
return m_strModVersion;
}
void ReGetClientSoft();
uint32 GetVersion() const
{
return m_nClientVersion;
}
uint8 GetMuleVersion() const
{
return m_byEmuleVersion;
}
bool ExtProtocolAvailable() const
{
return m_bEmuleProtocol;
}
bool SupportMultiPacket()const
{
return m_bMultiPacket;
}
bool SupportPeerCache() const { return m_fPeerCache; }
bool IsEmuleClient() const
{
return m_byEmuleVersion;
}
uint8 GetSourceExchangeVersion() const
{
return m_bySourceExchangeVer;
}
CClientCredits* Credits() const
{
return credits;
}
bool IsBanned() const;
const CString& GetClientFilename() const
{
return m_strClientFilename;
}
void SetClientFilename( CString fileName )
{
m_strClientFilename = fileName;
}
uint16 GetUDPPort() const
{
return m_nUDPPort;
}
void SetUDPPort(uint16 nPort)
{
m_nUDPPort = nPort;
}
uint8 GetUDPVersion() const
{
return m_byUDPVer;
}
bool SupportsUDP() const
{
return GetUDPVersion() != 0 && m_nUDPPort != 0;
}
uint16 GetKadPort() const
{
return m_nKadPort;
}
void SetKadPort(uint16 nPort)
{
m_nKadPort = nPort;
}
uint8 GetExtendedRequestsVersion() const
{
return m_byExtendedRequestsVer;
}
void RequestSharedFileList();
void ProcessSharedFileList(char* pachPacket, uint32 nSize, LPCTSTR pszDirectory = NULL);
void ClearHelloProperties();
bool ProcessHelloAnswer(char* pachPacket, uint32 nSize);
bool ProcessHelloPacket(char* pachPacket, uint32 nSize);
void SendHelloAnswer();
virtual bool SendHelloPacket();
void SendMuleInfoPacket(bool bAnswer);
void ProcessMuleInfoPacket(char* pachPacket, uint32 nSize);
void ProcessMuleCommentPacket(char* pachPacket, uint32 nSize);
void ProcessEmuleQueueRank(char* packet, UINT size);
void ProcessEdonkeyQueueRank(char* packet, UINT size);
void CheckQueueRankFlood();
bool Compare(const CUpDownClient* tocomp, bool bIgnoreUserhash = false) const;
void ResetFileStatusInfo();
uint32 GetLastSrcReqTime() const
{
return m_dwLastSourceRequest;
}
void SetLastSrcReqTime()
{
m_dwLastSourceRequest = ::GetTickCount();
}
uint32 GetLastSrcAnswerTime() const
{
return m_dwLastSourceAnswer;
}
void SetLastSrcAnswerTime()
{
m_dwLastSourceAnswer = ::GetTickCount();
}
uint32 GetLastAskedForSources() const
{
return m_dwLastAskedForSources;
}
void SetLastAskedForSources()
{
m_dwLastAskedForSources = ::GetTickCount();
}
bool GetFriendSlot() const;
void SetFriendSlot(bool bNV)
{
m_bFriendSlot = bNV;
}
bool IsFriend() const
{
return m_Friend != NULL;
}
void SetCommentDirty(bool bDirty = true)
{
m_bCommentDirty = bDirty;
}
bool GetSentCancelTransfer() const
{
return m_fSentCancelTransfer;
}
void SetSentCancelTransfer(bool bVal)
{
m_fSentCancelTransfer = bVal;
}
void ProcessPublicIPAnswer(const BYTE* pbyData, UINT uSize);
void SendPublicIPRequest();
// secure ident
void SendPublicKeyPacket();
void SendSignaturePacket();
void ProcessPublicKeyPacket(uchar* pachPacket, uint32 nSize);
void ProcessSignaturePacket(uchar* pachPacket, uint32 nSize);
uint8 GetSecureIdentState() const
{
return m_SecureIdentState;
}
void SendSecIdentStatePacket();
void ProcessSecIdentStatePacket(uchar* pachPacket, uint32 nSize);
uint8 GetInfoPacketsReceived() const
{
return m_byInfopacketsReceived;
}
void InfoPacketsReceived();
// preview
void SendPreviewRequest(const CAbstractFile* pForFile);
void SendPreviewAnswer(const CKnownFile* pForFile, CxImage** imgFrames, uint8 nCount);
void ProcessPreviewReq(char* pachPacket, uint32 nSize);
void ProcessPreviewAnswer(char* pachPacket, uint32 nSize);
bool GetPreviewSupport() const
{
return m_fSupportsPreview && GetViewSharedFilesSupport();
}
bool GetViewSharedFilesSupport() const
{
return m_fNoViewSharedFiles==0;
}
bool SafeSendPacket(Packet* packet);
void CheckForGPLEvilDoer();
//upload
EUploadState GetUploadState() const
{
return (EUploadState)m_nUploadState;
}
void SetUploadState(EUploadState news);
uint32 GetWaitStartTime() const;
void SetWaitStartTime();
void ClearWaitStartTime();
uint32 GetWaitTime() const
{
return m_dwUploadTime - GetWaitStartTime();
}
bool IsDownloading() const
{
return (m_nUploadState == US_UPLOADING);
}
bool HasBlocks() const
{
return !m_BlockRequests_queue.IsEmpty();
}
uint32 GetDatarate() const
{
return m_nUpDatarate;
}
uint32 GetScore(bool sysvalue, bool isdownloading = false, bool onlybasevalue = false) const;
void AddReqBlock(Requested_Block_Struct* reqblock);
void CreateNextBlockPackage();
uint32 GetUpStartTimeDelay() const
{
return ::GetTickCount() - m_dwUploadTime;
}
void SetUpStartTime()
{
m_dwUploadTime = ::GetTickCount();
}
void SendHashsetPacket(char* forfileid);
const uchar* GetUploadFileID() const
{
return requpfileid;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -