Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CG2Node::OnPing(G2Packet* pPacket)
- {
- ASSUME_LOCK(Neighbours.m_pSection);
- bool bUdp = false;
- bool bRelay = false;
- // bool bTestFirewall = false;
- CEndPoint addr;
- if(pPacket->m_bCompound)
- {
- char szType[9];
- quint32 nLength = 0, nNext = 0;
- while(pPacket->ReadPacket(&szType[0], nLength))
- {
- nNext = pPacket->m_nPosition + nLength;
- if(strcmp("UDP", szType) == 0 && nLength >= 6)
- {
- pPacket->ReadHostAddress(&addr);
- if(addr.isValid())
- {
- bUdp = true;
- }
- }
- else if(strcmp("RELAY", szType) == 0)
- {
- bRelay = true;
- }
- else if(strcmp("TFW", szType) == 0)
- {
- // bTestFirewall = true;
- }
- pPacket->m_nPosition = nNext;
- }
- }
- if(!bUdp && !bRelay)
- {
- // direct ping
- G2Packet* pPong = G2Packet::New("PO", false);
- SendPacket(pPong, false, true);
- return;
- }
- if(bUdp && !bRelay)
- {
- // /PI/UDP
- if(Neighbours.IsG2Hub())
- {
- G2Packet* pRelay = G2Packet::New("RELAY");
- pPacket->PrependPacket(pRelay);
- int nRelayed = 0, nCount = Neighbours.GetCount();
- QList<int> lToRelayIndex;
- for(int i = 0; i < nCount && nRelayed < quazaaSettings.Gnutella2.PingRelayLimit; ++i)
- {
- int nIndex = qrand() % nCount;
- if(!lToRelayIndex.contains(nIndex))
- {
- CNeighbour* pNode = Neighbours.GetAt(nIndex);
- if(pNode != this
- && pNode->m_nProtocol == dpG2
- && pNode->m_nState == nsConnected
- && static_cast<CG2Node*>(pNode)->m_nType == G2_LEAF )
- {
- pPacket->AddRef();
- ((CG2Node*)pNode)->SendPacket(pPacket, true, true);
- nRelayed++;
- }
- }
- }
- return;
- }
- }
- if(bUdp && bRelay)
- {
- G2Packet* pPong = G2Packet::New("PO", true);
- pPong->WritePacket("RELAY", 0);
- Datagrams.SendPacket(addr, pPong, true);
- pPong->Release();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement