📄 updownclient.h
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.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.
#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;
class CEMSocket;
class CAICHHash;
enum EUtf8Str;
struct IPRange_Struct2; //EastShare - added by AndCycle, IP to Country
struct Pending_Block_Struct{
Pending_Block_Struct()
{
block = NULL;
zStream = NULL;
totalUnzipped = 0;
fZStreamError = 0;
fRecovered = 0;
fQueued = 0;
}
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,
fQueued : 3;
};
#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_WAITCALLBACKKAD,
DS_REQHASHSET,
DS_NONEEDEDPARTS,
DS_TOOMANYCONNS,
DS_TOOMANYCONNSKAD,
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_INCOMING_BUDDY,
KS_CONNECTING_BUDDY,
KS_CONNECTED_BUDDY,
KS_NONE_LOWID,
KS_WAITCALLBACK_LOWID,
KS_QUEUE_LOWID
};
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;
}
//Only use this when you know the real IP or when your clearing it.
void SetIP( uint32 val )
{
m_dwUserIP = val;
m_nConnectIP = val;
}
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;
const uchar* GetBuddyID() const
{
return (uchar*)m_achBuddyID;
}
void SetBuddyID(const uchar* m_achTempBuddyID);
bool HasValidBuddyID() const
{
return m_bBuddyIDValid;
}
void SetBuddyIP( uint32 val )
{
m_nBuddyIP = val;
}
uint32 GetBuddyIP() const
{
return m_nBuddyIP;
}
void SetBuddyPort( uint16 val )
{
m_nBuddyPort = val;
}
uint16 GetBuddyPort() const
{
return m_nBuddyPort;
}
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -