public Contact(UInt128 uClientID, uint uIp, ushort uUdpPort, ushort uTcpPort, UInt128 uTarget, byte uVersion, KadUDPKey cUDPKey, bool bIPVerified) { m_uClientID = uClientID; m_uDistance = new UInt128(uTarget.High, uTarget.Low); m_uDistance.Xor(uClientID); m_uIp = uIp; UDPPort = uUdpPort; TCPPort = uTcpPort; Version = uVersion; UDPKey = cUDPKey; IsIpVerified = bIPVerified; InitContact(); }
public Contact(UInt128 uClientID, uint uIp, ushort uUdpPort, ushort uTcpPort, byte uVersion, KadUDPKey cUDPKey, bool bIPVerified) { m_uClientID = uClientID; Kademlia.GetPrefs().GetKadID(ref m_uDistance); m_uDistance.Xor(uClientID); m_uIp = uIp; UDPPort = uUdpPort; TCPPort = uTcpPort; Version = uVersion; UDPKey = cUDPKey; IsIpVerified = bIPVerified; InitContact(); }
public void GetClosestTo(uint uMaxType, UInt128 uTarget, uint uMaxRequired, Dictionary <UInt128, Contact> pmapResult, bool bEmptyFirst = true, bool bInUse = false) { // Empty list if requested. if (bEmptyFirst) { pmapResult.Clear(); } // Return 0 since we have no entries. if (m_listEntries.Count == 0) { return; } // First put results in sort order for uTarget so we can insert them correctly. // We don't care about max results at this time. foreach (var contact in m_listEntries) { if (contact.Type <= uMaxType && contact.IsIpVerified) { UInt128 uTargetDistance = contact.ClientID; uTargetDistance.Xor(uTarget); pmapResult[uTargetDistance] = contact; // This list will be used for an unknown time, Inc in use so it's not deleted. if (bInUse) { contact.IncUse(); } } } // Remove any extra results by least wanted first. while (pmapResult.Count > uMaxRequired) { // Dec in use count. if (bInUse) { (--pmapResult->end())->second->DecUse(); } // remove from results pmapResult->erase(--pmapResult->end()); } // Return result count to the caller. return; }