void CRoutingZone::OnSmallTimer() { if (!IsLeaf()) { return; } CContact *c = NULL; time_t now = time(NULL); ContactList entries; // Remove dead entries m_bin->GetEntries(&entries); for (ContactList::iterator it = entries.begin(); it != entries.end(); ++it) { c = *it; if (c->GetType() == 4) { if ((c->GetExpireTime() > 0) && (c->GetExpireTime() <= now)) { if (!c->InUse()) { m_bin->RemoveContact(c); delete c; } continue; } } if(c->GetExpireTime() == 0) { c->SetExpireTime(now); } } c = m_bin->GetOldest(); if (c != NULL) { if (c->GetExpireTime() >= now || c->GetType() == 4) { m_bin->PushToBottom(c); c = NULL; } } if (c != NULL) { c->CheckingType(); if (c->GetVersion() >= 6) { DebugSend(L"Kad2HelloReq", c->GetIPAddress(), c->GetUDPPort()); CUInt128 clientID = c->GetClientID(); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, c->GetIPAddress(), c->GetUDPPort(), c->GetVersion(), c->GetUDPKey(), &clientID, false); if (c->GetVersion() >= 8) { // FIXME: // This is a bit of a work around for statistic values. Normally we only count values from incoming HELLO_REQs for // the firewalled statistics in order to get numbers from nodes which have us on their routing table, // however if we send a HELLO due to the timer, the remote node won't send a HELLO_REQ itself anymore (but // a HELLO_RES which we don't count), so count those statistics here. This isn't really accurate, but it should // do fair enough. Maybe improve it later for example by putting a flag into the contact and make the answer count CKademlia::GetPrefs()->StatsIncUDPFirewalledNodes(false); CKademlia::GetPrefs()->StatsIncTCPFirewalledNodes(false); } } else if (c->GetVersion() >= 2) { DebugSend(L"Kad2HelloReq", c->GetIPAddress(), c->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, c->GetIPAddress(), c->GetUDPPort(), c->GetVersion(), 0, NULL, false); ASSERT(c->GetUDPKey() == CKadUDPKey(0)); } else { ASSERT(0); } } }
void CRoutingZone::OnSmallTimer() { if (!IsLeaf()) return; CContact *pContact = NULL; time_t tNow = time(NULL); ContactList listEntries; // Remove dead entries m_pBin->GetEntries(&listEntries); for (ContactList::iterator itContactList = listEntries.begin(); itContactList != listEntries.end(); ++itContactList) { pContact = *itContactList; if ( pContact->GetType() == 4) { if (((pContact->m_tExpires > 0) && (pContact->m_tExpires <= tNow))) { if(!pContact->InUse()) { //----------------------------------------------------------------- CString strID; CUInt128 uId = pContact->GetClientID(); uId.ToHexString(&strID); CString strIP; pContact->GetIPAddress(&strIP); TRACE(_T("DelContact id=%s ip=%s %u %u %u\n"), strID, strIP, pContact->GetTCPPort(), pContact->GetUDPPort(), CKademlia::GetRoutingZone()->GetNumContacts()); //----------------------------------------------------------------- m_pBin->RemoveContact(pContact); delete pContact; } continue; } } if(pContact->m_tExpires == 0) pContact->m_tExpires = tNow; } pContact = m_pBin->GetOldest(); if( pContact != NULL ) { if ( pContact->m_tExpires >= tNow || pContact->GetType() == 4) { m_pBin->RemoveContact(pContact); m_pBin->m_listEntries.push_back(pContact); pContact = NULL; } } if(pContact != NULL) { pContact->CheckingType(); if (pContact->GetVersion() >= 2/*47a*/) { //--->xt if (thePrefs.GetDebugClientKadUDPLevel() > 0) //DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), true); } else { //--->xt if (thePrefs.GetDebugClientKadUDPLevel() > 0) //DebugSend("KADEMLIA_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), false); if (pContact->CheckIfKad2()) { //--->xt if (thePrefs.GetDebugClientKadUDPLevel() > 0) //DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), true); } } } }
void CRoutingZone::OnSmallTimer() { if (!IsLeaf()) return; CContact *pContact = NULL; time_t tNow = time(NULL); ContactList listEntries; // Remove dead entries m_pBin->GetEntries(&listEntries); for (ContactList::iterator itContactList = listEntries.begin(); itContactList != listEntries.end(); ++itContactList) { pContact = *itContactList; if ( pContact->GetType() == 4) { if (((pContact->m_tExpires > 0) && (pContact->m_tExpires <= tNow))) { if(!pContact->InUse()) { m_pBin->RemoveContact(pContact); delete pContact; } continue; } } if(pContact->m_tExpires == 0) pContact->m_tExpires = tNow; } pContact = m_pBin->GetOldest(); if( pContact != NULL ) { if ( pContact->m_tExpires >= tNow || pContact->GetType() == 4) { m_pBin->PushToBottom(pContact); pContact = NULL; } } if(pContact != NULL) { pContact->CheckingType(); if (pContact->GetVersion() >= 6){ /*48b*/ if (thePrefs.GetDebugClientKadUDPLevel() > 0) DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CUInt128 uClientID = pContact->GetClientID(); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), pContact->GetVersion(), pContact->GetUDPKey(), &uClientID, false); if (pContact->GetVersion() >= KADEMLIA_VERSION8_49b){ // FIXME: // This is a bit of a work arround for statistic values. Normally we only count values from incoming HELLO_REQs for // the firewalled statistics in order to get numbers from nodes which have us on their routing table, // however if we send a HELLO due to the timer, the remote node won't send a HELLO_REQ itself anymore (but // a HELLO_RES which we don't count), so count those statistics here. This isn't really accurate, but it should // do fair enough. Maybe improve it later for example by putting a flag into the contact and make the answer count CKademlia::GetPrefs()->StatsIncUDPFirewalledNodes(false); CKademlia::GetPrefs()->StatsIncTCPFirewalledNodes(false); } } else if (pContact->GetVersion() >= 2/*47a*/){ if (thePrefs.GetDebugClientKadUDPLevel() > 0) DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), pContact->GetVersion(), 0, NULL, false); ASSERT( CKadUDPKey(0) == pContact->GetUDPKey() ); } else { if (thePrefs.GetDebugClientKadUDPLevel() > 0) DebugSend("KADEMLIA_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), 0, 0, NULL, false); if (pContact->CheckIfKad2()) { if (thePrefs.GetDebugClientKadUDPLevel() > 0) DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort()); CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), 1, 0, NULL, false); } } } }