Esempio n. 1
0
CContact *CRoutingZone::GetContact(const CUInt128& id) const throw()
{
    if (IsLeaf()) {
        return m_bin->GetContact(id);
    } else {
        CUInt128 distance = CKademlia::GetPrefs()->GetKadID();
        distance ^= id;
        return m_subZones[distance.GetBitNumber(m_level)]->GetContact(id);
    }
}
Esempio n. 2
0
CContact *CRoutingZone::GetContact(const CUInt128 &uID) const
{
	if (IsLeaf())
		return m_pBin->GetContact(uID);
	else{
		CUInt128 uDistance;
		CKademlia::GetPrefs()->GetKadID(&uDistance);
		uDistance.Xor(uID);
		return m_pSubZones[uDistance.GetBitNumber(m_uLevel)]->GetContact(uID);
	}
}
Esempio n. 3
0
CUInt128::CUInt128(const CUInt128 &uValue, UINT uNumBits)
{
	// Copy the whole ULONGs
	UINT uNumULONGs = uNumBits / 32;
	for (UINT iIndex=0; iIndex<uNumULONGs; iIndex++)
		m_uData[iIndex] = uValue.m_uData[iIndex];

	// Copy the remaining bits
	for (UINT iIndex=(32*uNumULONGs); iIndex<uNumBits; iIndex++)
		SetBitNumber(iIndex, uValue.GetBitNumber(iIndex));

	// Pad with random bytes (Not seeding based on time to allow multiple different ones to be created in quick succession)
	for (UINT iIndex=uNumBits; iIndex<128; iIndex++)
		SetBitNumber(iIndex, (rand()%2));
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
void CRoutingZone::GetClosestTo(uint32_t maxType, const CUInt128& target, const CUInt128& distance, uint32_t maxRequired, ContactMap *result, bool emptyFirst, bool inUse) const
{
    // If leaf zone, do it here
    if (IsLeaf()) {
        m_bin->GetClosestTo(maxType, target, maxRequired, result, emptyFirst, inUse);
        return;
    }

    // otherwise, recurse in the closer-to-the-target subzone first
    int closer = distance.GetBitNumber(m_level);
    m_subZones[closer]->GetClosestTo(maxType, target, distance, maxRequired, result, emptyFirst, inUse);

    // if still not enough tokens found, recurse in the other subzone too
    if (result->size() < maxRequired) {
        m_subZones[1-closer]->GetClosestTo(maxType, target, distance, maxRequired, result, false, inUse);
    }
}