Skip to content

Commit

Permalink
Using I/O completion ports for disk operations
Browse files Browse the repository at this point in the history
Improve handling of UNC paths
Minor GUI enhancements
  • Loading branch information
irwir committed Nov 4, 2023
1 parent 033762b commit ef58358
Show file tree
Hide file tree
Showing 562 changed files with 16,870 additions and 20,679 deletions.
17 changes: 17 additions & 0 deletions mbedtls/include/mbedtls/threading_alt.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
//this file is part of eMule
//Copyright (C)2017-2023 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / https://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
#ifdef _MSC_VER
#include <winsock2.h>
Expand Down
1 change: 0 additions & 1 deletion srchybrid/3DPreviewControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class C3DPreviewControl : public CStatic

public:
C3DPreviewControl();
virtual ~C3DPreviewControl() = default;

protected:
DECLARE_MESSAGE_MAP()
Expand Down
39 changes: 20 additions & 19 deletions srchybrid/AICHSyncThread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//Copyright (C)2002-2023 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / https://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
Expand Down Expand Up @@ -56,7 +56,6 @@ int CAICHSyncThread::Run()
const CString &fullpath(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + KNOWN2_MET_FILENAME);

CSafeFile file;
uint32 nLastVerifiedPos = 0;

// we need to keep a lock on this file while the thread is running
CSingleLock lockKnown2Met(&CAICHRecoveryHashSet::m_mutKnown2File, TRUE);
Expand All @@ -73,17 +72,18 @@ int CAICHSyncThread::Run()
}
return 0;
}
uint32 nLastVerifiedPos = 0;
try {
if (file.GetLength() >= 1) {
uint8 header = file.ReadUInt8();
if (header != KNOWN2_MET_VERSION)
AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName());

//setvbuf(file.m_pStream, NULL, _IOFBF, 16384);
//::setvbuf(file.m_pStream, NULL, _IOFBF, 16384);
ULONGLONG nExistingSize = file.GetLength();
while (file.GetPosition() < nExistingSize) {
aKnown2HashesFilePos.Add(file.GetPosition());
aKnown2Hashes.Add(CAICHHash(&file));
aKnown2Hashes.Add(CAICHHash(file));
uint32 nHashCount = file.ReadUInt32();
if (file.GetPosition() + nHashCount * (ULONGLONG)CAICHHash::GetHashSize() > nExistingSize)
AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName());
Expand Down Expand Up @@ -116,12 +116,12 @@ int CAICHSyncThread::Run()
return 0;
}

// now we check that all files which are in the shared file list have a corresponding hash in out list
// now we check that all files which are in the shared file list have a corresponding hash in the out list
// those who don't are added to the hashing list
CList<CAICHHash> liUsedHashes;
CSingleLock sharelock(&theApp.sharedfiles->m_mutWriteList, TRUE);

bool bDbgMsgCreatingPartHashes = true;

CSingleLock sharelock(&theApp.sharedfiles->m_mutWriteList, TRUE);
for (POSITION pos = BEFORE_START_POSITION; pos != NULL;) {
if (theApp.IsClosing()) // in case of shutdown while still hashing
return 0;
Expand Down Expand Up @@ -184,10 +184,10 @@ int CAICHSyncThread::Run()
uint32 nPurgeBecauseOld = 0;
uint32 nPurgeDups = 0;
static const CAICHHash empty; //zero AICH hash
while (file.GetPosition() < nExistingSize) {
ULONGLONG nCurrentHashsetPos = file.GetPosition();
ULONGLONG nCurrentHashsetPos;
while ((nCurrentHashsetPos = file.GetPosition()) < nExistingSize) {
ULONGLONG posTmp = 0; //position of an old duplicate hash
CAICHHash aichHash(&file);
CAICHHash aichHash(file);
uint32 nHashCount = file.ReadUInt32();
if (file.GetPosition() + nHashCount * (ULONGLONG)CAICHHash::GetHashSize() > nExistingSize)
AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName());
Expand Down Expand Up @@ -251,12 +251,12 @@ int CAICHSyncThread::Run()
}
} else {
// remember (/index) all hashes which are stored in the file for faster checking later on
for (INT_PTR i = 0; !theApp.IsClosing() && i < aKnown2Hashes.GetCount(); ++i)
for (INT_PTR i = 0; i < aKnown2Hashes.GetCount() && !theApp.IsClosing(); ++i)
CAICHRecoveryHashSet::AddStoredAICHHash(aKnown2Hashes[i], aKnown2HashesFilePos[i]);
}

