Ignore:
Timestamp:
Dec 12, 2009, 2:07:52 PM (12 years ago)
Author:
arnold
Message:

executable, but non-optimized P2PManager/Worker System

File:
1 edited

Legend:

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

    r971 r980  
    8585        private KeySearcher_IControl keySearcher;
    8686        private KeyPattern actualKeyPattern;
     87        /// <summary>
     88        /// workaround: Flag which will be set, when the OnAllMasterControlsInitialized
     89        /// Event is thrown. So we can assure the correct flow of the KeySearcher
     90        /// </summary>
     91        private bool allMasterControlsInitialized = false;
     92        /// <summary>
     93        /// workaround: Flag which will be set, when a worker wants to
     94        /// bruteforce a pattern, but the MasterControls of the base
     95        /// KeySearcher aren't initialized yet. In this case the pattern
     96        /// will be stored in the variable actualKeyPattern and will be
     97        /// processed when the OnMasterControlsInitialized-Event is thrown
     98        /// </summary>
     99        private bool tryBruteforcingBeforeMastersInitialized = false;
    87100
    88101        public KeySearcherMaster(KeySearcher_IControl keysearcher)
     
    92105            // subscribe to event before any bruteforcing has started, so we make sure that this event will thrown in every case
    93106            this.keySearcher.OnBruteforcingEnded += new KeySearcher.KeySearcher.BruteforcingEnded(keySearcher_OnBruteforcingEnded);
     107            this.keySearcher.OnAllMasterControlsInitialized += new KeySearcher_IControl.IsReadyForExecution(keySearcher_OnAllMasterControlsInitialized);
    94108        }
    95109
     
    108122        public void StartBruteforcing(KeyPattern pattern)
    109123        {
    110             this.actualKeyPattern = pattern;
    111             // first subscribing to this event when Bruteforcing gets started pro-active
    112             this.keySearcher.OnAllMasterControlsInitialized += new KeySearcher_IControl.IsReadyForExecution(keySearcher_OnAllMasterControlsInitialized);
     124            // if not all MasterControls are initialized, store the actual
     125            // pattern and wait for throwing the OnMasterControlsInitialized-Event
     126            if (!allMasterControlsInitialized)
     127            {
     128                tryBruteforcingBeforeMastersInitialized = true;
     129                this.actualKeyPattern = pattern;
     130                return;
     131            }
     132            Bruteforcing(pattern);
     133        }
     134
     135        /* dirty workaround, because it could happen, that a Worker
     136         * wants to start Bruteforcing before all Master Controls of the base
     137         * KeySearcber (IEncryptionControl und ICostControl) are finally
     138         * initialized, in this case the pattern will be stored and processed
     139         * after this event was thrown. */
     140        private void keySearcher_OnAllMasterControlsInitialized()
     141        {
     142            this.allMasterControlsInitialized = true;
     143            if (this.tryBruteforcingBeforeMastersInitialized)
     144            {
     145                Bruteforcing(actualKeyPattern);
     146                actualKeyPattern = null;
     147                this.tryBruteforcingBeforeMastersInitialized = false;
     148            }
     149        }
     150
     151        private void Bruteforcing(KeyPattern actualKeyPattern)
     152        {
     153            //because the KeySearcher object uses this property instead of the parameters in some internal methods... Dirty implementation...
     154            this.keySearcher.Pattern = actualKeyPattern;
     155            //necessary, because the Pattern property seems to work incorrect
     156            this.keySearcher.Pattern.WildcardKey = actualKeyPattern.WildcardKey;
     157
     158            this.keySearcher.BruteforcePattern(actualKeyPattern, this.keySearcher.ControlMaster, this.keySearcher.CostMaster);
    113159        }
    114160
     
    125171        }
    126172
    127         private void keySearcher_OnAllMasterControlsInitialized()
    128         {
    129             if (this.keySearcher.CostMaster != null && this.keySearcher.ControlMaster != null)
    130             {
    131                 //because the KeySearcher object uses this property instead of the parameters in some internal methods... Dirty implementation...
    132                 this.keySearcher.Pattern = actualKeyPattern;
    133                 //necessary, because the Pattern property seems to work incorrect
    134                 this.keySearcher.Pattern.WildcardKey = actualKeyPattern.WildcardKey;
    135                 this.keySearcher.BruteforcePattern(actualKeyPattern, this.keySearcher.ControlMaster, this.keySearcher.CostMaster);
    136             }
    137         }
    138 
    139173        #endregion
    140174
Note: See TracChangeset for help on using the changeset viewer.