Ignore:
Timestamp:
Jun 20, 2010, 10:27:22 PM (11 years ago)
Author:
Paul Lelgemann
Message:

o Work on the distributed KeySearcher presentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1674 r1682  
    1616using KeySearcher.Helper;
    1717using KeySearcher.P2P;
    18 using KeySearcher.Presentation;
     18using KeySearcherPresentation;
     19using KeySearcherPresentation.Controls;
    1920
    2021namespace KeySearcher
     
    3536        private Mutex maxThreadMutex = new Mutex();
    3637
    37         private KeyQualityHelper _keyQualityHelper;
     38        private KeyQualityHelper keyQualityHelper;
     39        private P2PQuickWatchPresentation p2PQuickWatchPresentation;
     40        private LocalQuickWatchPresentation localQuickWatchPresentation;
    3841
    3942        private KeyPattern.KeyPattern pattern = null;
     
    9497            {
    9598                costMaster = value;
    96                 _keyQualityHelper = new KeyQualityHelper(costMaster);
     99                keyQualityHelper = new KeyQualityHelper(costMaster);
    97100            }
    98101        }
     
    204207
    205208        private KeySearcherSettings settings;
    206         private AutoResetEvent _connectResetEvent;
     209        private AutoResetEvent connectResetEvent;
    207210
    208211        public KeySearcher()
    209212        {
    210213            settings = new KeySearcherSettings(this);
    211             QuickWatchPresentation = new KeySearcherQuickWatchPresentation();
     214            QuickWatchPresentation = new QuickWatch();
     215            localQuickWatchPresentation = ((QuickWatch) QuickWatchPresentation).LocalQuickWatchPresentation;
     216            p2PQuickWatchPresentation = ((QuickWatch)QuickWatchPresentation).P2PQuickWatchPresentation;
     217            p2PQuickWatchPresentation.UpdateSettings(this, settings);
     218
     219            settings.PropertyChanged += SettingsPropertyChanged;
     220        }
     221
     222        void SettingsPropertyChanged(object sender, PropertyChangedEventArgs e)
     223        {
     224            p2PQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
     225                                                             new Action(UpdateIsP2PEnabledSetting));
     226        }
     227
     228        void UpdateIsP2PEnabledSetting()
     229        {
     230            ((QuickWatch)QuickWatchPresentation).IsP2PEnabled = settings.UsePeerToPeer;
     231            p2PQuickWatchPresentation.UpdateSettings(this, settings);
    212232        }
    213233
     
    283303
    284304        #endregion
    285 
    286         /* BEGIN functionality */
    287305
    288306        #region whole KeySearcher functionality
     
    547565        private IControlEncryption sender;
    548566        private DateTime beginBruteforcing;
     567        private DistributedBruteForceManager distributedBruteForceManager;
    549568
    550569        // modified by Christian Arnold 2009.12.07 - return type LinkedList (top10List)
     
    570589            }
    571590
    572             bytesToUse = 0;
     591            // bytesToUse = 0;
    573592
    574593            try
     
    591610        }
    592611
    593         private Dispatcher _dispatcher;
    594 
    595612        private void BruteForceWithPeerToPeerSystem()
    596613        {
    597             _dispatcher = Dispatcher.CurrentDispatcher;
    598614            GuiLogMessage("Launching p2p based bruteforce logic...", NotificationLevel.Info);
    599615            ValidateConnectionToPeerToPeerSystem();
    600             var bruteForceManager = new DistributedBruteForceManager(this, pattern, settings, _keyQualityHelper);
    601             bruteForceManager.Execute();
     616            distributedBruteForceManager = new DistributedBruteForceManager(this, pattern, settings, keyQualityHelper,
     617                                                                     p2PQuickWatchPresentation);
     618            distributedBruteForceManager.Execute();
    602619        }
    603620
     
    625642        {
    626643            P2PManager.ConnectionManager.OnP2PConnectionStateChangeOccurred += HandleConnectionStateChange;
    627             _connectResetEvent = new AutoResetEvent(false);
     644            connectResetEvent = new AutoResetEvent(false);
    628645
    629646            P2PManager.Connect();
    630647
    631             _connectResetEvent.WaitOne();
     648            connectResetEvent.WaitOne();
    632649
    633650            if (P2PManager.IsConnected)
     
    645662        void HandleConnectionStateChange(object sender, bool newState)
    646663        {
    647             _connectResetEvent.Set();
     664            connectResetEvent.Set();
    648665        }
    649666
    650667        #endregion
    651668
    652         internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern)
     669        internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern, bool redirectResultsToStatisticsGenerator = false)
    653670        {
    654671            BigInteger size = pattern.size();
     
    703720                #endregion
    704721
    705                 showProgress(costList, size, keycounter, doneKeys);
     722                if (redirectResultsToStatisticsGenerator)
     723                {
     724                    distributedBruteForceManager.StatisticsGenerator.ShowProgress(costList, size, keycounter, doneKeys);
     725                }
     726                else
     727                {
     728                    showProgress(costList, size, keycounter, doneKeys);
     729                }
     730               
    706731
    707732                #region set doneKeys to 0
     
    719744                ((ThreadStackElement)threadStack.Pop()).ev.Set();
    720745
    721             if (!stop)
     746            if (!stop && !redirectResultsToStatisticsGenerator)
    722747                ProgressChanged(1, 1);
    723748
     
    758783            ProgressChanged((double)keycounter / (double) size, 1.0);
    759784
    760             if (QuickWatchPresentation.IsVisible && doneKeys != 0 && !stop)
     785            if (localQuickWatchPresentation.IsVisible && doneKeys != 0 && !stop)
    761786            {
    762787                double time = (Math.Pow(10, BigInteger.Log((size - keycounter), 10) - BigInteger.Log(doneKeys, 10)));
     
    783808                }
    784809
    785                 ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    786                 {
    787                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).keysPerSecond.Text = "" + doneKeys;
     810                localQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     811                {
     812                    localQuickWatchPresentation.keysPerSecond.Text = "" + doneKeys;
    788813                    if (timeleft != new TimeSpan(-1))
    789814                    {
    790                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).timeLeft.Text = "" + timeleft;
     815                        localQuickWatchPresentation.timeLeft.Text = "" + timeleft;
    791816                        try
    792817                        {
    793                             ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "" + DateTime.Now.Add(timeleft);
     818                            localQuickWatchPresentation.endTime.Text = "" + DateTime.Now.Add(timeleft);
    794819                        }
    795820                        catch
    796821                        {
    797                             ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "in a galaxy far, far away...";
     822                            localQuickWatchPresentation.endTime.Text = "in a galaxy far, far away...";
    798823                        }
    799824                    }
    800825                    else
    801826                    {
    802                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).timeLeft.Text = "incalculable :-)";
    803                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "in a galaxy far, far away...";
     827                        localQuickWatchPresentation.timeLeft.Text = "incalculable :-)";
     828                        localQuickWatchPresentation.endTime.Text = "in a galaxy far, far away...";
    804829                    }
    805830
    806                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Clear();
     831                    localQuickWatchPresentation.entries.Clear();
    807832                    linkedListNode = costList.First;
    808833                   
     
    818843                        entry.Text = enc.GetString(linkedListNode.Value.decryption);
    819844
    820                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Add(entry);
     845                        localQuickWatchPresentation.entries.Add(entry);
    821846                        linkedListNode = linkedListNode.Next;
    822847                    }
     
    826851
    827852
    828             else if (!stop && QuickWatchPresentation.IsVisible)
    829             {
    830 
    831                 ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    832                 {
    833                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Clear();
     853            else if (!stop && localQuickWatchPresentation.IsVisible)
     854            {
     855
     856                localQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     857                {
     858                    localQuickWatchPresentation.entries.Clear();
    834859                    linkedListNode = costList.First;                   
    835860                    int i = 0;
     
    845870                        entry.Text = enc.GetString(linkedListNode.Value.decryption);
    846871
    847                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Add(entry);
     872                        localQuickWatchPresentation.entries.Add(entry);
    848873                        linkedListNode = linkedListNode.Next;
    849874                    }
     
    872897        }
    873898
    874         internal void IntegrateNewResults(LinkedList<ValueKey> costList)
    875         {
    876             foreach (var valueKey in costList)
    877             {
    878                 if (_keyQualityHelper.IsBetter(valueKey.value, value_threshold))
     899        internal void IntegrateNewResults(LinkedList<ValueKey> updatedCostList)
     900        {
     901            foreach (var valueKey in updatedCostList)
     902            {
     903                if (keyQualityHelper.IsBetter(valueKey.value, value_threshold))
    879904                {
    880905                    valuequeue.Enqueue(valueKey);
     
    883908
    884909            updateToplist();
    885             UpdateWithShowProgress();
    886910        }
    887911
     
    941965                }
    942966            }
    943         }
    944 
    945         private void UpdateWithShowProgress()
    946         {
    947             showProgress(costList, 1, 0, 0);
    948967        }
    949968
Note: See TracChangeset for help on using the changeset viewer.