Changeset 1691


Ignore:
Timestamp:
Jun 22, 2010, 11:38:20 PM (11 years ago)
Author:
Sven Rech
Message:

quadratic sieve queue informations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/QuadraticSieve/PeerToPeer.cs

    r1689 r1691  
    7474        private uint downloaded = 0;
    7575        private uint uploaded = 0;
     76        private HashSet<int> ourIndices;
     77        private Queue<KeyValuePair<int, DateTime>> lostIndices;
     78        private int loadIndex;
    7679
    7780        public delegate void P2PWarningHandler(String warning);
     
    198201        private void LoadStoreThreadProc()
    199202        {
    200             int loadIndex = 0;
     203            loadIndex = 0;
    201204            downloaded = 0;
    202205            uploaded = 0;
    203             HashSet<int> ourIndices = new HashSet<int>();   //Stores all the indices which belong to our packets
     206            ourIndices = new HashSet<int>();   //Stores all the indices which belong to our packets
    204207            //Stores all the indices (together with there check date) which belong to lost packets (i.e. packets that can't be load anymore):
    205             Queue<KeyValuePair<int, DateTime>> lostIndices = new Queue<KeyValuePair<int, DateTime>>();
     208            lostIndices = new Queue<KeyValuePair<int, DateTime>>();
    206209            double lastPerformance = 0;
    207210            DateTime performanceLastPut = new DateTime();
     
    247250                        }                       
    248251                    }
    249 
     252                                       
    250253                    SynchronizeHead();
     254                    UpdateStoreLoadQueueInformation();
    251255
    252256                    bool busy = false;
     
    269273                        uploaded += (uint)yield.Length;
    270274                        ShowTransfered(downloaded, uploaded);
     275                        UpdateStoreLoadQueueInformation();
    271276                        busy = true;
    272277                    }
     
    283288                        TryReadAndEnqueueYield(loadIndex, checkAlive, lostIndices);
    284289                        loadIndex++;
     290                        UpdateStoreLoadQueueInformation();
    285291                        busy = true;
    286292                    }
    287293                   
    288                     //check all lost indices which are last checked longer than 2 minutes ago (but only if we have nothing else to do):
     294                    //check lost indices which are last checked longer than 2 minutes ago (but only if we have nothing else to do):
    289295                    if (!busy)
    290296                    {
    291                         int count = 0;
    292297                        //TODO: Maybe we should throw away those indices, which have been checked more than several times.
    293                         while (lostIndices.Count != 0 && lostIndices.Peek().Value.CompareTo(DateTime.Now.Subtract(new TimeSpan(0, 2, 0))) < 0)
     298                        if (lostIndices.Count != 0 && lostIndices.Peek().Value.CompareTo(DateTime.Now.Subtract(new TimeSpan(0, 2, 0))) < 0)
    294299                        {
    295300                            var e = lostIndices.Dequeue();
    296301                            TryReadAndEnqueueYield(loadIndex, true, lostIndices);
    297                             count++;
     302                            UpdateStoreLoadQueueInformation();                           
    298303                        }
    299 
    300                         if (count == 0)
     304                        else
    301305                            Thread.Sleep(5000);    //Wait 5 seconds
    302306                    }
     
    316320                quadraticSieveQuickWatchPresentation.amountOfPeers.Content = "" + activePeers.Count + " other peer" + (activePeers.Count!=1 ? "s" : "") + " active!";
    317321            }, null);
     322        }
     323
     324        private void UpdateStoreLoadQueueInformation()
     325        {
     326            if (storequeue != null && ourIndices != null && lostIndices != null)
     327            {
     328                quadraticSieveQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     329                {
     330                    int upload = storequeue.Count;
     331                    int download = head - loadIndex - ourIndices.Count(x => x > loadIndex);
     332                    int lost = this.lostIndices.Count;
     333                    quadraticSieveQuickWatchPresentation.queueInformation.Content = "Queue: Upload " + upload + "! Download " + download + "! Lost " + lost + "!";
     334                }, null);
     335            }
    318336        }
    319337
     
    472490
    473491            //store in queue, so the LoadStoreThread can store it in the DHT later:
    474             storequeue.Enqueue(compressedYield);           
     492            storequeue.Enqueue(compressedYield);
     493
     494            UpdateStoreLoadQueueInformation();
    475495        }
    476496
Note: See TracChangeset for help on using the changeset viewer.