📄 baseclient.cpp
字号:
SetDownloadState(DS_WAITCALLBACK);
if (GetUploadState() == US_CONNECTING)
{
if(Disconnected(_T("LowID and US_CONNECTING")))
{
delete this;
return false;
}
return true;
}
if (theApp.serverconnect->IsLocalServer(m_dwServerIP,m_nServerPort))
{
Packet* packet = new Packet(OP_CALLBACKREQUEST,4);
PokeUInt32(packet->pBuffer, m_nUserIDHybrid);
if (thePrefs.GetDebugServerTCPLevel() > 0)
DebugSend("OP__CallBackRequest", this);
theStats.AddUpDataOverheadServer(packet->size);
theApp.serverconnect->SendPacket(packet);
SetDownloadState(DS_WAITCALLBACK);
}
else
{
if ( GetUploadState() == US_NONE && (!GetRemoteQueueRank() || m_bReaskPending) )
{
if( !HasValidBuddyID() )
{
theApp.downloadqueue->RemoveSource(this);
if(Disconnected(_T("LowID and US_NONE and QR=0")))
{
delete this;
return false;
}
return true;
}
if( !Kademlia::CKademlia::isConnected() )
{
//We are not connected to Kad and this is a Kad Firewalled source..
theApp.downloadqueue->RemoveSource(this);
{
if(Disconnected(_T("Kad Firewalled source but not connected to Kad.")))
{
delete this;
return false;
}
return true;
}
}
if( GetDownloadState() == DS_WAITCALLBACK )
{
if( GetBuddyIP() && GetBuddyPort())
{
CSafeMemFile bio(34);
Kademlia::CUInt128 buddy(GetBuddyID());
bio.WriteUInt128(&buddy);
Kademlia::CUInt128 file(reqfile->GetFileHash());
bio.WriteUInt128(&file);
bio.WriteUInt16(thePrefs.GetPort());
Packet* packet = new Packet(&bio, OP_KADEMLIAHEADER);
packet->opcode = KADEMLIA_FINDSOURCE_REQ;
theStats.AddUpDataOverheadKad(packet->size);
theApp.clientudp->SendPacket(packet, GetBuddyIP(), GetBuddyPort());
SetDownloadState(DS_WAITCALLBACKKAD);
}
else
{
//Create search to find buddy.
Kademlia::CSearch *findSource = new Kademlia::CSearch;
findSource->setSearchTypes(Kademlia::CSearch::FINDSOURCE);
Kademlia::CUInt128 ID(GetBuddyID());
findSource->setTargetID(ID);
findSource->addFileID(Kademlia::CUInt128(reqfile->GetFileHash()));
if(Kademlia::CSearchManager::startSearch(findSource))
{
//Started lookup..
SetDownloadState(DS_WAITCALLBACKKAD);
}
else
{
//This should never happen..
ASSERT(0);
}
}
}
// else
// {
//At the moment we ONLY allow Kad callbacks for downloads!
// }
}
else
{
if (GetDownloadState() == DS_WAITCALLBACK)
{
m_bReaskPending = true;
SetDownloadState(DS_ONQUEUE);
}
}
}
}
// MOD Note - end
else
{
if (!Connect())
return false; // client was deleted!
}
return true;
}
bool CUpDownClient::Connect()
{
//Try to always tell the socket to WaitForOnConnect before you call Connect.
socket->WaitForOnConnect();
SOCKADDR_IN sockAddr = {0};
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(GetUserPort());
sockAddr.sin_addr.S_un.S_addr = GetConnectIP();
socket->Connect((SOCKADDR*)&sockAddr, sizeof sockAddr);
if (!SendHelloPacket())
return false; // client was deleted!
return true;
}
void CUpDownClient::ConnectionEstablished()
{
// ok we have a connection, lets see if we want anything from this client
// check if we should use this client to retrieve our public IP
if (theApp.GetPublicIP() == 0 && theApp.serverconnect->IsConnected() && m_fPeerCache)
SendPublicIPRequest();
switch(GetKadState())
{
case KS_CONNECTING_FWCHECK:
SetKadState(KS_CONNECTED_FWCHECK);
break;
case KS_CONNECTING_BUDDY:
case KS_INCOMING_BUDDY:
SetKadState(KS_CONNECTED_BUDDY);
break;
}
if (GetChatState() == MS_CONNECTING || GetChatState() == MS_CHATTING)
theApp.emuledlg->chatwnd->chatselector.ConnectingResult(this,true);
switch(GetDownloadState())
{
case DS_CONNECTING:
case DS_WAITCALLBACK:
case DS_WAITCALLBACKKAD:
m_bReaskPending = false;
SetDownloadState(DS_CONNECTED);
SendFileRequest();
break;
}
if (m_bReaskPending)
{
m_bReaskPending = false;
if (GetDownloadState() != DS_NONE && GetDownloadState() != DS_DOWNLOADING)
{
SetDownloadState(DS_CONNECTED);
SendFileRequest();
}
}
switch(GetUploadState())
{
case US_CONNECTING:
case US_WAITCALLBACK:
if (theApp.uploadqueue->IsDownloading(this))
{
SetUploadState(US_UPLOADING);
if (thePrefs.GetDebugClientTCPLevel() > 0)
DebugSend("OP__AcceptUploadReq", this);
Packet* packet = new Packet(OP_ACCEPTUPLOADREQ,0);
theStats.AddUpDataOverheadFileRequest(packet->size);
socket->SendPacket(packet,true);
}
}
if (m_iFileListRequested == 1)
{
if (thePrefs.GetDebugClientTCPLevel() > 0)
DebugSend(m_fSharedDirectories ? "OP__AskSharedDirs" : "OP__AskSharedFiles", this);
Packet* packet = new Packet(m_fSharedDirectories ? OP_ASKSHAREDDIRS : OP_ASKSHAREDFILES,0);
theStats.AddUpDataOverheadOther(packet->size);
socket->SendPacket(packet,true,true);
}
while (!m_WaitingPackets_list.IsEmpty())
{
if (thePrefs.GetDebugClientTCPLevel() > 0)
DebugSend("Buffered Packet", this);
socket->SendPacket(m_WaitingPackets_list.RemoveHead());
}
}
void CUpDownClient::ReGetClientSoft()
{
if (m_pszUsername == NULL){
m_clientSoft = SO_UNKNOWN;
return;
}
int iHashType = GetHashType();
if (iHashType == SO_EMULE){
LPCTSTR pszSoftware;
switch(m_byCompatibleClient){
case SO_CDONKEY:
m_clientSoft = SO_CDONKEY;
pszSoftware = _T("cDonkey");
break;
case SO_XMULE:
m_clientSoft = SO_XMULE;
pszSoftware = _T("xMule");
break;
case SO_AMULE:
m_clientSoft = SO_AMULE;
pszSoftware = _T("aMule");
break;
case SO_SHAREAZA:
m_clientSoft = SO_SHAREAZA;
pszSoftware = _T("Shareaza");
break;
case SO_LPHANT:
m_clientSoft = SO_LPHANT;
pszSoftware = _T("lphant");
break;
default:
if (m_bIsML || m_byCompatibleClient == SO_MLDONKEY){
m_clientSoft = SO_MLDONKEY;
pszSoftware = _T("MLdonkey");
}
else if (m_bIsHybrid){
m_clientSoft = SO_EDONKEYHYBRID;
pszSoftware = _T("eDonkeyHybrid");
}
else if (m_byCompatibleClient != 0){
m_clientSoft = SO_XMULE; // means: 'eMule Compatible'
pszSoftware = _T("eMule Compat");
}
else{
m_clientSoft = SO_EMULE;
pszSoftware = _T("eMule");
}
}
int iLen;
TCHAR szSoftware[128];
if (m_byEmuleVersion == 0){
m_nClientVersion = MAKE_CLIENT_VERSION(0, 0, 0);
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("%s"), pszSoftware);
}
else if (m_byEmuleVersion != 0x99){
UINT nClientMinVersion = (m_byEmuleVersion >> 4)*10 + (m_byEmuleVersion & 0x0f);
m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0);
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("%s v0.%u"), pszSoftware, nClientMinVersion);
}
else{
UINT nClientMajVersion = (m_nClientVersion >> 17) & 0x7f;
UINT nClientMinVersion = (m_nClientVersion >> 10) & 0x7f;
UINT nClientUpVersion = (m_nClientVersion >> 7) & 0x07;
m_nClientVersion = MAKE_CLIENT_VERSION(nClientMajVersion, nClientMinVersion, nClientUpVersion);
if (m_clientSoft == SO_EMULE)
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("%s v%u.%u%c"), pszSoftware, nClientMajVersion, nClientMinVersion, _T('a') + nClientUpVersion);
else if (m_clientSoft == SO_AMULE || nClientUpVersion != 0)
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("%s v%u.%u.%u"), pszSoftware, nClientMajVersion, nClientMinVersion, nClientUpVersion);
else
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("%s v%u.%u"), pszSoftware, nClientMajVersion, nClientMinVersion);
}
if (iLen > 0){
memcpy(m_strClientSoftware.GetBuffer(iLen), szSoftware, iLen*sizeof(TCHAR));
m_strClientSoftware.ReleaseBuffer(iLen);
}
return;
}
if (m_bIsHybrid){
m_clientSoft = SO_EDONKEYHYBRID;
// seen:
// 105010 0.50.10
// 10501 0.50.1
// 1051 0.51.0
// 1000 1.0
// 501 0.50.1
UINT nClientMajVersion;
UINT nClientMinVersion;
UINT nClientUpVersion;
if (m_nClientVersion > 100000){
UINT uMaj = m_nClientVersion/100000;
nClientMajVersion = uMaj - 1;
nClientMinVersion = (m_nClientVersion - uMaj*100000) / 100;
nClientUpVersion = m_nClientVersion % 100;
}
else if (m_nClientVersion > 10000){
UINT uMaj = m_nClientVersion/10000;
nClientMajVersion = uMaj - 1;
nClientMinVersion = (m_nClientVersion - uMaj*10000) / 10;
nClientUpVersion = m_nClientVersion % 10;
}
else if (m_nClientVersion > 1000){
UINT uMaj = m_nClientVersion/1000;
nClientMajVersion = uMaj - 1;
nClientMinVersion = m_nClientVersion - uMaj*1000;
nClientUpVersion = 0;
}
else if (m_nClientVersion > 100){
UINT uMin = m_nClientVersion/10;
nClientMajVersion = 0;
nClientMinVersion = uMin;
nClientUpVersion = m_nClientVersion - uMin*10;
}
else{
nClientMajVersion = 0;
nClientMinVersion = m_nClientVersion;
nClientUpVersion = 0;
}
m_nClientVersion = MAKE_CLIENT_VERSION(nClientMajVersion, nClientMinVersion, nClientUpVersion);
int iLen;
TCHAR szSoftware[128];
if (nClientUpVersion)
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("eDonkeyHybrid v%u.%u.%u"), nClientMajVersion, nClientMinVersion, nClientUpVersion);
else
iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("eDonkeyHybrid v%u.%u"), nClientMajVersion, nClientMinVersion);
if (iLen > 0){
memcpy(m_strClientSoftware.GetBuffer(iLen), szSoftware, iLen*sizeof(TCHAR));
m_strClientSoftware.ReleaseBuffer(iLen);
}
return;
}
if (m_bIsML || iHashType == SO_MLDONKEY){
m_clientSoft = SO_MLDONKEY;
UINT nClientMinVersion = m_nClientVersion;
m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0);
TCHAR szSoftware[128];
int iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("MLdonkey v0.%u"), nClientMinVersion);
if (iLen > 0){
memcpy(m_strClientSoftware.GetBuffer(iLen), szSoftware, iLen*sizeof(TCHAR));
m_strClientSoftware.ReleaseBuffer(iLen);
}
return;
}
if (iHashType == SO_OLDEMULE){
m_clientSoft = SO_OLDEMULE;
UINT nClientMinVersion = m_nClientVersion;
m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0);
TCHAR szSoftware[128];
int iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("Old eMule v0.%u"), nClientMinVersion);
if (iLen > 0){
memcpy(m_strClientSoftware.GetBuffer(iLen), szSoftware, iLen*sizeof(TCHAR));
m_strClientSoftware.ReleaseBuffer(iLen);
}
return;
}
m_clientSoft = SO_EDONKEY;
UINT nClientMinVersion = m_nClientVersion;
m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0);
TCHAR szSoftware[128];
int iLen = _sntprintf(szSoftware, ARRSIZE(szSoftware), _T("eDonkey v0.%u"), nClientMinVersion);
if (iLen > 0){
memcpy(m_strClientSoftware.GetBuffer(iLen), szSoftware, iLen*sizeof(TCHAR));
m_strClientSoftware.ReleaseBuffer(iLen);
}
}
int CUpDownClient::GetHashType() const
{
if (m_achUserHash[5] == 13 && m_achUserHash[14] == 110)
return SO_OLDEMULE;
else if (m_achUserHash[5] == 14 && m_achUserHash[14] == 111)
return SO_EMULE;
else if (m_achUserHash[5] == 'M' && m_achUserHash[14] == 'L')
return SO_MLDONKEY;
else
return SO_UNKNOWN;
}
void CUpDownClient::SetUserName(LPCTSTR pszNewName)
{
if (m_pszUsername){
free(m_pszUsername);
m_pszUsername = NULL;
}
if( pszNewName )
m_pszUsername = _tcsdup(pszNewName);
}
void CUpDownClient::RequestSharedFileList()
{
if (m_iFileListRequested == 0){
AddLogLine(true,GetResString(IDS_SHAREDFILES_REQUEST),GetUserName());
m_iFileListRequested = 1;
TryToConnect(true);
}
else{
AddLogLine(true,_T("Requesting shared files from user %s (%u) is already in progress"),GetUserName(),GetUserIDHybrid());
}
}
void CUpDownClient::ProcessSharedFileList(char* pachPacket, uint32 nSize, LPCTSTR pszDirectory){
if (m_iFileListRequested > 0){
m_iFileListRequested--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -