コード例 #1
0
ファイル: g2node.cpp プロジェクト: geekt/quazaa
void CG2Node::OnQuery(G2Packet *pPacket)
{
	// just read guid for now to have it in routing table

	QUuid oGUID;
	if( pPacket->m_bCompound )
		pPacket->SkipCompound();

	if( pPacket->GetRemaining() >= 16 )
	{
		oGUID = pPacket->ReadGUID();
		Network.m_oRoutingTable.Add(oGUID, this, false);

		if( m_nType == G2_LEAF ) // temporary
		{
			G2Packet* pQA = G2Packet::New("QA", true);
			quint32 tNow = time(0);
			pQA->WritePacket("TS", 4)->WriteIntLE(tNow);
			pQA->WritePacket("D", 8)->WriteHostAddress(&Network.m_oAddress);
			pQA->WriteIntLE(Network.m_nLeavesConnected);

			quint32 nCount = 0;

			for( uint i = 0; i < HostCache.size() && nCount < 100u; i++, nCount++ )
			{
				pQA->WritePacket("S", 6)->WriteHostAddress(&HostCache.m_lHosts[i]->m_oAddress);
			}

			pQA->WriteByte(0);
			pQA->WriteGUID(oGUID);
			//qDebug() << "Sending query ACK " << pQA->ToHex() << pQA->ToASCII();
			SendPacket(pQA, true, true);
		}
	}
}
コード例 #2
0
ファイル: query.cpp プロジェクト: c3c/quazaa
G2Packet* CQuery::ToG2Packet(CEndPoint* pAddr, quint32 nKey)
{
	G2Packet* pPacket = G2Packet::New("Q2", true);

	//bool bWantURL = true;
	bool bWantDN = (!m_sDescriptiveName.isEmpty());
	bool bWantMD = !m_sMetadata.isEmpty();
	//bool bWantPFS = true;

	if(pAddr)
	{
		G2Packet* pUDP = pPacket->WritePacket("UDP", 10);
		pUDP->WriteHostAddress(pAddr);
		pUDP->WriteIntLE(nKey);
	}

	if(bWantDN)
	{
		pPacket->WritePacket("DN", m_sDescriptiveName.toUtf8().size())->WriteString(m_sDescriptiveName, false);
	}
	if(bWantMD)
	{
		pPacket->WritePacket("MD", m_sMetadata.toUtf8().size())->WriteString(m_sMetadata, false);
	}

	foreach(CHash pHash, m_lHashes)
	{
		pPacket->WritePacket("URN", pHash.GetFamilyName().size() + CHash::ByteCount(pHash.getAlgorithm()) + 1);
		pPacket->WriteString(pHash.GetFamilyName() + "\0" + pHash.RawValue(), false);
	}
コード例 #3
0
ファイル: g2node.cpp プロジェクト: geekt/quazaa
void CG2Node::SendLNI()
{
	G2Packet* pLNI = G2Packet::New("LNI", true);
	pLNI->WritePacket("NA", 6)->WriteHostAddress(&Network.m_oAddress);
	pLNI->WritePacket("GU", 16)->WriteGUID(quazaaSettings.Profile.GUID);
	pLNI->WritePacket("V", 4)->WriteString(quazaaGlobals.VendorCode(), false);

	if( Network.isHub() )
	{
		quint16 nLeafs = quazaaSettings.Gnutella2.NumLeafs;
		pLNI->WritePacket("HS", 4);
		pLNI->WriteIntLE(Network.m_nLeavesConnected);
		pLNI->WriteIntLE(nLeafs);
		pLNI->WritePacket("QK", 0);
	}

	pLNI->WritePacket("g2core", 0);

	SendPacket(pLNI, false, true);
}
コード例 #4
0
void CNetwork::DispatchKHL()
{
	QMutexLocker l(&Neighbours.m_pSection);

	if(Neighbours.m_lNodes.isEmpty())
	{
		return;
	}

	G2Packet* pKHL = G2Packet::New("KHL");
	quint32 ts = time(0);
	pKHL->WritePacket("TS", 4)->WriteIntLE(ts);

	for(QList<CNeighbour*>::iterator itNode = Neighbours.begin(); itNode != Neighbours.end(); ++itNode)
	{
		CNeighbour* pNode = *itNode;

		if( pNode->m_nProtocol != dpGnutella2 )
				continue;

		if(((CG2Node*)pNode)->m_nType == G2_HUB && pNode->m_nState == nsConnected)
		{
			pKHL->WritePacket("NH", 6)->WriteHostAddress(&pNode->m_oAddress);
		}
	}

	quint32 nCount = 0;

	for(; nCount < (quint32)quazaaSettings.Gnutella2.KHLHubCount && HostCache.size() > nCount; nCount++)
	{
		pKHL->WritePacket("CH", 10)->WriteHostAddress(&HostCache.m_lHosts.at(nCount)->m_oAddress);
		pKHL->WriteIntLE(&HostCache.m_lHosts.at(nCount)->m_tTimestamp);
	}


	for(QList<CNeighbour*>::iterator itNode = Neighbours.begin(); itNode != Neighbours.end(); ++itNode)
	{
		CNeighbour* pNode = *itNode;

		if( pNode->m_nProtocol != dpGnutella2 )
			continue;

		if(pNode->m_nState == nsConnected)
		{
			((CG2Node*)pNode)->SendPacket(pKHL, false, false);
		}
	}
	pKHL->Release();
}