public void CheckingType() { if ((DateTime.Now - LastTypeSet).Ticks < 10 || m_byType == 4) { return; } m_tLastTypeSet = DateTime.Now; ExpireTime = DateTime.Now.AddMilliseconds(Opcodes.MIN2S(2)); m_byType++; //theApp.emuledlg->kademliawnd->ContactRef(this); }
public static void Process() { if (m_pInstance == null || !m_bRunning) { return; } bool bUpdateUserFile = false; uint uMaxUsers = 0; uint uTempUsers = 0; uint uLastContact = 0; DateTime tNow = DateTime.Now; Debug.Assert(m_pInstance.m_pPrefs != null); uLastContact = m_pInstance.m_pPrefs.GetLastContact(); SearchManager.UpdateStats(); if (m_tStatusUpdate <= tNow) { bUpdateUserFile = true; m_tStatusUpdate = tNow.AddMinutes(1); } if (m_tNextFirewallCheck <= tNow) { RecheckFirewalled(); } if (m_tNextUPnPCheck != DateTime.MinValue && m_tNextUPnPCheck <= tNow) { theApp.emuledlg.RefreshUPnP(); m_tNextUPnPCheck = DateTime.MinValue; // will be reset on firewallcheck } if (m_tNextSelfLookup <= tNow) { SearchManager.FindNode(m_pInstance.m_pPrefs.GetKadID(), true); m_tNextSelfLookup = tNow.AddHours(4); } if (m_tNextFindBuddy <= tNow) { m_pInstance.m_pPrefs.SetFindBuddy(); m_tNextFindBuddy = tNow.AddMinutes(20); } if (m_tExternPortLookup <= tNow && UDPFirewallTester.IsFWCheckUDPRunning() && GetPrefs().FindExternKadPort(false)) { // if our UDP firewallcheck is running and we don't know our external port, we send a request every 15 seconds Contact pContact = GetRoutingZone().GetRandomContact(3, Opcodes.KADEMLIA_VERSION6_49aBETA); if (pContact != null) { //DEBUG_ONLY(DebugLog("Requesting our external port from %s", IPAddress.Parse(IPAddress.NetworkToHostOrder(pContact.IPAddress).ToString()).ToString())); GetUDPListener().SendNullPacket(Opcodes.KADEMLIA2_PING, pContact.IPAddress, pContact.UDPPort, pContact.UDPKey, &pContact.ClientID); } else { DEBUG_ONLY(DebugLogWarning("No valid client for requesting external port available")); } m_tExternPortLookup = tNow.AddMilliseconds(15); } foreach (RoutingZone pZone in m_mapEvents.Values) { if (bUpdateUserFile) { // The EstimateCount function is not made for really small networks, if we are in LAN mode, it is actually // better to assume that all users of the network are in our routingtable and use the real count function if (IsRunningInLANMode()) { uTempUsers = pZone.GetNumContacts(); } else { uTempUsers = pZone.EstimateCount(); } if (uMaxUsers < uTempUsers) { uMaxUsers = uTempUsers; } } if (m_tBigTimer <= tNow) { if (pZone.m_tNextBigTimer <= tNow) { if (pZone.OnBigTimer()) { pZone.m_tNextBigTimer = tNow.AddHours(1); m_tBigTimer = tNow.AddSeconds(10); } } else { if (uLastContact && ((tNow - uLastContact) > (Opcodes.KADEMLIADISCONNECTDELAY - Opcodes.MIN2S(5)))) { if (pZone.OnBigTimer()) { pZone.m_tNextBigTimer = tNow.AddHours(1); m_tBigTimer = tNow.AddSeconds(10); } } } } if (pZone.m_tNextSmallTimer <= tNow) { pZone.OnSmallTimer(); pZone.m_tNextSmallTimer = tNow.AddMinutes(1); } } // This is a convenient place to add this, although not related to routing if (m_tNextSearchJumpStart <= tNow) { SearchManager.JumpStart(); m_tNextSearchJumpStart = tNow.AddMilliseconds(Defines.SEARCH_JUMPSTART); } // Try to consolidate any zones that are close to empty. if (m_tConsolidate <= tNow) { uint uMergedCount = m_pInstance.m_pRoutingZone.Consolidate(); if (uMergedCount > 0) { AddDebugLogLine(false, "Kad merged %u Zones", uMergedCount); } m_tConsolidate = tNow.AddMinutes(45); } //Update user count only if changed. if (bUpdateUserFile) { if (uMaxUsers != m_pInstance.m_pPrefs.GetKademliaUsers()) { m_pInstance.m_pPrefs.SetKademliaUsers(uMaxUsers); m_pInstance.m_pPrefs.SetKademliaFiles(); theApp.emuledlg.ShowUserCount(); } } if (!IsConnected() && !s_liBootstapList.IsEmpty() && ((tNow - m_tBootstrap).Milliseconds > 15 || (GetRoutingZone().GetNumContacts() == 0 && (tNow - m_tBootstrap).Milliseconds >= 2))) { Contact pContact = s_liBootstapList.RemoveHead(); m_tBootstrap = tNow; //DebugLog("Trying to Bootstrap Kad from %s, Distance: %s, Version: %u, %u Contacts left", ipstr(ntohl(pContact->GetIPAddress())), pContact->GetDistance().ToHexString(), pContact->GetVersion(), s_liBootstapList.GetCount()); m_pInstance.m_pUDPListener.Bootstrap(pContact.IPAddress, pContact.UDPPort, pContact.Version, pContact.ClientID); } if (GetUDPListener() != null) { GetUDPListener().ExpireClientSearch(); // function does only one compare in most cases, so no real need for a timer } }