#ifdef _DEBUG
for (POSITION pos = liUsedHashes.GetHeadPosition(); !theApp.IsClosing() && pos != NULL;) {
for (POSITION pos = liUsedHashes.GetHeadPosition(); pos != NULL && !theApp.IsClosing();) {
CKnownFile *pFile = theApp.sharedfiles->GetFileByAICH(liUsedHashes.GetNext(pos));
if (pFile == NULL) {
ASSERT(0);
Expand All @@ -278,7 +278,7 @@ int CAICHSyncThread::Run()
if (!m_liToHash.IsEmpty()) {
theApp.QueueLogLine(true, GetResString(IDS_AICH_SYNCTOTAL), m_liToHash.GetCount());
theApp.emuledlg->sharedfileswnd->sharedfilesctrl.SetAICHHashing(m_liToHash.GetCount());
// let first all normal hashing be done before starting out sync hashing
// first let all normal hashing be done before starting out sync hashing
CSingleLock sLock1(&theApp.hashing_mut); // only one file hash at a time
while (theApp.sharedfiles->GetHashingCount() != 0) {
if (theApp.IsClosing())
Expand Down Expand Up @@ -319,11 +319,12 @@ bool CAICHSyncThread::ConvertToKnown2ToKnown264(CSafeFile *pTargetFile)
// changing hashcount from uint16 to uint32

// there still exists a lock on known2_64.met and it should be not opened at this point
CString oldfullpath(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + OLD_KNOWN2_MET_FILENAME);
CString newfullpath(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + KNOWN2_MET_FILENAME);
const CString &sConfDir(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR));
const CString &oldfullpath(sConfDir + OLD_KNOWN2_MET_FILENAME);
const CString &newfullpath(sConfDir + KNOWN2_MET_FILENAME);

if (PathFileExists(newfullpath) || !PathFileExists(oldfullpath))
// only continue if the old file does and the new file does not exists
// continue only if the old file does exist, and the new file does not
if (::PathFileExists(newfullpath) || !::PathFileExists(oldfullpath))
return false;

CSafeFile oldfile;
Expand All @@ -336,7 +337,7 @@ bool CAICHSyncThread::ConvertToKnown2ToKnown264(CSafeFile *pTargetFile)
strError.AppendFormat(_T(" - %s"), szError);
LogError(LOG_STATUSBAR, _T("%s"), (LPCTSTR)strError);
}
// else -> known2.met also doesn't exists, so nothing to convert
// known2.met also doesn't exist, so nothing to convert
return false;
}

Expand All @@ -356,7 +357,7 @@ bool CAICHSyncThread::ConvertToKnown2ToKnown264(CSafeFile *pTargetFile)
try {
pTargetFile->WriteUInt8(KNOWN2_MET_VERSION);
while (oldfile.GetPosition() < oldfile.GetLength()) {
CAICHHash aichHash(&oldfile);
CAICHHash aichHash(oldfile);
uint32 nHashCount = oldfile.ReadUInt16();
if (oldfile.GetPosition() + nHashCount * (ULONGLONG)CAICHHash::GetHashSize() > oldfile.GetLength())
AfxThrowFileException(CFileException::endOfFile, 0, oldfile.GetFileName());
Expand Down
2 changes: 1 addition & 1 deletion srchybrid/AICHSyncThread.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//Copyright (C)2002-2023 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / https://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
Expand Down
32 changes: 15 additions & 17 deletions srchybrid/AbstractFile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// parts of this file are based on work from pan One (http://home-3.tiscali.nl/~meost/pms/)
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//Copyright (C)2002-2023 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / https://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
Expand Down Expand Up @@ -39,8 +39,8 @@ CAbstractFile::CAbstractFile()
: m_nFileSize(0ull)
, m_FileIdentifier(m_nFileSize)
, m_uRating()
, m_bCommentLoaded()
, m_uUserRating()
, m_bCommentLoaded()
, m_bHasComment()
, m_bKadCommentSearchRunning()
{
Expand All @@ -51,12 +51,12 @@ CAbstractFile::CAbstractFile(const CAbstractFile *pAbstractFile)
, m_FileIdentifier(pAbstractFile->m_FileIdentifier, m_nFileSize)
, m_strFileName(pAbstractFile->m_strFileName)
, m_strComment(pAbstractFile->m_strComment)
, m_strFileType(pAbstractFile->m_strFileType)
, m_uRating(pAbstractFile->m_uRating)
, m_bCommentLoaded(pAbstractFile->m_bCommentLoaded)
, m_uUserRating(pAbstractFile->m_uUserRating)
, m_bCommentLoaded(pAbstractFile->m_bCommentLoaded)
, m_bHasComment(pAbstractFile->m_bHasComment)
, m_bKadCommentSearchRunning(pAbstractFile->m_bKadCommentSearchRunning)
, m_strFileType(pAbstractFile->m_strFileType)
{

const CTypedPtrList<CPtrList, Kademlia::CEntry*> &list = pAbstractFile->getNotes();
Expand All @@ -77,16 +77,16 @@ CAbstractFile::~CAbstractFile()
void CAbstractFile::AssertValid() const
{
CObject::AssertValid();
(void)m_strFileName;
m_taglist.AssertValid();
(void)m_FileIdentifier;
(void)m_nFileSize;
(void)m_strFileName;
(void)m_strComment;
(void)m_uRating;
(void)m_strFileType;
(void)m_uRating;
(void)m_uUserRating;
CHECK_BOOL(m_bHasComment);
CHECK_BOOL(m_bCommentLoaded);
m_taglist.AssertValid();
}

void CAbstractFile::Dump(CDumpContext &dc) const
Expand All @@ -95,16 +95,16 @@ void CAbstractFile::Dump(CDumpContext &dc) const
}
#endif

bool CAbstractFile::AddNote(Kademlia::CEntry *pEntry)
bool CAbstractFile::AddNote(const Kademlia::CEntry &cEntry)
{
for (POSITION pos = m_kadNotes.GetHeadPosition(); pos != NULL; ) {
for (POSITION pos = m_kadNotes.GetHeadPosition(); pos != NULL;) {
const Kademlia::CEntry *entry = m_kadNotes.GetNext(pos);
if (entry->m_uSourceID == pEntry->m_uSourceID) {
ASSERT(entry != pEntry);
if (entry->m_uSourceID == cEntry.m_uSourceID) {
ASSERT(entry != &cEntry);
return false;
}
}
m_kadNotes.AddHead(pEntry);
m_kadNotes.AddHead(const_cast<Kademlia::CEntry&>(cEntry).Copy());
UpdateFileRatingCommentAvail();
return true;
}
Expand Down Expand Up @@ -149,12 +149,12 @@ void CAbstractFile::AddTagUnique(CTag *pTag)
for (INT_PTR i = m_taglist.GetCount(); --i >= 0;) {
const CTag *pCurTag = m_taglist[i];
if (( (pCurTag->GetNameID() != 0 && pCurTag->GetNameID() == pTag->GetNameID())
|| (pCurTag->GetName()[0] && pTag->GetName()[0] && CmpED2KTagName(pCurTag->GetName(), pTag->GetName()) == 0)
|| (pCurTag->HasName() && pTag->HasName() && CmpED2KTagName(pCurTag->GetName(), pTag->GetName()) == 0)
)
&& pCurTag->GetType() == pTag->GetType())
{
delete pCurTag;
m_taglist.SetAt(i, pTag);
m_taglist[i] = pTag;
return;
}
}
Expand Down Expand Up @@ -418,13 +418,11 @@ void CAbstractFile::RefilterKadNotes(bool bUpdate)
CString CAbstractFile::GetED2kLink(bool bHashset, bool bHTML, bool bHostname, bool bSource, uint32 dwSourceIP) const
{
CString strLink;
strLink.Format(_T("ed2k://|file|%s|%I64u|%s|")
strLink.Format(&_T("<a href=\"ed2k://|file|%s|%I64u|%s|")[bHTML ? 0 : 9]
, (LPCTSTR)EncodeUrlUtf8(StripInvalidFilenameChars(GetFileName()))
, (uint64)GetFileSize()
, (LPCTSTR)EncodeBase16(GetFileHash(), 16));

if (bHTML)
strLink = _T("<a href=\"") + strLink;
if (bHashset && GetFileIdentifierC().GetAvailableMD4PartHashCount() > 0 && GetFileIdentifierC().HasExpectedMD4HashCount()) {
strLink += _T("p=");
for (UINT j = 0; j < GetFileIdentifierC().GetAvailableMD4PartHashCount(); ++j) {
Expand Down
62 changes: 31 additions & 31 deletions srchybrid/AbstractFile.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//Copyright (C)2002-2023 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / https://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
Expand Down Expand Up @@ -71,31 +71,31 @@ class CAbstractFile: public CObject
CString GetED2kLink(bool bHashset = false, bool bHTML = false, bool bHostname = false, bool bSource = false, uint32 dwSourceIP = 0) const;


EMFileSize GetFileSize() const { return m_nFileSize; }
virtual void SetFileSize(EMFileSize nFileSize) { m_nFileSize = nFileSize; }
bool IsLargeFile() const { return (uint64)m_nFileSize > OLD_MAX_EMULE_FILE_SIZE; }
EMFileSize GetFileSize() const { return m_nFileSize; }
virtual void SetFileSize(EMFileSize nFileSize) { m_nFileSize = nFileSize; }
bool IsLargeFile() const { return (uint64)m_nFileSize > OLD_MAX_EMULE_FILE_SIZE; }

uint32 GetIntTagValue(uint8 tagname) const;
uint32 GetIntTagValue(LPCSTR tagname) const;
bool GetIntTagValue(uint8 tagname, uint32 &ruValue) const;
uint64 GetInt64TagValue(uint8 tagname) const;
uint64 GetInt64TagValue(LPCSTR tagname) const;
bool GetInt64TagValue(uint8 tagname, uint64 &ruValue) const;
void SetIntTagValue(uint8 tagname, uint32 uValue);
void SetInt64TagValue(uint8 tagname, uint64 uValue);
uint32 GetIntTagValue(uint8 tagname) const;
uint32 GetIntTagValue(LPCSTR tagname) const;
bool GetIntTagValue(uint8 tagname, uint32 &ruValue) const;
uint64 GetInt64TagValue(uint8 tagname) const;
uint64 GetInt64TagValue(LPCSTR tagname) const;
bool GetInt64TagValue(uint8 tagname, uint64 &ruValue) const;
void SetIntTagValue(uint8 tagname, uint32 uValue);
void SetInt64TagValue(uint8 tagname, uint64 uValue);
const CString& GetStrTagValue(uint8 tagname) const;
const CString& GetStrTagValue(LPCSTR tagname) const;
void SetStrTagValue(uint8 tagname, LPCTSTR);
CTag* GetTag(uint8 tagname, uint8 tagtype) const;
CTag* GetTag(LPCSTR tagname, uint8 tagtype) const;
CTag* GetTag(uint8 tagname) const;
CTag* GetTag(LPCSTR tagname) const;
void SetStrTagValue(uint8 tagname, LPCTSTR);
CTag* GetTag(uint8 tagname, uint8 tagtype) const;
CTag* GetTag(LPCSTR tagname, uint8 tagtype) const;
CTag* GetTag(uint8 tagname) const;
CTag* GetTag(LPCSTR tagname) const;
const CArray<CTag*, CTag*>& GetTags() const { return m_taglist; }
void AddTagUnique(CTag *pTag);
void DeleteTag(uint8 tagname);
void DeleteTag(CTag *pTag);
void ClearTags();
void CopyTags(const CArray<CTag*, CTag*> &tags);
void AddTagUnique(CTag *pTag);
void DeleteTag(uint8 tagname);
void DeleteTag(CTag *pTag);
void ClearTags();
void CopyTags(const CArray<CTag*, CTag*> &tags);
virtual bool IsPartFile() const { return false; }

bool HasComment() const { return m_bHasComment; }
Expand All @@ -107,9 +107,9 @@ class CAbstractFile: public CObject
const CString &GetFileComment();
UINT GetFileRating();
void LoadComment();
virtual void UpdateFileRatingCommentAvail(bool bForceUpdate = false) = 0;
virtual void UpdateFileRatingCommentAvail(bool bForceUpdate = false) = 0;

bool AddNote(Kademlia::CEntry *pEntry);
bool AddNote(const Kademlia::CEntry &cEntry);
void RefilterKadNotes(bool bUpdate = true);
const CKadEntryPtrList& getNotes() const { return m_kadNotes; }

Expand All @@ -123,16 +123,16 @@ class CAbstractFile: public CObject
#endif

protected:
EMFileSize m_nFileSize;
CArray<CTag*, CTag*> m_taglist;
CKadEntryPtrList m_kadNotes;
EMFileSize m_nFileSize; //must be before m_FileIdentifier due to initialisation list order
CFileIdentifier m_FileIdentifier;
CString m_strFileName;
CString m_strComment;
CString m_strFileName;
CString m_strComment;
CString m_strFileType;
UINT m_uRating;
bool m_bCommentLoaded;
UINT m_uUserRating;
bool m_bCommentLoaded;
bool m_bHasComment;
bool m_bKadCommentSearchRunning;
CString m_strFileType;
CArray<CTag*, CTag*> m_taglist;
CKadEntryPtrList m_kadNotes;
};
Loading

0 comments on commit ef58358

Please sign in to comment.