public bool CompareStrict(FileIdentifierBase rFileIdentifier) { return(MpdUtilities.Md4Cmp(md4Hash_, rFileIdentifier.MD4Hash) == 0 && FileSize == rFileIdentifier.FileSize && !(HasAICHHash ^ rFileIdentifier.HasAICHHash) && aichHash_ == rFileIdentifier.AICHHash); }
public bool CompareRelaxed(FileIdentifierBase rFileIdentifier) { return(MpdUtilities.Md4Cmp(md4Hash_, rFileIdentifier.MD4Hash) == 0 && (FileSize == 0 || rFileIdentifier.FileSize == 0 || FileSize == rFileIdentifier.FileSize) && (!HasAICHHash || !rFileIdentifier.HasAICHHash || AICHHash == rFileIdentifier.AICHHash)); }
public override bool Equals(object obj) { if (obj is MapCKey) { return(MpdUtilities.Md4Cmp(key_, (obj as MapCKey).Key) == 0); } return(base.Equals(obj)); }
public static bool operator !=(DeadSource ds1, DeadSource ds2) { return(!( // lowid ed2k and highid kad + ed2k check ((ds1.id_ != 0 && ds1.id_ == ds2.id_) && ((ds1.port_ != 0 && ds1.port_ == ds2.port_) || (ds1.kadPort_ != 0 && ds1.kadPort_ == ds2.kadPort_)) && (ds1.serverIP_ == ds2.serverIP_ || !MuleUtilities.IsLowID(ds1.id_))) // lowid kad check || (MuleUtilities.IsLowID(ds1.id_) && MpdUtilities.IsNullMd4(ds1.hash_) == false && MpdUtilities.Md4Cmp(ds1.hash_, ds2.hash_) == 0))); }
public UpDownClient FindClientByUserHash(byte[] clienthash, uint dwIP, ushort nTCPPort) { UpDownClient pFound = null; foreach (UpDownClient cur_client in clientList_) { if (MpdUtilities.Md4Cmp(cur_client.UserHash, clienthash) == 0) { if ((dwIP == 0 || dwIP == cur_client.IP) && (nTCPPort == 0 || nTCPPort == cur_client.UserPort)) { return(cur_client); } else { pFound = pFound != null ? pFound : cur_client; } } } return(pFound); }
public bool LoadMD4HashsetFromFile(Mpd.Generic.IO.FileDataIO file, bool bVerifyExistingHash) { byte[] checkid = new byte[16]; file.ReadHash16(checkid); DeleteMD4Hashset(); uint parts = file.ReadUInt16(); //TRACE("Nr. hashs: %u\n", (uint)parts); if (bVerifyExistingHash && (MpdUtilities.Md4Cmp(MD4Hash, checkid) != 0 || parts != TheoreticalMD4PartHashCount)) { return(false); } for (uint i = 0; i < parts; i++) { byte[] cur_hash = new byte[16]; file.ReadHash16(cur_hash); m_aMD4HashSet.Add(cur_hash); } if (!bVerifyExistingHash) { MpdUtilities.Md4Cpy(MD4Hash, checkid); } // Calculate hash out of hashset and compare to existing filehash if (m_aMD4HashSet.Count > 0) { return(CalculateMD4HashByHashSet(true, true)); } else { return(true); } }
public bool CalculateMD4HashByHashSet(bool bVerifyOnly, bool bDeleteOnVerifyFail) { if (m_aMD4HashSet.Count <= 1) { return(false); } byte[] buffer = new byte[m_aMD4HashSet.Count * 16]; for (int i = 0; i < m_aMD4HashSet.Count; i++) { MpdUtilities.Md4Cpy(buffer, i * 16, m_aMD4HashSet[i], 0, m_aMD4HashSet[i].Length); } byte[] aucResult = new byte[16]; KnownFile knownFile = MuleApplication.Instance.FileObjectManager.CreateKnownFile(); knownFile.CreateHash(buffer, (ulong)m_aMD4HashSet.Count * 16, aucResult); if (bVerifyOnly) { if (MpdUtilities.Md4Cmp(aucResult, MD4Hash) != 0) { if (bDeleteOnVerifyFail) { DeleteMD4Hashset(); } return(false); } else { return(true); } } else { MpdUtilities.Md4Cpy(MD4Hash, aucResult); return(true); } }
private bool ProcessPacket(byte[] packet, uint offset, uint size, byte opcode, uint ip, ushort port) { switch ((OperationCodeEnum)opcode) { case OperationCodeEnum.OP_REASKCALLBACKUDP: { MuleApplication.Instance.Statistics.AddDownDataOverheadOther(size); UpDownClient buddy = MuleApplication.Instance.ClientList.Buddy; if (buddy != null) { if (size < 17 || buddy.ClientSocket == null) { break; } if (MpdUtilities.Md4Cmp(packet, (int)offset, buddy.BuddyID, 0) == 0) { Array.Copy(BitConverter.GetBytes(ip), 0, packet, offset + 10, 4); Array.Copy(BitConverter.GetBytes(port), 0, packet, offset + 14, 2); Packet response = MuleApplication.Instance.NetworkObjectManager.CreatePacket(MuleConstants.PROTOCOL_EMULEPROT); response.OperationCode = OperationCodeEnum.OP_REASKCALLBACKTCP; response.Buffer = new byte[size]; Array.Copy(packet, offset + 10, response.Buffer, 0, size - 10); response.Size = size - 10; MuleApplication.Instance.Statistics.AddUpDataOverheadFileRequest(response.Size); buddy.SendPacket(response, true); } } break; } case OperationCodeEnum.OP_REASKFILEPING: { MuleApplication.Instance.Statistics.AddDownDataOverheadFileRequest(size); SafeMemFile data_in = MpdObjectManager.CreateSafeMemFile(packet, offset, size); byte[] reqfilehash = new byte[16]; data_in.ReadHash16(reqfilehash); KnownFile reqfile = MuleApplication.Instance.SharedFiles.GetFileByID(reqfilehash); bool bSenderMultipleIpUnknown = false; UpDownClient sender = MuleApplication.Instance.UploadQueue.GetWaitingClientByIP_UDP(ip, port, true, ref bSenderMultipleIpUnknown); if (reqfile == null) { Packet response = MuleApplication.Instance.NetworkObjectManager.CreatePacket(OperationCodeEnum.OP_FILENOTFOUND, 0, MuleConstants.PROTOCOL_EMULEPROT); MuleApplication.Instance.Statistics.AddUpDataOverheadFileRequest(response.Size); if (sender != null) { SendPacket(response, ip, port, sender.ShouldReceiveCryptUDPPackets, sender.UserHash, false, 0); } else { SendPacket(response, ip, port, false, null, false, 0); } break; } if (sender != null) { //Make sure we are still thinking about the same file if (MpdUtilities.Md4Cmp(reqfilehash, sender.UploadFileID) == 0) { sender.AddAskedCount(); sender.SetLastUpRequest(); //I messed up when I first added extended info to UDP //I should have originally used the entire ProcessExtenedInfo the first time. //So now I am forced to check UDPVersion to see if we are sending all the extended info. //For now on, we should not have to change anything here if we change //anything to the extended info data as this will be taken care of in ProcessExtendedInfo() //Update extended info. if (sender.UDPVersion > 3) { sender.ProcessExtendedInfo(data_in, reqfile); } //Update our complete source counts. else if (sender.UDPVersion > 2) { ushort nCompleteCountLast = sender.UpCompleteSourcesCount; ushort nCompleteCountNew = data_in.ReadUInt16(); sender.UpCompleteSourcesCount = nCompleteCountNew; if (nCompleteCountLast != nCompleteCountNew) { reqfile.UpdatePartsInfo(); } } SafeMemFile data_out = MpdObjectManager.CreateSafeMemFile(128); if (sender.UDPVersion > 3) { if (reqfile.IsPartFile) { ((PartFile)reqfile).WritePartStatus(data_out); } else { data_out.WriteUInt16(0); } } data_out.WriteUInt16((ushort)(MuleApplication.Instance.UploadQueue.GetWaitingPosition(sender))); Packet response = MuleApplication.Instance.NetworkObjectManager.CreatePacket(data_out, MuleConstants.PROTOCOL_EMULEPROT); response.OperationCode = OperationCodeEnum.OP_REASKACK; MuleApplication.Instance.Statistics.AddUpDataOverheadFileRequest(response.Size); SendPacket(response, ip, port, sender.ShouldReceiveCryptUDPPackets, sender.UserHash, false, 0); } } else { // Don't answer him. We probably have him on our queue already, but can't locate him. Force him to establish a TCP connection if (!bSenderMultipleIpUnknown) { if (((uint)MuleApplication.Instance.UploadQueue.WaitingUserCount + 50) > MuleApplication.Instance.Preference.QueueSize) { Packet response = MuleApplication.Instance.NetworkObjectManager.CreatePacket(OperationCodeEnum.OP_QUEUEFULL, 0, MuleConstants.PROTOCOL_EMULEPROT); MuleApplication.Instance.Statistics.AddUpDataOverheadFileRequest(response.Size); SendPacket(response, ip, port, false, null, false, 0); // we cannot answer this one encrypted since we dont know this client } } } break; } case OperationCodeEnum.OP_QUEUEFULL: { MuleApplication.Instance.Statistics.AddDownDataOverheadFileRequest(size); UpDownClient sender = MuleApplication.Instance.DownloadQueue.GetDownloadClientByIP_UDP(ip, port, true); if (sender != null && sender.UDPPacketPending) { sender.IsRemoteQueueFull = true; sender.UDPReaskACK(0); } break; } case OperationCodeEnum.OP_REASKACK: { MuleApplication.Instance.Statistics.AddDownDataOverheadFileRequest(size); UpDownClient sender = MuleApplication.Instance.DownloadQueue.GetDownloadClientByIP_UDP(ip, port, true); if (sender != null && sender.UDPPacketPending) { SafeMemFile data_in = MpdObjectManager.CreateSafeMemFile(packet, size); if (sender.UDPVersion > 3) { sender.ProcessFileStatus(true, data_in, sender.RequestFile); } ushort nRank = data_in.ReadUInt16(); sender.IsRemoteQueueFull = false; sender.UDPReaskACK(nRank); sender.AddAskedCountDown(); } break; } case OperationCodeEnum.OP_FILENOTFOUND: { MuleApplication.Instance.Statistics.AddDownDataOverheadFileRequest(size); UpDownClient sender = MuleApplication.Instance.DownloadQueue.GetDownloadClientByIP_UDP(ip, port, true); if (sender != null && sender.UDPPacketPending) { sender.UDPReaskFNF(); // may delete 'sender'! sender = null; } break; } case OperationCodeEnum.OP_PORTTEST: { MuleApplication.Instance.Statistics.AddDownDataOverheadOther(size); if (size == 1) { if (packet[0] == 0x12) { bool ret = MuleApplication.Instance.ListenSocket.SendPortTestReply('1', true); } } break; } case OperationCodeEnum.OP_DIRECTCALLBACKREQ: { if (!MuleApplication.Instance.ClientList.AllowCalbackRequest(ip)) { break; } // do we accept callbackrequests at all? if (MuleApplication.Instance.KadEngine.IsRunning && MuleApplication.Instance.KadEngine.IsFirewalled) { MuleApplication.Instance.ClientList.AddTrackCallbackRequests(ip); SafeMemFile data = MpdObjectManager.CreateSafeMemFile(packet, size); ushort nRemoteTCPPort = data.ReadUInt16(); byte[] uchUserHash = new byte[16]; data.ReadHash16(uchUserHash); byte byConnectOptions = data.ReadUInt8(); UpDownClient pRequester = MuleApplication.Instance.ClientList.FindClientByUserHash(uchUserHash, ip, nRemoteTCPPort); if (pRequester == null) { pRequester = MuleApplication.Instance.CoreObjectManager.CreateUpDownClient(null, nRemoteTCPPort, ip, 0, 0, true); pRequester.UserHash = uchUserHash; MuleApplication.Instance.ClientList.AddClient(pRequester); } pRequester.SetConnectOptions(byConnectOptions, true, false); pRequester.DoesDirectUDPCallbackSupport = false; pRequester.IP = ip; pRequester.UserPort = nRemoteTCPPort; pRequester.TryToConnect(); } break; } default: MuleApplication.Instance.Statistics.AddDownDataOverheadOther(size); return(false); } return(true); }