Brunet.Services.Dht.Dht.GetLeaveEarly C# (CSharp) Méthode

GetLeaveEarly() protected méthode

This helps us leave the Get early if we either have no results or our remaining results will not reach a majority due to too many nodes missing data. This closes the clients returns queue.
protected GetLeaveEarly ( AsDhtGetState adgs ) : void
adgs AsDhtGetState The AsDhtGetState to qualify for leaving early
Résultat void
    protected void GetLeaveEarly(AsDhtGetState adgs) {
      int left = adgs.queueMapping.Count;
      // Maybe we can leave early
      bool got_all_values = true;
      foreach (DictionaryEntry de in adgs.results) {
        int val = ((Hashtable) de.Value).Count;
        if(val < MAJORITY && ((val + left) >= MAJORITY)) {
          got_all_values = false;
          break;
        }
      }

      // If we got to leave early, we must clean up
      if(got_all_values) {
        if(Dht.DhtLog.Enabled) {
          ProtocolLog.Write(Dht.DhtLog, String.Format(
            "GetLeaveEarly found:left:total = {0}:{1}:{2}", 
            adgs.results.Count, left, DEGREE));
        }
        adgs.returns.Close();
        adgs.GotToLeaveEarly = true;
      }
    }