当前位置: 首页>>代码示例>>C++>>正文


C++ CUInt128类代码示例

本文整理汇总了C++中CUInt128的典型用法代码示例。如果您正苦于以下问题:C++ CUInt128类的具体用法?C++ CUInt128怎么用?C++ CUInt128使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CUInt128类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DebugLogWarning

void CRoutingZone::DbgWriteBootstrapFile()
{
	DebugLogWarning(_T("Writing special bootstrap nodes.dat - not intended for normal use"));
	try
	{
		// Write a saved contact list.
		CUInt128 uID;
		CSafeBufferedFile file;
		CFileException fexp;
		if (file.Open(m_sFilename, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary|CFile::shareDenyWrite, &fexp))
		{
			setvbuf(file.m_pStream, NULL, _IOFBF, 32768);

			// The bootstrap method gets a very nice sample of contacts to save.
			ContactMap mapContacts;
			CUInt128 uRandom(CUInt128((ULONG)0), 0);
			CUInt128 uDistance = uRandom;
			uDistance.Xor(uMe);
			GetClosestTo(2, uRandom, uDistance, 1200, &mapContacts, false, false);
			// filter out Kad1 nodes
			for (ContactMap::iterator itContactMap = mapContacts.begin(); itContactMap != mapContacts.end(); )
			{
				ContactMap::iterator itCurContactMap = itContactMap;
				++itContactMap;
				CContact* pContact = itCurContactMap->second;
				if (pContact->GetVersion() <= 1)
					mapContacts.erase(itCurContactMap);
			}
			// Start file with 0 to prevent older clients from reading it.
			file.WriteUInt32(0);
			// Now tag it with a version which happens to be 2 (1 till 0.48a).
			file.WriteUInt32(3);
			file.WriteUInt32(1); // if we would use version >=3, this would mean that this is not a normal nodes.dat
			file.WriteUInt32((uint32_t)mapContacts.size());
			for (ContactMap::const_iterator itContactMap = mapContacts.begin(); itContactMap != mapContacts.end(); ++itContactMap)
			{
				CContact* pContact = itContactMap->second;
				pContact->GetClientID(&uID);
				file.WriteUInt128(&uID);
				file.WriteUInt32(pContact->GetIPAddress());
				file.WriteUInt16(pContact->GetUDPPort());
				file.WriteUInt16(pContact->GetTCPPort());
				file.WriteUInt8(pContact->GetVersion());
			}
			file.Close();
			AddDebugLogLine( false, _T("Wrote %ld contact to bootstrap file."), mapContacts.size());
		}
		else
			DebugLogError(_T("Unable to store Kad file: %s"), m_sFilename);
	}
	catch (CFileException* e)
	{
		e->Delete();
		AddDebugLogLine(false, _T("CFileException in CRoutingZone::writeFile"));
	}

}
开发者ID:HackLinux,项目名称:eMule-IS-Mod,代码行数:57,代码来源:RoutingZone.cpp

示例2: StatsAddClosestDistance

void CKademlia::StatsAddClosestDistance(CUInt128 uDist){
	if (uDist.Get32BitChunk(0) > 0){
		uint32_t nToAdd = (0xFFFFFFFF / uDist.Get32BitChunk(0)) / 2;
		if (m_liStatsEstUsersProbes.Find(nToAdd) == NULL)
			m_liStatsEstUsersProbes.AddHead(nToAdd);
	}
	if (m_liStatsEstUsersProbes.GetCount() > 100)
		m_liStatsEstUsersProbes.RemoveTail();
}
开发者ID:HackLinux,项目名称:eMule-IS-Mod,代码行数:9,代码来源:Kademlia.cpp

示例3:

// UInt128 values are stored a little weird way...
// Four little-endian 32-bit numbers, stored in
// big-endian order
CUInt128 CFileDataIO::ReadUInt128() const
{
	CUInt128 value;
	for (int i = 0; i < 4; i++) {
		// Four 32bits chunks
		value.Set32BitChunk(i, ReadUInt32());
	}

	return value;
}
开发者ID:0vermind,项目名称:hmule,代码行数:13,代码来源:SafeFile.cpp

示例4: throw

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);
    }
}
开发者ID:supertanglang,项目名称:NeoLoader,代码行数:10,代码来源:RoutingZone.cpp

