public ClientCreditsImpl(CreditStruct in_credits) { credits_ = in_credits; InitalizeIdent(); unSecureWaitTime_ = 0; secureWaitTime_ = 0; waitTimeIP_ = 0; }
public ClientCreditsImpl(byte[] key) { credits_ = new CreditStruct(); MpdUtilities.Md4Cpy(credits_.abyKey, key); InitalizeIdent(); unSecureWaitTime_ = MpdUtilities.GetTickCount(); secureWaitTime_ = MpdUtilities.GetTickCount(); waitTimeIP_ = 0; }
private void ReadCreditStruct29a(SafeBufferedFile file, CreditStruct newcstruct) { file.Read(newcstruct.abyKey); newcstruct.nUploadedLo = file.ReadUInt32(); // uploaded TO him newcstruct.nDownloadedLo = file.ReadUInt32(); // downloaded from him newcstruct.nLastSeen = file.ReadUInt32(); newcstruct.nUploadedHi = file.ReadUInt32(); // upload high 32 newcstruct.nDownloadedHi = file.ReadUInt32(); // download high 32 newcstruct.nReserved3 = file.ReadUInt16(); }
private void WriteCreditStruct(SafeMemFile memfile, CreditStruct creditStruct) { memfile.WriteUInt32(creditStruct.nUploadedLo); // uploaded TO him memfile.WriteUInt32(creditStruct.nDownloadedLo); // downloaded from him memfile.WriteUInt32(creditStruct.nLastSeen); memfile.WriteUInt32(creditStruct.nUploadedHi); // upload high 32 memfile.WriteUInt32(creditStruct.nDownloadedHi); // download high 32 memfile.WriteUInt16(creditStruct.nReserved3); memfile.WriteUInt8(creditStruct.nKeySize); memfile.Write(creditStruct.abySecureIdent); }
public ClientCredits CreateClientCredits(CreditStruct credits) { return(new ClientCreditsImpl(credits)); }
private void ReadCreditStruct(SafeBufferedFile file, CreditStruct newcstruct) { ReadCreditStruct29a(file, newcstruct); newcstruct.nKeySize = file.ReadUInt8(); file.Read(newcstruct.abySecureIdent, 0, (int)CreditStruct.MAXPUBKEYSIZE); }
protected void LoadList() { string strFileName = System.IO.Path.Combine(MuleApplication.Instance.Preference.GetMuleDirectory(Mule.Preference.DefaultDirectoryEnum.EMULE_CONFIGDIR), CLIENTS_MET_FILENAME); if (!System.IO.File.Exists(strFileName)) { return; } SafeBufferedFile file = null; try { file = MpdObjectManager.CreateSafeBufferedFile(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); byte version = file.ReadUInt8(); if (version != (byte)VersionsEnum.CREDITFILE_VERSION && version != (byte)VersionsEnum.CREDITFILE_VERSION_29) { file.Close(); return; } // everything is ok, lets see if the backup exist... string strBakFileName = System.IO.Path.Combine(MuleApplication.Instance.Preference.GetMuleDirectory(Mule.Preference.DefaultDirectoryEnum.EMULE_CONFIGDIR), string.Format("{0}{1}", CLIENTS_MET_FILENAME, ".bak")); uint dwBakFileSize = 0; bool bCreateBackup = true; if (System.IO.File.Exists(strBakFileName)) { FileInfo fInfo = new FileInfo(strBakFileName); dwBakFileSize = (uint)fInfo.Length; if (dwBakFileSize > (uint)file.Length) { // the size of the backup was larger then the org. file, something is wrong here, don't overwrite old backup.. bCreateBackup = false; } } //else: the backup doesn't exist, create it if (bCreateBackup) { file.Close(); // close the file before copying System.IO.File.Copy(strFileName, strBakFileName, true); file = MpdObjectManager.CreateSafeBufferedFile(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); file.Seek(1, SeekOrigin.Begin); //set filepointer behind file version byte } uint count = file.ReadUInt32(); uint dwExpired = MpdUtilities.Time() - 12960000; // today - 150 day uint cDeleted = 0; for (uint i = 0; i < count; i++) { CreditStruct newcstruct = new CreditStruct(); if (version == (byte)VersionsEnum.CREDITFILE_VERSION_29) { ReadCreditStruct29a(file, newcstruct); } else { ReadCreditStruct(file, newcstruct); } if (newcstruct.nLastSeen < dwExpired) { cDeleted++; continue; } ClientCredits newcredits = MuleApplication.Instance.CoreObjectManager.CreateClientCredits(newcstruct); clients_[new MapCKey(newcredits.Key)] = newcredits; } file.Close(); } catch (Exception error) { MpdUtilities.DebugLogError(error); file.Close(); } }