Esempio n. 1
0
 public void AddToPending(Contact pending)
 {
     lock (pendingContacts)
     {
         pendingContacts.AddDistinctBy(pending, c => c.ID, (c) => PendingContactAdded?.Invoke(this, new ContactEventArgs()
         {
             Contact = c
         }));
     }
 }
Esempio n. 2
0
        /// <summary>
        ///  The contact that did not respond (or had an error) gets n tries before being evicted
        ///  and replaced with the most recently contact that wants to go into the non-responding contact's kbucket.
        /// </summary>
        /// <param name="toEvict">The contact that didn't respond.</param>
        /// <param name="toReplace">The contact that can replace the non-responding contact.</param>
        public void DelayEviction(Contact toEvict, Contact toReplace)
        {
            // Non-concurrent list needs locking.
            lock (pendingContacts)
            {
                // Add only if it's a new pending contact.
                pendingContacts.AddDistinctBy(toReplace, c => c.ID, (c) => PendingContactAdded?.Invoke(this, new ContactEventArgs()
                {
                    Contact = c
                }));
            }

            BigInteger key   = toEvict.ID.Value;
            int        count = AddContactToEvict(key);

            if (count == Constants.EVICTION_LIMIT)
            {
                ReplaceContact(toEvict);
            }
        }