示例5: CancelNodeFWCheckUDPSearch

bool CSearchManager::FindNodeFWCheckUDP(){
	CancelNodeFWCheckUDPSearch();
	CUInt128 uID;
	uID.SetValueRandom();
	DebugLog(_T("Starting NODEFWCHECKUDP Kad Search"));
	CSearch *pSearch = new CSearch;
	pSearch->m_uType = CSearch::NODEFWCHECKUDP;
	pSearch->m_uTarget = uID;
	return StartSearch(pSearch);
}
开发者ID:techpub,项目名称:archive-code,代码行数:10,代码来源:SearchManager.cpp

示例6:

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);
	}
}
开发者ID:HackLinux,项目名称:eMule-IS-Mod,代码行数:11,代码来源:RoutingZone.cpp

示例7: memcmp

bool CKadID::SetKey(CHolder<CPublicKey>& pKey, UINT eAlgorithm)
{
	if(m_PublicKey)
		return m_PublicKey->GetSize() == pKey->GetSize() && memcmp(m_PublicKey->GetKey(), pKey->GetKey(), m_PublicKey->GetSize()) == 0;

	CUInt128 ID;
	MakeID(pKey, ID.GetData(), ID.GetSize(), eAlgorithm);
	if(CompareTo(ID) != 0)
		return false;

	m_PublicKey = pKey;
	return true;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:13,代码来源:KadID.cpp

示例8: Cfg

CUInt128 CKademlia::MakeCloseTarget(int *pDistance)
{
	if(!m_pKadHandler)
	{
		if(pDistance)
			*pDistance = -1;
		return 0;
	}

	CUInt128 uMyID = m_pRootZone->GetID();
	NodeMap Nodes;
	m_pRootZone->GetClosestNodes(uMyID, Nodes, Cfg()->GetInt("BucketSize"));
	if(Nodes.size() < 2)
	{
		if(pDistance)
			*pDistance = -1;
		return 0;
	}
	
	// Find Median distance difference between nodes closest to us
	vector<CUInt128> Diff;
	for(NodeMap::iterator np = Nodes.begin(), n = np++; np != Nodes.end(); n = np++)
		Diff.push_back(np->first - n->first);
	CUInt128 Sep = Median(Diff);

	// generate ID that is closer to us than the closest node by a few difference
	CUInt128 uDistance = Nodes.begin()->first;
	for(int i=0; i < 3 && uDistance > Sep; i++)
		uDistance = uDistance - Sep;
	CUInt128 uCloser = uMyID ^ uDistance;

	// count the matchign bits
	UINT uLevel=0;
	for(; uLevel < uMyID.GetBitSize(); uLevel++)
	{
		if(uCloser.GetBit(uLevel) != uMyID.GetBit(uLevel))
			break;
	}

	// add a few more matching bytes
	for(UINT i=0; i < 4 && uLevel < uMyID.GetBitSize() - 1; i++)
	{
		uCloser.SetBit(uLevel, uMyID.GetBit(uLevel));
		uLevel++;
	}

	if(pDistance)
		*pDistance = (int)uMyID.GetBitSize() - uLevel;

	// create a random ID that we are closest to
	CUInt128 uRandom(uCloser, uLevel);
	//wstring sTest = (uMyID ^ uRandom).ToBin();
	return uRandom;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:54,代码来源:Kademlia.cpp

示例9: SendStoreRequest

bool CIndexed::SendStoreRequest(const CUInt128& uKeyID)
{
	Load* pLoad;
	if(m_mapLoad.Lookup(CCKey(uKeyID.GetData()), pLoad))
	{
		if(pLoad->uTime < (uint32)time(NULL))
		{
			m_mapLoad.RemoveKey(CCKey(uKeyID.GetData()));
			m_uTotalIndexLoad--;
			delete pLoad;
			return true;
		}
		return false;
	}
	return true;
}
开发者ID:litaobj,项目名称:easymule,代码行数:16,代码来源:Indexed.cpp

示例10: StatsAddClosestDistance

void CKademlia::StatsAddClosestDistance(const CUInt128& distance)
{
	if (distance.Get32BitChunk(0) > 0) {
		uint32_t toAdd = (0xFFFFFFFF / distance.Get32BitChunk(0)) / 2;
		std::list<uint32_t>::iterator it = m_statsEstUsersProbes.begin();
		for (; it != m_statsEstUsersProbes.end(); ++it) {
			if (*it == toAdd) {
				break;
			}
		}
		if (it == m_statsEstUsersProbes.end()) {
			m_statsEstUsersProbes.push_front(toAdd);
		}
	}
	if (m_statsEstUsersProbes.size() > 100) {
		m_statsEstUsersProbes.pop_back();
	}
}
开发者ID:Artoria2e5,项目名称:amule-dlp,代码行数:18,代码来源:Kademlia.cpp

示例11: FindNodeSpecial

bool CSearchManager::FindNodeSpecial(const CUInt128& id, CKadClientSearcher *requester)
{
	// Do a node lookup.
	AddDebugLogLineN(logKadSearch, wxT("Starting NODESPECIAL Kad Search for ") + id.ToHexString());
	CSearch *search = new CSearch;
	search->SetSearchTypes(CSearch::NODESPECIAL);
	search->SetTargetID(id);
	search->SetNodeSpecialSearchRequester(requester);
	return StartSearch(search);
}
开发者ID:windreamer,项目名称:amule-dlp,代码行数:10,代码来源:SearchManager.cpp

示例12: FindNodeSpecial

bool CSearchManager::FindNodeSpecial(const CUInt128 &uID, CKadClientSearcher* pRequester){
	// Do a node lookup.
	CString strDbgID;
	uID.ToHexString(&strDbgID);
	DebugLog(_T("Starting NODESPECIAL Kad Search for %s"), strDbgID);
	CSearch *pSearch = new CSearch;
	pSearch->m_uType = CSearch::NODESPECIAL;
	pSearch->m_uTarget = uID;
	pSearch->SetNodeSpecialSearchRequester(pRequester);
	return StartSearch(pSearch);
}
开发者ID:techpub,项目名称:archive-code,代码行数:11,代码来源:SearchManager.cpp

示例13: GetNextDecoyToPublish

void KadUDPPublisher::PublishNextDecoy(void)
{
    KademliaProtectorSystemReference ref;
    Vector v_files;

    GetNextDecoyToPublish(v_files);

    if(v_files.Size()==0)
        return;

    DonkeyFile *file=(DonkeyFile*)v_files.Get(0);

    //if(!file->m_last_publish.HasTimedOut(60*60)){
    //	return;
    //}

    ref.System()->LogToFile("KadUDPPublisher::PublishNextDecoy(void) BEGIN");

    //file->m_last_publish.Refresh();

    Vector v_contacts;
    //publish ourselves as a source for this file
    CUInt128 key;
    key.setValueBE(file->m_hash);
    ref.System()->GetContactManager()->GetContactsForKey(key,v_contacts);

    while(v_contacts.Size()>20) { //TYDEBUG
        v_contacts.Remove(rand()%v_contacts.Size());
    }

    TRACE("Publishing decoy %s\n",file->m_shash.c_str());
    for(int i=0; i<(int)v_contacts.Size(); i++) {
        if(rand()&1)
            continue;
        PublishSource(key.getDataPtr(),(KadContact*)v_contacts.Get(i));
    }
}
开发者ID:vdrive,项目名称:TrapperKeeper,代码行数:37,代码来源:KadUDPPublisher.cpp

示例14: HandleScope

CUInt128 CJSKadID::FromValue(v8::Local<v8::Value> value)
{
    v8::HandleScope HandleScope(v8::Isolate::GetCurrent());

	CUInt128 Value;
	if(value->IsString())
		Value.FromHex(CJSEngine::GetWStr(value));
	else if(value->IsObject())
	{
		if(CKadIDObj* pVariant = GetCObject<CKadIDObj>(value->ToObject()))
			Value = pVariant->m_Value;
		else if(CVariantPrx* pVariant = GetCObject<CVariantPrx>(value->ToObject()))
			Value = pVariant->GetCopy();
	}
	else	
	{
		sint64 iValue = value->IntegerValue();
		if(iValue < 0)
			Value = CUInt128(true);
		else
			Value = CUInt128((sint32)iValue);
	}
	return Value;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:24,代码来源:JSKadID.cpp

示例15:

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));
}
开发者ID:LjApps,项目名称:eMule-VeryCD,代码行数:15,代码来源:UInt128.cpp


注:本文中的CUInt128类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。