CFriend::CFriend(void) { m_dwLastSeen = 0; m_dwLastUsedIP = 0; m_nLastUsedPort = 0; m_dwLastChatted = 0; (void)m_strName; m_LinkedClient = 0; md4clr(m_abyUserhash); md4clr(m_abyKadID); m_FriendConnectState = FCS_NONE; m_dwLastKadSearch = 0; m_friendSlot = false; }
CDeadSource::CDeadSource(uint32 dwID, uint16 nPort, uint32 dwServerIP, uint16 nKadPort){ m_dwID = dwID; m_dwServerIP = dwServerIP; m_nPort = nPort; m_nKadPort = nKadPort; md4clr(m_aucHash); }
CAbstractFile::CAbstractFile() { md4clr(m_abyFileHash); m_nFileSize = (uint64)0; m_uRating = 0; m_bCommentLoaded = false; m_uUserRating = 0; m_bHasComment = false; }
//Added this to work with the IRC.. Probably a better way to do it.. But wanted this in the release.. CFriend::CFriend(const uchar* abyUserhash, uint32_t dwLastSeen, uint32_t dwLastUsedIP, uint16_t nLastUsedPort, uint32_t dwLastChatted, LPCTSTR pszName, uint32_t dwHasHash){ m_dwLastSeen = dwLastSeen; m_dwLastUsedIP = dwLastUsedIP; m_nLastUsedPort = nLastUsedPort; m_dwLastChatted = dwLastChatted; if(dwHasHash && abyUserhash){ md4cpy(m_abyUserhash,abyUserhash); } else md4clr(m_abyUserhash); md4clr(m_abyKadID); m_strName = pszName; m_LinkedClient = 0; m_friendSlot = false; m_FriendConnectState = FCS_NONE; m_dwLastKadSearch = 0; }
void KadUtilityFunctions::HashData(byte* in_string,UINT in_string_len,byte *output) { // time critial md4clr(output); bool PaddingStarted = false; UINT Hash[4]; Hash[0] = 0x67452301; Hash[1] = 0xEFCDAB89; Hash[2] = 0x98BADCFE; Hash[3] = 0x10325476; CFile* data = 0; if (in_string) data = new CMemFile(in_string,in_string_len); UINT Required = in_string_len; byte X[64*128]; while (Required >= 64){ UINT len = Required / 64; if (len > sizeof(X)/(64 * sizeof(X[0]))) len = sizeof(X)/(64 * sizeof(X[0])); data->Read(&X,len*64); for (UINT i = 0; i < len; i++) { MD4Transform(Hash, (UINT*)(X + i*64)); } Required -= len*64; } // bytes to read Required = in_string_len % 64; if (Required != 0){ data->Read(&X,Required); } // in byte scale 512 = 64, 448 = 56 if (Required >= 56){ X[Required] = 0x80; PaddingStarted = TRUE; memset(&X[Required + 1], 0, 63 - Required); MD4Transform(Hash, (UINT*)X); Required = 0; } if (!PaddingStarted) X[Required++] = 0x80; memset(&X[Required], 0, 64 - Required); // add size (convert to bits) UINT in_string_len2 = in_string_len >> 29; in_string_len <<= 3; memcpy(&X[56], &in_string_len, 4); memcpy(&X[60], &in_string_len2, 4); MD4Transform(Hash, (UINT*)X); md4cpy(output, Hash); if(data!=NULL){ delete data; } //safe_delete(data); }
CFriend::CFriend(void) { m_dwLastSeen = 0; m_dwLastUsedIP = 0; m_nLastUsedPort = 0; m_dwLastChatted = 0; (void)m_strName; m_LinkedClient = 0; md4clr(m_abyUserhash); m_friendSlot = false; }
CFriend::CFriend(CUpDownClient* client){ ASSERT ( client ); m_dwLastSeen = time(NULL); m_dwLastUsedIP = client->GetIP(); m_nLastUsedPort = client->GetUserPort(); m_dwLastChatted = 0; m_LinkedClient = NULL; m_friendSlot = false; m_FriendConnectState = FCS_NONE; m_dwLastKadSearch = 0; md4clr(m_abyKadID); md4cpy(m_abyUserhash, client->GetUserHash()); SetLinkedClient(client); }
//Added this to work with the IRC.. Probably a better way to do it.. But wanted this in the release.. CFriend::CFriend(const uchar* abyUserhash, uint32 dwLastSeen, uint32 dwLastUsedIP, uint16 nLastUsedPort, uint32 dwLastChatted, LPCTSTR pszName, uint32 dwHasHash){ m_dwLastSeen = dwLastSeen; m_dwLastUsedIP = dwLastUsedIP; m_nLastUsedPort = nLastUsedPort; m_dwLastChatted = dwLastChatted; if(dwHasHash && abyUserhash){ md4cpy(m_abyUserhash,abyUserhash); } else md4clr(m_abyUserhash); m_strName = pszName; m_LinkedClient = 0; m_friendSlot = false; }
void CMuleUDPSocket::SendPacket(CPacket* packet, uint32 IP, uint16 port, bool bEncrypt, const uint8* pachTargetClientHashORKadID, bool bKad, uint32 nReceiverVerifyKey) { wxCHECK_RET(packet, wxT("Invalid packet.")); /*wxCHECK_RET(port, wxT("Invalid port.")); wxCHECK_RET(IP, wxT("Invalid IP.")); */ if (!port || !IP) { return; } if (!Ok()) { AddDebugLogLineN(logMuleUDP, (m_name + wxT(": Packet discarded, socket not Ok (")) << Uint32_16toStringIP_Port(IP, port) << wxT("): ") << packet->GetPacketSize() << wxT("b")); delete packet; return; } AddDebugLogLineN(logMuleUDP, (m_name + wxT(": Packet queued (")) << Uint32_16toStringIP_Port(IP, port) << wxT("): ") << packet->GetPacketSize() << wxT("b")); UDPPack newpending; newpending.IP = IP; newpending.port = port; newpending.packet = packet; newpending.time = GetTickCount(); newpending.bEncrypt = bEncrypt && (pachTargetClientHashORKadID != NULL || (bKad && nReceiverVerifyKey != 0)) && thePrefs::IsClientCryptLayerSupported(); newpending.bKad = bKad; newpending.nReceiverVerifyKey = nReceiverVerifyKey; if (newpending.bEncrypt && pachTargetClientHashORKadID != NULL) { md4cpy(newpending.pachTargetClientHashORKadID, pachTargetClientHashORKadID); } else { md4clr(newpending.pachTargetClientHashORKadID); } { wxMutexLocker lock(m_mutex); m_queue.push_back(newpending); } theApp->uploadBandwidthThrottler->QueueForSendingControlPacket(this); }
//from emule void DonkeyFile::CreateHashFromInput(FILE* file,CFile* file2, int Length, byte* Output, byte* in_string) { // time critial md4clr(Output); bool PaddingStarted = false; UINT Hash[4]; Hash[0] = 0x67452301; Hash[1] = 0xEFCDAB89; Hash[2] = 0x98BADCFE; Hash[3] = 0x10325476; CFile* data = 0; if (in_string) data = new CMemFile(in_string,Length); UINT Required = Length; byte X[64*128]; while (Required >= 64) { UINT len = Required / 64; if (len > sizeof(X)/(64 * sizeof(X[0]))) len = sizeof(X)/(64 * sizeof(X[0])); if (in_string) data->Read(&X,len*64); else if (file) fread(&X,len*64,1,file); else if (file2) file2->Read(&X,len*64); for (UINT i = 0; i < len; i++) { MD4Transform(Hash, (UINT*)(X + i*64)); } Required -= len*64; } // bytes to read Required = Length % 64; if (Required != 0) { if (in_string) data->Read(&X,Required); else if (file) fread(&X,Required,1,file); else if (file2) file2->Read(&X,Required); } // in byte scale 512 = 64, 448 = 56 if (Required >= 56) { X[Required] = 0x80; PaddingStarted = TRUE; memset(&X[Required + 1], 0, 63 - Required); MD4Transform(Hash, (UINT*)X); Required = 0; } if (!PaddingStarted) X[Required++] = 0x80; memset(&X[Required], 0, 64 - Required); // add size (convert to bits) UINT Length2 = Length >> 29; Length <<= 3; memcpy(&X[56], &Length, 4); memcpy(&X[60], &Length2, 4); MD4Transform(Hash, (UINT*)X); md4cpy(Output, Hash); if(data!=NULL) { delete data; } //safe_delete(data); }
bool CUpDownClient::ProcessPeerCacheAnswer(const uchar* packet, UINT size) { const bool bDebug = (thePrefs.GetDebugClientTCPLevel() > 0); ASSERT( GetDownloadState() == DS_DOWNLOADING ); ASSERT( m_ePeerCacheDownState == PCDS_WAIT_CLIENT_REPLY ); if (bDebug) DebugRecv("OP_PeerCacheAnswer", this); if (socket == NULL || reqfile == NULL){ ASSERT(0); return false; } CSafeMemFile dataRecv(packet, size); uint8 uPCVersion = dataRecv.ReadUInt8(); if (uPCVersion != PCPCK_VERSION){ if (bDebug) Debug(_T(" ***Invalid packet version: 0x%02x\n"), uPCVersion); ASSERT(0); return false; } uint8 uPCOpcode = dataRecv.ReadUInt8(); if (uPCOpcode == PCOP_NONE){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Client does not support PeerCache; %s"), DbgGetClientInfo()); return false; } if (uPCOpcode != PCOP_RES){ if (bDebug) Debug(_T(" ***Invalid packet opcode: 0x%02x\n"), uPCOpcode); ASSERT(0); return false; } uint32 uPushId = 0; uint32 uRemoteIP = 0; uchar aucFileHash[16]; md4clr(aucFileHash); CString strInfo; UINT uTags = dataRecv.ReadUInt8(); while (uTags--) { CTag tag(&dataRecv, GetUnicodeSupport()!=utf8strNone); if (tag.GetNameID() == PCTAG_PUSHID && tag.IsInt()) { uPushId = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PushId=%u"), uPushId); } else if (tag.GetNameID() == PCTAG_PUBLICIP && tag.IsInt()) { uRemoteIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" RemoteIP=%s"), ipstr(uRemoteIP)); } else if (tag.GetNameID() == PCTAG_FILEID && tag.IsHash() && tag.GetHash() != NULL) { md4cpy(aucFileHash, tag.GetHash()); if (bDebug) strInfo.AppendFormat(_T(" FileId=%s"), md4str(aucFileHash)); } else { if (bDebug) strInfo.AppendFormat(_T(" ***UnkTag: %s"), tag.GetFullInfo()); ASSERT(0); } } if (bDebug) { if (dataRecv.GetPosition() < dataRecv.GetLength()) strInfo.AppendFormat(_T(" ***AddData: %u bytes"), (UINT)(dataRecv.GetLength() - dataRecv.GetPosition())); Debug(_T("%s\n"), strInfo); } if (uPushId == 0 || uRemoteIP == 0 || isnulmd4(aucFileHash)){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Invalid PeerCacheAnswer; %s"), DbgGetClientInfo()); return false; } if (md4cmp(aucFileHash, reqfile->GetFileHash()) != 0){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("PeerCacheAnswer reqfile does not match ed2k reqfile; %s"), DbgGetClientInfo()); return false; } m_uPeerCacheDownloadPushId = uPushId; m_uPeerCacheRemoteIP = uRemoteIP; if (!SendHttpBlockRequests()) return false; theApp.m_pPeerCache->DownloadAttemptStarted(); ASSERT( m_ePeerCacheDownState == PCDS_WAIT_CACHE_REPLY ); return true; }
bool CUpDownClient::ProcessPeerCacheQuery(const uchar* packet, UINT size) { const bool bDebug = (thePrefs.GetDebugClientTCPLevel() > 0); if (bDebug) DebugRecv("OP_PeerCacheQuery", this); if (socket == NULL){ ASSERT(0); return false; } CSafeMemFile dataRecv(packet, size); uint8 uPCVersion = dataRecv.ReadUInt8(); if (uPCVersion != PCPCK_VERSION){ if (bDebug) Debug(_T(" ***Invalid packet version: 0x%02x\n"), uPCVersion); ASSERT(0); return false; } uint8 uPCOpcode = dataRecv.ReadUInt8(); if (uPCOpcode != PCOP_REQ){ if (bDebug) Debug(_T(" ***Invalid packet opcode: 0x%02x\n"), uPCOpcode); ASSERT(0); return false; } uint32 uCacheIP = 0; uint16 uCachePort = 0; uint32 uPushId = 0; uchar aucFileHash[16]; uint32 uRemoteIP = 0; md4clr(aucFileHash); CString strInfo; UINT uTags = dataRecv.ReadUInt8(); while (uTags--) { CTag tag(&dataRecv, GetUnicodeSupport()!=utf8strNone); if (tag.GetNameID() == PCTAG_CACHEIP && tag.IsInt()) { uCacheIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" CacheIP=%s"), ipstr(uCacheIP)); } else if (tag.GetNameID() == PCTAG_CACHEPORT && tag.IsInt()) { uCachePort = (uint16)tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" CachePort=%u"), uCachePort); } else if (tag.GetNameID() == PCTAG_PUSHID && tag.IsInt()) { uPushId = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PushId=%u"), uPushId); } else if (tag.GetNameID() == PCTAG_FILEID && tag.IsHash() && tag.GetHash() != NULL) { md4cpy(aucFileHash, tag.GetHash()); if (bDebug) strInfo.AppendFormat(_T(" FileId=%s"), md4str(aucFileHash)); } else if (tag.GetNameID() == PCTAG_PUBLICIP && tag.IsInt()) { uRemoteIP = tag.GetInt(); if (bDebug) strInfo.AppendFormat(_T(" PublicIP=%s"), ipstr(uRemoteIP)); } else { if (bDebug) strInfo.AppendFormat(_T(" ***UnkTag: %s"), tag.GetFullInfo()); ASSERT(0); } } if (bDebug) { if (dataRecv.GetPosition() < dataRecv.GetLength()) strInfo.AppendFormat(_T(" ***AddData: %u bytes"), (UINT)(dataRecv.GetLength() - dataRecv.GetPosition())); Debug(_T("%s\n"), strInfo); } if (uCacheIP == 0 || uCachePort == 0 || uPushId == 0 || isnulmd4(aucFileHash)){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("Invalid PeerCacheQuery; %s"), DbgGetClientInfo()); return false; } CKnownFile* pUploadFile = theApp.sharedfiles->GetFileByID(aucFileHash); if (pUploadFile == NULL){ if (thePrefs.GetVerbose()) AddDebugLogLine(false, _T("PeerCacheQuery reqfile does not match ed2k reqfile; %s"), DbgGetClientInfo()); return false; } if (m_pPCUpSocket != NULL) { SetPeerCacheUpState(PCUS_NONE); m_pPCUpSocket->Safe_Delete(); ASSERT( m_pPCUpSocket == NULL ); } m_pPCUpSocket = new CPeerCacheUpSocket(this); m_pPCUpSocket->SetTimeOut(GetPeerCacheSocketUploadTimeout()); m_pPCUpSocket->Create(); SOCKADDR_IN sockAddr = {0}; sockAddr.sin_family = AF_INET; sockAddr.sin_port = htons(uCachePort); sockAddr.sin_addr.S_un.S_addr = uCacheIP; //Try to always tell the socket to WaitForOnConnect before you call Connect. m_pPCUpSocket->WaitForOnConnect(); m_pPCUpSocket->Connect((SOCKADDR*)&sockAddr, sizeof sockAddr); CStringA strPCRequest; strPCRequest.AppendFormat("GIVE %u\r\n", uPushId); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("PeerCache-GIVE", this, pUploadFile->GetFileHash()); Debug(_T(" %hs\n"), strPCRequest); } CRawPacket* pHttpPacket = new CRawPacket(strPCRequest); theStats.AddUpDataOverheadFileRequest(pHttpPacket->size); m_pPCUpSocket->SendPacket(pHttpPacket); m_pPCUpSocket->SetHttpState(HttpStateRecvExpected); m_bPeerCacheUpHit = false; SetPeerCacheUpState(PCUS_WAIT_CACHE_REPLY); //theApp.uploadBandwidthThrottler->AddToStandardList(0, m_pPCUpSocket); CSafeMemFile dataSend(128); dataSend.WriteUInt8(PCPCK_VERSION); dataSend.WriteUInt8(PCOP_RES); dataSend.WriteUInt8(3); CTag tagPushId(PCTAG_PUSHID, uPushId); tagPushId.WriteNewEd2kTag(&dataSend); CTag tagPublicIP(PCTAG_PUBLICIP, theApp.GetPublicIP()); tagPublicIP.WriteNewEd2kTag(&dataSend); CTag tagFileId(PCTAG_FILEID, (BYTE*)aucFileHash); tagFileId.WriteNewEd2kTag(&dataSend); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("OP__PeerCacheAnswer", this, aucFileHash); Debug(_T(" PushId=%u PublicIP=%s FileId=%s\n"), tagPushId.GetInt(), ipstr(tagPublicIP.GetInt()), md4str(tagFileId.GetHash())); } Packet* pEd2kPacket = new Packet(&dataSend, OP_EMULEPROT, OP_PEERCACHE_ANSWER); theStats.AddUpDataOverheadFileRequest(pEd2kPacket->size); socket->SendPacket(pEd2kPacket); return true; }