Changeset 1137


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
Files:
37 added
5 deleted
54 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPluginBase/Delegates.cs

    r947 r1137  
    1818using Cryptool.PluginBase.Editor;
    1919using Cryptool.PluginBase.Control;
     20using Cryptool.PluginBase.Miscellaneous;
    2021
    2122namespace Cryptool.PluginBase
     
    8485  public delegate void KeyPatternChanged();
    8586  public delegate void IControlStatusChangedEventHandler(IControl sender, bool readyForExecution);
     87
     88  #region Delegates for Manager-/Worker-Infrastructure
     89
     90  /// <summary>
     91    /// P2PWorker-Control delegate: will be thrown, when the actual job is successfully processed
     92    /// </summary>
     93    /// <param name="result"></param>
     94  public delegate void ProcessingSuccessfullyEnded(BigInteger jobId, byte[] result);
     95    /// <summary>
     96    /// P2PWorker-Control delegate: will be thrown, when processing was canceled by the user or due to an error
     97    /// </summary>
     98    /// <param name="result"></param>
     99  public delegate void ProcessingCanceled(byte[] result);
     100  public delegate void InfoText(string sText, NotificationLevel notLevel);
     101
     102  #endregion
    86103  #endregion
    87104}
  • trunk/CrypPlugins/KeySearcher/KeyPattern.cs

    r1135 r1137  
    2525namespace KeySearcher
    2626{
    27     public class KeyPattern : IJobPart<KeyPattern>
    28     {
     27    public class KeyPattern
     28    {       
    2929        private string pattern;
    3030        internal ArrayList wildcardList;
     
    382382         */
    383383
     384        // Added by Arnold - 2010.02.04
     385        public KeyPattern(byte[] serializedPattern)
     386        {
     387            KeyPattern deserializedPattern = Deserialize(serializedPattern);
     388            // set deserialized Pattern to actual pattern
     389            this.pattern = deserializedPattern.pattern;
     390            this.WildcardKey = deserializedPattern.WildcardKey;
     391            //this.wildcardList = deserializedPattern.wildcardList;
     392            if (deserializedPattern == null)
     393                throw new Exception("Invalid byte[] representation of KeyPattern!");
     394        }
     395
    384396        //added by Christian Arnold - 2009.12.02
    385397        /// <summary>
     
    466478            pattern_temp = encoder.GetString(serializedPattern, iWildCardLen + 2, iPatternLen);
    467479
     480            keyPatternToReturn = new KeyPattern(pattern_temp);
    468481            // test extracted pattern and wildcardKey!
    469             if (testWildcardKey(wildcardKey_temp))
    470             {
    471                 keyPatternToReturn = new KeyPattern(pattern_temp);
     482            if (keyPatternToReturn.testWildcardKey(wildcardKey_temp))
     483            {
    472484                keyPatternToReturn.WildcardKey = wildcardKey_temp;
    473485                return keyPatternToReturn;
  • trunk/CrypPlugins/KeySearcher/KeyPatternPool.cs

    r1129 r1137  
    1313     * It tries to split the pattern in such a way, that the parts have nearly the given partsize.
    1414     **/
    15     public class KeyPatternPool : IJobStack<KeyPattern>
     15    public class KeyPatternPool
    1616    {
    1717        private BigInteger partsize;
     
    6161            }
    6262            return false;
     63        }
     64
     65        // added by Arnie - 2010.02.04
     66        public bool Contains(byte[] serializedJob)
     67        {
     68            KeyPattern deserializedPattern = new KeyPattern(serializedJob);
     69            return Contains(deserializedPattern);
    6370        }
    6471
  • 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>
  • trunk/CrypPlugins/PeerToPeerBase/IP2PControl.cs

    r1066 r1137  
    44using System.Text;
    55using Cryptool.Plugins.PeerToPeer;
     6using Cryptool.PluginBase.Miscellaneous;
    67
    78namespace Cryptool.PluginBase.Control
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeer.cs

    r1115 r1137  
    492492        #region Communication protocol
    493493
    494         /* TODO:
    495          * - Test this methods
    496          * - Integrate data types of payload
    497          * - Implement deserialize method */
    498 
    499494        /// <summary>
    500495        /// generates a ct2- and p2p-compatible and processable message
     
    583578                //    retMsg[i] = message[i + 1];
    584579                //}
    585                 Buffer.BlockCopy(message, 1, retMsg, 0, message.Length - 1);
     580                Buffer.BlockCopy(message, 1, retMsg, 0, retMsg.Length);
    586581                return retMsg;
    587582            }
  • trunk/CrypPlugins/PeerToPeerJobs/IJobPart.cs

    r1129 r1137  
    1 using System;
     1/* Copyright 2010 Team CrypTool (Christian Arnold), Uni Duisburg-Essen
     2
     3   Licensed under the Apache License, Version 2.0 (the "License");
     4   you may not use this file except in compliance with the License.
     5   You may obtain a copy of the License at
     6
     7       http://www.apache.org/licenses/LICENSE-2.0
     8
     9   Unless required by applicable law or agreed to in writing, software
     10   distributed under the License is distributed on an "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12   See the License for the specific language governing permissions and
     13   limitations under the License.
     14*/
     15
     16using System;
    217using System.Collections.Generic;
    318using System.Linq;
    419using System.Text;
     20using Cryptool.PluginBase.Miscellaneous;
    521
    622namespace Cryptool.Plugins.PeerToPeer.Jobs
    723{
    8     public interface IJobPart<JobType>
     24    /// <summary>
     25    /// please implement additionally a static Deserialize method and a constructor
     26    /// with a parameter byte[], where you can Deserialize a byte[] representation
     27    /// of this class. The static Deserialize Method could call than the byte[] constructor!!!
     28    /// </summary>
     29    /// <typeparam name="JobType"></typeparam>
     30    public interface IJobPart
    931    {
     32        BigInteger JobId { get; set; }
    1033        byte[] Serialize();
    11         JobType Deserialize(byte[] serializedJobPart);
     34        //IJobPart<JobType> Deserialize(byte[] serializedJobPart);
    1235    }
    1336}
  • trunk/CrypPlugins/PeerToPeerJobs/IJobResult.cs

    r1130 r1137  
    1 using System;
     1/* Copyright 2010 Team CrypTool (Christian Arnold), Uni Duisburg-Essen
     2
     3   Licensed under the Apache License, Version 2.0 (the "License");
     4   you may not use this file except in compliance with the License.
     5   You may obtain a copy of the License at
     6
     7       http://www.apache.org/licenses/LICENSE-2.0
     8
     9   Unless required by applicable law or agreed to in writing, software
     10   distributed under the License is distributed on an "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12   See the License for the specific language governing permissions and
     13   limitations under the License.
     14*/
     15
     16using System;
    217using System.Collections.Generic;
    318using System.Linq;
    419using System.Text;
     20using Cryptool.PluginBase.Miscellaneous;
    521
    622namespace Cryptool.Plugins.PeerToPeer.Jobs
     
    1228        /// Result is represented by this class
    1329        /// </summary>
    14         int JobId { get; set; }
     30        BigInteger JobId { get; set; }
    1531        /// <summary>
    1632        /// You can allow intermediate results by using this flag
     
    2339        JobResultType Result { get; set; }
    2440        /// <summary>
    25         /// serializes this class, so you can recover all class information by deserializing
     41        /// serializes this class, so you can recover all class information by deserializing.
     42        /// HINT: You can Deserialize a byte[] representation of this class by using the constructor with
     43        /// the byte[] parameter!
    2644        /// </summary>
    2745        /// <returns>serialized byte[] representation of this class</returns>
    2846        byte[] Serialize();
    29         /// <summary>
    30         /// Deserializes a valid byte[] representation of a IJobResult.
    31         /// ATTENTION: Not only deserializes, but additionally recreates the whole class
    32         /// by dint of the byte[]. So all this class information will be overwritten.
    33         /// </summary>
    34         /// <param name="serializedJobResult">a valid byte[] representation of a IJobResult</param>
    35         /// <returns></returns>
    36         bool Deserialize(byte[] serializedJobResult);
    3747    }
    3848}
  • trunk/CrypPlugins/PeerToPeerJobs/JobResult.cs

    r1130 r1137  
    1 using System;
     1/* Copyright 2010 Team CrypTool (Christian Arnold), Uni Duisburg-Essen
     2
     3   Licensed under the Apache License, Version 2.0 (the "License");
     4   you may not use this file except in compliance with the License.
     5   You may obtain a copy of the License at
     6
     7       http://www.apache.org/licenses/LICENSE-2.0
     8
     9   Unless required by applicable law or agreed to in writing, software
     10   distributed under the License is distributed on an "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12   See the License for the specific language governing permissions and
     13   limitations under the License.
     14*/
     15
     16using System;
    217using System.Collections.Generic;
    318using System.Linq;
     
    520using System.IO;
    621using System.Reflection;
     22using Cryptool.PluginBase.Miscellaneous;
    723
    824namespace Cryptool.Plugins.PeerToPeer.Jobs
    925{
    10     public class JobResult<JobResultType> : IJobResult<JobResultType>
     26    public abstract class JobResult<JobResultType> : IJobResult<JobResultType>
    1127    {
    1228        #region Variables
    1329
    14         private int jobId;
    15         public int JobId
     30        private BigInteger jobId;
     31        public BigInteger JobId
    1632        {
    1733            get {  return this.jobId; }
    1834            set { this.jobId = value; }
    1935        }
    20         private bool isIntermediateJobResult;
     36        private bool isIntermediateJobResult = false;
    2137        public bool IsIntermediateResult
    2238        {
     
    4561        /// <param name="result">result of the job (e.g. simple conclusion, list, complex data structure)</param>
    4662        /// <param name="processingTime">Timespan between begin and end of processing the job</param>
    47         public JobResult(int jobId, JobResultType result, TimeSpan processingTime)
     63        public JobResult(BigInteger jobId, JobResultType result, TimeSpan processingTime)
    4864            :this(jobId,result,processingTime,false)
    4965        { }
     
    5672        /// <param name="processingTime">Timespan between begin and end of processing the job</param>
    5773        /// <param name="isIntermediateResult">Is this is only an intermediate result, set this parameter to true, otherwise choose false</param>
    58         public JobResult(int jobId, JobResultType result, TimeSpan processingTime, bool isIntermediateResult)
     74        public JobResult(BigInteger jobId, JobResultType result, TimeSpan processingTime, bool isIntermediateResult)
    5975        {
    6076            this.JobId = jobId;
     
    6480        }
    6581
     82        // TODO: Test this constructor, if it works fine, delete Deserialize Method
     83        /// <summary>
     84        /// If you have a serialized JobResult class, you can deserialize it by using this constructor!
     85        /// </summary>
     86        /// <param name="serializedJobResult">serialized JobResult class as a byte[]</param>
     87        public JobResult(byte[] serializedJobResult)
     88        {
     89            BigInteger temp_jobId;
     90            JobResultType temp_result;
     91            bool temp_isIntermediateResult;
     92            TimeSpan temp_processingTime;
     93
     94            MemoryStream memStream = new MemoryStream(serializedJobResult, false);
     95            try
     96            {
     97                Int32 testValue = 3000;
     98                byte[] readInt = BitConverter.GetBytes(testValue);
     99
     100                /* Deserialize JobId */
     101                memStream.Read(readInt, 0, readInt.Length);
     102                int jobIdLen = BitConverter.ToInt32(readInt, 0);
     103                byte[] jobIdByte = new byte[jobIdLen];
     104                memStream.Read(jobIdByte, 0, jobIdByte.Length);
     105                temp_jobId = new BigInteger(jobIdByte, jobIdByte.Length);
     106
     107                /* Deserialize Job result data */
     108                //memStream.Read(readInt, 0, readInt.Length);
     109                //int serializedDataLen = BitConverter.ToInt32(readInt, 0);
     110                //byte[] serializedJobResultByte = new byte[serializedDataLen];
     111                //memStream.Read(serializedJobResultByte, 0, serializedJobResultByte.Length);
     112                //temp_result = (JobResultType)GetDeserializationViaReflection(serializedJobResultByte, this.Result);
     113
     114                // right for bool???
     115                temp_isIntermediateResult = Convert.ToBoolean(memStream.ReadByte());
     116
     117                memStream.Read(readInt, 0, readInt.Length);
     118                int days = BitConverter.ToInt32(readInt, 0);
     119                memStream.Read(readInt, 0, readInt.Length);
     120                int hours = BitConverter.ToInt32(readInt, 0);
     121                memStream.Read(readInt, 0, readInt.Length);
     122                int minutes = BitConverter.ToInt32(readInt, 0);
     123                memStream.Read(readInt, 0, readInt.Length);
     124                int seconds = BitConverter.ToInt32(readInt, 0);
     125                memStream.Read(readInt, 0, readInt.Length);
     126                int millisec = BitConverter.ToInt32(readInt, 0);
     127                temp_processingTime = new TimeSpan(days, hours, minutes, seconds, millisec);
     128
     129                // read the rest of the byte[]-stream, this is the specialized JobResulType
     130                byte[] serializedJobResultByte = new byte[memStream.Length - memStream.Position];
     131                memStream.Read(serializedJobResultByte, 0, serializedJobResultByte.Length);
     132                temp_result = DeserializeResultType(serializedJobResultByte);
     133
     134                this.JobId = temp_jobId;
     135                this.IsIntermediateResult = temp_isIntermediateResult;
     136                this.ProcessingTime = temp_processingTime;
     137                this.Result = temp_result;
     138            }
     139            catch (Exception ex)
     140            {
     141                throw ex;
     142            }
     143            finally
     144            {
     145                memStream.Flush();
     146                memStream.Close();
     147                memStream.Dispose();
     148            }
     149        }
     150
     151        #region comparing methods
     152
     153        public override bool Equals(object obj)
     154        {
     155            if(obj == null)
     156                return false;
     157
     158            if (ReferenceEquals(this, obj))
     159                return true;
     160
     161            if (this.GetType() != obj.GetType())
     162                return false;
     163
     164            return this == (JobResult<JobResultType>)obj;
     165        }
     166
     167        public static bool operator ==(JobResult<JobResultType> left, JobResult<JobResultType> right)
     168        {
     169            if ((object)left == (object)right)
     170                return true;
     171
     172            if ((object)left == null || (object)right == null)
     173                return false;
     174
     175            if (left.jobId == right.JobId)
     176                return true;
     177
     178            return false;
     179        }
     180
     181        public static bool operator !=(JobResult<JobResultType> left, JobResult<JobResultType> right)
     182        {
     183            return !(left == right);
     184        }
     185
     186        public override int GetHashCode()
     187        {
     188            return this.JobId.GetHashCode();
     189        }
     190
     191        #endregion
     192
    66193        #region Serialization methods
     194
     195        protected abstract byte[] SerializeResultType();
     196
     197        protected abstract JobResultType DeserializeResultType(byte[] serializedResultType);
    67198
    68199        /* 4 Bytes: serialized JobId
     
    76207         * 4 Bytes: procTime.Milliseconds */
    77208        /// <summary>
    78         /// Serializes the whole class, so you can recreate this instance elsewhere by dint of this byte[]
     209        /// Serializes the whole class, so you can recreate this instance elsewhere by dint of this byte[].
     210        /// HINT: You can Deserialize a byte[] representation of this class by using the constructor with
     211        /// the byte[] parameter!
    79212        /// </summary>
    80213        /// <returns>serialized class as an byte[]</returns>
     
    86219            {
    87220                /* Serialize jobId */
    88                 byte[] intJobId = BitConverter.GetBytes(this.JobId);
    89                 memStream.Write(intJobId, 0, intJobId.Length);
     221                byte[] jobIdByte = this.JobId.getBytes();
     222                byte[] jobIdLen = BitConverter.GetBytes(jobIdByte.Length);
     223                memStream.Write(jobIdLen, 0, jobIdLen.Length);
     224                memStream.Write(jobIdByte, 0, jobIdByte.Length);
    90225
    91226                /* Serialize job result via Reflection */
    92                 byte[] serializedJobResult = GetSerializationViaReflection(this.Result);
    93                 byte[] byJobResultLen = BitConverter.GetBytes(serializedJobResult.Length);
    94                 memStream.Write(byJobResultLen, 0, byJobResultLen.Length);
    95                 memStream.Write(serializedJobResult, 0, serializedJobResult.Length);
     227                //byte[] serializedJobResult = GetSerializationViaReflection(this.Result);
     228                //byte[] byJobResultLen = BitConverter.GetBytes(serializedJobResult.Length);
     229                //memStream.Write(byJobResultLen, 0, byJobResultLen.Length);
     230                //memStream.Write(serializedJobResult, 0, serializedJobResult.Length);
    96231
    97232                byte[] intResultBytes = BitConverter.GetBytes(this.isIntermediateJobResult);
     
    108243                byte[] msecondsBytes = BitConverter.GetBytes(this.processingTime.Milliseconds);
    109244                memStream.Write(msecondsBytes,0,msecondsBytes.Length);
    110                                
     245
     246
     247                byte[] serializedJobResult = SerializeResultType();
     248                memStream.Write(serializedJobResult, 0, serializedJobResult.Length);
     249
     250
    111251                ret = memStream.ToArray();
    112252            }
     
    124264        }
    125265
    126         /// <summary>
    127         /// ATTENTION: Not only deserializes the DistributableJobResult, but additionally recreates the whole class
    128         /// by dint of the byte[]. So all this class information will be overwritten.
    129         /// </summary>
    130         /// <param name="serializedJobResult">a valid DistributableJobResult serialization</param>
    131         public bool Deserialize(byte[] serializedJobResult)
    132         {
    133             bool ret = false;
    134             MemoryStream memStream = new MemoryStream(serializedJobResult,false);
    135             try
    136             {
    137                 /* Deserialize JobId */
    138                 byte[] readInt = new byte[4];
    139                 memStream.Read(readInt, 0, readInt.Length);
    140                 this.JobId = BitConverter.ToInt32(readInt,0);
    141 
    142                 /* Deserialize Job result data */
    143                 memStream.Read(readInt,0,readInt.Length);
    144                 int serializedDataLen = BitConverter.ToInt32(readInt,0);
    145                 byte[] serializedJobResultByte = new byte[serializedDataLen];
    146                 memStream.Read(serializedJobResultByte, 0, serializedJobResultByte.Length);
    147                 this.Result = (JobResultType)GetDeserializationViaReflection(serializedJobResultByte, this.Result);
    148 
    149                 // right for bool???
    150                 memStream.Read(readInt, 0, readInt.Length);
    151                 this.isIntermediateJobResult = BitConverter.ToBoolean(readInt,0);
    152 
    153                 memStream.Read(readInt, 0, readInt.Length);
    154                 int days = BitConverter.ToInt32(readInt,0);
    155                 memStream.Read(readInt, 0, readInt.Length);
    156                 int hours = BitConverter.ToInt32(readInt, 0);
    157                 memStream.Read(readInt, 0, readInt.Length);
    158                 int minutes = BitConverter.ToInt32(readInt, 0);
    159                 memStream.Read(readInt, 0, readInt.Length);
    160                 int seconds = BitConverter.ToInt32(readInt, 0);
    161                 memStream.Read(readInt, 0, readInt.Length);
    162                 int millisec = BitConverter.ToInt32(readInt, 0);
    163                 this.processingTime = new TimeSpan(days, hours, minutes, seconds, millisec);
    164 
    165                 ret = true;
    166             }
    167             catch (Exception ex)
    168             {
    169                 throw ex;
    170             }
    171             finally
    172             {
    173                 memStream.Flush();
    174                 memStream.Close();
    175                 memStream.Dispose();
    176             }
    177             return ret;
    178         }
    179 
    180266        #endregion
    181267
    182         #region Reflection methods
    183 
    184         private byte[] GetSerializationViaReflection(object objectToSerialize)
    185         {
    186             byte[] serializedBytes = null;
    187             try
    188             {
    189                 MethodInfo methInfo = objectToSerialize.GetType().GetMethod("Serialize");
    190                 ParameterInfo[] paramInfo = methInfo.GetParameters();
    191                 ParameterInfo returnParam = methInfo.ReturnParameter;
    192                 Type returnType = methInfo.ReturnType;
    193 
    194                 serializedBytes = methInfo.Invoke(objectToSerialize, null) as byte[];
    195                 if (serializedBytes == null)
    196                     throw (new Exception("Serializing " + objectToSerialize.GetType().ToString() + " canceled!"));
    197             }
    198             catch (Exception ex)
    199             {
    200                 throw (new Exception("Invocing method 'Serialize' of '"
    201                     + objectToSerialize.GetType().ToString() + "' wasn't possible. " + ex.ToString()));
    202             }
    203             return serializedBytes;
    204         }
    205 
    206         private object GetDeserializationViaReflection(object serializedData, object returnType)
    207         {
    208             try
    209             {
    210                 MethodInfo methInfo = returnType.GetType().GetMethod("Deserialize", new[] { serializedData.GetType() });
    211                 object deserializedData = methInfo.Invoke(returnType, new object[] { serializedData });
    212                 if (deserializedData == null)
    213                     throw (new Exception("Deserializing " + returnType.ToString() + " canceled!"));
    214                 return deserializedData;
    215             }
    216             catch (Exception ex)
    217             {
    218                 throw (new Exception("Invocing method 'Deserialize' of '"
    219                     + returnType.ToString() + "' wasn't possible. " + ex.ToString()));
    220             }
    221         }
    222 
    223         #endregion
     268        //#region Reflection methods
     269
     270        //private byte[] GetSerializationViaReflection(object objectToSerialize)
     271        //{
     272        //    byte[] serializedBytes = null;
     273        //    try
     274        //    {
     275        //        MethodInfo methInfo = objectToSerialize.GetType().GetMethod("Serialize");
     276        //        ParameterInfo[] paramInfo = methInfo.GetParameters();
     277        //        ParameterInfo returnParam = methInfo.ReturnParameter;
     278        //        Type returnType = methInfo.ReturnType;
     279
     280        //        serializedBytes = methInfo.Invoke(objectToSerialize, null) as byte[];
     281        //        if (serializedBytes == null)
     282        //            throw (new Exception("Serializing " + objectToSerialize.GetType().ToString() + " canceled!"));
     283        //    }
     284        //    catch (Exception ex)
     285        //    {
     286        //        throw (new Exception("Invocing method 'Serialize' of '"
     287        //            + objectToSerialize.GetType().ToString() + "' wasn't possible. " + ex.ToString()));
     288        //    }
     289        //    return serializedBytes;
     290        //}
     291
     292        //private object GetDeserializationViaReflection(object serializedData, object returnType)
     293        //{
     294        //    try
     295        //    {
     296        //        MethodInfo methInfo = returnType.GetType().GetMethod("Deserialize", new[] { serializedData.GetType() });
     297        //        object deserializedData = methInfo.Invoke(returnType, new object[] { serializedData });
     298        //        if (deserializedData == null)
     299        //            throw (new Exception("Deserializing " + returnType.ToString() + " canceled!"));
     300        //        return deserializedData;
     301        //    }
     302        //    catch (Exception ex)
     303        //    {
     304        //        throw (new Exception("Invocing method 'Deserialize' of '"
     305        //            + returnType.ToString() + "' wasn't possible. " + ex.ToString()));
     306        //    }
     307        //}
     308
     309        //#endregion
    224310    }
    225311}
  • trunk/CrypPlugins/PeerToPeerJobs/PeerToPeerJobs.csproj

    r1130 r1137  
    4848  </ItemGroup>
    4949  <ItemGroup>
     50    <Compile Include="IDistributableJob.cs" />
    5051    <Compile Include="IJobResult.cs" />
     52    <Compile Include="JobMessages.cs" />
     53    <Compile Include="JobPart.cs" />
    5154    <Compile Include="JobResult.cs" />
    52     <Compile Include="IJobStack.cs" />
    5355    <Compile Include="IJobPart.cs" />
    5456    <Compile Include="Properties\AssemblyInfo.cs" />
    5557  </ItemGroup>
    5658  <ItemGroup>
    57     <None Include="All3Classes.cd" />
     59    <ProjectReference Include="..\..\CrypPluginBase\CrypPluginBase.csproj">
     60      <Project>{25DB2B47-A457-4EC2-960B-395CE07AE093}</Project>
     61      <Name>CrypPluginBase</Name>
     62    </ProjectReference>
     63  </ItemGroup>
     64  <ItemGroup>
     65    <None Include="cdJobClasses.cd" />
     66    <None Include="cdJobMessage.cd" />
    5867  </ItemGroup>
    5968  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisher.cs

    r1129 r1137  
    189189            if (this.p2pPublisher != null && !this.p2pPublisher.Started)
    190190            {
    191                 this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
     191                this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval * 1000);
    192192            }
    193193
     
    196196                this.p2pPublisher = new P2PPublisherBase(this.P2PControl);
    197197                this.p2pPublisher.OnGuiMessage += new P2PPublisherBase.GuiMessage(p2pPublisher_OnGuiMessage);
    198                 this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
     198                this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval * 1000);
    199199            }
    200200        }
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisherBase.cs

    r1129 r1137  
    8383            /* BEGIN: CHECKING WHETHER THERE HAS ALREADY EXIST ANOTHER PUBLISHER */
    8484            this.topic = sTopic;
    85             this.aliveMessageInterval = aliveMessageInterval * 1000;
     85            this.aliveMessageInterval = aliveMessageInterval;
    8686            AssignManagement(this.aliveMessageInterval);
    8787
     
    230230                    {
    231231                        GuiLogging("ALREADY REGISTERED peer with ID " + sender, NotificationLevel.Info);
    232                         // only for testing reasons
    233                         this.p2pControl.SendToPeer(PubSubMessageType.RegisteringAccepted, sender);
    234232                    }
    235233                    break;
  • trunk/CrypPlugins/PeerToPeerPublisher/SubscribersManagement.cs

    r1107 r1137  
    5757        public virtual bool Add(PeerId subscriberId)
    5858        {
     59            bool retValue = false;
    5960            if (!this.checkList.ContainsKey(subscriberId))
    6061            {
     
    6465                {
    6566                    this.checkList.Add(subscriberId, this.dateTimeNow);
    66                 }
    67                 return true;
    68             }
    69             else
    70                 return false;
     67                    retValue = true;
     68                }
     69            }
     70            return retValue;
    7171
    7272        }
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberBase.cs

    r1130 r1137  
    6969        /// </summary>
    7070        private PeerId actualPublisher;
     71        public PeerId ActualPublisher
     72        {
     73            get { return this.actualPublisher; }
     74            set { this.actualPublisher = value; }
     75        }
     76
    7177        /// <summary>
    7278        /// if true, check whether a new Publisher is the actual one
     
    7985        /// Status flag which contains the state of the Subscriber
    8086        /// </summary>
    81         public bool Started 
    82         {
    83             get { return this.started;  }
    84             private set { this.started = value;  }
     87        public bool Started
     88        {
     89            get { return this.started; }
     90            private set { this.started = value; }
    8591        }
    8692
     
    96102
    97103        /* END: Only for experimental cases */
    98 
    99104
    100105        public P2PSubscriberBase(IP2PControl p2pControl)
     
    243248                case PubSubMessageType.Pong:
    244249                case PubSubMessageType.Unregister:
    245                 case PubSubMessageType.Stop: 
     250                case PubSubMessageType.Stop:
    246251                case PubSubMessageType.Solution:
    247252                    break;
     
    260265
    261266        // registering isn't possible if no publisher has stored
    262         // its ID in the DHT Entry with the Key TaskName
     267        // his ID in the DHT Entry with the Key TaskName
    263268        private void OnRegisteringNotPossible(object state)
    264269        {
     
    306311                GuiLogging("First time received publishers ID.", NotificationLevel.Debug);
    307312            }
    308             //else if (actualPublisher != pid)
    309             //{
    310             //    GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
    311             //    SendMessage(pubId, PubSubMessageType.Register);
    312             //    actualPublisher = pid;
    313             //}
    314313
    315314            GuiLogging("RECEIVED: Publishers' peer ID '" + pid + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Debug);
     
    342341                }
    343342            }
    344             if (newPubId != actualPublisher)
    345                 Register();
    346343        }
    347344
     
    363360        private void OnTimeoutPublishersPong(object state)
    364361        {
    365             GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Warning);
     362            GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Info);
    366363            if (timeoutForPublishersPong != null)
    367364            {
     
    417414
    418415            this.Started = false;
    419             GuiLogging("Subscriber is completely stopped",NotificationLevel.Debug);
     416            GuiLogging("Subscriber is completely stopped", NotificationLevel.Debug);
    420417        }
    421418
     
    427424    }
    428425}
     426
     427
     428//using System;
     429//using System.Collections.Generic;
     430//using System.Linq;
     431//using System.Text;
     432//using Cryptool.PluginBase.Control;
     433//using Cryptool.PluginBase;
     434//using System.Threading;
     435
     436///*
     437// * All Subscriber functions work problem-free!
     438// *
     439// * IDEAS:
     440// * - Publisher takes subscriber list out of the DHT and registered
     441// *   itself with all subscribers pro-active (handle Register-Msg in Subscriber!)
     442// */
     443
     444//namespace Cryptool.Plugins.PeerToPeer
     445//{
     446//    public class P2PSubscriberBase
     447//    {
     448//        public delegate void GuiMessage(string sData, NotificationLevel notificationLevel);
     449//        public event GuiMessage OnGuiMessage;
     450//        public delegate void TextArrivedFromPublisher(byte[] data, PeerId pid);
     451//        public event TextArrivedFromPublisher OnTextArrivedFromPublisher;
     452//        public delegate void ReceivedStopFromPublisher(PubSubMessageType stopType, string sData);
     453//        /// <summary>
     454//        /// fired when Manager sent "stop" message to the worker.
     455//        /// </summary>
     456//        public event ReceivedStopFromPublisher OnReceivedStopMessageFromPublisher;
     457
     458//        #region Variables
     459
     460//        protected IP2PControl p2pControl;
     461//        private long sendAliveMessageInterval;
     462//        private long checkPublishersAvailability;
     463//        private long publisherReplyTimespan;
     464//        private string sTopic;
     465
     466//        /// <summary>
     467//        /// If the DHT Entry of the given Task is empty, continous try to
     468//        /// find a meanwhile inscribed Publishers PeerID
     469//        /// </summary>
     470//        private Timer timerRegisteringNotPossible;
     471//        /// <summary>
     472//        /// For informing the publisher pro-active, that this subscriber
     473//        /// is still interested in this Task.
     474//        /// </summary>
     475//        private Timer timerSendingAliveMsg;
     476//        /// <summary>
     477//        /// checking liveness, availability and/or changes (new peer) of the Publisher
     478//        /// </summary>
     479//        private Timer timerCheckPubAvailability;
     480//        /// <summary>
     481//        /// this timer gets started when the availability of the publisher,
     482//        /// at which the subscriber had registered, is checked. If the timer
     483//        /// callback is called and no Pong-message was received, the probability
     484//        /// that the Publisher is down is high!
     485//        /// </summary>
     486//        private Timer timeoutForPublishersPong;
     487//        /// <summary>
     488//        /// After register message is sent to publisher, this timer gets started.
     489//        /// If the publisher doesn't response with a RegisteringAccepted-Message,
     490//        /// the probability that the publisher is down is high!
     491//        /// </summary>
     492//        private Timer timeoutForPublishersRegAccept;
     493//        /// <summary>
     494//        /// PeerID of the actual publisher. This ID is will be checked continious
     495//        /// on liveliness and/or updated if Publisher had changed.
     496//        /// </summary>
     497//        private PeerId actualPublisher;
     498//        /// <summary>
     499//        /// PeerID of the actual publisher. This ID is will be checked continious
     500//        /// on liveliness and/or updated if Publisher had changed
     501//        /// </summary>
     502//        public PeerId ActualPublisher
     503//        {
     504//            get { return this.actualPublisher; }
     505//        }
     506
     507//        /// <summary>
     508//        /// if true, check whether a new Publisher is the actual one
     509//        /// and renew Settings
     510//        /// </summary>
     511//        private bool bolStopped = true;
     512
     513//        private bool started = false;
     514//        /// <summary>
     515//        /// Status flag which contains the state of the Subscriber
     516//        /// </summary>
     517//        public bool Started
     518//        {
     519//            get { return this.started;  }
     520//            private set { this.started = value;  }
     521//        }
     522
     523//        #endregion
     524
     525//        /* BEGIN: Only for experimental cases */
     526
     527//        public void SolutionFound(byte[] solutionData)
     528//        {
     529//            SendMessage(actualPublisher, PubSubMessageType.Solution);
     530//            this.p2pControl.SendToPeer(solutionData, actualPublisher);
     531//        }
     532
     533//        /* END: Only for experimental cases - 2010.02.07  */
     534
     535//        /* BEGIN: Added for P2PJobAdmin */
     536//        public P2PSubscriberBase()
     537//        {
     538//        }
     539
     540//        public void Start(IP2PControl p2pControl, string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
     541//        {
     542//            this.p2pControl = p2pControl;
     543//            Start(sTopic, checkPublishersAvailability, publisherReplyTimespan);
     544//        }
     545//        /* END: Added for P2PJobAdmin - 2010.02.07 */
     546
     547//        public P2PSubscriberBase(IP2PControl p2pControl)
     548//        {
     549//            this.p2pControl = p2pControl;
     550//        }     
     551
     552//        public void Start(string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
     553//        {
     554//            this.sTopic = sTopic;
     555//            this.checkPublishersAvailability = checkPublishersAvailability;
     556//            this.publisherReplyTimespan = publishersReplyTimespan;
     557//            Register();
     558//        }
     559
     560//        private void Register()
     561//        {
     562//            // Unfortunately you have to register this events every time, because this events will be deregistered, when
     563//            // Publisher/Manager sends a Unregister/Stop-Message... There isn't any possibility to check,
     564//            // whether the Events are already registered (if(dings != null) or anything else).
     565//            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
     566//            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
     567//            this.p2pControl.OnPayloadMessageReceived += new P2PPayloadMessageReceived(p2pControl_OnPayloadMessageReceived);
     568//            this.p2pControl.OnSystemMessageReceived += new P2PSystemMessageReceived(p2pControl_OnSystemMessageReceived);
     569
     570//            // because CheckPublishersAvailability checks this value, set it for the first time here...
     571//            // if bolStopped = true, the Timer for Checking Publishers liveliness doesn't start
     572//            this.bolStopped = false;
     573//            PeerId pubId = CheckPublishersAvailability();
     574//            // if DHT Entry for the task is empty, no Publisher exists at present.
     575//            // The method CheckPublishersAvailability starts a Timer for this case to continous proof Publisher-DHT-Entry
     576//            if (pubId == null)
     577//            {
     578//                this.Started = false;
     579//                // if PubId is null, the Publisher isn't started!
     580//                this.bolStopped = true;
     581//                GuiLogging("No publisher for registering found.", NotificationLevel.Info);
     582//                return;
     583//            }
     584
     585//            // when the actual publisher differs from the new detected publisher, change it
     586//            if (pubId != null && (actualPublisher != null && actualPublisher != pubId))
     587//            {
     588//                GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
     589//                actualPublisher = pubId;
     590//            }
     591//            SendMessage(pubId, PubSubMessageType.Register);
     592//            this.started = true;
     593//        }
     594
     595//        private void p2pControl_OnSystemMessageReceived(PeerId sender, PubSubMessageType msgType)
     596//        {
     597//            if (sender != actualPublisher)
     598//            {
     599//                GuiLogging("RECEIVED message from third party peer (not the publisher!): " + msgType.ToString() + ", ID: " + sender, NotificationLevel.Debug);
     600//                return;
     601//            }
     602//            switch (msgType)
     603//            {
     604//                case PubSubMessageType.RegisteringAccepted:
     605//                    GuiLogging("REGISTERING ACCEPTED received from publisher!", NotificationLevel.Info);
     606//                    if (this.timeoutForPublishersRegAccept != null)
     607//                    {
     608//                        this.timeoutForPublishersRegAccept.Dispose();
     609//                        this.timeoutForPublishersRegAccept = null;
     610//                    }
     611//                    break;
     612//                case PubSubMessageType.Ping:
     613//                    SendMessage(sender, PubSubMessageType.Pong);
     614//                    GuiLogging("REPLIED to a ping message from " + sender, NotificationLevel.Debug);
     615//                    break;
     616//                case PubSubMessageType.Register:
     617//                case PubSubMessageType.Unregister:
     618//                    GuiLogging(msgType.ToString().ToUpper() + " received from PUBLISHER.", NotificationLevel.Debug);
     619//                    // continuously try to get a unregister and than re-register with publisher
     620//                    Stop(msgType);
     621//                    Register();
     622//                    break;
     623//                case PubSubMessageType.Solution:
     624//                    Stop(msgType);
     625//                    GuiLogging("Another Subscriber had found the solution!", NotificationLevel.Info);
     626//                    break;
     627//                case PubSubMessageType.Stop:
     628//                    Stop(msgType);
     629//                    GuiLogging("STOP received from publisher. Subscriber is stopped!", NotificationLevel.Warning);
     630//                    break;
     631//                case PubSubMessageType.Pong:
     632//                    if (this.timeoutForPublishersPong != null)
     633//                    {
     634//                        this.timeoutForPublishersPong.Dispose();
     635//                        this.timeoutForPublishersPong = null;
     636//                    }
     637//                    break;
     638//                case PubSubMessageType.Alive:
     639//                default:
     640//                    // not possible at the moment
     641//                    break;
     642//            }
     643//        }
     644
     645//        private void p2pControl_OnPayloadMessageReceived(PeerId sender, byte[] data)
     646//        {
     647//            if (sender != actualPublisher)
     648//            {
     649//                GuiLogging("RECEIVED message from third party peer (not the publisher!): " + UTF8Encoding.UTF8.GetString(data) + ", ID: " + sender, NotificationLevel.Debug);
     650//                return;
     651//            }
     652//            // functionality swapped for better inheritance
     653//            HandleIncomingData(sender, data);
     654//        }
     655
     656//        /// <summary>
     657//        /// Incoming data will be printed in the information field and the OnTextArrivedEvent will be thrown
     658//        /// </summary>
     659//        /// <param name="senderId"></param>
     660//        /// <param name="sData"></param>
     661//        protected virtual void HandleIncomingData(PeerId senderId, byte[] data)
     662//        {
     663//            GuiLogging("RECEIVED: Message from '" + senderId
     664//                    + "' with data: '" + UTF8Encoding.UTF8.GetString(data) + "'", NotificationLevel.Debug);
     665
     666//            if (OnTextArrivedFromPublisher != null)
     667//                OnTextArrivedFromPublisher(data, senderId);
     668//        }
     669
     670//        private void SendMessage(PeerId pubPeerId, PubSubMessageType msgType)
     671//        {
     672//            if (timerSendingAliveMsg == null && !this.bolStopped)
     673//                timerSendingAliveMsg = new Timer(OnSendAliveMessage, null, sendAliveMessageInterval, sendAliveMessageInterval);
     674
     675//            switch (msgType)
     676//            {
     677//                case PubSubMessageType.Register:
     678//                    // stop "RegisteringNotPossibleTimer
     679//                    if (timerRegisteringNotPossible != null)
     680//                    {
     681//                        timerRegisteringNotPossible.Dispose();
     682//                        timerRegisteringNotPossible = null;
     683//                    }
     684//                    // start waiting interval for RegAccept Message
     685//                    if (this.timeoutForPublishersRegAccept == null)
     686//                        this.timeoutForPublishersRegAccept = new Timer(OnTimeoutRegisteringAccepted, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
     687//                    break;
     688//                case PubSubMessageType.Alive:
     689//                case PubSubMessageType.Ping:
     690//                case PubSubMessageType.Pong:
     691//                case PubSubMessageType.Unregister:
     692//                case PubSubMessageType.Stop:
     693//                case PubSubMessageType.Solution:
     694//                    break;
     695//                //case PubSubMessageType.Solution:
     696//                //    // when i send Solution to the Stop method, we will run into a recursive loop between SendMessage and Stop!
     697//                //    Stop(PubSubMessageType.NULL);
     698//                //    break;
     699//                default:
     700//                    GuiLogging("No Message sent, because MessageType wasn't supported: " + msgType.ToString(), NotificationLevel.Warning);
     701//                    return;
     702//            }
     703//            this.p2pControl.SendToPeer(msgType, pubPeerId);
     704
     705//            GuiLogging(msgType.ToString() + " message sent to Publisher", NotificationLevel.Debug);
     706//        }
     707
     708//        // registering isn't possible if no publisher has stored
     709//        // its ID in the DHT Entry with the Key TaskName
     710//        private void OnRegisteringNotPossible(object state)
     711//        {
     712//            Register();
     713//        }
     714
     715//        private void OnSendAliveMessage(object state)
     716//        {
     717//            SendMessage(actualPublisher, PubSubMessageType.Alive);
     718//        }
     719
     720//        /// <summary>
     721//        /// Returns the actual Publishers ID or null, when a publisher wasn't found in the DHT. In the second case,
     722//        /// a Timer will be started, to check periodically the DHT entry.
     723//        /// When the publishers entry changed the Publishers ID, a Register-message will be send to the new Publisher.
     724//        /// The Timer for periodically checking the Publishers availability is also started here.
     725//        /// </summary>
     726//        /// <returns>the actual Publishers ID or null, when a publisher wasn't found in the DHT</returns>
     727//        private PeerId CheckPublishersAvailability()
     728//        {
     729//            PeerId pid = DHT_CommonManagement.GetTopicsPublisherId(ref this.p2pControl, this.sTopic);
     730
     731//            if (pid == null)
     732//            {
     733//                if (timerRegisteringNotPossible == null && !this.bolStopped)
     734//                {
     735//                    // if DHT value doesn't exist at this moment, wait for 10 seconds and try again
     736//                    timerRegisteringNotPossible = new Timer(OnRegisteringNotPossible, null, 10000, 10000);
     737//                }
     738//                GuiLogging("Publisher wasn't found in DHT or settings didn't stored on the right way.", NotificationLevel.Debug);
     739//                return null;
     740//            }
     741
     742//            sendAliveMessageInterval = DHT_CommonManagement.GetAliveMessageInterval(ref this.p2pControl, this.sTopic);
     743
     744//            if (sendAliveMessageInterval == 0)
     745//            {
     746//                GuiLogging("Can't find AliveMsg-Settings from Publisher for the Subscriber.", NotificationLevel.Error);
     747//                return null;
     748//            }
     749
     750//            if (actualPublisher == null) //first time initialization
     751//            {
     752//                actualPublisher = pid;
     753//                GuiLogging("First time received publishers ID.", NotificationLevel.Debug);
     754//            }
     755//            //else if (actualPublisher != pid)
     756//            //{
     757//            //    GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
     758//            //    SendMessage(pubId, PubSubMessageType.Register);
     759//            //    actualPublisher = pid;
     760//            //}
     761
     762//            GuiLogging("RECEIVED: Publishers' peer ID '" + pid + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Debug);
     763
     764//            // setting timer to check periodical the availability of the publishing peer
     765//            if (timerCheckPubAvailability == null && !this.bolStopped)
     766//                timerCheckPubAvailability = new Timer(OnCheckPubAvailability, null, this.checkPublishersAvailability, this.checkPublishersAvailability);
     767
     768//            return pid;
     769//        }
     770
     771//        /// <summary>
     772//        /// Callback for timerCheckPubAvailability (adjustable parameter
     773//        /// in settings, usually every 60 seconds). If another Peer
     774//        /// takes over Publishing the Task, this will be handled in this callback, too.
     775//        /// </summary>
     776//        /// <param name="state"></param>
     777//        private void OnCheckPubAvailability(object state)
     778//        {
     779//            PeerId newPubId = CheckPublishersAvailability();
     780
     781//            if (newPubId == actualPublisher)
     782//            {
     783//                // Timer will be only stopped, when OnMessageReceived-Event received
     784//                // a Pong-Response from the publisher!
     785//                SendMessage(actualPublisher, PubSubMessageType.Ping);
     786//                if (timeoutForPublishersPong == null)
     787//                {
     788//                    timeoutForPublishersPong = new Timer(OnTimeoutPublishersPong, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
     789//                }
     790//            }
     791//            if (newPubId != actualPublisher)
     792//                Register();
     793//        }
     794
     795//        /// <summary>
     796//        /// This callback is only fired, when the publisher didn't sent a response on the register message.
     797//        /// </summary>
     798//        /// <param name="state"></param>
     799//        private void OnTimeoutRegisteringAccepted(object state)
     800//        {
     801//            GuiLogging("TIMEOUT: Waiting for registering accepted message from publisher!", NotificationLevel.Debug);
     802//            // try to register again
     803//            Register();
     804//        }
     805
     806//        /// <summary>
     807//        /// This callback os only fired, when the publisher didn't sent a response on the ping message.
     808//        /// </summary>
     809//        /// <param name="state"></param>
     810//        private void OnTimeoutPublishersPong(object state)
     811//        {
     812//            GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Warning);
     813//            if (timeoutForPublishersPong != null)
     814//            {
     815//                timeoutForPublishersPong.Dispose();
     816//                timeoutForPublishersPong = null;
     817//            }
     818//            // try to get an active publisher and re-register
     819//            CheckPublishersAvailability();
     820//        }
     821
     822//        /// <summary>
     823//        /// Will stop all timers, so Subscriber ends with sending
     824//        /// Register-, Alive- and Pong-messages. Furthermore an
     825//        /// unregister message will be send to the publisher
     826//        /// </summary>
     827//        public void Stop(PubSubMessageType msgType)
     828//        {
     829//            this.bolStopped = true;
     830//            if (actualPublisher != null && msgType != PubSubMessageType.NULL)
     831//                SendMessage(actualPublisher, msgType);
     832
     833//            #region stopping all timers, if they are still active
     834//            if (this.timerSendingAliveMsg != null)
     835//            {
     836//                this.timerSendingAliveMsg.Dispose();
     837//                this.timerSendingAliveMsg = null;
     838//            }
     839//            if (this.timerRegisteringNotPossible != null)
     840//            {
     841//                this.timerRegisteringNotPossible.Dispose();
     842//                this.timerRegisteringNotPossible = null;
     843//            }
     844//            if (this.timerCheckPubAvailability != null)
     845//            {
     846//                this.timerCheckPubAvailability.Dispose();
     847//                this.timerCheckPubAvailability = null;
     848//            }
     849//            if (this.timeoutForPublishersRegAccept != null)
     850//            {
     851//                this.timeoutForPublishersRegAccept.Dispose();
     852//                this.timeoutForPublishersRegAccept = null;
     853//            }
     854//            if (this.timeoutForPublishersPong != null)
     855//            {
     856//                this.timeoutForPublishersPong.Dispose();
     857//                this.timeoutForPublishersPong = null;
     858//            }
     859//            #endregion
     860//            GuiLogging("All Timers were stopped successfully", NotificationLevel.Debug);
     861
     862//            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
     863//            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
     864
     865//            this.Started = false;
     866//            GuiLogging("Subscriber is completely stopped",NotificationLevel.Debug);
     867//        }
     868
     869//        protected void GuiLogging(string sText, NotificationLevel notLev)
     870//        {
     871//            if (OnGuiMessage != null)
     872//                OnGuiMessage(sText, notLev);
     873//        }
     874//    }
     875//}
  • trunk/CrypTool 2.0.sln

    r1130 r1137  
    201201Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerCertificates", "CrypPlugins\PeerToPeerCertificates\PeerToPeerCertificates.csproj", "{7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}"
    202202EndProject
    203 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerManager", "CrypPlugins\PeerToPeerManager\PeerToPeerManager.csproj", "{81A16361-0F1F-4A82-9B52-E14759C3FEFD}"
    204 EndProject
    205 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerWorker", "CrypPlugins\PeerToPeerWorker\PeerToPeerWorker.csproj", "{4B0393E8-CB51-4E75-B1DA-951DDFF7D837}"
    206 EndProject
    207203Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerPublisher", "CrypPlugins\PeerToPeerPublisher\PeerToPeerPublisher.csproj", "{A1E7F287-DFC1-44C2-A681-C62DF46B43C5}"
    208204EndProject
     
    210206EndProject
    211207Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerJobs", "CrypPlugins\PeerToPeerJobs\PeerToPeerJobs.csproj", "{F1258427-AFDF-4DF7-ABF1-758A2325F505}"
     208EndProject
     209Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerManager_NEW", "CrypPlugins\PeerToPeerManager_NEW\PeerToPeerManager_NEW.csproj", "{B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}"
     210EndProject
     211Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerJobAdmin", "CrypPlugins\PeerToPeerWorker_NEW\PeerToPeerJobAdmin.csproj", "{98ABFA8B-D05C-4C28-A0A0-B40733A9B029}"
    212212EndProject
    213213Global
     
    11471147                {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    11481148                {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    1149                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Debug|.NET.ActiveCfg = Debug|Any CPU
    1150                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    1151                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
    1152                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
    1153                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
    1154                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Release|.NET.ActiveCfg = Release|Any CPU
    1155                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
    1156                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Release|Any CPU.Build.0 = Release|Any CPU
    1157                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    1158                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    1159                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Debug|.NET.ActiveCfg = Debug|Any CPU
    1160                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    1161                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Debug|Any CPU.Build.0 = Debug|Any CPU
    1162                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
    1163                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
    1164                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Release|.NET.ActiveCfg = Release|Any CPU
    1165                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Release|Any CPU.ActiveCfg = Release|Any CPU
    1166                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Release|Any CPU.Build.0 = Release|Any CPU
    1167                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    1168                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    11691149                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5}.Debug|.NET.ActiveCfg = Debug|Any CPU
    11701150                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     
    11971177                {F1258427-AFDF-4DF7-ABF1-758A2325F505}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    11981178                {F1258427-AFDF-4DF7-ABF1-758A2325F505}.Release|Mixed Platforms.Build.0 = Release|Any CPU
     1179                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Debug|.NET.ActiveCfg = Debug|Any CPU
     1180                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     1181                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
     1182                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
     1183                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
     1184                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Release|.NET.ActiveCfg = Release|Any CPU
     1185                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
     1186                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Release|Any CPU.Build.0 = Release|Any CPU
     1187                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
     1188                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
     1189                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Debug|.NET.ActiveCfg = Debug|Any CPU
     1190                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     1191                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Debug|Any CPU.Build.0 = Debug|Any CPU
     1192                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
     1193                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
     1194                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Release|.NET.ActiveCfg = Release|Any CPU
     1195                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Release|Any CPU.ActiveCfg = Release|Any CPU
     1196                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Release|Any CPU.Build.0 = Release|Any CPU
     1197                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
     1198                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    11991199        EndGlobalSection
    12001200        GlobalSection(SolutionProperties) = preSolution
     
    12071207                {A7CD30E7-5381-40CF-BB78-268EC998CCB3} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    12081208                {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    1209                 {81A16361-0F1F-4A82-9B52-E14759C3FEFD} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    1210                 {4B0393E8-CB51-4E75-B1DA-951DDFF7D837} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    12111209                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    12121210                {612FEE87-F51F-4BE6-81D1-F91EA4A5DD43} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    12131211                {F1258427-AFDF-4DF7-ABF1-758A2325F505} = {775BB529-52BD-4B18-A092-E4EA70E53838}
     1212                {B52F4D1D-1AB4-4E9B-B056-BE006A732BBD} = {775BB529-52BD-4B18-A092-E4EA70E53838}
     1213                {98ABFA8B-D05C-4C28-A0A0-B40733A9B029} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    12141214        EndGlobalSection
    12151215EndGlobal
Note: See TracChangeset for help on using the changeset viewer.