Official eMule-Board: Getclosestto - Official eMule-Board

Jump to content


Page 1 of 1

Getclosestto

#1 User is offline   Unknown1 

  • Wanna be Dev
  • PipPipPipPipPipPipPip
  • Group: Admin
  • Posts: 1288
  • Joined: 11-September 02

Posted 04 February 2006 - 10:42 PM

I normally don't do this.. But tatikiran pointed out an issue with Kad, so here is a patch that will be in next release.. Just copy the new methods to your Mod.. I'm assuming your smart enough to adjust the .h files and commenting out an ASSERT that will assert for a returned count of 50.. This fixes an issue where you will not get the number of results your asked for.

void CRoutingBin::GetClosestTo(uint32 uMaxType, const CUInt128 &uTarget, uint32 uMaxRequired, ContactMap *pmapResult, bool bEmptyFirst, bool bInUse)
{
	// Empty list if requested.
	if (bEmptyFirst)
 ápmapResult->clear();

	// Return 0 since we have no entries.
	if (m_listEntries.size() == 0)
 áreturn;

	// First put results in sort order for uTarget so we can insert them correctly.
	// We don't care about max results at this time.
	for (ContactList::const_iterator itContactList = m_listEntries.begin(); itContactList != m_listEntries.end(); ++itContactList)
	{
 áif((*itContactList)->GetType() <= uMaxType)
 á{
 á	CUInt128 uTargetDistance((*itContactList)->m_uClientID);
 á	uTargetDistance.Xor(uTarget);
 á	(*pmapResult)[uTargetDistance] = *itContactList;
 á	// This list will be used for an unknown time, Inc in use so it's not deleted.
 á	if( bInUse )
 á á(*itContactList)->IncUse();
 á}
	}

	// Remove any extra results by least wanted first.
	while(pmapResult->size() > uMaxRequired)
	{
 á// Dec in use count.
 áif( bInUse )
 á	(--pmapResult->end())->second->DecUse();
 á// remove from results
 ápmapResult->erase(--pmapResult->end());
	}
	return;
}


void CRoutingZone::GetClosestTo(uint32 uMaxType, const CUInt128 &uTarget, const CUInt128 &uDistance, uint32 uMaxRequired, ContactMap *pmapResult, bool bEmptyFirst, bool bInUse) const
{
	// If leaf zone, do it here
	if (IsLeaf())
	{
 ám_pBin->GetClosestTo(uMaxType, uTarget, uMaxRequired, pmapResult, bEmptyFirst, bInUse);
 áreturn;
	}

	// otherwise, recurse in the closer-to-the-target subzone first
	int iCloser = uDistance.GetBitNumber(m_uLevel);
	m_pSubZones[iCloser]->GetClosestTo(uMaxType, uTarget, uDistance, uMaxRequired, pmapResult, bEmptyFirst, bInUse);

	// if still not enough tokens found, recurse in the other subzone too
	if (pmapResult->size() < uMaxRequired)
 ám_pSubZones[1-iCloser]->GetClosestTo(uMaxType, uTarget, uDistance, uMaxRequired, pmapResult, false, bInUse);
}


I only did a quick test of the code.. So it is possible there is still a bug.. Have fun.

#2 User is offline   netfinity 

  • Master of WARP
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1658
  • Joined: 23-April 04

Posted 04 March 2006 - 09:24 PM

Tried it for a while and it seems to be working. For once Kad returns more results than the servers.

Great work, tatikiran and Unknown1!
eMule v0.50a [NetF WARP v0.3a]
- Compiled for 32 and 64 bit Windows versions
- Optimized for fast (100Mbit/s) Internet connections
- Faster file completion via Dynamic Block Requests and dropping of stalling sources
- Faster searching via KAD with equal or reduced overhead
- Less GUI lockups through multi-threaded disk IO operations
- VIP "Payback" queue
- Fakealyzer (helps you chosing the right files)
- Quality Of Service to keep eMule from disturbing VoIP and other important applications (Vista/7/8 only!)
0

  • Member Options

Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users