Ignore:
Timestamp:
Feb 11, 2010, 3:48:49 PM (12 years ago)
Author:
arnold
Message:

Completely redesigned Manager-JobAdmin-Worker-infrastructure to distribute Jobs with a Peer-to-Peer infrastructure to remote CT2-Workspaces.

To test this infrastructure, open 2 instances of CT and load P2P_Manager_NEW_DES.cte and in the other instance P2P_Worker_NEW.cte.
HINT: Working with remote peers isn't possible every time, because the so called "SuperNode", which is necessary for relaying, sometimes goes down. But testing this infrastructure on different computers in the same network should work every time.

Location:
trunk/CrypPlugins/KeySearcher_IControl
Files:
2 edited

Legend:

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

    r1100 r1137  
    2828using KeySearcher;
    2929using Cryptool.PluginBase.Control;
     30using Cryptool.Plugins.PeerToPeer;
     31using Cryptool.Plugins.PeerToPeer.Jobs;
     32using System.Threading;
    3033
    3134namespace Cryptool.Plugins.KeySearcher_IControl
     
    3538    public class KeySearcher_IControl : KeySearcher.KeySearcher, IAnalysisMisc
    3639    {
    37         private bool readyForExec = false;
    38         public bool ReadyForExec
    39         {
    40             get { return this.readyForExec; }
    41             private set { this.readyForExec = value; }
    42         }
    43 
    4440        //only change: mandatory = false!!!
    4541        [PropertyInfo(Direction.InputData, "Encrypted Data", "Encrypted data out of an Encryption PlugIn", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, "")]
     
    7268        #region IKeySearcherControl Members
    7369
    74         private IControlKeySearcher controlKeySearcher;
    75         [PropertyInfo(Direction.ControlSlave, "Master KeySearcher", "For distributed bruteforcing", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    76         public IControlKeySearcher ControlKeySearcher
     70        private IControlWorker controlWorker;
     71        [PropertyInfo(Direction.ControlSlave, "Master Worker", "For distributed job processing", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     72        public IControlWorker ControlWorker
    7773        {
    7874            get
    7975            {
    80                 if (this.controlKeySearcher == null)
     76                if (this.controlWorker == null)
    8177                {
    8278                    // to commit the settings of the plugin to the IControl
    83                     this.controlKeySearcher = new KeySearcherMaster(this);
     79                    this.controlWorker = new KeySearcherMaster(this);
    8480                }
    85                 return this.controlKeySearcher;
    86             }
    87         }
    88 
    89         #endregion
    90 
    91         /*
    92          * The original KeySearcher starts bruteforcing after the master control IEncryptionControl
    93          * had fired the event onStatusChanged. Because of repeatedly using this modded KeySearcher
    94          * we must establish an event which informs the KeySearcherMaster Control, that all other
    95          * necessary Controls (CostControl, EncryptControl) are already initialized.
    96          * Otherwise the direct call of bruteforcePattern could run into an Exception, because
    97          * Encryption Control isn't initialized already.
    98          */
    99         //public delegate void IsReadyForExecution();
    100         //public event IsReadyForExecution OnAllMasterControlsInitialized;
    101 
    102         public override void Execute()
    103         {
    104             //if(this.ControlMaster != null)
    105             //{
    106             //    if (OnAllMasterControlsInitialized != null)
    107             //        OnAllMasterControlsInitialized();
    108             //}
    109         }
     81                return this.controlWorker;
     82            }
     83        }
     84
     85        #endregion
    11086    }
    11187
    112     public class KeySearcherMaster : IControlKeySearcher
     88    public class KeySearcherMaster : IControlWorker
    11389    {
     90        #region processing and result variables and properties
     91       
     92        private BigInteger JobId;
     93        private DateTime dtStartProcessing;
     94        private DateTime dtEndProcessing;
     95
     96        #endregion
     97
    11498        private KeySearcher_IControl keySearcher;
    11599
     
    120104        }
    121105
    122         #region IControlKeySearcher Members
    123 
    124106        public IControlEncryption GetEncyptionControl()
    125107        {
     
    132114        }
    133115
    134         public void StartBruteforcing(KeyPattern pattern, byte[] encryptedData, byte[] initVector)
    135         {
    136             //because the KeySearcher object uses this property instead of the parameters in some internal methods... Dirty implementation...
    137             this.keySearcher.Pattern = pattern;
    138             //necessary, because the Pattern property seems to work incorrect
    139             this.keySearcher.Pattern.WildcardKey = pattern.WildcardKey;
    140 
    141             //New stuff because of changing the IControl data flow - Arnie 2010.01.18
    142 
    143             this.keySearcher.BruteforcePattern(pattern, encryptedData, initVector, this.keySearcher.ControlMaster, this.keySearcher.CostMaster);
    144         }
    145 
    146         public event KeySearcher.KeySearcher.BruteforcingEnded OnEndedBruteforcing;
    147116        void keySearcher_OnBruteforcingEnded(LinkedList<KeySearcher.KeySearcher.ValueKey> top10List)
    148117        {
    149             if (OnEndedBruteforcing != null)
    150                 OnEndedBruteforcing(top10List);
    151         }
    152 
    153         public void StopBruteforcing()
    154         {
    155             //this.keySearcher.OnAllMasterControlsInitialized -= keySearcher_OnAllMasterControlsInitialized;
    156         }
    157 
    158         #endregion
     118            this.dtEndProcessing = DateTime.Now;
     119            // Create a new JobResult
     120            TimeSpan processingTime = this.dtEndProcessing.Subtract(this.dtStartProcessing);
     121            KeyPatternJobResult jobResult =
     122                new KeyPatternJobResult(this.JobId, top10List, processingTime);
     123
     124            GuiLogging("Ended bruteforcing JobId '" + this.JobId.ToString() + "' in "
     125                + processingTime.TotalMinutes.ToString() + " minutes",NotificationLevel.Info);
     126
     127            // if registered, sending the serialized Job Result
     128            if (OnProcessingSuccessfullyEnded != null)
     129            {
     130                OnProcessingSuccessfullyEnded(this.JobId, jobResult.Serialize());
     131            }
     132        }
    159133
    160134        #region IControl Members
    161135
    162136        public event IControlStatusChangedEventHandler OnStatusChanged;
     137
     138        #endregion
     139
     140        #region IControlWorker Members
     141        public event ProcessingSuccessfullyEnded OnProcessingSuccessfullyEnded;
     142        public event ProcessingCanceled OnProcessingCanceled;
     143        public event InfoText OnInfoTextReceived;
     144
     145        string sTopicName = String.Empty;
     146        public string TopicName
     147        {
     148            get { return this.sTopicName; }
     149            set { this.sTopicName = value; }
     150        }
     151
     152        public bool StartProcessing(byte[] job, out BigInteger jobId)
     153        {
     154            jobId = 0; //out parameter
     155            if (job != null)
     156            {
     157                KeyPatternJobPart jobPart = new KeyPatternJobPart(job);
     158                if (jobPart != null)
     159                {
     160                    this.JobId = jobPart.JobId;
     161                    // fill out parameter
     162                    jobId = this.JobId;
     163                    this.dtStartProcessing = DateTime.Now;
     164
     165                    GuiLogging("Deserializing job with id '" + jobPart.JobId + "' was successful. Start bruteforcing the KeyPattern '" + jobPart.Pattern.WildcardKey + "'", NotificationLevel.Info);
     166
     167                    // call bruteforcing method in a thread, so this method didn't block the flow
     168                    Thread bruteforcingThread = new Thread(StartBruteforcing);
     169                    bruteforcingThread.Start(jobPart);
     170
     171                    return true;
     172                }
     173                else
     174                {
     175                    GuiLogging("The received job byte[] wasn't null, but couldn't be deserialized!", NotificationLevel.Warning);
     176                }
     177            }
     178            else
     179            {
     180                GuiLogging("Received job byte[] was null. Nothing to do.", NotificationLevel.Warning);
     181            }
     182            return false;
     183        }
     184
     185        private void StartBruteforcing(object what)
     186        {
     187            if (what is KeyPatternJobPart)
     188            {
     189                KeyPatternJobPart jobPart = what as KeyPatternJobPart;
     190                this.keySearcher.BruteforcePattern(jobPart.Pattern, jobPart.EncryptData, jobPart.InitVector,
     191                            this.keySearcher.ControlMaster, this.keySearcher.CostMaster);
     192            }
     193            else
     194                throw(new Exception("Bruteforcing object wasn't from Type 'KeyPatternJobPart'!"));
     195        }
     196
     197        public void StopProcessing()
     198        {
     199            this.keySearcher.Stop();
     200        }
     201
     202        private void GuiLogging(string sText, NotificationLevel notLevel)
     203        {
     204            if (OnInfoTextReceived != null)
     205                OnInfoTextReceived(sText, notLevel);
     206        }
    163207
    164208        #endregion
  • trunk/CrypPlugins/KeySearcher_IControl/KeySearcher_IControl.csproj

    r1130 r1137  
    6565      <Name>CrypPluginBase</Name>
    6666    </ProjectReference>
     67    <ProjectReference Include="..\KeyPatternJob\KeyPatternJob.csproj">
     68      <Project>{D726EBB6-0E54-477A-9C4C-F18848135055}</Project>
     69      <Name>KeyPatternJob</Name>
     70    </ProjectReference>
    6771    <ProjectReference Include="..\KeySearcher\KeySearcher.csproj">
    6872      <Project>{0579E099-66B2-43C3-B8A0-43CAE4895E68}</Project>
    6973      <Name>KeySearcher</Name>
    7074    </ProjectReference>
     75    <ProjectReference Include="..\PeerToPeerBase\PeerToPeerBase.csproj">
     76      <Project>{A7CD30E7-5381-40CF-BB78-268EC998CCB3}</Project>
     77      <Name>PeerToPeerBase</Name>
     78    </ProjectReference>
    7179    <ProjectReference Include="..\PeerToPeerJobs\PeerToPeerJobs.csproj">
    7280      <Project>{F1258427-AFDF-4DF7-ABF1-758A2325F505}</Project>
    7381      <Name>PeerToPeerJobs</Name>
     82    </ProjectReference>
     83    <ProjectReference Include="..\PeerToPeerWorker_NEW\PeerToPeerJobAdmin.csproj">
     84      <Project>{98ABFA8B-D05C-4C28-A0A0-B40733A9B029}</Project>
     85      <Name>PeerToPeerJobAdmin</Name>
    7486    </ProjectReference>
    7587  </ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.